akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;

bool is_valid(int &x, int &y) {
  int xx = -x + 2 * y, yy = 2 * x - y;
  if (xx < 0 || yy < 0 || xx % 3 != 0 || yy % 3 != 0) return false;
  x = xx / 3; y = yy / 3;
  return true;
}
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

vector<ll> fact, ifact;

void init_table(int n) {
  fact.assign(n + 1, 1), ifact.assign(n + 1, 1);
  for (int i = 2; i < n + 1; ++i) fact[i] = i * fact[i - 1] % MOD;
  ifact[n] = modinv(fact[n], MOD);
  for (int i = n; i > 2; --i) ifact[i - 1] = i * ifact[i] % MOD;
}

ll comb(int n, int r) {
  return fact[n] * (ifact[r] * ifact[n - r] % MOD) % MOD;
}
int main() {
  int x, y;
  cin >> x >> y;
  init_table(2e6 + 5);
  if (!is_valid(x, y)) {
    puts("0");
    return 0;
  }
  cout << comb(x + y, y) << endl;;
  return 0;
}



Measured memory_bytes: 31616
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <string>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  string s;
  while(n>0){
    char c = (n - 1) % 26 + 'a';
    s.push_back(c);
    if(n<=26){
      break;
    }
    int a = n % 26;
    n /= 26;
    if(a==0){
      n -= 1;
    }
  }
  for(int i=s.size()-1; i>=0; i--){
    cout << s[i];
  }
  cout << endl;
  return 0;
}

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

int main(){
	int resid[4][3][10] = {};
	int n;
	
	cin >> n;
	
	for(int i=0; i<n; i++){
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		resid[b-1][f-1][r-1] += v;
	}
	
	for(int b=0; b<4; b++){
		for(int f=0; f<3; f++){
			for(int r=0; r<10; r++){
				cout << " " << resid[b][f][r];
			}
			cout << "\n";
		}
		if(b==3) break;
		cout << "####################\n";
	}
	
	return 0;
}


Measured memory_bytes: 3104
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int main() {
	int N;
	vector<int>A;
	cin >> N;
	int ans = 1;
	int kis = 1;
	for (int i = 0; i < N; ++i) {
		int a; cin >> a;
		A.push_back(a);
		ans *= 3;
		if (a % 2 == 0) {
			kis *= 2;
		}
	}
	cout << ans - kis << endl;
	return 0;
}


Measured memory_bytes: 888
a=[]
for i in range(3):
    a.append(list(map(int,input().split())))

n=int(input())
for k in range(n):
    bk=int(input())
    for i in range(3):
        for j in range(3):
            if bk==a[i][j]:
                a[i][j]=0

c=0
for i in range(3):
    if a[0][i]==a[1][i] and a[0][i]==a[2][i]:
        c += 1
if a[0]==[0,0,0] or a[1]==[0,0,0] or a[2]==[0,0,0]:
    print("Yes")
elif c!= 0:
    print("Yes")
elif (a[0][0]==0 and a[1][1]==0 and a[2][2]==0) or (a[0][2]==0 and a[1][1]==0 and a[2][0]==0):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38452
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

