akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 2005
#define INF 2000000000
using namespace std;
using P = pair<int,int>;
int n,cnt[M],dp[M],dsum[M];
char s[M];
vector<int> e[M];
void check(int cur,int fa) {
    vector<P> tmp;
    cnt[cur] = s[cur]=='1' ? 1:0;
    dsum[cur] = 0;

    for (int i:e[cur]) if(i!=fa) {
        check(i, cur);
        cnt[cur] += cnt[i];
        dsum[cur] += dsum[i]+cnt[i];
        if (cnt[i]) tmp.push_back( make_pair(dsum[i]+cnt[i], dp[i]+cnt[i]) );
    }

    sort(tmp.begin(), tmp.end(), greater<P> ());

    if (tmp.size()) {
        int s1 = tmp[0].second;
        int s2 = 0;
        REP(i,1,(int)tmp.size()-1) s2 += tmp[i].first;

        if (s1<=s2) dp[cur] = dsum[cur]%2;
        else dp[cur] = s1 - s2;
    } else {
        dp[cur] = 0;
    }
}
int main()
{
    while (~scanf("%d", &n)) {
        REP(i,0,n) e[i].clear();
        scanf("%s", s+1);
        REP(i,1,n-1) {
            int x,y;
            scanf("%d %d",&x,&y);
            e[x].push_back(y);
            e[y].push_back(x);
        }

        int ans = INF;
        REP(root, 1, n) {
            check(root, -1);
            if (dp[root] == 0) {
                ans = min(ans, dsum[root]/2);
            }
        }
        printf("%d\n", ans==INF ? -1 : ans);
    }
    return 0;
}


Measured memory_bytes: 640
import heapq
N, M = map(int, input().split())
A = [-int(i) for i in input().split()]
heapq.heapify(A)
for i in range(M):
    a = -heapq.heappop(A) // 2
    heapq.heappush(A, -a)
print(-sum(A))

