akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
int n, p[1007], x[1007], dp[1007][5007], f[1007][5007], t, fa, lim;

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    cin >> n;
    for (int i = 2; i <= n; i++) cin >> p[i];
    for (int i = 1; i <= n; i++) cin >> x[i];

    for (int i = n; i > 0; i--) {
        fa = p[i], lim = x[i];
        for (int j = x[fa]; j >= 0; j--) {
            if (lim <= j)
                dp[fa][j] = dp[fa][j - lim] + dp[i][lim];
            else
                dp[fa][j] = (int) 1e7;

            if (dp[i][lim] <= j) {
                t = (dp[i][lim] == 0 ? 0 : dp[fa][j - dp[i][lim]]) + lim;
                if (dp[fa][j] > t) dp[fa][j] = t;
            }
            f[p[i]][j]=min(x[i]<=j?f[p[i]][j-x[i]]+f[i][x[i]]:1e7,
                           f[i][x[i]]<=j?f[p[i]][j-f[i][x[i]]]+x[i]:1e7);
        }
    }
    cout << (f[1][x[1]] < (int) 1e7 ? "POSSIBLE" : "IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 38528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define queue QQQ
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RAnK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn = 2e5+233;
int n,S,x[maxn];
ll p[maxn];
ll ans = 0;
int main(){
	n = rd(),S = rd();
	Rep(i,1,n){
		x[i] = rd(),p[i] = rd();
	}
	int l = 1,r = n;
	int last = -1;
	while(l <= r){
		if(x[r] <= S){
			ans += S - x[l];
			break;
		} else
		if(S <= x[l]){
			ans += x[r] - S;
			break;
		}
		
		if(p[l] < p[r]){
			if(last != 1) ans += x[r] - x[l];
			p[r] += p[l];
			l++;
			last = 1;
		} else{
			if(last != 2) ans += x[r] - x[l];
			p[l] += p[r];
			r--;
			last = 2;
		}
	}
	writeln(ans);
	return 0;
}

Measured memory_bytes: 1408
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()

ans = float('inf')
for i in range(-100, 101):
    opt = 0
    for k in range(N):
        opt += (A[k] - i) ** 2
    ans = min(ans, opt)
print(ans)

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

long long interest (long long X, long long money, long long &cnt) {
  if (X <= money) return cnt;
  cnt++;
  return interest(X, money * 1.01, cnt);
}

int main() {
  long long X, money = 100, cnt = 0;
  cin >> X;
  interest(X, money, cnt);
  cout << cnt << endl;
}


Measured memory_bytes: 3648
#include <iostream>

using namespace std;
typedef long long ll;
const int N=210;
int g[N][N];
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)g[i][j]=gcd(i,j);
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    for(int k=1;k<=n;k++)
    {
        int t=g[i][j];
        t=g[t][k];
        ans+=t;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3796
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");
		int a = Integer.parseInt(tmpArray[0]);
		int b = Integer.parseInt(tmpArray[1]);
		int c = Integer.parseInt(tmpArray[2]);
		
		System.out.println(Math.max(0, c - (a - b)));
		
	}

}


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


int main(){
  int a,b;
  cin >> a >> b;
  int ans;
  for (int i = 0; i < a; i++){
    if (i == 0){
      ans += b;
    }
    else{
      ans = ans * (b - 1);
    }
  }

  cout << ans << endl;
    
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,d,*mp = [int(i) for i in read().split()]

ans = 0
mp = iter(mp)
for x,y in zip(mp,mp):
    if x*x+y*y <= d*d: ans += 1

print(ans)

Measured memory_bytes: 54856
N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)
LB = A[-1] * 2  # 一回の握手で上がる幸福度の下限は、左手も右手もパワーが一番低い人を握った場合
UB = A[0] * 2   # 一回の握手で上がる幸福度の上限は、左手も右手もパワーが一番高い人を握った場合

# cgs[i] は パワーがi以上のゲストの数
cgs = [0] * (UB + 1)
for a in A:
    cgs[a] += 1
for i in range(UB, 0, -1):
    cgs[i - 1] += cgs[i]


# 組み合わせの数がM以上になる一回で発生する幸福度の閾値を二分探索する
def is_ok(n):
    m = 0
    for a in A:
        m += cgs[max(n - a, 0)]
    return m >= M


