akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int i = sc.nextInt();
			
			if(i == 0){
				break;
			}
			
			int s = 0;
			int sqr = (int)Math.floor(Math.sqrt((double)i));
			
			for(int j = 1; j <= sqr; j++){
				if((i != j) && (i % j == 0)){
					s = s + j;
					if ((j != 1) && (i != j * j)){
						s = s + (i / j);
					}
				}
			}
			
			if(i == s){
				System.out.println("perfect number");
			}else{
				if(i < s){
					System.out.println("abundant number");
				}else{
					System.out.println("deficient number");
				}
			}
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    string s; cin >> s;
    int start = 0, end = s.size();
    while (s[start] != 'A') start++;
    while (s[end] != 'Z') end--;

    cout << end - start + 1 << endl;

    return 0;
}


Measured memory_bytes: 640
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    def Count(self, x):
        return -self.root[self.Find_Root(x)]

m = 100010
uf = UnionFind(m*2)
n = int(input())
for i in range(n):
    x,y = map(int,input().split())
    y = y+m
    uf.Unite(x,y)

lx = {}
ly = {}
ans = 0
for i in range(m):
    rx = uf.Find_Root(i)
    lx[rx] = lx.get(rx,0)+1
    ry = uf.Find_Root(i+m)
    ly[ry] = ly.get(ry,0)+1
for i in range(m*2):
    ans += lx.get(i,0)*ly.get(i,0)

print(ans-n)

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

using LL = long long;

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

  int ans;
  int a, b;
  cin >> a >> b;

  int sub = b - a;
  int temp = 0;
  for (int i = 1; i < sub; i++) {
    temp += i;
  }

  ans = temp - a;
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll a[n+5];
	for(ll i=0;i<n;i++)
		cin>>a[i];

	map<ll,ll> pam;
	for(ll i=0;i<n;i++)
	{
		pam[i+1-a[i]]++;
	}

	ll ans = 0;
	for(ll i=0;i<n;i++)
	{
		ll Ans = pam[a[i]+i+1];
		ans+=Ans;
	}
	cout<<ans;

}

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

int main() {
  int n ;
  cin >> n;
  int ans =0; 
  for (int i=0;i<n;i++){
   if ( i+1 <10 ) {
     ans ++ ;
   }
    else if((i+1>99)&&(i+1<1000)){
      ans ++ ;
    }
    else if((i+1 >9999)&&(i+1<100000)){
      ans ++;
    }
  }
  cout <<ans;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
#define EXIT(answer) { cerr<<"EXIT #"<<__LINE__<<endl; cout<<answer<<endl; exit(0); }
#define sz(v) int(v.size())
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> istream& operator>>(istream& in, pair<T,U> &p) { in>>p.first>>p.second; return in; }
template<typename T> inline vector<T> READ(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    string s; cin>>s;
    if(s.length()%2)
        EXIT("No");
    FOR(i,s.length()) {
        if(s[i]==(i%2 ? 'i' : 'h'))
            ;
        else
            EXIT("No");
    }
    EXIT("Yes");

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cassert>
#include<utility>
#include<algorithm>
#define llong long long
#define pii pair<int,int>
#define mkpr make_pair
using namespace std;

const int N = 3e3;
const int P = 1e9+7;
char a[N+3];
int s[N+3];
int mxr[N+3];
llong dp[N+3][N+3];
int n,m,mm;
llong ans;

llong updmax(llong &x,llong y) {x = (x+y)%P;}

int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",a+1); for(int i=1; i<=n; i++) a[i] -= 48;
	for(int i=1; i<=n+1; i++) s[i] = s[i-1]+a[i];
	for(int i=1; i<=m; i++)
	{
		int x,y; scanf("%d%d",&x,&y); mxr[x] = max(mxr[x],y);
	}
	for(int i=1; i<=n+1; i++) mxr[i] = max(mxr[i],max(i,mxr[i-1]));
//	printf("mxr: "); for(int i=1; i<=n+1; i++) printf("%d ",mxr[i]); puts("");
	dp[1][s[mxr[1]]] = 1ll;
	for(int i=1; i<=n; i++)
	{
		for(int j=0; j<=n; j++)
		{
			if(dp[i][j])
			{
				int cnt1 = j,cnt0 = mxr[i]-(i-1)-j;
				if(cnt0>0) {updmax(dp[i+1][j+s[mxr[i+1]]-s[mxr[i]]],dp[i][j]);}
				if(cnt1>0) {updmax(dp[i+1][j+s[mxr[i+1]]-s[mxr[i]]-1],dp[i][j]);}
			}
		}
	}
	printf("%lld\n",dp[n+1][0]);
	return 0;
}

Measured memory_bytes: 68480
#include <bits/stdc++.h>
using namespace std;
int a,b;
string s1,s2,s3;
int main()
{
	cin>>s1>>s2;
	cin>>a>>b;
	cin>>s3;
	if(s3==s1)
	cout<<a-1<<" "<<b<<endl;
	else
	cout<<a<<" "<<b-1<<endl;
return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int l=sc.nextInt();
		int c=sc.nextInt();
		int r=sc.nextInt();
		if(l==1&&c==1&&r==0)System.out.println("Open");
		else if(l==0&&c==0&&r==1)System.out.println("Open");
		else System.out.println("Close");
	}
}

