akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
//#define INF 1000000007
#define ARRAY_MAX 1005
const int INF = 1e9+7;

int h,w,n;
char mp[ARRAY_MAX][ARRAY_MAX];
int mini[ARRAY_MAX][ARRAY_MAX];
int sx,sy;

int bfs(int y,int x,int goal){
    //y座標、x座標、食べられるチーズを作る工場

    for(int i = 0;i < ARRAY_MAX;i++){
        for(int j = 0;j < ARRAY_MAX;j++){
            mini[i][j] = -1;
        }
    }
    queue<pii> que;
    que.push(pii(y,x));
    mini[sy][sx] = 0;

    while(!que.empty()){

        pii now = que.front();
        que.pop();
        int now_y = now.first;
        int now_x = now.second;
        if(mp[now_y][now_x] == '0'+goal){
            sy = now_y;
            sx = now_x;//次の始点が今の終点になる。
            return mini[now_y][now_x];
        }

        for(int i = 0;i < 4;i++){
            int ny = now_y + dy[i];
            int nx = now_x + dx[i];
            if(0 <= ny && ny < h && 0 <= nx && nx < w && mp[ny][nx] != 'X' && mini[ny][nx] == -1){
                mini[ny][nx] = mini[now_y][now_x] + 1;
                que.push(pii(ny,nx));
            }
        }
    }
}

int main(){

    cin >> h >> w >> n;
    for(int i = 0;i < h;i++){
        scanf("%s",mp[i]);
    }

    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(mp[i][j] == 'S'){
                sy = i;
                sx = j;
                break;
            }
        }
    }

    int ans = 0;

    for(int i = 1;i <= n;i++){
        ans += bfs(sy,sx,i);
    }
    cout << ans << endl;

    return 0;
}



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

int main(void) {

  while(true){
    int a, b;
    char op;
    cin >> a >> op >> b;
    if(op == '?')
      break;
    else if(op == '+')
      cout << a + b << endl;
    else if(op == '-')
      cout << a - b << endl;
    else if(op == '*')
      cout << a * b << endl;
    else
      cout << int(a / b) << endl;
  }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N, M;
    cin >> N >> M;
    vec<vec<int>> G(N,vec<int>());
    
    rep(i,M){
        int a,b;
        cin >> a >> b;
        --a,--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    bool ans = false;
    auto dfs = [&](int i) {
        for (auto e : G[i]) {
            if(e==(N-1)) ans = true;
        }
    };

    for(auto e:G[0]){
        if(e==(N-1)) ans = true;
        else dfs(e);
    }

    cout << (ans?"POSSIBLE":"IMPOSSIBLE") << endl;    
}


Measured memory_bytes: 14936
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	
	public Main() {
		FastScanner scanner = new FastScanner();
		int N = scanner.nextInt();
		
		long[] A = new long[N];
		for (int i = 0; i < N; i++) {
			A[i] = scanner.nextLong();
		}
		
		long max = 0, sum = 0;
		for (int i = 0; i < N; i++) {
			if (max <= A[i]){
				max = A[i];
			} else {
				sum += max - A[i];
			}
		}
		System.out.println(sum);
	}
	
	public static void main(String[] args) {
		new Main();
	}
}

class FastScanner {
	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() {
		if (hasNextByte()) return buffer[ptr++];
		else return -1;
	}
	
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
		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 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();
		}
	}
	
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 35972
package main

import "fmt"

