akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

//typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define Se second
#define Fi first
#define rep(i, n) for(int i=0;i<n;i++)
#define pb(x) push_back(x)

int A[100050];

int sum[100050];

int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &A[i]);
	A[0] = A[N + 1] = 0;

	for (i = 1; i <= N + 1; i++) sum[i] = sum[i - 1] + abs(A[i] - A[i - 1]);

	for (i = 1; i <= N; i++) {
		int s = sum[N + 1] - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]);
		s += abs(A[i - 1] - A[i + 1]);
		printf("%d\n", s);
	}
	return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>
int main(){
int i,n;
double a[2],b[2],c[2],d[2];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a[0],&a[1],&b[0],&b[1],&c[0],&c[1],&d[0],&d[1]);
if((b[1]-a[1])*(d[0]-c[0])==(b[0]-a[0])*(d[1]-c[1]))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
    string s, t;
    cin >> s >> t;

    int N = s.size();
    int M = t.size();

    int sa[N + 1] = {};
    int sb[N + 1] = {};
    int ta[M + 1] = {};
    int tb[M + 1] = {};

    for(int i = 0; i < N; i++){
        sa[i + 1] = sa[i];
        sb[i + 1] = sb[i];
        if(s[i] == 'A') sa[i + 1]++;
        if(s[i] == 'B') sb[i + 1]++;
    }

    for(int i = 0; i < M; i++){
        ta[i + 1] = ta[i];
        tb[i + 1] = tb[i];
        if(t[i] == 'A') ta[i + 1]++;
        if(t[i] == 'B') tb[i + 1]++;
    }

    int Q;
    cin >> Q;

    vector<string> ans;

    for(int i = 0; i < Q; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;

        int x = ((sa[b] - sa[a - 1]) % 3) - ((sb[b] - sb[a - 1]) % 3);
        int y = ((ta[d] - ta[c - 1]) % 3) - ((tb[d] - tb[c - 1]) % 3);
        x += 3;
        y += 3;
        x %= 3;
        y %= 3;

        if(x == y){
            ans.push_back("YES");
        } else {
            ans.push_back("NO");
        }
    }

    for(string s : ans){
        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 7796
#include<iostream>
#include<cctype>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main(){
    int n,m,Max=m;
    cin>>n>>m;
    bool eFlag=false;
    while(n--){
        int in,out;
        cin>>in>>out;
        m=m-out+in;
        Max=max(m,Max);
        if(m<0)eFlag=true;
    }
    if(eFlag)cout<<0<<endl;
    else cout<<Max<<endl;
}

Measured memory_bytes: 1164
def main():
    W, H, N = map(int, input().split())
    area = [[0 for w in range(W)] for h in range(H) ]

    for n in range(N):
        x, y, a = map(int, input().split())
        
        if a == 1 :
            for i in range(H):
                for j in range(x):
                    area[i][j] = 1
            # dump(area, H, W)
                    
        elif a == 2:
            for i in range(H):
                for j in range(x, W):
                    area[i][j] = 1
            # dump(area, H, W)

        elif a == 3:
            for i in range(H - y, H):
                for j in range(W):
                    area[i][j] = 1
            # dump(area, H, W)
            
        elif a == 4:
            for i in range(H - y):
                for j in range(W):
                    area[i][j] = 1
            # dump(area, H, W)
    count = 0

    for i in range(H):
        for j in range(W):
            if area[i][j] == 0:
                count += 1
    print(count)

def dump(area, H, W):
    for i in range(H):
        for j in range(W):
            print(str(area[i][j]) + " ", end="")
        print()

main()

Measured memory_bytes: 3192
#include<stdio.h>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
  int n,h;
  int *a, *b;
  int maxa=0,maxa_num=0,maxa_b;
  int sum=0,num;

  scanf("%d %d", &n, &h);
  a = new int[n];
  b = new int[n];
  for(int i=0;i<n;++i){
    scanf("%d %d", &a[i], &b[i]);
  }
  for(int i=0;i<n;++i){
    if(a[i] > maxa){
      maxa = a[i];
      maxa_num = i;
    }
  }
  maxa_b = b[maxa_num];
  sort(a, a+n, greater<int>());
  sort(b, b+n, greater<int>());
  for(num=0;num<n;++num){
    sum += b[num];
    if(sum >= h){
      printf("%d\n",num+1);
      return 0;
    }
    if(b[num+1] < maxa){
      ++num;
      break;
    }
  }
  sum -= maxa_b;
  int sagyou = h-sum-maxa_b;
  if(sagyou%maxa){
    printf("%d\n", num + sagyou / maxa + 1);
  }else{
    printf("%d\n", num + sagyou / maxa);
  }
  delete [] a;
  delete [] b;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#define N 36
