akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
ll sum[30];
int main() {
	ll K, N;
	cin >> K >> N;
	if (K % 2 == 0) {
		cout << K / 2;
		for (int i = 0; i < N - 1; i++) cout << " " << K;
		cout << endl;
		return 0;
	}
	if (K == 1) {
		cout << 1;
		for (int i = 1; i < (N + 1) / 2; i++) cout << " " << 1;
		cout << endl;
		return 0;
	}
	int k = 0;
	sum[0] = 1;
	ll t = 1;
	while (1) {
		t *= K;
		if (sum[k] + t > N) break;
		sum[k + 1] = sum[k] + t;
		k++;
	}
	sum[k + 1] = sum[k] + t;
	k++;
	int d = (K + 1) / 2;
	cout << d;
	int i;
	int offset = 0;
	for (i = 1; i < N; i++) {
		if (N - i - 1 <= k && sum[N - i - 1] / 2 <= offset) break;
		cout << " " << d;
		if ((N-i) % 2) offset++;
	}
	int idx = (sum[N - i] + 1) / 2 - offset;
	for (int j = N - i - 1; j >= 0; j--) {
		if (idx == 0) idx = sum[j];
		if (idx == 1) break;
		idx--;
		cout << " " << (idx + sum[j] - 1) / sum[j];
		idx %= sum[j];
	}
	cout << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
const int maxn=1e6+10;
const int mod=998244353;

ll dp[maxn];
int main()
{
    int n,k;
    cin>>n>>k;
    ll ans=0;
    for(int i=1; i<=n; i++)
    {
        int a;
        cin>>a;
        dp[0]=i;
        for(int j=k; j>=a; j--)
            dp[j]=(dp[j]+dp[j-a])%mod;
        ans=(ans+dp[k])%mod;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int gcd(int a,int b){
  if(b%a==0) return a;
  int tmp;
  while(a%b){
    tmp=a%b;
    a=b;
    b=tmp;
  }
  return b;
}

int main(){
  int n;
  cin >> n;
  int ans;
  cin >> ans;
  int a;
  for(int i=0;i<n-1;i++){
    cin >> a;
    ans=gcd(ans,a);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
# %%
def main():
    N = input()
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            return
    print(ans)
if __name__ == '__main__':
    main()

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


struct UnionFindTree {
    vector<int> size, parents;
    
    UnionFindTree() {}
    UnionFindTree(int n) {
        size.resize(n, 0);
        parents.resize(n, 0);
        for (int i = 0; i < n; i++) { makeTree(i); }
    }
    
    void makeTree(int x) {
        parents[x] = x;
        size[x] = 1;
    }
    
    bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }
    
    bool unite(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);

        if (x == y) return false;
        if (size[x] > size[y]) {
            parents[y] = x;
            size[x] += size[y];
        } else {
            parents[x] = y;
            size[y] += size[x];
        }
        return true;
    }
    
    int findRoot(int x) {
        if (x != parents[x]) { parents[x] = findRoot(parents[x]); }
        return parents[x];
    }
    
    int treeSize(int x) { return size[findRoot(x)]; }
};



int main() {

  int N, M;
  scanf("%d %d", &N, &M);

  vector<int> A(M);
  vector<int> B(M);

  for (int i=0;i<M;i++){
    scanf("%d %d", &A[i], &B[i]);
  }
  
  UnionFindTree uf(N+1);

  int MAX_TREE=1;
  for (int i=0;i<M;i++){
    uf.unite(A[i], B[i]);
    MAX_TREE = max(MAX_TREE, max(uf.treeSize(A[i]), uf.treeSize(B[i])));
  }

  printf("%d\n", MAX_TREE);
  
  return 0;
}



Measured memory_bytes: 6388
n, k = map(int, input().split())
a = list(map(int, input().split()))

a_cum = [0 for _ in range(n+1)]
for i in range(n):
    a_cum[i+1] = a_cum[i] + a[i]

sum_list = []
for i in range(n+1):
    for j in range(i+1, n+1):
        sum_list.append(a_cum[j] - a_cum[i])
sum_list.sort()
#print(sum_list)
x = len(bin(a_cum[n])) - 2


def search(x, l):
    if x == 0:
        return 0
    m = len(l)
    next_l = []
    cnt = 0
    for i in range(m):
        if (l[i] >> (x-1)) & 1:
            cnt += 1
            next_l.append(l[i])
    if cnt >= k:
        return search(x-1, next_l) + 2 ** (x-1)
    else:
        return search(x-1, l)

print(search(x, sum_list))


Measured memory_bytes: 29320
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int d[20000];
int a[200];

int main()
{
  int i,j,n,ans,ma;
  scanf("%d",&n);
  for (i=0;i<n;i++)
    scanf("%d",&a[i]);
  ma=0;
  memset(d,0,sizeof(d));
  d[0]=1;
  for (i=0;i<n;i++)
  {
    for (j=ma;j>=0;j--)
    {
      if (d[j]==1) d[j+a[i]]=1;
    }
    ma+=a[i];
  }
  ans=0;
  for (i=ma;i>=0;i--)
    if ((d[i]==1)&&(i%10!=0))
    {
      ans=i;
      break;
    }
  printf("%d\n",ans);
  return 0;
}

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

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

    std::vector<std::vector<int> > dpt(s.size()+1, std::vector<int>(t.size()+1, 0));


    for (int i = 1; i <= s.size(); i++) {
        for (int j = 1; j <= t.size(); j++) {
            if (s[i-1] == t[j-1]) {
                dpt[i][j] = dpt[i-1][j-1] + 1;
            } else {
                if (dpt[i-1][j] > dpt[i][j-1]) {
                    dpt[i][j] = dpt[i-1][j];
                } else {
                    dpt[i][j] = dpt[i][j-1];
                }
            }
        }
    }
    std::string result = "";
    int i = s.size();
    int j = t.size();
    while (i > 0 && j > 0) {
        if (dpt[i][j] == dpt[i-1][j]) {
            i--;
        } else if (dpt[i][j] == dpt[i][j-1]) {
            j--;
        } else if (dpt[i][j] == dpt[i-1][j-1]+1) {
            result = t[j-1] + result;
            i--;
            j--;
        }
    }
    std::cout << result << std::endl;
}

Measured memory_bytes: 38780
#include <iostream>

using namespace std;

#define INF 2147483647

void update(int ,int ,int ,int*);
int find(int ,int, int ,int ,int, int*);

int main()
{
  
  int n, q, com, x, y,temp, i;
  cin >> n >> q;
  temp = 1;
  while(temp < n)
    temp = temp << 2;
  int A[2*temp-1];
  for(i=0; i<2*temp-1; i++)
    A[i] = INF;
  while(cin >> com >> x >> y)
    {
      if(com)
	{
	  cout << find(x, y+1, 0, 0, temp, A) <<endl;
	}else
	{
	  update(x, y,temp, A);
	}
    }
  return 0;
}

void update(int a, int b, int temp, int* A)
{
  a += temp - 1;
  A[a] = b;
  while(a > 0)
    {
      a = (a-1)/2;
      A[a] = min(A[2*a+1], A[2*a+2]);
    }
}
 
int find(int a,int b,int c,int d,int e , int* A)
{
  if(b <= d || e <= a)
      return INF;
  
  else if(a <= d && e <= b)
      return A[c];
  
  else
    return min(find( a, b, 2*c+1, d, (d+e)/2 , A),find( a, b, 2*c+2, (d+e)/2, e, A) );
}


Measured memory_bytes: 5112
#include <stdio.h>
        #include <string.h>


        #define N 1001


        int Comp(int a,int b){
          if(a<b)return b;
          else return a;
        }
        int lcs(char *x,char *y){

          int i,j;
          int lenx,leny;
          int dp[N][N];

          lenx=strlen(x);
          leny=strlen(y);

          for(i=0;i<=lenx;i++)dp[i][0]=0;

          for(j=0;j<=leny;j++)dp[0][j]=0;

          for(i=0;i<lenx;i++){

            for(j=0;j<leny;j++){

              if(x[i]==y[j]) dp[i+1][j+1]=dp[i][j]+1;
              else dp[i+1][j+1]=Comp(dp[i+1][j],dp[i][j+1]);

            }

          }

          return dp[lenx][leny];
        }
        int main(){

          int num;
          char x[N];
          char y[N];

          scanf("%d",&num);
          while(num>0){

            scanf("%s",x);
            scanf("%s",y);

            printf("%d\n",lcs(x,y));
            num--;
          }

          return 0;

        }



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

int main(){
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double ax,bx,cx;
    bx = 6*m;
    ax = 30*h + (bx*30)/360;
    cx = max(ax,bx)-min(ax,bx);
    if (cx > 180){
        cx -= 360;
    }
    double pi = 2.0*asin(1.0);
    cx = (pi*cx)/180.0;
    double c = a*a + b*b - 2*a*b*cos(cx);
    c = sqrt(c);
    cout << setprecision(10) << fixed << c << endl;    
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
#define int long long 
using namespace std;
typedef pair<int,int> ii;


__int128 ans = 1;

signed main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n; cin >> n;
	int arr[n];
	
	for(int i = 0;i < n;i++){
		cin >> arr[i];
		
	}
	
	sort(arr,arr+n);
	
	for(int i = 0;i < n;i++){
		int x = arr[i];
		ans *= x;
		if(ans > 1000000000000000000){
			cout << -1;
			return 0;
		}
	}
	
	cout << (long long) ans;
}


Measured memory_bytes: 4444
#include <stdio.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <complex>
#include <utility>
#include <algorithm>
#include <functional>

#define rep(i, n) for(int i=0; i<(int)(n); i++)
using namespace std;
typedef complex<double> P;

double cross(const P& a, const P& b) {
	return imag(conj(a)*b);
}

double dot(const P& a, const P& b) {
	return real(conj(a)*b);
}

int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if(cross(b, c)>0) return 1;
	if(cross(b, c)<0) return -1;
	if(dot(b, c)<0) return 2;
	if(norm(b)<norm(c)) return -2;
	return 0;
}

bool intersect(const P& a1, const P& a2, const P& b1, const P& b2) {
	return ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0
		&& ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0;
}

P crosspoint(const P& a1, const P& a2, const P& b1, const P& b2) {
	double a = cross(a2-a1, b2-b1);
	double b = cross(a2-a1, a2-b1);
	return b1 + b/a*(b2-b1);
}

int main()
{
	int Q;
	scanf("%d", &Q);
	rep(q, Q) {
		int xa, ya, xb, yb;
		scanf("%d%d%d%d", &xa, &ya, &xb, &yb);
		P s(xa, ya), e(xb, yb);
		int n;
		scanf("%d", &n);
		vector<pair<double, int> > v;
		rep(i, n) {
			int xs, ys, xt, yt, o, l;
			scanf("%d%d%d%d%d%d", &xs, &ys, &xt, &yt, &o, &l);
			P cs(xs, ys), ce(xt, yt);
			int k = (o==l) ? 1 : 0;
			if(intersect(s, e, cs, ce)) {
				double d = abs(s-crosspoint(s, e, cs, ce));
				v.push_back(make_pair(d, k));
			}
		}
		sort(v.begin(), v.end());
		int c=0;
		for(int i=1; i<(int)v.size(); i++) {
			if(v[i].second!=v[i-1].second) c++;
		}
		printf("%d\n", c);
	}
	return 0;
}

Measured memory_bytes: 840
a, b, c, x = STDIN.read.lines.map(&:to_i)
a += 1
b += 1
c += 1
ans = 0
a.times do |i|
  b.times do |j|
    c.times do |k|
      ans += 1 if i*500+j*100+k*50 == x
    end
  end
end
puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(void){
    int N,M;
    cin>>N>>M;
    vector<string> A(N),B(M);
    for (int i=0;i<N;i++) cin>>A[i];
    for (int i=0;i<M;i++) cin>>B[i];

    for (int i=0;i<N-M+1;i++){
        for (int j=0;j<N-M+1;j++){
            bool flag = true;
            for (int k=0;k<M;k++){
                if (A[i+k].substr(j,M)!=B[k]) flag = false;
            }
            if (flag) {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#
# abc102 b
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4
1 4 6 3"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
1000000000 1"""
        output = """999999999"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5
1 1 1 1 1"""
        output = """0"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    print(max(A)-min(A))


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16232
<?php
fscanf(STDIN, "%d", $N);
$arr = explode(" ", trim(fgets(STDIN)));
sort($arr);
// var_dump($arr);
$list = array();
for ($i = 1; $i <= $N; $i++) {
  $list[] = $arr[3*$N - $i *2];
}
echo array_sum($list);
?>

Measured memory_bytes: 36544
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MOD 1000000009
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
#define top(i,j) val[i*m+j]
#define s(a,b) strcmp(a,b)
typedef long long lli;
typedef unsigned short int usi;

int main()
{
    int t, x;
    float ans;
    scanf("%d %d",&t, &x);
    ans = (float)t/x;
    printf("%f",ans);


    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
ll int large=(ll int)1e16+7;
ll int mod=(ll int)1e9+7;
ll int const N=(ll int)1e5+10;

ll int mod_exp(ll int x,ll int n)
{
    ll int result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n=n/2;
    }
    return result;
}

ll int mod_inverse(ll int a)
{
    return mod_exp(a,mod-2);
}


ll int finde(ll int a,ll int par[])
{
    if(par[a]<0)
        return a;
    ll int res=finde(par[a],par);
    par[a]=res;
    return res;
}

void unione(ll int a,ll int b,ll int par[])
{
    if((a=finde(a,par))==(b=finde(b,par)))
    return;
    else
    {
       par[a]+=par[b];
       par[b]=a;
    }
}

ll int sqroot(ll int n)
{
  ll int i;
  rep(i,1,10000000)
  {
    if(i*i==n)
      return i;
    if(i*i>n)
    {
      return i-1;
    }
  }
}


int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll int T,i,j,ij;
T=1;
//cin>>T;
while(T--)
{
  ll int n;
  cin>>n;

  ll int ans=0;
  rep(i,1,n+1)
  {
     ans+= ( i*( (n/i)*((n/i)+1)   ) )/2;
  }

  cout<<ans;

}
return 0;
}
















Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
using namespace std;
using ll = long long;
void self_max(int &a,int b){
	a = max(a,b);
}

int main() {
	int a,b; cin >> a >> b;

	int diff = a - 2*b;

	if(diff < 0) cout << 0 << endl;
	else {
		cout << diff << endl;
	}

	return 0;
}

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

void solve(std::vector<std::string>& s)
{
    std::sort(s.begin(), s.end());

    std::cout << std::accumulate(s.begin(), s.end(), std::string()) << '\n';
}

int main()
{
    size_t n, l;
    std::cin >> n >> l;

    std::vector<std::string> s(n);
    for (size_t i = 0; i < n; ++i)
        std::cin >> s[i];

    solve(s);

    return 0;
}



Measured memory_bytes: 3628
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    string s; cin >> s;

    int N = s.length();
    for(int l=0; l<N; l++) {
        for(int r=l; r<N; r++) {
            // [0, l) と [r, N)
            string A = s.substr(0, l);
            string B = s.substr(r);
            string P = A + B;
            if(P == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#!python3.4
# -*- coding: utf-8 -*-
# panasonic2020/panasonic2020_a
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K = i2n()
    print(arr[K-1])
    return

main()


Measured memory_bytes: 3316
#include"iostream"
#include"cstdio"
#include"cmath"
#include"cstring"
#include"algorithm"
#include"stack"
#include"queue"
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long 
#define ull unsigned long long
#define MAXN 3005 

int n,m,k;
ll e[MAXN][MAXN]={0};
int x,y;
ll val;
ll dp[MAXN][MAXN][5];

int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=k;i++)
	{
		cin>>x>>y>>val;
		e[x][y]=val;
	}
	dp[1][1][0]=0;
	dp[1][1][1]=e[1][1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(i==n&&j==m) break;
			if(i<n)
			{
				if(e[i+1][j])
				{
					dp[i+1][j][0]=max(dp[i+1][j][0],max(dp[i][j][0],max(dp[i][j][1],max(dp[i][j][3],dp[i][j][2]))));
					dp[i+1][j][1]=max(dp[i+1][j][1],max(dp[i][j][0],max(dp[i][j][1],max(dp[i][j][3],dp[i][j][2])))+e[i+1][j]);
				}
				else dp[i+1][j][0]=max(dp[i+1][j][0],max(dp[i][j][0],max(dp[i][j][1],max(dp[i][j][3],dp[i][j][2]))));
			}
			if(j<m)
			{
				if(e[i][j+1])
				{
					dp[i][j+1][0]=max(dp[i][j+1][0],dp[i][j][0]);
					dp[i][j+1][1]=max(dp[i][j+1][1],max(dp[i][j][1],dp[i][j][0]+e[i][j+1]));
					dp[i][j+1][2]=max(dp[i][j+1][2],max(dp[i][j][2],dp[i][j][1]+e[i][j+1]));
					dp[i][j+1][3]=max(dp[i][j+1][3],max(dp[i][j][3],dp[i][j][2]+e[i][j+1]));
				}
				else
				{
					dp[i][j+1][0]=max(dp[i][j+1][0],dp[i][j][0]);
					dp[i][j+1][1]=max(dp[i][j+1][1],dp[i][j][1]);
					dp[i][j+1][2]=max(dp[i][j+1][2],dp[i][j][2]);
					dp[i][j+1][3]=max(dp[i][j+1][3],dp[i][j][3]);
				}
			}
		}
	}
	cout<<max(dp[n][m][0],max(dp[n][m][1],max(dp[n][m][2],dp[n][m][3])))<<endl;
	return 0;
} 

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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N, Q;
    cin >> N >> Q;
    vector<int> edge[N];
    int val[N] = {0};
    int decide[N] = {0};
    rep(i, N-1){
        int a, b;
        scanf("%d%d", &a, &b);
        edge[a-1].push_back(b-1);
        edge[b-1].push_back(a-1);
    }
    rep(i, Q){
        int n, v;
        scanf("%d%d", &n, &v);
        val[n-1] += v;
    }
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int op = q.front();
        q.pop();
        while(!edge[op].empty()){
            auto a = edge[op].end();
            a--;
            edge[op].pop_back();
            if(decide[*a] == 0){
                val[*a] += val[op];
                q.push(*a);
            }
        }
        decide[op] = 1;
    }
    rep(i, N){
        if(i == N-1) printf("%d\n", val[i]);
        else printf("%d ", val[i]);
    }
    return 0;
}

void solve(){}

Measured memory_bytes: 16244
#include <iostream>

using namespace std;

int N, M;

int solve(void) {
	int L = 0;
	int R = 100001;

	for ( int i = 0; i < M; i++ ) {
		int tL, tR;
		scanf("%d %d", &tL, &tR);

		if ( tR < L || R < tL ) return 0;
		L = max(tL, L);
		R = min(tR, R);

	}
	return R - L + 1;
}

int main(void) {

	scanf("%d %d", &N, &M);
	printf("%d\n", solve());
	
}


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

int main() {
    int n, y;

    cin >> n >> y;

    for(int i = 0; i <= n; i++) {
        for(int j = 0; i + j <= n; j++) {
            int k = n - i - j;

            if(y == (i * 10000 + j * 5000 + k * 1000)) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define double long double
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,int> Pi;
typedef pair<P,P> PP;
double eps=1e-8;
int mod=1e9+7;
int inf=1LL<<55;

priority_queue<P,vector<P>,greater<P> > pq;

template <typename T>
int Count(const vector<T> &v, T l,T r){
  //counting [l,r]
  auto L = lower_bound(v.begin(), v.end(), l );
  auto R = upper_bound(v.begin(), v.end(), r );
  // [l,r) change upper -> lower
  return R-L;
}

signed main(){
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<s.size();i++)
    if(s[i]=='+')ans++;
    else ans--;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){
	
	long long N;
	cin>>N;
	
	vector<pair<long long,long long>> P(N);
	
	for(long long i=0;i<N;i++){
		cin>>P[i].first;
		P[i].second = i;
	}
	
	sort(P.begin(),P.end(),greater<pair<long long,long long>> ());
	
	set<long long> S;
	long long ans = 0;
	
	for(long long i=0;i<N;i++){
		auto it1 = S.lower_bound(P[i].second);
		long long next,next2;
		if(it1==S.end()){
			next = N;
		}
		else{
			next = *it1;
		}
		
		if(it1==S.end())next2=Inf;
		else{
			it1++;
			if(it1==S.end()){
				next2=N;
			}
			else{
				next2 = *it1;
			}
		}
		
		long long pre,pre2;
		auto it2 = S.lower_bound(P[i].second);
		if(it2==S.begin()){
			pre=-1;
			pre2=Inf;
		}
		else{
			it2--;
			pre = *it2;
			if(it2==S.begin()){
				pre2 = -1;
			}
			else{
				it2--;
				pre2 = *it2;
			}
			
			/*
			if(it2==S.begin()){
				pre=-1;
				pre2=Inf;
			}
			else{
				pre = *it2;
				
				it2--;
				if(it2==S.begin())pre2=-1;
				else pre2 = *it2;
				
			}*/
		}
		long long A = ans;
		if(next2!=Inf){
			ans += (next2-next)*(P[i].second-pre)*P[i].first;
		}
		
		if(pre2!=Inf){
			ans += (next-P[i].second)*(pre-pre2)*P[i].first;
		}
		//cout<<next<<','<<next2<<','<<pre<<','<<pre2<<endl;
		S.insert(P[i].second);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 6528
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = ns().rstrip()
ok = False
if s.startswith("A"):
    if s[2:-1].count("C") == 1:
        ct = 0
        for c in s:
            if "a" <= c <= "z":
                ct += 1
        if ct == len(s)-2:
            ok = True
print("AC" if ok else "WA")


Measured memory_bytes: 3064
N = int(input())
S = input()

def calc():
    if len(S) % 2 == 1:
        return 'No'
    
    left = S[len(S)//2:]
    right = S[:len(S)//2]
    if left == right:
        return 'Yes'
    else:
        return 'No'

print(calc())

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

template <class T>  
inline bool RD(T &ret) {  
        char c; int sgn;  
        if (c = getchar(), c == EOF) return 0;  
        while (c != '-' && (c<'0' || c>'9')) c = getchar();  
        sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');  
        while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');  
        ret *= sgn;  
        return 1;  
}  
template <class T>  
inline void PT(T x) {  
        if (x < 0) putchar('-') ,x = -x;  
        if (x > 9) PT(x / 10);  
        putchar(x % 10 + '0');  
}

const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<int, int> pii;
typedef long double LD;


const LL MOD = 1e9 + 7;
LL dp[1 << 17][42];

int main() {
	LL ans = 0;
	int n, x, y, z;
	cin >> n >> x >> y >> z;
	int gmask = (1 << (x + y + z - 1)) | (1 << (z + y - 1)) | (1 << (z - 1));
	int m = 1 << (x + y + z);
	dp[0][0] = 1;
   	for(int i = 1; i <= n; i ++) {
		ans = 10 * ans % MOD;
		for(int mask = 0; mask < m; mask ++) {
			if((mask & gmask) == gmask) continue;
			for(int num = 1; num <= 10; num ++) {
				int nmask = ((mask << num) | (1 << (num - 1))) & (m - 1);
				if((nmask & gmask) == gmask) ans = (ans + dp[mask][i - 1]) % MOD;
				else dp[nmask][i] = (dp[nmask][i] + dp[mask][i - 1]) % MOD;
			}
		}
	}	
	cout << ans << endl;
}



Measured memory_bytes: 41728
/*
    Reference :-
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
ll mod=1000000007;

ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}

int main(){
    //std::ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    char a;
    cin>>a;
    cout<<char(a+1);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include<ctime>
#include<random>
#include<cstring>
#include<cstdlib>
#include<cstdint>
#include<fstream>
#include<strstream>
#include<vector>
#include<string>
#include<chrono>
#include<algorithm>

//#include "D:\Code\C++\Headers\zle_STL.h"


#define ll long long

using namespace std;


int main() {
	int N, K;
	cin >> N >> K;
	vector<int>p;
	p.resize(N);
	for (int c = 0; c < p.size(); c++) {
		cin >> p[c];
	}

	sort(p.begin(), p.end());
	int ans = 0;
	for (int g = 0; g < K; g++) {
		ans += p[g];
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &e : a) cin >> e;

    vector<vector<bool>> dp(2, vector<bool>(k + 1, false));
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j < 2; j++) {
            for (int x = 0; x < n; x++) {
                if (i - a[x] >= 0 && !dp[j ^ 1][i - a[x]]) {
                    dp[j][i] = 1;
                }
            }
        }
    }


    if (dp[0][k]) {
        cout << "First";
    } else {
        cout << "Second";
    }
}

int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline


def inpl():
    return list(map(int, input().split()))


N, M = inpl()
coins = inpl()

dp = [i for i in range(N + 1)]
coins.sort()

for n in range(coins[1], N + 1):
    for c in coins[1:]:
        if c > n:
            continue
        dp[n] = min(dp[n], dp[n - c] + 1)

# print(dp[N])
print(dp[N])



Measured memory_bytes: 7648
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
 
public class Main{
 
    Scanner sc;
 
    static final int INF=1<<28;
    static final double EPS=1e-9;
 
    void run(){
        sc=new Scanner(System.in);
        for(;;){
            int n=sc.nextInt();
            if(n==0)
                break;
            HashMap<Integer, Long> map=new HashMap<Integer, Long>();
            LinkedList<Integer> list=new LinkedList<Integer>();
            for(int i=0; i<n; i++){
                int id=sc.nextInt();
                long a=sc.nextInt();
                long b=sc.nextInt();
                if(!map.containsKey(id)){
                    list.addLast(id);
                    map.put(id, 0l);
                }
                map.put(id, map.get(id)+a*b);
            }
            boolean f=false;
            for(int id : list){
//              println("test:"+id+":"+map.get(id));
                if(map.get(id)>=1000000){
                    println(id+"");
                    f=true;
                }
            }
            if(!f)
                println("NA");
        }
        sc.close();
    }
 
    void print(String s){
        System.out.print(s);
    }
 
    void println(String s){
        System.out.println(s);
    }
 
    public static void main(String[] args){
        new Main().run();
    }
}


Measured memory_bytes: 36188
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)

typedef long long ll;


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

int main() {
  string s, t;
  cin >> s >> t;
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
//   cout << s << " " << t << endl;

  int l_s = s.size(); int l_t = t.size();
  int num = (l_s > l_t) ? l_t : l_s;
  string ans = "Yes"; int count_same = 0;
  rep(i, num) {
    //   cout << s[i]-'0' << " " << t[i]-'0' << endl;
      if ((s[i]-'0') == (t[i]-'0')) count_same++;
      if ((s[i]-'0') < (t[i]-'0')) break;
      if ((s[i]-'0') > (t[i]-'0'))
      {
          /* code */
          ans = "No";
          break;
      }
      if (i == num-1 && l_s > l_t)
      {
          /* code */
          ans = "No";
          break;
      }
  }
  if (count_same == l_t && count_same == l_s) ans = "No";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	char temp[10] = "";
	cin >> temp;
	int count = 0;
	for ( int i =0; i < 3; i++ ) {
		if ( temp[i] == 'o' )
			count++;
	}
    
    cout << 700 + count*100;
} // int main()

Measured memory_bytes: 256
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
L = [0] * (M-1)

for i in range(M-1):
    L[i] = abs(X[i+1] - X[i])

L.sort()

print(sum(L[:-(N-1)]) if N != 1 else sum(L))


Measured memory_bytes: 13960
#include <stdio.h>
#include <algorithm>

int GetMaxProfit(int R[], int N) {
    int max, min;
    min = R[0];
    max = R[1] - R[0];
    for (int i = 1; i < N; ++i) {
        max = std::max(R[i] - min, max);
        min = std::min(R[i], min);
    }
    return max;
}

int main() {
    int N;
    int R[200000];

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

    int result = GetMaxProfit(R, N);
    printf("%d\n", result);

    return 0;
}

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

int main()
{
	int n, t;
	cin >> n >> t;
	int ans = 10000;
	for(auto i = 0; i < n; ++i){
		int c, s;
		cin >> c >> s;
		if(s <= t) ans = min(ans, c);
	}
	if(ans == 10000) cout << "TLE" << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int right = 0;
    int penalty = 0;
    HashMap<Integer, Integer> map = new HashMap<>();
    HashSet<Integer> set = new HashSet<>();
    for(int i = 0; i < m; ++i) {
      int index = sc.nextInt();
      String s = sc.next();
      if(set.contains(index)) continue;
      if(s.equals("AC")) {
        penalty += map.getOrDefault(index, 0);
        ++right;
        set.add(index);
      } else {
        if(!map.containsKey(index)) {
          map.put(index, 1);
        } else {
          map.put(index, map.get(index) + 1);
        }
      }
    }
    System.out.println(right + " " + penalty);
  }
}

Measured memory_bytes: 68728
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e18
#define dump(x) cerr<<#x<<"="<<x<<endl
#define int long long

using ll = long long;
const ll mod = LLONG_MAX;

int N;
int a[200010];
int imos[200010];
signed main(){
  cin>>N;
  rep(i,N){
    cin>>a[i];
  }
  imos[0]=a[0];
  FOR(i,1,N){
    imos[i]+=imos[i-1]+a[i];
  }

  int ans=INF;
  int s,ara;
  rep(i,N-1){
    s=0;ara=0;
    s=imos[i];
    ara=imos[N-1]-imos[i];
    ans=min(ans,abs(s-ara));
  }
  cout<<ans<<endl;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

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

ll lcm(ll a, ll b) {
   return a / gcd(a, b) * b;
}

int N;
const int NN = 111111;
int C[NN], S[NN], F[NN];

int main() {
   cin >> N;
   rep (i, N-1) {
      cin >> C[i] >> S[i] >> F[i];
   }

   rep (i, N) { // i番目の駅から発車
      int tim = 0;
      repp (j, i, N-1) {
         if (i == j) tim += S[i];
         int a = S[j];
         while (1) {
            if (a >= tim) break;
            a += F[j];
         }
         // これは絶対かかる
         tim = a;
         tim += C[j];
      }
      cout << tim << endl;
   }

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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

int main() {
    int n;
    cin >> n;
    int l[n], maxl = 0, sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> l[i];
        chmax(maxl, l[i]);
        sum += l[i];
    }
    sum -= maxl;
    if (maxl < sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
   
class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String s1 = sc.nextLine();
            String s2 = sc.nextLine();
            String s3 = s1 + s1;
            if (s3.contains(s2)) {
                    System.out.println("Yes");
            }else{
                    System.out.println("No");
            }
        }
}


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

#define ll long long
#define P pair<int,int>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define asort(x) sort(x.begin(),x.end())

int main() {
    string s, t;
    cin>>s>>t;
    if(t.compare(0, s.length(), s) == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <math.h>
#include <iomanip>
#include <complex>

#define INF (10000000)


using namespace std;

int main(void)
{
  double d,e;
  double budget;
  double min_budget=INF;
 
  while(cin >> d >> e,d!=0 && e!=0)
    {

      for(int i=0;i<=d;i++)
	for(int j=0;j<=d;j++)
	  {
	    if((i+j)==d){
	      budget=abs((sqrt(i*i+j*j)-e));
	      
	       if(min_budget > budget)
		min_budget=budget;
	    }
	  }

      cout <<  min_budget << endl;

      min_budget=INF;
      
    }

  return 0;
}


Measured memory_bytes: 3284
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    ABC = list(map(int, input().split()))
    ABC.sort()
    if (ABC[-1] * 3 - sum(ABC)) % 2 == 0:
        print((ABC[-1] * 3 - sum(ABC)) // 2)
    else:
        print(((ABC[-1] + 1) * 3 - sum(ABC)) // 2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ul>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 200005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
ll sqr(ll x)
{
    return x*x;
}
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int sum = 0;
 int n,m;   cin>>n>>m;
 int val; f(m)
 {
     cin>>val; sum+=val;
 }
 if(n-sum >= 0)cout << n-sum;
 else cout << -1;
    return 0;
}
    


Measured memory_bytes: 3612
#include <iostream>
#define N 2002
using namespace std;
struct team{
  int tnum;
  int correct;
  int time;
};
int main(){
  int m,t,p,r,im[N],it[N],ip[N],ij[N],incorrect,i,j;
  struct team data[51];
  while(1){
    cin >> m >> t >> p >> r;
    if(m==0&&t==0&&p==0&&r==0) break;
    for(i=0;i<r;i++) cin >> im[i] >> it[i] >> ip[i] >> ij[i];
    for(i=1;i<=t;i++){
      data[i].tnum=i;
      data[i].correct=0;
      data[i].time=0;
    }
    for(i=0;i<r;i++){
      if(ij[i]==0){
	data[it[i]].correct++;
      	incorrect=0;
	for(j=0;j<i;j++){
	  if(it[i]==it[j]&&ip[i]==ip[j]) incorrect++;
	}
	data[it[i]].time=data[it[i]].time+incorrect*20+im[i];
      }
    }
    for(i=0;i<=t;i++){
      for(j=2;j<=t;j++){
	if(data[j].tnum>data[j-1].tnum) swap(data[j],data[j-1]);
      }
    }
    for(i=0;i<=t;i++){
      for(j=2;j<=t;j++){
	if(data[j].time<data[j-1].time) swap(data[j],data[j-1]);
      }
    }
    for(i=0;i<=t;i++){
      for(j=2;j<=t;j++){
	if(data[j].correct>data[j-1].correct) swap(data[j],data[j-1]);
      }
    }
    for(i=1;i<t;i++){
      cout << data[i].tnum;
      if(data[i].correct==data[i+1].correct&&data[i].time==data[i+1].time)
	cout << '=';
      else cout << ',';
      // if(i==t-1) cout << data[i+1].tnum;
    }
    cout << data[t].tnum << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,k,l,a,b,c,d,s;
    cin>>n;
    ll arr[n+10];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr+0,arr+n);
    c= INT_MAX;
    for(i=0;i<n;i++)
    {
        s=0;
        k=arr[i];
        while(k%2==0)
        {
            if(s>=c)
            {
                break;
            }
            k/=2;
            s++;
        }
        if(s<c)
        {
            c=s;
        }
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<ll, P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()
 
int main(){
    int a, b;
    cin >> a >> b;
    if(a < 10 && b < 10){
        cout << a*b << endl;
    }
    else{
        cout << -1 << endl;
    }
    return 0;
}

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

int main() {
    int h, w, k, co = 0, ans = 0;
    cin >> h >> w >> k;
    vector<vector<char>> c(h, vector<char>(w));
    rep(i, h) {
        rep(j, w) {
            cin >> c[i][j];
        }
    }
    for (int bit = 0; bit < (1 << h); ++bit) {
        for (int bit2 = 0; bit2 < (1 << w); ++bit2) {
            co = 0;
            rep(i, h) {
                rep(j, w) {
                    if (!(bit & (1 << i)))
                        if (!(bit2 & (1 << j)))
                            if (c[i][j] == '#')
                                co++;
                }
            }
            if (co == k)
                ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int n, m, a;
int amida[150];


int main()
{
	while (cin >> n >> m >> a) {
		if (n == 0 && m == 0 && a == 0)return 0;

		vector<PP> c;
		for (int i = 1; i <= n; i++) {
			amida[i] = i;
		}
		int h, p, q;
		for (int i = 0; i < m; i++) {
			cin >> h >> p >> q;
			c.push_back(PP(h, P(p, q)));
		}
		sort(c.begin(), c.end());

		for (int i = 0; i < c.size(); i++) {
			swap(amida[c[i].second.first], amida[c[i].second.second]);
		}
		cout << amida[a] << endl;
	}


	return 0;
}

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

#define rep(i, n)     for(int i = 0;      i < int(n); ++i)
#define rep3(i, a, b) for(int i = int(a); i < int(b); ++i)
#define all(x)        (x).begin(),(x).end()
#define sz(x)         int(x.size())
#define mp            make_pair
#define pb            push_back


typedef long long ll;

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> fact(n+1);
  int ans = 0;
  
  rep3(i, 1, n+1){
    for(int j = i; j < n+1; j += i){
      ++fact[j];
    }
    if(fact[i] == 8 && i % 2 == 1){
      ++ans;
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
N = int(readline())
h = list(map(int,readline().split()))
 
dp = [0]*N
dp[1] = abs(h[1]-h[0])
 
for i in range(2,N):
    dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
print(dp[N-1])

Measured memory_bytes: 14016
#include<stdio.h>
int main(void){
	int n;
	scanf("%d",&n);
	long long ans=0,now=0;
	for (int i=1;i<=n;i++){
		int a;
		scanf("%d",&a);
		if (a) now+=a;
		else ans+=now/2,now=0;
	}
	ans+=now/2;
	printf("%lld",ans);
}

Measured memory_bytes: 128
n = int(input())
a = []
for i in range(n):
    s, t = map(int, input().split())
    a.append([s, t])
a = sorted(a, key=lambda x: x[1])
time = 0
flag = True
for i in range(n):
    time += a[i][0]
    if time > a[i][1]:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  //Patern 1
  /*
  int area1, area2;
  
  area1 = a * b;
  area2 = c * d;
  
  if (area1 >= area2) cout << area1 << endl;
  else cout << area2 << endl;
  
  return 0;
  */
  
  //Patern 2
  /*
  if (a * b >= c * d) cout << a * b << endl;
  else cout << c * d << endl;
  */
  
  //Patern 3
  /*
  cout << ((a * b >= c * d) ? a * b : c * d) << endl;
  */
  
  //Patern 4
  cout << max(a * b, c * d) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define M 2000000
#define L 14

char H[M][L];

int getChar( char ch )
{
	if( ch == 'A') {
		return 1;
	} else if( ch == 'C') {
		return 2;
	} else if( ch == 'G') {
		return 3;
	} else if( ch == 'T') {
		return 4;
	} else {
		return 0;
	}
}

long long getKey( char str[] )
{
	long long sum = 0, p = 1, i;
	for ( i=0; i<strlen(str); i++ ) {
		sum += p*( getChar( str[i] ) );
		p *= 5;
	}
	return sum;
}

int find( char str[] )
{
	int i;
	long long hashkey;
	for( i=0; i<M; i++ ) {
		hashkey = getKey( str );
		hashkey = ( hashkey+ (i+1)*hashkey )%M;
		if( '\0' == H[ hashkey ][0] ) {
			return 0;
		} else {
		    if( 0 == strcmp( H[ hashkey ], str ) ) {
		    	return 1;
		    }
		}
	}
	return 0;
}

void insert( char str[] )
{
	int i;
	long long hashkey;
	for( i=0; i<M; i++ ) {
		hashkey = getKey( str );
		hashkey = ( hashkey+ (i+1)*hashkey )%M;
		if( '\0' == H[ hashkey ][0] ) {
			strcpy( H[ hashkey ], str );
			break;
		}
	}
    return;
}

int main() 
{

	int i, n;
	char str[L], com[9];
	
	for ( i=0; i<M; i++ ) {
		H[i][0] = '\0';
	}
	scanf( "%d", &n );
	for ( i=0; i<n; i++ ) {
		scanf( "%s %s", com, str );
		if ( com[0] == 'i' ){
			insert( str );
		} else {
			if( find( str ) ){
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}

    return 0;
}

Measured memory_bytes: 27952
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

long long x,sum[200005],n,ans=0,minn;
long long i;

int main()
{
    scanf("%lld",&n);
    sum[0]=0;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&x);
        sum[i]=sum[i-1]+x;//和数组 
    }
    /*for(i=1;i<=n;i++){
    	printf("%d ",sum[i]);
	}
	cout<<endl;
	*/
    ans=sum[n];
    minn=abs(2*sum[1]-sum[n]);//枚举找最小的差 
    for(i=2;i<=n-1;i++)
    {
        minn=min(minn,abs(2*sum[i]-sum[n]));
    }
    printf("%lld\n",minn);
    return 0;
}

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


int main(){
    int N;
    cin >> N;
    vector<int> X(N);
    rep(i,N) cin >> X.at(i);
    
    int mn = 10000000;
    rep(i,101){
        int ene = 0;
        rep(jj,N) ene += (i-X.at(jj))*(i-X.at(jj));
        mn = min(mn,ene);
    }
    
    cout << mn << endl;
}   

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

#define rep( i, n ) for( int i = 0; i < ( n ); i++ )
#define PI 3.14159265
typedef long long ll;

int main( void ) {

    int n, m, l;
    cin >> n >> m >> l;

    int A[ n ][ m ] = {}, B[ m ][ l ] = {};

    rep( i, n ) rep( j, m ) cin >> A[ i ][ j ];
    rep( i, m ) rep( j, l ) cin >> B[ i ][ j ];

    ll C[ n ][ l ] = {};

    rep( i, n ) {
        rep( j, l ) {
            rep( k, m )C[ i ][ j ] += A[ i ][k ] * B[ k ][ j ];
            if(j<l-1)
                cout << C[i][j] << " ";
            else
                cout << C[ i ][ j ] << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3240
import sys
input = lambda: sys.stdin.readline().rstrip() 
import numpy as np

def resolve():
    N = int(input())
    X = list(map(int, input().split()))

    minpower = np.inf
    for P in range(1, max(X)+1):
        minpower = min(sum([(x-P)**2 for x in X]), minpower)

    print(minpower)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 21548