akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
typedef long long int ll; 
typedef long double ld; 


int main()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll n;
	cin>>n;
	
	ll arr[n];
	
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	
	ll val = 1;
	
	ll st = 0;
	ll ans =  0;
	
	while(st<n)
	{
		ll flg = 0;
		for(ll i=st;i<n;i++)
		{
			if(arr[i]==val)
			{
				st = i;
				val++;
				ans++;
				flg = 1;
				break;
			}
		}
		
		if(flg==0)break;
		
	}
	
	ans = n-ans;
	
	if(ans==n)cout<<-1;
	else
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<vin> vvin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
const int MOD=1e9+7;

int main(){
  vll w(200);vvll dp(1000001,vll(2,MOD));
  rep(i,0,200){
    w[i]=((i+1)*(i+2)*(i+3))/6;
    
  }
  dp[0][0]=dp[0][1]=0;
  rep(i,1,1000001){
    rep(j,0,200){
      if(i>=w[j]&&dp[i-w[j]][0]!=MOD){
        dp[i][0]=min(dp[i-w[j]][0]+1,dp[i][0]);
        if(w[j]%2&&dp[i-w[j]][1]!=MOD){dp[i][1]=min(dp[i-w[j]][1]+1,dp[i][1]);}
      }
    }
  }
  ll n=1;
  while(n!=0){
    cin>>n;
    if(n==0)break;
    cout<<dp[n][0]<<" "<<dp[n][1]<<endl;
  }
}



Measured memory_bytes: 57300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





// editorialみた

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int ans = 0;
    rep(i, n) {
        if (i < n - 1 && h[i] < h[i + 1]) continue;
        int r = i;
        while (r + 1 < n && h[r] >= h[r + 1]) {
            r++;
            // cout << r << endl;
        }
        chmax(ans, r - i);
        i = r;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#coding:utf-8
import math

times = []
for i in range(5):
    times.append(int(input()))

last_item_index = -1
largest = -1

for i in range(5):
    if math.ceil(times[i] / 10)* 10 - times[i] > largest:
        largest = math.ceil(times[i] / 10)* 10 - times[i]
        last_item_index = i
        
for i in range(5):
    if not i == last_item_index:
        times[i] = math.ceil(times[i] / 10) * 10

print(sum(times))        


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
   
  long long int n,t,q;
  cin>>n>>t>>q;
  long long int p[n],h[n],s[n],ss[n];
  for(int i=0;i<n;i++){
      cin>>p[i]>>h[i];
      ss[i]=0;
  }
  long long int hs=-1,hc=-1,sc,ssc=0;
  for(int i=0;i<n;i++){
      if(h[i]==1){
          hc=i;
          if(hs==-1){
              hs=i;
          }
      }else{
          if(hc==-1){
              if(ssc==1){
                  s[i]=sc;
                  ss[i]=1;
              }
              
          }else{
              sc=(p[hc]+p[i])/2;
              ssc=1;
              s[i]=sc;
              ss[i]=1;
              s[hc]=sc;
              ss[hc]=1;
              for(int k=hs;k<hc;k++){
                  s[k]=sc;
                  ss[k]=1;
              }
              hs=-1;
              hc=-1;
          }
      }
  }
  for(int i=0;i<q;i++){
      int x;
      cin>>x;
      x--;
      if(ss[x]==0){
          if(h[x]==1){
              cout<<p[x]+t<<endl;
          }else{
              cout<<p[x]-t<<endl;
          }
      }else{
         if(h[x]==1){
             if(s[x]-p[x]>t){
                 cout<<p[x]+t<<endl;
             }else{
                 cout<<s[x]<<endl;
             }
         }else{
             if(p[x]-s[x]>t){
                 cout<<p[x]-t<<endl;
             }else{
                 cout<<s[x]<<endl;
             }
         }
      }
  }
    
}

