akhauriyash/Code-Regression huggingface dataset:
base1 = 1009
base2 = 1013
mask = (1 << 32) - 1
def calc_hash(f, r, c):
    global ph, pw, h
    tmp = [[0] * c for _ in range(r)]
    dr, dc = r - ph, c - pw
    t1 = 1
    for _ in range(pw):
        t1 = (t1 * base1) & mask
    for i in range(r):
        e = 0
        for j in range(pw):
            e = e * base1 + f[i][j]
        for j in range(dc):
            tmp[i][j] = e
            e = (e * base1 - t1 * f[i][j] + f[i][j + pw]) & mask
        tmp[i][dc] = e
    t2 = 1
    for _ in range(ph):
        t2 = (t2 * base2) & mask
    for j in range(dc + 1):
        e = 0
        for i in range(ph):
            e = e * base2 + tmp[i][j]
        for i in range(dr):
            h[i][j] = e
            e = (e * base2 - t2 * tmp[i][j] + tmp[i + ph][j]) & mask
        h[dr][j] = e
th, tw = map(int, input().split())
t = tuple(tuple(ord(c) for c in input()) for _ in range(th))
ph, pw = map(int, input().split())
p = tuple(tuple(ord(c) for c in input()) for _ in range(ph))
ans = []
if th >= ph and tw >= pw:
    h = [[0] * tw for _ in range(th)]
    calc_hash(p, ph, pw)
    key = h[0][0] & mask
    calc_hash(t, th, tw)
    for i in range(th - ph + 1):
        for j in range(tw - pw + 1):
            if h[i][j] & mask == key:
                ans.append(f"{i} {j}")
if ans:
    print("\n".join(a for a in ans))


Measured memory_bytes: 92016
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>
#include<cmath>
#include<fstream>
#include<numeric>

int main(){
	std::vector<int> T(5);
	int max_surplus = 0;

	for(int i=0;i<5;i++){
		std::cin >> T[i];
		int surplus = T[i]%10;
		if(surplus != 0){
			T[i] += (10 - surplus);
			if(max_surplus < (10 - surplus)) max_surplus = 10 - surplus;
		}
	}

	std::cout << std::accumulate(T.begin(),T.end(),0) - max_surplus << std::endl;
	return 0;
}


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


/**
 * AIZU ONLINE JUDGE
 * 0619
 *  2020/5/5
 */
public class Main {


    boolean main() throws IOException {

        Scanner sc = new Scanner(systemin);

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

        int sum = A + B + C + D - Math.min(Math.min(A, B), Math.min(C, D)) + Math.max(E, F);
        result.printf("%d\n",  sum);

        sc.close();
        return false;
    }



    PrintStream log;
    PrintStream result = System.out;
    BufferedReader systemin;

    static Main instance = new Main();

    Main() {
        systemin = new BufferedReader(new InputStreamReader(System.in));
        log = new PrintStream(new OutputStream() { public void write(int b) {} } );
    }

    public static void main(String[] args) throws IOException {

        instance.main();
        instance.systemin.close();
    }


}




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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
    }
    N -= K;
    int ans = N / (K-1) + (N%(K-1)!=0) + 1;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N, C; scanf("%d %d", &N, &C);
  vector<int> table(2 * 1e5 + 5, 0);
  vector<int> B(N), E(N), CL(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d %d %d", &B[i], &E[i], &CL[i]);
    B[i] = 2 * B[i] - 1;
    E[i] *= 2;
  }

  int upper = 2 * 1e5;
  vector<int> recorder(upper + 5, 0);
  for (int i = 1; i <= C; ++i) {
    vector<int> table(upper + 5, 0);
    for (int j = 0; j < N; ++j) {
      if (CL[j] != i) { continue; }
      ++table[B[j]];
      --table[E[j]];
    }
    for (int j = 1; j <= upper; ++j) {
      table[j] += table[j - 1];
    }
    for (int j = 1; j <= upper; ++j) {
      if (table[j] > 0) {
        ++recorder[j];
      }
    }
  }

  int ans = *max_element(recorder.begin(), recorder.end());
  printf("%d\n", ans);
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int waru = 1000000007;
  int64_t power = 1;
  for( int i = 1; i <= N; i++ ){
    power = power * i % waru;
  }
  cout << power << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> f(n + 1);
  for (int i = 1; i <= 100; ++i)
    for (int j = 1; j <= 100; ++j)
      for (int k = 1; k <= 100; ++k) {
        int val = i * i + j * j + k * k + i * j + i * k + k * j;
        if (val <= n)
          f[val]++;
      }
  for (int i = 1; i <= n; ++i)
    cout << f[i] << endl;
}

Measured memory_bytes: 3528
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random


def main():
    n = int(input())
    t_order = list(map(int, input().split()))
    happiness = list(map(int, input().split()))
    additional_hpns = list(map(int, input().split()))
    for i in range(len(happiness)):
        t_order[i]=t_order[i]-1
        
    sum=0
    for i in range(n):
        sum+=happiness[i]
        
        if i!=0:
            if t_order[i] == t_order[i-1] + 1:
                sum+=additional_hpns[t_order[i-1]]
                
    print(sum)
    
    return