func min(x int, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func max(x int, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

func sortThreeNumber(a int, b int, c int) (int, int, int) {
	minimum := min(min(a, b), c)
	maximum := max(max(a, b), c)
	middle := 0

	if a == minimum && b == maximum {
		middle = c
	} else if a == minimum && c == maximum {
		middle = b
	} else if b == minimum && a == maximum {
		middle = c
	} else if c == minimum && a == maximum {
		middle = b
	} else {
		middle = a
	}

	return minimum, middle, maximum
}

func main() {
	var a, b, c int

	fmt.Scan(&a, &b, &c)
	fmt.Println(sortThreeNumber(a, b, c))
}



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

int fib(int num) {
	if (num == 0)
	{
		return 0;
	}
	else
	{
		return fib(num - 1) + num;
	}
}
int main()
{
	int a = 0;
	cin >> a;
	cout << fib(a);
	//cin >> a;
    return 0;
}


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

int main(){
    ll N, L;
    cin >> N >> L;
    ll sum = 0;
    rep(i, 1, N+1) sum += L + i - 1;
    ll diff = 1e18, ans;
    rep(i, 1, N+1){
        if(diff > abs(sum - (sum - (L + i - 1)))){
            diff = abs(sum - (sum - (L + i - 1)));
            ans = sum - (L + i - 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef pair<int,int>P;
P moon[100001];
int main(void)
{
	int n,i,a;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a);
		moon[i].first=a;
		moon[i].second=i;
	}
	sort(moon+1,moon+n+1);
	for(i=1;i<=n;i++){
		if(i!=n){
			printf("%d ",moon[i].second);
		}
		else	printf("%d\n",moon[i].second);
	}
	return 0;
}

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

int main(){
    ll n;
    long double ans=0;
    long double bitcoin=0;
    long double money;
    string unit;
    cin>>n;
    rep(i,n){
        cin>>money>>unit;
        if(unit=="JPY"){
            ans+=money;
        }else{
            bitcoin+=money;
        }
    }

    ans+=bitcoin*380000.0;

    // cout<<bitcoin<<endl;
    cout<<ans<<endl;
}



Measured memory_bytes: 3708
INF = int(1e9)
def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    n = len(A)
    L = A[left:mid] + [INF] 
    R = A[mid:right] + [INF]
    i = 0
    j = 0
    cnt = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
            cnt = cnt + n1 - i
    return cnt

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left+right)//2
        cnt1 = mergeSort(A, left, mid)
        cnt2 = mergeSort(A, mid, right)
        cnt3 = merge(A, left, mid, right)
        return (cnt1 + cnt2 + cnt3)
    else: 
        return 0

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = mergeSort(a, 0, n)
    print(ans)
main()


Measured memory_bytes: 27500
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
#define MAX_N 3'000
#define MAX_T 3'000
int a[MAX_N+1], b[MAX_N+1];
ll mem[2][MAX_T+1][2];
ll& opt(int n, int t, bool seen) {
    return mem[n & 1][t][seen];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, T, S;
    cin >> N >> T >> S;
    for(int i = 1; i <= N; i++) {
        cin >> a[i] >> b[i];
    }
    for(int n = 0; n <= N; n++) {
        for(int t = 0; t <= T; t++) {
            for(bool seen : {1, 0}) {
                ll& ans = opt(n, t, seen);
                if(n == 0) {
                    ans = 0;
                } else {
                    ans = opt(n - 1, t, seen);
                    if(seen) {
                        if(b[n] <= t) {
                            ans = max(ans, opt(n - 1, t - b[n], seen) + a[n]);
                        }
                    } else {
                        ans = max(ans, opt(n, S, true));
                        if(S + b[n] <= t) {
                            ans = max(ans, opt(n - 1, t - b[n], seen) + a[n]);
                        }
                    }
                }
            }
        }
    }
    cout << opt(N, T, false) << endl;
    return 0;
}




Measured memory_bytes: 3308
### constant

MAX_N = 1024

### main

dists = []
st = 1
dists[st] = 0
q = [[st, [st]]]

while ! q.empty?
  u = q.shift
  ui, uds = u

  ud = dists[ui]
  nvd = ud + 1

  for d in uds
    vi = ui + d
    if vi <= MAX_N
      if dists[vi].nil?
        dists[vi] = nvd
        q << [vi, uds + [vi]]
      elsif dists[vi] == nvd
        q << [vi, uds + [vi]]
      end
    end

    vi = (ui - d).abs
    if vi >= 1
      if dists[vi].nil?
        dists[vi] = nvd
        q << [vi, uds + [vi]]
      elsif dists[vi] == nvd
        q << [vi, uds + [vi]]
      end
    end
  end
end
#p dists

loop do
  n = gets.to_i
  break if n == 0

  puts dists[n]
end

Measured memory_bytes: 89696
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
 
import itertools
n,m,q=n1()
s=n3(q)
 
Alist=list(itertools.combinations_with_replacement(range(1,m+1), n))
ans=0
for A in Alist:
    tmp=0
    for r in s:
        if A[r[1]-1]-A[r[0]-1]==r[2]:
            tmp+=r[3]
    ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 84700
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;


class Program {

	const long mod = 1000000007;
	//public static int[] max;

	static public  List<int> va=new List<int>();
	static void Main(string[] args) {

		char[] cs = new char[] { ' ', ',' };
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res="";
		//int res = 0; ;
		//int t = int.Parse(Console.ReadLine());
		//string str = Console.ReadLine();
		///int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int n = int.Parse(Console.ReadLine());

		//int num = vals[0];

		int res = 0;
		int n = int.Parse(Console.ReadLine());
		int[] vals = parseAry(Console.ReadLine().Split(cs));

		Array.Sort(vals);
		va = new List<int>(vals);

		while ( va.Count > 0 ) {
			if ( va.Count <= 1 ) { break; }

			int v = va[va.Count-1];
			va.RemoveAt(va.Count - 1);
			int x = v;
			int c = -1;
			if (v == 0) {return;};
    v |= (v >> 1);
    v |= (v >> 2);
    v |= (v >> 4);
    v |= (v >> 8);

    v |= (v >> 16);
			c=(int)numofbits5(v);

			int find = (1<<(int)c) - x;
			int k = Binary_SearchX(find);
			if ( k != -1 ) {
				va.RemoveAt(k);
				res++;
			}
		}
			Console.WriteLine(res);

		return;
	}
	static long numofbits5(long bits) {
		bits = ( bits & 0x55555555 ) + ( bits >> 1 & 0x55555555 );
		bits = ( bits & 0x33333333 ) + ( bits >> 2 & 0x33333333 );
		bits = ( bits & 0x0f0f0f0f ) + ( bits >> 4 & 0x0f0f0f0f );
		bits = ( bits & 0x00ff00ff ) + ( bits >> 8 & 0x00ff00ff );
		return ( bits & 0x0000ffff ) + ( bits >> 16 & 0x0000ffff );
	}


	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = long.Parse(str[i]); }
		return nums;
	}

	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { re[i] = str[i].ToString(); }
		return re;
	}

	static public int Binary_SearchX(int x) {
		int Lower = 0;
		int Upper = va.Count - 1;
		while ( Lower <= Upper ) {
			int Center = ( Lower + Upper ) >> 1;
			if ( x > va[(int)Center] ) {
				Lower = Center + 1;
			} else if ( x < va[(int)Center] ) {
				Upper = Center - 1;
			} else {
				return (int)Center;
			}
		}
		return -1;
	}
}