Measured memory_bytes: 14180
n = int(input())
AL = [0] + list(map(int, input().split()))
ball_plus_list = [0]*(n+1)
for i in range(n, 0, -1):
    sum_ball = 0
    for j in range(2, n//i + 1):
        sum_ball += ball_plus_list[i*j]
    if sum_ball%2 != AL[i]:
        ball_plus_list[i] = 1

ans = []
for i, ball_exist in enumerate(ball_plus_list):
    if ball_exist == 1:
        ans.append(str(i))
print(len(ans))
print(" ".join(ans))

Measured memory_bytes: 73692
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


vector<int> G[5];

int main(){
  rep(i,3){
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  rep(i,5){
    if(G[i].size() >= 3){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	string S;
	cin >> S;
	N = S.length();
	ll left = 0;
	ll right = N - 1;
	while (left < right) {
		if (S[left] == S[right]) {
			left++;
			right--;
		}
		else if (S[left] == 'x') {
			ans++;
			left++;
		}
		else if (S[right] == 'x') {
			ans++;
			right--;
		}
		else {
			cout << -1;
			exit(0);
		}
	}
	cout << ans;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;
void cout_vec(vector<long long> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}
void cout_mat(vector<vector<long long>> &mat){
    for(int i=0; i<mat.size(); i++){
        vector<long long> vec = mat[i];
        cout_vec(mat[i]);
    }
}

int main(){
    int N;
    cin >> N;
    vector<long long> vec(N,0);
    for(int i=0; i<N; i++){
        cin >> vec[i];
    }

    sort(vec.begin(), vec.end());

    vector<vector<long long>> dp(N+1, vector<long long>(1000*2+2,0));
    for(int j=0; j<N; j++){
        for(int k=j+1; k<N; k++){
            dp[k][vec[j]+vec[k]]++;
        }
    }
    for(int i=0; i<N-1; i++){
        for(int j=1000*2+1; j>0; j--){
            dp[i][j-1]+=dp[i][j];
        }
    }
    for(int i=0; i<1000*2+2; i++){
        for(int j=0; j<N-1; j++){
            dp[j+1][i]+=dp[j][i];
        }
    }

    long long ans=0;
    for(int i=1; i<N; i++){
        ans+=dp[i-1][vec[i]+1];
    }

    //cout_mat(dp);

    cout << ans << endl;
}

Measured memory_bytes: 31616
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 998244353
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=1e6+3;
PII arr[N];int dp[N];
int mod(ll x){x%=INF;
	if(x<0)
		x+=INF;
	return x;	
}
int Fe(int x,int y){
	if(!y)
		return 1;
	int h=Fe(x,y/2);
	h=mod(h*1LL*h);
	if(y&1)	
		h=mod(h*1LL*x);
	return h;			
}
int main(){
  //  freopen("file.in", "r", stdin);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    	int x;
		scanf("%d",&x);
		arr[x].ff=mod(arr[x].ff+x);
		arr[x].ss=mod(arr[x].ss+x*1LL*x);	
    }
    int ans=0;
    for(int i=N-3;i>=1;i--){
    	int a=0,b=0;
    	for(int j=i;j<N;j+=i){
    		a=mod(a+arr[j].ff);
    		b=mod(b+arr[j].ss);
    		dp[i]=mod(dp[i]-dp[j]);
    	}
    	dp[i]=mod(dp[i]+mod(a*1LL*a-b));
    	if(dp[i])
    		ans=mod(ans+mod(dp[i]*1LL*Fe(i,INF-2)));
    }
    printf("%d\n",mod(ans*1LL*Fe(2,INF-2)));
	return 0;
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    for(int i=0; i<n; i++) cin>>p[i];
    int cnt=0;
    for(int i=0; i<n; i++){
        if(p[i]==i+1){
            cnt++;
            int tmp=p[i];
            p[i]=p[i+1];
            p[i+1]=tmp;
        }
    }
    cout<<cnt<<endl;
}

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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (auto &v : a) cin >> v;
    int sum = accumulate(a.begin(), a.end(), 0);
    sort(a.rbegin(), a.rend());
    for (int i = 0; i < m; ++i)
    if (a[i] * 4 * m < sum) {
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
}

Measured memory_bytes: 256
import Control.Monad
import Data.List

main = do
    [n,l] <- map read . words <$> getLine :: IO [Int]
    print $  sum [l..(n+l-1)] - snd ((sort $ zip (map abs $[l..(n+l-1)]) [l..(n+l-1)]) !! 0)


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

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return num%5==1;
}

void solve() 
{
    int n;cin>>n;
    rep(i,10,55555){
        if(n==0)break;
        if(IsPrime(i)){
            cout<<i<<" ";
            n--;
        }
    }cout<<endl;
}

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

Measured memory_bytes: 256
# AOJ 1111: Cyber Guardian
# Python3 2018.7.15 bal4u

import re
while True:
	n, m = map(int, input().split())
	if (n|m) == 0: break
	rule, ans = [], []
	for i in range(n):
		g, s, d = input().split()
		rule.append((g[0] == 'p', re.compile((s+d).replace("?", "[0-9]"))))
	for i in range(m):
		s, d, m = input().split()
		sd = s+d
		for G, SD in rule[::-1]:
			if re.match(SD, sd):
				if G: ans.append((s, d, m))
				break
	print(len(ans))
	for a in ans: print(*a)



Measured memory_bytes: 7704
#include<iostream>

using namespace std;

int main(void){
  int N;
  cin >> N;
  int P[N];
  for(int i=0; i<N; i++) cin >> P[i];

  
  int ans=0;
  int flag;
  // N Max 2*10^5
  // order max (1 + 2*10^5) * N / 2
  // N(N+1) / 2
  // 1が出た時点で終了


  
  int max=0;
  int min=P[0];
  for(int i=0; i<N; i++){ // condition i

	if(P[i] <= min){
	  ans++;
	  min = P[i];
	}		



				   

	//if(P[i] == 1) break;
	


	
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();
		int r = sc.nextInt(), s = sc.nextInt(), p = sc.nextInt();
		char[] a = sc.next().toCharArray();
		long ans = 0l;
		for(int i = k; i < n; i++) {
			if(a[i] == a[i-k]) {
				a[i] = 'n';
			}
		}
		
		for(char c : a) {
			if(c == 'r') {
				ans += p;
			}else if(c == 's') {
				ans += r;
			}else if(c == 'p') {
				ans += s;
			}
		}
		
		System.out.println(ans);
		
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 35284
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <iomanip>
#include <limits>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int asc(const void* a, const void* b) {
	return *(int*)a- *(int*)b;
}

int main()
{
	int k, s;
	int ans = 0;
	cin >> k >> s;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			if (s - i - j >= 0 && s - i - j <= k) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int v[300300], w[300300];
ll dp[513][100010];
int need;
void dfs(int now)
{
    if(now > need) return;
    int i,j;
    int prev = now / 2;
    for(i=100000;i>0;i--) {
        dp[now][i] = max(dp[now][i], dp[prev][i]);
        if(i - w[now] < 0) continue;
        dp[now][i] = max(dp[now][i], dp[prev][i - w[now]] + v[now]);
    }
    dfs(now*2);
    dfs(now*2+1);
}
int main()
{
    int n,i,j,k,x,y,ans,curr,m;
    int tc;
    scanf("%d",&n);
    need = min(n, 512);
    for(i=1;i<=n;i++) {
        scanf("%d %d",&v[i],&w[i]);
    }
    dfs(1);
    int q;
    scanf("%d",&q);
    while(q--) {
        scanf("%d %d",&x,&y);
        if(x <= need) {
            printf("%lld\n", dp[x][y]);
        }
        else {
            vector<int> vi;
            while(x > need) {
                vi.push_back(x);
                x /= 2;
            }
            int sz = vi.size();
            ll chaeng = 0;
            for(i = 0; i < (1<<sz); i++) {
                int cost = 0, gain = 0;
                for(j = 0; j < sz; j++) {
                    if(i & (1 << j)) {
                        gain += v[vi[j]];
                        cost += w[vi[j]];
                    }
                }
                if(cost <= y) {
                    chaeng = max(chaeng, dp[x][y - cost] + gain);
                }
            }
            printf("%lld\n", chaeng);
        }
    }
    return 0;
}


Measured memory_bytes: 405884
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <functional>
#include <set>

using namespace std;

string s;
string t;

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

	bool f = false;
	string ans = "";
	for (int i = 0; i < s.length(); ++i) {
		bool g = true;
		for (int j = 0; j < t.length(); ++j) {
			if (i + j >= s.length()) {
				g = false;
			}
			g = g && (s[i + j] == '?' || s[i + j] == t[j]);
		}
		if (g) {
			string c = s;
			for (int j = 0; j < s.length(); ++j) {
				if (c[j] == '?')
					c[j] = 'a';
			}
			for (int j = 0; j < t.length(); ++j) {
				c[i + j] = t[j];
			}
			if (ans == "" || ans > c) {
				ans = c;
			}
		}
	}
	if (ans == "")
	{
		cout << "UNRESTORABLE" << endl;
	}
	else {
		cout << ans << endl;
	}
}

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

const int INF = 1e9;

const int MAXN = 15;
int N;
int W[MAXN][MAXN];

int V[1<<MAXN];
int dp[1<<MAXN][MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int M;
	cin >> N >> M;
	int tot = 0;
	for (int i = 0; i < M; i++) {
		int a, b, c; cin >> a >> b >> c; a--, b--;
		W[a][b] = W[b][a] = c;
		tot += c;
	}

	for (int m = 0; m < (1<<N); m++) {
		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {
				if ((m & (1 << i)) && (m & (1 << j))) {
					V[m] += W[i][j];
				}
			}
		}
	}

	for (int m = 1; m < (1 << N); m += 2) {
		dp[m][0] = V[m];
		for (int i = 1; i < N; i++) {
			dp[m][i] = -INF;
		}
		for (int v = (m-2) & m; true; v = (v-2) & m) {
			assert(v & 1);
			assert((m&v) == v);
			for (int i = 1; i < N; i++) {
				if (!((m^v) & (1 << i))) continue;
				for (int j = 0; j < N; j++) {
					if (!(v & (1 << j))) continue;
					if (W[i][j] == 0) continue;
					dp[m][i] = max(dp[m][i], dp[v][j] + V[m^v] + W[i][j]);
				}
			}
			if (v == 1) break;
		}
	}
	cout << tot - dp[(1<<N)-1][N-1] << '\n';

	return 0;
}


Measured memory_bytes: 2304
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,w=MI()
WV=[LI() for i in range(n)]
dp=[[inf]*(10**5+1) for i in range(n+1)]
dp[0][0]=0
for i in range(n):
    for j in range(10**5+1):
        if j-WV[i][1]>=0:
            dp[i+1][j]=min(dp[i+1][j],dp[i][j],dp[i][j-WV[i][1]]+WV[i][0])
        else:
            dp[i+1][j]=min(dp[i+1][j],dp[i][j])
for i in range(10**5+1):
    j=10**5-i
    if dp[-1][j]<=w:
        print(j)
        sys.exit()




            

    
    



Measured memory_bytes: 152916
from collections import defaultdict
N = int(input())
d = defaultdict(list)
A = list(map(int, input().split()))
li = []
for i in range(N):
    a = A[i]
    li.append(i+a)
    d[i-a].append(i)
ans = 0
for x in li:
    ans += len(d[x])
print(ans)

Measured memory_bytes: 147180
from itertools import accumulate
from bisect import *
n, m, *a = map(int, open(0).read().split())
a = [-x for x in a]
a.sort()
acc = list(accumulate(a)) + [0]
l = 0
r = 2 * 10 ** 5 + 1
while r - l > 1:
	mid = (l + r) // 2
	border = n - 1
	cnt = 0
	for x in a:
		while x + a[border] > -mid:
			border -= 1
			if border < 0:
				break
		if border < 0:
			break
		cnt += border + 1
		if cnt >= m:
			break
	if cnt >= m:
		l = mid
	else:
		r = mid
ans = tot = 0
for x in a:
	b = bisect(a, -l - x)
	tot += b
	ans += acc[b - 1] + x * b
ans += l * (tot - m)
print(-ans)


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

int main(void) {
  string S;
  cin >> S;
  set<char> s;
  for (int i = 0, len = S.length(); i < len; i++) {
    s.insert(S[i]);
  }
  cout << (s.size() == S.size() ? "yes" : "no") << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    if (A <= 8 && B <= 8) {
      System.out.println("Yay!");
    } else {
      System.out.println(":(");
    }
  }
}

Measured memory_bytes: 21972
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
a = list(map(int, input().split()))
if N == 1:
  print(0)
  exit(0)
if M == 0 and (N > 2):
  print("Impossible")
  exit(0)
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1] * (n + 1)
    self.rnk = [0] * (n + 1)

  def Find_Root(self, x):
    if self.root[x] < 0:
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if x == y:
      return 
    elif self.rnk[x] > self.rnk[y]:
      self.root[x] += self.root[y]
      self.root[y] = x
    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      if self.rnk[x] == self.rnk[y]:
        self.rnk[y] += 1

  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  def Count(self, x):
    return -self.root[self.Find_Root(x)]
uf = UnionFind(N)
d = [[] for _ in range(N)]
for _ in range(M):
  u, v = map(int, input().split())
  uf.Unite(u, v)
for i in range(N):
  d[uf.Find_Root(i)].append(a[i])
res = 0
x = []
y = 0
for i in range(N):
  d[i].sort(reverse = True)
  if len(d[i]):
    res += d[i].pop()
    y += 1
  x += d[i]
if y == 1:
  print(0)
  exit(0)
x.sort()
for i in range((y - 1) * 2 - y):
  if i >= len(x):
    print("Impossible")
    exit(0)
  res += x[i]
print(res)

Measured memory_bytes: 89016
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt()

	whole, not := 1, 1
	for i := 0; i < n; i++ {
		a := nextInt()

		whole *= 3

		if a%2 == 0 {
			not *= 2
		}
	}

	fmt.Println(whole - not)
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int A = scan.nextInt();
	int B = scan.nextInt();
	int C = scan.nextInt();
	int D = scan.nextInt();
	int E = scan.nextInt();
	int F = scan.nextInt();

	double max = -1;
	int max_water = 0;
	int max_suger = 0;
	for(int i = 0; 100*A*i <= F; i++){
	    for(int j = 0; 100*A*i+100*B*j <= F; j++){
		for(int k = 0; 100*A*i+100*B*j+C*k <= F; k++){
		    for(int l = 0; 100*A*i+100*B*j+C*k+D*l <= F; l++){
			if((A*i+B*j)*E < C*k+D*l){
			    //砂糖多すぎ
			}else{
			    double tmp = (double)100*(C*k+D*l)/(100*A*i+100*B*j+C*k+D*l);
			    if(tmp > max){
				max = tmp;
				max_water = 100*A*i+100*B*j+C*k+D*l;
				max_suger = C*k+D*l;
			    }
			}
		    }
		}
	    }
	}

	System.out.println(max_water+" "+max_suger);
    }
}


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;
const int K = 500;
const int maxN = 50;

