akhauriyash/Code-Regression huggingface dataset:
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li		int32_t
#define lli		long long
#define ulli unsigned long long

#define pn			 printf("\n")
#define nl			 cout<<'\n'
#define sf(N)        scanf("%lld",&N)
#define pf(N)        printf("%lld",N)
#define sf1(N1,N2)    scanf("%lld %lld",&N1,&N2)
#define pf1(N1,N2)    printf("%lld %lld",N1,N2)
#define sf2(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define pf2(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define sl          cout<<' '
#define ps          printf(" ")

#define rep(i,a,b)	for(i=a;i<b;i++)
#define repr(i,a,b)	for(i=a;i>b;i--)
#define elif		else if
#define mset(a,b)	memset(a,b,sizeof(a))

#define pb		push_back
#define pob		pop_back
#define itr		iterator
#define sz()	size()
#define szof    sizeof
#define lb		lower_bound
#define ub		upper_bound
#define mp		make_pair
#define vlli    vector<lli>
#define plli	pair<lli,lli>
#define vplli	vector<plli >
#define F   	first
#define S		second
#define Dup     erase(unique(V.begin(),V.end()),V.end())

#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define ALL(V)  V.begin(),V.end()

#define MX1     100000LL
#define MX2     1000000LL
#define Inf     1000000000000000LL
#define mod		1000000007LL
using namespace std;

lli Power(lli a,lli b)
{
    lli result=1;

    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }

        b=b>>1;
        a=(a*a)%mod;
    }

 return result;
}

int main()
{
    opt;

    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/

    string s;
    cin>>s;

    if(s[0]==s[1] and s[2]==s[1])
    {
        cout<<"Yes";
        exit(0);
    }

    if(s[2]==s[3] and s[2]==s[1])
    {
        cout<<"Yes";
        exit(0);
    }

    cout<<"No";






 return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,w;
  cin>>n>>w;
  long long int dp[n+1][w+1];
  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<=w;j++)
    {
     
       dp[i][j]=0;
    }
  }
  
  for(int i=1;i<=n;i++)
  {
      int w1;
      long long int c;
      cin>>w1>>c;
      
    for(int j=1;j<=w;j++)
    {
     
      if(w1<=j)
      {
        dp[i][j]=max(c+dp[i-1][j-w1],dp[i-1][j]);
      }
      else
        dp[i][j]=dp[i-1][j];
    }
  }
  cout<<dp[n][w];
  return 0;
  
}

