akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

int s[100000],t;
int n,q;
int cnt=0;

bool binary_search(int t_,int right,int left){
    int mid_ = (left + right)/2;
    //cout << t_ << " " << mid_ << endl;
    if(t_ == s[mid_]){
        cnt++;
        return true;
    }
    else if(mid_ == left || mid_ == right) return false;

    if(t_ <= s[mid_]){
        if(binary_search(t_,right,mid_)) return true;
    }
    else{
        if(binary_search(t_,mid_,left)) return true;
    }
    
    return false;
}

int main(){
    bool dim;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    cin >> q;
    for(int i=0;i<q;i++){
        cin >> t;
        dim = binary_search(t,0,n);
    }
    cout << cnt << endl;
    return 0;

}



Measured memory_bytes: 3444
import java.util.*;

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

        String S = sc.next();
        int l = S.length();
        int ans = 0;
        
       if(l%2==0){
           for(int i=0; i<l/2; i++){
               if(S.charAt(i)!=S.charAt(l-1-i)){
                    ans = ans + 1;
               }
           }
       }
       else{
           for(int i=0; i<l/2; i++){
               if(S.charAt(i)!=S.charAt(l-1-i)){
                   ans = ans + 1;
               }
           }
       }
       System.out.println(ans);
    }
}

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

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

    vector<int> rt(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        (rt.at(a - 1))++;
        (rt.at(b - 1))++;
    }

    for (int i = 0; i < N; i++) {
        cout << rt.at(i) << endl;
    }
}


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

int main() {

  int  N, A, B;
  cin >> N >> A >> B;

  int plan1 = A*N;
  int plan2 = B;

  if(plan1 < plan2)
    cout << plan1 << endl;
  else
    cout << plan2 << endl;
  
}


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

int main() {
	int n,taro,hanako;
	cin >> n;
	string a[n][2];
	for(int i = 0; i < n; i++){
		cin >> a[i][0];
		cin >> a[i][1];
	}
	for(int i = 0; i < n; i++){
		if(a[i][0] > a[i][1]){
			taro += 3;
		}else if(a[i][0] < a[i][1]){
			hanako += 3;
		}else{
			taro++;
			hanako++;
		}
	}
	cout << taro << " " << hanako << endl;
	return 0;
}


Measured memory_bytes: 3296
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    char c[2];

    scanf("%s", c);

    if(c[0] == 'a' || c[0] == 'e' || c[0] == 'i' || c[0] == 'o' || c[0] == 'u'){
        printf("vowel\n");
    }else{
        printf("consonant\n");
    }

    return 0;
}

Measured memory_bytes: 1604
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[233333];
int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	int pos=-1;
	for(int i=1;i<n;i++)
	{
		if(a[i]+a[i+1]>=k)
		{
			pos=i;
			break;
		}
	}
	if(pos==-1)
	{
		return cout<<"Impossible"<<endl,0;
	}
	cout<<"Possible"<<endl;
	for(int i=1;i<pos;i++)cout<<i<<endl;
	for(int i=n-1;i>pos;i--)cout<<i<<endl;
	cout<<pos<<endl;
	return 0;
}

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

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

	int n;
	cin >> n;
	int p[n];
	for (int i = 0; i < n; ++i) cin >> p[i];

	int max_val = *max_element(p, p+n);
	int ret = accumulate(p, p+n, 0) - max_val/2;

	cout << ret << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a[3],i,j,mp,count=0;
  for(i=0;i<3;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<3;i++){
    for(j=0;j<2;j++){
      if(a[j]<=a[j+1]){
        mp = a[j];
        a[j] = a[j+1];
        a[j+1] = mp;
      }
    }
  }
//  printf("%d%d%d\n",a[0],a[1],a[2]);
  while(a[0]!=a[1]){
    a[1]++; a[2]++; count++;
  }
//  printf("%d%d%d\n",a[0],a[1],a[2]);
  if((a[0]-a[2])%2==0){
    count += (a[0]-a[2])/2;
  }else{
    count += ((a[0]+1)-a[2])/2 + 1;
  }
  printf("%d",count);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
 
int main(void)
{
  int i, n, num=0 ,a[100] ,v ,flag;


  scanf("%d",&n);


  for (i = 0; i < n; i++) 

    scanf("%d",&a[i]);


  flag = 1;

  while(flag == 1) {

  flag=0;
  for (i =n-2; i >=0;i--) {

    if(a[i]>a[i+1]){

      v = a[i+1];
      a[i+1] = a[i];
      a[i] =  v;
      num++;
      flag = 1;
    }

  }


  }
  for(i = 0; i<n-1;i++)
  
  printf("%d ",a[i]);
  printf("%d\n",a[n-1]);
  printf("%d\n",num);
  return 0;
}


Measured memory_bytes: 1968
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
n = S()
if "9" in n:
    print("Yes")
else:
    print("No")
#B