void solve() {
	int n, d, m;
	cin >> n >> d >> m;
	vector<pair<int, int>> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
		b[i] = a[i].first;
	}

	sort(all(b));
	b.erase(unique(all(b)), b.end());
	for (auto& p : a) p.first = (int)(lower_bound(all(b), p.first) - b.begin());

	int cnt = b.size();
	vector<int> c(cnt);
	for (int i = 0; i < n; i++) c[a[i].first] = max(c[a[i].first], a[i].second);
	
	int now = 0;
	int ans = 0;
	vector<int> t(cnt + 1);
	for (int i = 0; i < cnt; i++) {
		now += t[i];
		if (now < c[i]) {
			int x = (c[i] - now) / m + ((c[i] - now) % m ? 1 : 0);
			ans += x;
			now += x * m;
			int id = (int)(upper_bound(all(b), b[i] + d * 2) - b.begin());
			t[id] -= x * m;
		}
	}
	cout << ans;
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

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

int h1, m1;
int h2, m2;
int k;

int main()
{
    cin >> h1 >> m1;
    cin >> h2 >> m2;
    cin >> k;
    int res = h2 * 60 + m2 - (h1 * 60 + m1) - k;
    cout << res << endl;
    return 0;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

bool flag[200005];

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N;
  scanf("%lld", &N);

  set<ll> ms;
  vector<ll> list;
  vector<ll> duplicated;

  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);

    bool has = (ms.find(v) != ms.end());
    if (!has) {
      list.emplace_back(v);
      ms.insert(v);
    } else {
      duplicated.emplace_back(v);
    }
  }

  sort(list.begin(), list.end());
  ll max = list[list.size() - 1];

  for (ll i = 0; i < list.size(); i++) {
    ll v = list[i];
    bool has = (ms.find(v) != ms.end());
    if (!has) {
      continue;
    }
    ll current = v;
    for (;;) {
      current += v;
      ms.erase(current);
      if (current > max) {
        break;
      }
    }
  }

  for (ll i = 0; i < duplicated.size(); i++) {
    ms.erase(duplicated[i]);
  }

  cout << ms.size() << endl;

  // cout << (ms.find(1) != ms.end()) << endl;  // 1
  // cout << (ms.find(2) != ms.end()) << endl;  // 0
  // cout << *ms.begin() << endl;               // 1
  // cout << *ms.rbegin() << endl;              // 7
  // cout << ms.size() << endl;                 // 6
  // ms.erase(3);
  // cout << ms.size() << endl;  // 4!
  // ms.erase(ms.find(5));
  // cout << ms.size() << endl;  // 3!
  // ms.clear();
  // cout << ms.size() << endl;  // 0
}