Measured memory_bytes: 17160
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  
  vector <int> p(N);
  for (int i = 0; i < N; i ++){
    cin >> p.at(i);
  }
  
  sort(p.begin(),p.end());
  
  int sum = 0;
  for (int tasu = 0; tasu < K; tasu ++){
    sum += p.at(tasu);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    ll H,N,total;
    cin >> H >> N;
    total = 0;
    for (size_t i = 0; i < N; i++)
    {
        ll a;
        cin >> a;
        total += a;
    }
    if (total >= H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int x = in.nextInt();
        final int n = in.nextInt();
        in.nextLine();
        final Set<Integer> set = IntStream.rangeClosed(0, 101).boxed().collect(Collectors.toSet());
        for (int i = 0; i < n; i++) {
            set.remove(in.nextInt());
        }
        int diff = Integer.MAX_VALUE;
        int res = Integer.MAX_VALUE;
        for (int item : set) {
            if (Math.abs(item - x) < diff) {
                diff = Math.abs(item - x);
                res = item;
            } else if (Math.abs(item - x) == diff) {
                res = Math.min(res, item);
            }
        }
        System.out.println(res);
    }
}


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

n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b, c = [int(x) for x in input().split()]
    edge[a - 1].append([c, b - 1])
    edge[b - 1].append([c, a - 1])
q, k = [int(x) for x in input().split()]
# print(edge)
import heapq
def dijkstra(s):
    d = [float("inf")]*n
    used = [False]*n
    d[s] = 0
    used[s] = True
    queue = []
    for e in edge[s]:
        heapq.heappush(queue, e)
    while queue:
        # print(queue, d)
        cost, to = heapq.heappop(queue)
        if used[to]:
            continue
        d[to] = cost
        used[to] = True
        for e in edge[to]:
            # print(e)
            if used[e[1]]:
                continue
            heapq.heappush(queue, [d[to] + e[0], e[1]])
    return d

d = dijkstra(k - 1)
# print(d)
ans = []
for _ in range(q):
    x, y = [int(x) for x in input().split()]
    ans.append(d[x - 1] + d[y - 1])
for i in ans:
    print(i)


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

using namespace std;

//int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dirs[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};

long long modd=1e9+7;

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("inp.in","r",stdin);
    //freopen("outp.out","w",stdout);
    int n, k;
    scanf("%d %d", &n, &k);
    vector<long long> v(n);
    for(int i=0; i<n; i++) scanf("%lld", &v[i]);
    if(k==1)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(v.begin(),v.end());
    vector<long long> powers(n+5,1);
    for(int i=1; i<n+5; i++)
    {
        powers[i]=(powers[i-1]*2)%modd;
    }
    vector<long long> facs(n+5,1);
    for(long long i=1; i<n+5; i++)
    {
        facs[i]=(facs[i-1]*i)%modd;
    }
    vector<long long> inv(n+5,1);
    for(long long i=2; i<n+5; i++)
    {
        inv[i]=-(modd/i)*inv[modd%i];
        inv[i]+=modd*modd;
        inv[i]%=modd;
        //cerr << (i*inv[i])%modd << endl;
    }
    vector<long long> fac_inv(n+5,1);
    for(long long i=1; i<n+5; i++)
    {
        fac_inv[i]=(fac_inv[i-1]*inv[i])%modd;
        //cerr << (fac_inv[i]*facs[i])%modd << endl;
    }
    long long ans=0;
    for(int highest_idx=k-1; highest_idx<n; highest_idx++)
    {
        long long mult=(facs[highest_idx]*fac_inv[k-1])%modd;
        mult=(mult*fac_inv[highest_idx-(k-1)])%modd;
        ans+=mult*v[highest_idx];
        ans+=modd*modd;
        ans%=modd;
    }
    for(int lowest_idx=0; lowest_idx+k-1<n; lowest_idx++)
    {
        int highest_idx=n-lowest_idx-1;
        long long mult=(facs[highest_idx]*fac_inv[k-1])%modd;
        mult=(mult*fac_inv[highest_idx-(k-1)])%modd;
        ans-=mult*v[lowest_idx];
        ans+=modd*modd;
        ans%=modd;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4224
import java.util.*;

public class Main {

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int min = sc.nextInt();
        int max = sc.nextInt();

        for (int i = 0; i < m - 1; i++) {
            int a = sc.nextInt();
            if (min < a) {
                min = a;
            }
            int b = sc.nextInt();
            if (b < max) {
                max = b;
            }
        }

        System.out.println(Math.max((Math.min(n, max) - min + 1), 0));

        sc.close();

    }

}