ok = LB
ng = UB + 1
while ng - ok > 1:
    m = (ok + ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m

# cps[i] は A[0]～A[i] の累積和
cps = A[:]
for i in range(1, N):
    cps[i] += cps[i - 1]

result = 0
for a in A:
# 左手固定
    t = cgs[max(ok - a, 0)] # 握手すると閾値を超えるひとたち
    if t != 0:
        result += a * t + cps[t - 1] # 1人目pとu回握手 + 右手はu人までと握手
        M -= t
result += ok * M # 閾値上の人の処理
print(result)


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

using namespace std;
typedef long long ll;
int main(){
    ll k,a,b;
    cin>>k>>a>>b;

    if(b<=a+1)
        cout<<k+1<<endl;
    else{
      ll cnt = a;
      k -= (a - 1);
      cnt = cnt + (b - a) * (k / 2);
      k %= 2;
      cnt += k;
      cout << cnt << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int sum = 0;
		for(int a = 1; a < K +1; a++) {
			for(int b = 1; b < K +1; b++) {
				for(int c = 1; c < K +1; c++) {
					sum += gcd(gcd(a, b), c);
				}
			}
		}
		System.out.println(sum);
		sc.close();
	}

/**
*	ユークリッドの互除法
*/		
    static int gcd(int a, int b) {
    	if(b == 0)return(a);
    	return(gcd(b, a % b));
		
    }
	
}

Measured memory_bytes: 35816
#include <stdio.h>

#define N_MAX 110000

int N;
int x[N_MAX];
int L;
int Q;
int a, b;

int ikeru_left[30][N_MAX];
int ikeru_right[30][N_MAX];

void maesyori(void) {
	int i, j;
	/* 各ホテルから1日で行けるホテルを求める */
	for (i = 0; i < N; i++) {
		int left, right, mid;
		/* 左へ */
		left = 0; ikeru_left[0][i] = right = i;
		while (left <= right) {
			mid = (left + right) / 2;
			if (x[i] - x[mid] <= L) {
				/* 行ける */
				right = mid - 1;
				if (mid < ikeru_left[0][i]) ikeru_left[0][i] = mid;
			} else {
				/* 行けない */
				left = mid + 1;
			}
		}
		/* 右へ */
		ikeru_right[0][i] = left = i; right = N - 1;
		while (left <= right) {
			mid = (left + right) / 2;
			if (x[mid] - x[i] <= L) {
				/* 行ける */
				left = mid + 1;
				if (ikeru_right[0][i] < mid) ikeru_right[0][i] = mid;
			} else {
				/* 行けない */
				right = mid - 1;
			}
		}
	}
	/* 各ホテルから2**k日で行けるホテルを求める */
	for (j = 1; j < 30; j++) {
		for (i = 0; i < N; i++) {
			ikeru_left[j][i] = ikeru_left[j - 1][ikeru_left[j - 1][i]];
			ikeru_right[j][i] = ikeru_right[j - 1][ikeru_right[j - 1][i]];
		}
	}
}

int motomeru(int start, int day, int ikeru[][N_MAX]) {
	int cur = start;
	int i;
	for (i = 0; i < 30; i++) {
		if ((day >> i) & 1) cur = ikeru[i][cur];
	}
	return cur;
}

int main(void) {
	int i, query_count;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &x[i]) != 1) return 1;
	}
	if (scanf("%d%d", &L, &Q) != 2) return 1;
	maesyori();
	for (query_count = 0; query_count < Q; query_count++) {
		int left, right, mid;
		int ret = N + 10;
		if (scanf("%d%d", &a, &b) != 2) return 1;
		a--; b--;
		left = 0; right = N; /* 着けるから絶対付くまで進捗する */
		while (left <= right) {
			int judge;
			mid = (left + right) / 2;
			if (a < b) {
				judge = motomeru(a, mid, ikeru_right) >= b;
			} else {
				judge = motomeru(a, mid, ikeru_left) <= b;
			}
			if (judge) {
				if (mid < ret) ret = mid;
				right = mid - 1;
			} else {
				left = mid + 1;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}


Measured memory_bytes: 24832
#include<stdio.h>
#define name 10
#define LEN 100005
typedef struct{
 char s[name];
  int time;
}P;
P Q[LEN+1];
int head,tail;
void Enqueue(P );
P Dequeue(void);
int main()
{
  int i,n,q,T=0;
  P y;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s%d",y.s,&y.time);
    Enqueue(y);
  }
  while(n!=0){
    y=Dequeue();
    if(y.time>q){
      y.time=y.time-q; 
      T+=q;
      Enqueue(y);
    } 
    else{
      T=T+y.time;
      printf("%s %d\n",y.s,T);
      n--;
    }
  }
  return 0;
}
 
void Enqueue(P Y){
  if(LEN==tail) tail=0; 
    Q[tail]=Y;
    tail++;
}
 
P Dequeue(void){
  if(head==LEN) head=0;
  return Q[head++];
}

Measured memory_bytes: 2160
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, D;
  cin >> N >>D;
  if(N%(2*D+1)==0){
    cout << N/(2*D+1) << endl;
  }
  else{
    cout << (N/(2*D+1))+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n, l = map(int, input().split())
    f = [l + i - 1 for i in range(1, n + 1)]

    print(sum(f) - min(f, key=lambda x: abs(0 - x)))


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29164
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#define SIZE 100005

using namespace std;

vector <int> vec[SIZE];
char str[SIZE];
bool dump[SIZE];
int deg[SIZE];
int col[SIZE];
int dp[SIZE];
int mx;

void dfs(int v,int p)
{
	int m1=0,m2=0;
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p&&!dump[to])
		{
			dfs(to,v);
			int vl=dp[to];
			if(m1<vl) swap(m1,vl);
			if(m2<vl) swap(m2,vl);
		}
	}
	mx=max(mx,m1+m2+col[v]);
	dp[v]=m1+col[v];
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--,b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	scanf("%s",&str);
	bool up=true;
	for(int i=0;i<n;i++)
	{
		if(str[i]=='W')
		{
			up=false;
			break;
		}
	}
	if(up)
	{
		puts("0");
		return 0;
	}
	queue <int> que;
	for(int i=0;i<n;i++)
	{
		deg[i]=vec[i].size();
		if(deg[i]==1&&str[i]=='B')
		{
			que.push(i);
		}
	}
	while(!que.empty())
	{
		int v=que.front();que.pop();
		dump[v]=true;
		for(int i=0;i<vec[v].size();i++)
		{
			int to=vec[v][i];
			deg[to]--;
			if(deg[to]==1&&str[to]=='B')
			{
				que.push(to);
			}
		}
	}
	int all=-2,rt;
	for(int i=0;i<n;i++)
	{
		if(!dump[i])
		{
			rt=i;
			all+=2;
			col[i]=(str[i]=='B'?0:1);
			col[i]^=(deg[i]%2);
			all+=col[i];
		}
	}
	if(all==1)
	{
		puts("1");
		return 0;
	}
	mx=0;
	dfs(rt,-1);
	//printf("* %d %d\n",all,mx);
	printf("%d\n",all-mx*2);
	return 0;
}