#define False 0
#define True 1

typedef struct  {
  char picture[3];
  int value;
} cards;

void BubbleSort(cards *C, int n) {
  int i, j;
  cards tmp;

  for(i = 0; i < n; i++) {
    for(j = n-1; j > i; j--) {
      if(C[j].value < C[j-1].value) {
        tmp = C[j];
        C[j] = C[j-1];
        C[j-1] = tmp;
      }
    }
  }
  for(i = 0; i < n; i++) {
    if(i > 0) printf(" ");
    printf("%s", C[i].picture);
  }
  printf("\n");
}

void SelectionSort(cards *C, int n) {
  int i, j, mini;
  cards tmp;

  for(i = 0; i < n; i++) {
    mini = i;
    for(j = i; j < n; j++) {
      if(C[j].value < C[mini].value) mini = j;
    }
    tmp = C[i];
    C[i] = C[mini];
    C[mini] = tmp;
  }

  for(i = 0; i < n; i++) {
    if(i > 0) printf(" ");
    printf("%s", C[i].picture);
  }
  printf("\n");
}

int isStable(cards *A, cards *B, int n) {
  int i, j, a, b;

  for(i = 0; i < n; i++) {
    for(j = i+1; j < n; j++) {
      for(a = 0; a < n; a++) {
        for(b = a+1; b < n; b++) {
          if(A[i].value == A[j].value && strcmp(A[i].picture, B[b].picture) == 0
            && strcmp(A[j].picture, B[a].picture) == 0)
          return False;
        }
      }
    }
  }
  return True;
}



int main() {
  int i, j, n;
  cards C[N], C1[N], C2[N];

  scanf("%d",&n);
  for(i = 0; i < n; i++) {
    scanf("%s", C[i].picture);
    C[i].value = C[i].picture[1] - 48;
    strcpy(C1[i].picture, C[i].picture);
    strcpy(C2[i].picture, C[i].picture);
    C1[i].value = C[i].value;
    C2[i].value = C[i].value;
  }

  BubbleSort(C1, n);
  if(isStable(C, C1, n) == False) printf("Not stable\n");
  else printf("Stable\n");
  SelectionSort(C2, n);
  if(isStable(C, C2, n) == False) printf("Not stable\n");
  else printf("Stable\n");

  return 0;
}

Measured memory_bytes: 628
#!/usr/bin/env ruby

n, x = gets.chomp.split(/ /).map(&:to_i)
l = []
l = gets.chomp.split(/ /).map(&:to_i)

c = 1
loc = 0
l.each do |i|
  if loc + i <= x
    c +=1
    loc += i
  else
    break
  end
end
puts c


Measured memory_bytes: 1788
#!/usr/bin/env python3
import sys


def solve(X: int, N: int, p: "List[int]"):
    sp = set(p)
    ans = min((i for i in range(-1, 107) if i not in sp), key=lambda x:abs(x-X))
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;
int n, m;
long long a[maxn], b[maxn], deg[maxn];
inline int read() {
	int x; scanf("%d", &x); return x;
}
int main() {
	#ifdef LOCAL
		freopen("1.in", "r", stdin);
	#endif
	char c; scanf("%c", &c);
	if (c >= 'a' && c <= 'z') puts("a");
	else puts("A"); 
	return 0; 
}	

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1010;
char grid[MAXN][MAXN];
int dp[MAXN][MAXN];
int n, m;
int main()
{
 	cin >> n >> m;
 	for (int i = 1; i <= n; i++)dp[0][i] = '#';
 	for (int i = 1; i <= m; i++)dp[i][0] = '#';
 	for (int i = 1; i <= n; i++)
 		for (int j = 1; j <= m; j++)
 			cin >> grid[i][j];
 	memset(dp, 0, sizeof(dp));
 	dp[1][1] = 1;
 	for (int i = 1; i <= n; i++)
 		for (int j = 1; j <= m; j++) {
 			if (grid[i - 1][j] == '.'){
 				dp[i][j] += dp[i - 1][j];
 				dp[i][j] %= MOD;
			}
			if (grid[i][j - 1] == '.') {
				dp[i][j] += dp[i][j - 1];
				dp[i][j] %= MOD;
			}
		}
	cout << dp[n][m] % MOD << endl;
	return 0;
}



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

typedef long long ll;

#define int ll

typedef pair<int, int> ii;

const int N = 2e5+100, M = 58, INF = 5e17;

int ls[N], a[N];

ii go[N][M];

int run(int it, int &cnt){
	for(int lg=M-1 ; lg>=0 ; lg--){
		if(go[it][lg].second > cnt)
			continue;
		cnt -= go[it][lg].second;
		it = go[it][lg].first;
		lg = M;
	}
	return it;
}

signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int n, k;cin >> n >> k;
	for(int i=0 ; i<n ; i++)
		cin >> a[i];
	for(int i=n-1 ; i>=0 ; i--)
		ls[a[i]] = i;
	for(int i=n-1 ; i>=0 ; i--){
		int ind = ls[a[i]];
		ls[a[i]] = i;
		go[i][0].first = (ind+1)%n;
		go[i][0].second = (ind>i ? ind-i : ind-i+n) + 1;
	}

	for(int lg=1 ; lg<M ; lg++)
		for(int i=0 ; i<n ; i++){
			go[i][lg].first = go[ go[i][lg-1].first ][lg-1].first;
			go[i][lg].second = go[ go[i][lg-1].first ][lg-1].second + go[i][lg-1].second;
			if(go[i][lg].second > INF)
				go[i][lg].second = INF;
		}

	int cnt = n*k;
	int it = run(0, cnt);
	vector<int> ans;
	multiset<int> st;
	for(int i=0 ; i<cnt ; i++){
		int cur = a[(i+it)%n];
		bool f = true;
		while(st.count(cur)){
			f = false;
			st.erase(st.find(ans.back()));
			ans.pop_back();
		}
		if(f){
			ans.push_back(cur);
			st.insert(cur);
		}
	}
	for(int i=0 ; i<ans.size() ; i++)
		cout << ans[i] << " \n"[i == ans.size()-1];
 	return 0;
}
















Measured memory_bytes: 196976
from operator import itemgetter

N= int(input())

AB = [list(map(int,input().split())) for _ in range(N)]

AB.sort(key=itemgetter(1))

ans = 'Yes'
t = 0

for a, b in AB:
    if t+a <= b: t += a
    else:
        ans='No'
        break

print(ans)



Measured memory_bytes: 53732
#include<iostream>
#include<algorithm>
#include<math.h>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define ll long long 

 



int main() {

	string x;
	cin>>x;
	for(int i = 0; i < x.length(); i++) {
		if(x[i] == '?') {
			x[i] = 'D';
		}
	}
      
     cout<<x<<endl;
  
}

Measured memory_bytes: 3716
def main():
    _ = int(input())
    a = [int(i) for i in input().split()]
    if 0 in a:
        print(0)
        return
    a.sort()

    limit = 10**18
    result = 1
    for i in a[::-1]:
        result *= i
        if result > limit:
            print(-1)
            return
    print(result)

main()


Measured memory_bytes: 21708
A,B,C,D = map(int,input().split())
MOD = 998244353
dp = [[0]*D for i in range(C)]
dp[A-1][B-1] = 1

for i in range(C):
    for j in range(D):
        if i!=A-1 or j!=B-1:
            val1 = dp[i-1][j]*(j+1)
            if i==0:
                val1 = 0
            val2 = dp[i][j-1]*(i+1)
            if j==0:
                val2 = 0
            val3 = 0
            if val1*val2!=0:
                val3 = i*j
            dp[i][j] = (val1+val2 - val3*dp[i-1][j-1])%MOD
            #dp[i][j] = (dp[i-1][j]*(j+1) + dp[i][j-1]*(i+1) - i*j)%MOD
# print(dp)
print(dp[C-1][D-1])



Measured memory_bytes: 139056
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int k;
  scanf("%d", &k);
  
  int max = max(a, max(b, c));
  int sum = a + b + c - max;
  rep(i, 0, k) {
    max *= 2;
  }
  int ans = sum + max;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>

#define reep(i,n,m) for(int i=(n);i<(m);i++)
#define rep(i,n) reep(i,0,n)

using namespace std;

typedef long long int ll;

ll dp[5][4001];

int main(){
    dp[0][0] = 1;
    reep(j,1,5){
        rep(i,1001){
            reep(k,i,4001){
                dp[j][k] += dp[j-1][k-i];
            }
        }
    }

    int n;
    while(scanf("%d",&n)!=EOF){
        cout << dp[4][n] << endl;
    }
    return 0;
}

Measured memory_bytes: 1336
/*
 Author: Alokit Kumar
 */
 #include<bits/stdc++.h>
 using namespace std;
 #define int long long
 int32_t main()
 {
   int t,n,i,j,k,l=0,m=1,s,s1=0;
   cin>>n;
   for(i=1;i<=n;i++)
   {
     j=n/i;
     s=(j*(j+1)*i)/2;
     s1+=s;
   }
   cout<<s1;
 }


Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define debug(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define debug(...) 
#define end_time()
#endif
 
 
#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
inline int gcd(int a, int b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); } 
inline int power(int x, int n, int m = LLONG_MAX)
    {  int res=1; x = (x%m + m)%m;
       while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
    }
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007

