akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using P = pair<LL, LL>;

int main(){
    int N;
    cin >> N;
    vector<LL>  a(N), b(N);
    vector<P>   vp(N);
    for(int i = 0;i < N;i++)    cin >> a[i] >> b[i];
    for(int i = 0;i < N;i++)    vp[i] = {a[i]+b[i], i};
    sort(vp.rbegin(), vp.rend());
    LL ans = 0;
    for(int i = 0;i < N;i++){
        if(i&1) ans -= b[vp[i].second];
        else    ans += a[vp[i].second];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  string s[N];
  ll t[N];
  rep(i,N) cin>>s[i]>>t[i];
  string x;
  cin>>x;
  ll check;
  ll ans=0;
  rep(i,N){
    if(x==s[i]){
      check=i+1;
    }
  }
  for(int i=check;i<N;i++){
    ans+=t[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3580
package main

import "fmt"

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	ans := max(a+b, max(a-b, a*b))
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;

int cost[100][100];
int d[100];//??????s?????????????°??????¢
bool used[100];
int arrow;//????????°

const int INF = 10000000;

void dijkstra(){
  fill(d,d+arrow,INF);
  fill(used,used + arrow,false);
  d[0] = 0;

  while(1){
    int v=-1;
    // ???????????????????????????????????????????????¢???????°???????????????¢???
    for(int u=0;u<arrow;u++){
      if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
    }

    if(v == -1) break;

    used[v] = true;

    for(int u=0; u<arrow; u++){
      if(cost[v][u] != INF){
        d[u] = min(d[u],d[v] + cost[v][u]);
      }
    }
  }

  for(int u=0; u<arrow; u++){
    cout << u << " " << d[u] << endl;
  }

}

int main(){

    cin >> arrow;

    int n,a,v,c;



    for(int i=0;i<arrow;i++){
      for(int j=0;j<arrow;j++){
        cost[i][j] = INF;
      }
    }

    /*for(int i=0; i<arrow; i++){
      cost[i][i] = 0;
    }*/

    for(int u=0;u<arrow;u++){

      cin >> n >> a;

      for(int i=0; i<a;i++){
        cin >> v >> c;
        cost[n][v] = c;
      }
    }

    dijkstra();

    return 0;
}

Measured memory_bytes: 3124
n, k, q = list(map(int, input().split()))
lisA = [int(input()) for i in range(q)]

#print(n, k, q)
#print(lisA)

pointA = [k] * (n+1)
#pointA[0]は無視

for i in lisA:
	pointA[i] += 1

for i in range(1, n+1):
	pointA[i] -= q
	if (pointA[i] <= 0):
		print("No")
	else:
		print("Yes")


Measured memory_bytes: 11776
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

int h,w;
char a[10][10]= {};

int dfs(int x,int y){
   // cout << x << " " << y << endl;
    if(h-1 == y && w-1 == x){
        a[y][x] = '.';
        rep(i,0,h)rep(j,0,w)if(a[i][j] =='#'){
            a[y][x] = '#';
            ret 0;
        }
        a[y][x] = '#';
        ret 1;
    }
    
    a[y][x] = '.';

    int ans = 0;
    if(a[y+1][x] == '#')ans = max(ans,dfs(x,y+1));
    if(a[y][x+1] == '#')ans = max(ans,dfs(x+1,y));

    a[y][x] = '#';
    
    ret ans;
}
int main(){
    cin >> h >> w;
    rep(i,0,h)rep(j,0,w)cin >> a[i][j];

    if(dfs(0,0)){
        P("Possible");
        ret 0;
    }
    P("Impossible");
	return  0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long[] d = new long[40];
        d[0] = 1L;
        for (int i = 1; i < 40; i++) {
            d[i] = d[i-1] * 2;
        }
        long ans = 0L;
        for (int i = 0; i < 40; i++) {
            if(h < d[i]) break;
            ans += d[i];
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 23380
//Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>

using namespace std; 


const int N = 1e5 + 5; 
int n;
int s[N];
int t[N];
int ans; 
int s2[N];
int t2[N]; 
map<int, int> cnt1;
map<int, int> cnt2;
map<int, int> par; 

int get(int x)
{
    if (par[x] == x)
    {
        return x; 
    }
    return par[x] = get(par[x]); 
}

void merge(int x, int y)
{
    x = get(x);
    y = get(y); 
    if (x != y)
    {
        par[y] = x; 
    }
}

int main()
{
    cin >> n; 
    for (int i = 0; i < n; i++) 
    {
        cin >> s[i]; 
    }
    for (int i = 0; i < n; i++) 
    {
        cin >> t[i]; 
    }
    for (int i = 0; i < n; i++)
    {
        s[n] ^= s[i]; 
        t[n] ^= t[i]; 
    }
    for (int i = 0; i < n + 1; i++)
    {
        par[s[i]] = -1; 
        par[t[i]] = -1; 
    }
    for (int i = 0; i < n + 1; i++)
    { 
        cnt1[s[i]]++;
    }
    for (int i = 0; i < n + 1; i++) 
    {
        cnt2[t[i]]++;
    }
    for (int i = 0; i < n; i++) 
    {
        if (cnt2[t[i]] != cnt1[t[i]])
        {
            cout << -1; 
            return 0; 
        }
    }
    bool check = true; 
    for (int i = 0; i < n + 1; i++) 
    {
        if (s[i] != t[i]) 
        {
            check = false; 
        }
    }
    if (check)
    {
        cout << 0; 
        exit(0);
    }
    for (int i = 0; i < n + 1; i++)
    {
        if (s[i] != t[i] || i == n)
        {
            if (i != n) 
            {
                ans++; 
            }
            if (par[s[i]] == -1) 
            {
                par[s[i]] = s[i]; 
            }
            if (par[t[i]] == -1) 
            {
                par[t[i]] = t[i]; 
            }
            if (i != n) 
            {
                merge(s[i], t[i]); 
            }
        }
    }
    for (auto &it : par) 
    {
        if (get(it.first) == it.first) 
        {
            ans++; 
        }
    }
    cout << ans - 1; 
}



Measured memory_bytes: 18368
#include <bits/stdc++.h>
using namespace std;

vector<long> L;

void dfs(long n) {
  if (n > 3234566667) return;
  L.push_back(n);
  int last = n % 10;
  int mi = max(0, last - 1);
  int mx = min(9, last + 1);
  for (int i = mi; i <= mx; i++) dfs(n * 10 + i);
}

int main() {
  int K;
  cin >> K;
  for (int i = 1; i <= 9; i++) dfs(i);
  sort(L.begin(), L.end());
  cout << L.at(K - 1) << "\n";
}

Measured memory_bytes: 4292
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    solve();
}

// N は 999 以下の正の整数

// ll N
// 答えを出力せよ。
void solve(){
    N%=10;
    if(N==3){
        cout<<"bon"<<endl;
    }else if(N==0||N==1||N==6||N==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"hon"<<endl;
    }
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	// ABC140-D, 1112, 52:57, WA(UNSOLVED), 
	int n, k;
	string s, invs;
	cin >> n >> k >> s;
	vector<int> v;
	int ans = 0;
	int changed = 0;
	for (int i = 1; i < n; ++i) {
		if (s[i - 1] == s[i]) ans++;
		else changed++;
	}
	changed++;
	if (changed == 1) {
		cout << ans << endl;
		return 0;
	}
	int i = 0;
	for (i = 0; i < k; ++i) {
		if (changed <= 2) break;
		ans += 2;
		changed -= 2;
	}
	if (changed == 2 && i != k) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3764
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<malloc.h>

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}


int main(void){
    char buf[200002];
    int st,go;

    my_gets(buf,200002,stdin);
    for(st=0;buf[st]!='A';st++);
    for(go=strlen(buf)-1;buf[go]!='Z';go--);

    printf("%d\n",go-st+1);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int mx = 100005;
const int md = 1e9+7;
int n, x, y;
vector<int> v[mx];
long long wh[2][mx];
int bfs(int ps, int pr){
    if(wh[0][ps]) return (wh[0][ps] + wh[1][ps]) % md;
    wh[0][ps] = wh[1][ps] = 1;
    for(int it: v[ps]){
        if(it == pr) continue;
        (wh[0][ps] *= bfs(it, ps)) %= md;
        (wh[1][ps] *=  wh[0][it]) %= md;
    }
    return (wh[0][ps] + wh[1][ps]) % md;
}

int main(){
    scanf("%d", &n);
    for(int i = 0; i < n-1; i++){
        scanf("%d%d", &x, &y);x--; y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    printf("%d\n", bfs(0, -1));
}

Measured memory_bytes: 14208
#include <stdio.h>
#include <stdlib.h>
int compare(const void *a,const void *b){
    if(*(int *)a>*(int *)b)return -1;
    return 1;
}
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    int h[n],i;
    for(i = 0;i<n;i++){
        scanf("%d",&h[i]);
    }
    long long count;
    count = 0;
    qsort(h,n,sizeof(int),compare);
    for(i=k;i<n;i++){
        count+=h[i];
    }
    printf("%lld",count);
    return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9 + 5;

void a()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}

int main()
{
    a();

    int n;
    cin >> n;
    vector<int> val(n), dp(n, INF);

    for(int i = 0; i < n; i++) cin >> val[i];

    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j : {i + 1, i + 2}){
            if(j < n) dp[j] = min(dp[j], dp[i] + abs(val[j] - val[i]));
        }
    }

   cout << dp[n-1];
}


Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int N = 1e+6;
const int mod = 1000000007;
int h,w;
char mat[1001][1001];
int32_t main()
{
	cin>>h>>w;

	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin>>mat[i][j];
		}
	}

	vector<vector<int> > dp(h+1,vector<int>(w+1,0));

	for(int i=w;i>=1;i--)
	{
		for(int j = h;j>=1;j--)
		{
			if(i==w&&j==h)
				{
					dp[j][i]=1;
				}
			if(mat[j][i]=='#')
			{
				dp[j][i]=0;
			}
			else
			{
				if(i+1<=w)
				{
					dp[j][i]=(dp[j][i]+dp[j][i+1])%mod;
				}
				if(j+1<=h)
				{
					dp[j][i]=(dp[j][i]+dp[j+1][i])%mod;
				}
			}
		}
	}
	cout<<dp[1][1]<<endl;

}

Measured memory_bytes: 9088
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;


    
    
    int main(){
        int n;cin>>n;
        map<string,int>mp;
        rep(i,n){
            string s;cin>>s;
            mp[s]++;
        }
        int mx = 0;
        for(auto m : mp){
            mx = max(mx,m.second);
        }
        int i = 0,cnt = 0;
        vector<string> s;
        for(auto m : mp){
            if(m.second == mx){
                s.push_back(m.first);
                cnt++;
            }
            i++;
        }
        sort(s.begin(),s.end());
        for(auto t : s){
            cout<<t<<endl;
        }
    }
    


Measured memory_bytes: 26868
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		if ((N & 1) == 0)
			System.out.println(N);
		else
			System.out.println(N << 1);
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int m;
    cin >> m;

    cout << 48 - m << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i)
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i)