Measured memory_bytes: 58832
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,rcnt=0,lcnt=0;                //l=='(', r==')'を数える
    string s;
    lli i,j;
    cin>>n>>s;
    rep(i,0,n){
        if(s[i]=='('){
            lcnt++;
        }
        else{
            if(lcnt>0){
                lcnt--;
            }
            else{
                rcnt++;
            }
        }
    }
//    cout<<"(が"<<rcnt<<"個、)が"<<lcnt<<"個必要"<<endl;
    s=string(rcnt,'(')+s+string(lcnt,')');
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
int x, y, n, m, k;
ll a[N], b[N], c[N];
priority_queue<ll, vector<ll>, greater<ll> >qa, qb;
int main() {
	scanf("%d%d%d%d%d", &x, &y, &n, &m, &k);
	for (int i = 1; i <= n; i++)scanf("%lld", &a[i]);
	for (int i = 1; i <= m; i++)scanf("%lld", &b[i]);
	for (int i = 1; i <= k; i++)scanf("%lld", &c[i]);
	sort(a + 1, a + n + 1, greater<ll>());
	sort(b + 1, b + m + 1, greater<ll>());
	sort(c + 1, c + k + 1, greater<ll>());
	for (int i = 1; i <= x; i++)qa.push(a[i]);
	for (int i = 1; i <= y; i++)qb.push(b[i]);
	int p = 1;
	while (1) {
		ll u = qa.top(), v = qb.top();
		if (p > k || c[p] <= u && c[p] <= v)break;
		if (c[p] - u > c[p] - v) {
			qa.pop();
			qa.push(c[p]);
		}
		else {
			qb.pop();
			qb.push(c[p]);
		}
		p++;
	}
	ll ans = 0;
	while (!qa.empty()) {
		ans += qa.top();
		qa.pop();
	}
	while (!qb.empty()) {
		ans += qb.top();
		qb.pop();
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 5748
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,a,b,c,d,e,f,ma=0;
  while(1){
    cin >> N;
    if(!N)
      return 0;
    vector<int> memo(1000000,0);
    ma = 0;
    REP(i,N){
      scanf("%d:%d:%d %d:%d:%d",&a,&b,&c,&d,&e,&f);
      memo[a*10000+b*100+c]++;
      memo[d*10000+e*100+f]--;
    }
    for(int i=1;i<memo.size();i++){
      memo[i] += memo[i-1];
      ma = max(ma,memo[i]);
    }
    cout << ma << endl;
  }
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}




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

   int main() {
   string S;
   int m,h;
   while(cin>>S>>m){
   for(int i=0;i<m;i++){
   cin>>h;
   S=S.substr(h)+S.substr(0,h);}
   cout<<S<<endl;
   }
   return 0;
   }


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2000+10;
vector<int> g[N];
int n,x,y,ans[N];
void cac(int s){
	queue<int> q;
	int dis[N];for(int i=0;i<N;i++)dis[i]=-1;
	dis[s]=0;q.push(s);
	while(q.size()){
		int u=q.front(); q.pop();
		//printf("%d %d\n", u, dis[u]);
		for(auto v:g[u]){
			if(dis[v]==-1){
				dis[v]=dis[u]+1; q.push(v);
			}
		}
	}
	for(int i=1;i<=n;i++) if(i>s)ans[dis[i]]++;
}
int main() {
	scanf("%d%d%d",&n,&x,&y);
	for(int i=1;i<n;i++) {
		g[i].push_back(i+1);
		g[i+1].push_back(i);
	}
	g[x].push_back(y);
	g[y].push_back(x);
	for(int i=1;i<=n;i++)cac(i);
	for(int i=1;i<n;i++)printf("%d\n", ans[i]);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int64_t sub(int64_t K, int64_t n) {
	int64_t cnt = 0;
	while (n < K) {
		cnt++;
		n *= 2;
	}
	return cnt;
}

int main() {
	int64_t N, K;
	cin >> N >> K;

	int64_t d = N - K;
	if (d < 0) d = 0;
	else d++;

	double ans = (double)d / N;
	int64_t m = min(N, K - 1);
	//cout << ans << endl;

	for (int64_t i = 1; i <= m; i++) {
		int64_t n = sub(K, i);
		//cout << n << endl;
		int64_t x = 1;
		for (int i = 0; i < n; i++) x *= 2;
		x *= N;
		//cout << x << endl;
		ans += (double)1 / x;
	}

	cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 3724
# frozen_string_literal: true

MOD = 10**9 + 7
n = gets.to_i
a = gets.split.map(&:to_i)
b = []
sum = 0
(0..(n - 2)).each do |i|
  sum += a[i]
  sum %= MOD
  b.push sum
end

sum = 0
(1..(n - 1)).each do |i|
  sum += a[i] * b[i - 1]
  sum %= MOD
end

puts sum


Measured memory_bytes: 29800
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)




int main(){
    int N;
    cin>>N;
    set<string>st;
    rep(i,N){
       string s;
       cin>>s;
       st.insert(s);
    }
  cout<<st.size()<<endl;
  return 0;
}



Measured memory_bytes: 19088
import java.util.*;

public class Main {

	String input;
	int p;
	HashMap< Integer, HashMap<Integer, Integer> > values;
	int[] sizes;
	static final int PARSE_ERROR = -1;
	static final int BUG = -2;

	void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			Integer ans = null;
			for(int i=1; ; i++){
				input = in.nextLine();
				if(input.equals(".")){
					if(i==1) return ;
					break;
				}
				if(ans != null) continue;
				if(i==1){
					values = new HashMap<Integer, HashMap<Integer, Integer> >();
					sizes = new int[0x100];
				}
				p = 0;
				if(input.indexOf("=") == -1){
					declaration();
				}
				else if(!assignment()){
					ans = i;
				}
			}
			System.out.println(ans==null?0:ans.intValue());
		}
	}

	boolean assignment(){
		int aname = array_name();
		p++;
		int num = expression();
		p++;
		p++;
		int expr = expression();
		if(expr < 0){
			return false;
		}
		if(sizes[aname] <= num){
			return false;
		}
		values.get(aname).put(num, expr);
		return true;
	}

	boolean declaration(){
		int aname = array_name();
		p++;
		int num = number();
		p++;
		sizes[aname] = num;
		values.put(aname, new HashMap<Integer, Integer>() );
		return true;
	}

	int expression(){
		if(p>=input.length()) return PARSE_ERROR;
		int num = number();
		if(num != PARSE_ERROR){
			return num;
		}
		int aname = array_name();
		p++;
		int exp = expression();
		p++;
		if(sizes[aname] <= exp || exp < 0){
			return BUG;
		}
		Integer ret = values.get(aname).get(exp);
		if(ret == null){
			return BUG;
		}
		return ret.intValue();
	}

	int array_name(){
		return input.charAt(p++);
	}

	int number(){
		if(!Character.isDigit(input.charAt(p))) return PARSE_ERROR;
		int r = input.charAt(p) - '0';
		p++;
		while(p < input.length() && Character.isDigit(input.charAt(p))){
			r = 10*r + input.charAt(p++) - '0';
		}
		return r;
	}

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

Measured memory_bytes: 13000
#set
n,y = gets.chomp.split(" ").map(&:to_i)
yukichi = 0
higuchi = 0
noguchi = 0

(0 .. n ).each do |yukichi|
    (0 .. n - yukichi).each do |higuchi|
        noguchi = n - yukichi - higuchi
        if noguchi < 0 then
            break
        end
        if y == yukichi * 10000 + higuchi * 5000 + noguchi * 1000 then
            print ("#{yukichi} #{higuchi} #{noguchi}\n")
            exit
        end
    end
end

print ("#{-1} #{-1} #{-1}\n")

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> map(H);
  for (int i = 0; i < H; i++) cin >> map[i];

  vector<vector <int>> result(H, vector<int>(W));
  vector<int> x_range = {1, 0, -1};
  vector<int> y_range = {1, 0, -1};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (map[i][j] == '#') {
        result[i][j] = -1;
      } else {
        int boms = 0;
        for (int dx : x_range) {
          for (int dy : y_range) {
            if ((dx != 0 || dy != 0) && 0 <= i + dy && i + dy < H && 0 <= j + dx && j + dx < W && map[i + dy][j + dx] == '#') boms++;
          }
        }
        result[i][j] = boms;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (result[i][j] == -1) {
        cout << "#";
      } else {
        cout << result[i][j];
      }
    }
    cout << endl;
  }
}


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

