akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())  #「A B」みたいなスペース空いた入力のとき
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N < 2:
    a = 0
else:
    a = comb(N, 2)

if M < 2:
    b = 0
else:
    b = comb(M, 2)
print(a+b)

Measured memory_bytes: 3060
#include <stdio.h>

int main(){
	long long i,j,k,n,min;
	
	scanf("%lld",&k);

	min=k;

	for(i=1; i*i<=k; i++){
		if(k%i==0){
			j=k/i;
			n=i+j-2;
			if(min>n){
				min=n;
			}
		}
	}

	printf("%lld",min);
	return 0;
}
		

Measured memory_bytes: 128
#include<iostream>
  using namespace std;
void cut(int* cards,int n,int k) {  
    int result[200];
    int i;
    for(i=0;i<k;i++) {
        result[2*n-k+i]=cards[i];
    }
    for(i=k;i<2*n;i++) {
        result[i-k]=cards[i];
    }
    for(i=0;i<n*2;i++) {
        cards[i]=result[i];
    }
}
  
void rf(int* cards,int n) {
    int result[200];
    int i;
    for(i=0;i<n;i++) {
        result[i*2]=cards[i];
        result[i*2+1]=cards[i+n];
    }
    for(i=0;i<n*2;i++) {
        cards[i]=result[i];
    }
}
  
int main(void) {
    int cards[200];
    int i,n,m,k;
 cin>>n>>m;
    for(i=0;i<n*2;i++)cards[i]=i+1;
    for(i=0;i<m;i++) {
        cin>>k;
        if(k==0)rf(cards,n);
        else cut(cards,n,k);
    }
    for(i=0;i<n*2;i++)cout<<cards[i]<<endl;
    return 0;
}

Measured memory_bytes: 1160
// arock - 2019-08-18

#include <iostream>
#include <vector>

using i64 = long long;

auto process(std::string s) {
	const int N = int(s.size());

	std::vector<int> last(26, -1);
	std::vector<std::vector<int>> next(N, std::vector<int>(26));
	for (int i = N - 1; i >= 0; i--) {
		last[s[i] - 'a'] = i;
		for (int j = 0; j < 26; j++) {
			next[i][j] = last[j];
		}
	}

	return next;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);

	std::string s, t;
	std::cin >> s >> t;

	std::string ss = s + s;
	auto nxt = process(ss);

	i64 ans = 0, cur = 0;
	for (char c : t) {
		int pos = nxt[cur][c - 'a'];
		if (pos == -1) {
			std::cout << -1 << '\n';
			return 0;
		}
		ans += pos - cur + 1;
		cur = (pos + 1) % s.size();
	}

	std::cout << ans << '\n';
}


Measured memory_bytes: 27472
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T x=0,f=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	char s[7];
	int main(){
		scanf("%s",s+1);
		if(s[3]==s[4] && s[5]==s[6]) puts("Yes");
		else puts("No");
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)

const int N = ((int)1e2) + 5;

int n;
char str1[N],str2[N];
int del;

int main ()
{
	scanf("%d",&n);
	scanf("%s",str1 + 1);
	scanf("%s",str2 + 1);
	for (int i = 1; i <= n; i++)
	{
		if (str1[i] == str2[1])
		{
			int d = 0;
			int j = i;
			int j2 = 1;
				while (str1[j] == str2[j2] && j <= n)
					d++,j++,j2++;
			del = max(d,del);
		}
	}
	printf("%d",(2 * n) - del);
}

Measured memory_bytes: 256
while True:    
    n, k = map(int, raw_input().split())
    if n==0: break
    t = [input()]
    sum = t[0]
    ans = -(1<<31)
    for i in range(1,k):
        t += [input()]
        sum += t[i]
    for i in range(k,n):
        t += [input()]
        sum += t[i] - t[i-k]
        ans = max(ans, sum)
    print ans

Measured memory_bytes: 10952
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    int a[3];

    cin >> a[0] >> a[1] >> a[2];

    sort(a, a+3);

    cout << a[2] * 10 + a[1] + a[0] << endl;
}


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

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

    const string ABC = "ABC";
    string s;
    cin >> s;
    while (1) {
        if (s == ABC) {
            cout << "Yes" << endl;
            return 0;
        }
        vector<int> cnt(3);
        int n = s.size();
        REP(i, n) { cnt[s[i] - 'A']++; }
        int mi = min({cnt[0], cnt[1], cnt[2]});
        int id = -1;
        REP(c, 3) {
            if (cnt[c] == mi) {
                if (id != -1) {
                    cout << "No" << endl;
                    return 0;
                }
                id = c;
            }
        }
        string t;
        REP(i, n) {
            if (i < n - 2 && s.substr(i, 3) == ABC) {
                t.push_back('A' + id);
                i += 2;
            } else {
                t.push_back(s[i]);
            }
        }
        if (s.size() == t.size()) {
            cout << "No" << endl;
            return 0;
        }
        s = move(t);
    }
}