Measured memory_bytes: 14336
n = int(input())
s1 = input()
s2 = input()
mod = 1000000007
if n == 1:
    print(3)
    exit()
cnt = 3 if s1[0] == s2[0] else 6
for i in range(1, n):
    if s1[i-1] == s1[i]:
        cnt *= 1
        continue
    if s1[i-1] == s2[i-1]:
        cnt = cnt * 2 % mod
    elif s1[i] != s2[i]:
        cnt = cnt * 3 % mod
    else:
        cnt *= 1
print(cnt)


Measured memory_bytes: 9144
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

struct Info{

	bool operator<(const struct Info &arg) const{

		return loc < arg.loc;
	}

	ll loc,dir;
};

int N;
ll L;
ll left_dp[SIZE],right_dp[SIZE];
Info info[SIZE];


int main(){

	scanf("%d %lld",&N,&L);
	L--;

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

		scanf("%lld %lld",&info[i].loc,&info[i].dir);
		info[i].loc--;
	}

	sort(info,info+N);

	left_dp[0] = 0;

	//i番目まで左詰めした時の、左端方向の得点
	for(int i = 0; i < N; i++){

		if(info[i].dir == 0){ //左向き

			left_dp[i+1] = left_dp[i]+(info[i].loc-i);

		}else{ //右向き

			left_dp[i+1] = left_dp[i]-(info[i].loc-i);
		}
	}

	right_dp[N] = 0;

	//i番目まで右詰めした時の、右端方向の得点
	for(int i = N-1; i >= 0; i--){

		if(info[i].dir == 0){ //左向き

			right_dp[i] = right_dp[i+1]-((L-(N-1-i))-info[i].loc);

		}else{ //右向き

			right_dp[i] = right_dp[i+1]+((L-(N-1-i))-info[i].loc);
		}
	}

	ll ans = 0;

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

		ans = max(ans,left_dp[i]+right_dp[i]);
	}

	printf("%lld\n",ans);

	return 0;
}




Measured memory_bytes: 6216
#include<bits/stdc++.h>
using namespace std;
typedef signed long long int ll;
int h,w,k;
int p=1000000007;

ll d[100005];
int interval[10];

int main(){
    interval[0]=1;
    interval[1]=2;
    interval[2]=3;
    for(int i=3;i<=8;i++){
        interval[i]=interval[i-1]+interval[i-2];
    }
    cin>>h>>w>>k;
    ll dp[105][15]={0};
    int left[10],right[10],center[10];
    for(int i=1;i<=w;i++){
        left[i]=interval[max(0,i-3)]*interval[max(0,w-i-1)];
        right[i]=interval[max(0,i-2)]*interval[max(0,w-i-2)];
        center[i]=interval[max(0,i-2)]*interval[max(0,w-i-1)];
        left[i]%=p;
        right[i]%=p;
        center[i]%=p;
        
    }
    dp[0][1]=1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            
            if(j==1){
                dp[i][1]=dp[i-1][1]*center[1]+dp[i-1][2]*right[1];
            }else if(j<w){
                
                dp[i][j]=dp[i-1][j-1]*left[j]+dp[i-1][j]*center[j]+dp[i-1][j+1]*right[j];
            }else{
                dp[i][w]=dp[i-1][w-1]*left[w]+dp[i-1][w]*center[w];
            }
            dp[i][j]%=p;
        }
    }
    cout<<dp[h][k]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>