if __name__ == '__main__':
    main()

# 料理i: 0 ~ n-1 が存在する
# 高橋くんはi番目に料理a_iを食べた
# 料理iから得られる満足はb_i
# 
# 1 2 3
# 2 5 4
# 3 6

# 3 1 2
# 4 2 5 
#    3


Measured memory_bytes: 66412
N = int(input())
A = [int(input()) for _ in range(N)]
A2 = [index - a for index, a in enumerate(A)]


def solve():
    if A[0] != 0:
        return -1
    for i in range(N - 1):
        if A[i + 1] - A[i] > 1:
            return -1
    ans = 0
    for i in range(N - 1):
        if A2[i] != A2[i + 1]:
            ans += i - A2[i]
    else:
        i = N - 1
        ans += i - A2[i]
    return ans

print(solve())


Measured memory_bytes: 18976
#include<stdio.h>
long long a[100009]={0},l,i,n,m,p;
int main()
{
	
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&m);
		a[m]++;
		
	}
	if(n%2==1)
	{
		if(a[0]==1)p=1;
		else  {
		printf("0");	return 0;
		}
		for(i=2;i<=n;i=i+2)
		{
			if(a[i]==2)p=(p*2)%1000000007;
			else {
				printf("0");
				return 0;
			}
		}
		
	}
	else {
		p=1;
		for(i=1;i<=n;i=i+2)
		{
			if(a[i]==2)p=(p*2)%1000000007;
			else {
				printf("0");
				return 0;
			}
		}
	}
	printf("%lld",p);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define maxn 20

typedef long long ll;
ll ans; 
int f[maxn * 2][maxn][maxn];
int n,cntr,cntb;
char ch[maxn * 2],r[maxn],b[maxn];