Measured memory_bytes: 3240
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        string[] st =  Console.ReadLine().Split(' ');
        long[] ab = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var u = Console.ReadLine();


        long ans = 0;
        if (u == st[0])
        {
            ab[0] -= 1;
        }
        if (u == st[1])
        {
            ab[1] -= 1;
        }
        Console.WriteLine( ab[0] +" "+ ab[1]);
    } 
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// 088d
int h, w;
string s[1000];
int ans = 0;
int d[100][100];

void bfs(){
    queue<P> q;
    q.push(P(0, 0));
    d[0][0] = 0;
    while(!q.empty()){
        P tmpQ = q.front();
        q.pop();
        rep(i, 4){
            int ny = tmpQ.first + dy[i], nx = tmpQ.second + dx[i];
            if (ny<h and ny>=0 and nx>=0 and nx<w){
                if (s[ny][nx]=='#' or d[ny][nx]!=1<<21) continue;
                d[ny][nx] = d[tmpQ.first][tmpQ.second]+1;
                q.push(P(ny, nx));
            }
        }
    }
}

int main(){
    cin >> h >> w;
    rep(i, h) cin >> s[i];
    rep(i, h)rep(j, w) d[i][j] = 1<<21;
    rep(i, h)rep(j, w) {
        if (s[i][j]=='#') ans++;
    }
    bfs();
    if (d[h-1][w-1]==1<<21) cout << -1 << endl;
    else cout << h*w - d[h-1][w-1] -1 - ans<< endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private byte[] runner;
	private static final int OUT_COUNT_FOR_CHANGE = 3;
	enum EVENT {HIT, HOMERUN, OUT};
	
	private byte out;
	private int scoreOfInning;
	
	public Main() {
		this.runner = new byte[3];
		this.out = 0;
		this.scoreOfInning = 0;
	}
	
	public boolean action(EVENT e) {
		boolean isChange = false;
		
		switch(e) {
		case HIT:
			scoreOfInning += hit();
			break;
		case HOMERUN:
			scoreOfInning += homerun();
			break;
		case OUT:
			isChange = out();
			break;
		default:
			break;
		}
		return isChange;
	}
	
	private int hit() {
		int ret = runner[2]==1 ? 1 : 0;
		
		runner[2] = runner[1];
		runner[1] = runner[0];
		runner[0] = 1;
		
		return ret;
	}
	
	private boolean out() {
		out++;
		if(out==OUT_COUNT_FOR_CHANGE) {
			System.out.println(scoreOfInning);
			out = 0;
			scoreOfInning = 0;
			clearRunner();
			return true;
		}
		return false;
	}
	
	private int homerun() {
		int ret = runner[0] + runner[1] + runner[2] + 1;
		
		clearRunner();
		return ret;
	}
	
	private void clearRunner() {
		runner[0] = runner[1] = runner[2] = 0;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		Main sim = new Main();
		
		int numOfDataSet = in.nextInt();
		EVENT e = EVENT.HIT;
		for(int i=0; i<numOfDataSet; i++) {
			do {
				String event = in.next();
				
				if(event.equals("HIT")) e = EVENT.HIT;
				else if(event.equals("HOMERUN")) e = EVENT.HOMERUN;
				else if(event.equals("OUT")) e = EVENT.OUT;
				else System.exit(1);
				
			} while(!sim.action(e));
		}
	}

}

Measured memory_bytes: 26308
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

