akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

long long ncr(int n, int r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod(ll a,ll b,ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll y =  mod(a,b/2,m);
        return (y*y)%m;
    }
    else{
        return ((a%m)*mod(a,b-1,m))%m;
    }
}

ll modinv(ll a,ll m){
return mod(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}



int main()
{
    int n;
    int total_weight;
    cin>>n>>total_weight;
    vector<int>w(n+1),v(n+1);
    for(int i=1;i<=n;i++){
        cin>>w[i]>>v[i];
    }
    //states of dp->what is important so far
    //total weight so far, item number
    ll dp[n+1][total_weight+1];//current value

   for(int i=0;i<=n;i++){
    dp[i][0]=0;
   }
   for(int i=0;i<=total_weight;i++){
    dp[0][i]=0;
   }
   for(int i=1;i<=n;i++){
    for(int j=1;j<=total_weight;j++){
        if(j-w[i]>=0){
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
        }
        else{
            dp[i][j]=dp[i-1][j];
        }
    }
   }
    cout<<dp[n][total_weight];



    return 0;
}


Measured memory_bytes: 82488
import java.util.Scanner;


public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		for(;;)
		{
			int w = scanner.nextInt();
			int h = scanner.nextInt();
			
			if(w==0 && h==0)
			{
				break;
			}
			
			for(int i=0; i<w; i++)
			{
				for(int j=0; j<h; j++)
				{
					if((i%2==0 && j%2==0) || (i%2==1 && j%2==1))
					{
						System.out.print("#");
					}
					else
					{
						System.out.print(".");
					}
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}

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

#define DEBUG 0
 


int main() {
    long long A,B, V, W, T;

    cin >> A >> V >> B >> W >> T;

    long long length = (V - W) * T;


    if(abs(B-A) <= length){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }


    return 0;

 
}



Measured memory_bytes: 3636
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;
#define rep(i,n) for(long long i=0;i<n;i++)
#define Rep(i,n0,n) for(long long i=n0;i<n;i++)
#define Com(i,j,n) for(long long i=0;i<n-1;i++)for(long long j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;

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

int main (){
	long long NNN,MMM;
	cin >> NNN >> MMM;
	long long x[NNN],y[NNN],z[NNN];
	rep(i,NNN){
		cin >> x[i] >> y[i] >>z[i];
	}
	//+++
	long long maxx=0;


	long long sumppp=0;
	vector <long long> tempppp;
	long long ppp=0;
	rep(i,NNN){
		ppp = x[i] + y[i] + z[i];
		tempppp.push_back(ppp);
		ppp=0;
	}
	sort(tempppp.rbegin(),tempppp.rend());
	rep(i,MMM){
		sumppp += tempppp[i];
	}
	maxx= max(maxx,sumppp);



	long long sumppm=0;
	vector <long long> tempppm;
	long long ppm=0;
	rep(i,NNN){
		ppm = x[i] + y[i] - z[i];
		tempppm.push_back(ppm);
		ppm=0;
	}
	sort(tempppm.rbegin(),tempppm.rend());
	rep(i,MMM){
		sumppm += tempppm[i];
	}
	maxx= max(maxx,sumppm);



	long long sumpmp=0;
	vector <long long> temppmp;
	long long pmp=0;
	rep(i,NNN){
		pmp = x[i] - y[i] + z[i];
		temppmp.push_back(pmp);
		pmp=0;
	}
	sort(temppmp.rbegin(),temppmp.rend());
	rep(i,MMM){
		sumpmp += temppmp[i];
	}	
	maxx= max(maxx,sumpmp);



	long long sumpmm=0;
	vector <long long> temppmm;
	long long pmm=0;
	rep(i,NNN){
		pmm = x[i] - y[i] - z[i];
		temppmm.push_back(pmm);
		pmm=0;
	}
	sort(temppmm.rbegin(),temppmm.rend());
	rep(i,MMM){
		sumpmm += temppmm[i];
	}	
	maxx= max(maxx,sumpmm);



	long long summpp=0;
	vector <long long> tempmpp;
	long long mpp=0;
	rep(i,NNN){
		mpp =  -x[i] + y[i] + z[i];
		tempmpp.push_back(mpp);
		mpp=0;
	}
	sort(tempmpp.rbegin(),tempmpp.rend());
	rep(i,MMM){
		summpp += tempmpp[i];
	}	
	maxx= max(maxx,summpp);



	long long summpm=0;
	vector <long long> tempmpm;
	long long mpm=0;
	rep(i,NNN){
		mpm =  -x[i] + y[i] - z[i];
		tempmpm.push_back(mpm);
		mpm=0;
	}
	sort(tempmpm.rbegin(),tempmpm.rend());
	rep(i,MMM){
		summpm += tempmpm[i];
	}	
	maxx= max(maxx,summpm);



	long long summmp=0;
	vector <long long> tempmmp;
	long long mmp=0;
	rep(i,NNN){
		mmp =  -x[i] - y[i] + z[i];
		tempmmp.push_back(mmp);
		mmp=0;
	}
	sort(tempmmp.rbegin(),tempmmp.rend());
	rep(i,MMM){
		summmp += tempmmp[i];
	}	
	maxx= max(maxx,summmp);



	long long summmm=0;
	vector <long long> tempmmm;
	long long mmm=0;
	rep(i,NNN){
		mmm =  -x[i] - y[i] - z[i];
		tempmmm.push_back(mmm);
		mmm=0;
	}
	sort(tempmmm.rbegin(),tempmmm.rend());
	rep(i,MMM){
		summmm += tempmmm[i];
	}	
	maxx= max(maxx,summmm);

	cout << maxx << endl;



	return 0;
}


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

vector<long long int> a;

long long int make(long long int b){
  	if(b>1000000010) return 0;
	a.push_back(b*10+3);
  	make(b*10+3);
  	a.push_back(b*10+5);
  	make(b*10+5);
  	a.push_back(b*10+7);
  	make(b*10+7);
}

bool check(long long int c){
  	string s;
	s=to_string(c);
  	bool three=false;
  	bool five=false;
  	bool seven=false;
  
	for(int i=0;i<s.size();i++){
    	if(s[i]=='3') three=true;
      	if(s[i]=='5') five=true;
      	if(s[i]=='7') seven=true;
    }
	if(three==true && five==true && seven==true){
    	return true;
    }else{
    	return false;
    }
}

int main() {
  	long long int n;cin>>n; 
 	make(0);
  	int cnt=0;
  	for(int i=0;i<a.size();i++){
    	if(a[i]>=356 && a[i]<=n){
        	if(check(a[i])) cnt++; 
        }
    }
  	cout<<cnt<<endl;
}


Measured memory_bytes: 1400
import sys
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
P = list(map(int, inputs[1].split()))
EP = [0.5*p + 0.5 for p in P]

buffer = sum(EP[:k])
Q = [buffer]
for i in range(k, n):
    buffer += EP[i] - EP[i-k]
    Q.append(buffer)
print(max(Q))

Measured memory_bytes: 24596
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
using namespace std;
double a[55];
int main()
{
    int n;cin>>n;
    for(int i=0;i<n;i++)
		cin>>a[i];
		for(int i=0;i<n-1;i++)
		{
			sort(a+i,a+n);
			a[i+1]=(a[i+1]+a[i])/2;
		}
	cout<<a[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int a,b1,b2,c=0;
	scanf("%d", &a);

	b1 = a / 500;
	c += b1 * 1000;

	a -= 500 * b1;
	b2 = a / 5;
	c += b2 * 5;

	printf("%d", c);
}

Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
S = input()

for i in range(1, len(S)//2):
	c = len(S) - 2*i
	ss = S[:c]
	if ss[:c//2] == ss[c//2:]:
		print(c)
		exit()
else:
	print(0)

Measured memory_bytes: 5204
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  LL N;
  cin >> N;
  vector<LL> A(N);
  vector<LL> B(N);
  LL Asum = 0;
  LL Bsum = 0;
  REP(i, N)
  {
    cin >> A[i];
    Asum += A[i];
  }
  REP(i,N){
    cin >> B[i];
    Bsum += B[i];
  }

  if(Bsum>Asum){
    cout << -1 << endl;
  }else{
    LL sum = 0;
    LL cnt = 0;
    vector<LL> hoge(0);
    REP(i, N)
    {
      LL diff = A[i] - B[i];
      if(diff>0){
        hoge.push_back(diff);
      }
      else if (diff < 0)
      {
        sum -= diff;
        cnt++;
      }
    }
    BACKSORT(hoge);

    LL idx = 0;
    while (sum > 0)
    {
      sum -= hoge[idx];
      idx++;
    }

    cout << idx+cnt << endl;
  }
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

int p;

// factorial(階乗)の計算

ll fac[10000] ={};

ll c_fac(int n) {
  if (fac[n]!=0) return fac[n];
  if (n==0) return fac[n]=1;
  return fac[n] = (c_fac(n-1)*n)%p;
}

// inverse(逆元)の計算

ll inv(ll a,ll m) {
  ll b = m, x = 1, y = 0;
  while (b!=0) {
    ll d = a/b;
    a -= b*d; swap(a, b);
    x -= y*d; swap(x, y);
  }
  return x>=0 ? x : x+m;
}

// combinataionの計算

ll nck(ll n, ll k) { 
  c_fac(n);
  if (n<k) return 0;
  ll nume = fac[n];
  ll deno = ( inv(fac[n-k],p) * inv(fac[k],p) ) % p;
  return ( nume * deno ) % p;
}

int main() {
  cin >> p;
  ll result[p]={};
  ll p1ck[p]; rep(i,p) p1ck[i] = nck(p-1,i);
  rep(i,p) {
    int a; cin >> a;
    if (a==0) continue;
    ll k = -1;
    rep(j,p) {
      ll b = k * p1ck[j];
      result[(p-1)-j] += b;
      result[(p-1)-j] %= p;
      k *= -1*i; k %= p;
    }
    result[0] += 1;
  }
  rep(i,p) result[i] = (result[i]%p+p)%p;
  rep(i,p) cout << result[i] << " "; cout << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int s;
	cin>>s;
	if(s==1||s==2||s==4){
		cout<<4;
	}
	else{
		int c=s;
		int ans=1;
		while(c!=4){
			if(c%2)c=3*c+1;
			else c=c/2;
			ans++;
		}
		cout<<ans+3;
	}
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

int main()

{

    string ss;
    cin >> ss;
    ll k;
    cin >> k;
    for(ll i = 0; i < ss.size(); i++)
    {

        if(ss[i] != '1')
        {

            cout << ss[i];
            return 0;
        }
        else if(i==k-1)
        {

            cout << ss[i];
            return 0;
        }
    }
}


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

int main()
{
	stack<int> car;
	vector<int> outlist;
	int carnum;

	while( cin >> carnum )
	{
		if(carnum)
		{
			car.push(carnum);
		}
		else
		{
			outlist.push_back(car.top());
			car.pop();
		}
	}

	for(size_t i=0; i<outlist.size(); ++i)
	{
		cout << outlist[i] << '\n';
	}
}

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

int main() {
  int n; cin >> n;
  cout << (n + 1000 - 1) / 1000 * 1000 - n << endl;
  return 0;
}

Measured memory_bytes: 3620
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    long int n,i,sum=0,sumtotal=0,fizzbuzzsum;
    cin>>n;
    
    for(i=1;i<=n;i++)
    {
        sumtotal+=i;
        if(i%5==0 || i%3==0)
        {sum+=i;}
    }
    fizzbuzzsum=sumtotal-sum;
    cout<<fizzbuzzsum;
    
        
    
    
    
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) cout << (x) << endl;
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;
const int MOD = 1000000007;
 
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string s;
	cin >> s;
	int ans = INF;
	rep(i, s.size() - 2) {
		string tmp = "";
		REP(j, i, i + 3) {
			tmp += s[j];
		}
		int n = stoi(tmp);
		chmin(ans, abs(753 - n));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>


main(){
	int N,l,r,i;
	int sum = 0;
	scanf("%d",&N);

	for(i = 0; i < N; i++){
		scanf("%d %d",&l,&r);
		sum += r - l + 1;
	}

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

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 10000000;
typedef double D;
const D EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> II;

/** Problem0059 : Intersection of Rectangles **/
struct  P {
	D x, y;
	P() {}
	P(D x_, D y_) : x(x_), y(y_) {}
};

struct Rec {
	P p1, p2;
};

int main()
{
	Rec r1, r2;
	while (cin>>r1.p1.x>>r1.p1.y>>r1.p2.x>>r1.p2.y>>r2.p1.x>>r2.p1.y>>r2.p2.x>>r2.p2.y) {
		if (r1.p2.x < r2.p1.x || r1.p1.x > r2.p2.x || r1.p2.y < r2.p1.y || r1.p1.y > r2.p2.y)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
	}
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for(int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int val = a[0];
	int cnt = 0;
	int ans = 0;
	for(int i = 0; i < N; i++) {
		if(val != a[i]) {
			if(cnt >= val) ans += cnt - val;
			else ans += cnt;
			cnt = 1;
			val = a[i];
		} else {
			cnt++;
		}
	}
	if(cnt >= val) ans += cnt - val;
	else ans += cnt;
	cout << ans << endl;
	return 0;

}

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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, ans = 1;
    cin >> n;
    vector<string> s(2);
    cin >> s[0] >> s[1];
    set<string> se; // 色確定済み

    rep(i, n) {
        // 縦
        if(s[0][i] == s[1][i]) {
            se.insert(s[0].substr(i, 1));
            if(i == 0) {
                ans = (ans*3)%MOD;
            }
            // もう一つ前も縦
            else if(s[0][i-1] == s[1][i-1]) {
                ans = (ans*2)%MOD;
            }
            // もう一つ前は横
            else {
                ans *= 1;
            }
        }
        // 横
        else {
            // もう見た
            if(se.count(s[0].substr(i, 1))) {
                continue;
            }
            // 新しい
            else {
                se.insert(s[0].substr(i, 1));
                if(i == 0) {
                    ans = (ans*6)%MOD;
                }
                // もう一つ前は縦
                else if(s[0][i-1] == s[1][i-1]) {
                    ans = (ans*2)%MOD;
                }
                // もう一つ前も横
                else {
                    ans = (ans*3)%MOD;
                }
            }
        }
    }

    cout << ans << endl;  

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
        ret %= MOD;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count))%MOD;
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


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


int main() {
  // 科目の数Nを受け取る
  int N, A, B;
  cin >> N;
  A = 0, B = 0;

  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  for (int m = 0; m < N; m++) {
    if (m % 2 == 0) {
      A += p.at(m);
    }
    else {
      B += p.at(m);
    }
  }
  cout << A - B << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int m, n;
        cin >> m >> n;
        if(m == 0)
            return 0;

        vector<int> book(n+1);
        book[0] = 0;
        cin >> book[1];
        for(int i=2; i<=n; ++i){
            cin >> book[i];
            book[i] += book[i-1];
        }

        int a = 1;
        int b = 1500000;
        while(a != b){
            int c = (a + b) / 2;
            int k = 1;
            for(int i=0; i<m; ++i){
                k = upper_bound(book.begin()+k, book.end(), book[k-1] + c) - book.begin();
                if(k == n+1)
                    break;
            }

            if(k == n+1)
                b = c;
            else
                a = c+1;
        }

        cout << a << endl;
    }
}

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

/* clang-format off */
#define int long long
struct Fast {Fast() {cin.tie(0); ios::sync_with_stdio(false);}} fast;

#define reps(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n+1)
#define deps(i, a, n) for (int i = (a); i >= (int)(n); --i)
#define dep(i, n) deps(i, n, 0)
#define each(i, n) for (auto&& i : n)

template <typename T> inline size_t maxElement(T beginIt, T endIt) { return max_element(beginIt, endIt); }
template <typename T> inline size_t minElement(T beginIt, T endIt) { return min_element(beginIt, endIt); }
template <typename T> inline size_t maxIndex(T beginIt, T endIt) { return distance(beginIt, *max_element(beginIt, endIt)); }
template <typename T> inline size_t minIndex(T beginIt, T endIt) { return distance(beginIt, *min_element(beginIt, endIt)); }
template <typename T> inline int sum(T beginIt, T endIt) { return accumulate(beginIt, endIt, 0); }
template <typename T> inline int mean(T beginIt, T endIt) { return sum(beginIt, endIt) / distance(beginIt, endIt); }
template <typename T> inline void debug(T x) { cerr << x << " " << "(L:" << __LINE__ << ")" << endl; }
/* clang-format on */

signed main(void) {
  /* */
  int num = 0; // num
  // int num = numeric_limits<int>::min(); // max
  // int num = numeric_limits<int>::max(); // min
  int N;
  array<int, 200000> A;
  string S;
  /* */

  cin >> N;

  rep(i, N) {
    cin >> A[i];
    A[i] -= i + 1;
  }

  sort(A.begin(), A.begin() + N);

  int b = A[N / 2];
  rep(i, N) num += abs(A[i] - b);

  cout << num << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

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

	static boolean solve() {
		int w = in.nextInt();
		int h = in.nextInt();
		if (w + h == 0) return false;

		int[][] t = new int[h][w];
		for (int i=0; i<h; i++) {
			for (int j=0; j<w; j++) {
				t[i][j] = in.nextInt();
			}
		}

		int[][] dp = new int[h][w];
		for (int i=0; i<w; i++) {
			if (t[0][i] == 0) dp[0][i] = 1;
		}

		for (int i=1; i<h; i++) {
			for (int j=0; j<w; j++) {
				if (t[i][j] == 1) continue;
				int sum = 0;
				if (j - 1 >= 0 && t[i][j] != 2 && t[i-1][j-1] == 0) {
					sum += dp[i-1][j-1];
				}
				if (j + 1 < w && t[i][j] != 2 && t[i-1][j+1] == 0) {
					sum += dp[i-1][j+1];
				}
				if (t[i-1][j] == 0) {
					sum += dp[i-1][j];
				}
				if (i - 2 >= 0 && t[i-2][j] == 2) {
					sum += dp[i-2][j];
				}
				dp[i][j] = sum;
			}
		}

		int ans = 0;
		for (int i=0; i<w; i++) {
			ans += dp[h-1][i];
			if (h - 2 >= 0 && t[h-2][i] == 2) {
				ans += dp[h-2][i];
			}
		}

		out.println(ans);

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 31844
s=input()

n=int((len(s)-1)*0.5)
ans="Yes"
for i in range(n):
  if (s[i]==s[n-1-i]) & (s[n+1+i]==s[n*2-i]) & (s[i]==s[n*2-i]):
    continue
  else:
    ans="No"
    break

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int M=1e9+7;
main(){
  int n,k,a=1;cin>>n>>k;
  r(i,n)a=(a*k)%M;
  cout<<a<<endl;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll long long
#define MAX
using namespace std;



int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;
    cin>>n;
    vector <int> dp(3);
    for(int i=0;i<n;i++){
        vector <int> c(3);
        vector <int> temp_dp(3);
        cin>>c[0]>>c[1]>>c[2];
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
               if(i != j) temp_dp[i] = max(temp_dp[i], dp[j] + c[i]);

               dp = temp_dp;
    }
    cout<<max({dp[0],dp[1],dp[2]})<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h,w;
    cin >> h >> w;
    char a[h][w];
    for(int i = 0;i < h;i++)
    {
        for(int j = 0;j < w;j++)
        {
            cin >> a[i][j];
        }
    }
    for(int i = 0;i < w + 2;i++)
    {
        cout << "#";
    }
    cout << "\n";
    for(int i = 0;i < h;i++)
    {
        cout << "#";
        for(int j = 0;j < w;j++)
        {
            cout << a[i][j];
        }
        cout << "#" << "\n";
    }
    for(int i = 0;i < w + 2;i++)
    {
        cout << "#";
    }
    
    return 0;
}

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

typedef long long int ll;

char s[1000000],t[1000000];

int main()
{
	scanf("%s",s);
	scanf("%s",t);
	ll count=0;
	for(ll i=0;i<strlen(s);i++)
		if(s[i]==t[i])
			count++;
	if(count==strlen(s))
		printf("Yes\n");
	else
		printf("No\n");
}
	


Measured memory_bytes: 3768
fun main(args :Array<String>) {
    val (x, y) = readIntegerList()
    println(x + y / 2)
}

fun readInteger() = readLine()!!.toInt()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


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

using ll = long long; 

const int mod = 1e9+7;

const int nax = 3005;

int dp[nax][nax];

char cmp[nax];

int add(int a, int b) {
    int c = a + b;
    if (c >= mod) {
        c -= mod;
    }
    return c;
}

int subtract(int a, int b) {
    int c = a - b;
    if (c < 0) {
        c += mod;
    }
    return c;
}

int main() {
    int n;
    scanf("%d", &n);
    scanf("%s", cmp);
    vector<int> pref_sum = vector<int>(n+1);
    dp[1][1] = 1;
    pref_sum[1] = 1;
    for (int len = 2; len <= n; len++) {
        for (int b = 1; b <= n; b++) {
            int L, R;
            if (cmp[len-2] == '<') {
                L = 1;
                R = b-1;
            }
            else {
                L = b;
                R = len-1;
            }
            dp[len][b] = add(dp[len][b], subtract(pref_sum[R], pref_sum[L-1]));
        }
        for (int b = 1; b <= n; b++) {
            pref_sum[b] = add(dp[len][b], pref_sum[b-1]);
        }
    }
    int answer = pref_sum[n];
    printf("%d", answer);
	return 0;
}


/*
nax = 3005
dp = [[0 for _ in range(nax)] for _ in range(nax)]
mod = 1e9+7
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c
def subtract(a, b):
    c = a - b
    if c < 0:
        c += mod
    return c

# dp[i][j] - the number of ways to put numbers in prefix of size 'i'
# such that the last number is 'j'
def main():
    n = int(raw_input())
    s = raw_input()    
    pref_sum = [0 for _ in range(n+1)]
    dp[1][1] = 1
    pref_sum[1] = 1
    for length in range(2, n+1):
        
        for b in range(1, length+1):
            if s[length-2] == '<':
                L = 1
                R = b-1
            else: # == '>'
                L = b
                R = length-1
            
            dp[length][b] = add(dp[length][b], subtract(pref_sum[R], pref_sum[L-1]))
            
            # for i in range(L, R+1):
            #     dp[length][b] = add(dp[length][b], dp[length-1][i])
                
            # for a in range(1, length):
            #     real_a = a
            #     if a >= b:
            #         real_a += 1
            #     if (real_a < b) != (s[length-2] == '<'):
            #         continue
            #     dp[length][b] = add(dp[length][b], dp[length-1][a])
        for b in range(1, length+1):
            pref_sum[b] = dp[length][b]
            pref_sum[b] = add(pref_sum[b], pref_sum[b-1])
        
    answer = 0
    for i in range(1, n+1):
        answer = add(answer, dp[n][i])
    answer = int(answer)
    print(answer)
    
main()

*/

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

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; }
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using pint = pair<int, int>; 
using pll  = pair<ll, ll>;
using vint = vector<int>; 
using vll  = vector<ll>;
using vstr = vector<string>;

//　定数, 変数 *********************************************
const ll MOD=1e9+7;
const ll INF=1ll<<60;

int X;

// *********************************************************
int main(){

    cin >> X;

    if(X <= 599){
        cout << '8';
    }else if(X <= 799){
        cout << '7';
    }else if(X <= 999){
        cout <<'6';
    }else if(X<=1199){
        cout<<'5';
    }else if (X<=1399){
        cout<<'4';
    }else if(X<=1599){
        cout<<'3';
    }else if(X<=1799){
        cout<<'2';
    }else{
        cout<<'1';
    }
    
    cout << endl;



    return 0;
}

Measured memory_bytes: 3616
import sys
def input(): return sys.stdin.readline().strip()


def main():
    D, G = map(int, input().split())
    question = []
    bonus = []
    for i in range(D):
        p, c = map(int, input().split())
        question.append(p)
        bonus.append(c)

    """
    決め打ち二分探索と思い込んで「x問解いて得られる最大得点」を出そうとして撃沈。。。
    結局その発想をしたところで、肝は
        ・どのボーナスを得るか
        ・ボーナスを取らない「唯一の」得点群はどれか
    なので、それなら初めからこれに着目して問題を解いたうえで、それが得点Gを超えるかどうか
    確かめた方が早い。
    """ 

    ans = sum(question)
    for state in range(1 << D):
        # ビットが立ってたら全完
        score = 0
        num = 0
        solved = set([])
        for i in range(D):
            if state & (1 << i):
                solved.add(i)
                num += question[i]
                score += 100 * (i + 1) * question[i] + bonus[i]
        if score >= G:
            ans = min(ans, num)
            continue

        # G点未満の場合は解いてない問題のうち最高得点のものを追加で解く
        last_idx = D - 1
        while last_idx in solved: last_idx -= 1
        for i in range(question[last_idx]):
            score += 100 * (last_idx + 1)
            num += 1
            if score >= G:
                ans = min(ans, num)
                break
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 40816
#include<stdio.h>

int search(int *,int,int);

int main(){
  int i,n,A[10000+1],b,x,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  scanf("%d",&b);
for(i=0;i<b;i++){
  scanf("%d",&x);
  if(search(A,n,x))sum++;
 }
 printf("%d\n",sum);

 return 0;
}

int search(int A[], int n, int x){
  int i=0;
  A[n]=x;
  while(A[i]!=x) i++;
  return i!=n;
}



Measured memory_bytes: 2104
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int N;

int rate[8];

int unq_low;
int cnt_high;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		if (a < 400)rate[0]++;
		else if (a < 800)rate[1]++;
		else if (a < 1200)rate[2]++;
		else if (a < 1600)rate[3]++;
		else if (a < 2000)rate[4]++;
		else if (a < 2400)rate[5]++;
		else if (a < 2800)rate[6]++;
		else if (a < 3200)rate[7]++;
		else cnt_high++;
	}
	for (int i = 0; i < 8; i++)if (rate[i] != 0)unq_low++;

	cout << max(unq_low, 1) << " " << unq_low + cnt_high << endl;





	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main{
    static Scanner s = new Scanner(System.in);
    static int score;
    static int[][] puzzle;

    public static void main(String[] args) {
        while (true){
            int H = s.nextInt();
            if(H==0)break;

            score=0;
            puzzle = new int[H][5];
            for(int i=0;i<H;i++){
                for(int j=0;j<5;j++){
                    puzzle[i][j]=s.nextInt();
                }
            }

            while (true) {
                boolean flag = vanish();
                if(!flag) break;
                move();
            }
            System.out.println(score);
        }
    }

    static boolean vanish(){
        boolean flag=false;
        for(int i=0;i<puzzle.length;i++){
            int nowNum=puzzle[i][0];
            int count=1;
            for(int j=1;j<5;j++){
                if(nowNum!=0 && nowNum==puzzle[i][j]){
                    count++;
                } else{
                    if(count>=3){
                        puzzle[i]=erase(puzzle[i],j-1,count,nowNum);
                        flag=true;
                        break;
                    }else{
                        count=1;
                        nowNum=puzzle[i][j];
                    }
                }

                if(j==4 && count>=3){
                    puzzle[i]=erase(puzzle[i],j,count,nowNum);
                    flag=true;
                }
            }
        }
        return flag;
    }

    static int[] erase(int[] puzzleLine,int num,int count,int point){
        for(int i=num;i>num-count;i--){
            puzzleLine[i]=0;
        }
        score+=point*count;
        return puzzleLine;
    }

    static void move(){
        for(int j=0;j<5;j++){
            int temp=puzzle.length-1;
            for(int i=puzzle.length-1;i>=0;i--){
                if(puzzle[i][j]!=0){
                    puzzle[temp][j]=puzzle[i][j];
                    temp--;
                }
            }
            for(int i=temp;i>=0;i--){
                puzzle[i][j]=0;
            }
        }
    }
}

Measured memory_bytes: 49700
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int ans = -1;
  int now = -1;
  REP(i, N){
    if(now+1 >= A[i]){
      if(now+1 == A[i]) ans++;
      else ans += A[i];
      now = A[i];
    }
    else{
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int n;
	int pa[65001],jo[65001];
	int i,j;
	long long int s,l,max;
	
	scanf("%d",&n);
	while(n!=0){
		s=0;
		for(i=0;i<n;i++){
			scanf("%d",&pa[i]);
			s+=pa[i];
		}
		for(i=0;i<n-1;i++){
			scanf("%d",&jo[i]);
			s+=jo[i];
		}
		sort(jo,jo+n-1);
		l=s;
		max=s;
		j=0;
		for(i=2;i<=n;i++){
		/*	printf("%d\n",l);*/
		//	printf("%d\n",jo[i-2]);
			l-=jo[j];
			s=l;
			s*=i;
			if(max<s){
				max=s;
			}
			j++;
		}
		printf("%lld\n",max);
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1552
S = input()
T = input()
n = len(S)
m = len(T)

ans = 'UNRESTORABLE'
for i in range(n - m + 1):
    flag = 1
    for j in range(m):
        if T[j] == S[i + j] or S[i + j] == '?':
            continue
        else:
            flag = 0
    if flag:
        ans = S[0 : i] + T + S[i + m :]
        ans = ans.replace('?', 'a')

print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class Program{
  public static void Main(){

    var input = Console.ReadLine().Split();
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);
    
    int ans = Math.Min(a+b,Math.Min(b+c,c+a));
    
    Console.WriteLine(ans);

  }
}


Measured memory_bytes: 13140
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b,x;
	while(cin>>a>>b>>x) {
		ll ans = b/x+1 - (0<=a-1 ? (a-1)/x+1 : 0);
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

#define MOD 998244353

long add(long a, long b) { long res = a + b; if (res >= MOD) res -= MOD; return res; }

long sub(long a, long b) { long res = a - b + MOD; if (res >= MOD) res -= MOD; return res; }

long mult(long a, long b) { return (a * b) % MOD; }

map<string, long> mem;

long calc(string s) {
    long res = mem[s];
    if (res > 0) return res;
    if (s.length() == 0) return 1;
    if (s[0] == '0') {
        res = calc(s.substr(1, s.length() - 1));
    } else {
        res = calc(s.substr(1, s.length() - 1));
        res = add(res, res);
    }
    for (int a = 1; a * 2 <= s.length(); a++) {
        string ss = s.substr(0, a);
        for (int b = 2; a * b <= s.length(); b++) {
            for (int i = 0; i < a; i++) {
                if (s[(b - 1) * a + i] == '0') {
                    ss[i] = '0';
                }
            }
            long c = mult(calc(ss), calc(s.substr(a * b, s.length() - a * b)));
            res = add(res, c);
        }
    }
    mem[s] = res;
    return res;
}

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

    string s;
    cin >> s;
    cout << calc(s) << "\n";

    return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
int main(){
 
  char s;
  cin>>s;
  
 	switch(s){
        
      case 'a':
      case 'i':
      case 'u':
      case 'e':
      case 'o':
        
        cout<<"vowel"<<endl;
        break;
        
      default:
        
        cout<<"consonant"<<endl;
        
    }
}

Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        char[] str = scan.next().toCharArray();
        int n = str.length;
        TreeMap<Double, Integer> sumIdx = new TreeMap<>();
        for (char c = 'a'; c <= 'z'; c++){
            double sum = 0;
            sumIdx.clear();
            sumIdx.put(0.0, -1);
            for (int i=0;i<n;i++) {
                sum += str[i] == c? 0.5: -0.5;
                Map.Entry<Double, Integer> lower = sumIdx.lowerEntry(sum);
                if (lower != null) {
                    if (lower.getValue() == i - 1) lower = sumIdx.lowerEntry(lower.getKey());
                    if (lower != null) {
                        System.out.println(lower.getValue() + 2 + " " + (i+1));
                        return;
                    }
                }
                sumIdx.putIfAbsent(sum, i);
            }
        }
        System.out.println("-1 -1");
    }
}


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

int main(){
    int N;
    int ans =0;
    cin >> N;
    vector<int> bvec(N);
    for(int i=0;i<N-1;i++){
        cin >> bvec[i];
    }
    bvec[N-1] = bvec[N-2];
    for(int i=1;i<N-1;i++){
        ans +=min(bvec[i],bvec[i-1]);
    }
    ans += bvec[0]+bvec[N-1];
    cout << ans << endl;
}

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

int N,C;
int imos[31][100001];
int main(int argc, const char * argv[]) {
    int i,j;
    cin >> N >> C;
    
    int s,t,c;
    for (i = 0; i < N; i++) {
        cin >> s >> t >> c;
        imos[c][s-1] += 1;
        imos[c][t] -= 1;
    }
    for (j = 1; j < 31; j++) {
        for (i = 1; i < 100001; i++) {
            imos[j][i] += imos[j][i-1];
            //if (imos[j][i]) imos[j][i] = 1;
        }
    }
    
    for (j = 1; j < 31; j++) {
        for (i = 0; i < 100001; i++) {
            if (imos[j][i]) imos[j][i] = 1;
        }
    }
    
    int ans = 0;
    for (i = 1; i < 100001; i++) {
        int sum = 0;
        for (j = 1; j < 31; j++) {
            sum += imos[j][i];
        }
        ans = max(sum, ans);
    }
    cout << ans << endl;
    
    return 0;
}


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

const int INF = 1001001001;

int main() {
  int h, w;
  cin >> h >> w;

  vector<vector<int>> c(10, vector<int>(10, INF));
  rep(i, 10) rep(j, 10) cin >> c[i][j];

  rep(k, 10) rep(i, 10) rep(j, 10) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);

  ll ans = 0;
  rep(i, h) rep(j, w) {
    int a;
    cin >> a;
    if (a == -1) continue;
    ans += c[a][1];
  }

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


Measured memory_bytes: 3568
import math
from sys import stdin
input = stdin.readline


def main():
  N = int(input())

  div = 0
  for i in range(int(math.sqrt(N)), 0, -1):
    if N % i == 0:
      div = i
      break

  print(div - 1 + N//div - 1)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 63184
#include <bits/stdc++.h>
using namespace std;
int main()
{  
	int a[4][4];
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			cin>>a[i][j];
		}
	}
	int b[4][4]={0};
	int n,x;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;	
		for(int i=1;i<=3;i++)
		{
			for(int j=1;j<=3;j++)
			{
				if(a[i][j]==x)
					b[i][j]=1;
			}
		}
	}
	for (int i=1;i<=n;i++)
		if(b[i][1]==1&&b[i][2]==1&&b[i][3]==1)
		{
			cout<<"Yes";
			return 0;
		}
	for (int j=1;j<=n;j++)
		if(b[1][j]==1&&b[2][j]==1&&b[3][j]==1)
			{
				cout<<"Yes";
				return 0;
			}
	if(b[1][1]==1&&b[2][2]==1&&b[3][3]==1)
		{
			cout<<"Yes";
			return 0;
		}
	if(b[1][3]==1&&b[2][2]==1&&b[3][1]==1)
		{
			cout<<"Yes";
			return 0;
		}
	cout<<"No";	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(int argc,char const *argv[]) {
    string str;
    cin>>str;
    map<char,bool> M;
    for(int i=0;i<str.size();i++) {
        M[str[i]]=true;
    }
    for(char i='a';i<='z';i++) {
        if(!M[i]) {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
    return 0;
}


Measured memory_bytes: 512
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
def main():
    N, M, K = map(int, readline().split())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    #方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める
    #A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。

    csumA = [0]
    for i in range(N):
        csumA.append(csumA[i] + A[i])

    csumB = [0]
    for i in range(M):
        csumB.append(csumB[i] + B[i])

    mx = 0
    for i in range(N+1):
        # r:= Aの山の上からi番目までの本を読むとき、残りの時間
        if K < csumA[i]:
            break
        left = -1
        right = M+1
        while right-left>1: 
            mid = (left+right)//2
            if K - csumA[i] >= csumB[mid]:
                left = mid
            else:
                right = mid
        mx = max(mx, i+left)
    print(mx)

if __name__ == '__main__':
    main()


Measured memory_bytes: 140184
#include "bits/stdc++.h"

using namespace std;

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

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

vector<vector<int>> c(3, vector<int>(3));
bool check(int b, int b2, int b3) {
	vector<vector<int>> cc = c;

	int cnt = 0;
	for (int i = 0; i < 3; i++) {
		if (c[i][0] - b == c[i][1] - b2
			&& c[i][0] - b == c[i][1] - b2
			&& c[i][1] - b2 == c[i][2] - b3) {
			cnt++;
		}
	}

	return cnt == 3;
}

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

	vector<int> ma(3);
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> c[i][j];
			ma[i] = max(ma[i], c[i][j]);
		}
	}

	for (int i = 0; i <= ma[0]; i++) {
		for (int j = 0; j <= ma[1]; j++) {
			for (int k = 0; k <= ma[2]; k++) {
				if (check(i, j, k)) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}

	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256