Measured memory_bytes: 13172
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<queue>
#include<set>
#include<climits>
using namespace std;

int main()
{
  long long n, max, min;
  cin >> n;
  vector<long long> v(n, 0);
  vector<long long> t(n, 0);

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

  t = v;

  sort(t.begin(), t.end());

  min = t[n / 2 - 1];
  max = t[n / 2];

  for (int i = 0; i < n; i++)
  {
    if (v[i] <= min)
      cout << max << endl;
    else if (v[i] >= max)
      cout << min << endl;
  }

}

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

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

  vector<long long int> ans(n+1);

  for(int i = 0; i <= n; i++){
    if(i == 0) ans[0] = 2;
    else if(i == 1) ans[1] = 1;

    else{
      ans[i] = ans[i-1] + ans[i-2];
    }
  }

  cout << ans[n] << endl;

  return 0;

}

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

typedef pair<int,int>P;

int C[105][15];



int main(){
	
	int c,n,m,s,d;
	while(cin>>c>>n>>m>>s>>d,c){
		vector<P>V[105];
		
		for(int i=0;i<105;i++){
			for(int j=0;j<15;j++)C[i][j]=1145141919;
		}
		
		for(int i=0;i<m;i++){
			int x,y,z;
			cin>>x>>y>>z;
			V[x].push_back(P(y,z));
			V[y].push_back(P(x,z));
		}
		
		priority_queue<P , vector<P> , greater<P> >Q;
		
		Q.push(P(0,c*1000+s));
		
		while(!Q.empty()){
			int cost=Q.top().first;
			int pos=Q.top().second%1000;
			int card=Q.top().second/1000;
			Q.pop();
			
			if(pos==d){
				cout<<cost<<endl;
				break;
			}
			if(C[pos][card]!=1145141919){
				continue;
			}
			
			//cout<<"#"<<pos<<" "<<card<<" "<<cost<<endl;
			
			C[pos][card]=cost;
			for(int i=0;i<V[pos].size();i++){
				//cout<<"$$"<<V[pos][i].first<<" "<<V[pos][i].second<<endl;
				if(card>0){
					if(C[V[pos][i].first][card-1]==1145141919){
						Q.push(P(cost+V[pos][i].second/2,(card-1)*1000+V[pos][i].first));
					}
				}
				if(C[V[pos][i].first][card]==1145141919){
					Q.push(P(cost+V[pos][i].second,card*1000+V[pos][i].first));
				}
			}
			
		}
		
	}
	
	
	
	return 0;
}


Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
int main(){
    LL a1,a2,a3;
    string ans;
    cin >> a1 >> a2 >> a3;
    if(a1+a2+a3>=22) ans = "bust";
    else ans = "win";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
      if(a == 3||a == 5|| a == 7){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
      sc.close();
    }
}

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