Measured memory_bytes: 79104
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,l[50000];
int main(){
	while(cin>>n,n){
		int p=0,prev,t,ans=0;
		cin>>t,prev=t,l[p]=1;
		rep(i,n-1){
			cin>>t;
			if(prev==t)l[p]++;
			else{
				if(i&1)l[++p]=1;
				else p>0?(p--,l[p]+=l[p+1]+1):l[p]++;
			}
			prev=t;
		}
		rep(i,p+1)ans+=t+i&1?0:l[p-i];
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 868
#include <stdio.h>

int main() {
  long int H, W, sum = 0;
  scanf("%ld %ld", &H, &W);
  
  if ((H == 1) || (W == 1)) {
    printf("1");
  }
  else {
    sum += (((H + 1) / 2) * ((W + 1) / 2)) + ((H / 2) * (W / 2));
  	printf("%ld", sum);
  }
  
  return 0;
}
      

Measured memory_bytes: 128
h, w, a, b = map(int, input().split())

def cmb1(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for i in range(b, w):
    ans += cmb1(i+h-1-a, i, mod)*cmb1(w-1-i+a-1, a-1, mod)
    ans %= mod
print(ans)

Measured memory_bytes: 122068
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;

int main(){
  int N;
  cin>>N;
  if(N/100==7 || (N/10)%10==7 || (N%100)%10==7) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
   int r[200000],n,minv,j,maxv;
   scanf("%d",&n);
   for(j=0;j<n;j++)
   {
      scanf("%d",&r[j]);
   }
   minv = r[0];
   maxv = -2000000000;
   for(j=1;j<n;j++)
   {
      maxv = (maxv > r[j]-minv) ? maxv : r[j]-minv ;
      minv = (minv < r[j]) ? minv : r[j] ;
   }
   printf("%d\n",maxv);
}


Measured memory_bytes: 2592
# Atcoder Express
from bisect import bisect_left, bisect_right
N = int(input())
time = list(map(int, input().split()))
vel = list(map(int, input().split()))
sum_t = [0 for i in range(N+1)]

for i in range(1, N+1):
    sum_t[i] = sum_t[i-1]+time[i-1]

dp = [[-float("inf") for j in range(101)] for i in range(20001)]
# dp[t][v]=開始からt秒後に速度v で走っている時に、t秒後に実現できる最大の移動距離
dp[0][0] = 0

for i in range(1, sum_t[-1]+1):
    # i秒後における更新

    bef = bisect_left(sum_t, i-1)
    phase = bisect_left(sum_t, i)

    bef_bound = vel[bef-1]  # i-1秒時点における速度制限
    bound = vel[phase-1]    # i秒後における速度制限
    if bef == 0:
        bef_bound = 100
        
    if bef_bound < bound:
        for j in range(bef_bound+2):
            if j == 0:
                if j+1 <= bef_bound:
                    dp[i][j] = max(dp[i-1][j]+j+0.25, dp[i-1][j+1]+j+0.5)
                else:
                    if j == bef_bound:
                        dp[i][j] = dp[i-1][j]+j+0.25

            elif j >= 1:
                if j+1 <= bef_bound:
                    dp[i][j] = max(dp[i-1][j-1]+j-0.5, dp[i-1]
                                   [j]+j+0.25, dp[i-1][j+1]+j+0.5)
                else:
                    if j == bef_bound:
                        dp[i][j] = max(dp[i-1][j-1]+j-0.5, dp[i-1][j]+j+0.25)
                    else:
                        if j-1 == bef_bound:
                            dp[i][j] = dp[i-1][j-1]+j-0.5

    elif bef_bound >= bound:
        for j in range(bound):
            if j == 0:
                # j+1<=bef_bound:
                dp[i][j] = max(dp[i-1][j]+j+0.25, dp[i-1][j+1]+j+0.5)
            elif j >= 1:
                dp[i][j] = max(dp[i-1][j-1]+j-0.5, dp[i-1]
                               [j]+j+0.25, dp[i-1][j+1]+j+0.5)

        dp[i][bound] = max(dp[i-1][bound]+bound, dp[i-1][bound-1]+bound-0.5)


ans = dp[sum_t[-1]][0]
print(ans)


Measured memory_bytes: 69492
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

vs dec(string s)
{
	vs res;
	string t;
	for (auto c : s)
	{
		if (c == '/')
		{
			res.push_back(t);
			t.clear();
		}
		else if (c == 'b')
		{
			t.push_back('b');
		}
		else if (isdigit(c))
		{
			REP(i, c - '0') t.push_back('.');
		}
		else assert(false);
	}
	res.push_back(t);
	return res;
}

string enc(string s)
{
	string res;
	int cnt = 0;
	for (auto c : s)
	{
		if (c == '.') cnt++;
		else
		{
			if (cnt != 0) res.push_back('0' + cnt);
			res.push_back('b');
			cnt = 0;
		}
	}		
	if (cnt != 0) res.push_back('0' + cnt);
	return res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	string s;
	while (cin >> s, s != "#")
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--; b--; c--; d--;
		vs fld = dec(s);
		fld[a][b] = '.';
		fld[c][d] = 'b';
		REP(i, fld.size()) cout << enc(fld[i]) << (i == fld.size() - 1 ? "\n" : "/");
	}
	return 0;
}

Measured memory_bytes: 3104
from pprint import pprint

n,k = map(int, input().split())

d = []
a = []

for i in range(k):
    d.append(int(input()))
    a.append(list(map(int,input().split())))

#pprint(n)
#pprint(k)
#pprint(d)
#pprint(a)

checkedlist = [0] * n
counter = 0

for i in range(k):
    for j in range(d[i]):
        if checkedlist[a[i][j] - 1] == 0:
            checkedlist[a[i][j] - 1] = 1
            counter += 1
        else:
            pass

print(n - counter)

Measured memory_bytes: 68848
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    string in; cin >> in;
    int n = in.size();
    bool ok = false;
    string T = "AKIHABARA";
    int j = 0;
    int i = 0;
    for(i = 0; i < n; i++){
        if(j == T.size()) break;
        if(in[i] == T[j]){
            j++;
        }
        else {
            if(T[j] != 'A') break;
            j++;
            i--;
        }
    }
    if(i == n and j >= T.size() - 1) ok = true;

    cout << (ok ? "YES":"NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    rep(i,n) cin >>a[i];
    rep(i,n) cin >>b[i];
    rep(i,n-1) cin >>c[i];

    int ans=0;
    int prev=-100;
    for(int i=0; i<n; i++){
        ans += b[a[i]-1];
        if(a[i]==prev+1){
            ans += c[prev-1];
        }
        prev = a[i];
    }

    cout << ans << endl;

}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		double[] x = new double[n];
		double sum = 0;
		long ave;
		
		for(int i=0; i<n; i++){
			x[i] = sc.nextDouble();
			sum += x[i];
		}
		
		ave = Math.round(sum / n);
		
		int ans = 0;
		for(int i=0; i<n; i++){
			ans += Math.pow(x[i]-ave, 2);
		}
		
		System.out.println(ans);
		

		sc.close();
	}
}



Measured memory_bytes: 11988
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

ll MOD = 1000000007;




int  main()
{
	string S;
	cin >> S;

	if (S == "Sunny")
	{
		cout << "Cloudy" << endl;
	}
	if (S == "Cloudy")
	{
		cout << "Rainy" << endl;
	}
	if (S == "Rainy")
	{
		cout << "Sunny" << endl;
	}

	return 0;
}

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

