akhauriyash/Code-Regression huggingface dataset:
def main():
    S = str(input())
    sl =  list(S)
    if len(S) != 26:
        alpha = [i for i in range(26)]
        for i in sl:
            alpha.remove(ord(i)-97)
        n = min(alpha)
        print(S+chr(97+n))
    elif S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        alpha = []
        for i in range(25):
            alpha.append(S[-i-1])
            if ord(max(alpha)) > ord(S[-i-2]):
                alpha.sort()
                for j in alpha:
                    if ord(j) > ord(S[-i-2]):
                        print(S[:(-i-2)]+j)
                        exit()

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
P, Y = [0] * M, [0] * M
city_list = [[] for _ in range(N)]

for i in range(M):
	p, y = map(int, input().split())
	city_list[p - 1].append(y)
	P[i] = p
	Y[i] = y
	
for i in range(N):
	city_list[i].sort()
	
for i in range(M):
	print('{:06}{:06}'.format(P[i], bisect.bisect_right(city_list[P[i] - 1], Y[i])))


Measured memory_bytes: 60208
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,sum=0;
  cin>>n;
  for(long long int i=1;i<=n;i++)
  {
    if((i%3==0)||(i%5==0))
    {
      continue;
    }
    else
    {
      sum+=i;
    }
  }
  cout<<sum;
}

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

int main(){
  int N, M;
  cin >> N;
  vector<string> blue(N);
  for (int i=0; i<N; i++){
    cin >> blue.at(i);
  }
  cin >> M;
  vector<string> red(M);
  for (int i=0; i<M; i++){
    cin >> red.at(i);
  }
  
  vector<int> sum_vec(N);
  for (int i=0; i<N; i++){
    string tmp_string = blue.at(i);
    // sum_vec.at(i) += 1;
    
    // 青いカードで同じ文字列を探す
    for (int j=0; j<N; j++){
      if (tmp_string==blue.at(j)){
        sum_vec.at(i) += 1;
      } else {
        ;
      }
    }
    
    // 赤いカードで同じ文字列を探す あったら-1
    for (int j=0; j<M; j++){
      if (tmp_string==red.at(j)){
        sum_vec.at(i) -= 1;
      } else {
        ;
      }
    }
  }
  
  // sum_vecから最大の値を取得
  int max = 0;
  for (int i=0; i<sum_vec.size(); i++){
    if (sum_vec.at(i) > max){
      max = sum_vec.at(i);
    } else {
      ;
    }
  }
  
  // 最大がマイナスだったら0
  if (max < 0){ 
    cout << 0 << endl;
  } else { 
    cout << max << endl;
  }
  
}

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

int main() {
    cout.tie(0)->sync_with_stdio(0);
    int X, N; cin >> X >> N;
    vector<bool> good(110, true);
    for (int i = 0; i < N; ++i) {
        int a; cin >> a;
        good[a] = false;
    }
    
    int a = X-1, b = X+1, res = 0;
    if (good[X]) cout << X << '\n';
    else {    
        while(a > -1 && b <= 105) {
            if (a > -1 && good[a]) {
                res = a;
                break;
            }
            else if (b <= 105 && good[b]) {
                res = b;
                break;
            }
            --a, ++b;
        }
       cout << res << '\n';
    }
}


Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"