int main(){
	
	scanf("%d",&n);
	scanf("%s",ch + 1);
	for (int i = 0 ; i < 1 << n ; i++){
		cntr = cntb = 0;
		for (int j = 0 ; j < n ; j++){
			if ( i & (1 << j) ){
				r[++cntr] = ch[j + 1];
			}
			else{
				b[++cntb] = ch[j + 1];
			}
		}
		f[n * 2 + 1][0][0] = 1;
		for (int j = 2 * n + 1 ; j > n + 1 ; j--){
			for (register int k = 0 ; k <= cntr ; k++) for (register int l = 0 ; l <= cntb ; l++) f[j - 1][k][l] = 0;
			for (register int k = 0 ; k <= cntr ; k++){
				for (register int l = 0 ; l <= cntb && k + l <= 2 * n - j + 1 ; l++){
					if ( f[j][k][l] ){
						if ( ch[j - 1] == r[k + 1] ) f[j - 1][k + 1][l] += f[j][k][l];
						if ( ch[j - 1] == b[l + 1] ) f[j - 1][k][l + 1] += f[j][k][l];
					}
				}
			}
		}
		ans += f[n + 1][cntr][cntb];
	//	cout<<i<<" "<<f[n + 1][cntr][cntb]<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
[n,m,x]=list(map(int,input().split()))
kashiko=[]
for i in range(n):
    kashiko.append(list(map(int,input().split())))

ichizero=[]
for i in range(2**n):
    kari=[]
    for keta in reversed(range(n)):
        kari.append(i//(2**keta))
        i=i%(2**keta)
    ichizero.append(kari)

mincost=pow(10,7)

for now in ichizero:
    chokudai=[0]*m
    cost=0
    for j in range(n):
        if now[j]==1:
            cost+=kashiko[j][0]
            for k in range(m):
                chokudai[k]+=kashiko[j][k+1]

    if min(chokudai)>=x:
        if mincost>cost:
            mincost=cost

if mincost==pow(10,7):
    ans=-1
else:ans=mincost

print(ans)

Measured memory_bytes: 9776
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds ;
#define ll int
#define ld long double
#define pp pair<ll,pair<ll,ll> >
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define hell 1000000007
#define f first
#define s second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree<ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t = 1 ;
void solve()
{
    ll n , k ;
    cin >> n >> k ;
    k <= (n+1)/2 ? cout << "YES" : cout << "NO" ;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //cin>>t;
    while(t--)
        solve();
    return 0 ;
}


Measured memory_bytes: 256
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


n=int(input())
edge=[[] for i in range(n+1)]
par=[0]*(n+1)#i番目の頂点とその親を結ぶ辺の色
par[1]=-1
col=[0]*(n-1)#i番目の辺の色
for i in range(n-1):
    a,b=mp()
    edge[a].append([a,b,i])
    edge[b].append([b,a,i])


que=deque([edge[1]])
while len(que):
    k=1
    q=que.popleft()
    for x,y,i in q:
        if col[i]==0:
            if k==par[x]:
                k+=1
            col[i]=k
            par[y]=k
            k+=1
            que.append(edge[y])
print(max(col))
for i in range(n-1):
    print(col[i])

    


Measured memory_bytes: 51208
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string s;

int main(){
    cin >> s;
    int N;
    vector<int> v;
    vector<int> ans;
    N = s.size();
    char c = 'R';
    int l = 0;
    for(int i=1;i<N;i++){
        if(i==N-1){
            if(s[i] == c){
                v.push_back(N-l);
            }else{
                v.push_back(N-l-1);
                v.push_back(1);
            }
            break;
        }
        if(s[i] == c) continue;
        v.push_back(i-l);
        l = i;
        c = s[i];
    }
    for(int i=0;i<v.size();i+=2){
        for(int j=0;j<v[i]-1;j++) ans.push_back(0);
        int r = v[i] / 2;
        int l = v[i+1] / 2;
        int rl = l+r;
        if(v[i]%2==1) rl++;
        ans.push_back(rl);
        rl = l+r;
        if(v[i+1]%2==1) rl++;
        ans.push_back(rl);
        for(int j=0;j<v[i+1]-1;j++) ans.push_back(0);
    }
    for(int i=0;i<ans.size();i++){
        cout << ans[i];
        if(i != ans.size()-1) cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1592
#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<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<exception>
#include<fstream>
#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<stack>
#include<set>
using namespace std;
double digit;
long long ans=1;
int n;
int main()
{
	cin>>n;
	for (int i=1;i<=n;++i)
	{
		long long tmp;
		scanf("%lld",&tmp);
		if (tmp==0)
		{
			cout<<0;
			return 0;
		}
		digit+=log10(tmp);
		ans*=tmp;
	}
	if (digit>18.0 || ans>1000000000000000000)
	{
		cout<<-1;
		return 0;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int>A(N);
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (i == 0){
      sum += abs(A.at(i));
    }
    else {
      sum += abs(A.at(i)-A.at(i-1));
    }
  }
  sum += abs(A.at(N-1));
  
  for (int i = 0; i < N; i++) {
    if (i == 0){
      cout << sum - abs(A.at(i)) - abs(A.at(i)-A.at(i+1)) + abs(A.at(i+1)-0) << endl;
    }
    else if (i == N-1){
      cout << sum - abs(A.at(i)) - abs(A.at(i)-A.at(i-1)) + abs(A.at(i-1)-0) << endl;
    }
    else {
      cout << sum - abs(A.at(i)-A.at(i-1)) - abs(A.at(i)-A.at(i+1)) + abs(A.at(i-1)-A.at(i+1)) << endl;
    }
  }
}

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

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

    string ans = "";
    if(a < b){
        rep(i, 0, b) ans += to_string(a);
        cout << ans << endl;
    }
    else {
        rep(i, 0, a) ans += to_string(b);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 384
n = int(input())
a = [int(x) for x in input().split()]

l, r = 0, 0
ans = 0
key = 0
while r < n:
  if key^a[r] == key+a[r]:
    key = key+a[r]
    r += 1
    continue
  key = key^a[l]
  ans += r-l
  l += 1
  if l > r:
    key = key^a[r]
    r += 1

while l < n:
  if key^a[l] == key-a[l]:
    ans += n-l
    l += 1
    continue
  break
print(ans)

Measured memory_bytes: 24584
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5+5;
ll a[N], b[N], sumA[N];
int n, m;

int f(ll remain) {
    int l = 0, r = n-1;

//    for(int i = l; i <= r; i++) {
//        cout << sumA[i] << '\n';
//    }

    //cout << r << ' ' << remain << '\n';
    int ans = 0;
    while(l <= r) {
        int mid = (l+r)/2;
        if(remain >= sumA[mid]) {
            ans = mid+1;
            l = mid+1;
        } else {
            r = mid-1;
        }
    }
    return ans;
}

int main(void) {
    ios::sync_with_stdio(false);
    ll num, k;
    cin >> n >> m >> k;

    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sumA[i] = a[i];
        if(i)
            sumA[i] += sumA[i-1];
    }
    for(int i = 0; i < m; i++) {
        cin >> b[i];
    }

    int ans = 0;
    ll sum = 0;
    for(int i = 0; i <= m; i++) {
        if(k >= sum) {
            //cout << k << ' ' << sum << ' ' << ans << '\n';
            ans = max(ans, i+f(k-sum));
        } else break;
        //cout << "A:" << ans << '\n';
        sum += b[i];
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 8300
n = int(input())
t, a = map(int, input().split())

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

idx = 0
tmp = 1000000000
for i, x in enumerate(h):
    ave_t = t - 0.006 * x
    if abs(a - ave_t) < abs(a - tmp):
        idx = i
        tmp = ave_t
print(idx + 1)


Measured memory_bytes: 3060
import java.util.*;
public class Main {
	Scanner sc;
	void run() {
		sc = new Scanner(System.in);
		int nums[] = {0,1,2,3,5,7,8,9};
		while (true) {
			int n = sc.nextInt();
			if (n == 0) break;
			LinkedList<Integer> ket = new LinkedList<Integer>();
			while(n!=0) {
//				System.out.print(n%8 + " ");
				ket.addFirst(n%8);
				n/=8;
			}
			for(Integer i: ket ) System.out.print(nums[i]); 
			
			System.out.println();
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
	
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, m = [int(x) for x in input().split()]
    s = input()
    t = input()
    g = gcd(n, m)
    ans = n * m // g
    a, b = n // g, m // g
    x, y = 0, 0
    for i in range(g):
        if s[x] != t[y]:
            print(-1)
            return
        x += a
        y += b
    print(ans)
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

2 2 2 2 2

"""


Measured memory_bytes: 9584
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int n = sc.nextInt();
		int ans = 0;
		
		if (n < 105) {
			ans = 0;
		} else if (n < 107) {
			ans = 1;
		} else {
			ans++;
			for (int i = 107; i <= n; i++) {
				if (i % 2 == 0) {
					continue;
				}
				int div = 1;
				int sum = 0;
				while (div <= i) {
					if (i % div == 0) {
						sum++;
					}
					div++;
				}
				if (sum == 8) {
					ans++;
				}
			}
		}

		System.out.println(ans);

		sc.close();
	}
}


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

int main() {
  int N,X,D=0,ans=1;
  cin>>N>>X;
  for(int i=0;i<N;i++){
    int L;
    cin >>L;
    D+=L;
    if(D<=X)ans++;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;
typedef pair<int,int> P;
typedef long long int ll;

int main()
{
    char str[120][120];
    int n, l, i, j;
    scanf("%d %d", &n, &l);
    for(i=0;i<n;i++)
        scanf(" %s", str[i]);
    for(i=0;i<n;i++)
        for(j=i+1;j<n;j++)
        {
            if(strcmp(str[i], str[j]) > 0)
            {
                char str1[120];
                strcpy(str1, str[i]);
                strcpy(str[i], str[j]);
                strcpy(str[j], str1);
            }
        }
    for(i=0;i<n;i++)
        printf("%s", str[i]);
    printf("\n");
    return 0;
}


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


long long fnd(long long x,long long p){
	if(p/x == p/(x+1)) return x;
	long long lo = x,hi = sqrt(p + 1);
	while(lo < hi){
		long long mid = (lo + hi+1)>>1;
		if(p/mid == p/(mid+1) || p/mid == p/(mid-1)) hi = mid-1;
		else lo = mid;
	}
	//cout<<lo<<" "<<p/(lo-1)<<" "<<p/lo<<" "<<p/(lo+1)<<endl;
	return lo+1;
}

int main(){
	int Q;cin>>Q;
	for(int n=0;n<Q;n++){
		long long int A,B;cin>>A>>B;
		long long p = A*B - 1;
		long long x = A+1,ty = 0;
		//cout<<x<<" "<<p<<endl;
//		while(p/x != p/(x+1)){
//			x += 1;
//			ty += 1;
//		}
		long long hx = fnd(A+1,p);
		ty += (hx-x);
		x = hx;
		//cout<<x<<" "<<fnd(A+1,p)<<endl;
		ty += p/x;
		long long y = B+1,tx = 0;
//		while(p/y != p/(y+1)){
//			y += 1;
//			tx += 1;
//		}
		//cout<<y<<" "<<fnd(B+1,p)<<endl;
		long long hy = fnd(B+1,p);
		tx += (hy-y);
		y = hy;
		tx += p/y;
		long long rx = A - tx,ry = B - ty;
		long long t = tx + ty + max(0LL,min(rx,ry)-1);
		cout<<t<<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);
		String s = sc.next();

		String[] a = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
		int[] b = {7,6,5,4,3,2,1};

		for(int i = 0 ; i < b.length ; i++){
			if(a[i].equals(s)){
				System.out.println(b[i]);
			}
		}
	}
}

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

int main(){
  int n,k; cin>>n>>k;
  vector<int> x(n);
  for (int i=0; i<n; i++) cin>>x[i];
  
  long long ans=10e9;
  for (int j=0; j<n-k+1; j++){
    long long t_ans=x[j+k-1]-x[j];
    t_ans+=min(abs(x[j+k-1]),abs(x[j]));
    ans=min(ans,t_ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    long long n,a,min=1000000,max=-1000000,s=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a>max)max=a;
        if(a<min)min=a;
        s=s+a;
    }
    cout<<min<<" "<<max<<" "<<s<<endl;
}



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

typedef long long ll;

using namespace std;

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

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;

int main(){
    int N,M;
    cin >> N >> M;
    vector<pair<int,int>> student(N);
    vector<pair<int,int>> check(M);
    rep(i,N) cin >> student[i].first >> student[i].second;
    rep(i,M) cin >> check[i].first >> check[i].second;
    rep(i,N){
        int min = abs(student[i].first-check[0].first)+abs(student[i].second-check[0].second);
        int min_n = 0;
        rep(j,M){
            if(min > abs(student[i].first-check[j].first)+abs(student[i].second-check[j].second)){
                min_n = j;
                min = abs(student[i].first-check[j].first)+abs(student[i].second-check[j].second);
            }
        }
        cout << min_n+1 << 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);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char al = a.charAt(a.length() - 1);
		char bf = b.charAt(0);
		char bl = b.charAt(b.length() - 1);
		char cf = c.charAt(0);
		if (al == bf && bl == cf) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

}

Measured memory_bytes: 22740
x =int(input())
a =[i**5 for i in range(120)]
for i in range(120):
    for j in range(i+1,120):
        if a[j] -a[i] ==x:
            print(j,i)
            break
        if a[j] +a[i] ==x:
            print(j,-i)
            break


Measured memory_bytes: 9180
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
  int h,w,i,j;
  char s='#',x='.';
  while(1){
    cin>>h>>w;
    if(h==0&&w==0) break;
    for(j=0;j<w;j++){
	cout<<s;
    }
    printf("\n");
    for(i=0;i<h-2;i++){
      cout<<s;
      for(j=0;j<w-2;j++){
	cout<<x;	
      }
      cout<<s;
      printf("\n");
    }
    for(j=0;j<w;j++){
	cout<<s;
    }
    printf("\n");
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  int N;
  cin>>N;
  vector<int>a(N);
  int sum=0;
  for(int i=0;i<N;i++){
    cin>>a[i];
    sum+=a[i];
  }
  int ave=round(((double)sum)/(double)N);
  int ans=0;
  for(int i=0;i<N;i++){
    ans=ans+(a[i]-ave)*(a[i]-ave);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    vector<ll> L(n + 1);
    L[0] = 2;
    L[1] = 1;
    for(int i = 2; i <= n; i++) {
        L[i] = L[i - 1] + L[i - 2];
    }
    cout << L[n] << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools

n = input()
if (n[-1] == '2' or n[-1] == '4' or n[-1] == '5' or n[-1] == '7' or n[-1] == '9'):
    print('hon')
elif (n[-1] == '0' or n[-1] == '1' or n[-1] == '6' or n[-1] == '8'):
    print('pon')
else:
    print('bon')



Measured memory_bytes: 9056
N, M = map(int, input().split())
if N >= M:
    print(0)
    exit()
lst = list(map(int, input().split()))
lst.sort()
lst2 = []
for i in range(1, M):
    lst2.append(lst[i] - lst[i-1])
lst2.sort()
print(sum(lst2[0:(M-N)]))


Measured memory_bytes: 13968
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

int N;
std::vector<int > edge[200005];
std::vector<int > dp(200005, 1001001001);
std::vector<int > ans(200005);
std::vector<int> a(200005);
void dfs(int n, int p=-1){
  auto itr2 = std::lower_bound(dp.begin(), dp.end(), a[n]);
  int temp = *itr2;
  *itr2 = a[n];
  auto itr = std::lower_bound(dp.begin(), dp.end(), 1001001000);
  ans[n] = itr - dp.begin();
  for (int i=0; i<edge[n].size(); i++){
    int dst = edge[n][i];
    if (dst==p) continue;
    dfs(dst, n);
  }
  *itr2 = temp;
  return;
}
  int main(){

  scanf("%d", &N);
  for (int i=0; i<N; i++){
    scanf("%d", &a[i]);
  }
  int u, v;
  for (int i=0; i<N-1; i++){
    scanf("%d", &u);
    scanf("%d", &v);
    u--;
    v--;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  dfs(0);
  for (int i=0; i<N; i++){
    std::cout << ans[i] << std::endl;
  }
			

  
  return 0;
}

Measured memory_bytes: 27588
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int n, l;
  cin >> n >> l;
  int r = l + n - 1;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += l + i;
  }
  int dif = 0;
  if (l > 0) dif = l;
  if (r < 0) dif = r;
  int ret = sum - dif;
  cout << ret << endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N+1);
  for(int i=1; i<=N; i++){
    cin >> A.at(i);
  }
  int Now=1;
  for(int i=1; i<=2*N; i++){
    Now=A.at(Now);
    if(Now==2){
      cout << i << endl;
      break;
    }
  }
  if(Now!=2){
    cout << -1 << endl;
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	ll a,b,x; cin>>a>>b>>x;
	if(a<=x && x<=a+b)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;
}

Measured memory_bytes: 3632
import Data.List
main :: IO ()
main = do
    n:p <- input <$> getContents
    let (a,b) = answer $ map snd $ sortOn fst $ zip p [1..]
    putStrLn $ showans a
    putStrLn $ showans b

input :: String -> [Int]
input = fmap read . words

answer :: [Int] -> ([Int],[Int])
answer p = (           tail $ reverse $ foldl foldlf [0] p
           , reverse $ tail $ reverse $ foldr foldrf [0] p)

foldrf p (h:acc) = ((h+p):h:acc)
foldlf (h:acc) p = ((h+p):h:acc)

showans :: [Int] -> String
showans [] = ""
showans (x:xs) = (show x) ++ " " ++ (showans xs)


Measured memory_bytes: 11004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

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

int main(){
  int n; cin >> n;
  vector<ll> v(n);
  map<ll, ll> cnt;
  for(int i=0; i<n; i++){
    cin >> v.at(i);
    cnt[v[i]] += 1;
  }
  ll ans=0, num=1;
  if(cnt[0]==1 && v[0]==0){
    ans = 1;
    for(int i=1; num<n; i++){
      for(int j=0; j<cnt[i]; j++){
        ans *= cnt[i-1];
        ans %= 998244353;
      }
      
      if(ans==0) break;
      num += cnt[i];
    }
  }
  //for(int i=0; i<n; i++) cout << cnt[i] << endl;
  cout << ans << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int A[] = { 0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

int main(void) {

	int K;
	cin >> K;


	cout << A[K] << endl;

	return 0;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        public static long res = long.MinValue;
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var h1 = int.Parse(input[0]);
            var m1 = int.Parse(input[1]);
            var h2 = int.Parse(input[2]);
            var m2 = int.Parse(input[3]);
            var k = int.Parse(input[4]);

            if (h2 < h1)
                h2 += 24;

            Console.WriteLine(h2 * 60 + m2 - h1 * 60 - m1 - k);

        }

    }
}



Measured memory_bytes: 27532
#include<iostream>
using namespace std;
int main()
{
    int a,b,n,k,i,l;
    cin>>a>>b;
    for(i=1;;i++)
    {
        k=(i*(i+1))/2;
        l=((i+1)*(i+2))/2;
        //cout<<i<<" "<<k<<" "<<l<<endl;
        if((k-a)==(l-b))
            break;
    }
    n=k-a;
    cout<<n<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1000000009

vector<int> primes = {2,3,5,7,11,13,17};
int nprime = primes.size();
vector<pair<int,int>> v;

int dfs(int d, map<int,int> state){
  if(d == nprime){
    // solve
    int ret = 0;
    map<int,int> tmp;
    for(auto p : v){
      bool ok = true;
      for(auto &sp : state){
        int c = 0;
        while(p.first%sp.first == 0){
          p.first /= sp.first;
          c++;
        }
        if(c > sp.second){
          ok = false;
          break;
        }
      }
      if(ok){
        if(p.first == 1) ret += p.second;
        else tmp[p.first] += p.second;
      }
    }
    for(auto &p : tmp) if(p.second>0) ret += p.second;
    // dbg(ret, vector<pair<int,int>>(all(state)));
    return ret;
  }
  else {
    int ret = -INF;
    state[primes[d]] = -1;
    for(int x=1; x<=300; x *= primes[d]){
      state[primes[d]]++;
      ret = max(ret, dfs(d+1, state));
    }
    return ret;
  }
}

int main(){
  int q;
  cin>>q;
  v.resize(q);
  rep(i,q){
    cin>>v[i].first>>v[i].second;
  }

  cout << dfs(0, map<int,int>()) << endl;

  return 0;
}


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

signed main(void)
{
	string t;
	cin >> t;
	rep(i, t.size())
	{
		if (t[i] == '?')
			t[i] = 'D';
	}
	cout << t << endl;
	return 0;
}


Measured memory_bytes: 3756
N,M = map(int,input().split())

dic_drink = {}
for i in range(N):
  ai,bi = map(int,input().split())
  if ai not in dic_drink:
    dic_drink[ai] = bi
  else:
    dic_drink[ai] += bi

price = 0
for ai,bi in sorted(dic_drink.items()):
  if M <= bi:
    price += ai*M
    break
  else:
    price += ai*bi
    M -= bi
    
print(price)

Measured memory_bytes: 22996
n=int(input())
a=list(int(x) for x in input().split())
b=list(int(x) for x in input().split())
ans=0
for i in range(n):
    kill=0
    if a[i]>=b[i]:
        kill=b[i]
    else:
        if a[i+1]+a[i]<b[i]:
            kill=a[i+1]+a[i]
            a[i+1]=0
        else:
            kill=b[i]
            a[i+1]=a[i+1]+a[i]-b[i]
    ans+=kill
print(ans)


Measured memory_bytes: 18624
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int h,w; cin >> h >> w;
  map<char,int> mp;
  rep(i,h) rep(j,w){
    char a; cin >> a;
    mp[a]++;
  }
  int one = 0, two = 0, four = 0;
  for(auto x : mp){
    four += x.second/4;
    x.second %= 4;
    two += x.second/2;
    x.second %= 2;
    one += x.second;
  }
  bool ok = true;
  if(h%2 && w%2){
    if(one != 1) ok = false;
  }else{
    if(one != 0) ok = false;
  }
  if(four < (h/2)*(w/2)) ok = false;
  cout << (ok ? "Yes" : "No");
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3600
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();
        int[] W = new int[N];
        int a = 0;
        int b = 0;
        for (int i=0; i<N; i++) {
            W[i] = reader.nextInt();
            a += W[i];
        }
        int ans = a;
        for (int i=0; i<N; i++) {
            a -= W[i];
            b += W[i];
            ans = Math.min(ans, Math.abs(a-b));
        }
        System.out.println(ans);
    }

    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



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

int main(){
  int a, b, ab, x, y;
  cin >> a >> b >> ab >> x >> y;
  ab *= 2; // a++, b++
  ll sum = a * x + b * y;
  ll ma = max(x, y);
  for(ll i = 1; i <= ma; i++){
    ll tmp = ab * i;
    ll tx = x - i;
    ll ty = y - i;
    if(tx > 0) tmp += tx * a;
    if(ty > 0) tmp += ty * b;
    sum = min(tmp, sum);
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <utility>
#include <valarray>

using namespace std;

int main()
{
    int N, M;
    scanf("%d %d\n", &N, &M);
    vector<vector<char>> A(N, vector<char>(N));
    for (int i = 0; i < N; ++i){
        for (int j = 0; j < N; ++j) A[i][j] = getchar();
        getchar();
    }
    vector<vector<char>> B(M, vector<char>(M));
    for (int i = 0; i < M; ++i){
        for (int j = 0; j < M; ++j) B[i][j] = getchar();
        getchar();
    }
    for (int i = 0; i <= N - M; ++i){
        for (int j = 0; j <= N - M; ++j){
            bool flag = true;
            for (int y = 0; y < M; ++y){
                for (int x = 0; x < M; ++x){
                    if (A[i + y][j + x] != B[y][x]){
                        flag = false;
                        break;
                    }
                }
                if (!flag) break;
            }
            if (flag){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int W[N];
    for (int i = 0; i < N; i++) {
        cin >> W[i];
    }
    int s1 = W[0], s2 = 0;
    for (int i= 1; i < N; i++) {
        s2 += W[i];
    }

    int res = abs(s1-s2);

    for (int T = 1; T < N; T++) {
        s1 += W[T];
        s2 -= W[T];
        res = min(res, abs(s1-s2));
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
    int main()
    {
    int N,i,j,k;
    scanf("%d",&N);
    int data[N];
    j=0;
    k=100;
    for(i=0;i<N;i++){
    scanf("%d",&data[i]);
    j += data[i];
      if(data[i] % 10 != 0 && data[i]<k){
      k=data[i];
      }
    }
    if(j % 10 != 0){
    printf("%d\n",j);
    }else if(k!=100){
    printf("%d\n",j-k);
    }else{
    printf("0\n");
    }
    return 0;
    }

Measured memory_bytes: 128
s = list(input())
t = list(input())

n, m = len(s), len(t)

dp = [[0] * (m + 1) for _ in range(n + 1)]

for i in range(n):
	for j in range(m):
		if s[i] == t[j]:
			dp[i + 1][j + 1] = dp[i][j] + 1
		else:
			dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])

res = []
while n != 0 and m != 0:
	if dp[n][m] == dp[n - 1][m]:
		n -= 1
	elif dp[n][m] == dp[n][m - 1]:
		m -= 1
	else:
		n -= 1
		m -= 1
		res.append(s[n])

print(''.join(res[::-1]))

Measured memory_bytes: 113500
#include<iostream>
#include<cmath>
#define MAX_X 1000

using namespace std;

int main()
{
       int X;
       
       int temp;
	   int b;
	
	   cin>>X;
		int min=X;
 

		if(X==1)
		{
			cout<<1;
			return 0;
		}

	   if(X>2)
	   {
		   for(b=2;b*b<X;b++)
		   {
			  temp=b;
			  while(temp<=X)
			  {
				   temp=temp*b;
			  }
			
			  temp=X-temp/b;
			  if(temp<min)    
					min=temp;
			}
	   }

          cout<<X-min;
          return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include<algorithm> 
using namespace std;
// main() is where program execution begins.


int main() {
string s, t, res;

cin >> s;
cin >> t;
int m = s.size()+1;
int n = t.size()+1;
int i, j;

int dp[m][n];
for (int i = 0; i < n; ++i)
{
	dp[0][i] = 0;
}

for (int i = 0; i < m; ++i)
{
	dp[i][0] = 0;
}

for (int i = 1; i < m ; ++i)
{
	for (int j = 1; j < n; ++j)
	{
		if(s[i-1] == t[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
		else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
	}
}

i = m-1;
j = n-1;
res = "";
while(dp[i][j] != 0){

	if(dp[i][j] != max(dp[i-1][j], dp[i][j-1])){ res = res + s[i-1]; i = i-1; j = j-1;}
	else if(dp[i][j] == dp[i-1][j]){i = i-1;}
	else j = j-1;
}
char tmp;
for (int i = 0; i < res.size()/2; ++i)
{
	tmp = res[i];
	res[i] = res[res.size()-i-1];
	res[res.size()-i-1] = tmp;
}

cout << res << endl;
return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
#include <random>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
typedef pair<int,int>PI; typedef vector<int> VI;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;
struct UnionFind{
    vector<int> par; //par: -1*elements(root) number of par(not root)
    UnionFind(int n){
        par = vector<int>(n,-1);
    }
    inline int root(int x){
        if(par[x]<0){
            return x;
        }else{
            return par[x]=root(par[x]);
        }
    }
    void unite(int x,int y){
        x=root(x);
        y=root(y);
        if(x!=y){
            if(par[x]<par[y]) swap(x,y);
            par[y] += par[x];
            par[x] = y;
        }
        return;
    }
    inline bool same(int x,int y){
        return root(x) == root(y);
    }
    int size(int x){
        return -par[root(x)];
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k,l;
    cin >> n >> k >> l;
    UnionFind road(n), rail(n);
    REP(i,k){
        int a,b;
        cin >> a >> b;
        road.unite(--a,--b);
    }
    REP(i,l){
        int a,b;
        cin >> a >> b;
        rail.unite(--a,--b);
    }
    map<PI,int> p;
    REP(i,n){
        p[{road.root(i),rail.root(i)}]++;
    }
    REP(i,n){
        cout<< p[{road.root(i),rail.root(i)}]<<(i!=n-1?" ":"\n");
    }
    return 0;
}


Measured memory_bytes: 13568
s=input()
i=0
flag=0
while i<len(s):
    if (i+1)%2==0:
        if s[i] =="L" or s[i] =="U" or s[i] =="D":
            pass
        else:
            flag+=1
         
    else:
        if s[i] =="R" or s[i] =="U" or s[i] =="D":
            pass
        else:
            flag+=1
     

    if flag==1:
        break


    i+=1

if flag==1:
    print("No")
else:
    print("Yes")

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

int main() {
	int N;
	cin >> N;
	cout << ((N & 1) == 0 ? N : N << 1);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

Nが偶数ならN, 奇数なら2Nを出力すれば良い
*/

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
using namespace std;

ll gcd(ll a, ll b){
	ll q = max(a, b);
	ll r = min(a, b);
	while (r){
		ll t = q;
		q = r;
		r = t % r;
	} return q;
}

int main(){
	ll n,g; cin >> n;
	vl a(n), b(n), vte(n), etv(n); cin >> a[0];
	g = a[0];
	vte[0] = a[0];
	for (ll i = 1; i < n; ++i){
		cin >> a[i];
		g = gcd(g, a[i]);
		vte[i] = g;
	}
  	g = a[n - 1];
	etv[0] = a[n - 1];
	for (ll i = 1; i < n; ++i){
		g = gcd(g, a[n - 1 - i]);
		etv[i] = g;
	}

	ll ans = g;
	for (ll i = 0; i < n ; ++i){
		if (i == 0) ans = max(ans, etv[n - 2]);
		else if (i == n - 1) ans = max(ans, vte[n - 2]);
		else ans = max(ans, gcd(vte[i - 1], etv[n - 2 - i]));
	}
  	cout << ans << endl;
	
}


Measured memory_bytes: 3328
class UnionFind():
    def __init__(self, n):
        self.parent = [-1]*n

    #aの属する集合の根を取得
    def root(self,a):
        if self.parent[a] < 0:return a
        self.parent[a] = self.root(self.parent[a])
        return self.parent[a]
    
    #aの属する集合の要素数を取得
    def size(self,a):
        return -self.parent[self.root(a)]

    #aとbをくっつける
    def connect(self,a,b):
        if self.root(a) == self.root(b):return False
        a = self.root(a);b = self.root(b)
        if self.size(a) < self.size(b):a,b = b,a
        self.parent[a] += self.parent[b]
        self.parent[b] = a
        return True

def hiku(n):
    return n-1

n,m = map(int,input().split())
a = [0]*m;b = [0]*m
for i in range(m):
    a[i],b[i] = map(hiku,map(int,input().split()))
ans = n*(n-1)//2
uni = UnionFind(n)
ansls = []
for i in range(m-1,-1,-1):
    ansls.append(ans)
    if uni.root(a[i]) != uni.root(b[i]):
        ans -= uni.size(a[i]) * uni.size(b[i])
        uni.connect(a[i],b[i])
for i in range(m-1,-1,-1):
    print(ansls[i])

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

int main (void){
  
  int K,A,B;
  scanf("%d%d%d",&K,&A,&B);
  int count=0;
  
  for(int i=A;i<=B;i++){
    if(i % K == 0) count++;
  }
  
  if (count>0) printf("OK");
  else printf("NG");
  
  return 0;
}

Measured memory_bytes: 1684
N = int(input())
A = list(input())
B = list(input())
C = list(input())

operations = 0
for i in range(N):
    if A[i] == B[i] and B[i] == C[i]:
        continue
    elif A[i] == B[i] or B[i] == C[i] or C[i] == A[i]:
        operations += 1
    else:
        operations += 2

print(operations)


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

namespace ALDS1_1_C
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			List<int> vs = new List<int>();

			for(int i = 0; i < n; i++) {
				vs.Add(int.Parse(Console.ReadLine()));
			}

			Console.WriteLine(vs.Count(x => PrimeNumber(x)));
		}

		private static bool PrimeNumber(int number)
		{
			if(number < 2) {
				return false;
			}
			if(number == 2) {
				return true;
			}
			if(number % 2 == 0) {
				return false;
			}

			double s = Math.Sqrt(number);
			for(int i = 3; i <= s; i += 2) {
				if(number % i == 0) {
					return false;
				}
			}

			return true;
		}
	}
}



Measured memory_bytes: 18312
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr0(i,n) for(ll i=0 ; i!=n ; i++)
#define fr1(i,n) for(ll i=1 ; i<=n ; i++)
#define testcase ll t; cin>>t; while(t--)
#define mod 1000000007
#define debug cout<<"\nAAAAAAAAAAAAAAAAAAAAAAAAA\n";

using namespace std;


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

  ll a,b,c;
  cin>>a>>b>>c;

  ll odd = a^b;
  odd^=c;

  cout<<odd;

}


Measured memory_bytes: 256