char str[51][51], ptr[51][51];
int n, m;
bool bfs(int x, int y){
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            if(str[x+i][y+j] != ptr[i][j]){
                return false;
            }
        }
    }
    return true;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%s",str[i]);
    for(int i=0;i<m;i++)
        scanf("%s",ptr[i]);
    bool flag = false;
    for(int i=0;i<=n-m;i++)
        for(int j=0;j<=n-m;j++)
            if(bfs(i,j))flag = true,i=n,j=n;
    printf(flag?"Yes":"No");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int w, h;
	boolean map[][];
	P s;
	LinkedList<P> dusts;
	P[] da;
	int[][] d;
	int size;
	int[][] mem;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			w = sc.nextInt();
			h = sc.nextInt();
			if( (w|h) == 0 ) break;
			map = new boolean[h+2][w+2];
			dusts = new LinkedList<P>();
			for(int i=1;i<=h;i++) {
				String str = sc.next();
				for(int j=1;j<=w;j++) {
					switch (str.charAt(j-1)) {
					case '*' :
						dusts.add(new P(j, i));
						map[i][j] = true;
						break;
					case 'x':
						map[i][j] = false;
						break;
					case 'o':
						s = new P(j, i);
						map[i][j] = true;
						break;
					case '.':
						map[i][j] = true;
					}
				}
			}
			size = dusts.size();
//			for(boolean[] a: map) debug(a);
			da = new P[size+1];
			da[0] = s;
			for(int i=1;i<=size;i++) da[i] = dusts.remove();
			d = new int[size+1][size+1];
			boolean flg = true;
			
			for(int i=0;i<size+1;i++) for(int j=i+1;j<size+1;j++) {
				d[i][j] = d[j][i] = bfs(da[i], da[j]);
				if(d[i][j] == INF ) flg = false;
			}
