akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;

  int A[50], B[50], C[50], D[50];

  rep(i, 0, N) {
    cin >> A[i] >> B[i];
  }

  rep(j, 0, M) {
    cin >> C[j] >> D[j];
  }

  rep(i, 0, N) {
    int min_dist = abs(A[i] - C[0]) + abs(B[i] - D[0]), checkpoint = 1;
    
    rep(j, 1, M) {
      const int cur_dist = abs(A[i] - C[j]) + abs(B[i] - D[j]);
      if (min_dist > cur_dist) {
        min_dist = cur_dist;
        checkpoint = j + 1;
      }
    }
    cout << checkpoint << endl;
  }
}


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


public class A{
	
	public static void Main(){
	
		int n = Int32.Parse(Console.ReadLine());
		if(n == 1)
		{
			Console.WriteLine("Hello World");			
		}
		else
		{
			int a = Int32.Parse(Console.ReadLine());
			int b = Int32.Parse(Console.ReadLine());
			Console.WriteLine(a + b);
		}		
		
	}
	
}

Measured memory_bytes: 13140
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}


void solve() {
    while (true) {
        int n, se, w, p;
        cin >> n >> se >> w >> p;
        if (n == 0) return;
        map<int, int> cnt;
        string s;
        REP(i, n) {
            s.push_back((se / 7) % 10 + '0');
            if (se % 2 == 0) se = (se / 2LL);
            else se = (se / 2) ^ w;
        }
        int ans = 0;
        
        if (p <= 10) {
            int geko[10] = {};
            for (int q = 0; q < s.length(); ++q) {
                int neko[10] = {};
                for (int t = 0; t < p; ++t) {
                    int target = t * 10 + s[q] - '0';
                    neko[target % p] += geko[t];
                }
                if(s[q] != '0')
                neko[(s[q] - '0') % p]++;
                for (int t = 0; t < p; ++t) {
                    geko[t] = neko[t];
                }
                ans += geko[0];
            }
            cout << ans << endl;
            continue;
        }
        reverse(ALL(s));
        int now = 0;
        cnt[now] = 1;
        int ta = 1;
        for (int q = 0; q < s.length(); ++q) {
            now += ta * (ll)(s[q] - '0');
            now %= p;
            if (s[q] != '0') {
                ans += cnt[now];
            }
            cnt[now]++;
            ta *= 10LL;
            ta %= p;
        }
        cout << ans << endl;
    }
}

#undef int
int main() {
    init();
    solve();
}



Measured memory_bytes: 8656
import sys
from itertools import accumulate

input = sys.stdin.readline


def binary_search(a, key):
    """Meguru type binary search"""
    ok = -1
    ng = len(a)

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= key:
            ok = mid
        else:
            ng = mid

    return ok


def main():
    N, M, K = map(int, input().split())
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))

    B_cumsum = tuple(accumulate(B))
    ans = 0
    time = 0
    for i in range(N + 1):
        if time > K:
            break
        j = binary_search(B_cumsum, K - time) + 1
        ans = max(ans, i + j)

        if i < N:
            time += A[i]

    print(ans)


if __name__ == "__main__":
    main()


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

//xを２進展開した時、各けたの数字を格納した。
vll calc(ll x){
  vll v;
  for (int l=0;l<100;l++){
    ll c=x%2;
    v.push_back(c);
    x/=2;
  }
  return v;
}

//xは、A_1,A_2,...,A_Nのつもり。数字の列。
vll counter(vll x){
  //初期化した。
  ll N=x.size();
  vll cnt(100);
  for (int l=0;l<100;l++){
    cnt[l]=0;
  }
  //各xの各げんA_iの各桁を計算して、その分cntにたす。
  for(ll i=0;i<N;i++){
    vll v=calc(x[i]);
    for(ll l=0;l<100;l++){
      cnt[l]+=v[l];
    }
  }
  
  return cnt;
}


