akhauriyash/Code-Regression huggingface dataset:
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools

# from operator import attrgetter, itemgetter
# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    t = input()

    l = len(s)

    sn = [0] * l
    tn = [0] * l
    sd = dict()
    td = dict()

    cnt = 0
    for i in range(l):
        c = s[i]
        if c in sd.keys():
            sn[i] = sd[c]
        else:
            cnt += 1
            sd[c] = cnt
            sn[i] = sd[c]
    cnt = 0
    for i in range(l):
        c = t[i]
        if c in td.keys():
            tn[i] = td[c]
        else:
            cnt += 1
            td[c] = cnt
            tn[i] = td[c]

    if all([sn[i] == tn[i] for i in range(l)]):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 58684
code = r"""
# distutils: language=c++
# distutils: include_dirs=/opt/atcoder-stl
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "<atcoder/segtree>" namespace "atcoder" nogil:
    cdef cppclass segtree[S, OP, E]:
        segtree(vector[S] v)
        void set(int p, S x)
        S get(int p)
        S prod(int l, int r)
        S all_prod()
        int max_right[F](int l)
        int min_left[F](int r)
ctypedef long seg_t
cdef extern from *:
    ctypedef int op_t "myop"
    ctypedef int e_t "mye"
    ctypedef int f_t "myf"
    cdef seg_t myop(seg_t a, seg_t b) nogil
    cdef seg_t mye() nogil
    cdef bool myf(seg_t k) nogil
cdef seg_t myop(seg_t a, seg_t b) nogil:
    if a > b:
        return a
    else:
        return b
cdef seg_t mye() nogil:
    return -1000000000
cdef seg_t v
cdef bool myf(seg_t k) nogil:
    return k < v

from cython.parallel cimport prange
from libc.stdio cimport scanf, printf
cdef void main():
    cdef int n, q, i, t, u
    scanf('%d%d', &n, &q)
    cdef vector[seg_t] a = vector[seg_t](n)
    for i in prange(n, nogil=1): scanf('%ld', &a[i])
    cdef segtree[seg_t, op_t, e_t] *seg = new segtree[seg_t, op_t, e_t](a)
    for i in prange(q, nogil=1):
        scanf('%d%d%d', &t, &u, &v)
        if t == 1:
            seg.set(u - 1, v)
        elif t == 2:
            printf('%ld\n', seg.prod(u - 1, v))
        else:
            printf('%ld\n', seg.max_right[f_t](u - 1) + 1)
main()
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('solve.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b solve.pyx')
import solve

Measured memory_bytes: 16920
hn=input().split(" ")
N=int(hn[0])
K=int(hn[1])
H=input().split(" ")
H=[int(s) for s in H]
H.sort(reverse=True)
#print(H)
ans=0
for i in range(N):
    if K>0:
        K-=1
    else:
        ans+=H[i]

print(ans)


Measured memory_bytes: 26020
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n;cin>>n;
  
  set<int> s;
  rep(i,n){
    int a;cin>>a;
    s.insert(a);
  }
  
  int ans = s.size();
  ans -= !(ans&1);
  print(ans);
  return 0;
}


Measured memory_bytes: 4992
n = int(input())
s = input()
black_in_left = 0
white_in_right = s.count('.')
ans = black_in_left + white_in_right

for x in s:
    if x == '#':
        black_in_left += 1
    if x == '.':
        white_in_right -= 1
    cost = black_in_left + white_in_right
    ans = min(ans, cost)
print(ans)

Measured memory_bytes: 3500
from collections import deque
n,m = map(int,input().split())
g = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    g[a-1].append(b)
    g[b-1].append(a)
d = [0]*n
check = [False]*n
check[0] = True
def bfs():
    q = deque()
    q.append(1)
    
    while q:
        room = q.popleft()
        for nroom in g[room-1]:
            if check[nroom-1]:
                continue
            d[nroom-1] = room
            check[nroom-1] = True
            q.append(nroom)

bfs()
print('Yes')
for i in range(1,n):
    print(d[i])

Measured memory_bytes: 34868
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n = 0;
    int max;
    int min;
    cin >> n;
    
    vector<int> sun(n);
    
    cin >> sun.at(0)>>sun.at (1);

    if(sun.at(0)>=sun.at(1)){
        max = sun.at(0);
        min = sun.at(1);
    }
    else{
        max = sun.at(1);
        min = sun.at(0);
    }
        for(int i = 2; i < n; i++){
         cin >> sun.at(i);
         if(sun.at(i) <= min) min = sun.at(i);
         if(max <= sun.at(i)) max = sun.at(i);
        }
        cout << max - min <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x,long long y){
  if(y==0) return x;
  return gcd(y,x%y);
}
long long lcm(long long x, long long y){
  return x*y/gcd(x,y);
}

int main() {
  long long a,b,c,d; cin>>a>>b>>c>>d;
  long long anti_div_a,anti_div_b;
  anti_div_a=(a-1)-(a-1)/c+(a-1)-(a-1)/d-((a-1)-(a-1)/lcm(c,d));
  anti_div_b=b-b/c+b-b/d-(b-b/lcm(c,d));
  cout<<anti_div_b-anti_div_a<<endl;
}

    
  


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
lli a = 0, b = 0, c = 0, h = 0, n = 0, w = 0, ans = 0, count = 0;
string s = "", t = "";
vector<pair<lli, lli>> pr;
map<lli, lli> mp;
set<lli> st;

//---------------------------------------------------------------------------------------------------
lli solve()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  ans = 3 * (n * n);
  return ans;
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  out(solve());
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    int n; cin >> n;
    vel a(n); rep(i,n) cin >> a[i];

    sort(rall(a));
    ll ans1  = a[0];

    ll mi = INF; ll ans2;
    rep1(i,n) {
        ll temp = abs( a[i]  - ans1 / 2 );
        if(mi > temp) ans2 = a[i]; 
        mi = min(mi, temp);
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}

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

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

int main()
{
    vector<string> lst(3);
    int n;
    cin >> n;
    int cnt = 0;

    rep(i, lst.size())
    {
        cin >> lst[i];
    }

    rep(i, n)
    {
        char a = lst[0][i];
        char b = lst[1][i];
        char c = lst[2][i];

        if (a == b && b == c)
        {
        }
        else if (a == b || b == c || c == a)
        {
            cnt++;
        }
        else
        {
            cnt += 2;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
# AOJ 0180 Demolition of Bridges
# Python3 2018.6.22

# UNION-FIND library
MAX = 105
id, size = [0]*MAX, [0]*MAX

def init(n):
	for i in range(n): id[i], size[i] = i, 1
	
def root(i):
	while i != id[i]:
		id[i] = id[id[i]]
		i = id[i]
	return i
	
def connected(p, q): return root(p) == root(q)
	
def unite(p, q):
	i, j = root(p), root(q)
	if i == j: return
	if size[i] < size[j]:
		id[i] = j
		size[j] += size[i]
	else:
		id[j] = i
		size[i] += size[j]
# UNION-FIND library

# 最小全域木。V:総ノード数、E:枝情報(a,b,cost)
def kruskal(V, edge):
	ee = sorted(edge, key=lambda x:(x[2]))
	init(V)
	ans = 0
	for e in ee:
		if not connected(e[0], e[1]):
			unite(e[0], e[1])
			ans += e[2]
	return ans;

while 1:
	n, m = map(int, input().split())
	if n == 0: break
	edge = []
	for i in range(m):
		s, t, w = map(int, input().split())
		edge.append((s, t, w))
	print(kruskal(n, edge))


Measured memory_bytes: 5608
// package app;

import java.util.Arrays;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String x = sc.next();
        // final String y = sc.next();

        final int A = sc.nextInt();
        final int B = sc.nextInt();
        // final int D = sc.nextInt();
        // System.out.println();

        System.out.println((A + B) % 24);

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 25044
n,k,s=map(int,input().split())
if s==1000000000:
  b=s-1
else:b=s+1
a=[]
for i in range(k):
  a.append(s)
for i in range(n-k):
  a.append(b)
for i in a:
  print(i, end =" ")

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

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

	int n,m;
	bool a[100005];
	cin >>n>>m;
	memset(a,1,sizeof(a));
	vector <long long> t(100005);
    t[0]=1;
    for(int i =0;i<m;i++)
    {
        int num;
        cin>>num;
        a[num]=false;
    }
	for(int i = 0;i<n;++i)
	{    for(int next = i+1;next<=min(n,i+2);++next)
    {
        if(a[next])
        {
            t[next]+=t[i];
            t[next]%=1000000007;
        }
    }
		
	}
	cout <<t[n]<<endl;

	return 0;
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

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

int main() {
    int a[3];
    rep(i, 3) cin >> a[i];
    sort(a, a + 3);
    int k;
    cin >> k;
    rep(i, k) a[2] *= 2;
    cout << a[0] + a[1] + a[2] << endl;
    return 0;
}

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

int main () {
  
  	int N, A ,B;
  	cin >> N >> A >> B;
  
  	if (N == 1) {
      cout << "Hello World" << endl;
    }
  	if (N == 2) {
      cout << A + B << endl;
    }
}

  


     


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[110];
int main(){
	int a;scanf("%d",&a);
	int N=0;
	int A=0;
	int B=0;
	int AB=0;
	int ret=0;
	for(int i=0;i<a;i++){
		scanf("%s",in);
		int n=strlen(in);
		for(int j=0;j<n-1;j++){
			if(in[j]=='A'&&in[j+1]=='B')ret++;
		}
		if(in[0]=='B'&&in[n-1]=='A')AB++;
		else if(in[0]=='B')B++;
		else if(in[n-1]=='A')A++;
		else N++;
	}
	ret+=min(A,B)+AB;
	if(A+B==0&&AB)ret--;
	printf("%d\n",ret);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
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; }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };
typedef pair<double, lint> Pa;
typedef pair<plint, lint> tlint;
struct edge {
	lint cost;
	lint u, v;
};

#include<atcoder/all>
using namespace atcoder;

lint op(lint a, lint b) { return max(a, b); }
lint e() { return -1; }
lint target;
bool f(lint v) { return v < target; }
lint N, Q, A;
lint T, X, V;
int main() {
	cin >> N >> Q;
	vector<lint> arr(N);
	REP(i, N) cin >> arr[i];
	segtree < lint, op, e > tree(arr);
	REP(i, Q) {
		cin >> T;
		if (T == 1) {
			cin >> X >> V; X--;
			tree.set(X, V);
		}
		else if (T == 2) {
			cin >> X >> V; X--;
			cout << tree.prod(X, V) << endk;
		}
		else {
			cin >> X >> target; X--;
			cout << tree.max_right<f>(X) + 1 << endk;
		}
	}
}


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

int main() {

    long long int n, k;
    cin >> n >> k;

    vector< long long int > v, a;
    long long int sum = 0;

    for ( long long int i = 0; i < n; i++ ) {
        long long int in;
        cin >> in;
        v.push_back( in );
        sum += in;
    }

    for ( long long int i = 1; i * i <= sum; i++ ) {
        if ( ( sum % i ) != 0 ) continue;
        a.push_back( i );
        if ( i * i != sum ) a.push_back( sum / i );
    }
    sort( a.begin(), a.end() );

    long long int ans = 1;
    for ( long long int i = 0; i < a.size(); i++ ) {
        long long int p = a[i];
        vector< long long int > x;
        for ( long long int j = 0; j < n; j++ ) {
            x.push_back( v[j] % p );
        }
        sort( x.begin(), x.end() );
        long long int cnt = 0;
        long long int z = n - 1;
        for ( long long int j = 0; j < z; j++ ) {
            cnt += x[j];
            while( x[j] > 0 ) {
                long long int g = ( p - x[z] ) % p;
                if ( x[j] < g ) {
                    x[z] += x[j];
                    break;
                }
                x[j] -= g;
                x[z] = 0;
                z--;
            }
        }
        if ( cnt > k ) continue;
        ans = p;
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
//#define int long long int
const int lim = (int)1e5 + 2;
vi adj[lim];
vi start(lim);
vi len(lim, -1);
pii intersect(int i, int j){
   if(len[i] == -1 && len[j] == -1)return mp(0, -1);
   if(len[i] == -1)return mp(start[j], len[j]);
   if(len[j] == -1)return mp(start[i], len[i]);
   if(start[i] % 2 != start[j] % 2)return mp(0, 0);
   int s = max(start[i],start[j]);
   int e = min(start[i] + len[i]*2 - 2, start[j] + len[j]*2 -2);
   if(e < s)return mp(0, 0);
   return mp(s, (e- s)/2 + 1);
}
void calc(int i, int k){
    //need to adjust the range for the child
    if(len[i] != -1)start[i]--,len[i]++;
    pii temp = intersect(i, k);
    if(len[i] != -1)start[i]++,len[i]--;
    start[k] = temp.first;
    len[k] = temp.second;
}
bool check(int cur, int P){
    for(int child: adj[cur]){
        if(child != P){
            if(check(child, cur))return true;
            calc(child, cur);
        }
    } 
//    cout << cur << " " << start[cur] << " " << len[cur]  <<endl;
    if(len[cur] == 0)return true;
    return false;
}
void dfs(int cur, int P){
    if(P != -1){
        int pval = start[P];
        if(len[cur] == -1)start[cur] = pval + 1;
        else{
            if(start[cur] < pval)start[cur] = pval -1;
            else start[cur] = pval+1;
        }
        len[cur] = 1;
    }
    for(int child: adj[cur]){
        if(child != P){
            dfs(child, cur);
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    int n;cin >> n;
    int x, y;
    FOR(i, n -1){
        cin >>x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int k;cin >> k;
    FOR(i, k){
        cin >>x >> y;
        start[x] = y;
        len[x] = 1;
    }
    if(check(1, -1))cout << "No";
    else{
        cout << "Yes" << "\n";
        //assuming start[1] = 0 if not set otherwise the set value will be used
        len[1] = 1;
        dfs(1, -1);
        FOR1(i, n){
            cout << start[i] << "\n";
        }
    }
}




Measured memory_bytes: 13440
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#define ll long long
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 3e5 + 1000,inf = 2e9;
int n,idcnt,st,en;
int id[2][N],dep[N];
int p[N],q[N];
int tot = 1,head[N],cur[N];
struct node{int nex,to,flow;} e[N << 4];
void add(int f,int t,int flow)
{
	e[++ tot].nex = head[f]; e[tot].to = t; e[tot].flow = flow; head[f] = tot;
	e[++ tot].nex = head[t]; e[tot].to = f; e[tot].flow = 0; head[t] = tot;
}
queue<int> qq;
int bfs()
{
	while(!qq.empty()) qq.pop();
	for(int i = 1;i <= en;i ++) cur[i] = head[i],dep[i] = 0; 
	dep[st] = 1; qq.push(st);
	while(!qq.empty())
	{
		int f = qq.front(); qq.pop();
		for(int i = head[f],to;i;i = e[i].nex)
		{
			to = e[i].to; if(dep[to] || !e[i].flow) continue;
			dep[to] = dep[f] + 1; qq.push(to);
			if(to == en) return 1;
		}
	}
	return 0;
}
int dinic(int now,int flow)
{
	if(now == en || !flow) return flow;
	int res = flow,k;
	for(int &i = cur[now],to;i && res;i = e[i].nex)
	{
		to = e[i].to; 
		if(dep[to] == dep[now] + 1 && e[i].flow)
		{
			k = dinic(to,min(res,e[i].flow));
			if(!k) {dep[to] = 0; continue;}
			e[i].flow -= k; e[i ^ 1].flow += k; res -= k;
		}
	}
	return flow - res;
}
void work(int now,int *nex,int *id){if(id[now]) return; id[now] = idcnt; work(nex[now],nex,id);}
int main()
{
	n = read(); int ans = n;
	for(int i = 1;i <= n;i ++) p[i] = read() + 1;
	for(int i = 1;i <= n;i ++) q[i] = read() + 1;
	for(int i = 1;i <= n;i ++) if(!id[0][i]) idcnt ++,work(i,p,id[0]);
	for(int i = 1;i <= n;i ++) if(!id[1][i]) idcnt ++,work(i,q,id[1]);
	st = ++ idcnt; en = ++ idcnt;
	for(int i = 1;i <= n;i ++)
	{
		if(p[i] == i && q[i] == i) ans --;
		else if(p[i] == i) add(id[1][i],en,1);
		else if(q[i] == i) add(st,id[0][i],1);
		else if(q[i] != p[i]) add(id[1][i],id[0][i],1);
		else add(id[1][i],id[0][i],1),add(id[0][i],id[1][i],1);
	}
	int flow = 0; while(bfs()) while(flow = dinic(st,inf)) ans -= flow;
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 16000
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    A = [II() for _ in range(n)]
    A2 = sorted(A, reverse=True)
    mx = A2[0]
    mx2 = A2[1]

    for a in A:
        if a == mx:
            print(mx2)
        else:
            print(mx)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 14112
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int a, b, t;
	cin >> a >> b >> t;
	cout << b * (t / a);
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  string s="No";
  if(a==b && b!=c){
    s="Yes";
  }
   if(b==c && a!=c){
    s="Yes";
  }
   if(a==c && b!=c){
    s="Yes";
  }
  cout << s << endl;
  
}

Measured memory_bytes: 256
from collections import Counter


def main():
    N = int(input())
    points = [tuple(map(int, input().split())) for _ in range(N)]
    counter = Counter()

    if N == 1:
        print(1)
        return

    for i in range(N):
        for j in range(N):
            if j == i:
                continue
            a = points[i]
            b = points[j]
            dx = b[0] - a[0]
            dy = b[1] - a[1]
            counter[(dx, dy)] += 1

    vec, _ = counter.most_common()[0]
    dx, dy = vec
    visited = set()
    pointset = set(points)
    cost = 0

    for p in points:
        if p in visited:
            continue
        visited.add(p)
        x, y = p
        cost += 1

        i = 1
        while True:
            n = (x + i * dx, y + i * dy)
            i += 1
            if n in pointset:
                visited.add(n)
            else:
                break
        i = 1
        while True:
            n = (x - i * dx, y - i * dy)
            i += 1
            if n in pointset:
                visited.add(n)
            else:
                break

    print(cost)


main()


Measured memory_bytes: 3956
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N = int(input())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

P, Q, R = map(int, input().split())

heap = []
heappush(heap, P * (-1))
heappush(heap, Q * (-1))
heappush(heap, R * (-1))

heappop(heap)

heap = list(map(lambda x: x * -1, heap))
print(sum(heap))






# def main():

# if __name__ == '__main__':
#     main()


Measured memory_bytes: 3568
#include<iostream>

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    int h[n+1]={0};
    int a[m]={0};
    int b[m]={0};
    int ans[n+1]={0};
    
    for(int i=1;i<n+1;i++)
        cin>>h[i];
     
    for(int j=0;j<m;j++){
        cin>>a[j]>>b[j];
        if( h[a[j]] > h[b[j]] ){
            ans[b[j]]--;
        }else if( h[a[j]] < h[b[j]] ){
            ans[a[j]]--;
        }else{
            ans[a[j]]--;
            ans[b[j]]--;
        }
    }
    
    int c=0;
    for(int i=1;i<=n;i++){
        if(ans[i]==0)
            c++;
    }
    
    cout<<c<<endl;
}

Measured memory_bytes: 5168
# -*- coding: utf-8 -*-
n, l = map(int, input().split())

apples = [l + i for i in range(n)]

min_apple_abs = 10000
min_apple = 10000
for a in apples:
    if abs(a) < min_apple_abs:
        min_apple_abs = abs(a)
        min_apple = a

pie = sum(apples)
_pie = pie - min_apple

print(_pie)


Measured memory_bytes: 2940
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;



int main() {
	int N;
	cin >> N;
	vector<long long>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	long long ans = LLONG_MAX;
	for (int i = v[0]; i <= v[N - 1]; i++) {
		long long check = 0;
		for (int j = 0; j < N; j++) {
			check += (v[j] - i) * (v[j] - i);
		}
		chmin(ans, check);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>

using namespace std;
main(){
  int i,num=0;
  string number;
  while(1){
  cin >> number;
  if(number=="0")break;
  
  
  for(i=0;i<number.size();i++){

    num+=number[i] -'0';
   
  }
  cout << num<<endl;
  num=0;
    }
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  vector<ll> a(5);
  for (int i = 0; i < 5; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  
  cout << (n + a[0] - 1)/a[0] + 4 << endl;
      


  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

constexpr int MOD = 1e9 + 7;

map<int, int> pri(int n) {
  map<int, int> res;
  int tmp = n;
  for (int i=2; i*i<=n; ++i) {
    while (tmp%i == 0) {
      tmp /= i;
      res[i]++;
    }
  }
  if (tmp != 1) res[tmp]++;
  return res;
}

long long inv(long long n) {
  long long res = 1;
  while (n > 1) {
    res *= (MOD - MOD / n);
    res %= MOD;
    n = MOD % n;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i=0; i<n; ++i) cin >> a.at(i);
  
  vector<int> cnt(1e6+1);
  for (int i=0; i<n; ++i) {
    for (auto p : pri(a.at(i))) {
      cnt.at(p.first) = max(cnt.at(p.first), p.second);
    }
  }
  
  long long g = 1;
  for (int i=2; i<1e6+1; ++i) {
    for (int j=0; j<cnt.at(i); ++j) {
      g *= i;
      g %= MOD;
    }
  }
  
  long long res = 0;
  for (int i=0; i<n; ++i) {
    res += (g * inv(a.at(i))) % MOD;
   	res %= MOD;
  }
  cout << res << endl;
  return 0;
}
 

Measured memory_bytes: 4224
n = gets.to_i
arr = Array.new(n + 1) { 0 }

1.upto(100) do |x|
  x.upto(100) do |y|
    y.upto(100) do |z|
      f = x**2 + y**2 + z**2 + x * y + y * z + z * x
      next if f > n

      if x == y && y == z
        arr[f] += 1
      else
        arr[f] += (x != y && y != z) ? 6 : 3
      end
    end
  end
end

puts arr.drop(1)

Measured memory_bytes: 14288
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}

signed main(){
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(a*n,b)<<endl;
	return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  int numB = 0;
  int numW = 0;
  vector<string> s(H);
  vector<vector<int>> d(H);
  vector<vector<bool>> reached(H);
  for (int i = 0; i < H; ++i) {
    cin >> s.at(i);
    for (int j = 0; j < W; ++j) {
      d.at(i).push_back(0);
      reached.at(i).push_back(false);
      if (s.at(i).at(j) == '#')
        ++numB;
      else
        ++numW;
    }
  }


  queue<tuple<int,int,int>> q;
  q.emplace(0, 0, 0);
  reached.at(0).at(0) = true;

  while(!q.empty()) {
    int idx_x = get<0>(q.front());
    int idx_y = get<1>(q.front());
    int dist = get<2>(q.front());
    for (auto idx : vector<pair<int,int>> {{idx_x+1,idx_y}, {idx_x,idx_y+1}, {idx_x-1, idx_y}, {idx_x, idx_y-1}}) {
      if (idx.first < 0 || idx.first >= W || idx.second < 0 || idx.second >= H)
        continue;
      if (reached.at(idx.second).at(idx.first) || s.at(idx.second).at(idx.first) == '#')
        continue;
      reached.at(idx.second).at(idx.first) = true;
      d.at(idx.second).at(idx.first) = dist+1;
      q.emplace(idx.first, idx.second, dist+1);
    }
    q.pop();
  }

  if (reached.at(H-1).at(W-1))
    cout << numW - d.at(H-1).at(W-1) - 1 << endl;
  else
    cout << -1 << endl;
  
  return 0;
}


Measured memory_bytes: 256
let () =
  let s =
    let s' = read_line () in
    String.concat  "" [s';s']
  in
  let t = read_line () in
  let s_len, t_len = String.length s, String.length t in
  let rec crawl s_i t_i =
    if t_i < t_len then
      begin
        if s_i < s_len then
          begin
            if s.[s_i] = t.[t_i] then crawl (s_i+1) (t_i+1)
            else crawl (s_i - t_i + 1) 0
          end
        else "No"
      end
    else "Yes"
  in
  print_string @@ crawl 0 0;
  print_string "\n";
;;


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

int main(){
	while(1){
		int a, b, c;
		char op;
		cin >> a >> op >> b;
		if(op == '?') break;
		if(op == '+') c = a + b;
		if(op == '-') c = a - b;
		if(op == '*') c = a * b;
		if(op == '/') c = a / b;
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int ans[55];
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    while(m--) {
        int a, b;
        cin >> a >> b;
        ans[a]++;
        ans[b]++;
    }
    for(int i = 1; i <= n; i++) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/perl
#B - AtCoder Beginner Contest 111

use strict;
use warnings;

# データ取得
our ($data);


    {
        $data = <STDIN>;
        chomp($data);
    }

    {
        my ($lsb) = 111;
        if ($data % $lsb) {
            $data = int(int(($data / $lsb) + 1) * $lsb);
        }
    }

print("$data\n");

exit(0);


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1e15

int n, m;

struct edge{
    int to;
    double cost;
    int limit;
    edge(int t, double c, int l): to(t), cost(c), limit(l){}
};

struct state{
    int node, speed, prev;
    double dist;
    state(int n, int s, int p, double d): node(n), speed(s), prev(p), dist(d) {}
    bool operator > (const state s) const {
        return dist > s.dist;
    }
};
 
void dijkstra(int start, vector<vector<vector<double> > > &d, vector<vector<edge> > graph){
    d[start][0][start] = 0.0;
    bool visit[31][31][31] = {};
    priority_queue<state, vector<state>, greater<state> > q;
    q.push(state(start, 0, start, 0.0));
    while (!q.empty()){
        state a = q.top();
        q.pop();
        int now = a.node, prev = a.prev, speed = a.speed;
        if (visit[now][speed][prev]) continue;
        visit[now][speed][prev] = 1;
        // printf("%d %d %d\n", now, prev, speed);
        if(d[now][speed][prev] < a.dist) continue;
        REP(i,graph[now].size()){
            edge e = graph[now][i];
            int next = e.to, limit = e.limit;
            if (next == prev) continue;
            FOR(dif,-1,1){
                int next_speed = speed + dif;
                if (next_speed <= 0 || next_speed > limit) continue;
                if (d[next][next_speed][now] > d[now][speed][prev] + e.cost/next_speed){
                    d[next][next_speed][now] = d[now][speed][prev] + e.cost/next_speed;
                    q.push(state(next, next_speed, now, d[next][next_speed][now]));
                }
            }
        }
    }
}

int main() {
    while (cin >> n >> m && n){
        vector<vector<edge> > graph(n);
        int s, g;
        cin >> s >> g;
        s--;
        g--;
        REP(i,m){
            int x, y, c;
            double d;
            cin >> x >> y >> d >> c;
            x--;
            y--;
            graph[x].push_back(edge(y,d,c));
            graph[y].push_back(edge(x,d,c));
        }
        vector<vector<vector<double> > > dist(n, vector<vector<double> > (31, vector<double> (n, INF)));
        dijkstra(s, dist, graph);
        double ans = INF;
        REP(i,n) ans = min(ans, dist[g][1][i]);
        if (ans == INF) cout << "unreachable" << endl;
        else printf("%.10f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3936
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();

        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int agcd = a[0];
        for (int i = 0; i < a.Length; i++)
        {
            agcd = gcd(agcd, a[i]);
        }
        int modk = nk[1] % agcd;
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] % agcd == modk && nk[1] <= a[i])
            {
                Console.WriteLine("POSSIBLE");
                return;
            }
        }
        Console.WriteLine("IMPOSSIBLE");
    }
    public static int gcd(int a, int b)
    {
        if (a < b) return gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
}

Measured memory_bytes: 20576
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <unordered_map>

#define mod 1000000007

using namespace std;
using ll = long long;

void solve(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a+b > c+d){
        cout << "Left" << endl;
    }else if(a+b < c+d){
        cout << "Right" << endl;
    }else{
        cout << "Balanced" << endl;
    }
}

int main(){
    solve();
    return 0;
}

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

using namespace std;

const int MAX_N = 3e3 + 5;

int n, m;

int dp[MAX_N][MAX_N];

char s[MAX_N], t[MAX_N], ans[MAX_N];

int main() {
  // dp[i][j] = maximum lcs using first i chars from s and first j chars from t
  // if s[i] == t[j], then there is a match, so, dp[i][j] = 1 + dp[i - 1][j - 1] (we take the two chars)
  // Else, there is no match, so we take the best option from dp[i - 1][j], dp[i][j - 1];
  int l;
  cin >> (s + 1) >> (t + 1);
  n = strlen(s + 1);
  m = strlen(t + 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (s[i] == t[j]) {
        dp[i][j] = 1 + dp[i - 1][j - 1];
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }
  l = 0;
  while (n > 0 && m > 0) {
    if (dp[n][m] == dp[n - 1][m]) {
      --n;
    } else if (dp[n][m] == dp[n][m - 1]) {
      --m;
    } else {
      --n;
      --m;
      ans[l++] = s[1 + n];
    }
  }
  reverse(ans, ans + l);
  cout << ans;
  return 0;
}


Measured memory_bytes: 35456
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer N = sc.nextInt();
        int d[] = new int[N+1];
        for(int i=1; i<=N; i++) {
            d[i] = sc.nextInt();
        }
        Arrays.sort(d);
        System.out.println(d[N/2 + 1] - d[N/2]);
    }
}

Measured memory_bytes: 51096
import java.util.Scanner;
public class Main {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int k = in.nextInt();
		int t = in.nextInt();
		int[] a = new int[t];
		
		int  max = 0;
		int sum = 0;
		for(int i =0;i<t;i++){
			a[i] = in.nextInt();
			sum+=a[i];
			if(a[i]>max) max = a[i];
		}
		if(max<=sum-max+1){
			System.out.println(0);
			return;
		}
		else{
			System.out.println(2*max-sum-1);
			return;
		}
	}

}


Measured memory_bytes: 9300
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

int main() {
	string s;
	cin >> s;
	cout << ((s == "ABC") ? "ARC" : "ABC") << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define mod 1000000007
template<class T> void add(T &a, T b) {a = (a + b) % mod;}

int dp[101][4][4][4];
int main() {
  int N; cin >> N;
  int A = 0, C = 1, G = 2, T = 3;
  dp[0][T][T][T] = 1;
  rep(i, 0, N) rep(j, 0, 4) rep(k, 0, 4) rep(l, 0, 4) rep(m, 0, 4) {
    if(dp[i][j][k][l] == 0) continue;
    if(k == A && l == G && m == C) continue;
    if(k == A && l == C && m == G) continue;
    if(k == G && l == A && m == C) continue;
    if(j == A && k == G && m == C) continue;
    if(j == A && l == G && m == C) continue;
    add(dp[i + 1][k][l][m], dp[i][j][k][l]);
  }
  int ans = 0;
  rep(i, 0, 4) rep(j, 0, 4) rep(k, 0, 4) {
    add(ans, dp[N][i][j][k]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256