#define DEBUG(...) fprintf(stderr , __VA_ARGS__)

template<typename T>inline int chkmin(T &x , const T &y){ return x > y ? x = y , 1 : 0; }
template<typename T>inline int chkmax(T &x , const T &y){ return x < y ? x = y , 1 : 0; }

template<typename T>inline T read(T &f)
{
	f = 0 ; int x = 1 ; char c = getchar();
	while(!isdigit(c)) c = x == '-' ? -1 : 1 , c = getchar();
	while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
	return f *= x;
}

using int64 = long long;
using uint64 = unsigned long long;

const int N = 100 + 5;

int64 Ans;

int n , A[N];	

int B[N];

int main()
{
	read(n);
	rep(i , 1 , n) B[i] = INT_MAX;
	rep(i , 1 , n - 1)
	{
		read(A[i]);
		chkmin(B[i] , A[i]);
		chkmin(B[i + 1] , A[i]);
	}
	rep(i , 1 , n) Ans += B[i];
	cout << Ans << endl;
	return 0;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
S = []
for i in range(H):
  S.append(list(input()))
  
if H == 1:
  if W == 1:
    if S[0][0] == '.':
      S[0][0] = str(0)
    print("".join(S[0]))
    exit()
  if W == 2:
    if S[0][0] == '.' and S[0][1] == '.':
      S[0][0] = str(0)
      S[0][1] = str(0)
    elif S[0][0] == '.' and S[0][1] == '#':
      S[0][0] = str(1)
    elif S[0][0] == '#' and S[0][1] == '.':
      S[0][1] = str(1)
    else:
      pass
    print("".join(S[0]))
    exit()
  
  if W > 2:
    for i in range(W):
      if S[0][i] == '.':
        if i == 0:
          S[0][i] = str(int(S[0][i+1] == '#'))
        elif 0 < i < W-1:
          S[0][i] = str(int(S[0][i-1] == '#') + int(S[0][i+1] == '#'))
        elif i == W-1:
          S[0][i] = str(int(S[0][i-1] == '#'))

    print("".join(S[0]))
    exit()
    
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      if i == 0:
        if j == 0:
          cnt = S[i][:j+2].count('#') + S[i+1][:j+2].count('#')
          S[i][j] = str(cnt)
        elif 0 < j < W - 1:
          cnt = S[i][j-1:j+2].count('#') + S[i +1][j-1:j+2].count('#')
          S[i][j] = str(cnt)
        elif j ==W -1:
          cnt = S[i][j-1:].count('#') + S[i+1][j-1:].count('#')
          S[i][j] = str(cnt)
      elif 0<i<H-1:
        if j == 0:
          cnt = S[i-1][:j+2].count('#')+S[i][:j+2].count('#') + S[i+1][:j+2].count('#')
          S[i][j] = str(cnt)
        elif 0 < j < W - 1:
          cnt = S[i-1][j-1:j+2].count('#')+ S[i][j-1:j+2].count('#') + S[i +1][j-1:j+2].count('#')
          S[i][j] = str(cnt)
        elif j ==W -1:
          cnt = S[i-1][j-1:].count('#') + S[i][j-1:].count('#') + S[i+1][j-1:].count('#')
          S[i][j] = str(cnt)
      elif i == H-1:
        if j == 0:
          cnt = S[i-1][:j+2].count('#') + S[i][:j+2].count('#')
          S[i][j] = str(cnt)
        elif 0 < j < W - 1:
          cnt = S[i-1][j-1:j+2].count('#') + S[i][j-1:j+2].count('#')
          S[i][j] = str(cnt)
        elif j ==W -1:
          cnt = S[i-1][j-1:].count('#') + S[i][j-1:].count('#')
          S[i][j] = str(cnt)

for i in range(H):
  print("".join(S[i]))

Measured memory_bytes: 3320
#include <bits/stdc++.h>

using namespace std;

int cnt[200005];

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 2; i <= n; i++) {
		int x;
		scanf("%d", &x);
		cnt[x]++;
	}
	
	for (int i = 1; i <= n; i++) printf("%d\n", cnt[i]);
}


