akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep01(i, n) for(int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for(int i = 1; i < (n); i++)
#define rep11(i, n) for(int i = 1; i < (n) + 1; i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
typedef struct { int x; int y; } Pos;
using namespace std;
const ll E9P7 = 1000000007; 

int main(){
    string s;
    cin >> s;
    if (s[s.length() - 1] == 's')
        cout << s << "es";
    else
        cout << s << "s";
    return 0;
}

Measured memory_bytes: 3624
#define z 1000000
a[z],b[z],n,i=1,x,c;main(){for(;i++<z;)a[i]=i;for(i=-1;i++<z;)if(a[i]){b[x++]=i;for(c=i;c<z;c+=i)a[c]=0;}while(~scanf("%d",&n)){c=0;while(b[c]<=n && b[c]!=0){c++;}printf("%d\n",c);}exit(0);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

const int mod = 2019;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vi d(n+1);
  int ten = 1;
  rREP(i, n) {
    int a = (s[i]-'0') * ten % mod;
    d[i] = (d[i+1]+a) % mod;
    ten *= 10; ten %= mod;
  }
  vi cnt(mod);
  ll ans = 0;
  rREPo(i, n) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4392
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys

INF = float('inf')


def solve(N: int, D: int, X: "List[int]", Y: "List[int]"):
    return sum(D*D >= (p*p + q*q) for p, q in zip(X, Y))


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    Y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    print(f'{solve(N, D, X, Y)}')


if __name__ == '__main__':
    main()


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

#define ll long long int
#define mem(n) memset(n,0,sizeof(n))
#define LCM(a,b) (a / __gcd(a,b) ) * b
#define gcd(a,b) __gcd(a,b)
#define for0(l,n) for(int l=0;l<n;l++)
#define for1(l,n) for(int l=1;l<=n;l++)
#define bug(n) cout<<">> "<<n<<" <<";
#define pb push_back
#define P1(a) cout<<a<<endl;
#define P2(a,b) cout<<a<<" "<<b<<endl;
#define P3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define S1(a) cin>>a
#define S2(a,b)cin>>a>>b
#define S3(a,b,c) S2(a,b),S2(c)
#define squerit(n) (ll)n*n
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)

bool vowel(char a)
{
    a= toupper(a);
    if((a=='A')||(a=='E')||(a=='I')||(a=='O')||(a=='U'))return 1;
    return 0;
}

ll n,m,q,a,b,c,sum=0,cnt=0;
ll arr[1000055];
map<ll,bool>mp;
string str;

ll can(ll x)
{
    if(arr[n-1]!=2)return -1;
    for0(i,n)
    {
        if(x<arr[i])
        {
            return 0;
        }
        ll div = x/arr[i];
        div *= arr[i];
        x = div;
    }
    return x;
}

int main()
{
    FastRead;
    cin>>n;
    for0(i,n)
    {
        cin>>arr[i];

    }
    vector<ll>v;
    ll big = 2, fin = 1000000000000000000;

    while(big<=fin)
    {
        ll mid = big+fin;
        mid/=2;
        a = can(mid);
        if(a==-1)
        {
            cout<<a<<endl;
            return 0;
        }
        //   if(mid==5||mid==6||mid==7||mid==8)cout<<mid<<"   "<<a<<endl;

        if(a==0||a==1)
        {
            big=mid+1;
        }
        else
        {
            fin = mid-1;
        }
        if(a==2)
        {
            v.pb(mid);
        }
    }
///   cout<<big<<" "<<fin<<endl;


    if(v.size())
    {
        sort(v.begin(),v.end());
        ll first = v[0];
        v.clear();
        ll big = first, fin = 1000000000000000000;

        while(big<=fin)
        {
            ll mid = big+fin;
            mid/=2;
            a = can(mid);
            if(a==-1)
            {
                cout<<a<<endl;
                return 0;
            }

            if(a==0||a==1||a==2)
            {
                big=mid+1;
            }
            else if(a>2)
            {
                fin = mid-1;
            }
            if(a==2)
            {
                v.pb(mid);
            }
        }

        if(v.size())
        {
            sort(v.begin(),v.end());

            cout<<first<<" "<<v[v.size()-1]<<endl;
        }
        else cout<<-1<<endl;



    }
    else cout<<-1<<endl;


}















Measured memory_bytes: 1024
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 1e5 + 5;
const int OO = 1e9;

void init() {

}

int n,a[N],b[N];
ll ans,cur;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;

    for(int i=0;i<n+1;++i) {

        cin >> a[i];

    }

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

        cin >> b[i];
        cur = min(b[i],a[i]);
        a[i] -= cur;
        b[i] -= cur;
        ans += cur;
        cur = min(b[i],a[i+1]);
        a[i+1] -= cur;
        ans += cur;

    }

    cout << ans << '\n';

    return 0;

}