Measured memory_bytes: 28636
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))

def lcm(a,b): return a*b//gcd(a,b)

l = A[0]
for i in range(1,N):
    l = lcm(l,A[i])
l -= 1

ans = 0
for a in A: ans += l % a
print(ans)

Measured memory_bytes: 5344
#define USE_MATH_DEFINES 1
#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 MOD 998244353ll
#define INF 1000000000000000000ll
#define EPS 1e-9

#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock

typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;

string S;


int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> S;
	
	if (S == "ABC") cout << "ARC";
	else cout << "ABC";
	
    return 0;
}


Measured memory_bytes: 3608
/*
How to lambda
  ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound
  1 2 2 2 3 3 
    ^lb   ^ub */
#include <bits/stdc++.h>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob push_back
#define LB(b,e,v) lower_bound(b,e,v)
#define UB(b,e,v) upper_bound(b,e,v)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
ll N,M;
string S,T;
int gcd(int x,int y) {
  return x%y==0?y:gcd(y,x%y);
}
void fail(){
  cout << -1 << endl;
  exit(0);
}
int main() {
  cout << fixed << setprecision(10);
  cin >> N >> M >> S >> T;
  ll G = gcd(N,M);
  bool bad=false;
  for(int i=0;i<G;++i)
    if (S[i*N/G]!=T[i*M/G])
      bad=true;
  if (bad)
    cout << -1 << endl;
  else
    cout << N * M / G << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include <set>

#define DIV 1000000007
using namespace std;
using ll = long long;

queue<int> q;
typedef struct {
    vector<pair<int,ll>> edge;
    ll dis;
    int visit;
}node_t;
vector<node_t> node;

void bfs() {
    int x = q.front();
    q.pop();
    
    for (auto ed : node[x].edge) {
        if (node[ed.first].visit) continue;
        node[ed.first].visit = 1;
        node[ed.first].dis = node[x].dis + ed.second;
        q.push(ed.first);
    }

    if (!q.empty())
        bfs();
}
int main() {
    int N;
    cin >> N;

    node = vector<node_t>(N + 1);
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        node[u].edge.push_back(make_pair(v, w));
        node[v].edge.push_back(make_pair(u, w));
    }

    node[1].visit = 1;
    q.push(1);
    bfs();
    for (int i = 1; i <= N; i++) {
        if (node[i].dis % 2 == 0)
            cout << 0 << endl;
        else
            cout << 1 << endl;
    }
}


Measured memory_bytes: 14080
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

string s;
string a = "AKIHABARA";

int main() {
	cin >> s;
	if (s.length() > a.length()) {
		cout << "NO" << endl;
		return 0;
	}
	int t = 0;
	for (int i = 0; i < a.length(); ++i) {
		if (s[t] != a[i]) {
			if (a[i] != 'A') {
				cout << "NO" << endl;
				return 0;
			}
		}
		else ++t;
	}
	cout << "YES" << endl;
	return 0;
}

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

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define rep(i,a,b) for(int i = a ; i <= b ; i++)
#define per(i,a,b) for(int i = b ; i >= a ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const LL INF = 1e18;
const int mod = 2010;
const int maxn = 2e5 + 7;

int a[maxn];

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
    return 0;
}


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

A = [input() for _ in range(N)]
B = "".join([input() for _ in range(M)])

for i in range(N - M + 1):
    for j in range(N - M + 1):
        A_ = "".join([A[k][j:(j+M)] for k in range(i, i + M)])
        if B == A_:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3064
#include <stdio.h>
void print_array(int a[], int n){
int i = 0;
    for(i = 0; i<n-1; i++)
        printf("%d ",a[i]);
    printf("%d\n",a[i]);
}
//inserion sort 
void insertion_sort(int a[], int n){
    for(int i = 1; i<n; i++){
        int key = a[i];
        /* insert A[i] into the sorted sequence A[0,...,j-1] */
        int j = i-1;
        while(j>=0 && a[j]>key){
            a[j+1] = a[j];
            j--;
            
        }
        a[j+1] = key;
        print_array(a,n);
    }
}

int main()
{
    int n = 0;
    scanf("%d",&n);
    int a[n+1];
    for(int i = 0; i<n; i++){
        scanf("%d",&a[i]);
    }
    print_array(a,n);
    insertion_sort(a,n);
    
    return 0;
}



Measured memory_bytes: 2752
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
    ll n;
    vector<pair<ll, ll> > pvec;
    cin >> n;
    for (ll i = 0; i < n; ++i) {
        ll ai, bi;
        scanf("%lld %lld", &ai, &bi);
        pvec.emplace_back(make_pair(bi, ai));
    }
    sort(pvec.begin(), pvec.end());
    ll cur_t = 0;
    bool tf = true;
    for (ll i = 0; i < n && tf; ++i) {
        ll a = pvec[i].second, b = pvec[i].first;
        cur_t += a;
        if (cur_t <= b) continue;
        else tf = false;
    }

    if (tf) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 6384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define loop(i,f,n) for(int i=(f);i<(n);i++)
