akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

typedef long double LD;
#define N 3200

const LD pi=acos(-1);
complex<LD> ans,agl[N];
int n,m,a[N];

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i){
		scanf("%d",a+i);
		agl[i]=polar((LD)1.0,pi*a[i]/m);
	}
	for (int i=1;i<=n;++i)
		for (int j=i+1;j<=n;++j)
			ans+=agl[i]*agl[j]*complex<LD>(((n-j)+(i-1)-(j-i-1)),0);
	ans=ans*complex<LD>(6.0/n/(n-1)/(n-2),0);
	printf("%.12Lf %.12Lf\n",ans.real(),ans.imag());
	
	return 0;
}
			

Measured memory_bytes: 1024
# coding:utf-8

import sys
INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, m = LI()
    A = LI()

    match = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    # dp[i]: ちょうどマッチをi本使ったときに作れる整数の最大の値
    dp = [-INF] * (n + 10)
    dp[0] = 0
    for i in range(n):
        for a in A:
            j = i + match[a]
            dp[j] = max(dp[j], dp[i] * 10 + a)

    return dp[n]


print(main())


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

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int soma = 0;
    int g[n];
    int p[n];
    for(int i = 0; i < n; i++)
        scanf("%d", &g[i]);
    for(int i = 0; i < n; i++)
        scanf("%d", &p[i]);
    for(int i = 0; i < n; i++)
        if(g[i] > p[i])
            soma += g[i] - p[i];
    printf("%d\n", soma);
    return 0;
}

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

int  partition(int *,int ,int );

int main(){
  int *A,n,i,j;

  scanf("%d",&n);
  A=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  j=partition(A,0,n);

  for(i=0;i<n;i++){
    if(i!=j){
      printf("%d",A[i]);
      if(i!=n-1) printf(" ");
      
    }else printf("[%d] ",A[i]);
  }
  printf("\n");
  
  free(A);

  return 0;
}

int  partition(int *A,int p,int r){
  int x,i,j,buf;
  x=A[r-1];
  i=p;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      buf=A[j];
      A[j]=A[i];
      A[i++]=buf;
    }
  }
  
  return i-1;
}



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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

class Primes {
private:
	vector<bool> is_prime_;
public:
	vector<int> Prime_Number;
	Primes(int N) {
		is_prime_.resize(N + 1, true);
		is_prime_[0] = is_prime_[1] = false;
		for (int i = 0; i < N + 1; i++) {
			if (is_prime_[i]) {
				Prime_Number.push_back(i);
				for (int j = 2 * i; j <= N; j += i) is_prime_[j] = false;
			}
		}
	}
	int operator[](int i) { return Prime_Number[i]; }
	int size() { return Prime_Number.size(); }
	int back() { return Prime_Number.back(); }
	bool isPrime(int q) { return is_prime_[q]; }
};

int main(void)
{
	int n;
	cin >> n;
	Primes p(55555);
	vector<int> ans;
	for (auto e : p.Prime_Number) {
		if (e % 5 == 1) {
			ans.push_back(e);
			if (ans.size() == n) break;
		}
	}
	for (auto e : ans) {
		cout << e << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    set<ll> S;
    FORI(i,0,N)
    {
        READV(x);
        S.insert(x);
    }
    if(sz(S)==N)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    

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


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 9600
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int x=sc.nextInt();
		if(x>500*n)
			System.out.println("No");
		else
			System.out.println("Yes");


	}

}


Measured memory_bytes: 21716
# https://atcoder.jp/contests/abc169/submissions/13893064