Measured memory_bytes: 6200
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
		if(b&1)
		    r=(r*a)%m;
		b>>1;
		a=(a*a)%m;
	}
	return r%m;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,a,b; cin>>n>>a>>b;
	if(a==0)cout<<0<<endl;
	else
    {
        ll x = n/(a+b);
        ll y = n%(a+b);
        if(y>=a)y = a;
        cout<<x*a+y<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ff first
#define ss second
#define pb push_back
#define Inf  1e18
#define inf -1e18
#define mod 1000000007
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll,ll>;
using umll = unordered_map<ll,ll>;
using sll = set<ll>;
using msll = multiset<ll>;
using pll = pair<ll,ll>;
 
ll MUL(ll A,ll B){
  return (A%mod*B%mod)%mod;
}
 
ll ADD(ll A,ll B){
  return (A%mod+B%mod)%mod;
}
 
ull power(ll A,ll B) {
    ull RES = 1;
    while (B > 0)
    {
        if (B & 1)
            RES = RES*A;
        B = B>>1;
        A = A*A;
    }
  return RES;
}
 

 
void testcases(int cases){
			int N , M,K;
			cin >> N >> M >> K;
			int tot = 0;
			char arr[N+2][M+2];
			for(int i = 0 ;i < N ; i ++){
				for(int j =0 ;j < M ;j ++){
					cin >> arr[i][j];
					if(arr[i][j]=='#')
					tot++;
				}
			}
			vector<vector<int>>A;
			vector<vector<int>>B;
					for(int i = 0;i <(1<<N) ;i ++){
						vector<int>res;
							for(int j = 0; j <N ;j ++){
									if(i&(1<<j))
									res.pb(j);
							}
							//cout << res.size() << "\n";
							A.push_back(res);
					}
					for(int i = 0;i <(1<<M) ;i ++){
						vector<int>res;
							for(int j = 0; j <M ;j ++){
									if(i&(1<<j))
									res.pb(j);
							}
							//cout << res.size() << "\n";
							B.push_back(res);
					}
			
					long ans = 0;
					for(int i = 0;i < (int)A.size(); i ++){
						for(int j =  0;j < (int)B.size(); j ++){
							set<pair<int,int>>S;
							
									for(int k = 0;k < (int)A[i].size(); k ++){
										//cout << A[i][k] << " ";
										for(int l = 0 ;l < M ;l ++){
											if(arr[A[i][k]][l]=='#')
												S.insert({A[i][k],l});
										}
									}
									//cout << "\n";
									for(int k = 0;k < (int)B[j].size(); k ++){
										//cout << B[j][k] << " ";
										for(int l = 0 ;l < N ;l ++){
											if(arr[l][B[j][k]]=='#')
												S.insert({l,B[j][k]});
										}
									}
									if((tot-S.size())==K){
										//cout  << "H" << "\n";
									ans++;
								}
									//cout << "\n\n\n";
									//if((tot-cnt1)==K)
									//ans++;
									//if((tot-cnt2)==K)
									//ans++;
									
							}
					}
					cout << ans << "\n";
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
    ll t;
   // cin >> t;
   t = 1;
    ll Case =1 ;
    while(t--)
    {
      testcases(Case++);
    }
}



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

using namespace std;

#define box pair<pair<int,int>,pair<int,int>>

pair<int,int> split(pair<int,int> p, int length){
	if(p.first*2 + p.second*2 == 0) return make_pair(0,0);
	length %= p.first*2 + p.second*2;
	if(length < p.first){
		//north 
		return make_pair(length, 0);
	} else if(length < p.first + p.second){
		//east
		return make_pair(0, length - p.first);
	} else if(length < p.first*2 + p.second){
		//south
		return make_pair(p.first - (length - p.first - p.second), 0);
	} else if(length < p.first*2 + p.second*2){
		//west
		return make_pair(0, p.second - (length - p.first*2 - p.second));
	}
}

int main(){
	int n,w,d;
	while(cin >> n >> w >> d,n!=0 || w!=0 || d!=0){
		vector<pair<pair<int,int>,pair<int,int>>> v;
		v.emplace_back(make_pair(make_pair(0,0),make_pair(w,d)));
		for(int i=0;i<n;i++){
			int p,s;
			cin >> p >> s;
			pair<int,int> q = split(make_pair(v[p-1].second.first - v[p-1].first.first,v[p-1].second.second - v[p-1].first.second),s);
			int x1 = v[p-1].first.first;
			int y1 = v[p-1].first.second;
			int x2 = q.first + v[p-1].first.first;
			int y2 = q.second + v[p-1].first.second;
			int x3 = v[p-1].second.first;
			int y3 = v[p-1].second.second;
			for(int i=p-1;i<v.size()-1;i++){
				v[i] = v[i+1];
			}
			if(q.second == 0){
				box a = make_pair(make_pair(x1,y1), make_pair(x2,y3));
				box b = make_pair(make_pair(x2,y1), make_pair(x3,y3));
				if(x2 - x1 < x3 - x2){
					v[v.size()-1] = a;
					v.emplace_back(b);
				} else {
					v[v.size()-1] = b;
					v.emplace_back(a);
				}
			} else {
				box a = make_pair(make_pair(x1,y1),make_pair(x3,y2));
				box b = make_pair(make_pair(x1,y2),make_pair(x3,y3));
				if(y2 - y1 < y3 - y2){
					v[v.size()-1] = a;
					v.emplace_back(b);
				} else {
					v[v.size()-1] = b;
					v.emplace_back(a);
				}
			}
		}
		vector<int> ans;
		for(int unsigned i=0;i<v.size();i++){
			ans.emplace_back((v[i].second.first - v[i].first.first) * (v[i].second.second - v[i].first.second));
		}
		sort(ans.begin(),ans.end());
		for(int unsigned i=0;i<ans.size();i++){
			if(i != 0) cout << " ";
			cout << ans[i];
		}
		cout << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 2976
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n=nxt();
    while(n--)
        cout<<"ACL";
    cout<<endl;
	printclock;
	return 0;
}

Measured memory_bytes: 3724
import sys

x1,y1,x2,y2,x3,y3 = map(int,sys.stdin.read().split())

a,b = x2-x1,y2-y1
c,d = x3-x1,y3-y1

area = abs(a*d-b*c)/2
edge = (a*a+b*b)**.5, (c*c+d*d)**.5, ((a-c)**2+(b-d)**2)**.5

pelim = sum(edge)
r = area * 2 / pelim

L = max(edge)
answer = r*L/(r+r+L)
print(answer)

Measured memory_bytes: 3064
N, X = map(int, input().split())
A = list(map(int, input().split()))

ans = 1e19

"""
abcdef
f +4(f-e) + 9+(e-d) + 16(d-c) + ...
= 5f + 5e + 7d + 9c + 11b + 13a
"""
mul = [5] + [5 + 2*i for i in range(N)]
#print(mul)

CX = [0] * (N+1)

#cum_sum
for i in range(N):
  CX[i+1] = CX[i] + A[i]
  
for k in range(1,N+1): # Number of robots (this loop will be ended early)
  cost = N*X + k*X # pickup and throw costs(fixed with k)
  
  # partial point answer (not using cumulative sum)
  # for i in range(1,N+1):
  #  cost += A[N-i] * mul[(i-1)//k]
  ix = N
  loopc = 0
  while ix > 0:
    if ix-k > 0:
      cost += (CX[ix] - CX[ix-k]) * mul[loopc]
    else:
      cost += (CX[ix]) * mul[loopc]
    loopc += 1
    ix -= k
  
  #print(k,cost)
  ans = min(ans,cost)
  if N//k <= 1: # early stopping (after mul is 5 for all A's, cost is monotonicaly increasing)
    print(ans)
    exit(0)
    
#print(ans)
  
  

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

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    if (i % 2 == 0) {
      if (s[i] == 'L') {
        goto NO;
      }
    } else if (s[i] == 'R') {
      goto NO;
    }
  }
  goto YES;
YES:
  cout << "Yes" << endl;
  return 0;
NO:
  cout << "No" << endl;
  return 0;
}


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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define pp pop_back()
#define ll long long
#define ld long double
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