int const INF = 1e5;
int const N = 301;

int h, w, dp[N][N], was[N][N], df[N][N], wasF[N][N];
vector<string> vs;
string s;

void clearDp(){
	for(int i=0;i<N;++i){
		for(int j=0;j<N;++j){
			dp[i][j] = INF;
			was[i][j] = 0;
			df[i][j] = 0;
			wasF[i][j] = 0;
		}
	}
}

int get(string &s1, string &s2, int p1, int p2){
	if(p1 == h || p2 == h){
		return 0;
	}
	if(was[p1][p2]){
		return dp[p1][p2];
	}
	was[p1][p2] = 1;
	int cost = df[p1][p2];
	return dp[p1][p2] = min(get(s1, s2, p1+1, p2), get(s1, s2, p1, p2+1)) + cost;
}

int buildF(string &s1, string &s2, int p1, int p2){
	if(p1 == h || p2 == h){
		return 0;
	}
	if(wasF[p1][p2]){
		return df[p1][p2];
	}
	wasF[p1][p2] = 1;
	df[p1][p2] = (s1[h-1-p1] == s2[h-1-p2] ? 1 : 0);
	return df[p1][p2] += buildF(s1, s2, p1+1, p2+1);
}


int main(){
	cin >> h >> w;
	for(int i=0;i<h;++i){
		cin >> s;
		vs.push_back(s);
	}
	int ans = 0;
	for(int i=1;i<w;++i){
		string s1 = "", s2 = "";
		for(int j=0;j<h;++j){
			s1 += vs[j][i-1];
			s2 += vs[j][i];
		}
		clearDp();
		for(int k=0;k<h;++k){
			for(int j=0;j<h;++j){
				buildF(s1, s2, k, j);
			}
		}
		ans += get(s1, s2, 0, 0);
	}

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


	return 0;
}

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