Measured memory_bytes: 1024
#include<stdio.h>
int N,W,v[105],w[105],i,j,dp[10005]={0},r;

int main()
{
	scanf("%d%d",&N,&W);
	for(i=0;i<N;i++)
		scanf("%d%d",&v[i],&w[i]);
	for(i=0;i<N;i++)
		for(j=0;j<=W;j++)
			if(j-w[i]>=0)
			{
				dp[j]=dp[j]<dp[j-w[i]]+v[i]?dp[j-w[i]]+v[i]:dp[j];
				r=r<dp[j]?dp[j]:r;
			}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 636
import queue
import copy

H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
INF = H*W+1

def movable(S,S_dist,px,py):
    if  0 <= px and px < H and 0 <= py and py < W:
        if S_dist[px][py] == INF and S[px][py] == ".":
            return True
    return False

def bfs(S,sx,sy):
    S_dist = [[INF for _ in range(W)] for _ in range(H)]
    #Sを直接いじれば訪問済みかどうか管理できるがそれだと毎回Sをリセットする必要がある
    #S_distのみ書き込みにすればS_distはローカルだからリセットが不要
    S_dist[sx][sy] = 0
    q = queue.Queue()
    q.put((sx,sy))
    vec = [(0,1),(0,-1),(1,0),(-1,0)]
    ret = 0
    while not q.empty():
        p = q.get()
        ret = S_dist[p[0]][p[1]]
        for vx,vy in vec:
            if movable(S,S_dist,p[0]+vx,p[1]+vy):
                S_dist[p[0]+vx][p[1]+vy] = S_dist[p[0]][p[1]]+1
                q.put((p[0]+vx,p[1]+vy))
    return ret

ans = 0
for i in range(H*W):
    if S[i//W][i%W] == ".":
        ans = max(ans,bfs(S,i//W,i%W))
print(ans)


Measured memory_bytes: 4080
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n,m;
const int maxn=100111;
char s[maxn];
char t[maxn];
int main()
{
	getii(n,m);
	for(int i=0;i<n;i++)s[i]=getreal();
	for(int i=0;i<m;i++)t[i]=getreal();
	ll ans=1ll*n*m/__gcd(n,m);
	bool ok=1;
	for(int i=0;i<n;i++)
	{
		if((1ll*i*m)%n==0)
		{
			ok&=s[i]==t[1ll*i*m/n];
		}
	}
	if(!ok)puts("-1");else cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N; ll C; cin >>N >>C;
  vector<ll> x(N),v(N); rep(i, N) cin >>x[i] >>v[i];
  ll res = 0;
  priority_queue<ll> left1,left2;
  // どちらも差し引き得られるカロリーを入れていく
  // left1 : 原点から左に何個か寿司を取る
  // left2 : 原点から左に何個か寿司を取ってきて原点に帰ってくる

  // 原点から時計回りにn個～0個寿司を取るとして、各々について最適なやつを選ぶ
  ll right1 = 0, right2 = 0;
  rep(i, N){ right1 += v[i]; right2 += v[i];}
  right1 -= x[N-1]; right2 -= 2*x[N-1];
  // どちらも差し引き得られるカロリーを入れていく
  // right1 : 原点から右に何個か寿司を取る
  // right2 : 原点から右に何個か寿司を取ってきて原点に帰ってくる

  // left1, right2 と left2, right1 がセットになるイメージ
  // 右回りにn, n-1, ..., 2, 1, 0 個取るときを考える
  ll leftxsum = 0;
  ll leftvsum = 0;
  for (int i=N; i>=0; i--){
    if (i < N){
      right1 -= v[i] - x[i];   if (i != 0) right1 -= x[i-1];
      right2 -= v[i] - 2*x[i]; if (i != 0) right2 -= 2*x[i-1];
    }
    if (i < N){
      leftvsum += v[i];
      leftxsum = C - x[i];
    }
    left1.push(leftvsum - leftxsum);
    left2.push(leftvsum - 2*leftxsum);

    // 右に行って帰ってきて左に行くパターン
    chmax(res, right2 + left1.top());

    // 左に行って帰ってきて右に行くパターン
    chmax(res, left2.top() + right1);
  }

  cout <<res <<endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0


int main() {

    int N,K,L;
    Scd3(N,K,L);

    vector<vi> ek(N),el(N);
    auto buildG = []( vector<vi>& e, int M ){
        int x,y;
        Rep(i,M){
            Scd2(x,y);
            x--,y--;
            e[x].push_back(y);
            e[y].push_back(x);
        }
    };
    buildG(ek,K);
    buildG(el,L);

    vi idk(N),idl(N);
    auto allocateID = []( vi& id, vector<vi>& e ){
        int N = id.size();
        int cnt = 0;
        stack<int> s;
        Rep(i,N){
            if( id[i] ) continue;
            cnt++;
            id[i] = cnt; s.push(i);
            while( s.size() ){
                int from = s.top(); s.pop();
                for( int to : e[from] ){
                    if( !id[to] ){
                        id[to] = cnt; s.push(to);
                    }
                }
            }
        }
    };
    allocateID(idk,ek);
    allocateID(idl,el);

    map<pii,int> counter;

    Rep(i,N){
        // printf ("%lld %d %d\n", i, idk[i], idl[i] );
        counter[{idk[i],idl[i]}]++;
    }

    Rep(i,N){
        printf( "%d%s", counter[{idk[i],idl[i]}], i==N-1?"\n":" " );
    }


    return 0;
}



Measured memory_bytes: 27820
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,M;cin>>N>>M;
  vector<pair<ll,int> > A(N);
  repeat(i,N){
    cin>>A[i].first;
    A[i].second=1;
  }
  repeat(i,M){
    int B;ll C;cin>>B>>C;
    A.push_back({C,B});
  }
  sort(A.begin(),A.end(),greater<pair<ll,int> >());
  int cnt=0;
  ll sum=0;
  for(auto a:A){
    cnt += a.second;
    sum += a.first*a.second;
    if(cnt>N){
      sum -= a.first*(cnt-N);
      break;
    }
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 7136
N = int(input())
red = [tuple(map(int, input().split())) for _ in range(N)]
blue = [tuple(map(int, input().split())) for _ in range(N)]

red.sort(key=lambda x: (x[1], x[0]), reverse=True)
blue.sort(key=lambda x: (x[0], x[1]))

cnt = 0
for i in range(len(blue)):
    for j in range(len(red)):
        if red[j][0] < blue[i][0] and red[j][1] < blue[i][1]:
            cnt += 1
            del red[j]
            break
print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<deque>
#include<bitset>
#include<cmath>
#include<map>
#include<iomanip>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a; i < b; i++)

int main() {

	int n;
	cin >> n;

	vector<ll> a(n);
	ll max = 1e18;
	ll ans = 1;
	rep(i, 0, n) {
		cin >> a[i];
		if (a[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}

	rep(i, 0, n) {
		if (max / ans < a[i]) {
			cout << -1 << endl;
			return 0;
		}
		ans *= a[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4008
#include<iostream>
using namespace std;
int main(){
	int bound[10]={91,81,75,69,64,60,57,54,51,48};
	char rank[11][16]={"heavy","light heavy","middle","light middle"
		,"welter","light welter","light","feather","bantam","fly","light fly"};
	double w;
	while(cin>>w){
		int ans=10;
		for(int i=0;i<10;i++){
			if(bound[i] < w){
				ans=i;
				break;
			}
		}
		cout<<rank[ans]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 233333,mo=1e9+7;
int n,k,fac[N],ifac[N],res;
inline int power(int a, int n){
	int res=1;
	while(n){
		if(n&1)res=1LL*res*a%mo;a=1LL*a*a%mo;n>>=1;
	}
	return res;
}
inline void iniC(int n){
	fac[0]=1;rep(i,1,n)fac[i]=1LL*fac[i-1]*i%mo;
	ifac[n]=power(fac[n],mo-2);
	per(i,n-1,0)ifac[i]=1LL*ifac[i+1]*(i+1)%mo;
}
inline int C(int n, int m){return m>=0&&m<=n?1LL*fac[n]*ifac[m]%mo*ifac[n-m]%mo:0;}
int main() {
	read(n);read(k);iniC(2*n);
	if(k==1)res=1;
	else if(k==n)res=(C(2*(k-1)-1,k-1)-C(2*(k-1)-1,k)+mo)%mo;
	else{
		res=((1LL*C(n+k-2,n-1)-C(n+k-2,n)-C(2*k-2,k-1)+C(2*k-2,k)+C(2*k-3,k-1)-C(2*k-3,k))%mo+mo)%mo;
	}
	if(n-k-1>=0)res=1LL*res*power(2,n-k-1)%mo;
	cout<<res;
	return 0;
}


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

struct modint{
    using i64=int_fast64_t;
    i64 a;
    static constexpr i64 MOD=1000000007;
    modint(){a=0;}
    modint(i64 a_){
        a=a_%MOD;
        if(a<0) a+=MOD;
    }
    modint inv()const{
        i64 n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y;
        y.a=a+x.a;
        if(y.a>MOD) y.a-=MOD;
        return y;
    }
    modint operator-(const modint& x){
        modint y;
        y.a=a-x.a;
        if(y.a<0) y.a+=MOD;
        return y;
    }
    modint operator*(const modint& x){
        modint y;
        y.a=(a*x.a)%MOD;
        return y;
    }
    modint operator/(const modint& x){
        modint y;
        y.a=(a*x.inv().a)%MOD;
        return y;
    }
    modint& operator+=(const modint& x){
        a+=x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint& operator-=(const modint& x){
        a-=x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    modint& operator*=(const modint& x){
        (a*=x.a)%=MOD;
        return *this;
    }
    modint& operator/=(const modint& x){
        (a*=x.inv().a)%=MOD;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    int_fast64_t a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(int_fast64_t a,int_fast64_t b){
    modint _;
    int_fast64_t n=1,A=a;
    while(b){
        if(b&1) (n*=A)%=modint::MOD;
        (A*=A)%=modint::MOD;
        b>>=1;
    }
    _.a=n;
    return _;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,t;
    in>>n>>t;
    vector<int> a(n),b(n),p(n);
    fr(i,n) in>>a[i]>>b[i],p[i]=i;
    sort(p.begin(),p.end(),[&](int i,int j){
        return a[i]<a[j];
    });
    const int N=t+3001;
    vector<int> dp(N),ndp(N);
    int ans=0;
    for(int i:p){
        ndp.assign(N,0);
        ifr(j,N){
            if(j>=a[i]) ndp[j]=dp[j-a[i]]+b[i];
        }
        ans=max(ans,ndp[t+a[i]-1]);
        fr(j,N) dp[j]=max(dp[j],ndp[j]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

using namespace std;


int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	long long int num[200000] = {};
	for (int i = 0; i < N; i++) {
		cin >> num[i];
		num[i] = num[i] * MOD + i;
	}
	sort(num, num + N);
	set<int> s;
	s.insert(-1);
	s.insert(N);
	for (int i = 0; i < N; i++) {
		auto j = s.lower_bound(num[i] % MOD);
		long long int box = *j - num[i] % MOD;
		--j;
		box *= (num[i] % MOD - *j);
		box *= i + 1;
		ans += box;
		s.insert(num[i] % MOD);
		//cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}

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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 912345678;

string s;

int main()
{
    cin >> s;
    for (auto c : s)
    {
        if (c == '1')
        {
            cout << '9';
        }
        else if (c == '9')
        {
            cout << '1';
        }
        else
        {
            cout << c;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
import sys

S=input()
N=len(S)-1
op = ['']*N
for i in range(1<<N):
    ans = int(S[0])
    for j in range(N):
        if 1&(i>>j):
            ans -= int(S[j+1])
            op[j] = '-'
        else:
            ans += int(S[j+1])
            op[j] = '+'
    if ans == 7:
        break

output = S[0]
for i in range(N):
    output = output + op[i] + S[i+1]
output = output + '=7'

print(output)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main() {
    int n, m;
    cin >> n;
    int t[n], sum=0;
    for(int i=0; i<n; i++) {
        cin >> t[i];
        sum += t[i];
    }
    cin >> m;
    int p, x;
    for(int i=0; i<m; i++) {
        cin >> p >> x;
        cout << sum - t[p-1] + x << 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>
#define ll long long
#define iiii tuple<int, int, int, int>
#define iii tuple<int, int, int>
#define ii pair<int, int>
#define fi first
#define vi vector<int>
#define vvi vector<vector<int>>
#define se second

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int M = 1e3;

double f(vector<ii>& a, double x, double y) {
    double res = 0;
    for (auto& i : a)
        res = max(res, (i.fi - x) * (i.fi - x) + (i.se - y) * (i.se - y));
    return res;
}

double ts(vector<ii>& a, double x) {
    double lef = -M, rig = M;
    int cnt = 100;
    while (cnt--) {
        double y1 = (lef + lef + rig) / 3;
        double y2 = (lef + rig + rig) / 3;
        if (f(a, x, y1) > f(a, x, y2))
            lef = y1;
        else
            rig = y2;
    }
    return sqrt(f(a, x, lef));
}

double cal(vector<ii>& a) {
    double lef = -M, rig = M;
    int cnt = 100;
    while (cnt--) {
        double x1 = (lef + lef + rig) / 3;
        double x2 = (lef + rig + rig) / 3;
        if (ts(a, x1) > ts(a, x2))
            lef = x1;
        else
            rig = x2;
    }
    return ts(a, lef);
}

void solve() {
    int n;
    cin >> n;
    vector<ii> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i].fi >> a[i].se;

    cout << fixed << setprecision(15) << cal(a) << '\n';
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

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

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.Math;

public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);
        final int MOD = 1000000007;

        int n = sc.nextInt();
        char[] c = sc.nextLine().toCharArray();
        int[][] cnt = new int[n][2]; // cnt[i][0] = # west, cnt[i][1] = # east

        if(c[0] == 'W') cnt[0][0]++;
        else cnt[0][1]++;

        for(int i=1;i<n;i++) {
            if(c[i] == 'W') cnt[i][0]++;
            else cnt[i][1]++;
            cnt[i][0] += cnt[i-1][0];
            cnt[i][1] += cnt[i-1][1];
        }

        int ans = n - 1;
        for(int i=0;i<n;i++) {
            int idx;
            if(c[i] == 'E') idx = 1;
            else idx = 0;
            cnt[i][idx]--;
            /*pw.println("i:" + i);
            pw.println("change to east: " + cnt[i][0]);
            pw.println("change to west: " + (cnt[n-1][1] - cnt[i][1]));*/
            ans = Math.min(ans, cnt[i][0] + (cnt[n-1][1] - cnt[i][1]));
            cnt[i][idx]++;
        }

        pw.println(ans);
        pw.close();
    }
}


Measured memory_bytes: 33876
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int N; cin >> N;
    vi p(N, 0);
    rep(i, 0, N){
        cin >> p[i];
        p[i]--;
    }
    int l = 0;
    int r = N-1;
    ll cnt = 0;
    while(l <= r){
        if(l == p[l]){
            swap(p[l], p[l+1]);
            cnt++;
        } else {
            l++;
        }
        if(r == p[r]){
            swap(p[r], p[r-1]);
            cnt++;
        } else {
            r--;
        }
    }
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h> 
#include <boost/multiprecision/cpp_int.hpp> 
using boost::multiprecision::cpp_int;
using namespace std;
int main()
{
  cpp_int a,b,c;
  cin>>a>>b;
  c=a*b;
  if(a==1 || b==1)
    c=1;
  else if(c%2==0)
    c=c/2;
  else
    c=(c/2)+1;
  cout<<c;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _1159
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                int[] line = ReadIntAr();
                if (line[0] + line[1] == 0) break;

                int res;
                int n = line[0];
                int p = line[1];
                int[] hasPebbleCount = new int[n];

                for (int i = 0 ; i < n ; i = (i + 1) % n)
                {
                    if (p>0)
                    {
                        p--;
                        hasPebbleCount[i]++;
                        if(hasPebbleCount[i] == line[1]) { Console.WriteLine(i);break; }
                    }
                    else
                    {
                        p = hasPebbleCount[i];
                        hasPebbleCount[i] = 0;
                    }
                }
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 15912
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (c >= a && c <= b)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 35676
#include<stdio.h>
int main()
{
    int a,b;
    char s[101];
    // 整数の入力
    scanf("%d", &a);
    // スペース区切りの整数の入力
    scanf("%d",&b);
    // 文字列の入力
    scanf("%s",s);
    // 出力
    if(s[b-1]=='A'){s[b-1]='a';}
    if(s[b-1]=='B'){s[b-1]='b';}
    if(s[b-1]=='C'){s[b-1]='c';}
    
    printf("%s\n",s);
    return 0;
}


Measured memory_bytes: 128
import sys
from fractions import gcd

N=input()
A=map(int, sys.stdin.readline().split())

minus_count=0
A_sum=0
A_min=float("inf")
for a in A:
    if a<0:
        minus_count+=1
    a=abs(a)
    A_min=min(A_min,a)
    A_sum+=a

if minus_count%2==0:
    print A_sum
else:
    print A_sum-A_min*2


Measured memory_bytes: 44696
#include <iostream>
#include <vector>
int main(){
    int n, k;
    char a;
    std::cin >> n;
    std::vector <char> v(n);
    for(int i=0; i<n; i++){
        std::cin >> v[i];
    }
    std::cin >> k;
    a = v.at(k-1);
    for(int i=0; i<n; ++i){
        if(a != v[i]){
            std::cout << "*";
        }else{
            std::cout << v[i];
        }
    }
    std::cout << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
// __uint128_t

int main(){
    ll N; cin >> N;
    ll SUM = 0;
    vector<ll> C(N+1); for(int i = 0; i < N+1; i++) cin >> C[i];
    if(N == 0 && C[0] == 1){
        cout << 1 << endl;
        return 0;
    }
    if(C[0] > 0 || C[N] == 0 ) {cout << -1 << endl; return 0;}
    vector<ll> P(N+1); P[N] = 0, P[N-1] = C[N];
    
    for(int i = N-1; i >= 0; i--){
        P[i] = C[i+1] + P[i+1];
    }


    ll temp = 1;
    for(int i = 0; i <= N; i++){
        P[i] = min(temp - C[i], P[i]); temp = 2*P[i];
        if((i <= N && P[i] < 0 )|| temp <= -1) {cout << -1 << endl;return 0;}

    }
    for(int i = 0; i < N+1; i++) SUM += C[i]+P[i];
    cout << SUM << endl;
}


Measured memory_bytes: 4852
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std ;
const int N = 200010 ; 
struct rec{
	int a,b,id ;
	friend inline bool operator < (const rec x,const rec y){
		return 1ll*x.a*y.b < 1ll*x.b*y.a ;  
	}
};
priority_queue<rec> q ;
int n,fa[N],f[N],cnt[N][2] ; 
inline int get(int x){
	return x == f[x] ? x : f[x] = get(f[x]) ; 
}
int main(){
	//freopen("in.txt","r",stdin) ; 
	cin >> n ;
	for(int i = 2 ; i <= n ; i++) scanf("%d",&fa[i]),f[i] = i ; 
	for(int i = 1 ; i <= n ; i++){ int val ; scanf("%d",&val) ; cnt[i][val]++ ; }
	for(int i = 2 ; i <= n ; i++) q.push((rec){cnt[i][0],cnt[i][1],i}) ;
	f[1] = 1 ; long long ans = 0 ;
	while(!q.empty()){
		rec x = q.top() ; q.pop() ; 
		int id = get(x.id),a = x.a,b = x.b ;  
		if(cnt[id][0] != a || cnt[id][1] != b) continue ;
		int y = get(fa[id]) ;
		ans += 1ll*cnt[y][1]*a ;
		cnt[y][0] += a ; cnt[y][1] += b ;
		f[id] = y ;
		if(y > 1) q.push((rec){cnt[y][0],cnt[y][1],y}) ; 
	}
	cout << ans << endl; 
	return 0 ; 
}

Measured memory_bytes: 9584
#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;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define MAXW (ll)(1e5 + 5)
#define MAXN (ll)(1e2 + 5)
#define INF (ll)(1e12)

ll n, w;
ll dp[MAXN][MAXW];
ll mg[MAXN];
ll val[MAXN];

ll solve(ll N, ll W)
{
    if (W < 0)
        return -INF;
    if (N < 0)
        return 0;
    
    if (dp[N][W] == -1)
        dp[N][W] = max(solve(N - 1, W - mg[N]) + val[N], solve(N - 1, W));
    return dp[N][W];
}

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

    cin >> n >> w;
    for (int i = 0; i < n; i++)
        cin >> mg[i] >> val[i];
    
    memset(dp, -1, sizeof(dp));

    cout << solve(n - 1, w) << "\n";
}


Measured memory_bytes: 82304
#include<cstdio>
#include<string>
#include<cstring>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

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

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

int h1(int key){ return key % M;}
int h2(int key){ return 1 + (key % (M-1));}

int find(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i=0;;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h],str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i=0;;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h],str) == 0) return 1;
        else if(strlen(H[h]) == 0){
            strcpy(H[h],str);
            return 0;
        }
    }
    return 0;
}

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












Measured memory_bytes: 17068
import java.util.Scanner;

public class Main {
	private static int[][] dir = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
	private static int ans;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			ans = 11;
			int w = sc.nextInt();
			if (w == 0) {
				sc.close();
				break;
			}

			int h = sc.nextInt();
			int[][] field = new int[h][w];
			int[] start = new int[2];
			for (int i = 0; i < field.length; i++) {
				for (int j = 0; j < field[i].length; j++) {
					field[i][j] = sc.nextInt();
					if (field[i][j] == 2) {
						// スタート地点の座標を保存しとく
						start[0] = i;
						start[1] = j;
						field[i][j] = 0;
					}
				}
			}
			int dfs = dfs(0, start[0], start[1], field);
			if (dfs > 10) {
				System.out.println(-1);
			} else {
				System.out.println(dfs);
			}
		}
	}

	static int dfs(int hit, int x, int y, int[][] field) {
		for (int d = 0; d < dir.length; d++) {
			int i = x;
			int j = y;

			i += dir[d][0];
			j += dir[d][1];

			if (i < 0 || i >= field.length || j < 0 || j >= field[i].length) {
				// フィールド外に出てしまった場合
				continue;
			} else if (field[i][j] == 1) {
				// すぐ隣が石の場合
				continue;
			}

			i -= dir[d][0];
			j -= dir[d][1];

			boolean next = true;
			while (true) {
				i += dir[d][0];
				j += dir[d][1];
				if (i < 0 || i >= field.length || j < 0 || j >= field[i].length) {
					// フィールド外に出てしまった場合
					next = false;
					break;
				}
				if (field[i][j] == 1) {
					// 障害物があった時
					break;
				} else if (field[i][j] == 3) {
					// ゴールだった時
					return hit + 1;
				}
			}

			if (next && ans > hit + 1) {
				field[i][j] = 0;
				int hitdfs = dfs(hit + 1, i - dir[d][0], j - dir[d][1], field);
				field[i][j] = 1;
				ans = Math.min(ans, hitdfs);
			}
		}

		return ans;

	}
}

Measured memory_bytes: 37368
/**akshaykumar99**/
 
#include<bits/stdc++.h>
using namespace std;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define pu push_back           
#define pp pop_back
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int MOD=1e9+7 ;
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+2;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> ivc;
typedef pair<ll,ll> ipr;

int main()
{
    IOS();
  
    string s,z,r;
    cin>>s;
    int i,n,j,ans=1;
    n=s.length();
    z=s[0];
    for(i=1;i<n;i++)
    {
        r=s.substr(i,1);
        //cout<<r<<" "<<z<<" "<<i<<"\n";
        if(r!=z)
        {
          z=s[i];
          ans++;
        }
        else
        {
          z=s.substr(i,2);
          i++;
          if(i!=n)
            ans++;
        }


    }
    cout<<ans;
 
}

Measured memory_bytes: 720
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int N = sc.nextInt();
        int[] a = new int[N];
        long sum = 0;
        for(int i = 0; i< N; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }
        double x = (double)sum/(double)N;
        if(x>=0) x += 0.5;
        else x -= 0.5;
        long y = (long)x;
        System.err.println(y);
        long cost = 0;
        for(int i = 0; i<N; i++) {
            cost += Math.pow(y-a[i],2);
        }
        System.out.println(cost);
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21588
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<deque>

using namespace std;

class UnionFind{//UnionFind木
 private:
    vector<int> Parent;
 public:
    UnionFind(int N){
        vector<int> Parent(N,-1);
    }

    int root(int A){
        if(Parent[A]<0) return A;
        return Parent[A]=root(Parent[A]);
    }

    int size(int A){
        return -Parent[root(A)];
    }

    bool connect(int A,int B){
        A=root(A);
        B=root(B);
        if(A==B) return false;
        if(size(A)<size(B)) swap(A,B);
        Parent[A]-=Parent[B];
        Parent[B]=A;
    }
};

typedef pair<int, int> P;
typedef long long ll;
const int division = 1000000007;


ll mpow(ll x, ll n){ //x^n(mod division) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % division;
        x = x*x % division;
        n = n >> 1;
    }
    return ans;
}

ll cmb(ll a, ll b){ //aCbをmod計算
    vector<ll> fac; //n!(mod division)
    vector<ll> ifac; //k!^{M-2} (mod division)
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    fac.push_back(1);
    ifac.push_back(1);
    for(ll i = 0; i<a; i++){
        fac.push_back(fac[i]*(i+1) % division); // n!(mod division)
        ifac.push_back(ifac[i]*mpow(i+1, division-2) % division); // k!^{M-2} (mod division) ←累乗にmpowを採用
    }
    ll tmp = ifac[a-b]* ifac[b] % division;
    return tmp * fac[a] % division;
}
int gcd(int x,int y){return y ? gcd(y,x%y) : x;};//xとyの最大公約数

int main(){
    int A,P;
    cin >> A >> P;
    P+=3*A;
    cout << P/2 << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8

while True:
   a = map(int,raw_input().split())
   if a == [0,0]:
      break
   print('#'*a[1])
   for i in range(a[0]-2):
      b ='.'*(a[1]-2)
      print('#'+b+'#')
   print('#'*a[1])
   print('')



Measured memory_bytes: 4640
// ダブリングで解く
// ダブリングのコードは http://satanic0258.hatenablog.com/entry/2017/02/23/222647 を参考とした

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define pb push_back
#define mp make_pair
#define mt make_tuple

// floor(log2(N))を求める  N>=2とする
ll calc_log2(ll N) {
    ll ans = 1;
    ll v = 2;
    while(v < N) {
        v *= 2;
        ans += 1;
    }
    return ans;
}

int main(void)
{
    cin.sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<int> As(N);
    REP(n, N) {
        int a;
        cin >> a; --a;
        As[n] = a;
    }

    // K: 何個先まで見る必要があるか
    ll LOG = calc_log2(K);

    // next[k][i]で、i番目の要素の「2^k個次の要素」を指す
    // (なお、i番目の要素に対して「2^k個次の要素」が存在しないとき、
    //  next[k][i]が指し示す要素番号を-1とします)
    std::vector<std::vector<int>> next(LOG + 1, std::vector<int>(N)); 

    // next[0]を計算
    for (int i = 0; i < N; ++i){
        next[0][i] = As[i];
    }

    // nextを計算
    for (int k = 0; k < LOG; ++k){
        for (int i = 0; i < N; ++i){
            if (next[k][i] == -1) {
                // 2^k個次に要素が無い時、当然2^(k+1)個次にも要素はありません
                next[k + 1][i] = -1;
            }
            else {
                // 「2^k個次の要素」の2^k個次の要素は、2^(k+1)個次の要素です
                next[k + 1][i] = next[k][next[k][i]];
            }
        }
    }

    // ----ここまで準備----

    // p番目の要素の「K個次の要素」を求めることを考えます
    int p = 0;
    for (int k = LOG - 1; k >= 0; --k){
        if (p == -1) {
            // pがすでに存在しない要素を指していたら、
            // それ以降で存在する要素を指すことはないためループを抜けます
            break;
        }
        if ((K >> k) & 1) {
            // Qを二進展開した際、k番目のビットが立っていたら、
            // pの位置を2^kだけ次にずらします
            p = next[k][p];
        }
    }

    cout << p + 1 << endl;

    return 0;
}


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

using namespace std;

int main(void)
{
	string s;
	cin >> s;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
		cout << "Bad" << endl;
	else
		cout << "Good" << endl;
}

Measured memory_bytes: 256
n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = []
for _ in range(m):
    p, x = map(int, input().split())
    px.append((p, x))

total = sum(t)
for p, x in px:
    print(total-t[p-1]+x)


Measured memory_bytes: 3060