//			for(int[] a: d) debug(a);
			if(!flg) {
				System.out.println(-1);
				continue;
			}
			
			mem = new int[size+1][1<<(size+1)];
			for(int[] a: mem) fill(a, -1);
			System.out.println( solve( (1<<(size+1)) - 1, 0 ) );
		}
	}
	
	int solve(int S, int node) {
		if( mem[node][S] >= 0 ) return mem[node][S];
		if( S == 0 ) return mem[node][S] = 0;
		int t = INF;
		for(int i=0;i<size+1;i++) {
			if( ((S>>i)&1) == 1 ) {
				t = min(t, solve(S-(1<<i), i) + d[node][i] );
			}
		}
		
		return mem[node][S] = t;
	}
	
	int dx[] = {-1,0,1,0};
	int dy[] = {0,-1,0,1};
	
	int bfs(P s, P t) {
		boolean[][] tmp = new boolean[h+2][w+2];
		for(int i=0;i<h+2;i++) for(int j=0;j<w+2;j++)
			tmp[i][j] = map[i][j];
		P now = new P(s.x, s.y);
		LinkedList<P> que = new LinkedList<P>();
		que.add(now);
		tmp[now.y][now.x] = false;
		for( ;!que.isEmpty(); ) {
//			debug(now.x, now.y);
			now = que.removeFirst();
			if( now.x == t.x && now.y == t.y ) return now.cnt;
//			tmp[now.y][now.x] = false;
			for(int i=0;i<4;i++) {
				if( tmp[now.y+dy[i]][now.x+dx[i]] ) {
					que.addLast(new P(now.x + dx[i], now.y + dy[i], now.cnt + 1));
					tmp[now.y+dy[i]][now.x+dx[i]] = false;
				}
			}
		}
		return INF;
	}
	
	class P {
		int x, y, cnt;
		P(int x, int y) {
			this.x = x;
			this.y = y;
			cnt = 0;
		}
		P(int x, int y, int cnt) {
			this.x = x;
			this.y = y;
			this.cnt = cnt;
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 13000
N,M=map(int,input().split())
b=[0]*(N+1)
dp=[0]*(N+2);dp[N]=1
for i in range(M):b[int(input())]=1
for i in range(N):
    if b[N-i-1]:continue
    dp[N-i-1]=(dp[N-i]+dp[N-i+1])%1000000007
print(dp[0])

Measured memory_bytes: 13496
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long
#define ull unsigned long long
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    string s;
    cin >> s;
    int K;
    cin >> K;
    int N = s.length();

    vector<string> key;
    for(int i = 0; i < N; i++){
        for(int k = 1; k <= K; k++){
            if(i+k <= N)    key.push_back(s.substr(i,k));
        }
    }

    sort(key.begin(), key.end());
    key.erase(unique(key.begin(), key.end()), key.end());
    cout << key[K-1] << endl;
    return 0;
}


Measured memory_bytes: 1660
#include <stdio.h>
int main ( void )
{
    int i, n, total = 0, min, sum = 0, tmp;
    int w[100];
    scanf("%d", &n);
    for ( i = 0; i < n; i++ )
    {
        scanf("%d", &w[i]);
        total += w[i];
    }
    min = total;
    for ( i = 0; i < n; i++ )
    {
        sum += w[i];
        tmp = total - 2 * sum; 
        if ( tmp < min )
        {
            if ( tmp < 0 )
            {
                if ( -tmp < min )
                    printf("%d", -tmp);
                else
                    printf("%d", min);
                return 0;
            }
            min = tmp;
        }
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int s;
  while(cin >> s, s) {
    REP(i,9) {
      int a;
      cin >> a;
      s -= a;
    }
    cout << s << endl;
  }
}

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

int D,M,d,q;
int c[30];
int s[400][30];
int type[400];
int last[29];
ll satis_level[400];

ll calc_score(){
  rep(i,0,D+2) satis_level[i] = 0;
  rep(j,1,27) last[j]=0;
  ll down_satis;
  rep(i,1,D+1){
    down_satis=0;
    last[type[i]] = i;
    satis_level[i] += s[i][type[i]];
    rep(j,1,27) down_satis += c[j]*(i-last[j]);
    satis_level[i] -= down_satis;
    satis_level[i+1] += satis_level[i];
  }
  return satis_level[D];
}

int main(){
  map<int,int, std::greater<int>> mp;
  cin >> D;
  rep(i,1,27){
    cin >> c[i];
    mp[c[i]]=i;
  }
  rep(i,1,D+1){
    rep(j,1,27){
      cin >> s[i][j];
    }
  }
  
  int j=1;
  for(auto i=mp.begin();j<=D;++i,j++) {
    type[j] = mp[i->first];
  }
  
  ll pre_score,new_score;
  int d,q,pq;
  pre_score = calc_score();
  random_device rnd; 
  mt19937 mt(rnd());
  uniform_int_distribution<> rand_d(1,D); 
  uniform_int_distribution<> rand_q(1,26); 
  rep(i,1,10000){
    d = rand_d(mt);
    q = rand_q(mt);
    pq = type[d];
    type[d] = q;
    new_score = calc_score();
    if(pre_score > new_score) type[d] = pq;
    else pre_score = new_score;
    if(pre_score > new_score && i%1000==0) type[d] = q;
  }
  
  rep(i,1,D+1) cout << type[i] << '\n';
  return 0;
}


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

int main(){
  vector<int> A(3);
  for(int i=0;i<3;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  for(int i=0;i<3;i++){
    cout << A.at(i);
    if(i!=2){
      cout << " ";
    }
  }
  cout << endl;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define M 110


int main(){
	IOS;
	tihs;


	string s;cin>>s;
	ll k;cin>>k;
	ll n=sz(s);
	ll ans=0,i=0,j=n-1,c1=0,c2=0;
	while(s[j]==s[n-1] and j>=0)c1++,j--;
	while(s[n-1]==s[i] and i<j)c2++,i++;
	if(i==j+1){
		cout<<(c1+c2)*k/2;
		return 0;
	}
	while(i<j){
		if(s[i]==s[i+1])i+=2,ans++;
		else i++;
	}
	cout<<ans*k+((c1+c2)/2)*(k-1)+(c1/2+c2/2);


	return 0;
}

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

int main(void)
{
  char s[100];
  scanf("%s", &s);
  
  int n;
  n = strlen(s);
  
  int i = 0;
  int k = n - 1;
  while (i < n / 2)
  {
    if (s[i] != s[k])
    {
      printf("No");
      return 0;
    }
    i++;
    k--;
  }
  
  int s2, s3;
  s2 = (n - 1) / 2 - 1;
  s3 = (n + 3) / 2 - 1;
  i = 0;
  k = n - 1;
  while (i < n / 2)
  {
    if (s[i] != s[s2] || s[s3] != s[k])
    {
      printf("No");
      return 0;
    }
    i++;
    s2--;
    s3++;
    k--;
  }
  
  printf("Yes");
  return 0;
}


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

int main(){
  string S;
  cin >> S;
  if (S[2]==S[3] && S[4]==S[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

const int MAXN = 300;

char mat[MAXN + 1][MAXN + 1];

inline int get(int x, int n) {
    if(x > n)
        x -= n;
    return x;
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, n;
    ios::sync_with_stdio(false);
    cin >> n;
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= n; j++) {
            cin >> mat[i][j];
        }
    }
    int ans = 0;
    for(int b = 0; b < n; b++) {
        bool flag = 1;
        for(i = 1; i <= n && flag; i++) {
            for(j = 1; j <= n && flag; j++) {
                if(mat[i][get(j + b, n)] != mat[j][get(i + b, n)]) {
                    flag = 0;
                }
            }
        }
        if(flag)
            ans++;
    }
    cout << ans * n;
    //cin.close();
    //cout.close();
    return 0;
}


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

using namespace std;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << std::endl;
}

template<typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

#else
#define trace(...)
#endif
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<ll> VLL;
 
const int dx[] = {-1, 0, 1, 0, -1,-1, 1, 1};
const int dy[] = { 0, 1, 0,-1, -1, 1,-1, 1};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1,  -1, 2 , -2, 2,-2, 1,-1};

#define MP make_pair
#define PB push_back
#define F first
#define S second
#define SZ(x)	       x.size()
#define MAX(a, b)      ((a)>(b)?(a):(b))
#define MIN(a, b)      ((a)<(b)?(a):(b))
#define ALL(a)         std::begin(a), std::end(a)
#define Fill(n,x)      memset(n,x,sizeof n);
#define IN_REP         int _t; cin >> _t ; while(_t--)
#define IOS            ios::sync_with_stdio(false);cin.tie(NULL)
#define Cin(a)         cin>>a;
#define Cin2(a,b)      cin>>a>>b;
#define Cin3(a,b,c)    cin>>a>>b>>c;
#define Cin4(a,b,c,d)  cin>>a>>b>>c>>d;
#define Cout(n)	       cout<<n<<endl;
#define REP(i,n)       for(int i=0;i<(n);i++)
#define FOR(i,a,b)     for(int i=(a);i<(b);i++)
#define FORR(i,n)      for(int i=(n);i>=0;i--)
#define EPS 1e-9

template <typename T> inline T GCD(T a,T b)   {ll t;while(a){t = a;a = b%a;b = t;}return b;}
template <typename T> inline T Pow(T base,T exp){ll result = 1;while (exp){if(exp&1)result*=base;exp>>=1;base*=base;}return result;}
template <typename T> inline T Mulmod(T a, T b, T c){ll x = 0,y = a%c;while(b>0){if(b&1) x = (x+y)%c;y = (y<<1)%c;b >>= 1;}return x;}
template <typename T> inline T Pow(T base,T exp,T mod){ll x = 1, y = base;while(exp>0){if(exp&1) x = Mulmod(x,y,mod);y = Mulmod(y,y,mod);exp >>= 1;}return x;}
template <typename T> inline T Cube(T a){return a*a*a;}

#define MAXN 1000005
const int MOD = (int) 1e9 + 7;
int n, q, m, k;
ll a[MAXN];

int main() {
    IOS;
    #ifdef RDS
  	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  	freopen("log.txt", "w", stderr); 
    #endif
    cin >> n >> m;
	cout << n-m+1 << endl;
    #ifdef RDS
	  fprintf(stdout,"\nTIME: %.3lf sec\n", (double)clock()/(CLOCKS_PER_SEC));
    #endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int N;
int A[200005], A2[200005];
void Read()
{
    cin >> N;
    for(int i = 1; i <= N; i++)
        cin >> A[i], A2[i] = A[i];
    sort(A2 + 1, A2 + N + 1);
}
int main()
{
    Read();
    for(int i = 1; i <= N; i++)
    {
        if(A[i] >= A2[N / 2 + 1])
            cout << A2[N / 2] << "\n";
        else
            cout << A2[N / 2 + 1] << "\n";
    }
    return 0;
}


Measured memory_bytes: 3712
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)
# define ll long long

using namespace std;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll a1, a2;
  a1 = a*b;
  a2 = c*d;

  cout << max(a1, a2) << endl;
}


Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    a, b, c, d = i_map()
    
    print(a*b if a*b >= c*d else c*d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 72784
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define INF 1e9
#define MOD 1000000007
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main(void){
    int H,A;cin>>H>>A;
    if(H%A!=0)cout<<H/A+1<<endl;
    else cout<<H/A<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<math.h>
#include<sstream>
using namespace std;
int main(){
int a,b; cin >>a>>b;
int ans=0;
for(int i=a;i<=b;i++){

  int s=i%10, t=i/10000 %10;
  int u=i/10%10, v=i/1000%10;

  if(s==t&&u==v) ans++;
}
cout<<ans<<endl;

}


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int mod = 1e9 + 7;

int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}

const int MAXN = 1e5 + 5, inf = 1e9;

int n, pos[MAXN], l[MAXN];
vector <point> v;

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

  cin >> n;
  REP(i, n){
    cin >> pos[i] >> l[i];
    v.pb(point(pos[i] - l[i], pos[i] + l[i]));
  }
  sort(v.begin(), v.end(), [](const point &A, const point &B){
       if(A.second != B.second) return A.second < B.second;
       return A.first > B.first;
       });

  int sol = 0, curr = -inf;
  REP(i, n){
    if(v[i].first >= curr){
      curr = v[i].second;
      sol ++;
    }
  }
  cout << sol;
}



Measured memory_bytes: 2040
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	ll A,B;
	int K;
	cin >> A >> B >> K;
	
	for(int i=0;i<K;i++){
		if(i % 2 == 0){
			if(A % 2 == 1) A--;
			B += A/2;
			A /= 2;
		} else {
			if(B % 2 == 1) B--;
			A += B/2;
			B /= 2;
		}
	}
	
	cout << A << " " << B << endl;
	
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;


int main() {
    int n, k; cin >> n >> k;
    vector<int> l;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    sort(v.begin(),v.end());
    // rep(i,n) cout << v[i];
    // cout << endl;
    rep(i, n-k+1){
        // cout << v[i] << v[i+k-1] << endl;
        l.push_back(v[i+k-1] - v[i]);
    }
    cout << *min_element(l.begin(), l.end()) << endl;
    return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
bool dp[100005];
int main(){
    int x;
    scanf("%d", &x);
    dp[0] = 1;
    for(int i=100;i<=105;i++){
        for(int j=0;j<=x;j++){
            if(i+j <= x && dp[j]){
                dp[i+j] = 1;
            }
        }
    }
    if(dp[x]) printf("1\n");
    else printf("0\n");
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	int n;
	cin >> n;
	int hoge[9][9];
	rep(i, 9) rep(j, 9) {hoge[i][j] = 0;}
	int topnumber,bottomnumber;
	for(int i=1; i<=n; i++) {
		topnumber = i;
		while(topnumber >= 10) {
			topnumber /= 10;
		}
		bottomnumber = i % 10;
		if(bottomnumber != 0) {
			hoge[topnumber - 1][bottomnumber - 1]++;
		}
	}
	int answer = 0;
	rep(i,9) rep(j,9) {
		answer += hoge[i][j] * hoge[j][i];
	}
	cout << answer << endl;
/*	int answer = 0;
	// axxxb and bxxxa
	// a != b 72 cases
	// a == b 9 cases

	// a == b
	int k, p, q;
	int count = 1; //桁数
	while(k >= 10) {
		k = n / 10;
		count++;
	}
	p = n % 10;
	int pow3 = k;
	for(int s=1; s<count; s++) pow3 * 10;
	q = (n - k * pow3) / 10;
	int hoge[9];
	rep(i,9) {
		hoge[i] = 0;
	}
	for (int i = count; i > 0; i--)
	{
		if (i == count)
		{
			int pow2 = 1;
			for(int t=1; t<i-2; t++) {
				pow2 * 9;
			}
			rep(i,count-1) hoge[i] += pow2;
			if (p < k) hoge[count-1] += q-1;
			else hoge[count-1] += q;
		}
		if (i == 1) {
			rep(i,9) hoge[i] +=1;
		}
		if (i == 2) {
			rep(i,9) hoge[i] +=1;
		}
		if (i > 2 && i < count)
		{
			int pow = 1;
			for(int j=1; j<i-2; j++) {
				pow * 9;
			}
			rep(i,9) hoge[i] +=pow;
		}
	}
	
	rep(i,9) {
		answer += hoge[i] * hoge[i];
	}

	// a != b
	int fuga[9][9];
	rep(i,9) {
		rep(j,9) {
			fuga[i][j] = 0;
		}
	}

	for (int i=count;i > 0; i--) {
		if (i == count) {
			int pows = 1;
			for(int j=1; j<i-2; j++) {
				pows * 9;
			}
			rep(i,9) rep(j,9) {
				if (i == k && j == p) {
					fuga[i][j] += q;
				}
				else if (i <= k) {
					fuga[i][j] += pows;
				}
				else if (i == k && j < p) {
					fuga[i][j] += q;
				}
				else if (i == k && j > p) {
					fuga[i][j] += q-1;
				}
			}
		}
		if (i == 2) {
			rep(i,9) rep(j,9) {
				if (i != j) fuga[i][j] += 1;
			}
		}
		if (i > 2 && i < count) {
			int powr = 1;
			for(int j=1; j<i-2; j++) {
				powr * 9;
			}
			rep(i,9) rep(j,9) {
				if(i != j) fuga[i][j] +=powr;
			}
		}
	}
	rep(i,9) rep(j,9) {
		if (i < j) {
			answer += fuga[i][j] * fuga[j][i];
		}
	}
	cout << answer << endl;
	*/

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>

int main(int argc, const char * argv[]) {
    // insert code here...
    int n;
    scanf("%d", &n);
    
    int m;
    scanf("%d", &m);
    
    std::map<int, std::set<int>> map;
   
    for (int i = 0; i < m; i++) {
        int k;
        scanf("%d", &k);
        
        std::set<int> set;
        
        for (int j = 0; j < k; j++) {
            int x;
            scanf("%d", &x);
            
            set.insert(x - 1);
        }
        
        map[i] = set;
    }
    
    std::vector<bool> p;
    
    for (int i = 0; i < m; i++) {
        int x;
        scanf("%d", &x);
        
        p.push_back(x);
    }
    
    int count = 0;
    
    for (int i = 0; i < std::pow(2, n); i++) {
        bool on = true;
        
        for (int j = 0; j < m; j++) {
            bool sw = false;
            
            for (int k : map.at(j)) {
                sw = sw ^ ((i & (int) std::pow(2, k)) != 0);
            }
            
            if (sw != p.at(j)) on = false;
        }
        
        if (on) count++;
    }
    
    printf("%d\n", count);
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
#define endl "\n"
#define vst vector<char>
#define vll vector<ll>
#define fo(i, x, y)   for (__typeof(x) i = x; i < y; ++i)
#define fr(i, x, y)   for (__typeof(x) i = x; i > y; i--)
#define sort(a) stable_sort(a.begin(),a.end())
#define sortd(a) stable_sort(a.begin(),a.end(),greater<int>())
#define vpr vector<pair<ll,ll>>
#define gcd(a,b) __gcd(a,b)
#define TC ll t; cin>>t; while(t--)
#define F first
#define S second
const ll N=1e9+7;
ll lcm(ll x,ll y){return (x*y*1LL)/gcd(x,y);}
 
ll power(ll x, ll y){ 
    ll res = 1; 
    while (y > 0){
        if (y & 1) 
            res = ((res) * (x));
        res %= N; 
        y = y >> 1; 
        x = ((x) * (x)); 
    }
    return res; 
}
 
ll powmod(ll a,ll b,ll n)
{
    ll x=1, y=a; 
    while (b > 0) 
    {
        if (b%2 == 1) 
        {
            x = (x*y) % n;
        }
        y = (y*y) % n; 
        b /= 2;
    }
    return x % n;
}
ll prime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            return 0;
        }
    }
    return 1;
}

  

int main()
{
   fast;
   ll n;
   cin>>n;
   ll a[n];
   fo(i,0,n)
   cin>>a[i];
   ll dp[n]={0};
   dp[1]=abs(a[1]-a[0]);
   
   fo(i,2,n)
   {
       ll v1=dp[i-1]+abs(a[i]-a[i-1]);
       ll v2=dp[i-2]+abs(a[i]-a[i-2]);
       dp[i]=min(v1,v2);
   }
   cout<<dp[n-1]<<endl;

   
    
}  


Measured memory_bytes: 5240
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
int n,d; 
int main(){
	cin>>n>>d;
	d=d*2+1;
	cout<<(n+d-1)/d<<endl;
return 0;
}


Measured memory_bytes: 256
#Problem D
N = int(input())
a = list(map(int,input().split()))

atm = 1000

for i in range(N-1):
    kb = 0
    if a[i+1] > a[i]:
        kb = atm//a[i]
        atm -= a[i]*kb
        atm += a[i+1]*kb
    elif a[i+1] < a[i]:
        pass

print(atm)



Measured memory_bytes: 61912
#include<bits/stdc++.h>
#include<iostream>
#define ll long long
using namespace std;
const int maxn=1e6+7;
const ll mod=2017;
//ll a[2000][2000];
bool u[2000];
ll n,m;
ll a[maxn],f[maxn];
int main()
{
    scanf("%lld %lld",&n,&m);
    ll mi=0x3f;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        mi=min(mi,a[i]);
    }
    ll z=-1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==mi)
        {
            z=i;
            //break;
        }
    }
    ll f1=max(1ll,z-m+1);
    ll ans=1<<30;
    for(ll i=f1;i<=z;i++)
    {
        ans=min(ans,(n-i-1)/(m-1)+(i+m-3)/(m-1));
    }

    ans++;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 4352