Measured memory_bytes: 4452
#include <stdio.h>

int main (void){
    char str[3];
    int num;

    scanf("%d",&num);
    switch (num%10)
    {
    case 3:
        printf("bon\n");
    break;

    case 0:
    case 1:
    case 6:
    case 8:
        printf("pon\n");
    break;
    default:
        printf("hon\n");
    break;
    }

    return 0;  
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
 
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
 
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
 
#define _  %  MOD
#define __ %= MOD
 
#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))
 
#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
#define fbo find_by_order
#define ook order_of_key
 
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
ll n,m;
ll inf=1e18;
const int N=15;
const int maxn=1005;
ll a[maxn],b[maxn];
vector<ll> c[maxn];
ll dp[1<<N][maxn];
ll f(ll i,ll j)
{
	if(i+1==power(2,n) && j<=(m+1)) return 0;
	if(j>m && i+1!=power(2,n)) return inf;
	if(dp[i][j]!=-1) return dp[i][j];
	ll ans=inf;
	ans=f(i,j+1);// if j is not selected
	// if j is selected
	ll ii=i;
	for(auto k:c[j])
	{
		k--;
		ii|=power(2,k);
	}
	ans=min(ans,f(ii,j+1)+a[j]);
	return dp[i][j]=ans;
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	cin>>n>>m;
   	repA(i,1,m)
	{
		cin>>a[i]>>b[i];
		rep(j,b[i])
		{
			ll val;
			cin>>val;
			c[i].pb(val);
		}
	}	
	memset(dp,-1,sizeof(dp));
	ll ans=f(0,1);
	if(ans>=inf) cout<<-1<<'\n';
	else cout<<ans<<'\n';
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!



Measured memory_bytes: 261060
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=200000+5,mod=998244353;
int ksm(int b,int n){
	int res=1;
	while(n){
		if(n&1) res=res*b%mod;
		b=b*b%mod; n>>=1;
	}
	return res;
}
int add(int x,int y){
	return (x+y)%mod;
}
int mul(int x,int y){
	return x*y%mod;
}
vector<int> e[N];
int n,dis[N],pre[N];
int dp[N][3][3];
int bfs(int st){
	queue<int> q;
	int res=0;
	for(int i=1;i<=n;++i)
		dis[i]=0;
	dis[st]=1; pre[st]=0; q.push(st);
	while(!q.empty()){
		int u=q.front();q.pop();
		if(dis[u]>dis[res]) res=u;
		//cout<<st<<" "<<u<<" "<<dis[u]<<" "<<res<<endl;
		for(int i=0;i<e[u].size();++i)
			if(dis[e[u][i]]==0) q.push(e[u][i]),dis[e[u][i]]=dis[u]+1,pre[e[u][i]]=u;
	}
	return res;
}
int L,tmp[3][3];
void dfs(int u,int fath,int dep){
	//cout<<u<<" "<<fath<<" "<<dep<<endl;
	if(dep==L/2) dp[u][1][1]=1;
	else dp[u][0][0]=1;
	for(int i=0;i<e[u].size();++i){
		int v=e[u][i];
		if(v==fath) continue;
		dfs(v,u,dep+1);
		for(int x=0;x<=2;++x)
			for(int y=0;y<=2;++y)
				tmp[x][y]=0;
		for(int x=0;x<=2;++x)
			for(int y=0;y<=2;++y)
				for(int a=0;a<=2;++a)
					for(int b=0;b<=2;++b)
						for(int type=0;type<=2;++type){
							int p=min(x+(type==1)*a,2ll),q=min(y+(type==2)*b,2ll);
							tmp[p][q]=add(tmp[p][q],mul(dp[u][x][y],dp[v][a][b]));
						}
		for(int x=0;x<=2;++x)
			for(int y=0;y<=2;++y)
				dp[u][x][y]=tmp[x][y];
	}
	//for(int x=0;x<=2;++x)
	//	for(int y=0;y<=2;++y)
		//	cout<<u<<" "<<x<<" "<<y<<" "<<dp[u][x][y]<<endl;
}
int c[N],tot;
void solve(){
	int from=bfs(1),to=bfs(from);
	tot=0;while(to) c[++tot]=to,to=pre[to];
	L=tot;
	if(tot&1){
		from=c[(tot+1)/2];
		dfs(from,0,0);
		cout<<mul(dp[from][1][1],ksm(2,mod-2));
		return;
	}
	else{
		from=c[tot/2],to=c[(tot+2)/2];
	//	cout<<from<<" "<<to<<" "<<tot<<endl;
		dfs(from,to,1);
		int x=0,y=0;
		for(int i=0;i<=2;++i)
			x=add(x,dp[from][i][1]);
		dfs(to,from,1);
		for(int i=0;i<=2;++i)
			y=add(y,dp[to][1][i]);
		cout<<mul(x,y);
		return;
	}
}
signed main(){
	int ans=0,u,v;
	cin>>n;
	for(int i=1;i<n;++i){
		cin>>u>>v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	solve();
	return 0;
}


Measured memory_bytes: 41600
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    cin >> n;
    int H[n];
    for(int i = 0;i<n;i++){
        cin >> H[i];
    }
    int count = 1;
    int max = H[0];
    for(int i = 1;i<n;i++){
        if(max<=H[i]){
            count++;
            max = H[i];
        } 
    }
    cout << count << endl;


    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>

using namespace std;
long long k, a, b;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);	
	cin >> k >> a >> b;
	if (a + 2 >= b || k + 1 <= a)
		cout << k + 1 << '\n';
	else
		cout << a + ((k - (a - 1)) / 2) * (b - a) + ((k - (a - 1)) % 2) << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using myui = uint64_t;
using myint = int64_t;

template<typename T>
T diff(const T& a, const T& b) {
    return a > b ? a - b : b - a;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    {
        myui n, k;
        string s;
        cin >> n >> s >> k;
        for(auto& c : s) {
            cout << (c == s[k-1] ? c : '*');
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
object Main {
	val s = new java.util.Scanner(System.in)
	def main(args: Array[String]) {
		val a, b, c = s.next();
		println(if(shiritori(a,b)&&shiritori(b, c))
			"YES"else"NO");
	}
	def shiritori(a1:String,a2:String):Boolean={
		a1.charAt(a1.length()-1)==a2.charAt(0);
	}
}


Measured memory_bytes: 25544
use proconio::input;

macro_rules! chmax {
    ($l: expr, $r: expr) => {
        $l = std::cmp::max($l, $r);
    };
}

fn main() {
    input! {
        n: usize,
        av: [i64; n],
    };

    let mut pv: Vec<(i64, i64)> = av.iter().enumerate().map(|(i, &a)| (a, i as i64)).collect();
    pv.sort_by_key(|(a, i)| (-a, -i));
    // dp[i][l] ... 降順で i 番目まで見て l 個を左側に配置したときの最大値
    let mut dp = vec![vec![0_i64; n + 1]; n + 1];
    for i in 0..n {
        let (a, i_a) = pv[i];
        for l in 0..i + 1 {
            let r = n - (i - l) - 1; // (i - l) 個が既に右側に配置されている
            chmax!(dp[i + 1][l + 1], dp[i][l] + a * (i_a - l as i64).abs());
            chmax!(dp[i + 1][l], dp[i][l] + a * (i_a - r as i64).abs());
        }
    }

    let ans = dp[n].iter().max().unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 33416
#include <bits/stdc++.h>
using namespace std;
 
//krishrawat
 
 
//----------------------------MACROS-------------------------------------------------
#define pb insert//                                                                 |
#define eb emplace_back//                                                           |
#define ff first//                                                                  |
#define ss second//                                                                 |
typedef long long int ll;//                                                         |
typedef long double ld;//                                                           |
#define all(a) a.begin(), a.end()//                                                 |
#define show(x) cerr << #x << " is " << x << "\n"//                                 |
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"//       |
typedef vector<ll> vl;//                                                            |
typedef vector<vl> vvl;//                                                           |
typedef pair<ll, ll> pp;//                                                          |
typedef vector<pp> vp;//                                                            |
typedef map<pp, ll> ipi;//                                                          |
typedef map<pp, char> ipc;//                                                        |
typedef map<ll, ll> ii;//                                                           |
typedef set<ll> sl;//                                                               |
typedef multiset<ll> msl;//                                                         |
typedef map<char, ll> ci;//                                                         |
typedef set<pair<ll, ll>> sp;//                                                     |
const ll mod = 1e9 + 7;//                                                           |
const ll N = 2e5 + 1;//                                                             |
//----------------------------------------------------------------------------------


void solve()
{   
    ll n;cin>>n;
    vl v(n);
    for(auto &i:v) cin>>i;
    ll k=v[n-1];
    k*=2;
    for(int i=0;i<n-1;i++){
        k=v[i]*2-k;
    }
    k=abs(k);
    k/=4;
    
    vl ans(n);
    ans[n-1]=k*2;
    for(int i=n-2;i>=0;i--){
        ans[i]=(v[i]-k)*2;
        k=(v[i]-k);
    }
    for(auto i:ans) cout<<i<<" ";
}
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    
    ll t; t=1;
    //cin>>t;
    while(t--) solve(); return 0;
}

Measured memory_bytes: 4752
import heapq

n, m = map(int, input().split())
a = [int(i) * (-1) for i in input().split()]
heapq.heapify(a)

for i in range(m):
    tmp = (heapq.heappop(a) * (-1)) // 2
    heapq.heappush(a, tmp * (-1))

print(sum(a) * (-1))


Measured memory_bytes: 14180
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;

int main(){
	int n;
	vector<P> v;

	cin >> n;
	for(int i=0;i<n;i++){
		int a,b;
		cin >> a >> b;
		v.push_back({b,a});
	}

	sort(v.begin(),v.end());

	int t = 0;
	for(int i=0;i<n;i++){
		t += v[i].second;
		if(t>v[i].first){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 2420
output = 'Yay!'
antennas = []
for i in range(5):
    antennas.append(int(input()))
area = int(input())

for i in range(5):
    for j in range(i+1,5):
        if max(antennas[i],antennas[j])-min(antennas[i],antennas[j]) > area:
            output = ':('
            break
    else:
        continue
    break

print(output)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a[5],k;
    for(int i=0;i<5;i++){
    	cin>>a[i];}
    	cin>>k;
    	sort(a,a+5);
		if(a[4]-a[0]>k)
		cout<<":(";
		else 
		cout<<"Yay!";}    	

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
   ll n,k; cin>>n>>k;
   n%=k; cout<<min(n,k-n)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;

int main()
{
    int W,H,x,y,r;

    cin >> W >> H >> x >> y >> r;

    if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=100005;
int n,X,val,p[N];
struct Ask{
	int x,l,r;
}A[N];
inline int F(Ask x,int y){
	if (y>=x.x)return x.r*y-x.x*(x.r-x.l);
	return y*x.l;
}
inline int cmp(Ask x,Ask y){
	return F(x,X)>F(y,X);
}
inline int check(int x){
	int t1=x%X,t2=x/X,ans=p[t2];
	for (int i=1;i<=t2;i++)ans=max(ans,p[t2+1]-F(A[i],X)+F(A[i],t1));
	for (int i=t2+1;i<=n;i++)ans=max(ans,p[t2]+F(A[i],t1));
	return ans>=val;
}
signed main(){
	scanf("%lld%lld",&n,&X);
	for (int i=1;i<=n;i++)scanf("%lld%lld%lld",&A[i].x,&A[i].l,&A[i].r),val+=A[i].x*A[i].l;
	sort(A+1,A+n+1,cmp);
	int l=0,r=n*X;
	for (int i=1;i<=n;i++)p[i]=p[i-1]+F(A[i],X);
	while (l<r){
		int mid=(l+r)/2;
		if (check(mid))r=mid;
		else l=mid+1;
	}
	printf("%lld\n",l);
}

Measured memory_bytes: 3328
from collections import deque

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    Q = deque([])
    Q.append([0,0])
    dh = [1,0,-1,0]
    dw = [0,1,0,-1]
    d = [[float('inf')] * W for _ in range(H)]
    d[0][0] = 0
    while Q:
        h, w = Q.popleft()
        if h == H - 1 and w == w - 1:
            break
        for i in range(4):
            nh = h + dh[i]
            nw = w + dw[i]
            if 0 <= nh < H and 0 <= nw < W:
                if S[nh][nw] == '.' and d[nh][nw] == float('inf'):
                    d[nh][nw] = min(d[nh][nw], d[h][w] + 1)
                    Q.append([nh,nw])

    if d[H-1][W-1] == float('inf'):
        print(-1)
        exit()
    
    cnt = 0
    for h in range(H):
        for w in range(W):
            if S[h][w] == '.':
                cnt += 1

    print(cnt - d[H-1][W-1] - 1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 74144
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int n, v[20], c[20];
  scanf("%d", &n);
  for(int i = 0; i < n; i++)
  {
    scanf("%d", &v[i]);
  }
  for(int i = 0; i < n; i++)
  {
    scanf("%d", &c[i]);
  }
  
  int ans = 0;
  for(int i = 0; i < n; i++)
  {
    if(v[i] - c[i] > 0)
    {
      ans += v[i] - c[i];
    }
  }
  
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 2e9;
const int MOD = 1e9+7;
const ll LINF = 1LL<<62;

int x[60], y[60];

int main() {
  IOS;

  int n,K;
  cin >> n >> K;
  ll ans = LINF;
  vector<int> x(n),y(n);
  REP(i,n) cin >> x[i] >> y[i];

  REP(i,n) {
    REP(j,n) {
      REP(k,n) {
        REP(l,n) {
          int cnt = 0;
          int lx = min(x[i],x[j]);
          int hx = max(x[i],x[j]);
          int ly = min(y[k],y[l]);
          int hy = max(y[k],y[l]);
          REP(m,n) {
            if (lx <= x[m] && x[m] <= hx && ly <= y[m] && y[m] <= hy) cnt++;
            if (K <= cnt) {
              ans = min(ans, (ll)(hx - lx) * (ll)(hy - ly));
              break;
            }
          }
        }
      }
    }
  }

  COUT(ans);
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int check=0;
bool Plus(int n,int sum){
  if(n==sum){
    check=1;
    return 1;
  }
  if(n<sum) return 0;
  Plus(n,sum+4);
  Plus(n,sum+7);
  return 0;
}
int main(){
  int n;
  cin >> n;
  bool a=Plus(n,0);
  if(check) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter

input = sys.stdin.readline

N = int(input())
D = list(map(int,input().split()))
dmax = max(D)
M = 998244353

if D[0]!=0:
	ans = 0
else:
	D = Counter(D)

	if D[0]!=1:
		ans = 0
	else:
		ans = 1
		for i in range(1,dmax+1):
			if D[i]==0:
				ans = 0
				break
			ans *= D[i-1]**D[i]
			ans = ans%M

print(ans)

Measured memory_bytes: 61988
import math

def main():
    num, hp = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]
    data_a = [data[i][0] for i in range(num)]
    data_b = [data[i][1] for i in range(num)]
    data_a.sort(reverse=True)
    data_b.sort(reverse=True)
    count = 0
    huru = data_a[0]
    nageru_ind = 0
    while hp > 0:
        if nageru_ind == num:
            count += math.ceil(hp / huru)
            break
        elif huru > data_b[nageru_ind]:
            count += math.ceil(hp / huru)
            break
        else:
            hp -= data_b[nageru_ind]
            nageru_ind += 1
        count += 1


    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 68696
#include<iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;

bool judge(VL &s, VL &h, ll x) {
  int n = s.size();
  VL t(n);
  rep(i, n) {
    if (x < h[i]) return false;
    t[i] = (x - h[i]) / s[i];
  }
  sort(all(t));
  rep(i, n) {
    if (t[i] < i) return false;
  }
  return true;
}


int main(){
  ll N, ans;
  cin >> N;
  vector<ll> A(N), B(N), C(N), ab(N+1), bcsum(N+1);

  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  rep(i, N) cin >> C[i];

  sort(all(A));
  sort(all(B));
  sort(all(C));

  ab[N] = 0;
  bcsum[N] = 0;
  for(int i = N-1; i >= 0; i--){
    bcsum[i] = N - distance(C.begin(), upper_bound(C.begin(), C.end(), B[i]));
    bcsum[i] += bcsum[i+1];
  }

  ans = 0;
  rep(i, N){
    ab[i] = distance(B.begin(), upper_bound(B.begin(), B.end(), A[i]));
    ans += bcsum[ab[i]];
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 4224
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A = readline().strip()
    B = readline().strip()
    C = readline().strip()

    A = list(A[::-1])
    B = list(B[::-1])
    C = list(C[::-1])

    P = A
    x = 'a'
    while True:
        if not P:
            if x == 'a':
                print('A')
            elif x == 'b':
                print('B')
            else:
                print('C')
            break
        x = P.pop()
        if x == 'a':
            P = A
        elif x == 'b':
            P = B
        else:
            P = C

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9084
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    long long x[3],k;
    cin>>x[0]>>x[1]>>x[2]>>k;
    sort(x,x+3);
    cout<<x[0]+x[1]+x[2]*pow(2,k)<<endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as	np

N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

reward = []

for i in range(N):
    r =	np.sum(A1[:i+1]) + np.sum(A2[i:])
    reward.append(r)

print(np.max(reward))

Measured memory_bytes: 14408
import java.util.Scanner;
public class Main{
    int n,k;
    int g=0,m=1;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        while(n!=0){
            for(int s=0;s<n;s++){
                k = sc.nextInt();
                if(k>=2){
                    m++;
                }else if(k==1){
                 g++;
                }
            }
            if(m>=2){
                System.out.println(m+g);
            }else{
                System.out.println("NA");
            }
            g=0;
            m=1;
            n=sc.nextInt();
        }
    }
     
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 158452
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

class UnionFind {
    vector<int> par;
    int c;

  public:
    UnionFind(int n) : par(n, -1), c(n) {}
    int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
    int size(int x) { return -par[find(x)]; }
    int count() const { return c; }
    bool same(int x, int y) { return find(x) == find(y); }
    bool unite(int x, int y) {
        if((x = find(x)) == (y = find(y))) return false;
        if(par[x] < par[y]) swap(x, y);
        par[y] += par[x];
        par[x] = y;
        return c--;
    }
};

int n, m;
int a[100009], b[100009], w[100009];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> n >> m;
    rep(i, m) cin >> a[i] >> b[i] >> w[i];

    vector<int> p(m);
    rep(i, m) p[i] = i;
    sort(ALL(p), [&](int a, int b) { return w[a] < w[b]; });

    UnionFind uf(n);

    int sum = 0;
    for(int i : p)
        if(uf.unite(a[i], b[i])) sum += w[i];

    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 4648
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False


def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

n = onem()

num = []

data = [[0 for i in range(50)] for j in range(60)]

base = 9
for i in range(n):
	po = input()[:-1]
	if not "." in po:
		aaa = int(po)
		tw = 0
		while aaa % 2 == 0:
			tw += 1
			aaa //= 2
		fi = 0
		while aaa % 5 == 0:
			fi += 1
			aaa //= 5
		num.append([tw + base,fi + base])
		data[tw + base][fi + base] += 1
	else:
		for j in range(len(po)):	
			if po[-(j+1)] != "0":
				po = po[:len(po)-j]
				break
			if po[-(j+1)] == ".":
				break
		for j in range(len(po)):
			if po[j] == ".":
				size = len(po)-1 - j
				break
		aaa = int(po.replace(".", ""))		
		tw = 0
		while aaa % 2 == 0:
			tw += 1
			aaa //= 2
		fi = 0
		while aaa % 5 == 0:
			fi += 1
			aaa //= 5
		
		num.append([tw-size + base,fi-size + base])
		data[tw-size + base][fi-size + base] += 1


for i in range(60):
	for j in range(49,0,-1):
		data[i][j-1] += data[i][j]


cou = 0
for i in num:
	a,b = i
	base = 9
	if a-base >= 0 and b-base >= 0:
		cou -= 1
	a -= base
	b -= base
	if a > 9:
		a = 9
	if b > 9:
		b = 9
	a *= -1
	a += base
	b *= -1
	b += base
	for j in range(a,60):
		cou += data[j][b]
print(cou//2)



		


Measured memory_bytes: 97200
#include <iostream>
#include <string>

int main(void){
  using namespace std;
  long long a[200000];
  long long sum=0;
  long long n;
  
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
    //cout << a[i];
  }

  for(int i=1;i<n;i++){
    if(a[i-1]>a[i]){
      sum = sum + (a[i-1]-a[i]);
      a[i]=a[i-1];
    }
  }

  cout << sum;
  
}
  

Measured memory_bytes: 5116
#include <bits/stdc++.h>
#define INF (1LL<<60)
#define MOD7 1000000007LL
#define PREP(i, s, x) for(ll i = (s); i < (x); i ++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i --)
#define REP(i, x) PREP(i, 0, x)
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;
template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return 1;}return 0;}

ll llgcd(ll a, ll b){
    if(b == 0)
        return a;
    return llgcd(b, a % b);
}

ll llpow(ll a, ll n){
    ll res = 1;
    while(n > 0){
        if(n & 1)
            res = res * a % MOD7;
        a = a * a % MOD7;
        n >>= 1;
    }
    return res;
}

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    bool flag = true;
    while(true){
        c -= b;
        if(c <= 0){
            flag = true;
            break;
        }

        a -= d;
        if(a <= 0){
            flag = false;
            break;
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
import std.stdio, std.string, std.conv, std.array, std.algorithm;
import std.uni, std.range, std.math, std.container, std.datetime;
import core.bitop;

immutable long MOD = 1_000_000_007;

void main(){
    char[] buf; readln(buf);
    auto input = buf.split.to!(int[]);
    auto N = input[0], K = input[1];
    readln(buf);
    auto D = buf.split;
    int ans = N;

    while(true){
        bool flag = true;
        auto anss = ans.to!string;
        
        foreach(d ; D){
            if(anss.canFind(d)){
                flag = false;
                break;
            }
        }

        if(flag){
            writeln(ans);
            return;
        }

        ++ans;
    }
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int c1 = 0, c2 = 0, c3 = 0;
	for (int i = 0; i < n; ++i) {
		int p;
		cin >> p;
		if (p <= a) c1++;
		else if (p <= b) c2++;
		else c3++;
	}
	cout << min({c1, c2, c3}) << endl;
	return 0;
}

Measured memory_bytes: 3564
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

long long int INF = 1000000000000000000LL; // 10^18
using namespace std;

typedef pair<int, int> P;

string A[1000];

int main(){
	
	int H, W, K;
	cin >> H >> W >> K;
	
	for(int i = 0; i < H; i++){
		cin >> A[i];
	}
	
	queue<P> que;
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(A[i][j] == 'S'){
				P p;
				p.first = i;
				p.second = j;
				que.push(p);
			}
		}
	}
	
	for(int loop = 0; loop <= K; loop++){
		int sz = que.size();
		if(sz == 0){
			break;
		}
		for(int i = 0; i < sz; i++){
			P p = que.front();
			que.pop();
			if(p.first < 0 || p.first >= H || p.second < 0 || p.second >= W){
				continue;
			}
			if(A[p.first][p.second] == 'k' || A[p.first][p.second] == '#'){
				continue;
			}
			A[p.first][p.second] = 'k';
			p.first++;
			que.push(p);
			p.first -= 2;
			que.push(p);
			p.first++;
			p.second++;
			que.push(p);
			p.second -= 2;
			que.push(p);
		}
	}
	
	int ans = 1000;
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(A[i][j] == 'k'){
				int dist = min(min(min(i, j), H - 1 - i), W - 1 - j);
				ans = min(ans, (dist - 1) / K + 2);
				if(dist == 0){
					ans = 1;
				}
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1152