using namespace std;

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

    if(a > k){
        cout << k << endl;
    }else if(a + b > k){
        cout << a << endl;
    }else{
        cout << a-(k-a-b) << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
long long d[100010]={1};
int mbk(long long a,int n,int m){return n?(mbk((a*a)%m,n/2,m)*(n%2?a:1))%m:1;}
int inv(int a,int m){return mbk((long long)a,m-2,m);}
int aCb(int a,int b,int m){//printf("%d %d\n",a,b);
  //if(a<0)return 0;
  if(a<b)return 1;
  return d[a]*inv(d[b],m)%m*inv(d[a-b],m)%m;
}
int main(){
  long long n,m,r,b,i,M=1e9+7;
  scanf("%lld %lld",&n,&m);
  for(i=1;i<=n;i++)d[i]=(d[i-1]*i)%M;
  for(i=0;i<m;i++){
    r=n-m;
    b=m;
    if(r<i||b<i+1)printf("0\n");
    else printf("%lld\n",(1LL*aCb(r+1,i+1,M)*aCb(b-1,i,M)%M));
  }
  return 0;
}
		 


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int dir[8][4]= { {1,1,1,1}, {1,1,1,-1},{1,1,-1,1},{1,-1,1,1},{1,-1,-1,-1},{1,-1,-1,1},{1,-1,1,-1},{1,1,-1,-1} };

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int a[4];
	char t;
	int number;
	for(int i=0;i<4;i++)
	{
		cin >> t;
		a[i] = t - 48;
	}
	for(int i=0;i<8;i++)
	{
		int sum = 0;
		for(int j=0;j<4;j++)
		{
			sum += a[j] * dir[i][j];
		}
		if (sum == 7)
		{
			number = i;
			break;
		}
	}
	cout <<( (dir[number][0] == 1) ? "" : "-");
	for (int i = 0; i < 3; i++)
		cout<<a[i]<< ((dir[number][i+1] == 1) ? "+" : "-");
	cout << a[3] << "=7";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k;
    cin >> k;
    long a[k];
    for(int i=0;i<k;i++)cin >> a[i];
    bool chk = true;
    long upper = 2;
    long lower = 2;
    for(int i=k-1;i>=0;i--){
        if(upper%a[i] != 0)upper -= upper%a[i];
        if(lower%a[i] != 0)lower += a[i] - (lower%a[i]);
        if(upper<lower){
            chk = false;
            break;
        }
        upper += a[i]-1;
    }
    if(chk)cout<<lower<<" "<<upper<<endl;
    else cout<<-1<<endl;
}


Measured memory_bytes: 1024
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
hash = Hash.new(0)
a.each do |i|
    hash[i] += 1
end
hash_2 = Hash.new(0)
arr = Array.new(n+1,0)
count = 0
hash.each do |i|
    ans =  (i[1] * (i[1] - 1)) / 2
    hash_2[i[0]] = ans
    count += ans
end
a.each do |j|
    all = count
    point = hash_2[j]
    sa_1 = (hash[j] * (hash[j] - 1)) / 2
    sa_2 = ((hash[j]-1) * (hash[j] - 2)) / 2
    count = count - sa_1 + sa_2
    puts count
    #count = count + (sa_1 - sa_2)
    count = all
end

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

const int M = 1e9+7;
long long pwr( long long a , long long b , long long m = M ){
	
	long long ret = 1;
	a %= m , b %= m;

	while( b>0 ){
		if(b&1)	ret = ret*a % m;
		a = a*a % m;
		b >>= 1;
	}

	return ret;
}

int main(){

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

	int n;
	cin>>n;

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

	sort(a.begin(),a.end(),greater<int>());
	long long ans = 0;

	for(int i=0 ; i<n ; ++i)
		ans = ( ans + 1ll*(i+2)*a[i] ) % M;

	ans = ans * pwr(2,2*n-2) % M;
	cout<< ans ;
}