int main(){
  //入力の受け取り
  ll N,K;cin>>N>>K;
  vll x;
  for(ll i=0;i<N;i++){
    ll a;cin>>a;
    x.push_back(a);
  }
  //各桁の買ううんとをした。
  vll count=counter(x);
  //Kをbinary representした。
  vll bin_K=calc(K);

  //maxを与えるXを求める。
  ll X=0;
  int flag=0;
  //大きい方から決めてく。
  for(int l=99;l>=0;l--){
    //X_lは、Xのl桁目？
    int X_l=0;
    //Kの上位とXの上位が一致していて、かつKのl桁目が0だったり
    if((flag==1)||(bin_K[l]==1)){
      if((N%2==1)&&(count[l]==N/2)){
        X+=pow(2,l);
        X_l=1;
      }
      else if(count[l]<N/2){
        X+=pow(2,l);
        X_l=1;
      }
    }

    if (X_l!=bin_K[l]){
      //Kのl桁目とXのl桁目が一致していないなら、flag=1。上から決めてるからね。
      flag=1;
    }
  }
  //最後に、実際の値を計算する。
  ll ans=0;
  for (ll i=0;i<N;i++){
    ans+=X^x[i];
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 1908
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        n: usize,
    }

    let n = n - 1; // 0-indexed
    let mut letter_count = 1;
    let mut pow = 26;
    let mut rest = n;
    while rest >= pow {
        rest -= pow;
        letter_count += 1;
        pow *= 26;
    }
    // letter_count 文字で rest 番目
    let mut rs = vec![];
    for _ in 0..letter_count {
        rs.push(rest % 26);
        if rest >= 26 {
            rest /= 26;
        } else {
            rest = 0;
        }
    }

    for i in rs.into_iter().rev() {
        let c = ('a' as u8 + i as u8) as char;

        print!("{}", c);
    }
    println!("");
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<Int> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }
	vector<vector<int>> g(N);
	for (int i = 0; i < M; ++i) {
		int x, y;
		cin >> x >> y;
		g[x].emplace_back(y);
		g[y].emplace_back(x);
	}

	vector<vector<pair<Int, int>>> tree;
	int T = 0;
	vector<int> belong(N, -1);
	for (int i = 0; i < N; ++i) {
		if (belong[i] >= 0) { continue; }
		
		deque<int> que;
		que.emplace_back(i);
		vector<pair<Int, int>> t;
		t.emplace_back(a[i], i);
		while (!que.empty()) {
			int u = que.front(); que.pop_front();
			if (belong[u] >= 0) { continue; }
			belong[u] = T;
			
			for (auto v : g[u]) {
				if (belong[v] >= 0) { continue; }
				que.emplace_back(v);
				t.emplace_back(a[v], v);
			}
		}
		tree.push_back(t);
		++T;
	}

	if (T == 1) {
		cout << "0\n";
		return 0;
	}

	Int ans = 0;
	vector<pair<Int ,int>> v;
	for (int i = 0; i < T; ++i) {
		sort(tree[i].begin(), tree[i].end());
		ans += tree[i][0].first;
		for (int j = 1; j < tree[i].size(); ++j) {
			v.emplace_back(tree[i][j]);
		}
	}
	
	sort(v.begin(), v.end());
	vector<int> cnt(T, 1);
	int V = T;
	for (int i = 0; i < T; ++i) {
		if (V >= 2 * (T - 1) || v.size() <= i) { break; }
		int idx = v[i].second;
		if (cnt[belong[idx]] >= T) { continue; }
		ans += v[i].first;
		++cnt[belong[idx]];
		++V;
	}
	
	if (V < 2 * (T - 1)) { cout << "Impossible\n"; }
	else { cout << ans << endl; }

	return 0;
}


Measured memory_bytes: 12628
s = input()

res = -1
if s == "SUN":
    res = 7
if s == "MON":
    res = 6
if s == "TUE":
    res = 5
if s == "WED":
    res = 4
if s == "THU":
    res = 3
if s == "FRI":
    res = 2
if s == "SAT":
    res = 1

print(res)

Measured memory_bytes: 38384
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

# def printA(A):
#     for i, n in enumerate(A):
#         print(n, end='')
#         if i != N-1:
#             print(' ', end='')
#     print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

S = [x for x in input().split()]

Z = {}

for s in S:
    if s in Z.keys():
        Z[s] += 1
    else:
        Z[s] = 1

maxlen = 0
maxlenstr = ''

maxnum = 0
maxnumstr = ''

for z in Z:
    if maxlen < len(z):
        maxlen = len(z)
        maxlenstr = z
    if maxnum < Z[z]:
        maxnum = Z[z]
        maxnumstr = z

print(maxnumstr,maxlenstr,sep=' ')    



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