void solve(){
	ld x;
	cin>>x;
	int p = 100;
    for(int i = 1; i<=4000; i++){
    	p*=(1.01);
    	if(p>=x){
			cout<<i<<"\n";
			return;
		}	
    }
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;++i) {
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	end_time();
	return 0;
}


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

int main(){
	int a,b,c;
	int ans;
	
	string cunning="776755555";
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		if(i<cunning.size()){
			cout<<cunning[i]<<endl;
			continue;
		}
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

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

void solve(void) {
  string str; cin >> str;
  int res = 0;

  int left = 0, right = (int)str.size()-1;
  while (right -left >= 0) {
    if (str[left] != str[right]) res++;
    left++; right--;
  }
  cout << res << endl;
}
int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key)
{
	int left = 0;
	int right = n;
	int mid;
	while ( left < right ){
		mid = (left + right) / 2;
		if ( key == A[mid] ) return 1;
		if ( key > A[mid] ) left = mid + 1;
		else if ( key < A[mid] ) right = mid;
	}
	return 0;
}

int main(){
	int i, q, k, sum = 0;
	scanf("%d", &n);
	for( i = 0; i < n; i++ ){
		scanf("%d", &A[i]);
	}
	
	scanf("%d", &q);
	for( i = 0; i < q; i++){
		scanf("%d", &k);
		if ( binarySearch( k ) ) sum++;
	}
	printf("%d\n", sum);
	
	return 0;
}	


Measured memory_bytes: 2108
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

bool cmp(pair<int, int> x, pair<int, int> y) {
  return y.F * x.S + y.S < x.F * y.S + x.S;
}

const int N = 2e5 + 10;
const int L = 32;
int dp[N][L];

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, t;
  cin >> n >> t;
  vector<pair<int, int>> kek;
  vector<int> lst;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a++;
    b += a;
    if (a == 1) {
      lst.pb(b);
    }
    else {
      kek.pb({a, b});
    }
  }
  sort(all(lst));
  sort(all(kek), cmp);
  dp[0][0] = 0;
  for (int i = 1; i < L; i++) {
    dp[0][i] = t + 1;
  }
  for (int i = 1; i <= SZ(kek); i++) {
    dp[i][0] = 0;
    for (int j = 1; j < L; j++) {
      dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] * kek[i - 1].F + kek[i - 1].S);
    }
  }
  int ans = 0;
  for (int i = 0; i < L; i++) {
    int sum = dp[SZ(kek)][i], cur = i;
    if (dp[SZ(kek)][i] > t) {
      continue;
    }
    for (int j = 0; j < SZ(lst); j++) {
      if (sum + lst[j] <= t) {
        sum += lst[j];
        cur++;
      }
    }
    ans = max(ans, cur);
  }
  cout << ans << '\n';
} 

Measured memory_bytes: 54124
#include <stdio.h>
int main(void){
  int r,c,i,j;
  scanf("%d%d",&r,&c);
  int a[101][101]={};
  for(i=0;i<r;i++){
      for(j=0;j<c;j++){
          scanf("%d",&a[i][j]);
          a[i][c]+=a[i][j];
          a[r][j]+=a[i][j];
          a[r][c]+=a[i][j];
          
        }
  }
  for(i=0;i<=r;i++){
      printf("%d",a[i][0]);
      for(j=1;j<=c;j++){
          
          printf(" %d",a[i][j]);
          
      }
      printf("\n");
  }
  
    return 0;
}

Measured memory_bytes: 2724
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i< N; i++) {
			list.add(Integer.parseInt(sc.next()));
		}
		sc.close();

		Collections.sort(list, Collections.reverseOrder());
		int diff = list.get(0) - list.get(N - 1);
		System.out.println(diff);
	}

}

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

int main(){
string S; cin >> S;
int ans = 0;
int tmp = 0;
for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
        tmp++;
    }
    else {
        tmp = 0;
    }
    ans = max(ans, tmp);
}

cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin>>n;
  VEC<int> a(n);
  REP(i,0,n){
    cin>>a[i];
  }
  bool even =1;
  LL cnt = 0;
  do{
    REP(i,0,n){
      even=even&(a[i]%2==0);
      if(even)a[i]/=2;
    }
    if(even)++cnt;
  }while(even);
  cout<<cnt<<endl;


  return 0;
}