#C
"""
n = I()
d = defaultdict(int)
for i in range(n):
    a = I()
    d[a] ^= 1
d = list(d.values())
print(sum(d))
"""
#D
"""
def dfs(n,k,l,a):
    if n == 0:
        a.append(l)
    for i in range(n):
        dfs(n-1,k[:i]+k[i+1:],l+[k[i]],a)
n,m,R = LI()
r = LI()
f = [i for i in range(n)]
for i in range(R):
    r[i] -= 1
v = [[float("inf") for j in range(n)] for i in range(n)]
for i in range(n):
    v[i][i] = 0
for i in range(m):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a][b] = c
    v[b][a] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            v[i][j] = min(v[i][j],v[i][k]+v[k][j])
l = []
dfs(R,r,[],l)
ans = float("inf")
for k in l:
    d = 0
    for i in range(R-1):
        d += v[k[i]][k[i+1]]
    ans = min(ans,d)
print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38640
#include <cstdio>
#include <algorithm>
#define maxn 1000010
using namespace std;
struct node{
	int l,r;
}a[maxn];
int tot;
char s[maxn];
int cmp(node a,node b){
	return a.l-a.r>b.l-b.r;
}
int main(){
	int n,ln,rn,l,r;
	int i,j;
	ln=rn=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		l=0,r=0;
		scanf("%s",s+1);
		for(j=1;s[j];j++)
			if(s[j]=='(')l++;
			else if(s[j]==')'){
				if(l)l--;
				else r++;
			}
		if(!l&&r)rn+=r;
		else if(l&&!r)ln+=l;
		else if(l&&r)a[++tot]=(node){l,r};	
	}
	sort(a+1,a+1+tot,cmp);
	for(i=1;i<=tot;i++){
		if(ln<a[i].r)
			return printf("No\n")*0;
		ln-=a[i].r,ln+=a[i].l;
	}
	if(ln!=rn)return printf("No\n")*0;
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
using namespace std;

const char* table[] = {
  NULL,
  "',.!?",
  "abcABC",
  "defDEF",
  "ghiGHI",
  "jklJKL",
  "mnoMNO",
  "pqrsPQRS",
  "tuvTUV",
  "wxyzWXYZ",
};

int main()
{
  string str;
  while (cin >> str) {
    str += '\0';
    char prev = 0;
    int row = 0, col = 0;
    for (int i = 0; i < (int)str.size(); ++i) {
      int n = str[i] - '0';
      if (n == 0) {
        if (prev == 0) {
          cout << ' ';
        } else {
          cout << table[row][col];
        }
      } else {
        if (n != prev) {
          if (prev != 0) { cout << table[row][col]; }
          row = n; col = 0;
        } else {
          ++col;
          if (table[row][col] == '\0') { col = 0; }
        }
      }
      prev = n;
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
s = input()
ans = True
for i in range(len(s) // 2):
    if s[len(s) - 1 - i] != s[i]:
        ans = False
if ans:
    for i in range(len(s) // 4):
        if s[(len(s) - 1) // 2 - i - 1] != s[i]:
            ans = False

    for i in range(len(s) // 2 + 1, len(s) // 4 + len(s) // 2 + 1):
        if s[i] != s[len(s) - 1 - i]:
            ans = False

print('Yes' if ans else 'No')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

// #define DEBUG

void printarray(int n, int a[])
{
    for (int i = 1; i < n + 1; i++)
    {
        cout << a[i];
        if (i != n)
            cout << " ";
    }
    cout << endl;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, w, vi, wi;
    const int vmax = 10000;
    const int wmax = 1000000001;
    cin >> n >> w;
    int dp_list[n + 1][vmax + 1] = {};
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= vmax; j++)
        {
            dp_list[i][j] = wmax;
        }
    }
    dp_list[0][0] = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> vi >> wi;
        for (int j = 0; j < vmax + 1; j++)
        {

            if (dp_list[i][j] + wi <= w)
            {
                dp_list[i + 1][j + vi] = min(dp_list[i][j + vi], dp_list[i][j] + wi);
            }
            dp_list[i + 1][j] = min(dp_list[i + 1][j], dp_list[i][j]);
        }
    }
    int ans = 0;
    for (int i = 0; i <= vmax; i++)
    {
        if (dp_list[n][i] != wmax) 
        ans = i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7052
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b; cin>>a>>b;
    char grid[100][100];
    rep(i,50)rep(j,100){
        grid[i][j]='#';
    }
    rep(i,50)rep(j,100){
        grid[i+50][j]='.';
    }
    int x=1,y=0;
    while(--a>0){
        if(y>=100){
            x+=2; y=0;
        }
        grid[x][y]='.';
        y+=2;
    }
    x=51; y=0;
        while(--b>0){
        if(y>=100){
            x+=2; y=0;
        }
        grid[x][y]='#';
        y+=2;
    }
    cout<<"100 100\n";
    rep(i,100){
        rep(j,100)cout<<grid[i][j];
        cout<<endl;
    }
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vector<int> vec;
  rep(i, 2*n) {
    int l;
    cin >> l;
    vec.push_back(l);
  }

  sort(all(vec), greater<>());

  int ans = 0;
  for (int i = 1; i <= vec.size(); i += 2) {
    ans += min(vec[i], vec[i-1]);
  }

  cout << ans << "\n";

  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define clear(v) memset(v,0,sizeof(v))

int table[8] = { 0, 1, 2, 3, 5, 7, 8, 9 };

void oct(int n){
	if (n >= 8){
		oct(n / 8);
	}
	cout << table[n % 8];
}

int main(){
	int n;
	while (cin >> n, n){
		oct(n);
		cout << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long int 
#define PI 3.14159265358979323846
signed main(){
	long double a,b,h,m;
 	cin>>a>>b>>h>>m;
 	long double theta = abs(m*6-(h*30+(m*30)/60));
  	
  	theta = min(360.0-theta,theta);
  //cout<<theta<<endl;
  	long double len = a*a+b*b-2*a*b*cos(((long double)(theta)*PI)/180.0);
  	cout<<setprecision(23)<<(sqrt(len))<<endl;
}


Measured memory_bytes: 4052
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(void){
    ll n;
    cin >> n;
    
    ll ans = 3000000000000;
    for(int i = 1; i <= 1000000; i++){
        if(n % i == 0){
            ll k = n / i;
            ans = min(ans, k+i-2);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define sii set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for(ll i=a ; i<n ; i++)
#define ld long double
#define rall(a) (a).rbegin(),(a).rend()
#define INF 1000000000
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
 
 
 
ll power(ll b,ll e,ll m)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}  
bool isPowerOfTwo(ll x)
{
    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
    return (x && !(x & (x - 1)));
}

int minimumChar(string S1, string S2) 
{ 
    // Get the sizes of both strings 
    int n = S1.size(), m = S2.size(); 
  
    int ans = INT_MAX; 
  
    // Traverse the string S2 
    for (int i = 0; i < m - n + 1; i++) { 
        int minRemovedChar = 0; 
  
        // From every index in S2, check the number of 
        // mis-matching characters in substring of 
        // length of S1 
        for (int j = 0; j < n; j++) { 
            if (S1[j] != S2[i + j]) { 
                minRemovedChar++; 
            } 
        } 
  
        // Take minimum of prev and current mis-match 
        ans = min(minRemovedChar, ans); 
    } 
  
    // return answer 
    return ans; 
} 


void solve()
{
  string s,t;
  cin>>s>>t;
  cout<<minimumChar(t,s);
}


int main()
{
  fastio
  int tt=1;
  // cin>>tt;
  while(tt--)
  {
    solve();
    cout<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <unordered_map>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

int const MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-12;
ll INF = LLONG_MAX / 10;

int main() {
	vector<ll> a(3);
	cin >> a[0] >> a[1] >> a[2];
	rep(t, 1000000) {
		rep(i, 3) if (a[i] % 2) {
			cout << t << endl;
			return 0;
		}
		vector<ll> _a(3);
		rep(i, 3) _a[i] = (a[(i + 1) % 3] + a[(i + 2) % 3]) / 2;
		a = _a;
	}
	cout << -1 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#define LL long long
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 2e5 + 5;
using namespace std;
struct T{
	struct A{
		int l, r;
		LL Minl, Minr, tg;
	}a[maxn << 2];
	void build(int cur, int l, int r){
		a[cur].l = l, a[cur].r = r;
		if (l == r){
			a[cur].Minl = INF;
			a[cur].Minr = INF;
			a[cur].tg = 0;
			return;
		} int mid = l + r >> 1;
		build(cur << 1, l, mid); build(cur << 1 | 1, mid + 1, r);
		a[cur].Minl = min(a[cur << 1].Minl, a[cur << 1 | 1].Minl);
		a[cur].Minr = min(a[cur << 1].Minr, a[cur << 1 | 1].Minr);
	}
	void pushdown(int cur){
		if (a[cur].tg == 0) return;
		a[cur << 1].tg += a[cur].tg;
		a[cur << 1].Minl += a[cur].tg;
		a[cur << 1].Minr += a[cur].tg; 
		a[cur << 1 | 1].tg += a[cur].tg;
		a[cur << 1 | 1].Minl += a[cur].tg;
		a[cur << 1 | 1].Minr += a[cur].tg;
		a[cur].tg = 0; 
	}
	LL Query(int cur, int p){
		if (a[cur].l == a[cur].r) return a[cur].Minl + a[cur].l;
		pushdown(cur);
		int mid = a[cur].l + a[cur].r >> 1;
		if (p <= mid) return Query(cur << 1, p);
		return Query(cur << 1 | 1, p);
	}
	LL QMinl(int cur, int l, int r){
		if (a[cur].l > r || a[cur].r < l) return INF;
		if (a[cur].l >= l && a[cur].r <= r) return a[cur].Minl;
		pushdown(cur);
		return min(QMinl(cur << 1, l, r), QMinl(cur << 1 | 1, l, r));
	}
	LL QMinr(int cur, int l, int r){
		if (a[cur].l > r || a[cur].r < l) return INF;
		if (a[cur].l >= l && a[cur].r <= r) return a[cur].Minr;
		pushdown(cur);
		return min(QMinr(cur << 1, l, r), QMinr(cur << 1 | 1, l, r));
	}
	void upd(int cur, int p, LL k){
		if (a[cur].l == a[cur].r){
			a[cur].Minl = min(a[cur].Minl, k - p);
			a[cur].Minr = min(a[cur].Minr, k + p);
			return;
		}
		pushdown(cur);
		int mid = a[cur].l + a[cur].r >> 1;
		if (p <= mid) upd(cur << 1, p, k);
		else upd(cur << 1 | 1, p, k);
		a[cur].Minl = min(a[cur << 1].Minl, a[cur << 1 | 1].Minl);
		a[cur].Minr = min(a[cur << 1].Minr, a[cur << 1 | 1].Minr);
	}
}t;
int n, A, B, Q;
LL x[maxn];
LL _abs(LL x){return x < 0 ? -x : x;}
int main(){
	scanf("%d%d%d%d", &n, &Q, &A, &B);
	for (int i = 1; i <= Q; i++) scanf("%lld", x + i);
	t.build(1, 1, n); t.upd(1, A, _abs(1ll * B - x[1])); t.upd(1, B, _abs(1ll * A - x[1]));
	for (int i = 2; i <= Q; i++){
		LL d = _abs(x[i] - x[i - 1]), tmp = t.Query(1, x[i - 1]);
		LL Minl = t.QMinl(1, 1, x[i]);
		LL Minr = t.QMinr(1, x[i], n);
		t.a[1].Minl += d;
		t.a[1].Minr += d;
		t.a[1].tg += d;
		t.upd(1, x[i - 1], min(tmp + d, min(Minl + x[i], Minr - x[i])));
	} LL ans = INF;
	for (int i = 1; i <= n; i++) ans = min(ans, t.Query(1, i));
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 18560
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<Integer> list = new ArrayList<>(n);
    for(int i = 0;i < n; i++){
      list.add(sc.nextInt());
      }
    Collections.sort(list);
    System.out.println(Math.abs(list.get(list.size() -1) - list.get(0)));
                       }}


Measured memory_bytes: 21844
using System;
using System.Linq;

namespace ALDS1_1_B
{
    class Program
    {
        static void Main(string[] args)
        {
            //入力
            var st = Console.ReadLine().Trim();
            var vals = st.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(e => int.Parse(e)).ToArray();

            var x = vals[0];
            var y = vals[1];
            if (x < y)
            {
                var z = y;
                y = x;
                x = z;
            }

            while (y > 0)
            {
                var r = x % y;
                x = y;
                y = r;
            }
            Console.WriteLine(x);
        }
    }
}



Measured memory_bytes: 18372
#include<iostream>
using namespace std;
int a[3000009],b[1000009];
int main(){
	int c;
	cin>>c;
	for(int i=2;i<=c;i++)
	{cin>>b[i];
	a[b[i]]++;
	}
	for(int i=1;i<=c;i++)
	cout<<a[i]<<endl;
	
	
}

Measured memory_bytes: 5156
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> iP;
typedef pair< LL, LL > LP;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 300005;

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );
            if( i * i != n ) ret.pb( n / i );

        }
    }
    sort( all( ret ) );
    return ret;
}

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

        LL n, a, b;
        LL na, nb;
        cin >> n >> a >> b;

        switch(n % 6) {
                case 0:
                        na = a;
                        nb = b;
                        //cout << a << " " << b;
                        break;

                case 1:
                        na = a - b;
                        nb = b;
                        //cout << a - b << " " << b;
                        break;

                case 2:
                        na = a - b;
                        nb = a;
                        //cout << a - b << " " << a;
                        break;

                case 3:
                        na = -b;
                        nb = a;
                        //cout << -b << " " << a;
                        break;

                case 4:
                        na = -b;
                        nb = a - b;
                        //cout << -b << " " << a - b;
                        break;

                case 5:
                        na = -a;
                        nb = a - b;
                        //cout << -a << " " << a - b;
                        break;
        }

        if ((n / 6) % 2) {
                na *= -1;
                nb *= -1;
        }

        cout << na << ' ' << nb << endl;

    return 0;
}


Measured memory_bytes: 3216
package main

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

func main() {
	A, B := getStdinInt2()

	if A >= 10 || B >= 10 {
		fmt.Printf("%d\n", -1)
		return
	}
	fmt.Printf("%d\n", A*B)
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntU64() uint64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return uint64(rtn)
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func getStdinIntArrU64() []uint64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]uint64, len(list))
	for idx, val := range list {
		r, _ := strconv.ParseInt(val, 10, 64)
		rtn[idx] = uint64(r)
	}
	return rtn
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
func abs64(n int64) int64 {
	if n < 0 {
		return -n
	}
	return n
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
 
 
int main()
{	
	int a,b,c,d,cnt=1;
	cin>>a>>b>>c>>d;
	while(a>0&&c>0)
	{
		if(cnt%2)c-=b;
		else a-=d;
		cnt++;
	}
	if(a<=0)cout<<"No"<<endl;
	else if(c<=0)cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cmath>
using namespace std;
 
int main() {
	int n;
	cin >> n;
	int p[n];
	int cnt = 0;
	for(int i = 0; i < n; ++i){
		cin >> p[i];
		double rt = sqrt(p[i]);
		for(int j = 2; j <= rt; ++j){
			if(p[i] % j == 0){
				++cnt;
				break;
			}
		}
	}
	cout << n - cnt << endl;
 
	return 0;
}

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

vector<int> era(int N){
	vector<int> is_prime(N+1,1);
	is_prime[0]=0;
	is_prime[1]=0;
	for(int p=2;p*p<=N;p++){
		if(!is_prime[p])continue;
		for(int i=p*2;i<=N;i+=p)is_prime[i]=0;
	}
	return is_prime;
}

signed main(){
	int N; cin>>N;
	vector<int> prime=era(N);
	vector<int> pri;
	for(int i=0;i<N+1;i++){
		if(prime[i]==1)pri.push_back(i);
	}
	map<int,int> fact;
	for(int i=2;i<=N;i++){
		int j=0;
		while(j<pri.size()){
			int tmp=i;
			while(tmp%pri[j]==0){
				fact[pri[j]]++;
				tmp/=pri[j];
			}
			j++;
		}
	}
	vector<int> f(100,0);
	for(auto p : fact){
		f[p.second]++;
	}
	for(int i=99;i>0;i--){
		f[i-1]+=f[i];
	}
	int ans=0;
	ans+=f[74];
	ans+=f[14]*(f[4]-1);
	ans+=f[24]*(f[2]-1);
	ans+=f[4]*(f[4]-1)/2*(f[2]-2);
	cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N,M;
int A[100010],B[100010];
vpi g[100010];
vi C,D;
bool f[100010];
bool ff[100010];
int d[100010];
int par[100010];
vpi r;
void add_edge(int from,int to,int n){
  g[from].pb(mp(to,n));
  g[to].pb(mp(from,n));
}
void dfs(int v,int rank){
  rep(i,g[v].size()){
    pi p=g[v][i];
    int w=p.first,n=p.second;
    if(ff[n]) continue;
    ff[n]=true;
    if(f[w]){
      d[v]++;
      C.pb(v+1);D.pb(w+1);
    }
    else{
      f[w]=true;
      par[w]=v;
      r.pb(mp(rank+1,w));
      dfs(w,rank+1);
    }
  }
}
int main(){
  cin>>N>>M;
  rep(i,M){
    cin>>A[i]>>B[i];
    A[i]--;B[i]--;
  }
  rep(i,M) add_edge(A[i],B[i],i);
  fill(f,0);
  fill(ff,0);
  fill(d,0);
  par[0]=0;
  r.pb(mp(0,0));
  f[0]=true;
  dfs(0,0);
  sort(r.begin(),r.end(),greater<pi>());
  rep(i,r.size()-1){
    int v=r[i].second;
    if(d[v]&1){
      C.pb(v+1);D.pb(par[v]+1);
    }
    else{
      d[par[v]]++;
      C.pb(par[v]+1);D.pb(v+1);
    }
  }
  if(d[0]&1){
    prin(-1);
  }
  else{
    rep(i,C.size()){
      prin2(C[i],D[i]);
    }
  }

  
  return 0;
}


Measured memory_bytes: 20084
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
using namespace std;
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("tst.txt", "r", stdin);
	#endif	
}
const int N=1e5+5,MAX=3e7,MOD=1e9+7;


int n,ans;
map<char,int>occ;
int main()
{	
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

	scanf("%d",&n);
	std::vector<int>a(n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	if(n%2)return !printf("0\n");

	sort(all(a));

	printf("%d\n",a[n/2]-a[n/2-1] );
	
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <set>
#include <limits.h>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> da(n);
	rip(i, n, 0) {
		cin >> da[i];
	}
	priority_queue<int> q;
	ll ans = 0;
	rip(i, n, 0) {
		ans = (ll) ans + da[i];
		q.push(da[i]);
	}
	rip(i, m, 0) {
		int no = q.top();
		q.pop();
		int ne = no / 2;
		ans = (ll)ans - (no - ne);
		q.push(ne);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1276
//Bismillahir Rahmanir-Rahim
/**@MSR**/
#include<bits/stdc++.h>
using namespace std;

#define mod 1e9+7
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<long long>
#define ll long long
#define lli long long int
#define el '\n'
#define mem(a,b) memset(a, b, sizeof(a) )

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define F1(i,n)  for(lli i=1;i<=n;i++)
#define F0(i,n)  for(lli i=0;i<n;i++)
#define FRev(i,n)  for(lli i=n-1;i>=0;i--)
#define ever (;;)

ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    ll x=(a/gcd(a,b))*b;
    return x;
}

int main()
{
    optimize();
    ll t,n,x,y,k,z,m,a,b;
    /**/
    cin>>n;
    //cout<<n%1000<<el;
    if(n%1000==0)
        cout<<"0"<<el;
    else
    {
         x=1000-(n%1000);
    cout<<x<<el;

    }

    return 0;
}
/**/



Measured memory_bytes: 3576
#pragma GCC Optimize("Ofast")
#pragma GCC Optimize "trapv"
#define _GLIBCXX_DEBUG

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

#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define TC int t; cin >> t; while(t--)
#define li long int
#define ll long long
#define ull unsigned long long 
#define Vec(x) vector <x>
#define Pai(x,y) pair <x,y>
#define Map(x,y) map <x,y>
#define UMap(x,y) unordered_map <x,y>
#define Set(x) set <x>
#define Sta(x) stack <x>
#define Qu(x) queue <x>
#define DQ(x) deque(x)
#define PriorQ(x)	priority_queue <x>
#define bg begin()
#define ed end()
#define sz size()
#define ct(x) count(x)
#define len length()
#define F first
#define S second
#define Makep make_pair
#define ins(x) insert(x)
#define ers(x) erase(x)
#define endl "\n";
#define MOD 1000000007
#define PI 3.1415926535897932384626
#define clr() clear()
#define fori0(n) for(int i=0;i<n;i++)
#define foriab(a,b) for(int i=a;i<b;i++)
#define mem0(x) memset(x,0,sizeof(x))
#define mem1(x) memset(x,1,sizeof(x))
#define autoit(x) for(auto it=x.beg;it!=x.ed;it++)
#define count0(x) __builtin_popcount(x)
#define ret return 
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

ll a[100005],dp[100005],n,k;

ll ans(ll i){
	if(i==n-1)
		return 0;
	if(i>=n)
		return INT_MAX;
	if(dp[i]!=-1)
		return dp[i];
	ll solution=INT_MAX;
	for(ll j=1;j<=k;j++){
		if(i+j<n)
		solution=min(solution,abs(a[i]-a[i+j])+ans(i+j));
	}
	return dp[i]=solution;
}

void solve(){
	memset(dp,-1,sizeof(dp));
	cin >> n >> k;
	for(ll i=0;i<n;i++)		cin >> a[i];
	cout << ans(0) << endl;
}

int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif	
	FAST
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	solve();
	ret 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)

int D, N, T[222], A[222], B[222], C[222], dp[222][111];

int main() {
	cin >> D >> N;
	
	for_(i,0,D) cin >> T[i];
	for_(i,0,N) cin >> A[i] >> B[i] >> C[i];
	
	memset(dp, -1, sizeof(dp));
	
	for_(i,0,N) if (A[i] <= T[0] && T[0] <= B[i]) dp[1][C[i]] = 0;
	
	int ans = 0;
	
	for_(i,1,D) for_(j,0,111) {
		if (dp[i][j] >= 0) {
			for_(k,0,N) {
				if (A[k] <= T[i] && T[i] <= B[k]) {
					int c = C[k];
					dp[i + 1][c] = max(dp[i + 1][c], dp[i][j] + abs(j - c));
					ans = max(ans, dp[i + 1][c]);
				}
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1268
#[allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::io::Write,
    std::ops::*,
};

#[allow(unused_macros)]
macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; }

const N: usize = 35;

#[fastout]
fn main() {
    input! {
        n: usize,
        xy: [(i64, i64); n]
    }
    let m = (xy[0].0 + xy[0].1).rem_euclid(2);
    for &(x, y) in xy.iter() {
        if (x + y).rem_euclid(2) != m {
            println!("-1");
            return;
        }
    }
    let mut d = (0..N - 1)
        .scan(1i64, |a, _| {
            *a *= 2;
            Some(*a)
        })
        .collect::<Vec<_>>();
    d.insert(0, 1);
    if m == 1 {
        println!("{}", N);
    } else {
        println!("{}", N + 1);
        print!("1 ");
    }
    println!("{}", d.iter().format(" "));
    for &(x, y) in xy.iter() {
        let mut u = x - y;
        let mut v = x + y;
        if m == 0 {
            u -= 1;
            v -= 1;
            print!("R");
        }
        let mut xs = vec![false; N];
        u += 1 << N;
        u -= 1;
        u /= 2;
        while u != 0 {
            xs[u.trailing_zeros() as usize] = true;
            u &= u - 1;
        }
        let mut ys = vec![false; N];
        v += 1 << N;
        v -= 1;
        v /= 2;
        while v != 0 {
            ys[v.trailing_zeros() as usize] = true;
            v &= v - 1;
        }
        for (u, v) in (0..N).map(|i| (xs[i], ys[i])) {
            if u && v {
                print!("R");
            } else if !u && !v {
                print!("L");
            } else if u && !v {
                print!("D");
            } else {
                print!("U");
            }
        }
        println!("");
    }
}


Measured memory_bytes: 2220
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 10000000005
#define NIL -1
int main(){
    ll x; cin >> x;
    ll ans = 0, count = 0;
    for(ll i = 1; count < x; i++){
        count += i;
        ans = i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
a, b, m = map(int, input().split())
arr1 = [int(j) for j in input().split()]
arr2 = [int(j) for j in input().split()]

pfx1 = []
pfx2 = []

su = 0
for i in range(a):
	su += arr1[i]
	pfx1 += [su]
su = 0
for i in range(b):
	su += arr2[i]
	pfx2 += [su]

mi = 9999999999999
k1 = min(arr1)
k2 = min(arr2)
for i in range(m):
	x, y, c = map(int, input().split())
	mi = min(mi, arr1[x-1]+arr2[y-1]-c, k1+k2)
print(mi)

Measured memory_bytes: 20972
import copy

s = input()
x,y = map(int,input().split())

X = []
Y = []
l = 0
f = -1
xinit = 0
A = s + 'T'
for a in A:
  if a == 'T':
    if f == -1:
      xinit = l
      f = 1
    elif f == 0:
      X.append(l)
      f = 1
    else:
      Y.append(l)
      f = 0
    l = 0
  else:
    l += 1

def pattern(P,init=0):
  Q = set()
  Q.add(init)
  for p in P:
    QQ = set()
    for q in Q:
      QQ.add(q+p)
      QQ.add(q-p)
    Q = copy.copy(QQ)
  return Q

XX = pattern(X,xinit)
YY = pattern(Y)
#print(XX,YY)
if x in XX and y in YY:
  print('Yes')
else:
  print('No')

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

import heapq
def dijkstra_with_path(adj, n, st=1):
    inf = float('inf')
    dj = [inf] * (n + 1)
    paths = dict((x, [x]) for x in range(n + 1))
    dj[st] = 0
    q = []
    heapq.heappush(q, (0, st))
    while q:
        fc, fn = heapq.heappop(q)
        if dj[fn] < fc: continue
        for tn, lc in adj[fn]:
            if dj[fn] + lc < dj[tn]:
                dj[tn] = dj[fn] + lc
                paths[tn] = paths[fn] + [tn]
                heapq.heappush(q, (dj[tn], tn))
    return dj, paths

links = set()
adj = dict((x, []) for x in range(N + 1))
for _ in range(M):
    a, b, c = map(int, input().split())
    adj[a].append((b, c))
    adj[b].append((a, c))
    links.add((a, b) if a < b else (b, a))

for x in range(1, N):
    _, paths = dijkstra_with_path(adj, N, x)
    for p in paths.values():
        t = (0, p[0])
        for v in p[1:]:
            t = (t[1], v)
            links -= set([t if t[0] < t[1] else (t[1], t[0])])
print(len(links))

Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

int dp[100100][3] = {0};
int a[100005];
int b[100005];
int c[100005];

int main(){
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }

    for(int i=1; i<=n; i++){
        dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
    }

    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int N, L;
	cin >> N >> L;
	string *S = new string[N];
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}

	string S_temp;
	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			if (S[i] > S[j]) {
				S_temp = S[i];
				S[i] = S[j];
				S[j] = S_temp;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		cout << S[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gc getchar()
#define lowbit(x) (x&(-x))
inline long long read(){
	long long sum=0,f=1;
	char ch=gc;
	while(!isdigit(ch)){
		if(ch=='-')f=-1;
		ch=gc;
	}
	while(isdigit(ch)){
		sum=(sum<<1)+(sum<<3)+(ch^48);
		ch=gc;
	}
	return f*sum;
}
long long a[2000010],t[2000010];
long long n,ans;
inline bool check(long long sum){
	if((a[n-1]<=sum&&a[n]<=sum)||(a[n]<=sum&&a[n+1]<=sum))return 1;
    if((a[n-1]>sum&&a[n]>sum)||(a[n]>sum&&a[n+1]>sum))return 0;
    for(int i=1;i<n-1;i++){
        if((a[n+i]<=sum&&a[n+i+1]<=sum)||(a[n-i]<=sum&&a[n-i-1]<=sum))return 1;
        if((a[n+i]>sum&&a[n+i+1]>sum)||(a[n-i]>sum&&a[n-i-1]>sum))return 0;
    }
    return a[1]<=sum;
}
int main(){
	//freopen("pyramid.in","r",stdin);
	//freopen("pyramid.out","w",stdout);
	n=read();
	for(register int i=1;i<=(n<<1)-1;i++)a[i]=read();
	bool fg=0;
	for(register int i=1;i<=(n<<1)-1;i++){
		if(a[i]!=0&&a[i]!=1){
			fg=1;
			break;
		}
	}
	if(fg){
		long long l=1,r=(n<<1)-1;
		while(l<r){
			long long mid=(l+r)>>1;
			if(check(mid))r=mid;
			else l=mid+1;
		}
		printf("%lld",l);
	}
	else{
		bool ffg=0;
		for(register int i=2;i<=(n<<1)-1;i=-~i){
			if(a[i]==a[i-1]){
				ffg=1;
				break;
			}
		}
		if(ffg){
			for(register int i=n,j=n;i>1&&j<(n<<1)-1;j=-~j,--i){
				if(a[i]==a[i-1]&&a[j]!=a[j+1]){
					printf("%d",a[i]);
					break;
				}
				if(a[i]!=a[i-1]&&a[j]==a[j+1]){
					printf("%d",a[j]);
					break;
				}
				if(a[i]==a[i-1]&&a[j]==a[j+1]&&a[i]==a[j]){
					printf("%d",a[i]);
					break;
				}
			}
		}
		else printf("%d",a[1]);
	}
	return 0;
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int n, c;
	cin >> n >> c;

	vector<vector<int>> d(c, vector<int>(c));
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			cin >> d[i][j];
		}
	}

	vector<vector<int>> e(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> e[i][j];
			e[i][j]--;
		}
	}

	vector<vector<int>> pre(3, vector<int>(c));
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				pre[(j + k) % 3][i] += d[e[j][k]][i];
			}
		}
	}

	int ans = INF;
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			for (int k = 0; k < c; k++) {
				if (i == j || i == k || j == k) {
					continue;
				}
				
				ans = min(ans, pre[0][i] + pre[1][j] + pre[2][k]);
			}
		}
	}

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


Measured memory_bytes: 1280
#include <cstring>
#include <iostream>
using namespace std;
int n, sx, sy, tx, ty; bool ok[11][10][10];
int main() {
	while (cin >> sx >> sy, sx + sy) {
		cin >> n; memset(ok, false, sizeof(ok));
		ok[0][sy][sx] = true;
		for (int i = 1; i <= n; i++) {
			cin >> tx >> ty;
			for (int j = 0; j < 1000; j++) {
				if (!ok[i - 1][j / 10][j % 10]) continue;
				for (int l = -2; l <= 2; l++) {
					for (int m = -2; m <= 2; m++) {
						if (0 <= j / 10 + l && j / 10 + l < 10 && 0 <= j % 10 + m && j % 10 + m < 10) {
							if (abs(ty - j / 10 - l) <= 1 && abs(tx - j % 10 - m) <= 1 && (abs(l) == 2 || abs(m) == 2) && abs(l * m) != 4) ok[i][j / 10 + l][j % 10 + m] = true;
						}
					}
				}
			}
		}
		int ret = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (ok[n][i][j]) ret = 1;
			}
		}
		cout << (ret ? "OK" : "NA") << endl;
	}
}

Measured memory_bytes: 3000
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = list(input())
    k = int(input())
    subs = set()
    lens = len(s)
    for i1 in range(k + 1):
        for i2 in range(lens - i1):
            subs.add("".join(s[i2:i2+i1+1]))
    subs_l = list(subs)
    subs_l.sort()
    print(subs_l[k-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 12944
#include"iostream"
#include"vector"
#include"string"
#include"map"
#include"set"
using namespace std;
int main(){
	string s;	
	cin >> s;
	set<char>st;
	for (int i = 0; i < s.length(); i++){
		st.insert(s[i]);
	}
	for (int i = 0; i < s.length(); i++){
		if (st.find(s[i]) != st.end()){
			s[i] = 'x';
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char) 
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
    
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let r: i32 = read();
  println!("{}", r * r);
}

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

int main() {
  int x,y,z;
  cin>>x>>y>>z;
  cout<<z<<" "<<x<<" "<<y<<endl;
  
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def parse_input(lines_as_string = None):


    lines = []
    if lines_as_string is None:
        lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    tokens = lines[0].split(" ")
    a, b, c = tokens

    return (a, b, c)


def solve(a, b, c):
    
    result = "No"
    if a + b > c and b + c > a and c + a > b:
        result = "Yes"

    return result

def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()


Measured memory_bytes: 3064
n, m, l = map(int, input().split())

def get_matrix(n):
	matrix = []
	for i in range(n):
		matrix.append(list(map(int, input().split())))
	return matrix

A = get_matrix(n)
B = get_matrix(m)

for i in range(n):
	for j in range(l):
		sum = 0
		for k in range(m):
			sum += A[i][k]*B[k][j]
		if j == l-1: print(sum)
		else: print(sum, end=' ')


Measured memory_bytes: 6568
#ifdef ONLINE_JUDGE

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

#define ui unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double

#define all(v) v.begin(), v.end()

#define speed ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ld PI = 3.1415926535897932384626;
ll MOD = 1000000007;
const ld EPS = 1e-9;
const int N = 3e5 + 7;

inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ui setBits(ui v) { ui c; for(c = 0 ; v; ++c) v &= (v - 1); return c; }
inline bool isPowerOfTwo(ui v) { return (v && !(v & (v - 1))); }
ll power(ll base, ull exp, ll mod = MOD) { 
	ll res = 1; base %= mod; 
	while(exp) { 
		if(exp & 1) res = (res * base)%mod; 
		exp >>= 1; base = (base * base)%mod; 
	} 
	return res; 
}
ll modInv(ll a, ll mod = MOD) { 
	if(mod == 1) return 0; 
	ll x = 1, y = 0, m = mod; 
	while(a > 1) { 
		ll q = a/m, t = m; m = a%m; a = t; t = y; y = x - q * y; x = t; 
	} 
	if(x < 0) x += mod; 
	return x; 
}
inline ui iabs(int x) { ui y = x; return (y > 0) ? y : -y; }
inline ll add(ll a, ll b, ll mod = MOD) { ll res = (a%mod + b%mod)%mod; return res; }
inline ll sub(ll a, ll b, ll mod = MOD) { ll res = (a%mod - b%mod + mod)%mod; return res; }
inline ll mult(ll a, ll b, ll mod = MOD) { ll res = (a%mod * b%mod)%mod; return res; }
inline ll div(ll a, ll b, ll mod = MOD) { ll res = (a%mod * modInv(b, mod))%mod; return res; }

#else

#include "custom.h"
using namespace std;

#endif

void openf() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif	
}

int main() {
	speed;
	openf();
	int N;
	cin >> N;
	int ans = ((N + 999)/1000) * 1000 - N;
	cout << ans << endl; 	
	return 0;
}  
  

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

total = A[0]
sum_a = sum(A)
ans = abs(sum_a - 2*total)
for i in range(1, N-1):
    total += A[i]
    ans = min(ans, abs(sum_a-2*total))

print(ans)

Measured memory_bytes: 24828
def main():
    x,y = map(int,input().split())
    tmp = [1]
    i = 2
    ans = 0
    # if x == y:
    #     ans += 1
    # a = factorization(x)
    # print(a)
    tempx = x

    for i in range(2, int(-(-x**0.5//1))+1):
        if tempx % i == 0:
            tmp.append(i)
            while tempx % i == 0:

                tempx //= i
    if tempx!=1:
        tmp.append(tempx)
    # print(tmp)

    for i,a in enumerate(tmp):
        if y % a == 0:
            tmp[i] = 1
        else:
            tmp[i] = 0
    print(sum(tmp))


if __name__=='__main__':
    main()


Measured memory_bytes: 38512
using System;
using System.Linq;
class c
{
    static void Main()
    {
        var inp = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        long ans = 0;
        while (true)
        {
            if (inp.Count(_ => _ % 2 == 1) > 0) break;
            else if (inp.Distinct().Count() == 1)
            {
                ans = -1;
                break;
            }
            var temp = new long[3] { inp[0], inp[1], inp[2] };
            inp[0] = (temp[1] + temp[2]) / 2;
            inp[1] = (temp[0] + temp[2]) / 2;
            inp[2] = (temp[0] + temp[1]) / 2;
            ans++;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
#include <stdio.h>

int euclid(int a,int b) {
	if(b==0)return a;
	else return euclid(b,a%b);
}

int main(void) {
	int a,b;
	int gcd;
	while(!feof(stdin)) {
		scanf("%d %d",&a,&b);
		if(feof(stdin))break;
		gcd=euclid(a,b);
		printf("%d %d\n",gcd,a/gcd*b);
	}
	return 0;
}

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

uint64_t gcd(uint64_t a, uint64_t b)
{
  return a == 0 ? b : gcd(b % a, a);
}

int main()
{
  int n;
  cin >> n;
  vector<uint64_t> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<uint64_t> lgcd(n + 1), rgcd(n + 1);
  for (int i = 1; i < n + 1; i++) {
    lgcd[i] = gcd(lgcd[i - 1], v[i - 1]);
  }
  for (int i = n - 1; i >= 0; i--) {
    rgcd[i] = gcd(rgcd[i + 1], v[i]);
  }
  uint64_t ans(0);
  for (int i = 0; i < n; i++) {
    ans = max(ans, gcd(lgcd[i], rgcd[i + 1]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560