s=S_()
n=len(s)
t=s[:~-n//2]
u=s[(n+2)//2:]
if s==s[::-1] and t==t[::-1] and u==u[::-1]:
    k=0
else:
    k=1

ans=Yn[k]
print(ans)

Measured memory_bytes: 38796
#include <iostream>

using namespace std;
typedef long long ll;

int n, k;

void solve() {
  ll cnt = 0;
  for (int i=k+1;i<=n;i++) {
      cnt += (i - k) * (n / i);
      if (n % i >= k) {
        cnt += (n % i) - k;
        if (k > 0) {
          cnt++;
        }
      }
    }
  cout << cnt << endl;
}

int main() {
  cin >> n >> k;
  solve();
}



Measured memory_bytes: 256
#include <cstdio>
#include <map>
#define mod 1000000007
#define LL long long
using namespace std;
map< pair<LL,LL>,pair<int,int> > mp;
LL gcd(LL a,LL b){//最大公约数
	return b?gcd(b,a%b):a;
}
LL quick_pow(LL a,LL b){//快速幂
	LL ret=1;
	while(b){
		if(b&1)ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret%mod;
}
int main(){
	int n,i;
	LL a,b,d,zero=0,sum=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%lld%lld",&a,&b);
		if(!a&&!b){zero++;continue;}//请注意，此句位置,请注意continue
		d=gcd(a,b);
		a/=d,b/=d;//让a,bi互质
		if(b<0)a=-a,b=-b;//目标，让b>0
		if(a<=0)mp[make_pair(b,-a)].second++;//请注意，此处是a<=0，注意=
		else mp[make_pair(a,b)].first++;
	}
	for(map< pair<LL,LL>,pair<int,int> >::iterator it=mp.begin();it!=mp.end();it++)
		sum=(quick_pow((LL)2,(LL)it->second.first)-1+quick_pow((LL)2,(LL)it->second.second)-1+1)%mod*sum%mod;
	sum=(sum+zero-1)%mod;
	sum=(sum%mod+mod)%mod;
	printf("%lld\n",sum);
	return 0;
}

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

typedef long long lnt;

const int N = 2e5 + 5;
const int mod = 998244353;

int base[N];

int fpow (int a, int b) { int ret = 1; while (b) { if (b & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod; b >>= 1; } return ret; }
int add (int a, int b) { return (a += b) >= mod ? a - mod : a; }
int sub (int a, int b) { return (a -= b) >= 0 ? a : a + mod; }
int mul (long long a, int b) { return a * b % mod; }
int inv (int a) { return fpow(a, mod - 2); }

#define nowr st, en, rt
#define lson st, (st + en) >> 1, rt << 1
#define rson ((st + en) >> 1) + 1, en, rt << 1 | 1

// struct {

int x[N << 2];
int lg[N << 2];
int w[N << 2];

void upd (int v, int st, int en, int rt) {
	if (v == 0) return;
	x[rt] = mul(v, w[rt]);
	lg[rt] = v;
}

void pu (int rt) {
	x[rt] = add(x[rt << 1], x[rt << 1 | 1]);
}

void pd (int st, int en, int rt) {
	upd(lg[rt], lson); upd(lg[rt], rson); lg[rt] = 0;
}

void modify (int l, int r, int v, int st, int en, int rt) {
	if (l > en || r < st) return;
	if (l <= st && en <= r) { upd(v, st, en, rt); return; }
	pd(nowr); modify(l, r, v, lson); modify(l, r, v, rson); pu(rt);
}

int query (int l, int r, int st, int en, int rt) {
	if (l > en || r < st) return 0;
	if (l <= st && en <= r) return x[rt];
	pd(nowr); return add(query(l, r, lson), query(l, r, rson));
}

void build (int st, int en, int rt) {
	x[rt] = 0; lg[rt] = 0;
	w[rt] = sub(base[en], base[st - 1]);
	if (st == en) { x[rt] = w[rt]; return; }
	build(lson); build(rson); pu(rt);
}

// } st;

int main (void) {
	int n, q;
	scanf("%d%d", &n, &q);
	base[n] = 1;
	for (int i = n - 1; i >= 1; i --)
		base[i] = mul(base[i + 1], 10);
	for (int i = 1; i <= n; i ++)
		base[i] = add(base[i - 1], base[i]);
	build(1, n, 1);
	for (int i = 1, l, r, d; i <= q; i ++) {
		scanf("%d%d%d", &l, &r, &d);
		modify(l, r, d, 1, n, 1);
		printf("%d\n", x[1]);
	}
}

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

int k[500000][700];

int main(){
	int n,sum=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>k[0][i];
	}
	for(int i=0;i<n-1;i++){
		for(int j=n-2;j>=i;j--){
			if(k[sum][j]>k[sum][j+1]){
				sum++;
				for(int l=0;l<n;l++){
					k[sum][l]=k[sum-1][l];
				}
				k[sum][j]=k[sum-1][j+1];
				k[sum][j+1]=k[sum-1][j];
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<k[sum][i];
		if(i<n-1){
			cout<<' ';
		}
		else{cout<<endl;}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 9344
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n, k, ans = 0;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }
    for(int i = 0; i < n - k; ++i){
        if(a.at(i) < a.at(i + k)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
    string s;
    cin >> s;
    if (s.substr(2,1) == s.substr(3,1) && s.substr(4,1) == s.substr(5,1)) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=b;i>=a;i--)
#define sc(x) scanf("%d",&x)
#define pb push_back
#define ll long long
int a[200005];
int vis[200005];
int now[200005];
int main(int argc, char** argv) {
	ll n,k;
	scanf("%d%lld",&n,&k);
	rep(i,1,n)
	{
		sc(a[i]);
	}
	int st=1,p=0;
	vis[st]=0;
	now[0]=1;
	while(!vis[a[st]])
	{
		p++;
		now[p]=a[st];
		vis[a[st]]=p;
		st=a[st];
	}
	int quan=p-vis[a[st]]+1;
	int pow=vis[a[st]];
	//cout<<quan<<endl;
	if(k<pow)
	{
		printf("%d\n",now[k]);
	}
	else printf("%d\n",now[pow+(k-pow)%quan]);
	
	return 0;
}

Measured memory_bytes: 5936
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a;
    cin>>n;
    vector<pair<int,int>>A(n);
    for(int i=0;i<n;i++)
    {
        cin>>a;
        A[i]=make_pair(a,i);
    }
    sort(A.begin(),A.end());
    for(int i=0;i<n;i++)
    {
        cout<<A[i].second+1<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
using namespace std;
int n,a[2][101],sum[2][101];
void Solve(){
	for (int j=0;j<2;++j){
		for (int i=1;i<=n;++i){
			sum[j][i] = sum[j][i-1]+a[j][i]; 
		}
	}
	int mx = -1;
	for (int i=1;i<=n;++i){
		if (sum[0][i] + sum[1][n] - sum[1][i-1] > mx) mx = sum[0][i] + sum[1][n] - sum[1][i-1];
	}
	cout << mx;
}

void Input(){
	cin >> n;
	for (int i=1;i<=n;++i)
		cin >> a[0][i];
	for (int i=1;i<=n;++i)
		cin >> a[1][i];
}

signed main(){
	Input();
	Solve();
}


Measured memory_bytes: 3572
/*
 * ID: adityaa
 * LANG: C++
 */
#include <bits/stdc++.h>
using namespace std;

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define PI 3.14159265359

/*-----------------------------------------------------------------------*/

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

/*-----------------------------------------------------------------------*/

// check base cases n = 0 , n = 1
// max / min questions - check for binary search
const int maxn = (int) 1e5 + 6;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int) 998244353;
int n , max_weight , weight[maxn] , value[maxn];
int dp[110][maxn];

signed main() {
    
    fio;
    cin >> n >> max_weight;
    for(int i = 1; i <= n; i++){
        cin >> weight[i] >> value[i];
    }
    
    for(int i = 1; i <= n; i++){
        for(int w = 0; w <= max_weight; w++){
            dp[i][w] = dp[i - 1][w];
            if(weight[i] > w) continue;
            dp[i][w] = max(dp[i][w] , dp[i - 1][w - weight[i]] + value[i]);
        }
    }
    
    int ans = -INF;
    for(int w = 0; w <= max_weight; w++){
        ans = max(ans , dp[n][w]);
    }
    
    cout << ans << endl;
    
    
    
    return 0;
    
}


Measured memory_bytes: 81408
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	
	int count = 0; 
	int ans;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '-') {
			count++;
			ans = i;
		}
	}
	
		
	
	if (count == 1 && ans == a) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
	
}

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

int main() {
	string s;
	cin >> s;
	bool lucy = false;

	for (int i = 0; i < 3; i++) {
		if (s[i] == '7') { lucy = true; break; }
	}

	if (lucy) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

N = int(input())
s = list()
t = list()
for i in range(N):
    _s, _t = map(str, input().split())
    s.append(_s)
    t.append(int(_t))
X = input()

ans = 0
for i in range(s.index(X) + 1, N):
    ans += t[i]

print(ans)


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll H, W, N;
  IN(H,W,N);
  if(H<W) swap(H,W);
  OUT((N-1)/H+1);

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
using namespace std;

const int maxn = 2e5+7;
const int maxm = 1e7+7;
int n,a[maxm];
vector<int>v[2],E[maxn];
bool bio[maxn];
int conn[maxn];
void init(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        a[x]=1;
    }
}
bool prime(int x){
    if(x==1)return false;
    for(int i=2;i*i<=x;i++)
        if(x%i==0)return false;
    return true;
}
bool dfs(int x){
    if(bio[x])return false;
    bio[x]=true;
    for(auto it : E[x]){
        if(conn[it] == -1 || dfs(conn[it])){
            conn[it] = x;
            return true;
        }
    }
    return false;
}
int main(){
    init();
    memset(conn,-1,sizeof(conn));
    for(int i=maxm-1;i;i--){
        a[i]^=a[i-1];
        if(a[i])v[i%2].push_back(i);
    }
    for(int i=0;i<v[0].size();i++){
        for(int j=0;j<v[1].size();j++){
            if(prime(abs(v[0][i]-v[1][j]))){
                E[i].push_back(j);
            }
        }
    }
    
    int match = 0;
    for(int i=0;i<v[0].size();i++){
        memset(bio,false,sizeof(bio));
        match+=dfs(i);
    }
    cout<<v[0].size()+v[1].size()-match+(v[0].size()-match)%2;
    return 0;
}

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

void Main(){
    
}

int main(){
  cout << fixed << setprecision(12);
  
  double r; //rは実数
  cin>>r;
  
  double area = r * r * M_PI;
  double cir = (r + r) * M_PI;
  cout<<area<<" "<<cir<<endl;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL;
  typedef pair<ll,char> PLC;
  typedef pair<char,ll> PCL;

int main(void){
  int M;cin >> M;
  ll K; cin >> K;
  ll M_2 = 1 << M;
  if( M_2<=K || ( M==1 && K==1) ){
    cout << -1 << endl;
    return 0;
  }
  int i;
  if(K!=0) cout << K << " ";
  REP(i,M_2){
    if(K!=0 && i==K)continue;
    cout << i << " ";
  }
  if(K!=0) cout << K << " ";
  REP(i,M_2){
    if(K!=0 && M_2-i-1==K)continue;
    cout << M_2-i-1 << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1792
n,x,y=map(int,input().split())
x-=1
y-=1
Ans={}
for i in range(n-1):
      for j in range(i+1,n):
            d=j-i
            dd=abs(x-i)+abs(y-j)+1
            dist=min(d,dd)
            if dist in Ans:
                  Ans[dist]+=1
            else:
                  Ans[dist]=1

for i in range(1,n):
      if i in Ans:
            print(Ans[i])
      else:
            print(0)

Measured memory_bytes: 50140
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let a: String = read(&mut stdin_lock, &mut buf, b'\n');
    let ans = a
        .chars()
        .map(|c| match c {
            '+' => 1,
            '-' => -1,
            _ => unreachable!(),
        })
        .fold(0, |acc, x| acc + x);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

int main() {
	ll n;
	cin >> n;
	vector<ll> A(n), L(n), R(n);
	for (auto& a: A)
		cin >> a;
		
	ll l = 0, r = 0;
	for (ll i = 0; i < n - 1; i++)
	{
		l ^= A[i];
		L[i] = l;
	}
	
	for (ll i = n - 1; i >= 0; i--)
	{
		r ^= A[i];
		R[i] = r;
	}
	
	for (ll i = 0; i < n; i++)
	{
		ll l = i > 0 ? L[i-1] : 0;
		ll r = i < n - 1 ? R[i+1] : 0;
		cout << (l ^ r) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 7892
lists = list(input())
leng = len(lists)
count = 0
flag = 0
for i in lists:
	if lists[count] == "?":
		if count + 1  < leng:
			if flag == 0:
				if (lists[count+1] == "D" or lists[count+1] == "?"):
					lists[count] = "P"
					flag = 1
				else:
					lists[count] = "D"
					flag = 0
			else:
				lists[count] = "D"
				flag = 0
		else:
			lists[count] = "D"
	else:
		flag = 1
	count = count + 1
print("".join(lists))

Measured memory_bytes: 10872
N = int(input())

tt = 0
xx = 0
yy = 0
f = 0
for i in range(N):
    t, x, y = map(int, input().split())

    dt = t - tt
    dx = x - xx
    dy = y - yy
    dxy = dx + dy

    if dt%2 == 0:
        if dxy <= dt and dxy%2 == 0:
            continue
        else:
            f = 1
            break
    else:
        if dxy <= dt and dxy%2 == 1:
            continue
        else:
            f = 1
            break

if f == 1:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <map>
#include <iostream>
using namespace std;

struct p{
	int x, y;
};
typedef struct p P;
const int INF = 1e+7;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

int w,h,n;
string m[1001];
P cheese[11];
int ans = 0;
int d[1001][1001];

void bfs(){
	for(int i=1 ; i <= n ; i++ ){
		P sp = cheese[i-1];
		int sx = cheese[i-1].x;
		int sy = cheese[i-1].y;
		int gx = cheese[i].x;
		int gy = cheese[i].y;
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				d[y][x] = INF;
			}
		}
		
		queue<P> q;
		q.push( sp );
		d[sy][sx] = 0;
		while( !q.empty() ){
			P now = q.front();
			q.pop();
			int x = now.x;
			int y = now.y;
			if( x == gx && y == gy ){
				ans += d[gy][gx];
				break;
			}
			for(int i=0 ; i < 4 ; i++ ){
				int mx = x + dx[i];
				int my = y + dy[i];
				if( mx < 0 || my < 0 || mx >= w || my >= h ) continue;
				if( m[my][mx] != 'X' ){
					P next;
					
					next.x = mx;
					next.y = my;
					if( d[my][mx] == INF ){
						d[my][mx] = d[y][x] + 1;
						q.push( next );
					}
				}
			}
		}
	}
}

int main(){
	cin >> h >> w >> n;
	for(int y=0 ; y < h ; y++ ){
		cin >> m[y];
	}
	
	
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			char c = m[y][x];
			if( c == 'S' ){
				cheese[0].x = x;
				cheese[0].y = y;
			}
			if( c >= '1' && c <= '9' ){
				cheese[ c - '0' ].x = x;
				cheese[ c - '0' ].y = y;
			}
		}
	}
	bfs();
	cout << ans << endl;
}

Measured memory_bytes: 6184
//@author :  |< U $ |-|
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<list>
#include<cstring>
#include<unordered_map>
#define ll long long
#define vi vector<long long>
#define pb push_back
#define pop pop_back
#define pi pair<long long ,long long>
#define vp vector<pair<long long,long long> >
#define mkp make_pair
#define in(i,n) for(i=0;i<n;i++)
#define fon(i,n,m) for(i=n;i<m;i++)
#define rfon(i,n,m) for(i=n;i>=m;i--)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
// #define map map<long long,long long>
#define inm1(b)  memset(b,-1,sizeof(b))
#define in0(b) memset(b,0,sizeof(b))
#define ininf(b) memset(b,1000000001,sizeof(b))
#define MOD         1000000007
#define I 1000000000000000001
#define t(a) cout<<a<<" "<<endl
#define tt(a,b) cout<<a<<" "<<b<<endl
#define th(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define TakeInput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
using namespace std;
ll gcd(ll a, ll b) {  if (a == 0)  return b; return gcd(b % a, a); }
 
ll power(ll x, ll y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
 
 
 
int main(){
    jaldi
    // #ifndef ONLINE_JUDGE
    // TakeInput
    // #endif
    ll i,j,t,m,k,n;
    

    cin>>n;
    ll a[n];
    in(i,n){
        cin>>a[i];
    }

    ll count=0;

    sort(a,a+n);
    count+=a[n-1];

    ll c=2; 
    rfon(i,n-2,0){
        ll f=1;
        in(j,2){
            if(c<n)
                count+=a[i];
            else{
                f=0;
                break;
            }
            c++;
        }
        if(f==0)break;
    }
    cout<<count;
}
 
 
 

Measured memory_bytes: 5204
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define eb emplace_back
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define P 3000  //check the limits, man
#define N 55
const ll INF = 1e18;
ll check(ll n,ll b)
{
    ll x=0;
    while(n>0)
    {
        x+=(n%b);
        n/=b;
    }
    return x;
}
int main()
{
    ll n,s,x,i,a,b;
    llin(n);
    llin(s);
    if(n==s)
    {
        llout(n+1);
        return 0;
    }
    x=sqrt(n);
    lp(i,2,x+1)
    {
        if(check(n,i)==s)
        {
            out(i);
            return 0;
        }
    }
    x=sqrt(n-s);
    ll ans=INF;
    lp(i,1,x+1)
    {
        if((n-s)%i==0)
        {
            b=((n-s)/i)+1;
            a=s-i;
            if(i<b && a<b && a>=0)
                ans=min(ans,b);
        }
    }
    if(ans==INF)
        ans=-1;
    llout(ans);
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int a, b, c;
  std::cin >> a >> b >> c;
  if (b - a == c - b)
    std::cout << "YES" << std::endl;
  else
    std::cout << "NO" << std::endl;
}

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


int main(void){
    // Your code here!
    int n;
    cin>>n;
    
    vector<int> v;
    
    for(int i=1; i<10; i++){
        v.push_back(111*i);
    }
    
    if(n<=v[0]){
        cout<<111<<endl;
    }else{
        for(int i=1; i<v.size(); i++){
            if(v[i-1]<n&&n<=v[i]){
                cout<<v[i]<<endl;
                break;
            }
        }
    }
    

    
    
    
    
    
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
using ll = long long;
using ull = unsigned long long;

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i, n) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  // 昇順に入れる
  vector<ll> a;
  rep(i, n-1) {
    if (i % 2 == 0) {
      a.push_back(v[i/2]);
    } else {
      a.push_back(v[n-((i-1)/2)-1]);
    }
  }
  if (abs(a[0] - v[n/2]) < abs(a[n-2] - v[n/2])) {
    a.push_back(v[n/2]);
  } else {
    a.insert(a.begin(), v[n/2]);
  }
  // 降順に入れる
  sort(v.begin(), v.end(), greater<ll>());
  vector<int> b;
  rep(i, n-1) {
    if (i % 2 == 0) {
      b.push_back(v[i/2]);
    } else {
      b.push_back(v[n-((i-1)/2)-1]);
    }
  }
  if (abs(b[0] - v[n/2]) < abs(b[n-2] - v[n/2])) {
    b.push_back(v[n/2]);
  } else {
    b.insert(b.begin(), v[n/2]);
  }
  ll pa = a[0];
  ll pb = b[0];
  ll ca = 0;
  ll cb = 0;
  for(int i = 1; i < n; i++) {
    ca += abs(a[i] - pa);
    cb += abs(b[i] - pb);
    pa = a[i];
    pb = b[i];
  }
  cout << max(ca, cb);
}


Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> A(a), B(b), x(m), y(m), c(m);
    int ans = 1e9;
    int amin = 1e9, bmin = 1e9;

    rep(i,a) {
        cin >> A[i];
        amin = min(amin, A[i]);
    }
    rep(i,b) {
        cin >> B[i];
        bmin = min(bmin, B[i]);
    }
    rep(i,m){
        cin >> x[i] >> y[i] >> c[i];
        x[i]--; y[i]--;
    }

    ans = amin + bmin;

    rep(i,m){
     int tmp;
        tmp = A[x[i]] + B[y[i]] - c[i];
        ans = min(ans, tmp);
    }

    dunk(ans);
}








Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main(int argc, char *argv[]){
  int N,M;
  cin>>N>>M;
  map<int,vector<int> > mp;
  for(int i=0; i<M; i++){
    int a,b;
    cin>>a>>b;
    mp[a].push_back(b);
  }
  for(auto itr1=mp[1].begin(); itr1!=mp[1].end(); ++itr1){
    if(mp.count(*itr1)){
      int index=*itr1;
      for(auto itr2=mp[index].begin();itr2!=mp[index].end(); ++itr2){
	if(*itr2==N){
	  cout<<"POSSIBLE"<<endl;
	  return 0;
	}
      }
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
}


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

using namespace std;

int main(){
    int D,G,ans=1e9;
    cin>>D>>G;
    vector<int> p(D),c(D);

    for(int i=0;i<D;i++){
        cin>>p[i]>>c[i];
    }

    for(int i=0;i<(1<<D);i++){
        int ma=0;int num=0;int bigmax=-1;
        for(int j=0;j<D;j++){
            if(i>>j&1){
                ma += 100*(j+1)*p[j]+c[j];
                num += p[j];
            }else{
                bigmax = j;
            }
        }
        if(ma<G){
            int s1 = 100*(bigmax+1);
            int tmp = (G-ma+s1-1)/s1;
            if(tmp>=p[bigmax])continue;

            num+=tmp;
        }
        ans = min(ans,num);
    }
    cout<<ans;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    int sum = accumulate(a.begin(), a.end(), 0);

    int ave = round((double)sum / (double)n);

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        ans += (a[i] - ave) * (a[i] - ave);
    }

    cout << ans << endl;
}

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

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1e9;

int f(int i, VI& p, VI& go, vector<bool>& vis){
  if(vis[i]) return go[i];
  vis[i] = true;
  if(p[i] == 0) return go[i] = i;
  return go[i] = f(i+p[i], p, go, vis);
}

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

  int N; cin >> N;
  VI p(N), path(N, INF), go(N, -1);
  REP(i,N) cin >> p[i];

  vector<bool> vis(N, false);
  REP(i,N)
	f(i, p, go, vis);

  queue<int> q;
  q.push(0);
  path[0] = 0;
  while(!q.empty()){
	int i = q.front(); q.pop();
	for(int j=i+1;j<=min(i+6,N-1);++j){
	  if(go[j] < 0) continue;
	  if(path[go[j]] > path[i]+1){
		path[go[j]] = path[i] + 1;
		q.push(go[j]);
	  }
	}	
  }
  
  cout << path[N-1] << endl;
  
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;


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

  rep(i,s.size()) {
    if (s[i] != t[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

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


Measured memory_bytes: 3040
import java.util.*;

public class Main{
	public static void main(String args[]){
		int mod = 1000000007;
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		
		if(W==1){
			System.out.print("1");
			return;
		}
		
		long[][] dp = new long[H+1][W+1];
		dp[0][1] = 1;
		for(int i=2; i<=W; i++){
			dp[0][i] = 0;
		}
		for(int i=1; i<=H; i++){
			dp[i][1] = ((dp[i-1][1]*f(W-2)) + (dp[i-1][2]*f(W-3)))%mod;
			dp[i][W] = ((dp[i-1][W]*f(W-2)) + (dp[i-1][W-1]*f(W-3)))%mod;
			for(int j=1; j<=W-1; j++){
				dp[i][j] = ((dp[i-1][j-1]*f(j-3)*f(W-j-1)) + (dp[i-1][j]*f(j-2)*f(W-j-1)) + (dp[i-1][j+1]*f(j-2)*f(W-j-2)))%mod;
			}
		}
		System.out.print(dp[H][K]);
		return;
	}

	public static int f(int a){
		if(a<0){
			return 1;
		}
		switch(a){
			case 0: return 1;
			case 1: return 2;
			case 2: return 3;
			case 3: return 5;
			case 4: return 8;
			case 5: return 13;
			case 6: return 21;
			case 7: return 34;
			default: return 0;
		}
	}
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void debug_out() {cerr << endl;}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H), debug_out(T...);}

int main() {
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
#define debug(...) 3
    fastIO;
#endif
    string s;
    cin>>s;
    ll sum=0;
    forn(i,sz(s))sum+=s[i]-'0';
    if(sum%9==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3648
import java.util.*;class Main{public static void main(String[]z){int n,i;for(Scanner s=new Scanner(System.in);(n=s.nextInt())>0;){int[]a=new int[n];for(i=n;i-->0;)a[i]=s.nextInt();Arrays.sort(a);for(i=--n;i-->2;)a[1]+=a[i];System.out.println(a[1]/--n);}}}

Measured memory_bytes: 12000
#include<iostream>
#include<climits>
#include<numeric>
#include<algorithm>
#include <sstream>
#include<cstring>
#include<cmath>
#include<iterator>
#include<utility>
#include<array>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<forward_list>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;

int main()
{
#ifdef RAHUL
    freopen("input.txt","r",stdin);
#endif

int t;
cin>>t;
int arr[t];
for (int i = 0; i < t; ++i)
{
	/* code */
	cin>>arr[i];
}
int count=0;
for (int i = 0; i < t; ++i)
{
	for (int j = i+1; j <t;j++)
	{
		/* code */
		count+=arr[i]*arr[j];
	}
	/* code */
}
cout<<count<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007
vector<int> mx = {1, 0, -1, 0} ;
vector<int> my = {0, 1, 0, -1} ;
int main() {
    int h ,w ;
    cin >> h >> w; 
    vector<string> g (h) ;
    rep(i, h){
        cin >> g[i] ;
    }
    queue<P> ques ;
    vector<P> vec ;
    rep(i, h){
        rep(j, w){
            if(g[i][j] == '.'){
                P p = P(i, j) ;
                ques.push(p) ;
                vec.push_back(p) ;
            }
        }
    }
    int ans = 0 ;
    int num = vec.size() ;
    while(!ques.empty()){
        P q = ques.front() ;
        ques.pop() ;
        int sx = q.first ;
        int sy = q.second ;
        rep(i, num){
            int gx = vec[i].first ;
            int gy = vec[i].second ;
            vector<vector<int>> list (h ,vector<int> (w)) ;
            queue<P> que ;
            que.push(P(sx, sy)) ;
            while(!que.empty()){
                P p = que.front() ;
                que.pop() ;
                int x = p.first ; 
                int y = p.second ;
                int cost = list[x][y] ;
                if(x == gx && y == gy){
                    break ;
                }
                rep(v, 4){
                    int nx = x + mx[v] ;
                    int ny = y + my[v] ;
                    if(nx < 0 || ny < 0 || nx >= h || ny >= w){
                        continue ;
                    }
                    if(g[nx][ny] == '#') continue ;
                    if(list[nx][ny] > 0) continue ;
                    list[nx][ny] = cost + 1 ;
                    que.push(P(nx, ny)) ;
                }
            }
            ans = max(list[gx][gy], ans) ;
        }
    }
    cout << ans << endl ;
}  

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, Q; cin >> N >> Q;
    int v, w;
    if (N == 1) {
        rep(i, Q) {
            cin >> v >> w;
            cout << v << '\n';
        }
        return 0;
    }
    rep(i, Q) {
        cin >> v >> w;
        while (v != w) {
            if (v > w) v = (v + N - 2) / N;
            else w = (w + N - 2) / N;
        }
        cout << v << '\n';
    }
    return 0;
}

Measured memory_bytes: 1280
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 51
#define LL long long
LL dp[MAXN][MAXN][MAXN],ans;
int main()
{
	int n,A,x;
	scanf("%d%d",&n,&A);
	dp[0][0][0]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		for(int m=i-1;m>=0;m--)
			for(int j=0;j<A;j++)
				for(int k=0;k<=n;k++)
					if(k+(j+x)/A<=n)
						dp[(j+x)%A][k+(j+x)/A][m+1]+=dp[j][k][m];
	}
	for(int i=1;i<=n;i++)
		ans+=dp[0][i][i];
	printf("%lld\n",ans);
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int len=s.length();
	len--;
	while(true){
		if(len%2==0){
			int i;
			for(i=0; i<len/2; i++){
				if(s.at(i)!=s.at(len/2 + i)){
					break;
				}
			}
			if(i==len/2){
				cout << len << endl;
				return 0;
			}
		}
		len--;
	}

	return 0;
}

Measured memory_bytes: 256