import java.util.*;
import java.io.*;
import java.math.BigInteger;
//267630EY
public class Main
{
  static PrintWriter out=new PrintWriter(System.out);

  public static void main(String[] args) throws IOException
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] a=sc.nextIntArray(n);
    int sum=0;
    for(int i=0;i<n;i++)
    {
        sum+=a[i];
    }
    BigInteger pos=BigInteger.ONE;
    int ans=0;
    for(int x:a)
    {
        pos=pos.or(pos.shiftLeft(x));
    }
    for(int i=(sum+1)/2;i<=sum;i++)
    {
        if(pos.testBit(i))
        {
            ans=i;
            break;
        }
    }
    out.println(ans);
    out.flush();



        
   
      
      
                
    
  }
  
  static class Scanner
  {
    BufferedReader br;
    StringTokenizer tk=new StringTokenizer("");
    public Scanner(InputStream is) 
    {
      br=new BufferedReader(new InputStreamReader(is));
    }
    
    public boolean hasNext()
    {
      

      boolean result=false;
      
      try 
      {
        result = br.ready();
      } 
      catch (IOException e)
      {
        System.err.println(e);
      }
      return result;
    }
    
    public int nextInt() throws IOException
    {
      if(tk.hasMoreTokens())
        return Integer.parseInt(tk.nextToken());
      tk=new StringTokenizer(br.readLine());
      return nextInt();
    }
    public long nextLong() throws IOException
    {
      if(tk.hasMoreTokens())
        return Long.parseLong(tk.nextToken());
      tk=new StringTokenizer(br.readLine());
      return nextLong();
    }
    public String next() throws IOException
    {
      if(tk.hasMoreTokens())
        return (tk.nextToken());
      tk=new StringTokenizer(br.readLine());
      return next();
    }
    public String nextLine() throws IOException
    {
      tk=new StringTokenizer("");
      return br.readLine();
    }
    public double nextDouble() throws IOException
    {
      if(tk.hasMoreTokens())
        return Double.parseDouble(tk.nextToken());
      tk=new StringTokenizer(br.readLine());
      return nextDouble();
    }
    public char nextChar() throws IOException
    {
      if(tk.hasMoreTokens())
        return (tk.nextToken().charAt(0));
      tk=new StringTokenizer(br.readLine());
      return nextChar();
    }
    public int[] nextIntArray(int n) throws IOException
    {
      int a[]=new int[n];
      for(int i=0;i<n;i++)
        a[i]=nextInt();
      return a;
    }
    public long[] nextLongArray(int n) throws IOException
    {
      long a[]=new long[n];
      for(int i=0;i<n;i++)
        a[i]=nextLong();
      return a;
    }
    public int[] nextIntArrayOneBased(int n) throws IOException
    {
      int a[]=new int[n+1];
      for(int i=1;i<=n;i++)
        a[i]=nextInt();
      return a;
    }
    public long[] nextLongArrayOneBased(int n) throws IOException
    {
      long a[]=new long[n+1];
      for(int i=1;i<=n;i++)
        a[i]=nextLong();
      return a;
    }
  }
}



