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

int main(){
    int n, p;
    while(cin >> n >> p, n != 0){
        vector<int> candidates(n);
        int i = 0, w = p;
        while(true){
            if(w > 0){
                candidates[i]++;
                w--;
            }else{
                w = candidates[i];
                candidates[i] = 0;
            }
            if(candidates[i] == p){
                cout << i << endl;
                break;
            }
            i = (i + 1) % n;
        }
    }

    return 0;
}


Measured memory_bytes: 3092
#include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define int long long
#define double long double
#define INF INT_MAX
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int w, h, x, y;
signed main() {
	cin >> w >> h >> x >> y;
	cout << w * h / 2.0 << " " << (x == w / 2.0 && y == h / 2.0 ? 1 : 0) << endl;
}

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

class Program
{
  public static void Main(string[] args)
  {
    int n = int.Parse(Console.ReadLine());
    int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int ans = (Gcd(a[0],a[1]));
    for (int i = 2; i < n; i ++) ans = Gcd(ans, a[i]);
    Console.WriteLine(ans);
  }
  public static int Gcd(int a, int b) {
    if (a < b) return Gcd(b, a); // 引数を入替えて自分を呼び出す
    while (b != 0) {
      var remainder = a % b;
      a = b;
      b = remainder;
    }
    return a;
  }
}


Measured memory_bytes: 21728
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct p
{
	ll a;
	int b;
	int c;
};

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	mod r(1);
	mod p(n);
	int tn = n;

	for (int i = 1024 * 1024 * 1024, j = 30; j >= 1; j--, i /= 2)
		for (; j <= tn; tn -= j, r *= i);
	r -= 1;
	if (a > b)
	{
		int t = b;
		b = a;
		a = b;
	}

	mod ar(n);
	for (int i = 1; i < a; i++)
		ar *= n - i;
	for (int i = 2; i <= a; i++)
		ar /= i;
	r -= ar;
	for (int i = a; i < b; i++)
		ar *= n - i;
	for (int i = a + 1; i <= b; i++)
		ar /= i;
	r -= ar;

	printf("%lld", r.val);

	return 0;
}


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

bool ch (pair<int, int> p1, pair<int, int> p2) {
	return p1.second < p2.second;
}

int main(){
    int N, T;
    cin>>N>>T;
   	pair<int, int> BA[N];
    for(int i=0; i<N; i++){
      cin>>BA[i].second>>BA[i].first;
    }
    sort(BA, BA+N, ch);
    ll DP[N+1][T+1];
  	for(int i=0; i<N+1; i++){
      	for(int j=0; j<T+1; j++){
          	DP[i][j]=-1;
        }
    }
  	DP[0][0]=0;
  	ll Max=0;
    for(int i=0; i<N; i++){
        for(int j=0; j<=T-1; j++){
          	if(DP[i][j]==-1)continue;
			DP[i+1][j]=max(DP[i][j], DP[i+1][j]);
            if(j+BA[i].second<T){
                DP[i+1][j+BA[i].second]=max(DP[i+1][j+BA[i].second],DP[i][j]+BA[i].first);
            }
          Max = max (Max, DP[i + 1][j]);
				Max = max (Max, DP[i][j] + BA[i].first);
        }
    }
   cout<<Max;
   
}



Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sync ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD  1000000007 
#define lld long long
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
int32_t main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int ans=c-(a-b);
	if(ans>0)
		cout<<ans<<endl;
	else
		cout<<0<<endl;
}

Measured memory_bytes: 256
import itertools

h,w = map(int,input().strip().split())
grid = []
for _ in range(h):
    grid.append(list(input().strip()))

grid = filter(lambda r: any(map(lambda c : c == '#', r)), grid)
grid = zip(*grid)
grid = filter(lambda r: any(map(lambda c : c == '#', r)), grid)
grid = zip(*grid)

for r in grid:
    print(''.join(r))


Measured memory_bytes: 39408
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
int a[101];
int b[101];
bool used[51];

vector<int>G[51];

bool cc[101];

bool dfs(int s, int t){
	if(s==t){
		return true;
	}
	cc[s]=true;
	REP(i,G[s].size()){
		if(cc[G[s][i]]==false){
			bool aa=dfs(G[s][i],t);
			if(aa==true)return true;
		}
	}
	return false;
}

bool reach(int s,int t){
	REP(i,51){
		cc[i]=false;
	}
	return dfs(s,t);
}