int main() {
	int X, Y, Z, K;
	cin >> X >> Y >> Z >> K;
	vector<long> A(X), B(Y), C(Z), AB, ABC;
	for (long& i : A) cin >> i;
	for (long& i : B) cin >> i;
	for (long& i : C) cin >> i;
	for (long& i : A) {
		for (long& j : B) AB.push_back(i + j);
	}
	sort(AB.begin(), AB.end(), [](long& a, long& b)->bool { return a > b; });
	if (AB.size() > K) {
		AB.erase(AB.begin() + K, AB.end());
	}
	for (long& i : AB) {
		for (long& j : C) ABC.push_back(i + j);
	}
	sort(ABC.begin(), ABC.end(), [](long& a, long& b)->bool { return a > b; });
	for (int i = 0; i < K; ++i) cout << ABC[i] << endl;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input(), M = input();

    vector< int > s(M);
    vector< char > c(M);
    range(i, 0, M) {
        cin >> s[i] >> c[i];
        s[i]--;
    }
    
    range(i, 0, 1000) {
        string n = to_string(i);
        if (n.size() != N) continue;
        bool f = true;
        range(j, 0, M) {
            f = f && (n[s[j]] == c[j]);
        }
        
        if (!f) continue;
        
        cout << n << endl;
        return;
    }

    cout << -1 << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 256
ARGF.each_line do |line|
  h, w = line.split.map(&:to_i)
  break if h == 0 && w == 0
  h.times do |i|
    case i
    when 0, (h - 1)
      puts '#' * w
    else
      print "#", ("." * (w - 2)), "#\n"
    end
  end
  puts
end

Measured memory_bytes: 6096
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,A,B;

signed main(){
	cin>>A>>B>>N;
	int R=min(N,B-1);
	cout<<A*R/B<<endl;
	return 0;
}


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

using ll = long long;

int main() {
    int K;
    cin >> K;
    vector<ll> A(K);
    rep(i, K) cin >> A[i];
    ll minN = 2, maxN = 2;
    for (int i = K - 1; i >= 0; i--) {
        minN = (minN + A[i] - 1) / A[i] * A[i];
        maxN = maxN / A[i] * A[i] + A[i] - 1;
        //cout << minN << " " << maxN << "\n";
    }
    if (minN > maxN) cout << "-1\n";
    else cout << minN << " " << maxN << "\n";
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    ll n;
    ll a[100001];
    ll dp[100001];
    ll frog(ll ind)
    {
      if(ind == (n - 1)) return 0;
      if(ind >= n) return INT_MAX;
      if(dp[ind] != -1) return dp[ind];
      ll left = abs(a[ind] - a[ind + 1]) + frog(ind + 1);
      ll right = INT_MAX;
      if(ind + 2 < n){
      right = abs(a[ind] - a[ind + 2]) + frog(ind + 2);
      }
      dp[ind] = min(left , right);
      return dp[ind];
    }
    int main()
    {
      cin>>n;
      for(ll i = 0 ;i < n;i++){
      cin>>a[i];
      }
      memset(dp,-1,sizeof(dp));
       cout<<frog(0);
      
    }

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

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

    int c[100] = { 0 }, t[100] = { 0 };
    for( int i = 0; i < N; ++i )
        cin >> c[i] >> t[i];

    int ans = 1001;
    for( int i = 0; i < N; ++i )
        if( t[i] <= T && c[i] < ans ) ans = c[i];

    if( ans != 1001 ) cout << ans << endl;
    else cout << "TLE" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()
#define max(a,b) (a>b ? a : b)
#define min(a,b) (a<b ? a : b)
 
const int MOD = 998244353;
const int INF = 1000002;
const double PI =4*atan(1);
const double eps = 1e-7;
const long long oo = 1e18;

int resolve(string S, string T){
  int s = (int)S.size(), t = (int)T.size();
  vector<vector<int>> dp(s+1, vector<int>(t+1, 0));

  for(int i=0; i<s; i++){
    for(int j=0; j<t; j++){
      if(S[i]==T[j]) dp[i+1][j+1] = dp[i][j]+1;
      else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
    }
  }
  return dp[s][t];
}

int main(){
  int N;
  cin >> N;
  rep(i,N){
    string S, T;
    cin >> S >> T;
    cout << resolve(S, T) << endl;
  }
}


Measured memory_bytes: 6772
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H1, M1, H2, M2, K;
    int T1, T2;
    
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    
    T1 = H1 * 60 + M1;
    T2 = H2 * 60 + M2;
    
    cout << T2 - T1 - K << endl;
    
    
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int a[110];
int main()
{
    int x,n;
    cin>>x>>n;
    for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int x1=x,x2=x; 
	while(1)
	{
		bool f1=false,f2=false;
		for(int i=0;i<n;i++)
		{
			if(x2==a[i])
			{
				f2=true;
				break;
			}
		}
		if(f2==false)
		{
			cout<<x2;
			return 0;
		}
		for(int i=0;i<n;i++)
		{
			if(x1==a[i])
			{
				f1=true;
				break;
			}
		}
		if(f1==false)
		{
			cout<<x1;
			return 0;
		}
		x2--;
		x1++;
	}
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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



	int A, B, C;
	cin >> A >> B >> C;

	if (A == B) co(C);
	else if (B == C) co(A);
	else co(B);

	Would you please return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*

val pw = PrintWriter(System.out)

fun main(args: Array<String>) {
    val s = read().toMutableList().sorted().joinToString(separator="")
    val t = read().toMutableList().sortedDescending().joinToString(separator="")
    //s.sort()
    //t.sort()

    println(if(s < t) "Yes" else "No")


    pw.flush()
}

fun inputList() = 
    readLine()!!.split(" ").map(String::toInt)

fun sum_digits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

/****** Decrared Functions ******/

// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }


fun println(value : Any) {
    pw.println(value)
}

fun gcd(a: Long, b: Long): Long = 
    if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
    if(b==0L) a else gcd(b, a % b)


Measured memory_bytes: 36336
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define Test ll t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define rep(i, a, b) for(ll i=a;i<b;i++)
#define repR(i,a,b) for(ll i=a;i>=b;i--)
#define loopS(i,a,b,step) for(ll i=a;i<b;i+=step)
#define loopRS(i,a,b,step) for(ll i=a;i>=b;i-=step)
#define ull unsigned long long int
#define pll pair<ll,ll>
#define puu pair<ull, ull>
#define V vector
#define M map
#define UM unordered_map
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf INT_MAX
#define S3(a,b,c) cin >> a >> b >> c
#define S2(a,b) cin >> a >> b
#define debug(x) cerr << #x << " = " << x << endl;
#define debug2(x,y) cerr << #x << " = " << x << " " << #y << " = " << y << endl;
#define debug3(x,y,z) cerr << #x << " = " << x << " " << #y << " = " << y <<  " " << #z << " = " << z << endl;
using namespace std;

void input(ll n, ll arr[]) {
	rep(i, 0, n)cin >> arr[i];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout.tie(NULL);
	ll n; string s; S2(n, s);
	n = s.size();
	ll preRed[n + 1], preWhite[n + 1];
	init(preRed, 0);
	init(preWhite, 0);
	ll cr = 0, cw = 0;
	rep(i, 0, n) {
		if (s[i] == 'R')cr++;
		preRed[i + 1] = preRed[i] + (s[i] == 'R');
	}
	rep(i, 0, n) {
		if (s[i] == 'W')cw++;
		preWhite[i + 1] = preWhite[i] + (s[i] == 'W');
	}
	if (cw && cr) {
		cout << min(cr - preRed[cr], cw - (preWhite[n] - preWhite[cr])) << endl;
	} else cout << 0 << endl;

}


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

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  int ans = A[0];
  for (int i = 1; i < N; i++) ans = Gcd(ans, A[i]);
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e6 + 10;
int N;
int A[MAXN];
int x[MAXN], rk[MAXN];
int cnt[MAXN];

int main() {
	register int i, j = 0;
	scanf("%d", &N);
	for(i = 1; i <= N; ++i)
		scanf("%d", x + i), rk[i] = i, cnt[i] = N;
	if(N == 1) return puts(x[1] == 1 ? "Yes\n1" : "No"), 0;
	sort(rk + 1, rk + N + 1, [&](int a, int b) {return x[a] < x[b];});
	for(i = 1; i <= N; ++i) {
		while(cnt[rk[i]] > N - rk[i] + 1) {
			--cnt[rk[i]];
			while(j <= N * N && A[j + 1]) ++j;
			if(j > N * N)  return puts("No"), 0;
			A[++j] = rk[i];
		}
		if(A[x[rk[i]]]) return puts("No"), 0;
		A[x[rk[i]]] = rk[i]; --cnt[rk[i]];
	}
	i = 1;
	for(; j <= N * N; ++j) {
		if(A[j]) continue;
		if(cnt[rk[i]] > 0) --cnt[rk[i]], A[j] = rk[i];
		else {while(cnt[rk[i]] == 0) ++i; --cnt[rk[i]]; A[j] = rk[i];}
		if(j <= x[rk[i]]) return puts("No"), 0;
		if(i > N) return puts("No"), 0;
	}
	puts("Yes");
	for(i = 1; i <= N * N; ++i)
		printf("%d%c", A[i], " \n"[i == N * N]);
	return 0;
}

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

int main(){
  vi v(3);
  rep(i,3) cin >> v[i];
  sort(v.begin(),v.end());
  cout << v[0]+v[1] << endl;
}


Measured memory_bytes: 3608
# 下記であればＯＫ。
#   2 or 3で割り切れる
#   2・3を含む
#   2の倍数の和が3の倍数、3の倍数の和が2の倍数。


def main():
    MAX_S = 30000
    N = int(input())
    if N == 3:
        print('2 3 25')
        return
    multi_2 = [2, 4]  # a % 2 == 0 and a % 3 != 0
    multi_3 = [3, 9]  # a % 3 == 0 and a % 2 != 0
    multi_6 = []  # a % 6 == 0
    cnt = 4
    i = 4
    while cnt + 2 <= N and 2 * (i + 1) <= MAX_S:
        multi_2.extend([2 * i, 2 * (i + 1)])
        cnt += 2
        i += 3
    j = 5
    while cnt + 2 <= N and 3 * (j + 2) <= MAX_S:
        multi_3.extend([3 * j, 3 * (j + 2)])
        cnt += 2
        j += 4
    k = 1
    while cnt + 1 <= N and 6 * k <= MAX_S:
        multi_6.append(6 * k)
        cnt += 1
        k += 1
    print(' '.join(map(str, multi_2 + multi_3 + multi_6)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 11320
let lower_bound (a : int array) first last v =
  let rec doit len first =
    if len = 0 then first
    else
      let half = len / 2 in
      let mid = first + half in
      if a.(mid) < v then doit (len - half - 1) (mid + 1)
      else doit half first in
  doit (last - first + 1) first

let () =
  let n = read_int () in
  let t = Array.make (n + 1) max_int in
  let rec doit i l =
    if i = n then l
    else begin
      let a = read_int () in
      let x = lower_bound t 0 n a in
      t.(x) <- a;
      doit (i + 1) (if l > x + 1 then l else x + 1)
    end in
  doit 0 0 |> Printf.printf "%d\n"

Measured memory_bytes: 5228
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  vector<P> v;
  int zcn=0;
  for(int i=0;i<n;i++){
    int cnt=1;
    for(int j=i+1;j<n;j++){
	 if(s[i]==s[j])cnt++;
	 else break;
    }
    i+=cnt-1;
    v.pb(P(s[i],cnt));
    if(s[i]=='0')zcn++;
  }
  if(zcn<=k){
    cout<<n<<endl;
    return 0;
  }
  int ans=0;
  int sum=0;
  int cntk=0;
  int l=0,r;
  for(int i=0;i<v.size();i++){
    if(v[i].fi=='0')cntk++;
    if(cntk>k){
	 r=i;
	 break;
    }
    sum+=v[i].se;
  }
  for(;;){
    ans=max(ans,sum);
    sum-=v[l++].se;
    if(v[l].fi=='0')sum-=v[l++].se;
    sum+=v[r++].se;
    ans=max(ans,sum);
    if(r==v.size())break;
    sum+=v[r++].se;
    ans=max(ans,sum);
    if(r==v.size())break;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2548
import java.util.Scanner;

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

		var result = true;
		for (var i = 0; i < s.length(); i++) {
			var si = s.substring(i, i + 1);
			if (i % 2 == 0 && si.equals("L") || i % 2 == 1 && si.equals("R")) {
				result = false;
				break;
			}
		}

		System.out.println(result ? "Yes" : "No");
	}
}


Measured memory_bytes: 35676
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(a: usize, b: usize) -> usize {
    if b > a {
        return gcd(b, a);
    }
    if a % b == 0 {
        return b;
    }
    gcd(b, a % b)
}

fn main() {
    input! {
        n: usize,
        x: [usize; n + 1],
    }
    let mut x = x;
    x.sort();
    let mut d = vec![0; n];
    for i in 0..n {
        d[i] = x[i + 1] - x[i];
    }
    let mut g = d[0];
    for i in 1..n {
        g = gcd(g, d[i]);
    }
    println!("{}", g);
}


Measured memory_bytes: 6396
#include<iostream>
#include<cstdlib>

using namespace std;

int top=0,S[200];


void push(int elem){
    ++top;
    S[top]=elem;
    return;
}

int pop(){
    --top;
    return S[top+1];
}

int main(){
    int a,b;
    char C[200];
    while(cin >> C){
        if(C[0]=='+'){
            a=pop();
            b=pop();
            push(a+b);
        }

        else if(C[0]=='-'){
            b=pop();
            a=pop();
            push(a-b);
        }

        else if(C[0]=='*'){
            a=pop();
            b=pop();
            push(a*b);
        }
        else {
            push(atoi(C));
        }
    }
    cout<<pop()<<endl;
    return 0;
}

Measured memory_bytes: 1148
#include<iostream>
#include<algorithm>
using namespace std;
struct A{
    int a;
    int b;
}AA[100000];
bool comp(A x,A y){
    return x.a<y.a;
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>AA[i].a;
        AA[i].b=i+1;
    }
    sort(AA,AA+n,comp);
    for(int i=0;i<n;i++){
        cout<<AA[i].b;
        if(i<n-1){
            cout<<" ";
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
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(){
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];

  sort(all(a),greater<int>());
  ll ans = 0;
  for(int i = 1; i < n; i++) ans += a[i/2];
  cout << ans;
  return 0;
}


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

const ll LLMAX=1000000000000000000;

bool overflow(ll a, ll b) {
	if (a==0 || b==0) return false;
	ll prod=a*b;
	if (prod/a==b) {
		return false;
	}
	else {
		return true;
	}
}

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) {
		cin >> a.at(i);
	}
	bool iszero=false;
	rep(i,n) {
		if (a.at(i)==0) {
			iszero=true;
		}
	}

	ll ans;
	if (!iszero) {
		ans=1;
		for (int i=0;i<n;i++) {
			if(ans*a.at(i)<ans || ans*a.at(i)>LLMAX) {
				ans=-1;
				break;
			}
			else {
				ans*=a.at(i);
			}
		}
	}
	else {
		ans=0;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define N 100005
#define mod 1000000007
using namespace std;
typedef long long ll;
char s[N];
int sum[27],n;
int main()
{	
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n;i++) sum[s[i]-'a']++;
	ll ans=1;
	for(int i=0;i<26;i++) (ans*=sum[i]+1)%=mod;
	printf("%lld\n",(ans+mod-1)%mod);
	return 0;
}

Measured memory_bytes: 384
from collections import Counter

S = input()
MOD = 2019
div10 = 202  # modInverse(10, MOD). Note MOD is not prime so can't use FLT!


def solve1(S):
    # Naive implementation
    counts = [0 for i in range(MOD)]
    total = 0
    for d in S:
        d = int(d)
        nextCounts = [0 for i in range(MOD)]
        nextCounts[d] += 1
        for k, v in enumerate(counts):
            nextCounts[(10 * k + d) % MOD] += v
        counts = nextCounts
        total += counts[0]
    return total


def solve2(S):
    # Instead of shuffling the entire counts, update how we index into counts instead
    # The cumulative shuffle function forward is something like a * index + b for some calculable a, b
    # Then indexing into counts[t][x] is same as indexing into counts[0][(x - b) / a]

    negPowTen = 1  # our a
    prefix = 0  # our b
    counts = [0 for i in range(MOD)]
    total = 0
    for d in S:
        d = int(d)
        prefix = (10 * prefix + d) % MOD
        negPowTen = (negPowTen * div10) % MOD
        counts[((d - prefix) * negPowTen) % MOD] += 1
        total += counts[((0 - prefix) * negPowTen) % MOD]
    return total


def solve3(S):
    # Alternative solution, precompute prefixes, p[i+1] == (10 * p[i] + S[i]) % MOD
    # Then you have for S = '1817181712114'
    # p[1] = 1
    # p[2] = 18
    # p[3] = 181
    # p[4] = 1817
    # etc
    # Then want to count all i j such that:
    # (p[j] - p[i] * pow(10, j - i)) % M == 0
    # Which is equivalent to
    # (p[j] * pow(10, -j) - p[i] * pow(10, -i) % M == 0
    negPowTen = 1
    total = 0
    prefix = 0
    counts = [0 for i in range(MOD)]
    counts[0] = 1
    for d in S:
        prefix = (prefix * 10 + int(d)) % MOD
        key = (prefix * negPowTen) % MOD
        total += counts[key]
        counts[key] += 1
        negPowTen = (negPowTen * div10) % MOD

    return total


def solve4(S):
    # Compute all suffixes instead
    # S     = '1817181712114'
    # suf[1] =             4
    # suf[2] =            14
    # suf[3] =           114
    # suf[4] =          2114
    #
    # Difference of suffixes is almost correct but has extra 10s.
    # For example 2114 to 114 is the string 2 but our difference returns 2000.
    # Luckily 2 and 5 aren't divisible by 2019 so the extra 10s don't matter when counting.
    N = len(S)
    suf = 0
    powTen = 1
    counts = [0 for i in range(MOD)]
    total = 0
    counts[0] = 1
    for i in range(N):
        d = int(S[N - 1 - i])
        suf = (powTen * d + suf) % MOD
        total += counts[suf]
        counts[suf] += 1
        powTen *= 10
    return total


#assert solve1(S) == solve2(S) == solve3(S) == solve4(S)
ans = solve3(S)
print(ans)


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N, K; cin >> N >> K;
  int sum = 0, max = 0;
  vector<int> p(N);
  rep(i, N) {
    cin >> p[i];
    sum += p[i];
    if (i - K >= 0) {
      sum -= p[i - K];
    }
    max = std::max(max, sum);
  }
  printf("%.20f\n", max / 2.0 + 0.5 * K);
}


Measured memory_bytes: 1152
from collections import deque
n = int(input())
a = input().split()
b = deque()
f = True
for ai in a:
    if f:
        b.appendleft(ai)
    else:
        b.append(ai)
    f = not f
if f:
    b.reverse()
    print(" ".join(b))
else:
    print(" ".join(b))

Measured memory_bytes: 26688
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
using namespace std;

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

int gcd_of_vector(vector<int> A, int begin, int end){
  int result = A[begin];
  for(int i=begin;i<end;i++){
    result = gcd(A[i],result);
  }
  return result;
}

int gcd_of_vector_with_skip(vector<int> A, int skip){
  int result = A[0];
  if(skip==0)result=A[1];
  for(int i=1;i<A.size();i++){
    if(i==skip)continue;
    result = gcd(A[i],result);
  }
  return result;
}

int main()
{
  int N,ans,gcd1,gcd2;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }

  if(N>=100){
    ans=1000000010;
    for(int i=0;i<1;i++){
      //random_shuffle(A.begin(),A.end());
      gcd1 = gcd_of_vector(A,1,N/2);
      gcd2 = gcd_of_vector(A,N/2,N);
      ans = min(ans,max(gcd1,gcd2));
    }
  }else{
    ans=0;
    for(int i=0;i<N;i++){
      ans=max(ans,gcd_of_vector_with_skip(A,i));
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 1024