def main():
    from itertools import zip_longest

    LIMIT = 10 ** 18

    N = int(input())
    *A, = map(int, input().split())

    while len(A) > 1:
        A = [x * y for x, y in zip_longest(A[::2], A[1::2], fillvalue=1)]

    if A[0] > LIMIT:
        print(-1)
    else:
        print(A[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 22036
#include <stdio.h>
#define MAXCARD 100010
#define INF 2000000000

struct Card {
    int value;
    char type;
};
typedef struct Card card_t;


card_t A[MAXCARD]; // for quickSort
card_t B[MAXCARD]; // for mergeSort
card_t L[MAXCARD/2], R[MAXCARD/2];


void swap(int a, int b)
{
    card_t t = A[a];
    A[a] = A[b];
    A[b] = t;
}

void merge(card_t B[], int l, int m, int r)
{
    int i, j, k;
    
    for (i = 0; i < m-l; i++) L[i] = B[l+i];
    for (i = 0; i < r-m; i++) R[i] = B[m+i];
    
    L[m-l].value = R[r-m].value = INF;
    
    for (i=j=0, k=l; k < r; k++) {
        if (L[i].value <= R[j].value) {
            B[k] = L[i++];
        }
        else {
            B[k] = R[j++];
        }
    }
}

void mergeSort(card_t B[], int l, int r)
{
    if (l+1 < r) {
        int m = (l+r)/2;
        mergeSort(B, l, m);
        mergeSort(B, m, r);
        merge(B, l, m, r);
    }
}


int partition(card_t A[], int p, int q)
{
    int x, i, j;
    x = A[q].value;
    i = p-1;
    for (j = p; j < q; j++) {
        if (A[j].value <= x) {
            i++;
            swap(i, j);
        }
    }
    swap(q, i+1);
    return i+1;
}

void quickSort(card_t A[], int p, int r) 
{
    if (p < r) {
        int q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q+1, r);
    }
}

int main()
{
    int i;    
    int N;
    
    scanf("%d", &N);
    getchar();
    for (i = 0; i < N; i++) {
        scanf("%c %d", &A[i].type, &A[i].value);
        getchar();
        B[i] = A[i];
    }
    
    quickSort(A, 0, N-1);
    mergeSort(B, 0, N);
    
    /*
    puts("quickSort");
    for (i = 0; i < N; i++) {
        printf("%c %d\n", A[i].type, A[i].value);
    }
    puts("mergeSort");
    for (i = 0; i < N; i++) {
        printf("%c %d\n", B[i].type, B[i].value);
    }
    */
    
    int isStable = 1;
    for (i = 0; i < N; i++) {
        if (A[i].type != B[i].type) {
            isStable = 0;
            break;
        }
    }
    if (isStable) {
        puts("Stable");
    } else {
        puts("Not stable");
    }
    
    for (i = 0; i < N; i++) {
        printf("%c %d\n", A[i].type, A[i].value);
    }
    
    return 0;
}

Measured memory_bytes: 2952
def solve(N, K, As):
    alls = []
    for i in range(N):
        for j in range(i + 1, N + 1):
            alls.append("{:041b}".format(sum(As[i:j])))
    def find(i, alls):
        if i > 40:
            return []
        ones = [a for a in alls if a[i] == "1"]
        if len(ones) < K:
            return find(i + 1, alls)
        elif len(ones) == K:
            return ones
        elif len(ones) > K:
            ret = find(i + 1, ones)
            if len(ret) == 0:
                return ones[0:K]
            else:
                return ret

    ans = find(0, alls)
    if len(ans):
        a = 0xFFFFFFFFFFF
        for p in ans:
            a &= int(p, 2)
        return a
    else:
        return 0

if __name__ == "__main__":
    l = input()
    N = int(l.split(" ")[0])
    K = int(l.split(" ")[1])
    As = [int(c) for c in input().split()]
    print(solve(N, K, As))


Measured memory_bytes: 61104
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n=input()
ans = ''
for s in n:
    if s=='1':
        ans += '9'
    elif s=='9':
        ans += '1'
    else:
        ans += s

print(int(ans))

Measured memory_bytes: 3064
#include "stdio.h"
int main(int argc, char const *argv[])
{
	int i,j,a,b,card[4][13],count,num;
	char mark[2];
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			card[i][j] = 0;
		}
	}
	scanf("%d",&num);
	for(i=0;i<num;i++){
		scanf("%s",mark);
		if(mark[0] == 'S')
			a = 0;
		else if(mark[0] == 'H')
			a = 1;
		else if(mark[0] == 'C')
			a = 2;
		else
			a = 3;
		scanf("%d",&b);
		b = b -1;
		card[a][b] = 1;
	}
	for(i=0;i<4;i++){
		for (j=0;j<13;j++)
		{
			if(card[i][j] == 0)
			{
				if(i==0)
					printf("S ");
				else if(i==1)
					printf("H ");
				else if(i==2)
					printf("C ");
				else 
					printf("D ");
				
				printf("%d\n",j+1);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 596
#include<cstdio>
#include<iostream>
using namespace std;
inline int read()
{
	int x=0,f=1; char ch=0;
	while(!isdigit(ch)) f=(ch=='-'?-1:1),ch=getchar();
	while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
int main()
{
	int a=read(),b=read();
	printf("%d\n",max(a+b,max(a-b,a*b)));
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=2e5+5;
int n,m,f[N],sz[N],ans;

int getf(int x){
	if(f[x]==x) return x;
	return f[x]=getf(f[x]);
}

void merge(int x,int y){
	x=getf(x);y=getf(y);
	if(x==y) return ;
	f[x]=y;
	sz[y]+=sz[x];
}

signed main(){
	read(n,m);
	for(int i=1;i<=n;i++) f[i]=i,sz[i]=1;
	for(int i=1,x,y;i<=m;i++){
		read(x,y);
		merge(x,y);
	}
	for(int i=1;i<=n;i++) if(getf(i)==i) ans=max(ans,sz[i]);
	write(ans);
}

Measured memory_bytes: 11452
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  int A[N],B[N],C[N-1];
  for(int i=0;i<N;i++) cin>>A[i];
  for(int i=0;i<N;i++) cin>>B[i];
  for(int i=0;i<N-1;i++) cin>>C[i];
  
  int ans=B[A[0]-1];
  
  for(int i=1;i<N;i++){
    ans+=B[A[i]-1];
    if(A[i-1]+1==A[i]) ans+=C[A[i-1]-1];
  }
  
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
a = Array.new
b = Array.new
a[0], b[0] = gets.split.map(&:to_i)
i = 0
while a[i] != 0 && b[i] != 0 do
	i += 1
	a[i], b[i] = gets.split.map(&:to_i)
end
i = 0
while a[i] != 0 && b[i] != 0 do
	for j in 1..b[i] do
		print "#"
	end
	puts
	for j in 2..a[i]-1 do
		print "#"
		for k in 2..b[i]-1 do
			print "."
		end
		print "#"
		puts
	end
	for j in 1..b[i] do
		print "#"
	end
	puts
	puts
	i += 1
end

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


int gcd(int a, int b) {
    if (b==0) return a;
   	else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}


int main(){
	ll N;
	cin>>N;
	vector<ll> A(N);
	ll sum=0;
	REP(i,N){
		cin>>A[i];
		sum+=A[i];
	}
	
	if(sum%2==0){
		cout<<"YES"<<endl;
	}
	else cout<<"NO"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 1024
#define ll long long
#define R register
#include <bits/stdc++.h>

using namespace std;

namespace ARC022C
{
int n, a[55], b[55];
ll f[55], ans;

inline void solve()
{
  scanf("%d", &n);
  for (int j = 0; j <= 50; ++j)
  {
    f[j] = 0, f[j] |= (1ll << j);
    for (int k = 1; k <= j; ++k)
      if(((1ll << 51) - 1) & (1ll << k)) f[j] |= f[j % k];
  }
  for (R int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (R int i = 1; i <= n; ++i) scanf("%d", &b[i]);
  int flag = 1;
  for (R int j = 1; j <= n; ++j)
    if((f[a[j]] & (1ll << b[j])) == 0) flag = 0;
  if(flag == 0) return printf("%lld\n", -1ll), void();
  for (int i = 50; i; --i)
  {
    for (int j = 0; j <= 50; ++j)
    {
      f[j] = 0, f[j] |= (1ll << j);
      for (int k = 1; k <= j; ++k)
        if((ans + (1ll << i) - 1) & (1ll << k)) f[j] |= f[j % k];
    }
    int flag = 1;
    for (R int j = 1; j <= n; ++j)
      if((f[a[j]] & (1ll << b[j])) == 0) flag = 0;
    if(!flag) ans += (1ll << i);
  }
  printf("%lld\n", ans);
}
}

int main()
{
  return ARC022C::solve(), 0;
}

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

using namespace std;

template<typename T>
class Stack {
private:
    struct Node {
        T val;
        Node *next;
    };

    Node *top;

public:
    Stack() {
        top = new Node();
        top->next = NULL;
    }

    ~Stack() {
        while (top->next != NULL) {
            Node *top_old = top;
            top = top_old->next;
            delete top_old;
        }
        delete top;
    }

    void push(T a) {
        Node *top_old = top;
        top = new Node();
        top->val = a;
        top->next = top_old;
        return;
    }

    T pop() {
        if (top->next == NULL) {
            return NULL;
        } else {
            Node *top_old = top;
            T v = top_old->val;
            top = top_old->next;
            delete top_old;
            return v;
        }
    }
};

int64_t calc(Stack<string> &s) {
    string str = s.pop();
    if (str == "+") {
        return calc(s) + calc(s);
    } else if (str == "-") {
        int64_t a = calc(s);
        int64_t b = calc(s);
        return b - a;
    } else if (str == "*") {
        return calc(s) * calc(s);
    } else {
        return stoi(str);
    }
}

int main() {
    string str;
    Stack<string> s;

    while (cin >> str) s.push(str);
    cout << calc(s) << endl;

    return 0;
}

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

int main()
{
  int n;
  int a[100005];
  int total = 0;
  
  cin >> n;
  a[0] = 0;
  for ( int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  a[n + 1] = 0;

  for ( int i = 0; i <= n; i++) {
    total += abs(a[i] - a[i + 1]);
  }
 
  for ( int i = 1; i<= n; i++) {
    int ans = total;

    ans -= abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i]);
    ans += abs(a[i - 1] - a[i + 1]);

    cout << ans << endl;
  }
  
  return (0);
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const ll mod = 1e9 + 7;
int main()
{
	SPEED
	ll n, k, temp;
	cin >> n >> k;
	priority_queue <ll> pq;
	
	for (ll i = 0; i < n; ++i)
	{
		cin >> temp;
		pq.push(temp);
	}

	if (k>=n)
	{
		cout << 0;
		return 0;
	}


	for (ll i = 0; i < k; ++i)
	{
		pq.pop();
	}

	ll s = 0;

	while (pq.empty() == false) 
    { 
        s += pq.top(); 
        pq.pop(); 
    }

    cout << s;
	return 0;
}

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

int main(){
  
  string s;
  cin >> s;
  int c = 0;
  if (s[0] == '1') c++;
  if (s[1] == '1') c++;
  if (s[2] == '1') c++;
  
  cout << c << endl;

  
}

Measured memory_bytes: 256
from collections import deque
S = deque(input())
Q = int(input())
query = [input().split() for _ in range(Q)]
reverse = False
for q in query:
    if q[0] == '1':
        reverse = not reverse
    else:
        if q[1] == '1':
            if not reverse:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if not reverse:
                S.append(q[2])
            else:
                S.appendleft(q[2])
if reverse:
    S.reverse()
print(''.join(S))


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

int main(){
  string s, t;
  cin >> s >> t;
  int ans = 0;
  if(s[0] == t[0]) ans++;
  if(s[1] == t[1]) ans++;
  if(s[2] == t[2]) ans++;
  cout << ans << endl;
  return 0;
}
  

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int gcd_euclid(int u, int v) {
	  int r;
		  while (0 != v) {
				    r = u % v; u = v; v = r; /* swap */
						  }
							  return u;
}

int main()
{

	int a;

	cin >> a;
	cout << 2 * a / gcd_euclid(2, a);

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main()
{
   string S;
   cin >> S;
   if (S[S.size() - 1] == 's')
      S += "es";
   else
      S += "s";
   cout << S << endl;
   return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
using namespace std;

struct Node { 
    int parent, left, right; 
};

struct Node t[10000];

void pre(int a) {
    if (a == -1) return;
    cout << " " << a;
    pre(t[a].left);
    pre(t[a].right);
}

void inParse(int a) {
    if (a == -1) return;
    inParse(t[a].left);
    cout << " " << a;
    inParse(t[a].right);
}

void postParse(int a) {
    if (a == -1) return;
    postParse(t[a].left);
    postParse(t[a].right);
    cout << " " << a;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        t[i].parent = -1;
    }
    int v, l, r;
    for (int i = 0; i < n; i++){
        cin >> v >> l >> r;
        t[v].left = l;
        t[v].right = r;
        if (l != -1) t[l].parent = v;
        if (r != -1) t[r].parent = v;
    }
    int root;
    for (int i = 0; i < n; i++) if (t[i].parent == -1) root = i;
    
    cout << "Preorder" << endl;
    pre(root);
    cout << endl;
    cout << "Inorder" << endl;
    inParse(root);
    cout << endl;
    cout << "Postorder" << endl;
    postParse(root);
    cout << endl;
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       RESET(a, b)        memset(a, b, sizeof(a))
#define       gcd(a, b)          __gcd(a, b)
#define       MX                 300005
#define       MOD               1000000007
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
bool cmp(ll x,ll y)
{
   return x>y;
}
int main(void)
{
   long long int t,n,m,k,x,y,a[200001];
   vector<ll> v,v1,v2;
   vector< pair <ll,ll> >p,p1,p2;
   set<ll> st;
   priority_queue<ll> pq;
   priority_queue< ll,vector<ll>,greater<ll> > lpq;
   priority_queue< pair<ll,ll> > phpq;
   priority_queue< pair<ll,ll>,vector< pair<ll,ll> >,greater< pair <ll,ll> > > plpq;
   string s;
   //cin>>t;
   //while(t--)
   {
      cin>>s;
      ll sum=0;
      for(ll i=0;i<s.size();i++)
      {
         sum+=ll(s[i]-'0');
      }
      if(sum%9==0)
         cout<<"Yes"<<endl;
      else
         cout<<"No"<<endl;
   }
   return 0;
}


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


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main() {
    int n;
    string s;int k;
    cin >> n >> k >> s;
    s[k-1] = (s[k-1] - 'A') + 'a';
    cout << s << endl;
}


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

int main(){
  string s;cin>>s;
  int n=s.size();
  bool f=0;
  REP(i,n){
    if(s.at(i)!=s.at(n-1-i)) f=1;
  }
  for(int i=0;i<(n-1)/2;i++){
    if(s.at(i)!=s.at((n-1)/2-i-1)) f=1;
  }
  int j=0;
  for(int i=(n+3)/2-1;i<n;i++){
    if(s.at(i)!=s.at(n-1-j)) f=1;
    j++;
  }
    
  cout<<(f?"No":"Yes");
}

Measured memory_bytes: 256
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-09 16:18:57
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

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

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

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

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

    if (b - a + 1 >= 2*k) {
        for (int i = 0; i < k; i++) cout << a+i << endl;
        for (int i = 0; i < k; i++) cout << b-k+i+1 << endl;
    } else {
        for (int n = a; n <= b; n++) cout << n << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
tmp = -999999
for i in range(N):
    if tmp <= H[i]-1:
        tmp = H[i] -1
    elif tmp <= H[i]:
        tmp = H[i]
    else:
        print('No')
        break
else:
    print('Yes')

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

int A,B;
char F[102][102];
int main(){
	cin >> A >> B;
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++){
			if(i<=50) F[i][j] = '#';
			else F[i][j] = '.';
		}
	}
	int i = 1,j = 1;
	for(int c=1;c<=A-1;c++){
		F[i][j] = '.';
		if(j+2<=100){
			j += 2;
		}else{
			i += 2;
			j = 1;
		}
	}
	i = 53,j=1;
	for(int c=1;c<=B-1;c++){
		F[i][j] = '#';
		if(j+2<=100){
			j += 2;
		}else{
			i += 2;
			j = 1;
		}	
	}
	cout << 100 << " " << 100 << endl;
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++){
			cout << F[i][j];
			if(j==100) cout << endl;
		}
	}	
}

Measured memory_bytes: 256
h, w = list(map(int, input().split()))
init_board = []
for i in range(h):
    init_board.append([_ for _ in input()])

board = []
# 行から削除する
for i in range(h):
    if init_board[i] != ["."] * w:
        board.append(init_board[i])

# 行列を転置する
new_board = []
for i in range(w):
    add_row = []
    for j in range(len(board)):
        add_row.append(board[j][i])
    if add_row != ["."] * len(add_row):
        new_board.append(add_row)

# 最後に形を戻す
answer_board = []
for i in range(len(new_board[0])):
    add_row = []
    for j in range(len(new_board)):
        add_row.append(new_board[j][i])
    answer_board.append(add_row)

# 出力
for i in range(len(answer_board)):
    print("".join(answer_board[i]))


Measured memory_bytes: 3316
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

func main() {
	x, err := strconv.Atoi(input())
	if err != nil {
		log.Fatalln(err)
	}

	y, err := strconv.Atoi(input())
	if err != nil {
		log.Fatalln(err)
	}

	//if y%2 == 1 {
	//	fmt.Println("No")
	//}

	for a := 0; a <= x; a++ {
		b := x - a

		if y == 2*a+4*b {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}


Measured memory_bytes: 1816
#!/usr/bin/env python
#-*- coding:utf-8 -*-

def calc(n,m,ope):
	n = int(n)
	m = int(m)
	rslt = 0
	if ope == "+":
		rslt = n + m
	elif ope == "-":
		rslt = n - m
	elif ope == "*":
		rslt = n * m
	else:
		try:
			raise ValueError("invalid operator!")
		except ValueError as e:
			print(e)
	return rslt
		
def main():
	formula = raw_input().split()
	stack = []
	for f in formula:
		if f == '+' or f == '-' or f == '*':
			pop1 = stack.pop()
			pop2 = stack.pop()
			rslt = calc(pop2, pop1,f)
			stack.append(rslt)
		else:
			stack.append(f)
		
	print stack.pop()




#def test():

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

Measured memory_bytes: 6456
s = io.read()
s1 = tonumber(s:sub(1, 2))
s2 = tonumber(s:sub(3, 4))
f1 = 0 < s1 and s1 <= 12
f2 = 0 < s2 and s2 <= 12
if f1 and f2 then
  print("AMBIGUOUS")
elseif f1 then
  print("MMYY")
elseif f2 then
  print("YYMM")
else
  print("NA")
end


Measured memory_bytes: 2612
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define FAST ios_base::sync_with_stdio(false);cin.tie(0);
    const double EPS = 1e-9;
    const double PI = acos(-1);
    const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
    //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
    //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
    const int dx[] = {0 , 1 , 0 , -1};
    const int dy[] = {1 , 0 , -1 , 0};
    //#define MOD         1000000007LL
    #define MAX         1005
    const ll MOD = 1000000000 + 7;

    bool vis[MAX][MAX];
    int cost[MAX][MAX];
    string maze[MAX];
    int w , h ,cx , cy , fx , fy;
    bool isSafe(int x , int y)
    {
        if(x < 0 || x >= w || y < 0 || y >= h)return false;
        return true;
    }
    int main()
    {
        FAST
        int t;
        t = 1;

        while(t--)
        {

           cin >> w >> h;
           cin >> cx >> cy;
           cx-- , cy--;
           cin >> fx >> fy;
           fx--,fy--;

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

           memset(cost , -1 , sizeof cost);

           deque<pair <int , int > > q;
           q.push_front({cx , cy});
           cost[cx][cy] = 0;

           while(!q.empty())
           {

               pair <int, int> t = q.front();
               q.pop_front();

               if(vis[t.first][t.second])
               {
                   continue;
               }
               vis[t.first][t.second] = true;

               for(int i = 0 ; i < 4 ; i++)
               {
                   int nx = t.first + dx[i];
                   int ny = t.second + dy[i];

                   if(!isSafe(nx , ny))continue;
                   if(maze[nx][ny] == '#')continue;

                   if(cost[nx][ny] == -1 || cost[t.first][t.second] < cost[nx][ny])
                   {
                       cost[nx][ny] = cost[t.first][t.second];
                       q.push_front({nx , ny});
                   }

               }

               for(int i = -2 ; i < 3 ; i++)
               {
                   for(int j = -2 ; j < 3 ; j++)
                   {
                       int nx = t.first + i;
                       int ny = t.second + j;

                       if(!isSafe(nx , ny))continue;
                       if(maze[nx][ny] == '#')continue;

                       if(cost[nx][ny] == -1 || cost[t.first][t.second] + 1 < cost[nx][ny])
                       {
                           cost[nx][ny] = cost[t.first][t.second] + 1;
                           q.push_back({nx , ny});
                       }

                   }
               }

           }

           cout << cost[fx][fy] << endl;
        }
    }



Measured memory_bytes: 9668
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
signed main(){
  int n,d,a,ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>d>>a;
    if(d==a){
      ans++;
    }
    else if(ans<3) ans=0;
  }
  if(ans>=3) cout<<"Yes\n";
  else cout<<"No\n";
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	int n; cin >> n;
	for(int a = 1 ; a < 1000 ; a++){
		ll a5 = 1;
		for(int i = 0 ; i < 5 ; i++){
			a5 *= a;
		}
		for(int b = -1000 ; b < 1000 ; b++){
			ll b5 = 1;
			for(int i = 0 ; i < 5 ;  i++){
				b5 *= b;
			}
			if(a5-b5 == n){
				cout<<a<<" "<<b<<"\n";
				return;
			}
		}
	}			
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)

int selectionSort(int A[], int n) {
    int cnt = 0;
    REP(i, n) {
        int minj = i;
        FOR(j, i, n) if (A[minj] > A[j]) minj = j;
        if (A[i] > A[minj]) {
            swap(A[i], A[minj]);
            cnt++;
        }
    }
    return cnt;
}

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

    int n;
    cin >> n;
    int A[n];
    REP(i, n) cin >> A[i];

    int cnt = selectionSort(A, n);
    REP(i, n) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}

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

int main(){
  long int N, D, a, b, cnt;
  cnt = 0;
  cin >> N >> D;
  double d;
  for(int i = 0; i < N; i++){
    cin >> a >> b;
    d = sqrt(a * a + b * b);
    if(d <= D) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3652
N, M, X = map(int,input().split())
A = list(map(int, input().split()))

P = 0
Q = 0

for j in range(X):
    if j in A:
        P += 1

for k in range(N-X):
    if k + X + 1  in A:
        Q += 1

print(min(P, Q))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  
  int B;
  
  int N = 0;
  
  cin >> A >> B;
  
  for (int i = A; B >= i; i++) {
    
    int man, sen, hyaku, juu, iti;
    
    iti = i % 10;
      
    juu = i % 100 / 10;
      
    hyaku = i % 1000 / 100;
      
    sen = i % 10000 / 1000;
      
    man = i % 100000 / 10000;
      
      
    if (man == iti && juu == sen) {
      
      N++;
      
    }
    
    
  }
  
  cout << N << endl;
}

Measured memory_bytes: 256
characters = list(input())
n = int(input())
for i in range(n):
  order_list = list(map(str, input().split()))
  order_list[1] = int(order_list[1])
  order_list[2] = int(order_list[2])
  if order_list[0] == 'replace':
    for j in range(order_list[1], order_list[2]+1):
      characters[j] = order_list[3][j-order_list[1]]
  if order_list[0] == 'reverse':
    sliced_part = characters[order_list[1]:order_list[2]+1]
    sliced_part = sliced_part[::-1]
    for j in range(order_list[1], order_list[2]+1):
      characters[j] = sliced_part[j-order_list[1]]
  if order_list[0] == 'print':
    for i in range(order_list[1], order_list[2]+1):
      print(characters[i], end='')
    print('')


Measured memory_bytes: 5740
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

struct UnionFind {
  vector<int> par; // 親を指すvector,-par[親]は木のサイズ
  UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
  int root(int x) { // 親をたどる&データの整理
    if(par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  bool unite(int x, int y) { // データの結合
    x = root(x);
    y = root(y);
    if(x == y) return false;
    if(par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  bool same(int x, int y) {return root(x) == root(y);} // 所属判定
  int size(int x) {return -par[root(x)];} // 木のサイズ
};

//head

int n, m;
int ans;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  UnionFind uft(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    uft.unite(a, b);
  }
  rep(i, n) if(uft.root(i) == i) ans++;
  cout << ans-1 << endl;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; using namespace atcoder;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;

	dsu uf(N);
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		a--; b--;
		uf.merge(a, b);
	}

	int ans = uf.groups().size() - 1;
	cout << ans << endl;
}







Measured memory_bytes: 8944
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
int g(char ch)
{
    return ch - 'a' + 1;
}
signed main()
{
    IOS
    string s,t; cin>>s>>t;
    bool Hs[27],Ht[27];
    for(int i=1;i<=26;i++)
    {
        Hs[i] = 0;
        Ht[i] = 0;
    }
    int kk;
    for(int i=0;i<s.length();i++)
    {
        kk = g(s[i]);
        Hs[kk] = 1;
    }
    for(int i=0;i<t.length();i++)
    {
        kk = g(t[i]);
        Ht[kk] = 1;
    }
    for(int i = 1;i<=26;i++)
    {
        if(Ht[i] == 1 && Hs[i] == 0)
        {
            cout<<-1<<endl;
            return 0;
        }
    }
    int l = s.length();
    map<char, vector<int> > Hash;
    char ch;
    for(int i=0;i<s.length();i++)
    {
        ch = s[i];
        Hash[ch].pb(i+1);
    }
    for(auto it : Hash)
    {
        sort(it.se.begin(),it.se.end());
    }
    int mc = 0,look_after = 0;
    int ind,si,ans = 0;
    for(int i = 0;i<t.length();i++)
    {
        ch = t[i];
        si = Hash[ch].size();
        ind = upper_bound(Hash[ch].begin(),Hash[ch].end(),look_after) - Hash[ch].begin();
       // cout<<i<<"  "<<ch<<ind<<endl;
        if(ind >= si)
        {
            mc++;
            look_after = 0;
            i--;
            goto abc;
        }
        look_after = Hash[ch][ind];
       // cout<<look_after<<endl;
        abc: ;
    }
    ans = l*mc + look_after;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2244
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String str = scan.nextLine();
    int n = Integer.parseInt(str);
    str = scan.nextLine();
    String[] strs = str.split(" ");
    int count = 0;
    for (int i = 0; i < n; i+=2) {
      if (Integer.parseInt(strs[i]) % 2 == 1) count++;
    }
    System.out.println(count);
  }
}

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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 1e5 + 20;
const int maxm = (int) 1e6 + 20;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL MOD)
{
    if(n < 0) a = fp(a, MOD - 2, MOD), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % MOD) if(n & 1) res = res * a % MOD; return res;
}

string s[3];
bool ck[3][3][2222];

void check_string(int x, int y, int pos)
{
    string &head = s[x];
    string &tail = s[y];

    for(int i = pos, j = 0; i < head.size() && j < tail.size(); i++, j++)
        if(head[i] != '?' && tail[j] != '?' && head[i] != tail[j])
        {
            ck[x][y][pos] = 0;
            return ;
        }
    ck[x][y][pos] = 1;
}


void work()
{
    for(int i = 0; i < 3; i++) cin >>s[i];
    int mxlen = 0;
    for(int i = 0; i < 3; i++) mxlen = max(mxlen, (int)s[i].size());

    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++)
            if(i != j)
                for(int k = 0; k < s[i].size(); k++)
                    check_string(i, j, k);

    int ans = mxlen * 3;
    int t[] = {0, 1, 2};
    do
    {
        int x = t[0], y = t[1], z = t[2];
        for(int i = 0; i < s[x].size() + 1; i++)
        {
            if(i < s[x].size() && ck[x][y][i] == 0) continue;
            for(int j = 0; j < s[y].size() + 1 || i + j < s[x].size() + 1; j++)
            {
                if(i + j < s[x].size() && ck[x][z][i + j] == 0) continue;
                if(j < s[y].size() && ck[y][z][j] == 0) continue;

                ans = min(ans, max((int)s[x].size(), max(i + (int)s[y].size(), i + j + (int)s[z].size())));
            }
        }

    }while(next_permutation(t, t + 3));
    cout <<ans <<endl;
}

int main(int argc, char **argv)
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> vec[100005];
int visited[100005]={0},color[100005],graph[100005]={0};

void dfs(int v,int c)
{
    visited[v]=1;
    graph[v]=c;
    for(int i=0;i<vec[v].size();i++)
    {
        int u=vec[v][i];
        if(visited[u]==0)
        {
            dfs(u,c);
        }

    }
}


int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>color[i];
    }
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        vec[x].push_back(y);
        vec[y].push_back(x);
    }
    for(int i=1;i<=n;i++)
    {
        if(visited[i]==0)
        {
            dfs(i,i);
        }
    }
    //for(int i=1;i<=n;i++)
    //{
      //  cout<<graph[i]<<" ";
    //}
    //cout<<endl;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(graph[i]==graph[color[i]])
            ans++;
    }
    cout<<ans<<endl;
}


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

using namespace std;

int a, b;
int c = 0;

int main() {
	scanf("%d %d", &a, &b);
	for (int i = a; i <= b; i++) {
		string x = to_string(i);
		bool check = true;
		for (int j = 0; j < x.size(); j++) {
			if (x[j] != x[x.size() - 1 - j]) {
				check = false;
				break;
			}
		}
		if (check) {
			c++;
		}
	}
	printf("%d", c);
	return 0;
}

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

long long n;
map<string, int> mp;
string st[] = {"AC", "WA", "TLE", "RE"};

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    ++mp[s];
  }
  for (int i = 0; i < 4; ++i) cout << st[i] << " x " << mp[st[i]] << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>