using namespace std;

int n,cnt;
int main()
{
	cin >> n;
	int t=n;
	while(n)
		cnt+=(n%10),n/=10;
	if(t%cnt==0) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
from numpy import zeros, maximum
from sys import stdin

def main():
    N, T, *AB = map(int, stdin.buffer.read().split())

    dp = zeros(6010, int)
    for w, v in sorted(zip(*[iter(AB)] * 2)):
        dp[w:T + w] = maximum(dp[w:T + w], dp[:T] + v)

    print(dp.max())

main()


Measured memory_bytes: 12500
import java.util.*;
import java.lang.*;
class Main
{
  public static void findDivisors(long[] a,int n)
  {
    for(int i=1;i<=n;i++)
    {
      for(int j=i;j<=n;j+=i)
        a[j]++;
    }
  }
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
   // double max=Math.pow(10,7);
    long[] a=new long[n+1];
    //Arrays.fill(a,0);
    findDivisors(a,n);
    long ans=0;
    for(int i=1;i<=n;i++)
    {
      ans=ans+(i*a[i]);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 116068
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define vsort(v) sort(v.begin(), v.end());
#define vunique(v) unique(v.begin(), v.end());

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

	int N;
	cin >> N;
	int N1, N10;
	N10 = N / 10;
	N1 = N % 10;
	if(N10 == 9 or N1 == 9) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
score1 = score2 = 0
n = int(input())
for _ in range(n):
    s1, s2 = input().split()
    if(s1 > s2): score1 += 3
    elif(s1 < s2): score2 += 3
    else:
        score1 += 1
        score2 += 1
print(score1, score2)

Measured memory_bytes: 7632
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;

int R, C;

int clockwise_dist(int x, int y){
	if(x==0) return y;
	if(y==C) return C+x;
	if(x==R) return C*2+R-y;
	if(y==0) return (C+R)*2-x;
	return -1;
}

int main() {
	int N;
	cin >> R >> C >> N;
	vector<pair<int, int>> v;
	for(int i=0; i<N; ++i){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int s=clockwise_dist(x1, y1), t=clockwise_dist(x2, y2);
		if(s>=0 && t>=0){
			v.emplace_back(make_pair(s, i));
			v.emplace_back(make_pair(t, i));
		}
	}
	sort(v.begin(), v.end());
	stack<int> stk;
	for(int i=0; i<v.size(); ++i){
		if(stk.size()==0) stk.emplace(v[i].second);
		else if(stk.top()==v[i].second) stk.pop();
		else stk.emplace(v[i].second);
	}
	cout << (stk.size()==0 ? "YES": "NO") << endl;
	return 0;
}

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

using namespace std;

char s[100001];

int main() {
  int n;
  scanf ("%d", &n);
  scanf("%s", s + 1);
  int a = 0, b = 0;
  for (int i = 1; i <= n; ++i)
    if (s[i] == 'R')
      ++a;
    else
      ++b;
  puts(a > b ? "Yes" : "No");
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    int num;
    cin >> num;
    vec[num-1] = i+1;
  }
  for(int i=0; i<n; i++){
    cout << vec[i] << " ";
  }
  return 0;
}

Measured memory_bytes: 1152
#include<iostream>

using namespace std;

int main(){
  int a,b,c,d;
  int ans;
  cin >> a>>b>>c>>d;
  
  if(b<=c || d<=a) ans=0;
  else if(a<=c && b<=d) ans=b-c;
  else if(a<=c && d<=b) ans=d-c;
  else if(c<=a && b<=d) ans=b-a;
  else if(c<=a && d<=b) ans=d-a;
  
  cout << ans;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

typedef long long ll;
int main(){
  ll n,m;
  cin >> n >> m;
  ll maxPair = 0;
  maxPair = min(n,m/2);
  n -= maxPair;
  m -= maxPair * 2;
  //cout << maxPair << endl;
  if(n == 0 && m > 0){
    maxPair += m / 4;
  }
  cout << maxPair << endl;
  return 0;
}


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

long long a, b;

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> a >> b;

	string s;

	stringstream ss;

	ss << a;

	s = ss.str();

	stringstream sss;

	sss << b;

	s += sss.str();

	long long res = atoll(s.c_str());

	for (long long i = 1; i <= 1e5; i++)
	{
		if (i*i == res) return cout << "Yes", 0;
	}
	cout << "No";
	return 0;
}

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

int main(){
    double a,b,C,S,L,h;
    cin >> a >> b >> C;
    double pi = acos(-1);
    double rad = C*pi/180;
    S = a*b*sin(rad)/2;
    L = a+b+sqrt(a*a+b*b-2*a*b*cos(rad));
    h=2*S/a;
    printf("%lf\n%lf\n%lf\n",S,L,h);
    return 0;
}


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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    int n; cin >> n;
    int ans = 1;
    while (ans * ans <= n) ans++;
    ans--;
    cout << ans * ans << endl;
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll big = 1000000007;
const ll mod = 998244353;

ll n,m,k;



int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;

    cin >> n;
    vl A;
    for(int c1 = 0; c1 < n; c1++){
        cin >> a;
        A.push_back(a);
    }
    sort(all(A));

    ll a1 = A[n-1];
    ll mi = big*big;
    ll a2 = -1;
    for(int c1 = 0; c1 < n-1; c1++){
        ll d = abs(a1-2*A[c1]);
        if(d < mi){
            mi = d;
            a2 = A[c1];
        }
    }
    cout << a1 << " " << a2 << "\n";

    return 0;
}


Measured memory_bytes: 1400
#include <stdio.h>

int main(void)
{
    int x, y;
    scanf("%d %d", &x, &y);

    int i, j;
    for (i = 0; i <= x; i++)
    {
        for (j = 0; j <= x; j++)
        {
            if (2 * i + 4 * j == y && (i+j)==x)
            {
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}


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

using namespace std;

long long convert(int n) {
    if(n == 0) return 0;
    return 1LL * 10 * convert(n/2) + n%2;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long long ans = 0;
    vector<int> pos(21, -1);
    vector<int> range(n);
    //cout << fixed << setprecision(20) << setfill('0');
    for(int i = 0; i < n; i++) {
        range[i] = i + 1;
        for(int j = 0; j <= 20; j++) {
            if(a[i] & (1 << j)) {
                range[i] = min(range[i], i - pos[j]);
                pos[j] = i;
            }
            else {
                //last 1 is at pos[j], if no one then pos[j] = -1
                if(pos[j] != -1)
                    range[i] = min(range[i], range[pos[j]] + i - pos[j]);
            }
        }
        //cout << "i = " << convert(a[i]) << " , range = " << range << endl;
        ans += 1LL * range[i];
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define INF 2e9
#define MOD 1e9+7
#define ALL(v) v.begin(), v.end()

int ni() {
    int i;
    cin >> i;
    return i;
}

int main() {
    string s, t;
    cin >> s >> t;
    int N = s.length();
    int M = t.length();

    REPR(i, N-1) {
        if (s[i] == '?' || s[i] == t[0]) {
            bool ok = true;
            REP(j, M) {
                if (i+j >= N || (s[i+j] != '?' && s[i+j] != t[j])) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                string ans = "";
                FOR(j, 0, i) {
                    if (s[j] == '?') ans.append("a");
                    else ans.push_back(s[j]);
                }
                ans.append(t);
                FOR(j, i+M, N) {
                    if (s[j] == '?') ans.append("a");
                    else ans.push_back(s[j]);
                }
                cout << ans << endl;
                return 0;
            }
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(),v.end()

int main() {
  ll n;
  cin >> n;
  ll sum=0;
  
  vector<ll> a(10000001);
  for(ll i=1;i<=10000000;i++){
  	ll max=10000000/i;
    for(ll j=1;j<=max;j++){
    	a[j*i]++;
    }
  }
  
  for(ll i=1;i<=n;i++){
    ll yaku;
    yaku=a[i];
    sum+=i*yaku;
  }
  
  cout << sum << endl;
}



Measured memory_bytes: 81372
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll n;
string s;
cin>>n>>s;
for(int i=0;i<s.size();i++){
cout<<(char)('A'+(s.at(i)-'A'+n)%26);
}

}










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

using namespace std;

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

    int n,m;
    cin>>n>>m;

    if(n==m)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		
		if(line.equals("A")) {
			System.out.println("T");
		}else if(line.equals("T")) {
			System.out.println("A");			
		}else if(line.equals("C")) {
			System.out.println("G");			
		}else {
			System.out.println("C");			
		}
	}

}


Measured memory_bytes: 35648
#include <iostream>

using namespace std;

#define rep(i,N) for(int i=0;i<N;i++)
#define MAXA 100001
#define MAXB 100001
#define MAXM 100001
typedef long long ll;

int A,B,M;
int a[MAXA];
int b[MAXB];
int x[MAXM],y[MAXM],c[MAXM];

int main(){
  cin >> A >> B >> M;
  int mina = 500001,minb = 500001;
  rep(i,A){ 
    cin >> a[i];
    mina = min(a[i],mina);
  }
  rep(i,B){ 
    cin >> b[i];
    minb = min(b[i],minb);
  }
  rep(i,M){
    cin >> x[i] >> y[i] >> c[i];
  }
  ll val = mina + minb;
  rep(i,M){
    ll price = a[x[i]-1] + b[y[i]-1] - c[i];
    if(price < val)val = price;
  }

  cout << val << endl;

  return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	stack<int> GradS;
	stack<pair<int, int>> PartSum;

	int sum = 0;
	char ch;

	for (int i = 0;cin >> ch;i++)
	{
		if (ch == '\\')
			GradS.push(i);
		else if (ch == '/' && GradS.size() > 0)
		{
			// ????????????????????¢?????´????????????
			int j = GradS.top();
			GradS.pop();

			// ?????¨???/??????\??????????????¨??§??¢????????????
			int p = i - j;

			// ?????¢????????????
			sum += p;

			// ????????´???????????????????????????
			while (PartSum.size() > 0 && PartSum.top().first > j)
			{
				p += PartSum.top().second;
				PartSum.pop();
			}

			// ?????¨??????????????¢??§?????¨?????¢???
			PartSum.push(make_pair(j, p));
		}
	}

	vector<int> ans;

	// ???????????????????????????vector?????????
	while (PartSum.size() > 0)
	{
		ans.push_back(PartSum.top().second);
		PartSum.pop();
	}

	// ??????
	cout << sum << endl;
	cout << ans.size();
	for (int i = ans.size() - 1;i >= 0;i--)
	{
		cout << " ";
		cout << ans[i];
	}
	cout << endl;

	return 0;
}

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

int balls[20];
int R, L;

bool dfs(int n) {
  if (n == 10) {
    return true;
  }
  if (R < balls[n]) {
    R = balls[n];
    if (dfs(n+1)) {
      return true;
    }
  }
  if (L < balls[n]) {
    L = balls[n];
    if (dfs(n+1)) {
      return true;
    }
  }
  return false;
}

int main(void) {
  int N;
  cin >> N;
  while (N--) {
    for (int i = 0; i < 10; i++) {
      cin >> balls[i];
    }
    R = balls[0];
    L = 0;

    if (dfs(1)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define see(x) cout<<#x<<" : "<<(x)<<endl;
#define ya cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define ff first
#define sc second
typedef long long ll;
using namespace std;

int main()
{
    char s;
    cin>>s;
    if(s=='A')cout<<'T'<<endl;
    else if(s=='T')cout<<'A'<<endl;
    else if(s=='C')cout<<'G'<<endl;
    else cout<<'C'<<endl;
    return 0;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
int main()
{
	 int a,b;
	 scanf("%d %d",&a,&b);
	 char str[100000];
	 scanf("%s",str);
	 int t = 1;
	 int l = strlen(str);
	 if(l!= a+b+1)
	 {
		  printf("No\n");
     }
     else {
		 
		 for(int i=0; i<l; i++)
		 {
			  if(i == a ) {
				 if( str[i]!='-')
				 {
				  t = 0;
				  break;
				 }
			  }
			 else{
			    if(str[i] !='1' && str[i] !='2' && str[i] !='3' && str[i] != '4'  && str[i] !='5' && str[i] !='6' && str[i] !='7' && str[i] != '8' && str[i] !='0' && str[i] !='9')
		         {
				   t = 0 ;
				   break;
			     }
			}
	     }
	       if(t == 0) printf("No\n");
	       else printf("Yes\n");
	    }
	     return 0;
	  
}	    
	    
	    
	    
				  
		 
		 
		 
	
	 


Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}


void solve(long long N, std::vector<long long> h){
    VI dp(N);
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2; i <N; i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[N-1]<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, std::move(h));
    return 0;
}


Measured memory_bytes: 1408