void main()
{
	int nedan, maisu, okane;

	scanf("%d", &nedan);
	maisu = nedan / 1000;
	okane = nedan - (maisu * 1000);
	

	if (okane == 0)
		printf("0");

	else
	{
		okane = 1000 - okane;
		printf("%d", okane);
	}


}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
long long n,m,total;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    if (n%2==1){
        cout<<0;
        return 0;
    }
    n/=2;
    for (long long i=5;n/i>=1;i*=5){
        total+=n/i;
    }
    cout<<total;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	int h, w, n, sx, sy;cin >> h >> w >> n >> sy >> sx;
	string a, b;cin >> a >> b;

	int U = 1;
	int D = h;
	int L = 1;
	int R = w;

	REV(i, n){
		if(b[i] == 'U')D = min(h, D + 1);
		if(b[i] == 'D')U = max(1, U - 1);
		if(b[i] == 'R')L = max(1, L - 1);
		if(b[i] == 'L')R = min(w, R + 1);

		if(U > D || L > R){
			cout << "NO" << endl;
			return 0;
		}

		if(a[i] == 'U')U++;
		if(a[i] == 'D')D--;
		if(a[i] == 'R')R--;
		if(a[i] == 'L')L++;

		if(U > D || L > R){
			cout << "NO" << endl;
			return 0;
		}
	}

	if(sx >= L && sx <= R && sy >= U && sy <= D){
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 776
#include<iostream>
using namespace std;
int main(){
  int n,ans,t;
  while(cin>>n){
    ans = 1;
    t = 1; 
    for(int i=1;i<=n;i++){
      ans += t;
      t++;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    int ans = 0;
    ans = a - (b * 2);
    if(ans < 0){
        cout << 0 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
def kaibun(w):
    n=len(w)
    if w[:n//2]==w[::-1][:n//2]:
        return True
    return False

s=input()
n=len(s)
if kaibun(s) and kaibun(s[:(n-1)//2]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std; typedef long long ll;
int main(){ 
 int a,b,c; cin >> a >> b >> c;
  if( a == b){ cout << c << endl; return 0;}
  else if( b == c){ cout << a << endl; return 0;}
  else{ cout << b << endl; return 0;
      }
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[][] A = new long[N][2];
		for (int i = 0; i < N; ++i) {
			A[i] = new long[] { sc.nextLong(), i };
		}
		Arrays.sort(A, new Comparator<long[]>() {
			@Override
			public int compare(long[] o1, long[] o2) {
				return Long.compare(o1[0], o2[0]);
			}
		});

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < N; ++i) {
			if (A[N - 1][1] == i) {
				pw.println(A[N - 2][0]);
			} else {
				pw.println(A[N - 1][0]);
			}
		}
		pw.close();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

int main() {
	int n;
	cin >> n;
	int k = 0;
	vector<char> ans;
	if (n==0) ans.push_back('0');
	while(n!=0) {
		char w;
		if (n%2) {
			w = '1';
			if(k%2) n = (n + 1) / 2;
			else n = (n - 1) / 2;
		}
		else {
			w = '0';
			n /= 2;
		}
		k++;
		ans.push_back(w);
	}
	int len = ans.size();
	for (int i=len-1;i>=0;i--) printf("%c", ans[i]);
	printf("\n");

	return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.conv;
import std.math;
import std.string;

void main()
{
	auto tokens = split(chomp(readln()));
	auto h = to!int(tokens[0]);
	auto w = to!int(tokens[1]);
	int[][] cell;
	cell.length = h;
	foreach (y; 0..h)
	{
		foreach (token; split(chomp(readln())))
		{
			cell[y] ~= to!int(token);
		}
	}

	int[][] result;
	foreach (y; 0..h-1)
	{
		foreach (x; 0..w)
		{
			if (cell[y][x] % 2 == 1)
			{
				--cell[y][x];
				++cell[y+1][x];
				result ~= [y+1, x+1, y+2, x+1];
			}
		}
	}
	foreach (x; 0..w-1)
	{
		if (cell[h-1][x] % 2 == 1)
		{
			--cell[h-1][x];
			++cell[h-1][x+1];
			result ~= [h, x+1, h, x+2];
		}
	}

	writeln(result.length);
	foreach (e; result)
	{
		writeln(e[0], " ", e[1], " ", e[2], " ", e[3]);
	}
	stdout.flush();
}

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

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair
using namespace std;
using ll = long long;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
int mod;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;

    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

    cin >> mod;
    vector<bool> m(mod + 1);

    mint x = 7;
    int ans = 1;
    while (true) {
        if (m[x.x] == true) {
            cout << -1 << endl;
            return 0;
        }
        if (x.x == 0) break;
        m[x.x] = true;
       
        x *= 10;
        x += 7;
        ans++;
    }

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
int main()
{
	map<int,int> mp;
	int a,b,c,n,ar[200009],flag=0,i;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
    	scanf("%d",&ar[i]);
    }

    for(i=1; i<=n; i++)
    {
    	a=ar[i];
    	if(mp.find(a)==mp.end())
    	{
    		mp[a]=1;
    	}
    	else
    	{
    		flag=1;
    		break;

    	}
    }
    if(flag) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;

    return 0;
}

Measured memory_bytes: 10368
# -*- coding: utf-8 -*-
import sys


N,M = map(int,input().split())
A = list(map(int,input().split()))


res = 0
Total = sum(A)
for a in A:
    if a*4*M>=Total:
        res += 1
if res>=M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38484
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  s=list(S())

  s[k-1]=s[k-1].lower()
  return ''.join(s)

print(main())


Measured memory_bytes: 7704
#include<bits/stdc++.h>
using namespace std;
#define bolt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
bool isprime(ll n){for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x%mod;while(y>0){if(y&1)res=((res%mod)*(x%mod))%mod;y=y>>1;x=((x%mod)*(x%mod))%mod;}return res;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res=((res%mod)*((n-i)%mod))%mod;res=((res%mod)*(power(i+1,mod-2))%mod)%mod;}return res;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll sol=a>b?a:b;return sol;}
ll min(ll a,ll b){ll sol=a<b?a:b;return sol;}
int main()
{
   bolt;
   ll h,a;
   cin>>h>>a;
   ll sum=0;
   for (ll i=0;i<a;i++)
   {
      ll s;
      cin>>s;
      sum+=s;
   }
   if (sum<h)
      cout<<"No\n";
   else
      cout<<"Yes\n";

}


Measured memory_bytes: 256
n=int(input())
l=[k for k in range(1,n+1)]
phrase=[]
ans=1
a=1
def prime(x):
    i=2
    while i*i<=x:
        if x%i==0:
            return False
        i+=1
    return True
for i in range(2,n+1):
    if prime(i):
        phrase.append(i)
for j in phrase:
    for m in range(n):
        while l[m]%j==0:
            a+=1
            l[m]=l[m]/j
    ans=ans*a
    a=1
print(ans%1000000007)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

vector<vector<P>> g(100001);
vector<ll> dis(100001,0LL);
vector<bool> used(100001,false);

bool flag = true;

void dfs(int i,ll d){
	for(int j = 0; j < g[i].size(); j++) { 
		if (used[g[i][j].fs] && (d + g[i][j].sc != dis[g[i][j].fs])){
			flag = false;
			break;
		}
		else if(!(used[g[i][j].fs])){
			dis[g[i][j].fs] = d + g[i][j].sc;
			used[g[i][j].fs] = true;
			dfs(g[i][j].fs,dis[g[i][j].fs]);
		}
	}
}


int main(){
	int n,m;cin>>n>>m;
	ll l,r,d;

	for(int i = 0; i < m; i++) {
		cin>>l>>r>>d;
		g[l].pb(mp(r,d));
		g[r].pb(mp(l,-1LL * d));
	}
	for(int i = 1; i <= n; i++) {
		if (!(used[i])){
			used[i] = true;
			dfs(i,0LL);
		}
	}
	if (flag){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 16512
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
char c[101],a[101],d[101],e[101],f[101],g[101];
int main()
{
	 int lenc,l1,i,pd=0; 
     scanf("%s",c); 
     for(i=0;;i++)
     {
     	if(c[i]=='\0')break;
     }
     lenc=i;
     for(i=0;i<lenc;i++)
     {
     	a[lenc-i-1]=c[i];
     }
     
     if(strcmp(c,a)==0)
     {
     	l1=(lenc-1)/2;
     	for(i=0;i<l1;i++)
     	{
     		d[l1-i-1]=c[i];
     		e[i]=c[i];
     	}
     	
        if(strcmp(e,d)!=0)cout<<"No";
        else
        {
        	l1=(lenc+3)/2-1;
        	for(i=l1;i<lenc;i++)
        	{
        		f[i-l1]=c[i];
        	}
        	for(i=0;i<lenc-l1;i++)
        	{
        		g[lenc-l1-i-1]=f[i];
        	}
        	if(strcmp(f,g)!=0)cout<<"No";
        	else cout<<"Yes";
        }
     }
     else
     cout<<"No"; 
    
} 

Measured memory_bytes: 256
MOD=10**9+7
N=int(input())

dp=[[0 for _ in range(3)] for _ in range(64)]
dp[63][0]=1

for d in range(62,-1,-1):
  b=(N>>d)&1 
  s=dp[d+1][:]
  dp[d][0]=dp[d+1][0]+(1^b)*dp[d+1][1] % MOD
  dp[d][1]=b*dp[d+1][0]+dp[d+1][1] % MOD
  dp[d][2]=(1+b)*dp[d+1][1]+3*dp[d+1][2] % MOD

print(sum(dp[0][:]) % MOD)

Measured memory_bytes: 9152
S = input()
N = len(S)
result = True

if S != S[::-1]:
    result = False

S2 = S[0:int((N-1)/2)]
if S2 != S2[::-1]:
    result = False

S3 = S[int((N+1)/2):]
if S3 != S3[::-1]:
    result = False

if result:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include<stdio.h>
int dp[50];

int fib(int num){

  if(num==0||num==1)return dp[num]=1;
  if(dp[num]!=-1)return dp[num];
  dp[num]=fib(num-1)+fib(num-2);
  return dp[num];
}

int main(void){
  int n,i;
  scanf("%d",&n);
  for(i=0;i<50;i++)dp[i]=-1;
  printf("%d\n",fib(n));
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>

using namespace std;

int main(){
    int n;
    int d;
    int result;

    cin>>n>>d;
    
    if(n%(2*d+1)==0){
        cout<<n/(2*d+1)<<endl;
    }else{
        cout<<n/(2*d+1)+1<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
using ll = long long;
int fact(ll n){
    ll ans = 1;
    lrep(i, 0, n){
        ans *= (i+1);
    }
    return ans;
}
int main() {
    ll N; 
    cin >> N;
    vector<int>row(N);
    vector<int>rows(N);
    vector<int>rowg(N);
    int s = 0, g = 0, count = 0;
    rep(i, 0, N) row[i] = i+1;
    rep(i, 0, N) cin >> rows[i];
    rep(i, 0, N) cin >> rowg[i];
    lrep(i, 0, fact(N)){
        if(row == rows) s = count;
        if(row == rowg) g = count;    
        next_permutation(row.begin(), row.end());
        count++;
    }
    cout << abs(s - g) << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;

typedef pair<int,int> P;

int w, h, ans;
int t[12][12];
bool closed[12][12];

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

bool judge(int array[12][12]){
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(array[i][j] != array[0][0]){
        return false;
      }
    }
  }

  return true;
}

void show(int s[12][12]){
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout<<s[i][j]<<" ";
    }
    cout<<endl;
  }
  cout<<"--\n";
}

void nextState(int from[12][12], int to1[12][12], int to2[12][12]){
  int color1, color2;
  if(from[0][0] == 0)      { color1 = 1; color2 = 2; }
  else if(from[0][0] == 1) { color1 = 0; color2 = 2; }
  else                     { color1 = 0; color2 = 1; }

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      to1[i][j] = to2[i][j] = from[i][j];
    }
  }

  queue<P> open;
  open.push(P(0, 0));
  memset(closed, 0, sizeof(closed));
  to1[0][0] = color1;
  to2[0][0] = color2;

  while(!open.empty()){
    P p = open.front();
    open.pop();

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

      if(0 <= nx && nx < w && 0 <= ny && ny < h && !closed[ny][nx] && from[ny][nx] == from[0][0]){
        to1[ny][nx] = color1;
        to2[ny][nx] = color2;
        closed[ny][nx] = true;
        open.push(P(nx, ny));
      }
    }
  }
}

void solve(int s[12][12], int cnt){
  if(judge(s)){
    ans = min(ans, cnt);
    return;
  }
  if(cnt >= ans){
    return;
  }

  int next1[12][12];
  int next2[12][12];

  nextState(s, next1, next2);
  solve(next1, cnt + 1);
  solve(next2, cnt + 1);
}

int main(){
  while(cin >> w >> h, w || h){
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        char ch;
        cin >> ch;

        if(ch == 'R')      t[i][j] = 0;
        else if(ch == 'G') t[i][j] = 1;
        else if(ch == 'B') t[i][j] = 2;
      }
    }

    ans = 18;
    solve(t, 0);

    cout << ans << endl;
  }
}

Measured memory_bytes: 1220
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
int asc(const void *a,const void *b){
return *(int *)b - *(int *)a;
}
int main(int argc,char *argv[]){
 int n,k;
 scanf("%d%d",&n,&k);
 int a[n],ans=0;
 rep(i,n)scanf("%d",&a[i]);
 qsort((void *)a,n,sizeof(a[0]),asc);
 rep(i,k)ans+=a[i];
 printf("%d\n",ans);
 return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<ctype.h>
#include<math.h>
#define PI 3.14159265359
#define N_MAX 1000
#define NUM 1000
#define min(x,y) ((x) < (y) ? (x) : (y))
#define max(x,y) ((x) > (y) ? (x): (y))

int gcd(int x, int y);

int main()
{
  int a, b, ans;
  scanf("%d %d", &a, &b);
  printf("%d\n",gcd(a,b));
  return 0;
}

int gcd(int x, int y)
{
  if(1 < x && 1 < y)
    {
      if(x == y) return x;
      else return gcd(min(x,y),max(x,y)%min(x,y));
    }
  else if(x == 0 || y == 0) return max(x,y);
  else return 1;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
using vs= vector<string>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

bool kaibun(string s){
  string st=s;
  reverse(all(s));
  if(st==s){
    return true;
  }else{
    return false;
  }
}

int main(){
  string s,s2,s3;
  int n,ans=0;
  cin >> s;
  n= s.size();
  if(kaibun(s)){
    ans++;
  }
  s2= s.substr(0,(n-1)/2);
  if(kaibun(s2)){
    ans++;
  }
  s3= s.substr((n+3)/2-1,n);
  if(kaibun(s3)){
    ans++;
  }
  if(ans==3){
    cout << "Yes";
  }else{
    cout << "No";
  }
  
  return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {
  val Array(l, r)  = StdIn.readLine().split(" ").map(_.toInt)

  val lr = (l / 2019).floor
  val rr = (r / 2019).floor

  if (lr != rr) {
    println(0)
  } else {

    val lm = l % 2019
    val rm = r % 2019

    if (lm == 0 || rm == 0) {
      println(0)
    } else {
      var v = 2019
      for( i <- lm until rm) {
        for (j <- i + 1 to rm) {
          v = math.min(v, (i * j) % 2019)
        }
      }
      println(v)
    }
//      println((lm to rm).combinations(2).map{ i => (i(0) * i(1)) % 2019 }.min)
  }
}
  



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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)

#define L(x) ((x)*2)
#define R(x) ((x)*2+1)

#ifndef __SOULTCH
#define endl '\n'
#define debug(...) 
#else
#define __debug_a(v) cout << " [+] " << #v << " = " << (v) << endl
#define __debug_b(v) cout << "     " << #v << " = " << (v) << endl
#define debug1(v1) __debug_a(v1);
#define debug2(v1, v2) __debug_a(v1), __debug_b(v2);
#define debug3(v1, v2, v3) __debug_a(v1), __debug_b(v2), __debug_b(v3);
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define debug(...) GET_MACRO(__VA_ARGS__, debug3, debug2, debug1)(__VA_ARGS__)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << pai.first << ' ' << pai.second;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    rep(i, sz(v)) cout << v[i] << ' ';
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> s) {
    for (T p : s) cout << p << ' ';
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> s) {
    for (auto p : s) cout << '(' << p << ") ";
    return os;
}

template<typename T, typename V>
istream &operator>>(istream &is, pair<T, V> &pai) {
	is >> pai.first >> pai.second;
	return is;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int v = 10, s = 0, a;
    rep(i, 5) cin >> a, v = min(v, (a-1+10)%10+1), s += ((a-1)/10+1)*10;

    cout << s-(10-v);
}








Measured memory_bytes: 256
def A():
    x = input()
    arr = list(map(int, x.split()))
    medic = arr[0] + arr[1]
    poison = arr[2]
    eat_poison = 0

    delicious_0 = arr[1]
    delicious_1 = arr[2]
    # calclate eat poison
    even = poison - medic
    if even > 0:
        eat_poison = medic + 1
    else:
        eat_poison = poison
    
    delicious = eat_poison + arr[1]
    print(delicious)


if __name__=='__main__':
    A()

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		int b[31];
		memset(b, 0, sizeof(b));
		b[0] = n;
		while (true)
		{
			int t = find(b, b+n, 0) - b;
			for (int i = 0; i < t-1; ++i)
				printf("%d ", b[i]);
			printf("%d\n", b[t-1]);

			if (t == n)
				break;

			int u;
			u = t-1;
			while (b[u] == 1)
				--u;
			--b[u];
			++u;
			fill(b+u, b+n, 0);
			int s = t - u + 1;
			while (s--)
			{
				if (b[u] == b[u-1])
					++u;
				++b[u];
			}
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

#define PI 3.14159265358979323846

int main(){
    ll a, b, h, m;
    cin >> a >> b >> h >> m;
    double c1, c2;
    c1 = ((60*h+m)*0.5);
    c2 = (m*6)%360;
    double x1, x2, y1, y2;
    x1 = a*cos(c1*PI/180.0);
    y1 = a*sin(c1*PI/180.0);
    x2 = b*cos(c2*PI/180.0);
    y2 = b*sin(c2*PI/180.0);
    double ans = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    ans = pow(ans, 0.5);
    printf("%.10lf", ans);
    return 0;
}

Measured memory_bytes: 4228
#include <iostream>
#define rep(i, n)for(int i=1; i<=n; i++)
using namespace std;

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

    bool can = false;
    rep(i, 9){
        rep(j, 9){
            if(i*j==n){
                can = true;
                break;
            } 
        }
    }

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

Measured memory_bytes: 3616
def otoshidama():
    N,Y = map(int, input().split())

    for i in range(N + 1):
        for j in range(N + 1 - i):
            k = N - i - j
            if i * 10000 + j * 5000 + k *1000 == Y:
                print('{0} {1} {2}'.format(i,j,k))
                return

    print('{0} {1} {2}'.format(-1,-1,-1))

def main():
    otoshidama()

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n, m = map(int, input().split())
if m == 0:
  lst = []
else:
  lst = [int(i) for i in input().split()]

nums = []
min_l = 1000
for i in range(103):
  if i in lst:
    continue
  l = abs(i - n)
  if l < min_l:
    min_l = l
    min_num = i
  elif l >= min_l:
    break
print(min_num)

Measured memory_bytes: 9052
n, q = gets.chomp.split(" ").map{|i|i.to_i}
queue = Array.new(2*n)
queue[0] = 0
1.upto(n) do |i|
  queue[i] = gets.chomp
end

tail = n
cnt = 0
queue.each do |p|
  next if p == 0
  break if p == nil
  p_n, p_t = p.split(" ")
  r = p_t.to_i - q
  if r <= 0
    cnt += p_t.to_i
    puts "#{p_n} #{cnt}"
  else
    cnt += q
    queue[tail+1] = "#{p_n} #{r}"
    tail += 1
  end
end


Measured memory_bytes: 18336
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int main(){
  int n;
  cin>>n;
  vector<pair<int,int> > v;
  for(int i = 0;i<n;i++){
    int a;
    cin>>a;
    v.push_back(make_pair(a,i));
  }
  int ans = 0;
  sort(v.begin(),v.begin()+n);
  for(int i= 0;i<n;i++){
    if(i % 2 != v[i].second%2)
      ans++;
  }
  cout<<ans/2<<endl;
  return 0;
}


Measured memory_bytes: 1400
use proconio::input;

fn main() {
  input! {
    n: usize,
    a: [usize; n-1],
  }

  let mut cnt: Vec<i64> = vec![0; n];
  for x in a {
    cnt[x-1] += 1;
  }
  for r in cnt {
    println!("{}", r);
  }
}

Measured memory_bytes: 6412
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    int ret = m;
    for(int i=0; i<n; ++i){
        int a, b;
        cin >> a >> b;
        m += a - b;
        if(m < 0){
            cout << 0 << endl;
            return 0;
        }
        ret = max(ret, m);
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 1160
import sys
from collections import Counter

def make_prime_checker(n):
    # nまでの自然数が素数かどうかを表すリストを返す  O(nloglogn)
    is_prime = [False, True, False, False, False, True] * (n//6+1)
    del is_prime[n+1:]
    is_prime[1:4] = False, True, True
    for i in range(5, int(n**0.5)+1):
        if is_prime[i]:
            is_prime[i*i::i] = [False] * (n//i-i+1)
    return is_prime

def main():
    Primes = [p for p, is_p in enumerate(make_prime_checker(2200)) if is_p]
    def decomp(n):
        res1 = res2 = 1
        for p in Primes:
            cnt = 0
            while n % p == 0:
                n //= p
                cnt += 1
            cnt %= 3
            if cnt == 1:
                res1 *= p
            elif cnt == 2:
                res2 *= p
        if int(n**0.5)**2 == n:
            res2 *= int(n**0.5)
        else:
            res1 *= n
        return res1 * res2 * res2, res1 * res1 * res2

    N, *S = map(int, sys.stdin.buffer.read().split())
    T = []
    inv_dict = {}
    for s in S:
        t, t_inv = decomp(s)
        T.append(t)
        inv_dict[t] = t_inv

    counter_T = Counter(T)
    ans = 0
    for t, t_cnt in counter_T.items():
        if t == 1:
            ans += 1
            continue
        t_inv = inv_dict[t]
        t_inv_cnt = counter_T[t_inv]
        if t_cnt > t_inv_cnt or (t_cnt == t_inv_cnt and t > t_inv):
            ans += t_cnt
    print(ans)

main()


Measured memory_bytes: 38732
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	vector<ll> x(n), y(n), h(n);
	ll p=-1;
	rep(i, n)
	{
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] > 0 && p == -1)
		{
			p = i;
		}
	}
	ll eq = 0;

	for (ll i = 0; i <= 100; i++)
	{
		for (ll j = 0; j <= 100; j++)
		{
			ll height = 0;
			height = h[p] + abs(i - x[p]) + abs(j - y[p]);
			for (ll k = 0; k < n; k++)
			{
				ll H = max(height - abs(i - x[k]) - abs(j - y[k]), 0LL);
				if (h[k] == H)
				{
					eq++;
				}
			}
			if (eq == n)
			{
				cout << i << " " << j << " " << height << endl;
				ret;
			}
			eq = 0;
		}
	}
	return 0;
}

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

using namespace std;

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

typedef long long ll;

const ll mod = 1e9+7;

ll power(ll n, ll m = mod - 2){
	ll res=1;
	for(n %= mod; m; m /= 2){
		if(m % 2) res = (res * n) % mod;
		n = (n * n) % mod;
	}
	return res;
}

ll fact[200001];

void init() {
	fact[0] = 1;
	rep(i, 200000) fact[i+1] = (i+1) * fact[i] % mod;
}

ll comb(ll a, ll b) {
	return fact[a] * power(fact[a-b] * fact[b] % mod) % mod;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll h, w, a, b, res=0;
	cin >> h >> w >> a >> b;
	h--, w--;
	if(h-a > w-b) {
		swap(h, w);
		swap(a, b);
	}

	init();
	rep(i, h-a+1) {
		res += comb(h-a+b, i) * comb(w+a-b, h-i) % mod;
		res %= mod;
	}

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


Measured memory_bytes: 1792
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy


def moji_list(a, b):
    # アルファベット小文字 → (97, 123)
    # アルファベット大文字 → (65, 91)
    # 半角数字 → (48, 58)
    # ひらがな → (12353, 12436)
    # カタカナ → (12449, 12532+1)
    # 全角数字 → (65296, 65306)
    return [chr(i) for i in range(a, b)]


s = list(read().rstrip().decode())
ans = float('inf')
for al in moji_list(97, 123):
    cnt = 0
    check_s = deepcopy(s)
    while len(set(check_s)) > 1:
        cnt += 1
        ss = []
        for bf, af in zip(check_s, check_s[1:]):
            ss.append(af if af == al else bf)
        check_s = ss
    ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 3436
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
const long long Mod=1000000007;
int n,k,m,a[25010];
long long f[25010][410],s[25010][410];
bool used[25010];
long long pw(long long x,long long y)
{
	long long res=1;
	while (y)
	{
		if (y&1)
		{
			res=res*x%Mod;
		}
		x=x*x%Mod;
		y>>=1;
	}
	return res;
}
int main()
{
	scanf("%d%d%d",&n,&k,&m);
	for (int i=0;i<m;i++)
	{
		scanf("%d",&a[i]); 
	}
	bool flag=false;
	for (int i=0;i+k<=m;i++)
	{
		memset(used,false,sizeof(used));
		int now=0;
		for (int j=0;j<k;j++)
		{
			now+=(!used[a[i+j]]);
			used[a[i+j]]=true;
		}
		if (now==k)
		{
			flag=true;
			break;
		}
	}
	long long ans=pw(k,n-m)*(n-m+1)%Mod;
	if (flag)
	{
		printf("%lld\n",ans);
		return 0;
	}
	int l,r;
	l=r=-1;
	memset(used,false,sizeof(used));
	for (int i=0;i<m;i++)
	{
		if (used[a[i]])
		{
			l=i;
			break;
		}
		used[a[i]]=true;
	}
	memset(used,false,sizeof(used));
	for (int i=m-1;i>=0;i--)
	{
		if (used[a[i]])
		{
			r=i;
			break;
		}
		used[a[i]]=true;
	}
	for (int i=1;i<k;i++)
	{
		f[0][i]=1;
		s[0][i]=i;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<k;j++)
		{
			f[i][j]=(f[i-1][j+1]*(k-j)%Mod+s[i-1][j])%Mod;
			s[i][j]=(s[i][j-1]+f[i][j])%Mod;
		}
	}
	long long res=0;
	if (l!=-1)
	{
		for (int i=0;i<=n-m;i++)
		{
			res=(res+f[i][l]*f[n-i-m][m-r-1]%Mod)%Mod;
		}
	}
	else
	{
		for (int i=0;i<=n-m;i++)
		{
			long long p=1;
			for (int j=i+m;j<i+k && j<=n;j++)
			{
				if (j==n)
				{
					res=(res+f[i][j-i]*p%Mod)%Mod;
				}
				else
				{
					res=(res+f[i][j-i]*s[n-j-1][j-i]%Mod*p%Mod)%Mod;
				}
				p=p*(k-j+i)%Mod;
			}
		}
	}
	ans=(ans-res+Mod)%Mod;
	printf("%lld\n",ans);
    return 0;
}
//所爱隔山海，山海不可平，海有舟可渡，山有路可行，此爱翻山海，山海皆可平。

Measured memory_bytes: 160512
import java.util.*;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char d = a.charAt(a.length()-1);
		char e = b.charAt(0);
		char f = b.charAt(b.length()-1);
		char g = c.charAt(0);
		if (d==e&&f==g) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 22100
#include<iostream>
#include<stdio.h>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;

#define INF (1<<24)

struct Event {
  int id,u,v,w;
  Event (int id=0,int u=0,int v=0,int w=0):id(id),u(u),v(v),w(w){}
  bool operator < (const Event &p)const{
    if(v==0&&p.v==0)return (u==p.u&&w==p.w&&id>p.id)||(u==p.u&&w>p.w)||(u>p.u);
    else return (u==p.u&&v==p.v&&id>p.id)||(u==p.u&&v>p.v)||(u>p.u);
  }
};

priority_queue<Event> Q;

int m,n;
int U[2][10],ID[2][10];

vector<int> ans;

bool init();
bool input();
int minimamU();
int check0();
int check1(Event);
void car_in(Event);
void car_out(Event);

int main(){
  Event event;
  while(init()&&input()){
    while(!Q.empty()){
      event=Q.top();Q.pop();
      
      if(event.v==1){
	car_in(event);
      }else if(event.v==0){
	car_out(event);
      }
      /*
      cout<<event.id<<' '<<event.u<<' '<<event.v<<' '<<event.w<<endl;
      for(int i=0;i<2;i++){
	for(int j=0;j<m;j++){
	  if(ID[i][j]!=INF){
	    printf("%2d %2d  ",ID[i][j],U[i][j]);
	  }else{
	    cout<<"       ";
	  }
	}
	cout<<endl;
      }
      cout<<endl;
      */
    }
      
    for(int i=0;i<(int)ans.size();i++){
      if(i)cout<<' ';
      cout<<ans[i];
    }
    cout<<endl;
  }

  return 0;
}


void car_in(Event event){
  int A=check0(),B;
  if(A!=INF){
    U[0][A]=event.u+event.w;
    ID[0][A]=event.id;
    Q.push(Event(ID[0][A],U[0][A],0,A));
  }else{
    B=check1(event);
    if(B==INF){
      event.u=minimamU();
      Q.push(event);
    }else{
      U[1][B]=max(U[0][B],event.u+event.w);
      ID[1][B]=ID[0][B];
      U[0][B]=event.u+event.w;
      ID[0][B]=event.id;
      Q.push(Event(ID[0][B],U[0][B],0,B));
    }
  }
}

void car_out(Event event){
  int I=-1,J=-1;
  for(int i=0;i<2;i++)
    for(int j=0;j<m;j++)
      if(U[i][j]==event.u&&ID[i][j]==event.id){
	I=i; J=j;
      }
  if(I==-1&&J==-1)return;
  if(I==1)return;

  U[I][J]=INF;
  ID[I][J]=INF;
  ans.push_back(event.id);

  if(ID[1][J]!=INF){
    swap(ID[0][J],ID[1][J]);
    swap(U[0][J],U[1][J]);
    Q.push(Event(ID[0][J],U[0][J],0,J));
  }
    

}

int check0(){
  for(int i=0;i<m;i++)if(ID[0][i]==INF)return i;
  return INF;
}
int check1(Event event){
  int mini=INF,miniI,x;
  for(int i=0;i<m;i++){
    if(ID[1][i]!=INF)continue;
    x=U[0][i]-(event.u+event.w);
    if(x<0)continue;
    if(x<mini){
      mini=x;
      miniI=i;
    }
  }
  if(mini!=INF)return miniI;
  
  
  for(int i=0;i<m;i++){
    if(ID[1][i]!=INF)continue;
    x=(event.u+event.w)-U[0][i];
    if(x<mini){
      mini=x;
      miniI=i;
    }
  }
  if(mini!=INF)return miniI;
  
  return INF;
}

bool init(){
  while(!Q.empty())Q.pop();
  for(int i=0;i<2;i++){
    for(int j=0;j<10;j++){
      U[i][j]=ID[i][j]=INF;
    }
  }
  ans.clear();
  return true;
}

bool input(){
  int a;
  cin>>m>>n;
  if(m==0&&n==0)return false;
  for(int i=0;i<n;i++){
    cin>>a;
    Q.push(Event(i+1,i*10,1,a));
  }
  return true;
}

int minimamU(){
  int res=INF;
  for(int i=0;i<2;i++){
    for(int j=0;j<m;j++){
      res=min(res,U[i][j]);
    }
  }
  return res;
}

Measured memory_bytes: 1216
a = input()
dic = {'01': 1, '02': 2, '03': '3','04': 1, '05': 2, '06': '3','07': 1, '08': 2, '09': '3','10': 1, '11': 2, '12': '3'}
b = a[0:2]
c = a[2:4]
if c in dic and b in dic:
	print("AMBIGUOUS")
if c in dic and b not in dic:
	print("YYMM")
if c not in dic and b in dic:
	print("MMYY")
if c not in dic and b not in dic:
	print("NA")



Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
int main(){
  int a,b,c=0;
  scanf("%d%d",&a,&b);
  for(int i=b;i;i/=10)c++;
  for(int i=0;i<c;i++)a*=10;
  a+=b;
  for(int i=1;i<1000;i++){
    if(a==i*i){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    double s = 0;
    double ss = 0;
    String[] array1 ;
    String[][] array2 = new String[n][d];
    int count =0;

    for(int i=0; i<n; i++){
      for(int j=0; j<d; j++){
        array2[i][j] = sc.next();
      }
    }

    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        for(int k=0; k<d; k++){
          s += Math.pow((Integer.valueOf(array2[i][k])-Integer.valueOf(array2[j][k])),2) ;
          //System.out.println(s);
        }
        ss = Math.sqrt(s);
        if(ss == (int)ss && ss != 0){
          count += 1;
        }
        s= 0;
      }
    }
    System.out.println(count/2);
  }
}

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

using namespace std;

int main() 
{
    int N;
    cin>>N;
    
    int temp=N%10;
    
    if(temp==2||temp==4||temp==5||temp==7||temp==9)
    {
        cout<<"hon"<<endl;
    }
    else if(temp==0||temp==1||temp==6||temp==8)
    {
        cout<<"pon"<<endl;
    }
    else
    {
        cout<<"bon"<<endl;
    }
    
    
}

Measured memory_bytes: 3632
import fractions

a,b = map(int,input().split())

def prime(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

arr = list(set(prime(a)) & set(prime(b)))
print(1+ len(arr))

Measured memory_bytes: 64236
eval"N,*D="+`dd`.split*?,
A=[0]*N
m=998244353
f=->a,b{b>0?a**b[0]*f[a,b/2]**2%m:1}
D.map{|d|A[d]+=1}
s=q=1
A.map{|a|s=s*f[q,q=a]%m}
p A[0]==1&&D[0]==0?s:0

Measured memory_bytes: 22620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  long a=0,b=s.size()-1;
  while(s[a]!='A') a++;
  while(s[b]!='Z') b--;
  cout << b-a+1 << endl;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
#define M 1000000000
typedef long long int ll;

vector<ll> adj[200005];
ll I[200005];
ll L[200005];
ll ans[200005];
ll vis[200005] = {0};
stack< pair<ll, ll> > changes;
ll n, arr[200005], u, v;

void dfs(ll cur, ll a){
	vis[cur] = 1;
	
	// for(int i = 0; i <= n; i++)
	// 	cout << I[i] << " ";
	// cout << endl;
	
	ll ind = lower_bound(I, I + n+1, arr[cur]) - I;
	// cout << ind << " " << I[ind] << " " << arr[cur] << endl;
	if(I[ind] == INT_MAX)
		a = ind;
	changes.push(make_pair(ind, I[ind]));
	I[ind] = arr[cur];
	L[cur] = ind;
	ans[cur] = a;
	
	for(int i = 0; i < adj[cur].size(); i++){
		if(vis[adj[cur][i]] == 0)
			dfs(adj[cur][i], a);
	}
	
	I[changes.top().first] = changes.top().second;
	changes.pop();
}

int main(){

	cin >> n;
	I[0] = -INT_MAX;
	for(int i = 1; i <= n; i++){
		cin >> arr[i];
		I[i] = INT_MAX;
	}
	for(int i = 0; i < n-1; i++){
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1, 0);
	for(int i = 1; i <= n; i++){
		cout << ans[i] << endl;
	}
	
	return 0;

}

Measured memory_bytes: 42200
///In the name of ALLAH

#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;
 
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()
#define mx_int_prime 999999937
 
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
 
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define sqr(a) ((a) * (a))
 
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


const int mx = 1e5+123;

ll dp[123][mx];
int n, W, v[mx], w[mx];


long long solve ( int i, int j )
{
  if ( i > n ) return 0;
  if ( dp[i][j] != -1 ) return dp[i][j];

  long long ret1 = 0, ret2 = 0;

  if ( w[i] + j <= W ) ret1 = v[i] + solve ( i+1, w[i] + j );
  ret2 = solve ( i+1, j );

  return dp[i][j] = max ( ret1, ret2 );

}


int main()
{
  optimize();

  cin >> n >> W;
  for ( int i = 1; i <= n; i++ ) {
    cin >> w[i] >> v[i];
  }

  memset ( dp, -1, sizeof(dp) );
  cout << solve ( 1, 0 ) << endl;
  

  return 0;
}

Measured memory_bytes: 99800
import copy as cp

def bin_search(n,lst):
    l=0
    r=len(lst)
    
    while r-1>=l:
        i=(l+r)//2
        if lst[i]==n: return i
        elif lst[i]<n: l=i+1
        else: r=i

N,M = map(int,input().split())
P = []
Y = []
for i in range(M):
    p,y = map(int,input().split())
    P.append(p)
    Y.append(y)
#print(N,M,P,Y)

C_lst = [[] for _ in range(N)]
for i in range(M):
    C_lst[P[i]-1].append(Y[i])
#print(N,M,P,Y,C_lst)
C_cp = cp.deepcopy(C_lst)
for i in range(N):
    C_cp[i].sort()
for i in range(M):
    ans = "0"*(6-len(str(P[i]))) + str(P[i])
    idx = bin_search(Y[i],C_cp[P[i]-1]) + 1
    ans += "0"*(6-len(str(idx))) + str(idx)
    print(ans)

Measured memory_bytes: 47300
#include <bits/stdc++.h>
using namespace  std;
int main(){
  int N;
  cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  for (int i=0;i<N;i++){
    cin >> V.at(i);
  }
  for (int i=0;i<N;i++){
    cin >> C.at(i);
  }
  int S=0;
  for (int j=0;j<N;j++){
    if ((V.at(j)-C.at(j))>0){
      S+=V.at(j)-C.at(j);
    }
    else {
      S=S;
    }
  }
  cout << S << endl;
}

 


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
using namespace std;
int main() {
  int L;
  cin >> L;
  printf("%f\n", double(L * L * L) / (3 * 3 * 3));
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>

using namespace std;

int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int a[200000];
	for(long long int i=0; i<n; i++){
		scanf("%lld", &a[i]);
	}
	long long int ans=0;
	set<long long int> st;
	for(long long int i=n-1; i>=0; i--){
		if(i==n-1){
			ans+=a[n-1];
			if(a[n-1]>n-1){
				printf("%d\n", -1);
				return 0;
			}
			st.insert(a[n-1]-(n-1));
		}else if(a[i]+1==a[i+1]){
			auto itr=st.end();
			itr--;
			long long int max=*itr;
			if(a[i]>i || a[i]<max+i){
				printf("%d\n", -1);
				return 0;
			}
			st.insert(a[i]-i);
		}else{
			ans+=a[i];
			auto itr=st.end();
			itr--;
			long long int max=*itr;
			if(a[i]>i || a[i]<max+i){
				printf("%d\n", -1);
				return 0;
			}
			st.insert(a[i]-i);
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 11136
#include <iostream>

int N,M;
int T[101],P[191],X[101];


int main(){
    std::cin>>N;
    int sum=0;
    for(int i=0;i<N;++i){
        std::cin>>T[i];
        sum+=T[i];
    }
    std::cin>>M;
    for(int i=0;i<M;++i){
        std::cin>>P[i]>>X[i];
        P[i]--;
        std::cout<<sum+X[i]-T[P[i]]<<std::endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,k,i;
	scanf("%d %d %d",&a,&b,&k);
	if(b-a+1>=k*2)
	{
		for(i=a;i<=a+k-1;i++)
		{
			printf("%d\n",i);
		}
		for(i=b-k+1;i<=b;i++)
		{
			printf("%d\n",i);
		}
	}
	else
	{
		for(i=a;i<=b;i++)
		{
			printf("%d\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.{BufferedReader, IOException, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting

object Main {
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val H = sc.nextInt()
    val W = sc.nextInt()

    val INF = 10010
    val c = Array.ofDim[Int](10, 10)
    for {
      i <- 0 to 9
      j <- 0 to 9
    } c(i)(j) = sc.nextInt()

    val dp: Array[Int] = Array.fill(10)(INF)
    dp(1) = 0
    for {
      _ <- 0 until 10
      i <- 0 to 9
      j <- 0 to 9
    } {
      dp(i) = math.min(dp(i), dp(j) + c(i)(j))
    }

    val ans = (for {
      _ <- 0 until H
      _ <- 0 until W
    } yield {
      sc.nextInt() match {
        case -1 | 1 => 0
        case a => dp(a)
      }
    }).sum

    println(ans)
  }

  def main(args: Array[String]): Unit = {
    solve()
  }

  class InputReader(val stream: InputStream) {
    val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextChar(): Char = next.charAt(0)
  }

}


Measured memory_bytes: 35188