bool check(){
	REP(i,51){
		G[i].clear();
	}
	REP(i,51){
		REP(j,51){
			if(used[j]==true){
				if(j!=0)
				G[i].push_back(i%j);
			}
		}
	}
	REP(i,N){
		if(reach(a[i],b[i])==false)return false;
	}
	return true;
}

int main(){
	cin>>N;
	REP(i,N){
		cin>>a[i];
	}
	REP(i,N){
		cin>>b[i];
	}
	REP(i,51){
		if(i==0){
			used[i]=false;
		}else{
			used[i]=true;
		}
	}
	if(check()==false){
		cout<<-1<<endl;
	}else{
		for(int i=50;i>0;i--){
			used[i]=false;
			if(check()==false){
				used[i]=true;
			}
			//cout<<i<<endl;
		}
		LL ans=0;
		LL now=1;
		REP(i,51){
			if(used[i]==true){
				ans+=now;
			}
			now*=2;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

    if (a <= 5) {
        cout << 0 << endl;
    }  else if (a <= 12) {
        cout << b/2 << endl;
    } else {
        cout << b << endl;
    }
    
    return 0;
}





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

#define MAX_N 1000
#define MAX_M 1000

int main(){
	ll x;
	cin >> x;
	ll ans = 100;
	ll year = 0;
	while(ans < x){
		ans = ans + ans * 0.01;
		year++;
	}
	cout << year << endl;

}



Measured memory_bytes: 3636
def max_heapify(A, i):
    left_id = 2 * i
    right_id = left_id + 1

    largest_id = i
    if left_id <= len(A) and A[left_id - 1] > A[largest_id - 1]:
        largest_id = left_id
    if right_id <= len(A) and A[right_id - 1] > A[largest_id - 1]:
        largest_id = right_id
    
    if i != largest_id:
        A[i - 1], A[largest_id - 1] = A[largest_id - 1], A[i - 1]
        max_heapify(A, largest_id)

def show(A):
    for i in A:
        print('', i, end = '')
    print()

heap_size = int(input())
A = list(map(int, input().split()))
for i in range(heap_size // 2, 0, -1):
    max_heapify(A, i)
show(A)


Measured memory_bytes: 63696
a,b,c,k=map(int,input().split())
if k%2==0:
    na=k*a+(k-1)*b+(k-1)*c
    nb=(k-1)*a+k*b+(k-1)*c
    if abs(na-nb)>10**18:
        print("Unfair")
    else:
        print(na-nb)
else:
    na=(k-1)*a+k*b+k*c
    nb=k*a+(k-1)*b+(k)*c
    if abs(na-nb)>10**18:
        print("Unfair")
    else:
        print(na-nb)
    


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

using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if (b<=a) cout<<"delicious";
  else if (b>a && b<=a+x)  cout<<"safe";
  else if (b>a+x) cout<<"dangerous";
  return 0;
}


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

using namespace std;

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

int main(void)
{
    int n, x;
    cin >> n >> x;
    vector<int> point(n),dis(n);
    for (int i = 0; i < n;i++){
        cin >> point.at(i);
        dis.at(i) = abs(point.at(i) - x);
    }
    int ans = dis.at(0);
    for (int i = 1; i < n; i++){
        int a = dis.at(i);
        if(ans<a)
            swap(ans, a);
        ans = max_common(ans,a);

    }
    cout << ans << endl;

    return 0;
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, K; cin >> N >> K;
  vector<bool> use(10, true);
  REP(i,K){
	int d; cin >> d;
	use[d] = false;
  }
  for(int i=N;;++i){
	string s = to_string(i);
	bool ok = true;
	REP(i,SZ(s))
	  if(!use[s[i]-'0'])
		ok = false;
	if(ok){
	  cout << i << endl;
	  break;
	}
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int m=9,n=9,i,j,sum;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            sum=i*j;
            printf("%dx%d=%d\n",i,j,sum);
        }
    }

return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int clamp(int mi, int val, int ma) {
    if (val <= mi) return mi;
    if (val >= ma) return ma;
    return val;
}
int main() {
    int X, K; cin >> X >> K;
    vector<tuple<int, int, int, int>> events;
    for (int i = 0; i < K; i++) {
        int R; cin >> R;
        events.emplace_back(R, 0, 0, 0);
    }
    int Q; cin >> Q;
    for (int i = 0; i < Q; i++) {
        int T, A; cin >> T >> A;
        events.emplace_back(T, 1, A, i);
    }
    vector<int> ans(Q);
    int left = 0, right = X, pos = 0, prev = 0, dir = -1;
    sort(begin(events), end(events));
    for (auto &tup : events) {
        int time, type, A, idx; tie(time, type, A, idx) = tup;
        if (type == 0 && dir == +1) {
            pos += time - prev;
            if (pos + right - left > X) right = max(left, left + X - pos);
            pos = min(pos, X);
            prev = time;
            dir *= -1;
        } else if (type == 0 && dir == -1) {
            pos -= time - prev;
            if (pos < 0) left = min(left - pos, right);
            pos = max(pos, 0);
            prev = time;
            dir *= -1;
        } else if (type == 1 && dir == +1) {
            A = clamp(left, A, right);
            ans[idx] = clamp(0, pos - left + A + time - prev, X);
        } else {
            A = clamp(left, A, right);
            ans[idx] = clamp(0, pos - left + A - time + prev, X);
        }
    }
    for (int a : ans) cout << a << '\n';
    return 0;
}


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

int main() {

  int N;
  cin >> N;

  map<pair<int,int>, int> red;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    red[make_pair(a,b)] = 0;
  }

  set<pair<int,int>> blue;
  for (int i = 0; i < N; i++) {
    int c, d;
    cin >> c >> d;
    blue.insert(make_pair(c,d));
  }

  int answer = 0;

  for (auto b:blue) {
    int x = b.first;
    int y = b.second;
    vector<pair<int,int>> c;
    for (auto r:red) {
      if (r.second == 0) {
        if (r.first.first < x && r.first.second < y) {
          c.push_back(make_pair(r.first.second, r.first.first));
        }
      }
    }
    if (0 < c.size()) {   
      sort(c.begin(), c.end(), greater<pair<int,int>>());
      red[make_pair(c[0].second,c[0].first)] = 1;
      answer++;
    }
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <queue>

template<typename T>
class TBinaryHeap
{
    std::vector<T> FArray;
    void BubbleUp(std::size_t Index)
    {
        assert(FArray.size() > Index);
        if(Index == 1) return;
        int Parent = Index / 2;
        if(FArray[Index] <= FArray[Parent]){
            return;
        }
        std::swap(FArray[Index], FArray[Parent]);
        BubbleUp(Parent);
    }
    void BubbleDown(std::size_t Index)
    {
        assert(FArray.size() > Index);
        std::size_t Left  = Index * 2;
        std::size_t Right = Left + 1;
        if(Left  >= FArray.size()) return;
        std::size_t Target = Right >= FArray.size() ? Left : FArray[Left] > FArray[Right] ? Left : Right;
        if(FArray[Target] > FArray[Index]){
            std::swap(FArray[Index], FArray[Target]);
            BubbleDown(Target);
        }
    }
public:
    TBinaryHeap()
    {
        FArray.reserve(2000000);
        FArray.resize(1); // dummy
    }
    void push(const T& Value)
    {
        FArray.push_back(Value);
        BubbleUp(FArray.size()-1);
    }
    void pop()
    {
        assert(FArray.size() >= 1);
        FArray[1] = FArray.back();
        FArray.pop_back();
        if(FArray.size() == 1) return; // dummy???????????????
        BubbleDown(1);
    }
    const T& top()
    {
        return FArray[1];
    }
};
int main()
{
    char Line[19];
    int Value;

    // std::priority_queue<int> S;
    TBinaryHeap<int> S;
    while(1){
        std::fgets(Line, 19, stdin);
        if(Line[0] == 'i'){
            S.push(std::atoi(&Line[7]));
        }else
        if(Line[1] == 'x'){
            std::printf("%d\n", S.top());
            S.pop();
        }else{
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 6248
#include <iostream>

using namespace std;

struct answers {
	int bend;
	int cend;
	int aend;
};

const int MAXN = 1E5;
answers ans[MAXN];

int main () {
	int n;
	cin >> n;
	int a, b, c;
	for (int i = 0; i < n; i ++) {
		cin >> a >> b >> c;
		if (i == 0) {
			ans[0].aend = a;
			ans[0].bend = b;
			ans[0].cend = c;
			continue;
		}
		ans[i].aend = max(ans[i - 1].bend, ans[i - 1].cend) + a;
		ans[i].bend = max(ans[i - 1].cend, ans[i - 1].aend) + b;
		ans[i].cend = max(ans[i - 1].bend, ans[i - 1].aend) + c;
	}
	int maxx = max(ans[n - 1].aend, ans[n - 1].bend);
	maxx = max(maxx, ans[n - 1].cend);
	cout << maxx << endl;
	return 0; 
}


Measured memory_bytes: 4716
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#define ll long long
#define maxn 200005
#define re register
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

void write(int x)
{
	if(x>=10) write(x/10);
	putchar(x%10+'0');
}

int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a*b>c*d) cout<<a*b;
	else cout<<c*d;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    k=int(input())
    print(l[k-1])
   

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
<?php
$n=trim(fgets(STDIN));
$a[]=0;
while($n>0){
  $x=trim(fgets(STDIN));
  isset($a[$x])?++$a[$x]:$a[$x]=1;
  --$n;
}
$n=trim(fgets(STDIN));
while($n>0){
  $x=trim(fgets(STDIN));
  if(isset($a[$x])){
    --$a[$x];
  }
  --$n;
}
echo max($a);

Measured memory_bytes: 4604
#include <stdio.h>
#include <string.h>

int main (){

    char A[12],B[12],C[12];
    scanf("%s %s %s", A, B ,C);
    for(int i = 0; i < strlen(A); i++){
        if(A[i] >= 'A' && A[i] <= 'Z'){
            return 1;
        }
    }
    for(int i = 0; i < strlen(B); i++){
        if(B[i] >= 'A' && B[i] <= 'Z'){
            return 1;
        }
    }
    for(int i = 0; i < strlen(C); i++){
        if(C[i] >= 'A' && C[i] <= 'Z'){
            return 1;
        }
    }
    if (A[strlen(A)-1] == B[0] && B[strlen(B)-1] == C[0]){
        printf("YES\n");
    }else {
        printf("NO\n");
    }


    return 0;
}

Measured memory_bytes: 1632
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter};
use std::io::*;
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        {
            let entries = [$(&stringify!([$arg]:), &$arg as &Debug),*];
            stderr().write_fmt(format_args!("{:?}\n", entries)).unwrap();
        }
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn main() {
    let (N, M) = read!(usize, i64);
    let A = read![[i64]];

    let mut S = vec![0; N];
    for i in 0..N {
        S[i] += A[i];
        S[i] %= M;

        if i + 1 < N {
            S[i + 1] += S[i];
            S[i + 1] %= M;
        }
    }

    // debug!(S);

    let mut k = 0_i64;
    let mut map = HashMap::new();
    map.insert(0, 1);
    for a in S {
        if let Some(&lk) = map.get(&a) {
            // debug!(a, lk);
            k += lk;
        }

        *map.entry(a).or_insert(0) += 1;
    }

    println!("{}", k);
}


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

int main() {
    string s;
    int n=0;
    cin >> s;
    for(int i=0;i<4;i++){
        if(s[i]=='+'){
            n++;
        } else {
            n--;
        }
    }
    cout << n << endl;
    
}

Measured memory_bytes: 256
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

x, a = map(int, input().split())
print('0') if x < a else print('10')

Measured memory_bytes: 5076
#include <cstdio>
using namespace std;

int main(){
	unsigned n[9], k, t;
	int s;
	for( scanf("%d", &s); s--; ){
		for(int i = 0; i < 9; ++i ){
			scanf("%x", &n[i]);
		}

		k = 0;
		for(int i = 0; i < 32; ++i){
			t = 0;
			for(int j = 0; j < 8; ++j){
				t += n[j] ^ k;
			}
			k |= (t ^ n[8]) & (1 << i);
		}
		printf("%x\n", k);
	}
}

Measured memory_bytes: 1032
#include<iostream>
using namespace std;
#define ll long long
const int maxn=5050;
const ll inf1=1e16+9;
ll a[maxn][maxn];
ll P[maxn],C[maxn];
ll n,k;
ll solve(int i)
{    ll j,ans;
     ll  Max=-inf1;
    ans=1;j=P[i]; 
    do
    {   a[i][ans]=a[i][ans-1]+C[j];
	   if(ans<=k&&Max<a[i][ans])
         Max=a[i][ans];
	   j=P[j];
	   ans++;
	   if(ans>k) break;
	}while(P[i]!=j);
	a[i][0]=ans-1;
	//printf("%lld ",a[i][1]);
    //	for(int j=0;j<=ans-1;j++)printf("%lld ",a[i][j]);printf("             %lld",Max);printf("\n");
	return Max;
}
int main ()
{   cin>>n>>k;
    for(int i=1;i<=n;i++)
      cin>>P[i];
    for(int i=1;i<=n;i++)
      cin>>C[i];
    ll Max=-inf1;
    for(int i=1;i<=n;i++)
    {  Max=max(solve(i),Max);
	}
	ll num,numl;
	for(int i=1;i<=n;i++)
	{   if(a[i][0]<k&&a[i][a[i][0]]>0)
	    {   num=a[i][a[i][0]]*(k/a[i][0]-1);
	        Max=max(Max,num);
	        for(int j=1;j<=a[i][0];j++)
	        {   numl=num+a[i][j];
	            Max=max(Max,numl);
			}
			num+=a[i][a[i][0]];
	       for(int j=1;j<=k%a[i][0];j++)
	       {   numl=num+a[i][j];
	           Max=max(numl,Max);
		   }
		}
	}
	cout<<Max<<endl;
	return 0;
}

Measured memory_bytes: 200828
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define int long long
int INF = 1e9+7;
signed main() {
    int K,T;
    cin >> K >> T;
    vector<int>a(T);
    for(int i = 0; i < T; i++) {
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    cout << max(0LL,a[T-1]-1-(K-a[T-1])) << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(final String[]  args){
        final Scanner sc = new Scanner(System.in);
        final int A = Integer.parseInt(sc.next());
        final int B = Integer.parseInt(sc.next());
        if (A + B >= 10){
            System.out.println("error");
        }
        else{
            System.out.println(A+B);
        }
        sc.close();
    }
}

Measured memory_bytes: 35604
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N,K;
    cin >> N >> K;
    int x[N];
    int left = -1;
    for(int i=0; i<N; i++){
        cin >> x[i];
        if(x[i] < 0) left = i;
    }
    if(left < 0) {
        cout << x[K-1] << endl;
        return 0;
    }
    int ans=1000000000;
    for(int i=max(0,left-K+1); i<=left+1 && K+i-1<N; i++){
        int y;
        if(left-i+1 != K && i != left+1){
            y = x[K+i-1] - x[i];
            y += min(-x[i],x[K+i-1]);
        }
        else if(left-i+1 == K) {
            y = -x[i];
        }
        else y = x[left+K];
        if(ans > y) ans = y;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
import java.io.*;
import java.math.BigDecimal;


public class Main {
	public static void main(String[] args) throws IOException {
		// System.out.println("Hello world");
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		while(true){
			double x, y;
			int n = 6;
			String c = br.readLine();
			if(c.equals(""))
				break;
			double[] arr = new double[n];
			for(int i = 0; i < n; i++){
				if(c.indexOf(" ") !=  -1){
					String str = c.substring(0, c.indexOf(" "));
					arr[i] =Double.parseDouble(str);
					c = c.substring(c.indexOf(" ") + 1);
				}
				else{
					arr[i] =Double.parseDouble(c);
				}
			}
			x = (arr[2]*arr[4] - arr[1]*arr[5]) / (arr[0]*arr[4] - arr[1]*arr[3]);
			y = (arr[2]-arr[0]*x)/ arr[1];

			Double ansX = new Double(x);
			Double ansY = new Double(y);
			if(ansX.equals(-0.0))
				x *= -1;
			if(ansY.equals(-0.0))
				y *= -1;
			
			System.out.printf("%.3f %.3f\n", x, y);
		}
	}
		

	  private static double round(double d){
		    int newScale = 3; // ツ渉ャツ青板点ツ暗按可コ6ツ個づ慊づ仰づ淞づゥ
		    BigDecimal bd = new BigDecimal(d);
		    BigDecimal bd2 = bd.setScale(newScale, BigDecimal.ROUND_HALF_UP);
		    double d2 = bd2.doubleValue();
		    return d2;
		  }
	  private static void keta(double d){
		  int k = (int)d;
		  System.out.print(k + ".");
		  d = d-k;
		  if(d < 0)
			  d *= -1;
		  d = round(d);
		  d *= 1000;
		  k = (int)d;
		  if(k == 0)
			  System.out.print("000");
		  else
			  System.out.print(String.format("%03", k));
	  }
}

Measured memory_bytes: 12000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC022A {
    class Program {
        static void Main(string[] args) {
            string S = Console.ReadLine();
            int num = S.Length;
            string ans = "";
            bool ok = false;
            string[] alph = new string[26] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
            bool[] alem = new bool[26];
            if (num != 26) {
                for (int i = 0; i < num; i++) {
                    string al = S.Substring(i, 1);
                    int numal = -1;
                    for (int j = 0; j < 26; j++) {
                        if (al == alph[j]) {
                            numal = j;
                            break;
                        }
                    }
                    alem[numal] = true;
                }
                int numfal = -1;
                for (int i = 0; i < 26; i++) {
                    if (!alem[i]) {
                        numfal = i;
                        break;
                    }
                }
                ans = S + alph[numfal];
            } else {
                int valnum = -1;
                int valchar = -1;
                for (int i = 0; i < 25; i++) {
                    string pre = S.Substring(i, 1);
                    string nex = S.Substring(i + 1, 1);
                    int prenum = -1;
                    int nexnum = -1;
                    for(int j = 0; j < 26; j++) {
                        if(pre == alph[j]) {
                            prenum = j;
                        }
                        if(nex == alph[j]) {
                            nexnum = j;
                        }
                    }
                    if (prenum < nexnum) {
                        valnum = i;
                        valchar = prenum;
                    }
                }
                if(valnum == -1) {
                    ok = true;
                } else {
                    for(int i=valnum + 1; i < 26; i++) {
                        string pre = S.Substring(i, 1);
                        int prenum = -1;
                        for (int j = 0; j < 26; j++) {
                            if (pre == alph[j]) {
                                prenum = j;
                            }
                        }
                        alem[prenum] = true;
                    }
                    int numb = -1;
                    for(int i = 0; i < 26; i++) {
                        if(alem[i] && valchar < i) {
                            numb = i;
                            break;
                        }
                    }
                    ans = S.Substring(0, valnum) + alph[numb];
                }
            }
            if (ok) {
                Console.WriteLine(-1);
            } else {
                Console.WriteLine(ans);
            }
        }
    }
}


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

int main() {
  rep(i,0,5){
    int a;
    cin >> a;
    if(a != i+1){
      cout << i+1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
     
#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)
     
#define INF LONG_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>
     
int main(){
  int f=0;
  string str;
  cin>>str;

  for(int i=0;i<str.length();i++){
    if(str[i]=='C')f=1;
    if(str[i]=='F' and f==1)f=2;
  }

  if(f==2)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
      
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

// 終了判定
template <typename T,
		  typename enable_if<is_integral<T>::value>::type* = nullptr>
bool finds(T left, T right) {
	return right - left > 1;
}

// 二分探索
template <typename T>
T bin_search(T left, T right, auto pred) {
	while(finds<T>(left, right)) {
		T middle = (left + right) / 2;
		if(pred(middle)) {
			left = middle;
		} else {
			right = middle;
		}
	}
	return left;
}

ll sad(VLL& a, ll b) {
	ll ret = 0;
	REP(i, a.size()) { ret += abs(a[i] - (b + i + 1)); }
	return ret;
}

int main() {
	int n;
	cin >> n;
	VLL a(n);
	REP(i, n) { cin >> a[i]; }

	ll result = bin_search<ll>(
		-n, 1000000010LL, [&](ll b) { return sad(a, b - 1) > sad(a, b); });

	cout << sad(a, result) << endl;
	return 0;
}


Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3001;
ll grid[N][N];
ll memo[N][N][4];
ll solve(int r,int c,int items)
{
	if(r <= 0 || c <= 0)
		return -1e7;
	if(memo[r][c][items] != -1)
		return memo[r][c][items];
	if(r == 1 && c == 1){
		if(items >= 1 && grid[r][c])
			return grid[r][c];
		return 0;
	}
	if(items == 0)
		return memo[r][c][items] = max(solve(r-1,c,3),solve(r,c-1,items));
	if(grid[r][c] == 0)
		return memo[r][c][items] = max(solve(r,c-1,items),solve(r-1,c,3));
	if(grid[r][c])
		return memo[r][c][items] = max(grid[r][c] + max(solve(r,c-1,items-1),solve(r-1,c,3)),max(solve(r,c-1,items),solve(r-1,c,3)));
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int R,C,K;
	cin >> R >> C >> K;
	memset(grid,0,sizeof(grid));
	memset(memo,-1,sizeof(memo));
	for(int i = 0;i < K;++i){
		int r,c;
		ll v;
		cin >> r >> c >> v;
		grid[r][c] = v;
	}
	ll ans = solve(R,C,3);
	cout << ans << "\n";
}


Measured memory_bytes: 356212
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	vector<int> h(n);
	for (int i = 0; i < n; i++)
	{
		cin >> h.at(i);
	}

	vector<int> dp(n, inf);
	dp.at(0) = 0;


	for (int i = 1; i < n; i++)
	{
		dp.at(i) = min(dp.at(i), dp.at(i - 1) + abs(h.at(i) - h.at(i - 1)));
		if (i - 2 >= 0)
		{
			dp.at(i) = min(dp.at(i), dp.at(i - 2) + abs(h.at(i) - h.at(i - 2)));
		}
	}

	cout << dp.at(n - 1) << endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(c>=b||d<=a) cout << 0;
	else if(c>=a&&d<=b) cout << d-c;
	else if(a>c&&b<d) cout <<b-a;
	else if(c<b&&d>b) cout << b-c;
	else if(d>a&&c<a) cout << d-a;
 
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{
    char a;
    int b;
}re;
int n;
void merge(re a[], int left, int mid, int right){
    int i = left;
    int j = mid+1;
    re t[n];
    int k = 0;
    while(i <= mid && j <= right){
        if(a[i].b <= a[j].b) t[k++] = a[i++];
        else t[k++] = a[j++];
    }
    while(i <= mid) t[k++] = a[i++];
    while(j <= right) t[k++] = a[j++];

    for(int p = 0; p < k; p++){
        a[left + p] = t[p];
    }
}
void mergeSort(re a[], int left, int right){
    if(left < right){
        int mid = (left + right) / 2;
        mergeSort(a, left, mid);
        mergeSort(a, mid+1, right);
        merge(a, left, mid, right);
    }
}

int partition(re a[], int p, int r){
    int i = p-1;
    int x = a[r].b;
    for(int j = p; j < r; j++){
        if(a[j].b <= x){
            i++;
            re t = a[i];
            a[i] = a[j];
            a[j] = t;
        }
    }
    re temp = a[i+1];
    a[i+1] = a[r];
    a[r] = temp;
    return i+1;
}
void quickSort(re 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(){
    scanf("%d", &n);
    re a[n];
    re b[n];
    re c[n];
    for(int i = 0; i < n; i++){
        char ch; int d;
        getchar();
        scanf("%c %d", &ch, &d);
        a[i].a = ch, b[i].a = ch, c[i].a = ch;
        a[i].b = b[i].b = c[i].b = d;
    }

    mergeSort(b, 0, n-1);
    quickSort(c, 0, n-1);
    int flag = 1;
    for(int i = 0; i < n; i++){
        if(b[i].a != c[i].a || b[i].b != c[i].b ){
            flag = 0;break;
        }
    }
    if(flag) printf("Stable\n");
    else printf("Not stable\n");
    for(int i = 0; i < n; i++){
        printf("%c %d\n", c[i].a, c[i].b);
    }
    return 0;
}


Measured memory_bytes: 4836
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
			int N = nextInt();
			String s = next();
			if(N >= 3200){
				myout(s);
			}else{
				myout("red");
			}
	}
	//Method addition frame start




	//Method addition frame end
}


Measured memory_bytes: 32708
n=int(input())
arr=[int(input()) for _ in range(n)]
pos=[0]*(n+1)
for i in range(n):
  pos[arr[i]]=i
cnt=[0]*(n+1)
cnt[1]=1
for i in range(2,n+1):
  if pos[i-1]<pos[i]:
    cnt[i]=cnt[i-1]+1
  else:
    cnt[i]=1
print(n-max(cnt))

Measured memory_bytes: 26796
def distribute(n, person, min, max, mode="even"):
    # n 個を person 人に分配する
    # 返り値は [[a (個), a 個もらう人数], ...]
    if person==0 and n==0:
        return []
    elif not min*person <= n <= max*person:
        return None
    elif mode=="even":
        q, m = divmod(n, person)
        if m==0:
            return [[q, person]]
        else:
            return [[q, person-m], [q+1, m]]
    elif mode=="greedy":
        n -= min * person
        q, m = divmod(n, max-min)
        if m==0:
            return [[min, person-q], [max, q]]
        else:
            return [[min, person-1-q], [min+m, 1], [max, q]]
    else:
        raise ValueError("'mode' must be 'even' or 'greedy'.")

import numpy as np
N, A, B = map(int, input().split())
Ans = np.arange(N, 0, -1, dtype=np.int64)
Ans[:A] = np.flipud(Ans[:A])
c = N-A
D = distribute(c, B-1, min=1, max=A, mode="even")
if D is None:
    print(-1)
    exit()
idx = A
for p, n in D:
    for _ in range(n):
        Ans[idx:idx+p] = np.flipud(Ans[idx:idx+p])
        idx += p
print(" ".join(str(int(a)) for a in Ans))


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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,k; cin>>a>>b>>k;
	for (int d=min(a,b); d>=1; d--) {
		if(a%d==0&&b%d==0) {
			k--;
			if(!k) {
				cout<<d<<"\n";
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#B - Shiritori(ABC109)
N=int(input())
s=True
w1=input()
W=[w1]
for i in range(N-1):
    w2=input()
    W.append(w2)
    if len(set(W))==len(W) and w1[-1]==w2[0]:
        w1=w2
    else:
        s= False
if s:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
//
// Created on 2020/07/12.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int h,w;
    cin>>h>>w;

    int ok = 0;

    vector<vector<int>>grid(h + 2,vector<int>(w + 2,-1));
    for (int i = 1; i <= h; ++i) {
        string line;
        cin>>line;
        for (int j = 1; j <= w; ++j) {
            if(line[j-1] == '.'){
                grid[i][j] = INF;
                ok ++;
            }else{
                grid[i][j] = -1;
            }
        }
    }
    queue<vector<int>>q;
    vector<pair<int,int>>move = {{1,0},{0,1},{-1,0},{0,-1}};
    q.push({1,1,1});
    //h,w,cnt
    while(!q.empty()){
        int now_h = q.front()[0];
        int now_w = q.front()[1];
        int cnt = q.front()[2];
        if(grid[now_h][now_w] > cnt){
            grid[now_h][now_w] = cnt;
            for (int i = 0; i < move.size(); ++i) {
                int next_h = now_h + move[i].first;
                int next_w = now_w + move[i].second;
                if(grid[next_h][next_w] > cnt){
                    q.push({next_h,next_w,cnt + 1});
                }
            }
        }
        q.pop();
    }
    int ans;
    if(grid[h][w] == INF){
        ans = -1;
    }else{
        ans = ok - grid[h][w];
    }
    cout<<ans<<endl;
    return 0;
}


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



namespace Test1 {

    class ClassMain {

        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine())!=null) {
                string[] strs = line.Split(' ');
                int n0 = int.Parse(strs[0]), n1 = int.Parse(strs[1]);
                int[] ints = new int[2];
                ints[0] = n0; ints[1] = n1;
                euclid(ints);
                Console.WriteLine(ints[1]);
            }
        }
        private static void euclid(int[] ints) {
            int large = Math.Max(ints[0],ints[1]);
            int small = Math.Min(ints[0],ints[1]);
            while (large % small != 0) {
                int reg = large%small;
                large = small;
                small = reg;
            }
            ints[1] = small;
        }
    }
}

Measured memory_bytes: 5596
#include<stdio.h>

int f(int n){
	for(int i=2;i*i<=n;i++)if(n%i==0)return 0;
	return 1;
}

int main(){
	int n;
	scanf("%d",&n);
	int ans=0;
	while(n--){
		int t;
		scanf("%d",&t);
		ans+=f(t);
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 2052
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

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

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}
	//------------------------------------------
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

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



	public void exec() throws Exception{
		long H = sc.nextLong();
		long order = 1;
		long sum = 0;
		while(H>0) {
			sum += order;
			H = (H>>1);
			order = order*2;
		}
		out.println(sum);

	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n,ok=0;
	cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		b[i]=a[i];
	}
	sort(b,b+n);
	for(int i=0;i<n;i++)
	{
		if(a[i]!=b[i])
		{
			ok++;
		}
	}
	if(ok>2)
	{
		cout<<"NO"<<endl;
	}
	else
	{
		cout<<"YES"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;
#ifdef LOCAL
#define debug(x)   cerr<<#x<<" = "<<x<<endl
#else
#define debug(x) 
#endif
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define pii pair<int,int>
#define endl '\n'
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
const int inf = 1e18 + 5;
signed main()
{
    #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif 
    IOS
    int depth = 0;
    int h; cin>>h;
    while(h>0)
    {
        h /= 2;
        depth++;
    }
    int ans = 0;
    for(int i=1;i<=depth;i++)
    {
        ans += pow(2,i-1);
        //else ans += pow(2,i);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
H=int(input())+1
A=[0]+list(map(int,input().split()))
def s(x,y):A[x],A[y]=A[y],A[x];h(y)
def h(i):
 l=2*i;r=l+1
 if r<H:
  if A[i]<A[l]:
   if A[l]<A[r]:s(i,r)
   else:s(i,l)
  elif A[i]<A[r]:s(i,r)
 elif l<H and A[i]<A[l]:s(i,l)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 65488