vector<int> Zalgorithm(const string &s)
{
  int n = s.size();
  vector<int> res(n);
  res[0] = n;
  int i = 1, j = 0;
  while (i < n)
  {
    while (i + j < n && s[j] == s[i + j])
      ++j;
    res[i] = j;
    if (j == 0)
    {
      ++i;
      continue;
    }

    int k = 1;
    while (i + k < n && res[k] < j - k)
    {
      res[i + k] = res[k];
      k++;
    }
    i += k;
    j -= k;
  }
  return res;
}
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  string s;
  cin >> s;

  int res = 0;
  for (int i = 0; i < N; i++)
  {
    string t = s.substr(i);
    auto lcp = Zalgorithm(t);

    for (int j = 0; j < t.size(); j++)
    {
      int l = min(lcp[j], j);
      res = max(res, l);
    }
  }
  cout << res << endl;
  return 0;
}
//参考


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

using namespace std;

int n, k;
int a[55];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	int p = 1;
	for (int i = 2; i <= n; ++i) {
		if (a[i] < a[p]) {
			p = i;
		}
	}
	vector<int> ans;
	for (int i = 1; i <= n; ++i) {
		if (i == p) {
			continue;
		}
		ans.push_back(i);
		--a[i];
	}
	ans.push_back(p);
	--a[p];
	while (k) {
		int nw = -1;
		for (int i = 1; i <= n; ++i) {
			if (i == p) {
				continue;
			}
			if (nw == -1 || a[i] < a[nw]) {
				nw = i;
			}
		}
		if (!a[nw]) {
			cout << -1 << '\n';
			return 0;
		}
		for (int i = 1; i <= n; ++i) {
			if (i == p || i == nw) {
				continue;
			}
			ans.push_back(i);
			--a[i];
		}
		ans.push_back(nw);
		--a[nw];
		p = nw;
		--k;
	}
	
	cout << (int) ans.size() << '\n';
	
	for (int v : ans) {
		cout << v << ' ';
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;

int main(void) {
    while (true) {
        int n;
        int r;
        cin >> n >> r;
        if (n == 0) {
            break;
        }

        VI hana(n);
        for (int i = 0; i < n; i++) {
            hana[i] = n - i;
        }
        for (int i = 0; i < r; i++) {
            int p;
            int c;
            cin >> p >> c;
            VI temp(p - 1);
            for (int j = 0; j < p - 1; j++) {
                temp[j] = hana[j]; 
            }
            for (int j = 0; j < c; j++) {
                hana[j] = hana[j + p - 1]; 
            }
            for (int j = 0; j < p - 1; j++) {
                hana[j + c] = temp[j]; 
            }
        }
        cout << hana[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c,d,e;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        if(a<=b)
            printf("%d\n",a*c);
        else
            printf("%d\n",b*c+(a-b)*d);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 100001
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<P1,ll> P2;
typedef list<int> li;
typedef list<li> lli;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll a;
	int b;
};

int main(){

	int d,t,s;
	cin>>d>>t>>s;
	if(t*s>=d)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 3612
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
  cout << fixed << setprecision(30);
  ll n;
  cin>>n;
  if(n%2==0)putout(n/2);
  else putout(n/2+1);
}


Measured memory_bytes: 256
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10
    tmp = 0
    S = input()
    min_num = 0
    tmp_sum = 0
    diffs = deque()
    prev = ''
    ans = down = up = 0
    for i,c in enumerate(S):
        # dbg(i,ans)
        if c == '<':
            #trough
            if prev == '>':
                ans += down*(down-1)//2
                ans += max(down,up)
                down = up = 0
            ans += up
            up += 1
        
        else:
            down += 1

        prev = c

    #trough
    if S[-1] == '>':
        ans += down*(down-1)//2
        ans += max(down,up)
    if S[-1] == '<':
        ans += up

    print(ans)



    
main()

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

int main() {
    int arr[3],i,temp;
    cin>>arr[0]>>arr[1]>>arr[2];
    
    temp = arr[0];
    arr[0] = arr[1];
    arr[1] = temp;
    
    temp = arr[0];
    arr[0] = arr[2];
    arr[2] = temp;
    
    
    for(i=0;i<3;i++){
        cout<<arr[i]<<" ";
    }
    cout<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import itertools

S = input()

num_list = []
list_S =list(S)

kugiri = [i for i in range(1,len(S))]

for i in range(len(S)):
    if i == 0:
        num_list.append(int(S))
        continue
    combi_list = list(itertools.combinations(kugiri, i))
    for j in range(len(combi_list)):
        temp_num_list = []
        for k in range(len(combi_list[j])):
            if k == 0:
                temp_num_list.append(int(S[:combi_list[j][k]]))
            if k == len(combi_list[j]) - 1:
                temp_num_list.append(int(S[combi_list[j][k]:]))
            else:
                temp_num_list.append(int(S[combi_list[j][k]:combi_list[j][k+1]]))
        num_list.append(sum(temp_num_list))

print(sum(num_list))

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

class MyClass
{
    public static int ReadInt()
    {
        return int.Parse(Console.ReadLine());
    }

    public static int[] ReadInts()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }

    public static void Main(string[] args)
    {
        var input = ReadInts();
        var N = input[0];
        var M = input[1];
        var a = new int[N];
        var b = new int[M];
        for (int i = 0; i < N; i++)
        {
            a[i] = ReadInt();
        }
        for (int i = 0; i < M; i++)
        {
            b[i] = ReadInt();
        }
        var vote = new int[N];
        for (int i = 0; i < M; i++)
        {
            for (int j = 0; j < N; j++)
            {
                if (a[j] <= b[i])
                {
                    vote[j] += 1;
                    break;
                }
            }
        }
        var max = 0;
        for (int i = 0; i < N; i++)
        {
            if (vote[max] < vote[i])
            {
                max = i;
            }
        }
        Console.WriteLine(max + 1);
    }
}



Measured memory_bytes: 16404
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

template <typename T>
string tostring(const T& input) {
    ostringstream oss;
    oss << input;
    return oss.str();
}


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

int k=s.size();

string t=tostring(k-2);

string r=s[0]+t+s[k-1];

cout<<r<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main()

{

    long long int n, i, sum = 0;

    long long int a[100005];

    scanf("%lld", &n);

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

        scanf("%lld", &a[i]);

    sum = a[0];

    for (i = 1; i < n; i++)

    {

        if (a[i] > sum)

            sum = a[i];

        if (a[i] <= sum - 2)

            break;

    }

    if (i != n)

        printf("No\n");

    else

        printf("Yes\n");

    return 0;

}



Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
llong a, b, c;
string s[100005];
string ans;

bool dfs(llong i, llong a, llong b, llong c) {
    if (a < 0 || b < 0 || c < 0) return false;
    if (i >= n && a >= 0 && b >= 0 && c >= 0) {
        return true;
    }
    else if (i >= n) {
        return false;
    }

    if (s[i] == "AC") {
        if (dfs(i + 1, a + 1, b, c - 1)) {
            ans += 'A';
            return true;
        }
        else if (dfs(i + 1, a - 1, b, c + 1)) {
            ans += 'C';
            return true;
        }
        return false;
    }
    else if (s[i] == "AB") {
        if (dfs(i + 1, a + 1, b - 1, c)) {
            ans += 'A';
            return true;
        }
        else if (dfs(i + 1, a - 1, b + 1, c)) {
            ans += 'B';
            return true;
        }
        return false;
    }
    else if (s[i] == "BC") {
        if (dfs(i + 1, a, b + 1, c - 1)) {
            ans += 'B';
            return true;
        }
        else if (dfs(i + 1, a, b - 1, c + 1)) {
            ans += 'C';
            return true;
        }
        return false;
    }
}

int main() {
    cin >> n >> a >> b >> c;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }

    dfs(0, a, b, c);
    reverse(ans.begin(), ans.end());

    if (ans.size() == n) {
        cout << "Yes" << endl;
        for (int i = 0; i < n; i++) {
            cout << ans[i] << endl;
        }
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 14688
N = int(input())
i = 0
str = ""

if N == 0:
  print('0')
  exit(0)

while(N != 0):
  if N % 2 == 1:
    str = '1' + str
    N = N - 1
  else:
    str = '0' + str
  #print(i,N)
  N = N // (-2)
  #i += 1

print(str)

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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<string> res = {"AC","WA","TLE","RE"};
    vector<int> C(4);
    for (int i=0;i<N;i++){
        string s;
        cin >> s;
        for (int j=0;j<4;j++){
            if (s==res[j]) C[j]++;
        }
    }
    for (int i=0;i<4;i++){
        cout << res[i] << " x " << C[i] << "\n";
    }
}

Measured memory_bytes: 3652
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>

using namespace std;

template<typename T, typename S>
istream& operator >> (istream& is, pair<T, S>& p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

int Solve(const vector<char>& A, const vector<char>& B) {
    int H = A.size();
    vector<vector<int>> cost(H * 2 + 1, vector<int>(H + 1, 0));
    for (int shift = -H; shift <= H; ++shift) {
        int i = shift + H;
        for (int j = 1; j <= H; ++j) {
            cost[i][j] = cost[i][j - 1];
            if (shift <= 0) { // A starts right away, B start after |shift| chars
                if (j + shift >= 1 && A[j - 1] == B[j + shift - 1]) {
                    cost[i][j]++;
                }
            } else {// B starts right away, A start after shift chars
                if (j - shift >= 1 && B[j - 1] == A[j - shift - 1]) {
                    cost[i][j]++;
                }
            }
        }
    }
    vector<vector<int>> dp(H + 1, vector<int>(H + 1, 0));
    for (int al = 1; al <= H; ++al) {
        for (int bl = 1; bl <= H; ++bl) {
            dp[al][bl] = cost[bl - al + H][max(bl, al)]
                       + min(dp[al - 1][bl], dp[al][bl - 1]);
        }
    }
    return dp[H][H];
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int H, W;
    cin >> H >> W;
    vector<vector<char>> C(W, vector<char>(H));
    for (int j = 0; j < H; ++j) {
        for (int i = 0; i < W; ++i) {
            cin >> C[i][j];
        }
    }
    int ans = 0;
    for (int i = 1; i < W; ++i) ans += Solve(C[i - 1], C[i]);
    cout << ans;
}


Measured memory_bytes: 4524
#include <bits/stdc++.h>
        #include<iostream>
        #include<cstdio>
        #include<vector>
        #include<queue>
        #include<map>
        #include<cstring>
        #include<string>
        #include <math.h>
        #include<algorithm>
        #include<functional>
   //    #define int long long
        #define inf  1000000007
        #define pa pair<int,int>
#define ll long long
        #define pal pair<ll,ll>
        #define ppa pair<int,pa>
        #define EPS (1e-10)
        #define equals(a,b) (fabs((a)-(b))<EPS)

        using namespace std;

        class Point{
        	public:
        	double x,y;
        	Point(double x=0,double y=0):x(x),y(y) {}
        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
        	Point operator * (double a) {return Point(x*a,y*a);}
        	Point operator / (double a) {return Point(x/a,y/a);}
        	double absv() {return sqrt(norm());}
        	double norm() {return x*x+y*y;}
        	bool operator < (const Point &p) const{
        		return x != p.x ? x<p.x: y<p.y;
        	}
        	bool operator == (const Point &p) const{
        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
        	}
        };
        typedef Point Vector;

        struct Segment{
        Point p1,p2;
        };

    double hen(Vector a){
    if(fabs(a.x)<EPS && a.y>0) return acos(0);
    else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
    else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
    else if(fabs(a.y)<EPS && a.x>0) return 0.0;
    else if(a.y>0) return acos(a.x/a.absv());
    else return 2*acos(0)+acos(-a.x/a.absv());

    }

        double dot(Vector a,Vector b){
        	return a.x*b.x+a.y*b.y;
        }
        double cross(Vector a,Vector b){
        	return a.x*b.y-a.y*b.x;
        }
        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};
        //----------------kokomade temple------------
int n,k;
signed main(){

int a,b;
	
	cin>>a>>b;
	
	if(a<=0 && b>=0) cout<<"Zero"<<endl;
	else if(a>0) cout<<"Positive"<<endl;
	else{
		if((a-b)%2==0) cout<<"Negative"<<endl;
		else cout<<"Positive"<<endl;
	}
	
	return 0;
        }


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

#define jaldi ios_base::sync_with_stdio(false)
#define fr(i,j,n) for(i=j;i<n;i++)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%ld",&x)
#define sll(x) scanf("%lld",&x)
#define sc(x) scanf("%c",&x)
#define ss(x) scanf("%s",x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%ld",x)
#define pll(x) printf("%lld",x)
#define pc(x) printf("%c",x)
#define ps(x) printf("%s",x)
#define vi vector<int> 
#define vl vector<long> 
#define vll vector<long long>
#define vc vector<char>  
#define vs vector<string>
#define vvi vector<vector<int>> 
#define vvll vector<vector<long long>> 
#define F first
#define S second
#define ll long long
#define pb push_back
#define ppii pair<int,int> 
#define ppll pair<long long,long long>
#define ppcc pair<char,char>
#define ppss pair<string,string> 
#define vpll vector<pair<long long,long long>>
#define PI 3.1415926535897932384626
#define precision(x) cout<<fixed<<setprecision(x) 
#define mod 1000000007

int x_d[8] = {-1,1,0,0,-1,-1,1,1};
int y_d[8] = {0,0,-1,1,-1,1,-1,1};

ll power(ll b,ll e)
{
    if(b==0)
        return 0;
    
    ll r=1;
    while(e>0)
    {
        if(e%2)
            r=(r*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return r;
}

int main()
{
    jaldi;
    precision(20);
    ll i,j;

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

    map<ll,ll> mp;
    fr(i,0,n)
    {
        ll h;
        cin>>h;
        mp[i]=h;
    }
    vector<vector<ll>> adj(n);

    for(i=0;i<m;i++)
    {
        ll u,v;
        cin>>u>>v;
        u--;v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    
    ll ans=0;

    for(i=0;i<n;i++)
    {
        ll cur=mp[i],f=0;
        for(j=0;j<adj[i].size();j++)
        {
            if(cur<=mp[adj[i][j]])
                f=1;
        }
        if(f==0)
            ans++;
    }
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 15276
#include <iostream>

int main(void){
  int a,b;
  std::cin >> a >> b;
  int sum = 0;
  if(a > b){
    sum += a;
    a -= 1;
  }else{
    sum += b;
    b -= 1;
  }
    if(a > b){
    sum += a;
    a -= 1;
  }else{
    sum += b;
    b -= 1;
  }
  std::cout << sum << std::endl;

  return 0; 
}

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

typedef struct pair{
    int n;
    char c;
}Pair;

int n;
Pair a[36];
Pair b[36];
string bubble = "", selection = "";

void stableJudge(){
    int flag = 1;
    for(int i = 0; i < n; i++){
        if(a[i].c != b[i].c || a[i].n != b[i].n)
            flag = 0;   
    }
    if(flag){
        cout << "Stable";
    }else{
        cout << "Not stable";
    }
    cout << endl;
}

void bubbleSort(){
    for(int i = 0; i < n; i++){
        for(int j = n-1; j > i; j--){
            if(a[j].n < a[j-1].n){
                swap(a[j],a[j-1]);
            }
        }
    }

    for(int i = 0; i < n; i++){
        cout << a[i].c << a[i].n - '0';
        if(i != n-1) cout << " ";
    }
    cout << endl;
    cout << "Stable" << endl;
}

void selectionSort(){
    int minj;
    for(int i = 0; i < n; i++){
        minj = i;
        for(int j = i; j < n; j++){
            if(b[j].n < b[minj].n){
                minj = j;
            }
        }
        swap(b[i],b[minj]);
    }

    for(int i = 0; i < n; i++){
        cout << b[i].c << b[i].n - '0';
        if(i != n-1) cout << " ";
    }
    cout << endl;
}

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        string tmp;
        cin >> tmp;
        a[i].c = tmp[0];
        a[i].n = tmp[1];
        b[i].c = tmp[0];
        b[i].n = tmp[1];
    }
    
    bubbleSort();
    selectionSort();
    stableJudge();

    return 0;
}


Measured memory_bytes: 3140
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N;
    int A[200010], B[200010];
    cin >> N;
    for (int i=0;i<N;i++) cin >> A[i];
    for (int i=0;i<N;i++) cin >> B[i];

    set<pair<int,int>> res;
    if (N%2) {
        int x = 0;
        for (int i=0;i<N;i++) x ^= (A[i]^B[i]);
        for (int i=0;i<N;i++) {
            if ((A[i] ^ B[0]) == x) res.emplace(i,x);
        }
    } else {
        int C[200010];
        C[0] = 0;
        for (int i=0;i<N;i++) C[i+1] = (C[i] ^ A[i]);
        C[N+1] = (C[N] ^ A[0]);
        int y = 0;
        for (int i=0;i<N;i++) y ^= B[i];
        if (C[N] == y) {
            int x = (B[0] ^ B[1]);
            for (int i=0;i<N;i++) {
                if ((C[i+2]^C[i]) == x) res.emplace(i,A[i]^B[0]);
            }
        }
    }

    for (auto itr: res) {
        cout << itr.first << " " <<  itr.second << endl;
    }

    return 0;
}


Measured memory_bytes: 15104
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
  int b,a;
  cin >> b>>a;
  
  vector<string> p(b);
  rep(i,b){
    cin>> p[i];  
  } 
  
  sort(all(p));
  
  string ans ="";
  rep(i,b){
    ans+=p[i];
  }
  
  cout << ans << endl;
  
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll sum[202020];

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        sum[i+1] = sum[i] + a[i];
    }
    ll ans = 1e18;
    for (int cur=2; cur<=n-2; ++cur) {
        ll left = sum[cur]/2;
        ll right = (sum[n] - sum[cur]) / 2 + sum[cur];

        int lidx = lower_bound(sum, sum+cur+1, left) - sum;
        if (lidx > 1) {
            ll tmp1 = abs(sum[lidx] - (sum[cur]-sum[lidx]));
            ll tmp2 = abs(sum[lidx-1] - (sum[cur] - sum[lidx-1]));
            if (tmp1 > tmp2) lidx--;
        }
        ll p = sum[lidx];
        ll q = sum[cur] - sum[lidx];

        int ridx = lower_bound(sum+cur+1, sum+n, right) - sum;
        if (ridx > cur+1) {
            ll tmp1 = abs(sum[ridx] - sum[cur] - (sum[n] - sum[ridx]));
            ll tmp2 = abs(sum[ridx-1] - sum[cur] - (sum[n] - sum[ridx-1]));
            if (tmp1 > tmp2) ridx--;
        }

        ll r = sum[ridx] - sum[cur];
        ll s = sum[n] - sum[ridx];

        ans = min(ans, abs(max({p, q, r, s}) - min({p, q, r, s})));
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#ABC 088 B

N = int(input())
x = list(map(int,input().split()))
x = sorted(x, reverse=True)
a = 0
b = 0
ans = 0

if N % 2 == 0:
    for i in range(N//2):
        a += x[2*i]
        b += x[2*i + 1]
    ans = a-b
else:
    for i in range((N-1)//2):
        a +=  x[2*i]
        b +=  x[2*i + 1]
    ans = a+ x[-1] - b
    
print(ans)

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

int f(ll a, ll b) {
  ll m = max(a,b);
  int res = 0;
  while(m > 0) {
    res++;
    m /= 10;
  }
  return res;
}

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

  ll n;
  cin >> n;
  int ans = inf;
  for(ll i = 1; i*i <= n; i++) {
    if(n % i != 0) continue;
    chmin(ans, f(i,n/i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n=gets.chomp.to_i

origin = []
["S","H","C","D"].each do |m|
    1.upto 13 do |n|
        origin << m + " #{n}"
    end
end

while card = gets
    if origin.include?(card.chomp)
        origin.delete(card.chomp)
    end
end

origin.each do |c|
    puts c
end

Measured memory_bytes: 6096
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N, A;
    cin >> N >> A;
    cout << (N % 500 <= A ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int x , y ,i;
    for (i=0; 4 ; i ++){
        cin >> x >> y;
        if ((x == 0) && (y == 0)){
            break;
        }else{
            if (x <= y){
                cout << x << " " << y << endl;
            } else{
                cout << y << " " << x << endl;
            }
        }
    }

}


Measured memory_bytes: 3004
n, k = map(int, input().split())

num = list(map(int, input().split()))
t = [-1] * n
count = 0
s = 1

while t[s - 1] == -1:
  if count == k:
    break

  t[s - 1] = count
  count += 1
  s = num[s - 1]
else:
  z = (k - t[s - 1]) % (count - t[s - 1])
  s = t.index(t[s - 1] + z) + 1
print(s)


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

const ll INF = LLONG_MAX;

struct Edge {//グラフ
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to; cap = _cap; rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));//最小カット計算時逆辺は0にする
}

void Dijkstra(Graph& G, ll s, vector<ll>& d) {//O(|E|log|V|)
    d.resize(G.size());
    rep(i, d.size())d[i] = INF;
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P>> q;
    q.push(make_pair(0, s));
    while (!q.empty()) {
        P a = q.top();
        q.pop();
        if (d[a.second] < a.first)continue;
        rep(i, G[a.second].size()) {
            Edge e = G[a.second][i];
            if (d[e.to] > d[a.second] + e.cap) {
                d[e.to] = d[a.second] + e.cap;
                q.push(make_pair(d[e.to], e.to));
            }
        }
    }
}

//グラフ構築例
int main(){
  ll n;
  cin>>n;
  Graph g(n);
  rep(i,n-1){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    add_edge(g,a,b,c,true,c);
  }
  ll q,k;
  cin>>q>>k;
  k--;
  vector<ll> d(n);
  Dijkstra(g,k,d);
  rep(i,q){
    int x,y;
    cin>>x>>y;
    x--;y--;
    cout<<d[x]+d[y]<<endl;
  }
}

Measured memory_bytes: 15352
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]


killed = 0
for i in range(n):
    mn = min(B[i], A[i])
    killed += mn
    A[i] -= mn
    B[i] -= mn
    mn = min(B[i], A[i+1])
    killed += mn
    A[i+1] -= mn
    B[i] -= mn

print(killed)


Measured memory_bytes: 18624
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定
#include <list> //前後に数値を入れれる配列
#include <map> //map



#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
ll chg_DegRad(int deg) {
	return deg * PI / 180.0;
}

//radian → degree
ll chg_RadDeg(int rad) {
	return rad * 180.0 / PI;
}

//距離
double dis(double xa, double ya, double xb, double yb) {
	return pow(pow(xa - xb, 2.0) + pow(ya - yb, 2.0), 0.5);
}

//提出コード↓

double n, ans;
int x[10], y[10];




int main() {
	cin >> n;
	rep(i, n) cin >> x[i] >> y[i];
	rep(i, n) {
		REP(j, i, n) {
			ans += dis(x[i], y[i], x[j], y[j]);
		}
	}
	ans = (ans * 2.0) / n;
	cout << setprecision(10) << ans << endl;

	return 0;
}



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

int main() {
  char c;
  cin >> c;

  if (c == 'a' || 
      c == 'e' || 
      c == 'i' || 
      c == 'o' || 
      c == 'u'){
  cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }

}


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

int main()
{
  int n;
  int b, f, r, v;
  int resident[4][3][10] = { 0 };

  cin >> n;
  for (int i = 0; i < n; i++) {
     cin >> b >> f >> r >> v;
     resident[b-1][f-1][r-1] += v;
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++)
        cout << " " << resident[i][j][k];
      cout << endl;
    }
    if (i < 3) {
      for(int sh = 0; sh < 20; sh++) cout << "#";
      cout << endl;
    }
  }

  return 0;
}


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

int main() {
    long long a,b,x;
    cin>>a>>b>>x;

    if(a==0){
        cout<<b/x+1<<endl;
    }
    else {
        cout<<b/x-(a-1)/x<<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

const long long MOD = 1000000007;

int main(){
  string t;
  cin >> t;
  int n=t.size();
  rep(i,n){
    if(t.at(i)=='?') t.at(i)='D';
  }
  cout << t << endl;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define ll long long
#define ii pair <int, ll>
#define vi vector <int>
#define graph vector <vi>
#define tam 300010
using namespace std;

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

	int l, r, d;
	cin >> l >> r >> d;
	int cont = 0;
	for (int i = 1; i * d <= r; i++) {
		if (i * d >= l) cont++;
	}
	cout << cont << "\n";
	return 0;
}

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

int main() {
  char a,b,c,d;
  cin>>a>>b>>c>>d;
  int A=a- '0', B=b- '0', C=c- '0',D=d- '0';
  int T =A+B+C+D;
  char op1='+',op2='+',op3='+';
  if(T!=7){
    if(T-2*B==7) op1='-';
    else if (T-2*C==7) op2='-';
    else if(T-2*D==7) op3='-';
    else if(T-2*B-2*C==7) op1='-',op2='-';
    else if(T-2*C-2*D==7) op2='-',op3='-';
    else if(T-2*B-2*D==7) op1='-',op3='-';
    else op1='-', op2='-',op3='-';
  }
  cout<<A<<op1<<B<<op2<<C<<op3<<D<<"=7";
  
  
  
}


Measured memory_bytes: 256
def main():
    import sys
    import numpy as np

    x, y, a, b, c = map(int, input().split())
    p = list(map(int, sys.stdin.readline().split()))
    q = list(map(int, sys.stdin.readline().split()))
    r = list(map(int, sys.stdin.readline().split()))

    p = sorted(p,reverse=True)
    q = sorted(q,reverse=True)
    r = sorted(r,reverse=True)

    p = p[:x]
    q = q[:y]

    i = max(r)
    j = sum(x > i for x in p)
    k = sum(x > i for x in q)

    pd = p[j:]
    qd = q[k:]

    m = (x-j) + (y-k)

    rem = sorted(pd + qd + r,reverse=True)
    ans = sum(p[:j] + q[:k]) + sum(rem[:m])
    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 31648
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;

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

  int n;
  cin >> n;
  set<string> st;
  string a;
  rep(i,n){
    cin >> a ;
    st.insert(a);
  }
  cout << st.size() << endl;
  return 0;
  }


Measured memory_bytes: 19184
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] A = new int[N];
    int check =0, total =0;
    for (int i=0; i<N; i++) {
      A[i] = sc.nextInt();
      total += A[i];
    }
    for (int i=0; i<N; i++) {
      if (total % (4 * M) == 0) {
        if (A[i] >= total / (4 * M)) {
          check++;
        }
      } else {
        if (A[i] > total / (4 * M)) {
          check++;
        }
      }
    }
    if (check >= M) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 27232