using namespace std;

int main()
{
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u == s)
        a--;
    else if(u == t)
        b--;
    cout<<a<<" "<<b<<endl;
    return 0;
}


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

int main(){
  string numal[]={"101","000000","000011","10010001","010001","000001","100101",
		 "10011010","0101","0001","110","01001","10011011","010000","0111",
		 "10011000","0110","00100","10011001","10011110","00101","111",
                 "10011111","1000","00110","00111","10011100","10011101","000010",
		 "10010010","10010011","10010000"};
  string numtmp=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string alpha[]={"00000","00001","00010","00011","00100","00101","00110","00111",
		  "01000","01001","01010","01011","01100","01101","01110","01111",
		  "10000","10001","10010","10011","10100","10101","10110","10111",
		  "11000","11001","11010","11011","11100","11101","11110","11111"};
  string altmp="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
  string line,chli,ans;
  while(1){
    getline(cin,line);
    if(cin.eof()) break;
    for(int i=0;i<line.size();i++){
      for(int j=0;j<32;j++){
	if(line[i] == altmp[j]){
	  chli += alpha[j];
	  break;
	}
      }
    }
    for(int j=3;j<=8;j++){
      string tmp = chli.substr(0,j);
      for(int k=0;k<32;k++){
	if(numal[k] == tmp){
	  ans += numtmp[k];
	  chli.erase(0,j);
	  j = 2;
	  break;
	}
      }
    }
    cout << ans << endl;
    ans.erase();
    chli.erase();
  }
}

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