inline int min(int a, int b) {
    return (a > b) ? b : a;
}

inline int max(int a, int b) {
    return (a > b) ? a : b;
}

const int N = 2e5 + 10;
const int inf = 1e9+10;
const ll linf = 1e18+9;

ll n, m, k, t, a[N], b[N], id[N], ama, bma, ami = inf, bmi = inf, dma, dmi = inf;

bool cmp(int x,int y) {
    return a[x] < a[y];
}

int main() {
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) {
        scanf("%d%d",&a[i], &b[i]);
        if(a[i] > b[i])
            swap(a[i], b[i]);
        id[i] = i;
        ama = max(ama, a[i]);
        ami = min(ami, a[i]);
        bma = max(bma, b[i]);
        bmi = min(bmi, b[i]);
    }
    ll ret = (ama - ami) * (bma - bmi);
    sort(id + 1,id + n + 1, cmp);
    for(int i = 1; i <= n; i++) {
        dma = max(dma, b[id[i]]);
        dmi = min(dmi,b[id[i]]);
        ret = min(ret, (max(dma, a[id[n]]) - min(dmi, a[id[i+1]])) * (bma - ami));
    }
    printf("%lld\n", ret);
    return 0;
}


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

int main()
{
  int K, S;
  int res=0;
  cin >> K >> S;

  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
      int Z = S - (i+j);
      if (0 <= Z && Z <= K) res++;
    }
  }
  
  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;cin>>a>>b;
    int k;cin>>k;
    rep(i, k){
        if(i%2==0){
            if(a%2!=0){
                a-=1;
            }
            a/=2;
            b+=a;
        } else {
            if(b%2!=0){
                b-=1;
            }
            b/=2;
            a+=b;
        }
    }
    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	int a,N;
	cin >> N;
	int res = 0;
	int num = 1;
	for (int i = 0; i < N; ++i) {
		cin >> a;
		if (a == num) {
			++num;
		}
		else {
			++res;
		}
	}
	if (num == 1) {
		cout << -1 << endl;
	}
	else {
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

vector<int> a;

bool isOK(int index, int key) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key) {
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main()
{
	int n; cin>>n;
	rep(i,n)
	{
		int e;
		cin>>e;
		a.push_back(e);
	}
	sort(a.begin(),a.end());
	int count=0;
	for(int i=0;i<(n-2);i++)
		for(int j=i+1;j<(n-1);j++)
		{
			int find=binary_search(a[i]+a[j]);
			count+=find-j-1;
		}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

string A;
int cnt[26];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> A;
  for (char c : A) {
    cnt[c-'a']++;
  }
  int ans = A.size()*(A.size()+1)/2;
  for (int i = 0; i < 26; i++) {
    ans -= cnt[i]*(cnt[i]+1)/2;
  }
  ans++;
  cout << ans << endl;

  return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };




void solve() {
    int N; cin >> N;
	ll d[N][N];
	rep(i, N)rep(j, N) cin >> d[i][j];

	rep(k, N)rep(i, N)rep(j, N){
		if(d[i][j] > d[i][k] + d[k][j]){
			cout << -1 << endl;
			return;
		}
	}

	rep(k, N)rep(i, N)rep(j, N){
		if(k != i && i != j && j != k && d[i][j] == d[i][k] + d[k][j]){
			d[i][j] = INF;
		}
	}

	ll ans = 0;
	rep(i, N)rep(j, N){
		if(i<j && d[i][j] != INF) ans += d[i][j];
	}

	cout << ans << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n,m;
  cin >> n >> m;
  int key = m/n;
  int ans = 0;
  for(int i = key;i >= 0;i--){
    if((m-i)%i == 0){
      key = i;
      break;
    }
  }
  cout << key << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

K, X = map(int, input().split())

A = []
for i in range(X-K+1, X+K):
    A.append(str(i))

res = " ".join(A)
print(res)



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

using namespace std;

int main(int argc, char const* argv[])
{
    int N,A;
    cin>>N>>A;
    if((N%500)<=A){
        cout<<"Yes"<<endl;
    }   
    else{
        cout<<"No"<<endl;
    }   
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

string s;
int n,k;

main(){
  cin>>n>>k;
  cin>>s;
  s[k-1]=s[k-1]+'a'-'A';

  cout<<s<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

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

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int x; cin >> x;

  if (x == 1) {
    outl(1);
    return;
  }

  vector<int> a;
  for (int i = 2; i * i <= x; i++) {
    for (int d = i; d <= x; d *= i) {
      a.push_back(d);
    }
  }
  sort(a);
  outl(a[a.size() - 1]);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
 
int main() {
ll n;
cin>>n;
ll a[n]={};
ll counter=0;
ll f=0;
for(ll i=0;i<n;i++){
cin>>a[i];
counter+=a[i];}
sort(a,a+n);
if(counter%10!=0){
cout<<counter<<endl;}
else{
for(ll i=0;i<n;i++){
if(a[i]%10!=0){
cout<<counter-a[i]<<endl;
f++;
break;}}
if(f==0){
cout<<0<<endl;}}}


Measured memory_bytes: 256
# 122
# 対の値を出力する　A と T、C と G
# 入力値　A, C, G, T

# 入力
b = str(input())

# 処理
if b == "A":
    print("T")
elif b == "T":
    print("A")
elif b == "C":
    print("G")
elif b == "G":
    print("C")

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

using namespace std;

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

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

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

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

  dfs(0);

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


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

int N;
int s[101];

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

    cin >> N;
    int sum = 0;
    for(int i = 0; i < N; ++i){
        cin >> s[i];
        sum += s[i];
    }

    if(sum % 10 != 0){
        cout << sum << endl;
    }
    else {
        int ans = 0;
        for(int i = 0; i < N; ++i){
            if(s[i] % 10 != 0){
                ans = max(ans, sum - s[i]);
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast")   //Comment optimisations for an interatcive problem - use endl
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
 
using namespace std;
 
#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f              first                 
#define  s              second
#define  endl           "\n"
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" "<<endl;
#define  deb1(a)        cout<<a<<" "<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" "<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" "<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;            
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;
 
const ll   N     =  1e6+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test=1,n,u,v,a[N],dp[N];
vll adj[N];
multiset <int> s;

void dfs(int x, int par){
    int del = -1;
    s.insert(a[x]);
    auto it = s.lower_bound(a[x]);
    it++;
    if(it != s.end()) del = *it,s.erase(it);
    dp[x] = s.size();
    for(auto it : adj[x]){
        if(it != par) dfs(it,x);
    }
    s.erase(a[x]);
    if(del != -1) s.insert(del);
}

void solve(){
    cin>>n;
    for(int i = 1; i <= n; i++) cin>>a[i];
    for(int i = 1; i < n; i++){
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1,0);
    for(int i = 1; i <= n; i++) cout<<dp[i]<<endl;
}

int main(){
    fastio;
    //cin>>test;
    for(int i = 1; i <= test; i++){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}

Measured memory_bytes: 53692
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <assert.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
using namespace std;

// #define __DEBUG__

#ifdef __DEBUG__
bool debug_disabled = false;
#else
bool debug_disabled = true;
#endif

#define dbg if (debug_disabled) {} else cerr

void solve() {
    int S, W;
    cin >> S >> W;
    if (W >= S) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//FUNCTION

void solve(void)
{
  int N; cin>>N;
  vector<vector<char> > vvec (N,vector<char>(N,0));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      cin>>vvec[i][j];
    }
  }
  int ANS = 0;
  for (int w = 0; w < N; w++)
  {
    int check = 1;
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < N; j++)
      {
          if(vvec[i][(j+w)%N] != vvec[j][(i+w)%N])check = 0;
      }
    }
         if(check == 1) ANS++; 
  }
  cout<<ANS*N<<endl;
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

int n, m, s, g[2] = {0};
int memo[105][105] = {0};

int solve();

int main() {
  while(1) {
    cin >> n >> m >> s >> g[0] >> g[1];
    --s, --g[0], --g[1];
    if(n + m == 0) break;
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j) memo[i][j] = inf;
    for(int i = 0; i < m; ++i) {
      int a, b, c;
      cin >> a >> b >> c;
      --a, --b;
      memo[a][b] = c;
    }

    cout << solve() << endl;
  }
  return 0;
}

int solve() {
  int ans = inf;
  for(int i = 0; i < n; ++i) memo[i][i] = 0;
  for(int k = 0; k < n; ++k)
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j)
        memo[i][j] =
            min(memo[i][j], memo[i][k] + memo[k][j]);
  for(int i = 0; i < n; ++i)
    ans = min(ans,
              memo[s][i] + memo[i][g[0]] + memo[i][g[1]]);
  return ans;
}


Measured memory_bytes: 3052
#include<iostream>
#include<vector>
#include<queue>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  string s1,s2;
  cin >>s1;
  cin >>s2;
  
  reverse(s2.begin(),s2.end());

  if (s1==s2){
  cout << "YES";
  }else{
  cout << "NO";
  }
    return 0;
}






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

using namespace std;
int N, M, A, B, C, D, x1, x2, y1, y2;
int K[30][30];
int ans;
const int infty = 10000000;

int main() {
  // 初期化
  for (int i=0; i<30; i++) {
    for (int j=0; j<30; j++) {
      K[i][j] = infty;
    }
  }
  // 入力
  scanf("%d%d", &N, &M);
  for (int i=0; i<M; i++) {
    scanf("%d,%d,%d,%d", &A, &B, &C, &D);
    K[A][B] = C;
    K[B][A] = D;
  }
  scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);
  // Floyd-Warshall アルゴリズム
  for (int k=1; k<=N; k++) {
    for (int i=1; i<=N; i++) {
      for (int j=1; j<=N; j++) {
	if (K[i][j] > K[i][k] + K[k][j]) {
	  K[i][j] = K[i][k] + K[k][j];
	} 
      }
    }
  }
  ans = y1 - y2 - K[x1][x2] - K[x2][x1];
  printf("%d\n", ans);
}

Measured memory_bytes: 1176
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
typedef pair<int,int> P;
char s,t,b;
P dp[20][5][5];
char fld[5][5]={"ABC","DEF","GHI"};
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
P rep(int now,int y,int x){
	int X,Y,l,r;
	if(dp[now][y][x].second>=0)
		return dp[now][y][x];
	P pre,sum=P(0,0);
	if(now==0){
		if(fld[y][x]==t){
			return dp[now][y][x]=P(1,1);
		}
		return dp[now][y][x]=P(0,1);
	}
	for(int i=0;i<4;i++){
		X=x+dx[i];
		Y=y+dy[i];
		if(X>=0&&X<3&&Y>=0&&Y<3&&fld[Y][X]!=b){
			pre=rep(now-1,Y,X);
			sum=P(sum.first+pre.first,sum.second+pre.second);
		}
		else{
			pre=rep(now-1,y,x);
			sum=P(sum.first+pre.first,sum.second+pre.second);
		}
	}
		return dp[now][y][x]=sum;
}
int main(){
	int n;
	P ans;
	while(cin>>n,n){
		cin>>s>>t>>b;
		for(int i=0;i<=n;i++)
		for(int j=0;j<3;j++)
		for(int k=0;k<3;k++){
			dp[i][j][k].first=-1;
			dp[i][j][k].second=-1;
		}
		for(int i=0;i<3;i++)
		for(int j=0;j<3;j++){
			if(fld[i][j]==s){
				rep(n,i,j);
				ans=P(dp[n][i][j].first,dp[n][i][j].second);
			}
		}
		printf("%.8lf\n",(double)ans.first/ans.second);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
    string s; cin >> s;
    set<char>st;
    for(auto c : s){
        st.insert(c);
    }
    if(st.size() == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
void main() {
    writeln(readln.chomp.to!int ^^ 2 - readln.chomp.to!int);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>

using namespace std;
const int maxn = 1e5 + 5;
char s[maxn], t[maxn];
int q;
int preas[maxn], prebs[maxn];
int preat[maxn], prebt[maxn];

int main(){
    scanf("%s", s + 1);
    scanf("%s", t + 1);
    int n = strlen(s + 1);
    int m = strlen(t + 1);
    for(int i = 1;i <= n;i++){
        preas[i] = preas[i - 1] + (s[i] == 'A');
        prebs[i] = prebs[i - 1] + (s[i] == 'B');
    }
    for(int i = 1;i <= m;i++){
        preat[i] = preat[i - 1] + (t[i] == 'A');
        prebt[i] = prebt[i - 1] + (t[i] == 'B');
    }
    cin >> q;
    while(q--){
        int l1, r1, l2, r2;
        scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
        int cnt1 = preas[r1] - preas[l1 - 1];
        int cnt2 = prebs[r1] - prebs[l1 - 1];
        int cnt3 = preat[r2] - preat[l2 - 1];
        int cnt4 = prebt[r2] - prebt[l2 - 1];
        if(((cnt4 - cnt3) - (cnt2 - cnt1)) % 3 == 0){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}


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

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

  int cnt = 0;

  for(int i = 0; i < n; i++){
    int a;
    cin >> a;

    while(!(a % 2)){
      cnt++;
      a /= 2;
    }
  }

  cout << cnt << endl;

  return 0;

}


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

int value[1001];
int weight[1001];
int dp[1001][100001];

int main(){
	int N, W;
	cin >> N >> W;
	
	for(int i=0; i<N; i++) cin >> value[i] >> weight[i];
	
	for(int i=0; i<N; i++){
		for(int w=0; w<=W; w++){
			if(w-weight[i] >= 0) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
			else dp[i+1][w] = dp[i][w];
		}
	}
	
	cout << dp[N][W] << endl;
	
	return 0;
}


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

bool is_product_overflow(ll a, ll b) {
    if(a<(ll)(9223372036854775807)/b) return true;
    else return false;
}

int main(void){
    int n;
    cin>>n;
    vector<ll> v(n);
    rep(i, n){
        cin>>v[i];
    }
    rep(i, n) {
        if(v[i] == 0) {
            cout<<0<<endl;
            return 0;
        }
    }
    ll ans = 1;
    rep(i, n){
        if(is_product_overflow(ans, v[i])){//オーバーフリーしていない
            if(ans*v[i]<=(ll)1e18) {
                ans *= v[i];
            }
            else {
                cout<<-1<<endl;
                return 0;
            } 
        }
        else{
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4052
from itertools import product
H,W=list(map(int, input().split()))
M=[list(input()) for _ in range(H)]
S=set(product([-1,0,1],repeat=2))-{(0,0)}

for i in range(H):
  for j in range(W):
    if M[i][j]=='#':
      continue
    c=0
    for k in S:
      h=i+k[0]
      w=j+k[1]
      if 0<=h<H and 0<=w<W:
        if M[h][w]=='#':
          c+=1
    M[i][j]=str(c)
for i in range(H):
  print(''.join(M[i]))

Measured memory_bytes: 68892
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int Mod=998244353;
const int Phi=998244352;
const int N=2e5+5;
const int G=3;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
int n,m,len,L,R[N],A[N],B[N],fac[N],inv[N],f[2][N];
int mod(int x){return x>=Mod?x-Mod:x;}
void Prepare(int maxn){
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=maxn;i++)fac[i]=1ll*fac[i-1]*i%Mod;
	for(int i=2;i<=maxn;i++)inv[i]=1ll*inv[Mod%i]*(Mod-Mod/i)%Mod;
	for(int i=2;i<=maxn;i++)inv[i]=1ll*inv[i-1]*inv[i]%Mod;
}
int C(int n,int m){return n<m?0:1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;}
int Pow(int x,int y){
	int ans=1,tot=x;
	while(y){
		if(y&1)ans=1ll*ans*tot%Mod;
		tot=1ll*tot*tot%Mod;
		y>>=1;
	}
	return ans;
}
void NTT(int a[],int n,int f){
	for(int i=0;i<n;i++)if(i<R[i])swap(a[i],a[R[i]]);
	for(int i=1;i<n;i<<=1){
		int Wn=Pow(G,Phi+f*Phi/(i<<1));
		for(int j=0;j<n;j+=(i<<1)){
			int W=1;
			for(int k=0;k<i;k++){
				int x=a[j+k],y=1ll*W*a[j+k+i]%Mod;
				a[j+k]=mod(x+y);a[j+k+i]=mod(x-y+Mod);W=1ll*W*Wn%Mod;
			}
		}
	}
	if(f==-1){
		int Inv=Pow(n,Mod-2);
		for(int i=0;i<n;i++)a[i]=1ll*a[i]*Inv%Mod;
	}
}
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();m=read();
	int t=0;Prepare(2e5);
	len=1;L=0;while(len<=n+n+2){len<<=1;L++;}
	for(int i=0;i<len;i++)R[i]=(R[i>>1]>>1)|((i&1)<<(L-1));
	for(int i=0;i<=n;i++)f[t][i]=C(n,i);
	for(int i=m-1;i>=0;i--){
		t^=1;
		for(int j=0;j<len;j++)A[j]=B[j]=0;
		for(int j=0;j<n;j++)A[j]=inv[n-j+2];
		for(int j=0;j<=n;j++)B[j]=1ll*f[t^1][j]*fac[j+2]%Mod;
		NTT(A,len,1);NTT(B,len,1);
		for(int j=0;j<len;j++)A[j]=1ll*A[j]*B[j]%Mod;
		NTT(A,len,-1);
		for(int j=0;j<=n;j++)f[t][j]=mod(1ll*A[n+j]*inv[j]%Mod+1ll*f[t^1][j]*mod(C(j+1,2)+1)%Mod);
	}
	printf("%d",f[t][0]);
	return 0;
}

Measured memory_bytes: 5004
# D - Div Game
from collections import deque

def pf(N):
    ans = deque([])
    p = 2
    while N>1:
        if N%p==0:
            k = 0
            while N%p==0:
                N //= p
                k += 1
            ans.append(k)
        p += 1+(p>2)
        if p**2>N:
            p = N
    return ans

def func(a):
    tmp = 0
    while True:
        a -= tmp+1
        if a<0:
            return tmp
        else:
            tmp += 1

N = int(input())
ans = 0
l = pf(N)
while len(l)>0:
    ans += func(l.popleft())
print(ans)

Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    ll m,vv,p;
    cin>>n>>m>>vv>>p;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    sort(all(a));
    int lo = 0, hi = n-1;
    // rep(i,0,n) cerr<<a[i]<<" ";
    // cerr<<endl;
    while(lo<hi) {
        int v = vv;
        int mid = (lo+hi)/2;
        auto b = a;
        int count=0;
        b[mid] += m;
        --v;
        for(int i=0; i<mid && v>0; ++i) {
            b[i]+=m;
            --v;
        }
        ll totleft = ((ll)v)*m;
        rep(i,mid+1,n) {
            if(totleft<0) break;
            ll toadd = min(totleft,max(0LL,b[mid]-b[i]));
            // debug(i);
            // debug(toadd);
            totleft-=toadd;
            b[i]+=toadd;
        }
        for(int i=n-1;i>mid && totleft>0;--i) {
            ll toadd = min(m-(b[i]-a[i]), totleft);
            // debug(i);
            // debug(toadd);
            totleft -= toadd;
            b[i] += toadd;
        }
        // assert(totleft<=0);
        // debug(mid);
        // rep(i,0,n) cerr<<b[i]<<" ";
        // cerr<<endl;
        rep(i,0,n) if(i!=mid && b[i]>b[mid]) ++count;
        if(count<p) hi = mid;
        else lo = mid+1;
    }
    int ans = n-lo;
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    long a[N];
    long ans = 1;
    int ans_tmp=0;
    
    for(int i = 0;i<N; i++){
        cin >> a[i];
        if(a[i]==0){
            ans=0;
            cout << ans << endl;
            return 0;}
    }

    for(int i = 0;i<N; i++){
        
        if(a[i] > 1000000000000000000/ans){
            ans = -1;
            break;
        }
        ans = ans* a[i];
        
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main() {
  int n;
  cin>>n;
  if(n==1){
    cout<<0<<endl;
    return 0;
  }
  cout<<1<<endl;
}

Measured memory_bytes: 3592
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double aa = sc.nextInt();
        double bb = sc.nextInt();
        int a = (int)aa;
        int b = (int)bb;
        int d = a / b;
        int r = a % b;
        double f = aa / bb;
        System.out.println(d + " " + r + " " + String.format("%.5f", f));
      }
    }



Measured memory_bytes: 26372