Measured memory_bytes: 1024
#include<iostream>
void swap(int *a,int*b){
    int work;
    work=*a;
    *a=*b;
    *b=work;
    return;
}
using namespace std;
int main(){
    int a,b;

    while(cin>>a>>b){
        if(b>a)swap(&a,&b);
        while(a=a%b,a)swap(&a,&b);
        cout<<b<<endl;
    }
    return 0;
}

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

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

    int N;
    cin>>N;

    vector<int> A(N-1), ans(N,0);
    for(int i=0;i<N-1;i++) {
        cin>>A[i];
        ans[A[i]-1]++;
    }

    for(int i : ans)
        printf("%d\n",i);
    
    return 0;
}



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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const ll INF = 1LL << 60;
//Write From this Line

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

	int ans = 0;
	rep(i,n){
		int love = a[i];
		if(i > love) continue;
		else {
			if (a[love] == i)
			ans ++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;
#define REP(i,s,N) for(ll i=s;i<N;++i)

int main () {
	int N;
	cin >> N;
	vector<ll> A(N);
	REP(i,0,N) scanf("%lld", &A[i]);

	sort(A.begin(), A.end());
	ll res = abs(A[0] - A[N-1]);
	cout << res << endl;
	return 0;
}



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

int main() {
  int N, A = 0,B = 0,G = 0;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++){
     cin >> v.at(i);
  }
 for (int i = 0; i < N; i++){
   int TOP = 0;
   int MAX = 0;
   for (int b = 0; b < N; b++){
     if (v.at(b) > MAX){
          MAX = v.at(b);
          TOP = b;
     }
   }
   G++;
   if (G % 2 == 1){
     A += MAX;
     v.at(TOP) = -1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
   }else{
     B += MAX;
     v.at(TOP) = -1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
   }
 }
  cout << A - B << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main() {
   int n;
   scanf("%d", &n);
  
   int v[n];
   int c[n];
  
   for(int i = 0; i < n; i++) {
      scanf("%d",&v[i]);
   }
   for(int i = 0; i < n; i++) {
      scanf("%d",&c[i]);
   }
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(v[i] - c[i] > 0){
      ans += v[i] - c[i];
    }
  }
  
  printf("%d", ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
using namespace std;

const double PI=acos(-1);

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

    int np = floor((double)n / 1.08);
    bool z = true;
    for(int i = np - 10; i <= np + 10; i++){
        if(floor(i*1.08) == n){
            cout << i << endl;
            z = false;
            break;
        }
    }
    if(z) cout << ":(" << endl;

    return 0;
}

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

int main()
{
  int a;
  string s;
  
  cin >> a;
  cin >> s;
  
  if (a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
loop do
  m, f, r = gets.split.map(&:to_i)
  sum = m + f
  case
  when m < 0 && f < 0 && r < 0
    exit
  when m < 0 || f < 0
    puts "F"
  when sum >= 80
    puts "A"
  when sum >= 65
    puts "B"
  when sum >= 50
    puts "C"
  when sum >= 30
    puts ( r < 50 )? "D": "C"
  else
    puts "F"
  end
end

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

int main() {
  int n,ans = 0;
  cin >> n;
  vector<int>l(n);
  rep(i,0,n) cin >> l[i];
  sort(l.begin(),l.end());
  rep(i,0,n-2) rep(j,i+1,n-1) rep(k,j+1,n){
    if(l[k] < l[i]+l[j]) ans++;
    else break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define qwq(x) cerr<<"# "<<#x<<" = "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned long long u64;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int S=(1<<26)+5,N=105,mod=998244353;
int f[S],g[N][N],h[N],a[N],n;
unordered_map<u64,int> F;
char s[N];

int fix(int x){
	return x>=mod?x-mod:x;
}

int solve(u64 s,int n){
	if(n<=1)return (s&1)+1;
	if(n<=25&&f[s|(1<<n)])return f[s|(1<<n)];
	if(n>25&&F.count(s|(1ll<<n)))return F[s|(1ll<<n)];	
	int res=solve(s>>1,n-1),suf[n+1],pre[n+1];
	if(s&1)res=fix(res+res);
	memset(suf,-1,sizeof suf);
	memset(pre,0,sizeof pre);
	rep(len,1,n/2){
		u64 st=(1ll<<len)-1,las=-1; int ans=0;
		for(int p=0,k=1;p+len<=n;p+=len,k++){
			st&=s>>p;
			if(k>=2){
				if(st!=las)ans=solve(st,len);
				if(suf[p+len]==-1)
					suf[p+len]=solve(s>>(p+len),n-p-len);
				pre[p+len]=fix(pre[p+len]+ans);
				las=st;
			}
		}
	}
	REP(i,n+1)if(pre[i]&&suf[i])
		res=(res+(ll)pre[i]*suf[i])%mod;
	if(n<=25)f[s|(1<<n)]=res;
	else F[s|(1ll<<n)]=res;
	return res;
}

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	rep(i,1,n)a[i]=s[i]-'0',g[i][i]=a[i]+1;
	rep(len,1,n/2)
		rep(l,1,n-2*len+1){
			u64 full=(1ll<<len)-1,st=(1ll<<len)-1,las=-1; int ans=0;
			for(int p=l,k=1;p+len<=n+1;p+=len,k++){
				REP(i,len)st&=full-(1ll<<i)+((1ll*a[p+i])<<i);
				if(k>=2){
					if(st!=las)ans=solve(st,len);
					las=st,g[l][p+len-1]=fix(g[l][p+len-1]+ans);
				}
			}
		}
	h[0]=1;
	rep(i,1,n)rep(j,0,i-1)
		h[i]=(h[i]+(ll)h[j]*g[j+1][i])%mod;
	cout<<h[n]<<endl;
	return 0;
}

Measured memory_bytes: 262656
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    long h = Long.parseLong(in.readLine());
    h = calc(h);
    System.out.println(h);
  }
  
  public static long calc(long h) {
    long res = 1;
    if(h>1)
      res = 1 + 2 * calc(h/2);
    return res;
  }
}

Measured memory_bytes: 32648
# vim: set fileencoding=utf-8:


def main():
    S = [int(ele) for ele in raw_input()]
    # len(S)の最大は10なので、線形走査
    diffs = []
    for idx in xrange(2, len(S)):
        temp = int(str(S[idx - 2]) + str(S[idx - 1]) + str(S[idx]))
        diffs.append(abs(temp - 753))

    print(min(diffs))


if __name__ == "__main__":
    main()


Measured memory_bytes: 2568
#include <cstdio>

int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}

int main(void)
{
    int n, ans, tmp1, tmp2;
    scanf("%d", &n);
    scanf("%d %d", &tmp1, &tmp2);
    ans = gcd(tmp1, tmp2);
    for (int i = 3; i <= n; i++)
    {
        int tmp;
        scanf("%d", &tmp);
        ans = gcd(ans, tmp);
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f,max_n=100005;
inline ll lowbit(ll x){return x&(-x);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
double r,pi=acos(-1);
long long a,b,x;
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	cin>>a>>b;
	for(int i=1;i<=b;i++)
	{
		cin>>x;
		a-=x;
	}
	if(a<0)
	{
		cout<<"-1";
	}
	else cout<<a;
	return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
double eps=1e-8;
struct S{
  P s,t;
  S(P s=P(),P t=P()): s(s),t(t) {}
};
struct C{
  P p;
  double r;
  C(P p=P(),double r=0):p(p),r(r){}
};


bool eq(double a,double b){
  return (-eps<a-b&&a-b<eps);
}

double Sqrt(double a){
  if(a<0)return 0;
  return sqrt(a);
}

int ccw(P a,P b,P c){
  b-=a;c-=a;a=c*conj(b);
  if(a.imag()>eps)return 1;
  if(a.imag()<-eps)return -1;
  if(a.real()<-eps)return 2;
  if(abs(b)+eps<abs(c))return -2;
  return 0;
}

bool isIntersect(S a,S b){
  return (ccw(a.s,a.t,b.s)*ccw(a.s,a.t,b.t)<=0 &&
          ccw(b.s,b.t,a.s)*ccw(b.s,b.t,a.t)<=0);
}

S crossPoint(C a,C b){
  P base=b.p-a.p;
  double k=(-b.r*b.r+a.r*a.r+norm(base));
  double w=k/(2.0*abs(base)),h=Sqrt(a.r*a.r-w*w);
  base/=abs(base);
  return S(a.p+base*P(w,h),a.p+base*P(w,-h));
}
/*
P getCrossPointCC(P p1,double r1,P p2,double r2){
  double cA = (r1*r1+norm(p1-p2)-r2*r2) / (2.0*r1*abs(p1-p2));
  return p1+(p2-p1)/abs(p1-p2)*r1*P(cA,sqrt(1.0-cA*cA));
}
*/
double abs(S s){
  return abs(s.s-s.t);
}

int n;
vector<C> t;
vector<S> u;

bool check(int l,int r,S s){
  for(int i=l;i<=r;i++){
    if(isIntersect(u[i],s))continue;
    return false;
  }
  return true;
}

double solve(){
  vector<double> A(n+1,1e9),B(n+1,1e9);
  u[0].s=u[0].t=t[0].p;
  u[n].s=u[n].t=t[n-1].p;
  A[0]=B[0]=0;
  for(int i=1;i<=n;i++){
    for(int j=0;j<i;j++){
      S target;
      
      target=S(u[j].s,u[i].s);
      if(check(j+1,i,target))A[i]=min(A[i],A[j]+abs(target));

      target=S(u[j].t,u[i].s);
      if(check(j+1,i,target))
        A[i]=min(A[i],B[j]+abs(target));

      target=S(u[j].s,u[i].t);
      if(check(j+1,i,target))
        B[i]=min(B[i],A[j]+abs(target));

      target=S(u[j].t,u[i].t);
      if(check(j+1,i,target))
        B[i]=min(B[i],B[j]+abs(target));
    }
    // printf("%d %.8f\n",i,min(A[i],B[i]));
  }
  return min(A[n],B[n]);
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    t.clear();
    t.resize(n+1);
    u.clear();
    u.resize(n+1);
    for(int i=0;i<n;i++){
      double x,y,r;
      cin>>x>>y>>r;
      t[i]=C(P(x,y),r);
      if(i){
        u[i]=crossPoint(t[i],t[i-1]);
        //        u[i].s=getCrossPointCC(t[i].p,t[i].r,t[i-1].p,t[i-1].r);
        //        u[i].t=getCrossPointCC(t[i-1].p,t[i-1].r,t[i].p,t[i].r);
      }
    }
    printf("%.8f\n",solve());
  }
  return 0;
}

Measured memory_bytes: 1288
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	if (n >= 65 && n <= 90)cout << "1" << endl;
	else if (n >= 97 && n <= 122)cout << "2" << endl;
	else cout << "0" << endl;
	return 0;
}


Measured memory_bytes: 3088
n = int(input())
a= list(input().split())
a = [int(i) for i in a]

a.sort()
a.reverse()

alice=0
bob=0 

for i in range(n):
    
    if i % 2 == 0 :
        alice += a[i]
    else :
        bob += a[i]
        
print(alice - bob)

Measured memory_bytes: 3064
s = input()
t = input()
n = len(s)
ans = 'No'
for i in range(n):
    a = ''
    for k in range(n):
        l = k + i
        if l >= n: l = l - n
        a += s[l]
    if a == t:
        ans = 'Yes'
        break

print(ans)

Measured memory_bytes: 3060
// B.

#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int n, x, mn = 1LL << 30, m;
	cin >> n >> x;
	for (int i = 0; i < n; ++i) {
		cin >> m;
		x -= m;
		mn = min(mn, m);
	}
	int ans = n + x / mn;
	cout << ans << endl;
	return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y

#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

// util {{{
#define FOR(i, start, end) for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f, c, ...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); })(c))
#define ll long long int
#define VI vector<int>
template <typename C>
i64 SIZE(const C &c)
{
    return static_cast<i64>(c.size());
}

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {})
{
    if (comp(xmax, x))
    {
        xmax = x;
        return true;
    }
    return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {})
{
    if (comp(x, xmin))
    {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit
{
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

bool isOK(int mid, double key)
{
}

int binary_search(double key)
{
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2000000000;
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key))
            right = mid;
        else
            left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

bool isKaibun(string st)
{
    bool ans = true;
    int n = st.length();
    REP(i, n / 2)
    {
        if (st[i] != st[n - i - 1])
        {
            return false;
        }
    }
    return true;
}

int toInt(char a)
{
    return a - '0';
}

int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

void solve()
{
    int N;
    cin >> N;
    if (N >= 30)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

signed main()
{

    solve();

    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <map>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

ll N,M;
ll a[2];
ll ans = 1;
int main(){
  cin >> N >> M;
  rep(i,N){
    ll t;
    cin >> t;
    a[t%2]++;
  }
  if(M==1){
    if(a[1] == 0){
      cout << "0" << endl;
      return 0;
    }
  }
  rep(i,a[1]-1){
    ans *= 2;
  }
  rep(i,a[0]){
    ans *= 2;
  }
  cout << ans << endl;
}


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

#define Pi acos(-1.)
#define pb push_back
#define all(x) (x).begin(), x.end()
#define mp make_pair
#define fi first
#define se second
#define pii pair<int, int>
#define FILE "474"
#define standart 1

using namespace std;

typedef long long ll;

const int INF = 1e9 + 322;
const ll LINF = 2e18 + 474;
const int MAXN  = 2e5 + 228;
const int MOD = 1e9 + 7;
const double eps = 1e-14;


void solve() {
    ll n, y;
    cin >> n >> y;
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n - i; j++) {
            ll k = n - i - j;
            ll x = i * (ll)10000 + j * (ll)5000 + k * (ll)1000;
            if(x == y) {
                cout << i << " " << j << " " << k << endl;
                return;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}



int main() {
    if(!standart) {
        freopen(FILE".in", "r", stdin);
        freopen(FILE".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T = 1;
    while(T--)
        solve();

    return 0;
}


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

int main()
{
	string s;
	cin >> s;
	char c0;
	c0 = s.at(0);
	if (c0 == s.at(1) && (c0 == s.at(2) || c0 == s.at(3)))
	{
		cout << "No" << endl;
		return 0;
	}
	if (c0 == s.at(1) && s.at(2) == s.at(3))
		cout << "Yes" << endl;
	else if ((c0 == s.at(2) && s.at(1) == s.at(3)) || (c0 == s.at(3) && s.at(1) == s.at(2)))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
// ※※※ 解答不能 ※※※
// 解き直し.
// ABC 135解説
// https://img.atcoder.jp/abc135/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL MOD = 1e9 + 7;
LL dp[100005][13];

int main(){

    // 1. 入力情報取得.
    char S[100005];
    scanf("%s", S);
    int n = strlen(S);
    
    // 2. 場合の数を計算.
    // 解説通り.
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        int c;
        if(S[i] == '?') c = -1;
        else            c = S[i] - '0';
        for(int j = 0; j < 10; j++){
            if(c != -1 && c != j) continue;
            for(int ki = 0; ki < 13; ki++) dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki];
        }
        for(int j = 0; j < 13; j++) dp[i + 1][j] %= MOD;
    }
    
    // 3. 出力 ～ 後処理.
    printf("%llu\n", dp[n][5]);
    return 0;

}


Measured memory_bytes: 10496
import java.util.*;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = Integer.parseInt(sc.next());
		
		int count = 0;
		
		if(N % 2 == 0 ){
			System.out.println(N/2);
		
		} else {
			System.out.println(N/2 + 1);
		}
		
	
	
	}

}

Measured memory_bytes: 22740
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int n;
ll a[40001], t[40001];
ll H, A, D, S;
typedef pair<ld, int> speP;
vector<speP> v;
int main() {
	cin >> n;
	ll ans = 0;
	cin >> H >> A >> D >> S;
	bool valid = true;
	rep(i, n) {
		ll h, d, s;
		cin >> h >> a[i] >> d >> s;
		a[i] = max(a[i] - D, (ll)0);
		if (s < S) {
			ans -= a[i];
		}
		ll damage = A - d;
		if (damage <= 0&&a[i]>0) {
			valid = false; break;
		}
		else if (damage <= 0)continue;
		else {
			t[i] = (h + damage - 1) / damage;
			v.push_back({ a[i] / (ld)t[i], i });
		}
	}
	if (!valid)cout << -1 << endl;
	else {
		sort(v.begin(), v.end(),greater<speP>());
		ll sum = 0;
		rep(i, v.size()) {
			int id = v[i].second;
			sum += t[id];
			ans += sum * a[id];
			if (ans >= H)break;
		}
		if (ans >= H)cout << -1 << endl;
		else cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 5344
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		String S = "";
		int Count = 0;

		Scanner scan = new Scanner(System.in);

		S = scan.next();
		
		for(int i=0;i< S.length();i++) {
			String str=S.substring(i, i+1);
			if(str.equals("+")) {
				Count++;
			}else if(str.equals("-")){
				Count--;
			}else {
				
			}
		}
		System.out.println(Count);
	}

}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll n,k,sum=0,ans;
    cin >> n >> k;
    vector<ll> x(n),dist(n);
    rep(i,n) cin >> x[i];
    rep(i,n){
        dist[i] = min(x[i],k-x[i]);
    }
    rep(i,n) sum += dist[i];
    ans = sum * 2;
    cout << ans << "\n"; 
    return 0;
}

Measured memory_bytes: 256
import heapq
N, M =map(int, input().split())
A=list(map(lambda x: int(x)*(-1), input().split())) #各要素を-1倍
heapq.heapify(A) #Aを優先度付きキューに

for _ in range(M):
	temp_min=heapq.heappop(A)
	heapq.heappush(A, (-1)*(temp_min*(-1)//2))
print(-sum(A))


Measured memory_bytes: 20460
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr ll INF = 1ll << 55;

template <typename T> inline constexpr bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline constexpr bool chmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

// multi-dimensional vector (require c++14)
template <typename T, typename U>
static inline vector<U> make_nd_vector(T &&n, U &&val) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
static inline decltype(auto) make_nd_vector(T &&n, Args &&... args) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<decltype(make_nd_vector(forward<Args>(args)...))>(
      forward<T>(n), make_nd_vector(forward<Args>(args)...));
}
//
// Print from Iterator
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
//
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

int main() {
  string s, t;
  cin >> s >> t;
  Yes(s == t.substr(0, t.length() - 1));
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int a,b;
    cin >>a>>b;
    int ans = 0;
    vector<int> tower(999);
    for(int i = 1;i < 1000;i++){
        tower[i] = (i*(i+1))/2;
    }
    ans = (b-a) + tower[b-a - 2] - a;
    cout << ans - 1 << endl;
}   


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

int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << "Hello World" << endl;
  }
  if (n == 2) {
    int a, b;
    cin >> a >> b;
    cout << a+b << endl;
  }
}

Measured memory_bytes: 256
// <------------- Template -----------------------> //


#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(0);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAX5];

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, y, q, m, k;
string s, t, d;
ll sum = 0;
ll cou = 0;
vll B,W;

// <------------- Implement Functions Here ----------> //

void dfs(ll x,ll color ,ll time_in=0) {
	if(color == 1) 		B[x]=time_in;
	else if(color == 2) W[x]=time_in;
	for(auto it : adj[x]) {
		bool iswhite = (color == 1) && (B[it] != -1);
		bool isblack = (color == 2) && (W[it] != -1);
		if(isblack || iswhite) continue;
		dfs(it,color,time_in+1);
	}
} 

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n ;
	for(ll i=0;i<n-1;i++) {
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	B = vll(n+1,-1),W = vll(n+1,-1);
	B[1] = 0;
	W[n] = 0;
	dfs(1,1);
	dfs(n,2);
	ll ans = 0;
	for(ll i=1;i<=n;i++) {
		if(B[i]<=W[i]) ans++;
		else ans--;
	}
	if(ans > 0) cout<<"Fennec";
	else cout<<"Snuke";
}

int main() {
	fastio; randomINT;
	//cin>>T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 14948
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        int a = Integer.parseInt(scanner.nextLine());

        if (n % 500 <= a) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21076
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
#define FOR(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
int num[10];
int B[10];
int C[10];
bool flag;
void solve(int, int, int);

int main(void){
	int N;
	cin >> N;
	for(int k = 0; k < N; k++){
		flag = false;
		fill_n(B , 10, -1);
		fill_n(C , 10, -1);
		for(int i = 0; i < 10; i++){
			cin >> num[i];
		}
		solve(0, 0, 0);
		if(flag){cout << "YES" << endl; continue;}
		cout << "NO" << endl;
	}

	return 0;
}

void solve(int cnt,int right, int left){
	if(cnt == 10){
		flag = true;
		return;
	}
	if(num[cnt] > right) solve(cnt+1, num[cnt], left);
	if(num[cnt] > left) solve(cnt+1, right, num[cnt]);
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  
  for(int i=a; i>0; i--){
    if(a%i==0 && b%i==0){
      k--;
      if(k==0){ 
        cout << i <<endl;
        return 0;
      }
    }
  }
}
      

Measured memory_bytes: 256