int n, a;
bool flag = 0;

int main(){
    cin >> n;
    for (int i = 0; i < n; ++i){
        cin >> a;
        if (a % 2 == 1)flag = 1;
    }
    cout << (flag ? "first" : "second") << endl;
}

Measured memory_bytes: 256
def f(x):
  s = set()
  s.add(1)
  for b in xrange(2, x+1):
    y = b
    for p in xrange(x+1):
      y *= b
      if y > x: break
      s.add(y)
  l = sorted(list(s))
  return l[-1]
  
X=int(raw_input())
print f(X)

Measured memory_bytes: 2568
N, M = map(int, input().split())
L = [[0, 0] for _ in range(M)]
for i in range(M):
    L[i][0], L[i][1] = map(int, input().split())

ans = [0, 10**6]

for i in range(M):
    ans[0] = max(ans[0], L[i][0])
    ans[1] = min(ans[1], L[i][1])

print(ans[1]-ans[0]+1 if ans[1]-ans[0]+1>0 else 0)

Measured memory_bytes: 19572
k = int(input())

# キュー
from collections import deque

d = deque()
for i in range(1,10):
    d.append(i)

for i in range(k):
    tmp = d.popleft()
    right = tmp%10
    if(right!=0):
        d.append(tmp*10+right-1)
    d.append(tmp*10+right)
    if(right!=9):
        d.append(tmp*10+right+1)

print(tmp)

Measured memory_bytes: 11968
N,A,B = map(int,input().split())
sum=0

for i in range(1,N+1):

    a=i//10000
    x=i-10000*a

    b=x//1000
    x=x-1000*b

    c=x//100
    x=x-100*c

    d=x//10
    e=x-10*d

    s=a+b+c+d+e
    if A<=s<=B:
        sum+=i

print(sum)

Measured memory_bytes: 3064