Measured memory_bytes: 256
import math
N,a,b=(int(x) for x in input().split())
if abs(a-b)%2==0:
    print(abs(a-b)//2)
else:
    c1=a-1+1+(b-a)//2
    c2=N-b+1+(b-a)//2
    print(min(c1,c2))


Measured memory_bytes: 2940
read
tr ' ' '\n'|awk 'function a(x){return x<0?-x:x}{b[NR]=$0}END{for(i=1;i<NR;i++)s+=a(b[i]-b[i+1]);s+=a(b[1])+a(b[NR]);print s-a(b[1])-a(b[1]-b[2])+a(b[2]);for(i=2;i<NR;i++)print s-a(b[i-1]-b[i])-a(b[i]-b[i+1])+a(b[i-1]-b[i+1]);print s-a(b[NR-1]-b[NR])-a(b[NR])+a(b[NR-1])}'

Measured memory_bytes: 9072
import math
n,k=map(int,input().split())
n_lis=[int(i) for i in range(1,n+1)]
p=float(1/n)
p_lis=[]
for i in range(n):
    if n_lis[i]<k:
        atai=float(k/n_lis[i])
        kaisu=-(-math.log(atai,2)//1) # loop処理しなくてよいので記述が楽
        p_lis.append((1/2)**(kaisu))
    else:
        p_lis.append(1)

print(p*sum(p_lis))

Measured memory_bytes: 7832
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
  #define pb push_back
#define f first
#define s second
  #define MAXN 100005
using namespace std;
int arr[MAXN];
int main()
{
	std::ios::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	ll u,v;
	ll ans=0;
	for(int i=0; i<n; i++) {
		cin>>u>>v;
		ans+=min(u/a,v/b);
	}

	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import re
s = input()
a = []
a += [re.match(r'.*keyence$', s)]
a += [re.match(r'k.*eyence$', s)]
a += [re.match(r'ke.*yence$', s)]
a += [re.match(r'key.*ence$', s)]
a += [re.match(r'keye.*nce$', s)]
a += [re.match(r'keyen.*ce$', s)]
a += [re.match(r'keyenc.*e$', s)]
a += [re.match(r'keyence.*$', s)]
print('YES' if any(a) else 'NO')

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

int main() {
    vector<vector<int>> bingo(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> bingo[i][j];
        }
    }
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int b;
        cin >> b;
        for (int j = 0; j < 3; j++) {
            replace(bingo.at(j).begin(), bingo.at(j).end(), b, -1);
        }
    }
    bool isb = false;
    if ((bingo[0][0] == -1) && (
        (bingo[0][1] == -1 && bingo[0][2] == -1) ||
        (bingo[1][0] == -1 && bingo[2][0] == -1) ||
        (bingo[1][1] == -1 && bingo[2][2] == -1))) {
        isb = true;
    } else if ((bingo[1][1] == -1) && (  
        (bingo[0][1] == -1 && bingo[2][1] == -1) ||
        (bingo[1][0] == -1 && bingo[1][2] == -1) ||
        (bingo[0][2] == -1 && bingo[2][0] == -1))) {
        isb = true;
    } else if ((bingo[2][2] == -1) && (
        (bingo[2][0] == -1 && bingo[2][1] == -1) ||
        (bingo[0][2] == -1 && bingo[1][2] == -1))) {
        isb = true;
    }
    cout << (isb ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3612
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, h) rep(j, w) cin >> a[i][j];

  vector<int> x, y, xp, yp;
  rep(i, h - 1) rep(j, w) {
    if(a[i][j] % 2) {
      a[i][j]--;
      a[i + 1][j]++;
      y.push_back(i + 1);
      x.push_back(j + 1);
      yp.push_back(i + 2);
      xp.push_back(j + 1);
    }
  }
  rep(j, w - 1) {
    if(a[h - 1][j] % 2) {
      a[h - 1][j]--;
      a[h - 1][j + 1]++;
      y.push_back(h);
      x.push_back(j + 1);
      yp.push_back(h);
      xp.push_back(j + 2);
    }
  }
  int n = y.size();
  cout << n << endl;
  rep(i, n) {
    cout << y[i] << ' ';
    cout << x[i] << ' ';
    cout << yp[i] << ' ';
    cout << xp[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 5224
#include<stdio.h>
#include<stdlib.h>
 
int main()
{
long int a,b,s;
scanf("%ld %ld", &a, &b);
    if((a%2!=0 && b%2==0)||(a%2==0 && b%2!=0))
{
     printf("IMPOSSIBLE\n");
}
else
{
         s=((a+b)/2);
   printf("%ld\n",s);
}
 
    return 0;
    getch();
}

Measured memory_bytes: 128
#ABC124 D-Handstand
n,k = map(int,input().split())
s = []
count = 0
last = 1
for i in input():
    if i=='1':
        if last==1:
            count+=1
        else:
            s.append(count)
            count=1
        last = 1
    else:
        if last==0:
            count+=1
        else:
            s.append(count)
            count=1
        last = 0
s.append(count)
if last==0:
    s.append(0)

k = min(k,len(s)//2)
ans = 0

for j in range(len(s)//2-k+1):
    if j==0:
        now = sum(s[:k*2+1])
        ans = now
    else:
        now = now-s[j*2-1]-s[j*2-2]+s[(j+k)*2]+s[(j+k)*2-1]
        ans = max(ans,now) 
print(ans)

Measured memory_bytes: 10152
n, k = gets.split.map(&:to_i)
name = []
time = []

n.times{|i|
    name[i], time[i] = gets.split
}

time = time.map(&:to_i)

t = 0

finished_name = []
finished_time = []

while name.length > 0
    if time[0] <= k
        finished_name.push(name[0])
        finished_time.push(t + time[0])
        t = t + time[0]
        name.shift
        time.shift
    else
        x = name.shift
        name.push(x)
        time[0] -= k
        x = time.shift
        time.push(x)
        t += k
    end
end

n.times{|i|
    printf("%s %d\n", finished_name[i], finished_time[i])
}


Measured memory_bytes: 13288
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int k=gi();
	    int a=gi();
	    int b=gi();
	    
	    int w=b%k;

	    //System.out.print(nr*2*Math.PI);
	    if (b-w>=a) {
	    	System.out.print("OK");
	    }else {
	    	System.out.print("NG");
	    }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

using namespace std;

vector<vector<pair<int, int>>> edges;
vector<int> colors;

void dfs(int cur) {
  auto& nexts = edges[cur];
  for (auto next : nexts) {
    if (colors[next.first] == -1) {
      colors[next.first] = next.second ^ colors[cur];
      dfs(next.first);
    }
  }
}

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

  int N;
  cin >> N;

  edges.resize(N);
  for (int i = 1; i < N; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    edges[--u].emplace_back(--v, w % 2);
    edges[v].emplace_back(u, w % 2);
  }
  colors.resize(N, -1);
  colors[0] = 0;

  dfs(0);

  for (auto color : colors) {
    cout << color << endl;
  }
}


Measured memory_bytes: 7424
using System;
using System.Collections.Generic;
using System.Linq;

class Pg
{
    static void Main()
    {
        Read0100().ToList().ForEach(delegate (IEnumerable<IEnumerable<int>> Data)
        {
            var ans =Data.GroupBy(x => x.First())
            .Where(g => g.Sum(x => x.Skip(1).First() * x.Last()) >= 1000000)
            .Select(x => x.Key);
            Console.WriteLine(ans.Count() != 0 ? string.Join("\n", ans) : "NA");
        });
    }
    private static IEnumerable<IEnumerable<IEnumerable<int>>> Read0100()
    {
        int n;
        while ((n = int.Parse(Console.ReadLine())) != 0)
        {
            var selllst = new List<IEnumerable<int>>();
            while (n-- > 0)
                selllst.Add(Console.ReadLine().Split().Select(int.Parse));
            yield return selllst;
        }
    }
}


Measured memory_bytes: 16528
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 




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

ll cnt1[61];

int main() {
    ll n; cin >> n;
    rep(i, 0, n){
        ll a; cin >> a;
        bitset<60> s(a);
        rep(i, 0, 60){
            if(s.test(i)) cnt1[i]++;
        }
    }
    ll ans = 0;
    rep(i, 0, 60){
        ans += ((cnt1[i]*(n-cnt1[i])%MOD)*((1LL<<i)%MOD))%MOD;
        ans %= MOD;
    }
    co(ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FastRead;        ios_base::sync_with_stdio(0);cin.tie(NULL);
#define pb               push_back
#define mp               make_pair
#define F                first
#define S                second
#define ll               long long 
using namespace std;

const int N = 1e5+10;
ll int DP[N];

int main() {
    
    FastRead;
    ll int W, N, w, v; 
    cin >> N >> W;
    
    for(int j = 0; j < N; ++j){
        cin >> w >> v;
        
        for(int i = W; i >= w; --i){
            DP[i] = max(DP[i], DP[i-w]+v);
        }
    }
    cout << DP[W];
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int N;
	cin >> N;

	double sum = 0.0;
	for (int i = 0; i < N; i++) {
		double a;
		cin >> a;
		sum += 1.0 / a;
	}
	cout << 1.0 / sum << endl;
}


Measured memory_bytes: 3768
#include <stdio.h>
#include <math.h>

int main(){
    int n;

    while(1){
        scanf("%d",&n);
        if(n==0)
            break;
        
        double x[n];
        double sum=0;
        double sum_h=0;
        double average;
        
        for(int i=0;i<n;i++){
            scanf("%lf",&x[i]);
            sum+=x[i];
        }
        
        average = sum / n;
        
        for(int i=0;i<n;i++){
            sum_h += pow((x[i]-average),2);
        }
        printf("%f\n",sqrt(sum_h/n));
    }
}


Measured memory_bytes: 2028
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll n3 = n*3;
    vll a(n3);
    REP(i,n3){
        cin >> a[i];
    }
    vll mae(n+1);
    priority_queue<ll,vector<ll>, greater<ll> > pq1;
    REP(i,n){
        mae[0]+=a[i];
        pq1.push(a[i]);
    }
    REP(i,n){
        ll now = pq1.top();
        if(a[n+i]<=now){
            mae[i+1]=mae[i];
        }else{
            pq1.pop();
            pq1.push(a[n+i]);
            mae[i+1]=mae[i]+a[n+i]-now;
        }
    }
    vll usi(n+1);
    priority_queue<ll> pq2;
    REP(i,n){
        usi[0]+=a[n3-1-i];
        pq2.push(a[n3-1-i]);
    }
    REP(i,n){
        ll now = pq2.top();
        if(a[n*2-1-i]>=now){
            usi[i+1]=usi[i];
        }else{
            pq2.pop();
            pq2.push(a[n*2-1-i]);
            usi[i+1]=usi[i]+a[n*2-1-i]-now;
        }
    }
    ll ans = mae[0]-usi[n];
    for(int i=1;i<=n;i++){
        ans = max(ans,mae[i]-usi[n-i]);
    }
    cout << ans << endl;

    return 0;
}

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

long long t = 10;
long long ans;

int main() {
  long long  n;
  cin >> n;
  if (n & 1)
  	return cout << 0 << '\n', 0;
  while (t <= n) {
    ans += (n / t);
    t *= 5;
  }
  cout << ans << '\n';
 	return 0; 
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <functional>
#include <cmath>
#define SIZE 12

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

bool use[SIZE];

bool ok(int n)
{
	while(n>0)
	{
		if(use[n%10]) return false;
		n/=10;
	}
	return true;
}
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=0;i<k;i++)
	{
		int d;
		scanf("%d",&d);
		use[d]=true;
	}
	while(!ok(n)) n++;
	printf("%d\n",n);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; }

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int main(){
    int a, b;
    cin >> a >> b;
    if(b%a){
        cout << b - a << endl;
    }else{
        cout << b + a << endl;
    }
}



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

int main(){
    /*
    1+2+3...+tの合計値が初めてxを超える時を求めれば良い。
    ぴったりじゃなくとも超えた分の時間を飛ばなかったことにすれば良い。
    */
    ll x;
    cin >> x;
    ll t = 1;
    while(x > t*(t+1)/2){
        t ++;
    }
    cout << t << endl;
}

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

int main() {

	double l;
	cin >> l;

	double ans;
	ans = pow(l,3);
	ans = ans / 27;

	cout << fixed << setprecision(6);
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<queue>
#include<vector>

const int INF = 1e9 + 7;
int distance[500005][3];

int main(void){
    int n, m;
    std::cin >> n >> m;
    std::vector<std::vector<int>> edge(n);
    std::queue<std::pair<int, int>> q;
    for(int i = 0; i < m; i++){
        int u, v;
        std::cin >> u >> v;
        u--;
        v--;
        edge[u].push_back(v);
    }
    int s, t;
    std::cin >> s >> t;
    s--;
    t--;

    for(int i = 0; i < 500005; i++){
        for(int j = 0; j < 3; j++){
            distance[i][j] = INF;
        }
    }

    q.push(std::make_pair(s, 0));
    distance[s][0] = 0;
    while(!q.empty()){
        int now_n = q.front().first;
        int now_l = q.front().second;
        for(int next_n : edge[now_n]){
            int next_l = (now_l + 1) % 3;
            if(distance[next_n][next_l] != INF){
                continue;
            }
            distance[next_n][next_l] = distance[now_n][now_l] + 1;
            q.push(std::make_pair(next_n, next_l));
        }
        q.pop();
    }
    int ans = distance[t][0];
    if(ans == INF){
        ans = -1;
    }else{
        ans /= 3;
    }
    std::cout << ans << std::endl;
    return 0;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    VSORT(a);
    int ans = a.back() - a.front();
    cout << ans << endl;
    return 0;
}


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

const int mod = 1000000007;

int N;
bool a[21][21];
int dp[1 << 21];

int main() {
    cin >> N;
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            cin >> a[i][j];

    dp[0] = 1;
    for(int S = 1; S < 1 << N; S++) {
        int i = __builtin_popcount(S);
        for(int j = 0; j < N; j++) {
            if(S >> j & 1 && a[i - 1][j] == 1) {
                dp[S] += dp[S ^ 1 << j];
                dp[S] %= mod;
            }
        }
    }

    cout << dp[(1 << N) - 1] << endl;

    return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <thread>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int a,b;
    cin >> a >> b;
    string s;
    rep(i,a)rep(j,b){
        cin >> s;
        if(s=="snuke"){
            cout << char('A'+j) << i+1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define int long long
using namespace std;
const long long maxn = 1000100, mod = 1e9 + 7, maxa = 3e6 + 100, maxb = 23, base = 737, base2 = 3079, mod2 = 242121643;
const long long inf = 2e18 + 13;
long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}

long long h[maxn];
bool visited[maxn];
vector <int> v[maxn];

void bfs(int x)
{
    queue <int> q;
    q.push(x);
    visited[x] = 1;
    while(q.size())
    {
        x = q.front();
        q.pop();
        for(auto u : v[x])
        {
            if(!visited[u])
            {
                visited[u] = 1;
                h[u] = h[x] + 1;
                q.push(u);
            }
        }
    }
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    bfs(0);
    cout << (h[n - 1] == 2 ? "POSSIBLE" : "IMPOSSIBLE") << endl;  
    return 0;
}












Measured memory_bytes: 35560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
#define PI 3.14159265359
#define dij priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>
typedef long long ll;
//
int main(){
  ll n,w;cin>>n>>w;
  vector<vector<ll>> v(n,vector<ll>(2));
  rep(i,n)cin>>v[i][0]>>v[i][1];
  vector<vector<ll>> dp(n,vector<ll> (w+1));
  rep(i,w+1){
    if(v[0][0]>i)dp[0][i]=0;
    else dp[0][i]=v[0][1];
  }
  rep(i,n-1){
    rep(j,w+1){
      if(j-v[i+1][0]>=0)dp[i+1][j]=max(dp[i][j],dp[i][j-v[i+1][0]]+v[i+1][1]);
      else dp[i+1][j]=dp[i][j];
    }
  }
  // rep(i,n){
  //   rep(j,w+1)cout<<dp[i][j]<<" ";
  //   cout<<endl;
  // }
  cout<<dp[n-1][w]<<endl;;
}

Measured memory_bytes: 82468
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  vi v(3);

  rep(i,3)
  {
    cin >> v[i];
  }

  vsort(v);

  if( v[2] == v[1] + v[0])
    cout << "Yes" ;
  else
  {
    cout << "No";
  }
  
  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long 
int main(){
   	lli n,i,j,c=0,s=0;
	cin >> n;
    lli arr[n-1];
    lli brr[1000001]={0};
    for(i=0;i<n-1;i++) cin >> arr[i];
    unordered_map<lli, lli> m;
    for(i=0;i<n-1;i++)
    {
    	m[arr[i]]++;
    }
    for(auto it :m)
    {
    	brr[it.first]=it.second;
    }
    for(i=1;i<=n;i++)
    {
    	cout << brr[i] << endl;
    }
 
    return 0;
}

Measured memory_bytes: 20748
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
  "math/rand"
  "math/big"
  "time"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)
	
  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())
  cnt := 0
  for i := 0; i < n; i++ {
    sc.Scan()
    m, _ := strconv.Atoi(sc.Text())
    if isPrime(big.NewInt(int64(m))) {
      cnt++
    }
  }
  fmt.Println(cnt)
}

func isPrime(p *big.Int) bool {
	zero := big.NewInt(0)
	one := big.NewInt(1)
	two := big.NewInt(2)

	if p.Cmp(two) == 0 {
		return true
	}
	
	// p - 1 = 2^s * dに分解する
	d := new(big.Int).Sub(p, one)
	s := 0
	for new(big.Int).And(d, one).Cmp(zero) == 0 {
		d.Rsh(d, 1)
		s++
	}
	
	n := new(big.Int).Sub(p, one)
	k := 20
	rnd := rand.New(rand.NewSource(time.Now().UnixNano()))

	for i := 0; i < k; i++ {
		result := false
		// [1, n-1]からaをランダムに選ぶ
		a := new(big.Int).Rand(rnd, n)
		a.Add(a, one)
		
		// a^{2^r * d} mod p != -1(= p - 1 = n)の比較
		tmp := new(big.Int).Exp(a, d, p)
		for r := 0; r < s; r++ {
			if tmp.Cmp(n) == 0 {
				result = true
				break
			}
			tmp.Exp(tmp, two, p)
		}
		
		// a^d != 1 mod p の比較
		if !result && new(big.Int).Exp(a, d, p).Cmp(one) != 0 {
			return false
		}
	}
	
	return true
}


Measured memory_bytes: 6244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    int N,K;
    cin >> N >> K;
    vector<int> P(N);
    REP(i,N)cin >> P[i];
    sort(ALL(P));
    ll sum = 0;
    REP(i,K)sum += P[i];
    cout << sum << "\n";
}

Measured memory_bytes: 3616