bool check(int x)
{
	if (x == 0 || x % 10 != 0)return true;
	else return false;
}
int main()
{
	int n;
	cin >> n;
	vector<int> s(n);
	loop(i, 0, n)cin >> s[i];
	vector<bool> dp(10001, false);
	dp[0] = true;
	dp[s[0]] = true;
	loop(i, 1, n)
	{
		for (int j = 10000; j >= 0; j--)
		{
			if (dp[j])dp[j + s[i]] = true;
		}
	}
	//loop(i, 0, 51)cout << i << " " << dp[i] << endl;
	int ans = 0;
	loop(i, 0, 10001)
	{
		if (dp[i] && check(i))ans = max(ans, i);
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int n=0;
    string str;
    while(cin >> str){
        bool flag = true;
        for(int i=0;i<str.size()/2;i++){
            if(str[i] != str[str.size()-1-i])
                flag = false;
        }
        if(flag)
            n++;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <algorithm>
#define MAX_N 1000001
using namespace std;

vector<bool> p(MAX_N);
int a, d, n;

bool isPrime(int x){
  if(x <= 1) return false;

  for(int i = 2; i * i <= x; ++i) {
    if(x % i == 0) return false;
  }
  return true;
}

int solve() {
  int cnt = 0;
  for(int i = 0;; ++i) {
    int nx = a + i * d;
    if(nx > 2 && nx % 2 == 0) continue;
    if(p[nx]) cnt++;

    if(cnt == n) return nx;
  }
}

int main() {
  for(int i = 0; i < MAX_N; ++i) {
    if(isPrime(i)) p[i] = true;
    else p[i] = false;
  }
  while(cin >> a >> d >> n && a && d && n) {
    cout << solve() << endl;
  }
  return 0;
}



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

using namespace std;

class build
{
public:
    build(int s)
    {
        n = s;
        for(int i = 0;i < 10;i++)
        {
            f1[i] = 0;
            f2[i] = 0;
            f3[i] = 0;
        }
    }
    void    set(int fn,int rn,int mn);
    int     get(int fn,int rn);
    int n;
    int f1[10];
    int f2[10];
    int f3[10];
};

void build::set(int fn, int rn, int mn)
{
    switch(fn)
    {
    case 1:
        f1[rn] += mn;
        break;
    case 2:
        f2[rn] += mn;
        break;
    case 3:
        f3[rn] += mn;
        break;
    default:
        break;
    }
}

int build::get(int fn, int rn)
{
    switch(fn)
    {
    case 0:
        return f1[rn];
    case 1:
        return f2[rn];
    case 2:
        return f3[rn];
    default:
        break;
    }

    return 0;
}

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

    build a(1);
    build b(2);
    build c(3);
    build d(4);

    for(int i = 0;i < n;i++)
    {
        int bn;
        int fn;
        int rn;
        int mn;
        cin >> bn >> fn >> rn >> mn;
        switch(bn)
        {
        case 1:
            a.set(fn,rn - 1,mn);
            break;
        case 2:
            b.set(fn,rn - 1,mn);
            break;
        case 3:
            c.set(fn,rn - 1,mn);
            break;
        case 4:
            d.set(fn,rn - 1,mn);
        default:
            break;
        }
    }

    for(int i = 0;i < 3;i++)
    {
        for(int j = 0;j < 10;j++)
        {
            cout << " " << a.get(i,j);
        }
        cout << endl;
    }
    cout << "####################" << endl;
    for(int i = 0;i < 3;i++)
    {
        for(int j = 0;j < 10;j++)
        {
            cout << " " << b.get(i,j);
        }
        cout << endl;
    }
    cout << "####################" << endl;
    for(int i = 0;i < 3;i++)
    {
        for(int j = 0;j < 10;j++)
        {
            cout << " " << c.get(i,j);
        }
        cout << endl;
    }
    cout << "####################" << endl;
    for(int i = 0;i < 3;i++)
    {
        for(int j = 0;j < 10;j++)
        {
            cout << " " << d.get(i,j);
        }
        cout << endl;
    }

    return 0;
}

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

int main() {
    
    int n;
    cin>>n;
    int x[n];
    
    int s=0;

    for(int i=0;i<n;i++){
        cin>>x[i];
        if(x[i]%2==0 && (x[i]%3!=0 && x[i]%5!=0))s=1;
    }
    
    if(s==0)cout<<"APPROVED";
    else cout<<"DENIED";
    
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int n,a[100000],ans=0;
		scanf("%d",&n);
	for(int i=1;i<=2*n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+2*n);
	for(int i=1;i<=2*n;i+=2)
		ans+=a[i];
	printf("%d\n",ans);
	return 0;
 } 

Measured memory_bytes: 128
/*  ex7-1
    toshiwaka */

//point構造体
typedef struct point{
    int x_elem;
    int y_elem;
}point;

//ref_pointからx,y軸方向にshift_x,shift_yだけそれぞれ移動
//移動後の点の座標をshifted_pointのメンバに代入
void shift_point(point *shifted_point, point *ref_point, int shift_x, int shift_y);

#include <stdio.h>

int main(void) {
  //point:正方形の頂点
  //diff:2点間のx,y軸方向の距離
  point point[4], diff;

  //入力
  scanf("%d %d %d %d", &point[0].x_elem, &point[0].y_elem, &point[1].x_elem, &point[1].y_elem);

  //2点間のx,y軸方向の距離
  diff.x_elem = point[1].x_elem - point[0].x_elem;
  diff.y_elem = point[1].y_elem - point[0].y_elem;

  //残りの２点を算出
  shift_point(&point[2], &point[1], -1 * diff.y_elem, diff.x_elem);
  shift_point(&point[3], &point[0], -1 * diff.y_elem, diff.x_elem);

  //出力
  printf("%d %d %d %d\n", point[2].x_elem, point[2].y_elem, point[3].x_elem, point[3].y_elem);

  return 0;
}


//ref_pointからx,y軸方向にshift_x,shift_yだけそれぞれ移動
//移動後の点の座標をshifted_pointのメンバに代入
void shift_point(point *shifted_point, point *ref_point, int shift_x, int shift_y){
  shifted_point->x_elem = ref_point->x_elem + shift_x;
  shifted_point->y_elem = ref_point->y_elem + shift_y;
};

Measured memory_bytes: 1704
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    s = f.read_str()
    if 'L' in s[::2]:
        return "No"
    if 'R' in s[1::2]:
        return "No"
    return "Yes"


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 33384
/*
         ██╗ ██████╗ ██╗███╗   ██╗    ██╗   ██╗███████╗
         ██║██╔═══██╗██║████╗  ██║    ██║   ██║██╔════╝
         ██║██║   ██║██║██╔██╗ ██║    ██║   ██║███████╗
    ██   ██║██║   ██║██║██║╚██╗██║    ██║   ██║╚════██║
    ╚█████╔╝╚██████╔╝██║██║ ╚████║    ╚██████╔╝███████║
     ╚════╝  ╚═════╝ ╚═╝╚═╝  ╚═══╝     ╚═════╝ ╚══════╝
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
ll st[maxn],tot;
struct lb
{
    const ll MAXL = 60;
    vector<ll> a;
    lb()
    {
        for (int i = 0; i < 64; i++)
            a.push_back(0);
    }
    void insert(ll t)
    {
        for(int i=0;i<tot;i++)
        {
            if((t>>st[i])&1)
            {
                if(a[i]) t^=a[i];
                else {a[i]=t;break;}
            }
        }
    }
    ll query_max()
    {
        ll res = 0;
        for(int i=0;i<tot;i++)
        {
            if(!((res>>st[i])&1)) res^=a[i]; 
        }
        return res;
    }
    ll query_min()
    {
        return a[0];
    }
} lb;

int main()
{
    int n;
    scanf("%d", &n);
    ll ans=0;
    vector<ll>ass;
    for (int i = 1; i <= n; i++)
    {
        ll x;
        scanf("%lld", &x);
        ans^=x;
        ass.push_back(x);
    }
    for(int i=60;i>=0;i--)
    {
        if(!((ans>>i)&1)) st[tot++]=i;
    }
    for(auto it:ass)
    {
        lb.insert(it);
    }
    ll qaq=lb.query_max();
    // cout<<qaq<<" "<<ans<<endl;
    printf("%lld\n",qaq+(qaq^ans));
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	
	int i;
	int* R = (int*)malloc(sizeof(int)*n);
	for(i=0;i<n;i++){
		cin >> R[i];
	}
	
	int min_num = R[0];
	int max_result = INT_MIN;
	for(i=1;i<n;i++){
		max_result = max(max_result,R[i]-min_num);
		if(R[i]<min_num){
			min_num = R[i];
		}
		
	}
	cout << max_result << endl;
	return 0;
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();
    
    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();

    vector<VL> dp(n + 1, VL(m + 1, 0));
    dp[0][0] = 1;
    FOR(i, 0, n)FOR(j, 0, m) {
        if (s[i] == t[j])(dp[i + 1][j + 1] += dp[i][j]) %= mod;
        (dp[i + 1][j] += dp[i][j]) %= mod;
    }

    ll ans = 0;
    eFOR(i, 1, n)(ans += dp[i][m]) %= mod;
    cout << ans << "\n";
}


Measured memory_bytes: 10708
import qualified Data.Map as Map
import Control.Monad
import Control.Monad.ST
import Data.STRef

main :: IO ()
main = do
  [n, m] <- (map read . words) <$> getLine :: IO [Int]
  (graph, edges) <- buildGraph (Map.fromList [] ) [] m
  print $ length [True | rm <- edges, bfs graph 1 rm < n]

buildGraph graph edges 0 = return (graph, edges)
buildGraph graph edges n = do
  [a, b] <- (map read . words) <$> getLine :: IO [Int]
  let graph' = Map.insertWith (++) a [b] graph
  let graph'' = Map.insertWith (++) b [a] graph'
  buildGraph graph'' ((a, b):edges) (n - 1)

-- あるノードから辿れるノードの総数を求める
bfs :: Map.Map Int [Int] -> Int -> (Int, Int) -> Int
bfs graph start rm = runST $ do
  visitedRef <- newSTRef (Map.fromList [] :: Map.Map Int Bool)
  count <- newSTRef (0 :: Int)
  let queue = [start]
      loop [] = return ()
      loop queue = do
        let p:queue' = queue
        let maybeNeighbors = Map.lookup p graph
        case maybeNeighbors of
          Nothing -> undefined
          Just neighbors ->
            forM_ neighbors $ \n -> do
              visited <- readSTRef visitedRef
              let v = Map.lookup n visited
              case v of
                Just True -> return ()
                Nothing ->
                  if (p == fst rm && n == snd rm) || (p == snd rm && n == fst rm)
                    then return ()
                    else do
                      let visited' = Map.insert n True visited
                      writeSTRef visitedRef visited'
                      modifySTRef count (+1)
                      loop (queue' ++ [n])

  loop queue
  readSTRef count

Measured memory_bytes: 1020
S = input()
Slen = len(S)
zo = [str(i%2) for i in range(Slen)]
zeroone = (Slen - sum([zo[i] == S[i] for i in range(len(S))]))
oz = [str((i+1)%2) for i in range(Slen)]
onezero = (Slen - sum([oz[i] == S[i] for i in range(len(S))]))
print(min(zeroone, onezero))

Measured memory_bytes: 16484
#include<stdio.h>
#include<math.h>
 
int main(){
    long int n,i,j,t;
    char data[10];

    scanf("%ld",&n);
     
    for(;n>0;n--){
        scanf(" %s ",data);
         
        for(i=0;i<8;i++){
            for(j=i;j<8;j++){
                if(data[i]<data[j]){
                    t=data[i];
                    data[i]=data[j];
                    data[j]=t;
                }
            }
        }

        t=0;
         
        for(i=0;i<8;i++){
            t+=((int)data[i]-48)*(int)pow(10,7-i);
            t-=((int)data[i]-48)*(int)pow(10,i);
        }

        printf("%ld\n",t);
    }
    return 0;
}

Measured memory_bytes: 644
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = FL;
		var l = new List<long>();
		while (N != 0)
		{
			int r = N % 2 == 0 ? 0 : 1;
			N = (N - r) / (-2);
			l.Add(r);
		}
		l.Reverse();
		if (l.Count == 0) l.Add(0);
		WriteLine(string.Join("", l));
	}
}


Measured memory_bytes: 13268
//by xiqiao
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int p[55],m;
int x[10005],head=201,tail=200,num;
void get(ll n){
	if(n==0)return;
	if(n&1){
		get(n/2);
		x[++tail]=++num;
	}
	else{
		get(n-1);
		x[--head]=++num;
	}
}
int main(){
	cin>>n;
	get(n);
	printf("%d\n",num*2);
	for(int i=head;i<=tail;i++)cout<<x[i]<<" ";
	for(int i=1;i<=num;i++)cout<<i<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
import math

cooking_times = [int(input()) for _ in range(5)]

last_order_index = None
last_order_time = 10
for i, cooking_time in enumerate(cooking_times):
    ones_place = int(str(cooking_time)[-1])
    if last_order_time > ones_place != 0:
        last_order_time = ones_place
        last_order_index = i

time = 0
for i, cooking_time in enumerate(cooking_times):
    if i == last_order_index:
        time += cooking_time
    else:
        time += int(math.ceil(cooking_time / 10) * 10)

print(time)

Measured memory_bytes: 3064
(lambda NK,S:
    (lambda N,K,O:
        (lambda P:
            (lambda Sdash:print(
                    sum(map(
                            lambda i:(lambda j:(0<=j<N)and(Sdash[i]==Sdash[j]))(i-1+(Sdash[i]=="R")*2)
                            ,
                            range(N)
                    ))
            ))(''.join(
                [
                    (
                        lambda val,key:[val,("R"if val[0]=="L"else"L")*len(val)][key%2 and key//2<P]
                    )(O[k],k)
                        for k in range(len(O))]
            ))
        )(
            min(len(O)//2,K)
        )
    )(
        NK[0],NK[1],__import__("re").findall(r"(R+|L+)",S)
    )
)(
    tuple(map(int,input().split())),input()
)

Measured memory_bytes: 6336
k, n = list(map(int,input().split()))
a = list(map(int,input().split()))

dist = []

for i in range(0, n-1):
  dist.append(a[i + 1] - a[i])
dist.append(k - a[n - 1] + a[0])

answer = max(dist)

print(k - answer)

Measured memory_bytes: 26444
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define reps2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;


int main(){
    int n;
    char str[8];
    cin >> str;
    cout << ((str[2] == str[3] && str[4] == str[5]) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <cstdio>
#include <string>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>

using namespace std;

long long int mod = 1000000007;

int main(){
    int n;
    cin>>n;
    string s[2];
    cin>>s[0]>>s[1];
    long long int ans;
    if(s[0][0] == s[1][0]){
        ans = 3;
    }else{
        ans = 6;
    }
    for(int i = 1; i < n; i++){
        if(s[0][i] == s[1][i]){
            if(s[0][i-1] == s[1][i-1]){
                ans *= 2;
            }
        }else{
            if(s[0][i-1] == s[1][i-1]){
                ans *= 2;
            }else if(s[0][i] != s[0][i-1]){
                ans *= 3;
            }
        }
        ans %= mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
def calc(value, replacement)
  value.each{
    |v| v.gsub!("X", replacement) 
  }
  return true   if  value[0].to_i + value[1].to_i == value[2].to_i
end
 
def head(str)
  str[0, 1]
end
 
def checkWrong(value)
  return (head(value[0]) == "0" && value[0].size > 1) || (head(value[1]) == "0" && value[1].size > 1) || (head(value[2]) == "0" && value[2].size > 1)
end
 
while input = gets
  x = "NA"
  for replacement in 0..9
    value = input.chomp.scan(/[^(\+=)]+/)
    if  calc(value, replacement.to_s) && !checkWrong(value)
      x = replacement.to_s
      break
    end
  end
  puts x
end
 
#for test : X5+5=1X X+X=X X5+X5=10

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

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main()
{
    int N, M;
    cin >> N >> M;
    UnionFind tree(N);
    for (int i = 0; i < M; i++)
    {
        int x,y;
        cin >> x >> y;
        tree.unite(x,y);
    }
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        count = max(count,tree.size(i));
    }
    cout << count << endl;
}

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

signed main()
{
  int k, n;
  cin >> k >> n;

  int a[n], b[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n-1; ++i) b[i] = a[i+1] - a[i];
  b[n-1] = a[0] + (k - a[n-1]);

  cout << k - *max_element(b, b+n) << '\n';

  return (0);
}


Measured memory_bytes: 5164
let (n1, n2) = (3, 9)

let n_limit = 100
let mdt = Array.make_matrix n2 n2 0
let path = Array.make n_limit 0
let dx = [| 0; -1; 0; 1 |]
let dy = [| 1; 0; -1; 0 |]
let dir = [| "r"; "u"; "l"; "d" |]

type puzzle = { f : int array; space : int; md : int }

let initialize_mdt () =
  for i = 0 to n2 - 1 do
    for j = 0 to n2 - 1 do
      mdt.(i).(j) <- abs (i / n1 - j / n1) + abs (i mod n1 - j mod n1)
    done
  done

let get_all_md f =
  Array.fold_left (fun (i, sum) e ->
    (i + 1, if e = n2 then sum else sum + mdt.(i).(e-1)))
    (0, 0) f
  |> snd

let dfs pzl limit =
  let rec doit depth prev pzl =
    if pzl.md = 0 then true
    else if depth + pzl.md > limit then false
    else begin
      let sx = pzl.space / n1 in
      let sy = pzl.space mod n1 in
      let rec move r =
        if r = 4 then false
        else begin
          let tx = sx + dx.(r) in
          let ty = sy + dy.(r) in
          if tx < 0 || ty < 0 || tx >= n1 || ty >= n1 then move (r + 1)
          else if max prev r - min prev r = 2 then move (r + 1)
          else begin
            let { f; space; md } = pzl in
            let a = tx*n1 + ty in
            let b = sx*n1 + sy in
            let md = md - mdt.(a).(f.(a) - 1) in
            let md = md + mdt.(b).(f.(a) - 1) in
            let newf = Array.copy f in
            let t = newf.(a) in
            newf.(a) <- newf.(b);
            newf.(b) <- t;
            if doit (depth + 1) r { f = newf; space = a; md } then begin
              path.(depth) <- r;
              true
            end else move (r + 1)
          end
        end in
      move 0
    end in
  doit 0 (-n_limit) pzl

let idastar f space =
  let pzl = { f; space; md = get_all_md f } in
  let rec doit limit =
    if limit > n_limit then assert false
    else if dfs pzl limit then begin
      let str = ref "" in
      for i = 0 to limit - 1 do
        str := !str ^ dir.(path.(i));
      done;
      !str
    end else doit (limit + 1) in
  doit pzl.md

let () =
  initialize_mdt ();
  let f = Array.make n2 0 in
  let space = ref 0 in
  for i = 0 to n2 - 1 do
    f.(i) <- Scanf.scanf "%d " (fun i -> i);
    if f.(i) = 0 then begin
      f.(i) <- n2;
      space := i;
    end
  done;
  idastar f !space |> String.length |> Printf.printf "%d\n"

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

using namespace std;

// We assume that all characters of s are small letters.
int findMaxLen(const string s){
    vector<vector<int>> appearance(26);

    for (int i = 0; i < s.size(); i++){
        appearance[s[i] - 'a'].push_back(i);
    }

    int maxLenSoFar = 0;
    for (auto a : appearance){
        // 出現数が2未満のアルファベットは対象外
        if (a.size() < 2){
            continue;
        }
        for (int i = 0; i < a.size();++i){
            auto left = s.cbegin()+a[i];
            for (int j = i + 1; j < a.size(); ++j){
                if(a[j]-a[i]>maxLenSoFar){
                    auto right = s.cbegin() + a[j];
                    int l = 0;
                    for (auto it = left; it < right && right + l < s.cend();it++,++l){
                        if(*it != *(right+l)){
                            break;
                        }
                    }
                    maxLenSoFar = max(maxLenSoFar, l);
                }
            }
        }
    }
    return maxLenSoFar;
}

int findMaxLenSlowly(const string s){
    int maxLenSoFar = 0;
    for (auto left = s.cbegin(); left+maxLenSoFar < s.cend();left++){
        for (auto right = left + maxLenSoFar + 1; right < s.cend() && right + maxLenSoFar  < s.end(); right++){
            int l = 0;
            for (auto it = left; it < right && right + l < s.cend(); it++, ++l){
                if (*it != *(right + l)){
                    break;
                }
            }
            maxLenSoFar = max(maxLenSoFar, l);
        }
    }
    return maxLenSoFar;
}

int main(){
    string s;
    int len; // not used
    cin >> len;
    cin >> s;
    cout << findMaxLenSlowly(s) << endl;
 //   cout << findMaxLen(s) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<tuple>
#include<set>

#include<algorithm>
using namespace std;

#define INF ((int)(1e9))
#define MAX 110000


int main(){
	int n, m, temp;
	set<int> ve;
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>temp;
		ve.insert(temp);
	}
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>temp;
		ve.erase(temp);
	}
	
	for(int y : ve) cout<<y<<endl;
	return 0;
}


Measured memory_bytes: 12448
#include<stdio.h>
int main(void){
	int N;
	scanf("%d",&N);
	int a;
	int H;
	int max=0;
	int cnt=0;
	for(a=0;a<N;a++){
		scanf("%d",&H);
		if(H>=max){
			cnt++;
			max=H;
		}
	}
	printf("%d",cnt);
return 0;
}

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

int main()
{
  char ch;
  while(1){
    scanf("%c",&ch);
    if (ch == '\n') {
      break;
    } else if('a' <= ch && ch <= 'z'){
      printf("%c", ch-32);
    }else if('A' <= ch && ch <= 'Z') {
      printf("%c", ch+32);
    }else {
      printf("%c", ch);
    }
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 3152
#include <stdio.h>
#include <math.h>
int main(void){
    int a,b,n = 0,ans = 0,x;
    scanf("%d %d\n",&a,&b);
    if(a<b){
        n=b;
        while(n>=0){
            x= a * pow(10,n-1);
            ans = ans + x ;
            n -=1;
        }
        printf("%d",ans);
    }else if(a>b){
        n=a;
        while(n>=0){
            x= b * pow(10,n-1);
            ans = ans + x ;
            n -=1;
        }
        printf("%d",ans);
    }else if(a=b){
        n=a;
        while(n>=0){
            x= b * pow(10,n-1);
            ans = ans + x ;
            n -=1;
        }
        printf("%d",ans);
    }
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int n;
vector<pair<LL,LL>> v;

pair<LL,LL> myplus(pair<LL,LL> p, LL d, int rot){
  if(rot==0){
    p.first -= d;
  }else if(rot==1){
    p.first += d;
  }else if(rot==2){
    p.second -= d;
  }else if(rot==3){
    p.second += d;
  }
  return p;
}

LL m_dist(pair<LL,LL> p1, pair<LL,LL> p2){
  return abs(p1.first-p2.first) + abs(p1.second-p2.second);
}

int main(){
  LL tmp1,tmp2;
  cin>>n;
  REP(i,n){
    cin>>tmp1>>tmp2;
    v.push_back(make_pair(tmp1,tmp2));
  }
  FOR(i,1,n){
    if((v[0].first+v[0].second+v[i].first+v[i].second)%2!=0){
      cout<<-1<<endl;
      return 0;
    }
  }

  vector<LL> d;
  LL d_in = 1LL;
  REP(i,38)
    d_in*=2;
  if((v[0].first+v[0].second)%2==0){
    REP(i,40){
      d.push_back(d_in);
      d_in = max((LL)1,d_in/2);
    }
  }else{
    REP(i,39){
      d.push_back(d_in);
      d_in = d_in/2;
    }
  }
  cout<<d.size()<<endl;
  REP(i,d.size()){
    cout<<d[i]<<" ";
  }
  cout<<endl;

  string ops[4] = {"L","R","D","U"};
  REP(i,n){
    string s_out = "";
    pair<LL,LL> pos = make_pair(0LL,0LL);
    REP(j,d.size()){
      vector<LL> v_val;
      REP(k,4){
	v_val.push_back(m_dist(v[i],myplus(pos,d[j],k)));
      }
      int min_idx = distance(v_val.begin(),min_element(v_val.begin(),v_val.end()));
      s_out += ops[min_idx];
      pos = myplus(pos,d[j],min_idx);
    }
    cout<<s_out<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
# if true

# include <iostream>
# include <algorithm>
# include <vector>

using Int = long long;

int main()
{

    Int N; std::cin >> N;
    
    std::vector<std::pair<int, int>> data(N);
    for (auto& val : data) std::cin >> val.first >> val.second;

    std::sort(data.begin(), data.end(), [](const auto& lhs, const auto& rhs) { return lhs.second < rhs.second; });

    auto isPossible = true;
    Int  accum{};
    for (const auto& val : data)
    {
        accum += val.first;

        if (accum > val.second) 
            isPossible = false;
    }

    if (isPossible) std::cout << "Yes";
    else            std::cout << "No";

    return 0;
}

# endif

Measured memory_bytes: 1792