Measured memory_bytes: 222408
#include<bits/stdc++.h>
using namespace std;
int n,v,ans,a[100005],b[100005];
int main(){
	scanf("%d%d",&n,&v);
	for (int i=1;i<=n;i++)
		scanf("%d%d",&a[i],&b[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	for (int i=n;i>=1&&b[i]>a[n]&&v>0;v-=b[i],i--,ans++);
	if (v>0) ans=ans+v/a[n]+(v%a[n]!=0);
	printf("%d\n",ans);
}

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

int main()
{
  int n, m;
  vector<vector<char>> a(50, vector<char>(50)), b(50, vector<char>(50));
  bool flag;

  cin >> n >> m;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
      cin >> a[i][j];
  }
  for (int i = 0; i < m; i++)
  {
    for (int j = 0; j < m; j++)
      cin >> b[i][j];
  }
  for (int i1 = 0; i1 < n - m + 1; i1++)
  {
    for (int i2 = 0; i2 < n - m + 1; i2++)
    {
      flag = true;
      for (int j = 0; j < m; j++)
      {
        for (int k = 0; k < m; k++)
        {
          if (a[i1+j][i2+k] != b[j][k])
          {
            flag = false;
            break;
          }
        }
        if (!flag)
          break;
      }
      if (flag)
        break;
    }
    if (flag)
      break;
  }
  cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x) std::sort(ALL(x), greater<decltype(x)::value_type>())
#define RSORT2(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)
#define FCT(x) [](int a) -> int {int r = 1; REP(i, a){r *= i;} return r;}(x)

itn main() {
	std::ios::sync_with_stdio(false);

	int a, b, c, d;

	cin >> a >> b >> c >> d;

	if (c >= b) {
		cout << 0;
	}
	else {
		cout << max(min(b, d) - max(a, c), (int)0);
	}

	return 0;
}


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

const int MAX_E = 200*100;
const int MAX_N = 200*100;
double data[200][4];

struct UnionFind
{
  int par[MAX_N];
  int rank[MAX_N];

  void init(int n){
    for(int i = 0; i < n; ++i){
      par[i] = i;
      rank[i] = 0;
    }
  }
  int find(int x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(rank[x] < rank[y]) par[x] = y;
    else{
      par[y] = x;
      if(rank[x] == rank[y]) rank[x]++; 
    }
  }
  bool same(int x, int y){
    return find(x) == find(y);
  }
};
struct Edge {
  int u, w;
  double cost;
};
bool comp(const Edge &e1, const Edge &e2)
{
  return e1.cost < e2.cost;
}

Edge es[MAX_E]; 
int v, e; 
    UnionFind uf;


int main()
{
  for(;;){
    int n;
    scanf("%d",&n);
    if(n==0)return 0;
    //double data[n][4];
    e = n*(n-1)/2;
    v = n;
    
    uf.init(n*(n-1)/2);

    for(int i=0;i<n;i++){
      cin >> data[i][0] >> data[i][1] >> data[i][2] >> data[i][3];
    }

    int count=0;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	Edge et;
	et.u=i;
	et.w=j;
	double length = sqrt(((data[i][0]-data[j][0])*(data[i][0]-data[j][0]))+((data[i][1]-data[j][1])*(data[i][1]-data[j][1]))+((data[i][2]-data[j][2])*(data[i][2]-data[j][2])))-data[i][3]-data[j][3];
	if(length<0.0){
	  uf.unite(i,j);
	  length=0.0;
	}
	et.cost=length;
	es[count++]=et;
      }
    }
    
    //printf("A:%d %d\n",count,e);

    sort(es,es+e,comp);
    double ans = 0.0;

    for(int i = 0; i < e; ++i){
      Edge et = es[i];
      //printf("B:%f\n",et.cost);
      if(!uf.same(et.u, et.w)){
	uf.unite(et.u, et.w); 
	ans += et.cost; 
      }
    }
    
    printf("%.3f\n",ans);

  }
}
  

Measured memory_bytes: 1428
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//????????????
void lntrim(char *str) {  
  char *p;  
  p = strchr(str, '\n');  
  if(p != NULL) {  
    *p = '\0';  
  }  
}  
int main(void) {
	char words[201]={};
	char ring[401]={};
	//????????°??????????????\???
	fgets(words, sizeof(words), stdin);	
	lntrim(words);
	//????????????2????????????
	strcpy(ring,words);
	strcat(ring,words);
	
	char search[101]={};
	//????´¢??????????????\???
	fgets(search, sizeof(search), stdin);
	
	lntrim(search);
	//????´¢
	printf(strstr(ring,search)!=NULL ? "Yes\n" : "No\n");
	
	return 0;
}

Measured memory_bytes: 528