#include <cstdio>#include <cstring>usingnamespacestd;
constintN=21;
intb, n;
intcost[N];
boolinput();
voidsolve();
intmain()
{
#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endifwhile (input()) {
solve();
}
return0;
}
boolinput()
{
scanf("%d%d", &b, &n);
if (b==0&&n==0) returnfalse;
memset(cost, 0x00, sizeof(cost));
for (inti=1; i<=b; i++) {
scanf("%d", &cost[i]);
}
for (inti=0; i<n; i++) {
intdebtor, creditor, debenture;
scanf("%d%d%d", &debtor, &creditor, &debenture);
cost[debtor] -=debenture;
cost[creditor] +=debenture;
}
returntrue;
}
voidsolve()
{
boolok=true;
for (inti=1; i<=b; i++) {
if (cost[i] <0) {
ok=false;
break;
}
}
printf("%s\n", ok?"S" : "N");
}