n=int(input())
A=[i*(i+1)//2 for i in range(4500)]

def qq(score,ANS):
    if score==0:return ANS
    if score==1: return ANS+[1]
    maxmon= bileft(A,score)
    return qq(score-maxmon, ANS+[maxmon])
ANS=qq(n,[])
for i in ANS:
    print(i)

Measured memory_bytes: 171324
#include<stdio.h>
long long dp[102][10][1001];
int main(void){
    dp[0][0][0]=1;
    for(int i=0;i<=100;i++){
        for(int j=0;j<=9;j++){
            for(int k=0;k<=1000;k++){
                if((i+k)<=1000 && j+1 <= 9){
                    dp[i+1][j+1][k+i]+=dp[i][j][k];
                }
                dp[i+1][j][k]+=dp[i][j][k];
            }
        }
    }
    while(1){
        int cnt,sum;
        scanf("%d %d",&cnt,&sum);
        if(cnt==0&&sum==0)break;
        printf("%lld\n",dp[101][cnt][sum]);
    }
    return 0;
}

Measured memory_bytes: 8928
flag = False
a = []
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

h, w = map(int, input().split())

for i in range(h):
    a.append(input())

for k in range(h):
    for j in range(w):
        if a[k][j] == "#":
            for i in range(4):
                nx = j + dx[i]
                ny = k + dy[i]

                if nx < 0 or ny < 0 or nx >= w or ny >= h:
                    continue
                if a[ny][nx] == "#":
                    break
            else:
                flag = True
                print("No")
        if flag:
            break
    if flag:
        break
else:
    print("Yes")

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

int main() {
 vector<vector<int>> card(3, vector<int>(3));
 
 for(int i = 0; i < 3; i++){
	 cin >> card.at(i).at(0); 
     cin >> card.at(i).at(1);
     cin >> card.at(i).at(2);
 }
 int times; cin >> times;
 
 vector<vector<int>> hits(3, vector<int>(3,0));
 for(int i = 0; i < times; i++) {
    int current; cin >> current;
	for(int j = 0; j < 3; j++)  {
      for(int k = 0; k < 3; k++) {
       if(card.at(j).at(k) ==  current) {
        hits.at(j).at(k)++; 
       }
      }
    }
 }
  for(int j = 0; j < 3; j++)  {
    int check = 0;
      for(int k = 0; k < 3; k++) {
        check += hits.at(j).at(k); 
      }
    if(check == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  for(int j = 0; j < 3; j++)  {
    int check = 0;
      for(int k = 0; k < 3; k++) {
        check += hits.at(k).at(j); 
      }
    if(check == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  if(hits.at(1).at(1) == 1) {
   if(hits.at(0).at(0) == 1 && hits.at(2).at(2) == 1 ) {
      cout << "Yes" << endl;
      return 0;
   } else if(hits.at(0).at(2) == 1 && hits.at(2).at(0) == 1 ) {
      cout << "Yes" << endl;
      return 0;
   }
  }
  
  cout << "No" << endl;
  
 return 0; 
}

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

int cities[100010];

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

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

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

    int ans = abs(cities[0] - x);

    for (int i = 0; i < n - 1; i++)
    {
        ans = gcd(ans, abs(cities[i] - cities[i + 1]));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int k;
int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
    cin>>k;
    cout<<a[k-1];
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200010], n;
ll ans;
int main()
{
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	for (int i = 0; i < n; i++)
	{
		if (i && a[i] > a[i-1]+1)
		{
			printf("-1\n");
			return 0;
		}
		else if (!i && a[i])
		{
			printf("-1\n");
			return 0;
		}
		if (i && a[i] == a[i-1]+1) ans++;
		else ans += a[i];
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1792
L, R = map(int ,input().split())
if R-L >= 2019:
    print(0)
else:
    li = []
    for i in range(L, R+1):
        li.append(i%2019)
    l = []
    for i in range(len(li)-1):
        for j in range(i+1,len(li)):
            l.append((li[i]*li[j])%2019)
    a = min(l)

    print((a)%2019)


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n, m;
	cin >> n >> m;

	ll scc = min(n, m / 2);
	ll cccc = (m - 2 * scc) / 4;

	out(scc + cccc);

	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<int> vi;

signed main(){
    string S;
    int size,check,temp;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> S;
    size = (int)S.size();
    temp = -1;
    ll count = 0;
    rep(i,size) {
        check = 0;
        loop(j,temp+1,size) {
            if(S[j]=='W') {
                temp = j;
                check = 1;
                break;
            }
        }
        if(check == 0) {
            break;
        }
        count += temp-i;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 720
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

readString = map BS.unpack . BS.words

getIntList = readIntList <$> BS.getLine

getString = concat . readString <$> BS.getLine

splitK :: String -> Int -> [String]
splitK [] k = []
splitK t k = s : splitK t' k
  where
    (s, t') = splitAt k t

calc :: String -> Int -> Int -> Int -> Int
calc [] p' r' s' = 0
calc [c] p' r' s'
  | c == 'p' = p'
  | c == 'r' = r'
  | c == 's' = s'
calc t p' r' s'
  | c == 'p' = p' + calc t' p' r' s'
  | c == 'r' = r' + calc t' p' r' s'
  | c == 's' = s' + calc t' p' r' s'
  where
    c = head t
    c' = head (tail t)
    t' = if c /= c' then tail t else tail (tail t)

main = do
  [n, k] <- getIntList
  [s', p', r'] <- getIntList
  t <- getString
  let ts = transpose (splitK t k)
  print $ sum $ map (\t -> calc t p' r' s') ts


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

int main(){
	int h,w;
	cin >> h >> w;
	int n;
	cin >> n;
	
	vector<int> a(n);
	rep(i,n){
		cin >> a[i];
	}
	
	queue<int> que;
	rep(i,n){
		rep(j,a[i]){
			que.push(i+1);
		}
	}
	
	int ans[105][105];
	
	for (int i = 0; i < h; ++i) {
		if(i % 2 == 0){
			for (int j = 0; j < w; ++j) {
				ans[i][j] = que.front();
				que.pop();
			}
		}else{
			for (int j = w-1; j >= 0 ; --j) {
				ans[i][j] = que.front();
				que.pop();
			}
		}
	}
	
	rep(i,h){
		rep(j,w){
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
	
    return 0;
}



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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int dp[1 << 21];

int main(){
    while (true) {
        int n;
        cin >> n;
        if (!n) return 0;
        
        string country[45];
        int power[45], nearc[45];
        int near[45][45];
        string nears[45][45];
        for (int i = 0; i < n; ++i) {
            cin >> country[i] >> power[i] >> nearc[i];
            for (int j = 0; j < nearc[i]; ++j) {
                cin >> nears[i][j];
            }
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                for (int k = 0; k < nearc[j]; ++k) {
                    if (country[i] == nears[j][k]) {
                        near[j][k] = i;
                    }
                }
            }
        }
        int n1 = n / 2;
        int n2 = n - n1;
        for (int i = 0; i < (1 << n1); ++i) {
            dp[i] = 0;
            for (int j = 0; j < n1; ++j) {
                if ((i >> j) & 1) {
                    dp[i] += power[j + n2];
                    for (int k = 0; k < nearc[j + n2]; ++k) {
                        if (near[j + n2][k] >= n2 && ((i >> (near[j + n2][k] - n2)) & 1))
                            goto A;
                    }
                }
            }
            continue;
            
        A:
            dp[i] = 0;
            for (int j = 0; j < n1; ++j) {
                if ((i >> j) & 1) {
                    dp[i] = max(dp[i], dp[i - (1 << j)]);
                }
            }
        }
        int ma = 0;
        for (int i = 1; i < (1 << n2); i += 2) {
            int sum = 0, bitmsk = 0;
            for (int j = 0; j < n2; ++j) {
                if ((i >> j) & 1) {
                    sum += power[j];
                    for (int k = 0; k < nearc[j]; ++k) {
                        if (near[j][k] >= n2){
                            bitmsk |= 1 << (near[j][k] - n2);
                        }
                        else if ((i >> near[j][k]) & 1)
                            goto B;
                    }
                }
            }
            ma = max(ma, sum + dp[bitmsk ^ ((1 << n1) - 1)]);
            
        B:
            continue;
        }
        cout << ma << "\n";
    }
    return 0;
}

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

string grid[500];
int posy[26][2],posx[26][2];
int pos[26][2][2];
bool use[26];
int n,m;
int res;

bool cluck(int y,int x,int z){
  int k;
  int cnt[26];
  for(int i=0;i<26;i++)cnt[i] = 0;

  k = 1;
  while(y+k<n && grid[y+k][x] == '.')k++;
  if(y+k<n)cnt[grid[y+k][x]-'A']++;

  k = 1;
  while(x+k<m && grid[y][x+k] == '.')k++;
  if(x+k<m)cnt[grid[y][x+k]-'A']++;

  k = 1;
  while(y-k>=0 && grid[y-k][x] == '.')k++;
  if(y-k>=0)cnt[grid[y-k][x]-'A']++;

  k = 1;
  while(x-k>=0 && grid[y][x-k] == '.')k++;
  if(x-k>=0)cnt[grid[y][x-k]-'A']++;

  if(cnt[z]==2){
    res += 2;
    grid[posy[z][0]][posx[z][0]] ='.';
    grid[posy[z][1]][posx[z][1]] ='.';
    return true; 
  }
  return false;
}

int main(){
  cin >> n >> m;
  for(int i=0;i<n;i++)cin >> grid[i];

  for(int i=0;i<26;i++){
    posy[i][0] = -1;
    posx[i][0] = -1;
    posy[i][1] = -1;
    posx[i][1] = -1;
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(grid[i][j] != '.'){
	if(posy[grid[i][j]-'A'][0]<0){
	  posy[grid[i][j]-'A'][0] = i;
	  posx[grid[i][j]-'A'][0] = j;
	}else{
	  posy[grid[i][j]-'A'][1] = i;
	  posx[grid[i][j]-'A'][1] = j;
	}
      }
    }
  }

  res = 0;
  while(1){
    bool f = false;
    for(int i=0;i<26;i++){
      if(posy[i][0] == posy[i][1]){
	int s = min(posx[i][0],posx[i][1]),g = max(posx[i][0],posx[i][1]);
	for(int j=s+1;j<g;j++){
	  if(grid[posy[i][0]][j]=='.')f |= cluck(posy[i][0],j,i);
	}
      }else if(posx[i][0] == posx[i][1]){
	int s = min(posy[i][0],posy[i][1]),g = max(posy[i][0],posy[i][1]);
	for(int j=s+1;j<g;j++){
	  if(grid[j][posx[i][0]]=='.')f |= cluck(j,posx[i][0],i);
	}
      }else{
	if(grid[posy[i][0]][posx[i][1]] == '.')f |= cluck(posy[i][0],posx[i][1],i);
	if(grid[posy[i][1]][posx[i][0]] == '.')f |= cluck(posy[i][1],posx[i][0],i);
      }
    }
    if(!f)break;
  }

  cout << res << endl;
}

Measured memory_bytes: 0
#include <stdio.h>

void swap(int x,int y);

int main(){
    int x1, x2;
    while(1){
    scanf("%d %d",&x1,&x2);
    if(x1 == 0 && x2 == 0) break;
    swap(x1,x2);
    }
}

void swap(int x,int y){
    if(x > y){
        printf("%d %d\n",y,x);
    }else{
        printf("%d %d\n",x,y);
    }
}

Measured memory_bytes: 1796
import java.util.*;
import java.io.*;

import static java.lang.Character.isUpperCase;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
       int N = in.nextInt();
       String S = in.next();
       if(N%2!=0)
       {
           System.out.println("No");
       }
        else
            {
                if(S.substring(0 , N/2).equals(S.substring(N/2 , N)))
                {
                    System.out.println("Yes");
                }
                else
                    {
                        System.out.println("No");
                    }
            }
    }

}
















Measured memory_bytes: 35796
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const ll mod = 1e9 + 7 ;
const ll inf =
 // 1e9 + 5 ;
 1e18L + 5;
const ll nax = 2e5 + 5;
void min_self(ll&a , ll b){a=min(a,b);}
void max_self(ll&a , ll b){a=max(a,b);}
void add_self(ll&a , ll b){a=(a+b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll h , n ; cin >> h>> n ; 
vector<pair<ll,ll>> v(n) ; 
for(ll i = 0 ; i<n ; i++){
	ll k , l  ; cin >> k>> l ; 
	v[i] = {k , l };
}

vector<ll> dp(h+1,inf) ; 
dp[0]=0;
for(ll i = 0 ; i<n ; i++){
	for(ll j = 1 ; j<= h ; j++){

	if(j-v[i].first>=0)	min_self (dp[j] , (dp[j-v[i].first] + v[i].second ));
	else min_self(dp[j] , v[i].second);
	}
	// for(auto it:dp)cout<<setw(3) << it;cout << endl;
}
 cout << dp[h] ;
	
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
int mod=998244353;
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    int dp[n+1];
    dp[1]=0;
    dp[2]=abs(arr[2]-arr[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
       // cout<<dp[i]<<endl;
    }
    cout<<dp[n]<<endl;
}


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

int main() {
  string S;
  cin >> S;
  int length = S.size();
  vector<int> ans(length, 0);
  int cnt = 0;
  for (int i = 0; i < length; i++) {
    if (S[i] == 'R') cnt++;
    else {
      ans[i] += cnt/2;
      ans[i-1] += (cnt+1)/2;
      cnt = 0;
    }
  }
  for (int i = length-1; i >= 0; i--) {
    if (S[i] == 'L') cnt++;
    else {
      ans[i] += cnt/2;
      ans[i+1] += (cnt+1)/2;
      cnt = 0;
    }
  }
  for (int i = 0; i < length; i++) {
    cout << ans[i];
    if (i != length) cout << " ";
    else cout << endl;
  }
}


Measured memory_bytes: 3828
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll H, N;
  cin >> H >> N;
  vl A(N);
  REP(i, N) cin >> A[i];
  ll sum = 0;
  REP(i, N) sum += A[i];
  if (sum >= H)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
int main()
{	
	int a[3],d=0;
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	for(int i=0;i<3;i++)
	{
		for(int j=i+1;j<3;j++)
		{
			if(a[j]==a[i])
				d++;
		}
	}
	if(d==3)
	printf("%d\n",1);
	else
	printf("%d\n",3-d);
	return 0;
}

Measured memory_bytes: 128
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    y, m, d = map(int, S.split('/'))
    if m <= 4:
        print('Heisei')
    elif m > 4:
        print('TBD')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> p;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template <class T> bool chmax(T &a, const T &b) {
  if(a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if(b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

  int l = 0;
  rep(i, n) chmax(l, a[i]);
  int r = a[0];
  int rv = min(r, l - r);
  rep(i, n) {
    if(a[i] == l) continue;
    int nv = min(a[i], l - a[i]);
    if(rv <= nv) {
      r = a[i];
      rv = nv;
    }
  }
  cout << l << ' ' << r << endl;

  return 0;
}


Measured memory_bytes: 640
# coding: utf-8

n,m=map(int,input().split())
while n!=0:
    d=[]
    p=[]
    
    for i in range(n):
        d_i,p_i=map(int,input().split())
        d.append(d_i)
        p.append((p_i,i)) #タプルでインデックス情報を付加
    #警備がいない場合の期待値を求める
    
    hazard=0
    for i in range(n):
        hazard+=d[i]*p[i][0]
    
    #単位長さあたりの期待値で降順ソート
    p.sort(key=lambda x:-x[0])
    
    for i in range(n):
        rest=d[p[i][1]]
        if m<rest:
            hazard-=m*p[i][0]
            break
        else:
            m-=rest
            hazard-=rest*p[i][0]
        
    print(hazard)
    n,m=map(int,input().split())



Measured memory_bytes: 7268
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int N;
  cin >> N;
  
  int c[N];
  int s[N];
  int f[N];
  
  for(int i=1;i<N;i++){
  cin >> c[i] >> s[i] >> f[i];}
  
  
//早く次の駅に行ったほうがいい
//現時点秒直近の出発時刻＞現時点の点を探し
//その時刻にcを足したものをans現時点の時刻とする,という操作を繰り返す
// 最初の駅が iの時は、s[i]からs[N-1]までやる

 vector<int> ans(N,0);
  
 for(int i=1;i<N;i++){
   for(int j=i;j<N;j++){
     if (ans[i] < s[j]) ans[i] = s[j] + c[j];
     else if (ans[i] % f[j] ==0) ans[i] += c[j];
     else ans[i] = ((ans[i] / f[j]) + 1) * f[j] + c[j];
     }
   
   cout << ans[i]<< "\n";}
  
   cout << 0;
  
}
   

Measured memory_bytes: 256
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/3/ALDS1_3_C


import sys
from collections import deque


def solve():
    # linked list
    dll = deque()

    # get all lines at one time
    lines = sys.stdin.readlines()

    for i in range(1, int(lines[0]) + 1):
        # get one line
        ope = lines[i].split()

        # insert X
        if ope[0] == 'insert':
            dll.appendleft(ope[1])

        # delete ...
        elif ope[0] == 'delete':
            if ope[1] in dll:
                dll.remove(ope[1])
        elif ope[0] == 'deleteFirst':
            dll.popleft()
        elif ope[0] == 'deleteLast':
            dll.pop()

    print(*dll, sep=' ')


if __name__ == '__main__':
    solve()



Measured memory_bytes: 212232
Ss = input()

N = len(Ss)
SPrev = ''
i = 0
ans = 0
while i < N-1:
    if Ss[i] != SPrev:
        SPrev = Ss[i]
        i += 1
    else:
        SPrev = Ss[i:i+2]
        i += 2
    ans += 1

if i == N-1 and SPrev != Ss[-1]:
    ans += 1

print(ans)


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  ll r,s,p; cin>>r>>s>>p;
  map<char,ll> m;
  m['s']=r;
  m['p']=s;
  m['r']=p;
  string t; cin>>t;
  
  vb check(n*2);
  ll ans=0;
  rep(i,n){
    if(check[i]) continue;
    ans+=m[t[i]];
    if(i+k<n && t[i+k]==t[i]) check[i+k]=true;
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 512
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    map<string,ll> Z;
    FORI(i,0,N)
    {
        string S;
        cin>>S;
        Z[S]++;
    }
    cout<<"AC x "<<Z["AC"]<<endl;
    cout<<"WA x "<<Z["WA"]<<endl;
    cout<<"TLE x "<<Z["TLE"]<<endl;
    cout<<"RE x "<<Z["RE"]<<endl;

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


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3812
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>

//#define PI 3.141592653589

using namespace std;

//  文字列を置換する
std::string Replace( std::string String1, std::string String2, std::string String3 )
{
    std::string::size_type  Pos( String1.find( String2 ) );

    while( Pos != std::string::npos )
    {
        String1.replace( Pos, String2.length(), String3 );
        Pos = String1.find( String2, Pos + String3.length() );
    }

    return String1;
}



int main()
{
	int n;
	string str;
	
	cin >> n;
	cin.ignore();
	for (int i=0; i<n; i++)
	{
		getline(cin, str);
		str = Replace(str, "Hoshino", "Hoshina");
		cout << str << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< long long int ,long long int > iil;
typedef long long ll;
typedef vector< ll > vl;
const ll MOD = 1e9+7,MAX = 1e5;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for( auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define EE '\n'
#define ll long long int
#define forn(i,n) for ( int i=0 ; i<n ; i++ )
#define fornl(i,n) for(ll i=0;i<n;i++)
#define forni(i,j,n) for ( int i=j ; i<n ; i++ )
#define PI 3.14159265
#define g(a,b) a>b?a:b
#define l(a,b) a<b?a:b
#define SOT(A) sort(A.begin(),A.end())
#define SOTR(A) sort(A.rbegin(),A.rend())

//////////////////Sieve////////////////////
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
//////////////////Sieve////////////////////



int main(){
    int t=1;
    //cin>>t;
    forn(term,t){
        ll n,m,s=0;
        cin>>n>>m;
        cout<<min((n%m),m-n%m)<<endl;
        
    }
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

int main(){
    int N=in();
    int C[N-1], S[N-1], F[N-1];
    rep(i, N-1){
        cin>>C[i]>>S[i]>>F[i];
    }
    int t;
    rep(i, N-1){
        t=0;
        for(int j=i;j<N-1;j++){
            if(t<S[j]){
                t=S[j]+C[j];
            }
            else{
                if(t%F[j]!=0)
                t+=(F[j]-t%F[j])+C[j];
                else
                t+=C[j];
            }
        }
        cout<<t<<endl;
    }
    cout<<0<<endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[derive(Debug)]
struct UnionFind {
    par: Vec<usize>,
    rank: Vec<usize>,
    pub sum: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind {
            par: (0..n).collect(),
            rank: vec![0; n],
            sum: vec![1; n],
        }
    }

    fn find(&mut self, x: usize) -> usize {
        let par = self.par[x];
        if par != x {
            self.par[x] = self.find(par);
        }
        self.par[x]
    }

    fn unite(&mut self, x: usize, y: usize) {
        let x = self.find(x);
        let y = self.find(y);
        if x == y {
            return;
        }

        let rx = self.rank[x];
        let ry = self.rank[y];
        if rx < ry {
            self.par[x] = y;
            self.sum[y] += self.sum[x];
        } else {
            self.par[y] = x;
            self.sum[x] += self.sum[y];
            if rx == ry {
                self.rank[x] += 1;
            }
        }
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut ab: Vec<(usize, usize)> = Vec::new();
    for _ in 0..m {
        let a: usize = read();
        let b: usize = read();
        ab.push((a-1, b-1));
    }
    let mut sum = n * (n-1) / 2;
    let mut ans: Vec<usize> = vec![0; m];
    let mut uf = UnionFind::new(n);
    ans[m-1] = sum;
    for i in (1..m).rev() {
        let (a, b) = ab[i];
        if !uf.same(a, b) {
            let a = uf.find(a);
            let b = uf.find(b);
            sum -= uf.sum[a] * uf.sum[b];
            uf.unite(a, b);
        }
        ans[i-1] = sum;
    }
    for i in 0..m {
        println!("{}", ans[i]);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 11516
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int mo = 998244353;

ll ksm(ll x, ll y) {
	ll s = 1;
	for(; y; y /= 2, x = x * x % mo)
		if(y & 1) s = s * x % mo;
	return s;
}

const int N = 2e5 + 5;

int n;
char s[N];
int a[N];
ll ans, sum, a2[N];
ll cnt[N], f[N];
int w[N], w0;

int main() {
	//freopen("a.in", "r", stdin);
	scanf("%d", &n);
	a2[0] = 1; fo(i, 1, n) a2[i] = a2[i - 1] * 2 % mo;
	scanf("%s", s + 1);
	reverse(s + 1, s + n + 1);
	fo(i, 1, n) a[i] = s[i] - '0';
	sum = 1;
	fo(i, 1, n) sum = (sum + a2[i - 1] * a[i]) % mo;
	ans = sum * 2 * n % mo;
	fo(d, 1, n - 1) if(n % d == 0 && (n / d % 2 == 1)) {
		w[++ w0] = d;
		ll ps = 0;
		fo(j, n - d + 1, n) ps = (ps + a2[j - (n - d + 1)] * a[j]) % mo;
		cnt[d] += ps;
		int ky = -1;
		fd(i, n / d - 2, 0) {
			fd(j, d, 1) {
				int x = a[n - d + j], y = a[i * d + j];
				if((n / d - 1 - i) % 2 == 1) x = !x;
				if(x < y) { ky = 1; break;}
				if(x > y) { ky = 0; break;}
			}
			if(ky != -1) break;
		}
		if(ky != 0) cnt[d] ++;
	}
	fo(i, 1, w0) {
		int x = w[i];
		f[x] = cnt[x];
		fo(j, 1, i - 1) if(x % w[j] == 0 && x / w[j] % 2 == 1)
			f[x] -= f[w[j]];
		ans -= (ll) (2 * n - 2 * x) * f[x];
	}
	ans = (ans % mo + mo) % mo;
	pp("%lld\n", ans);
}

Measured memory_bytes: 4736
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int mod=1000000007;
long long ex[100003];
long long c[100003];
long long b[100003];
long long a[100003];
/*
long long searchEX(char s[], int start, int end){
    long long result;
    if(start==end) result=1;
    else if(s[start]=='?') result = 3*searchEX(s, start+1, end);
    else result = searchEX(s, start+1, end);
    return result%mod;
}
long long searchC(char s[], int start, int end){
    long long result;
    if(start==end) result=0;
    else if(s[start]=='C') result = searchEX(s, start+1, end)+searchC(s,start+1,end);
    else if(s[start]=='?') result = searchEX(s, start+1, end)+3*searchC(s, start+1, end);
    else result = searchC(s, start+1, end);
    return result%mod;
}
long long searchB(char s[], int start, int end){
    long long result;
    if(start==end) result=0;
    else if(s[start]=='B') result = searchC(s, start+1, end)+searchB(s,start+1,end);
    else if(s[start]=='?') result = searchC(s, start+1, end)+3*searchB(s, start+1, end);
    else result = searchB(s, start+1, end);
    return result%mod;
}
long long searchA(char s[], int start, int end){
    long long result;
    if(start==end) result=0;
    else if(s[start]=='A') result = searchB(s, start+1, end)+searchA(s,start+1,end);
    else if(s[start]=='?') result = searchB(s, start+1, end)+3*searchA(s, start+1, end);
    else result = searchA(s, start+1, end);
    return result%mod;
}
*/
void searchEX(char s[], int start, int end){
    ex[end] = 1;
    for(int i=end-1; i>=start; i--){
        if(s[i]=='?') ex[i] = (ex[i+1]*3)%mod;
        else ex[i] = ex[i+1];
    }
    return;
}
void searchC(char s[], int start, int end){
   c[end] = 0;
    for(int i=end-1; i>=start; i--){
        if(s[i]=='C') c[i]=ex[i+1]+c[i+1];
        else if( s[i]=='?') c[i]=ex[i+1]+c[i+1]*3;
        else c[i] = c[i+1];
        c[i] = c[i]%mod;
    }
}
void searchB(char s[], int start, int end){
   b[end] = 0;
    for(int i=end-1; i>=start; i--){
        if(s[i]=='B') b[i]=c[i+1]+b[i+1];
        else if( s[i]=='?') b[i]=c[i+1]+b[i+1]*3;
        else b[i] = b[i+1];
        b[i] = b[i]%mod;
    }
}
void searchA(char s[], int start, int end){
   a[end] = 0;
    for(int i=end-1; i>=start; i--){
        if(s[i]=='A') a[i]=b[i+1]+a[i+1];
        else if( s[i]=='?') a[i]=b[i+1]+a[i+1]*3;
        else a[i] = a[i+1];
        a[i] = a[i]%mod;
    }
}

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

    searchEX((char*)s.c_str(),0,s.length());
    searchC((char*)s.c_str(),0,s.length());
    searchB((char*)s.c_str(),0,s.length());
    searchA((char*)s.c_str(),0,s.length());
    cout << a[0] <<endl;
    
    //cout << searchA((char*)s.c_str(),0,s.length()) << endl; 
    return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#define N 1005
#define inf 1000000000
#define lowbit(o) o&(-o)
using namespace std;
int i,j,k,l,s,n,m,tot,last[N],x,Next[N],to[N],a[N],f[N][5005];
struct node {
	int a[3];
}A[N];
inline void add(int x,int y) {
	Next[++tot]=last[x]; last[x]=tot; to[tot]=y;
}
inline void Min(int &x,int y) {
	x=min(x,y);
}
int main() {
	scanf("%d",&n);
	for (i=2;i<=n;i++) scanf("%d",&x),add(x,i);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=n;i;i--) {
		for (j=1;j<=a[i];j++) f[0][j]=inf;
		f[0][0]=tot=0;
		for (j=last[i];j;j=Next[j]) {
			++tot;
			for (k=0;k<=a[i];k++) f[tot][k]=inf;
			for (k=0;k<=a[i]-A[to[j]].a[1];k++) Min(f[tot][k+A[to[j]].a[1]],f[tot-1][k]+A[to[j]].a[2]);
			for (k=0;k<=a[i]-A[to[j]].a[2];k++) Min(f[tot][k+A[to[j]].a[2]],f[tot-1][k]+A[to[j]].a[1]);
		}
		A[i].a[2]=inf;
		for (j=0;j<=a[i];j++) Min(A[i].a[2],f[tot][j]);
		if (A[i].a[2]==inf) return puts("IMPOSSIBLE"),0;
		A[i].a[1]=a[i];
	}
	puts("POSSIBLE");
}


Measured memory_bytes: 17280
#include <stdio.h>
 
int main(void) {
    int num,i;
    int a,b,c;
    int right;
    scanf("%d",&num);
    for(i=0;i<num;i++) {
        scanf("%d %d %d",&a,&b,&c);
        right=0;
        if(a*a+b*b==c*c)right=1;
        if(b*b+c*c==a*a)right=1;
        if(c*c+a*a==b*b)right=1;
        printf("%s\n",right?"YES":"NO");
    }
    return 0;
}

Measured memory_bytes: 580
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N, Y;
    cin >> N >> Y;

    const ll C = 10 * N - Y / 1000;

    FOR(x, 0, N)
    {
        if (C < 0)
            break;

        FOR(y, 0, N - x)
        {
            ll z = N - x - y;
            if (5 * y + 9 * z == C)
            {
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

class BM{
public:
	//pattern???text????????????????????????
	std::string text, pattern;
	BM(std::string tex, std::string pat) : text(tex), pattern(pat){};

	int skip[256];

	void find(std::vector<int> &ret){
		int patSize = pattern.size();

		rep(i, 256)skip[i] = patSize;
		rep(i, patSize)skip[pattern[i]] = (patSize - i - 1);

		int i = patSize - 1;
		while (i < text.size()){
			int check = 0;
			while (check < patSize && text[i - check] == pattern[patSize - check - 1])++check;
			if (check == patSize){
				ret.push_back(i - patSize + 1);
				++i;
			}
			else i = std::max(i + 1, i - check + skip[text[i - check]]);
		}
	}
};

int main(){
	std::string a, b;
	std::cin >> a >> b;

	BM bm(a, b);
	std::vector<int> v;
	bm.find(v);

	rep(i, v.size()){
		std::cout << v[i] << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1220
(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let n = Scanf.sscanf (read_line ()) "%d" (
        fun n -> 
                n
)

let lst = Str.split (Str.regexp " ") (read_line ())
          |> List.map int_of_string

let rec f lst =
        let exists = List.exists (fun elmnt -> elmnt mod 2 = 1) lst in
                if exists then
                        0
                else
                        1 + (f (List.map (fun elmnt -> elmnt lsr 1) lst))

let () =
        f lst
        |> Printf.printf "%d\n"



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

struct Edge{
    ll to;
    ll weight;
    Edge(ll t, ll w): to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;

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

    ll n;
    cin >> n;

    Graph g(n);
    rep(i, n-1){
        ll a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        g[a].push_back(Edge(b, c));
        g[b].push_back(Edge(a, c));
    }

    ll q, k;
    cin >> q >> k;
    --k;

    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
    pq.push(make_pair(0, k));
    const ll INF = 1LL << 60;
    vector<ll> dist(n, INF);
    dist[k] = 0;
    while(!pq.empty()){
        pair<ll, ll> p = pq.top();
        pq.pop();
        int v = p.second;

        for(auto ne: g[v]){
            if(dist[v] + ne.weight < dist[ne.to]){
                dist[ne.to] = dist[v] + ne.weight;
                pq.push(make_pair(dist[ne.to], ne.to));
            }
        }
    }

    // rep(i, n) cout << dist[i] << " ";
    // cout << endl;

    rep(i, q){
        ll x, y;
        cin >> x >> y;
        --x;
        --y;

        cout << dist[x] + dist[y] << "\n";
    }

    return 0;
}

Measured memory_bytes: 11120
#include<iostream>
#include <algorithm>
#include <string>
#define syso(s) std::cout<<s<<endl;
#define sc(i) std::cin>>i;
#define rep(i,n)for(i=0;i<n;i++)
using namespace std;
int main() {
	int a;
	sc(a);
	if (a >= 1200) {
	syso("ARC")
	}
	else {
		syso("ABC")
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt()*2;
    Integer[] l=new Integer[n];
    for(int i=0;i<n;i++){
      l[i]=sc.nextInt();
    }
    Arrays.sort(l);
    int ans=0;
    for(int i=0;i<n;i+=2){
      ans+=l[i];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764