akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <stdlib.h>
#define inf 1e9

using namespace std;

struct edge{
	int to, cap, rev;
	edge(int a, int b, int c){
		to = a, cap = b, rev = c;
	}
};

int n, N;
int x[105], X[205];
bool prime[10000005];
map<int, int> mp;
vector<int> vec;

vector<edge> G[205];
int S, T;
bool used[205];

int dfs(int v, int f)
{
	used[v] = true;
	if(v == T) return f;
	
	int ret;
	for(int i = 0; i < G[v].size(); i++){
		if(used[G[v][i].to] || G[v][i].cap <= 0) continue;
		ret = dfs(G[v][i].to, min(f, G[v][i].cap));
		if(ret > 0){
			G[v][i].cap -= ret;
			G[G[v][i].to][G[v][i].rev].cap += ret;
			return ret;
		}
	}
	return 0;
}

void add_edge(int s, int t, int cap)
{
	G[s].push_back(edge(t, cap, G[t].size()));
	G[t].push_back(edge(s, 0, G[s].size()-1));
}

int main(void)
{
	cin >> n;
	for(int i = 2; i < 10005; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 10000005; j+=i) prime[j] = true;
	}
	prime[1] = prime[2] = true;
	
	for(int i = 1; i <= n; i++) cin >> x[i];
	for(int i = 1; i <= n; i++){
		mp[x[i]]++, mp[x[i]+1]++;
	}
	for(auto it = mp.begin(); it != mp.end(); it++){
		if(it->second % 2) vec.push_back(it->first);
	}
	N = vec.size();
	for(int i = 0; i < N; i++) X[i+1] = vec[i];
	
	S = N+1, T = N+2;
	int odd = 0, even = 0;
	for(int i = 1; i <= N; i++){
		if(X[i]%2) add_edge(S, i, 1), odd++;
		else add_edge(i, T, 1), even++;
	}
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= N; j++){
			if(i == j) continue;
			if(X[i]%2 && X[j]%2 == 0 && !prime[abs(X[i]-X[j])]) add_edge(i, j, 1);
		}
	}
	
	int mx = 0, flow;
	while(1){
		for(int i = 1; i <= T; i++) used[i] = false;
		flow = dfs(S, inf);
		if(flow <= 0) break;
		mx += flow;
	}
	
	int ans = mx;
	odd -= mx, even -= mx;
	ans += odd/2*2, ans += even/2*2;
	ans += odd%2*3;
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d) 
	{
		cout<<"Yes";
	    return 0;
	}
	else
	{
		if(abs(a-b)<=d&&abs(b-c)<=d) 
		{
			cout<<"Yes";
			return 0;
		}
		else cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < (y); x++)
#define Repe(x,y,z) for(int x = z; x <(y); x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N;
    Scd(N);
    vector<int> a(1<<N);
    Rep(i,1<<N){
        Scd(a[i]);
    }

    using pii = pair<int,int>;
    vector<pii> dp(1<<N,pii(a[0],0));
    Rep(i,1<<N){
        dp[i].first = a[i];
    }
    vector<int> ss(4);
    Rep(j,N){
        Rep(i,1<<N){
            if( i & (1 << j) ){
                int ji = i & ~(1<<j);
                ss[0] = dp[i].first;
                ss[1] = dp[i].second;
                ss[2] = dp[ji].first;
                ss[3] = dp[ji].second;
                sort(ss.begin(),ss.end());
                dp[i].first = ss[3];
                dp[i].second = ss[2];
            }
        }
    }

    int ma = 0;
    Repe(i,1<<N,1){
        ma = max( ma, dp[i].first + dp[i].second);
        printf ("%d\n", ma );
    }


    return 0;
}



Measured memory_bytes: 6144
#include <cstdio>
#include <algorithm>

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

using namespace std;

const int inf = 3e5;

int n;
int c[1000];
int w[1000];
int dp[1000][1000];

int judge(int x, int y){
	if(dp[x][y] > 0){
		return dp[x][y];
	}
	if(x == y){
		return dp[x][y] = w[x];
	}
	int t;
	if((t = judge(x + 1, y)) <= c[x]){
		return dp[x][y] = t + w[x];
	}
	if((t = judge(x, y - 1)) <= c[y]){
		return dp[x][y] = t + w[y];
	}
	return dp[x][y] = inf;
}

int main(){
	scanf("%d", &n);
	rep(i, n){
		scanf("%d%d", &c[i], &w[i]);
	}
	int ans = 0;
	int t = 0;
	while(t < n){
		++ans;
		for(int i = n - 1; i >= t; --i){
			if(judge(t, i) != inf){
				t = i + 1;
				break;
			}
		}
	}

	/*
	rep(i, n){
		rep(j, n){
			printf("%d ", dp[i][j]);
		}
		printf("\n");
	}
	*/

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4980
#include <iostream>
using namespace std ;
typedef long long ll ;
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)

ll a[101];
ll dp[100010];

int main() {
fast ;
  	ll N, K;
    cin >> N >> K;
    for(int i=0; i<N; i++) 
      cin >> a[i];
    
    dp[0]=0;
    for(int i=1; i<=K; i++) {
        for(int j=0; j<N; j++) {
            if(i>=a[j] && dp[i-a[j]]==0) {
                dp[i]=1;
                break;
            }
        }
    }
  	if(dp[K])
	cout << "First" << endl ;
  	else
      cout << "Second" << endl ;
    
}

Measured memory_bytes: 1024
def combi(n,k)
  k=n-k if 2*k > n
  return 1 if k == 0
  ((n-k+1)..n).reduce(&:*)/((1..k).reduce(&:*))
end

n = gets.to_i

ns = Array.new(10).map{Array.new(10).map{Array.new(0)}}
for i in 1..9
  for j in 1..9
    ns[i][j].push(0)
  end
end

for i in 1..n
  if i % 10 != 0
    if i < 10
      ns[i][i].push(i)
  	else
      s = i.to_s.split("")
      st = s[0].to_i
      en = s[-1].to_i
      ns[st][en].push(i)
    end
  end
end

cnt = 0
for i in 1..9
  for j in i..9
    len1 = ns[i][j].length - 1
    len2 = ns[j][i].length - 1
    if len1 > 0 && len2 > 0
      if i == j
        cnt += len1*len2
      else
        cnt += len1*len2*2
      end
    end
  end
end
puts cnt

Measured memory_bytes: 4092
s = int(input())
N = 10 ** 9
x2 = (s//N*N+N)-s
y1 = 1
x1 = N
y2 = (s + y1 * x2) // N
if s == N * N:
    x1 = N
    y1 = 0
    x2 = 0
    y2 = N
assert(abs(x1*y2-x2*y1)==s)
assert(0 <= x1 <= N)
assert(0 <= y1 <= N)
assert(0 <= x2 <= N)
assert(0 <= y2 <= N)
print(0, 0, x1, y1, x2, y2)

Measured memory_bytes: 38256
const main = (inputs) => {
  var array = inputs[0].split(" ");
  var array2 = inputs[1].split(" ");
  var N = array[0] - 0;
  var M = array[1] - 0;
  var sum = 0;

  for (var i = 0; i < M; i++) {
    sum = sum + Number(array2[i]);
  }

  console.log(N - sum < 0 ? -1 : N - sum);
}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));

Measured memory_bytes: 30740
#include <cmath>
#include <iostream>
#include <vector>
#include <iomanip>

int main(){
  int N,M;
  std::cin >> N >> M;
  std::vector<std::vector<int>> t_arr(N);
  for(int i = 0; i < M; i++){
    int s,t;
    std::cin >> s >> t;
    s--; t--;
    t_arr[s].push_back(t);
  }

  std::vector<std::vector<double>> p_arr(N, std::vector<double>(N, 0.0));
  for(int i = N-2; i >= 0; i--){
    auto& pi = p_arr[i];
    for(int idel = N-1; idel >= 0; idel--){
      if(idel > i || idel == i-1 || (idel==i && t_arr[i].size() == 1)){
        double pa = 0.0;
        for(auto&& neigh: t_arr[i]){
          pa += p_arr[neigh][idel];
        }
        pa /= t_arr[i].size();
        pi[idel] = pa+1;
      }else if(idel == i){
        int imax = 0;
        double pmax = -1.0;
        for(int ineigh=0; ineigh<t_arr[i].size(); ineigh++){
          auto&& neigh = t_arr[i][ineigh];
          if(p_arr[neigh][idel] > pmax){
            pmax = p_arr[neigh][idel];
            imax = ineigh;
          }
        }
        double pa = 0.0;
        for(int ineigh=0; ineigh<t_arr[i].size(); ineigh++){
          if(ineigh == imax) continue;
          auto&& neigh = t_arr[i][ineigh];
          pa += p_arr[neigh][idel];
        }
        pa /= (t_arr[i].size()-1);
        pi[idel] = pa+1;
      }else{
        pi[idel] = pi[idel+1];
      }
    }
  }

  double pmin = 1.e8;
  for(int i = 0; i < N; i++){
    pmin = std::min(pmin, p_arr[0][i]);
  }
  std::cout << std::setprecision(10) << std::fixed << pmin << std::endl;

  return 0;
}



Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
 
const int N = 102;
const long double eps = 1e-12;
 
int n,k;
long double x[N],y[N],f[N],rd[N];
 
vector<pair<long double,long double> > intersect(long double a,long double b,long double c,long double r){
	vector<pair<long double,long double> > ret;
	long double x0 = -a*c/(a*a+b*b), y0 = -b*c/(a*a+b*b);
	if (c*c > r*r*(a*a+b*b)+eps) {
		return ret;
	}
	if (abs (c*c - r*r*(a*a+b*b)) < eps) {
		ret.push_back({x0,y0});
		return ret;
	}
	long double d = r*r - c*c/(a*a+b*b);
    long double mult = sqrt (d / (a*a+b*b));
    long double ax, ay, bx, by;
    ax = x0 + b * mult;
    bx = x0 - b * mult;
    ay = y0 - a * mult;
    by = y0 + a * mult;
    ret.push_back({ax,ay});
    ret.push_back({bx,by});
    return ret;
}
 
long double dist(long double x,long double y,long double xx,long double yy){
	return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));
}
 
bool check(long double xxx){
	vector<pair<long double,long double> > points;
	for(int i=0;i<n;i++){
		rd[i] = xxx;
		points.push_back({x[i],y[i]});
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			long double x2 = x[j] - x[i],y2 = y[j] - y[i];
			vector<pair<long double,long double> > p = intersect(-2.0*x2,-2.0*y2,x2*x2+y2*y2+rd[i]*rd[i]-rd[j]*rd[j],rd[i]);
			for(auto hano:p){
				points.push_back({hano.first+x[i],hano.second+y[i]});
			}
		}
	}
	
	for(auto p:points){
		int cnt = 0;
		for(int i=0;i<n;i++){
			if(dist(p.first,p.second,x[i],y[i]) <= rd[i]+eps){
				cnt++;
			}
		}
		if(cnt >= n) return true;
	}
	return false;
}
 
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
	}
	
	//cout<<check(1.0)<<endl;
	//return 0;
	
	long double l = 0.0,r =20000,mid,ans = 20000;
	while(r-l > eps){
		mid = (l+r)/2.0;
		//cout<<mid<<" "<<check(mid)<<endl;
		if(check(mid)){
			r = mid - eps;
			ans = min(ans,mid);
		}
		else{
			l = mid + eps;
		}
	}
	
	cout<<setprecision(12)<<ans;
	
	return 0;
}


Measured memory_bytes: 3936
import sys

def main():
    N = int(input())
    xy = [[int(e) for e in input().split()] for _ in range(N)]
    if N == 1:
        print(1)
        return
    else:
        d_list = [(i[0] - j[0], i[1] - j[1]) for i in xy for j in xy if i != j]
        items = list(set(d_list))
        s = 1
        for item in items:
            c = d_list.count(item)
            if c > s:
                s = c
        print(N - s)
        return

main()

Measured memory_bytes: 3444
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{  
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine());
        StringTokenizer st=new StringTokenizer(br.readLine()," ");
        long[] arr=new long[N];
        for(int i=0;i<N;i++) arr[i]=Integer.parseInt(st.nextToken());
        HashMap<Long,Integer> map=new HashMap<Long,Integer>();
        long count=0;
        for(int i=0;i<N;i++){
            if(map.containsKey(i-arr[i])) count=count+(map.get(i-arr[i]));
            if(map.containsKey(arr[i]+i)){
                int f=map.get(arr[i]+i);
                map.remove(arr[i]+i);
                map.put(arr[i]+i,f+1);
            }
            else map.put(arr[i]+i,1);
        }
        System.out.println(count);
    }
}


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

using namespace std;
int main(){
    int n,p1=0,p2=0;
    string s1,s2;
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> s1>> s2;
        if(s1 > s2){
            p1 += 3;
        } else if( s1 < s2 ){
            p2 += 3;
        } else{
            p1 ++;p2++;
        }
    }
    cout << p1  << ' ' << p2 << endl;
}


Measured memory_bytes: 3188
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
    }
    
    static long MOD = (long)1e9+7;

	public static long fact(long x) {
		long ret = 1;
		for(int i = 1; i <=x ; i++)
			ret = ret * i % MOD;
		return ret;
	}
 
	public static long count(long n, long m) {
		if(Math.abs(n-m) > 1)
			return 0;
		long tmp = fact(n) * fact(m) % MOD;
		if(n == m) return 2 * tmp % MOD;
		else return tmp;
	}

	public static void solve() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        sc.close();
        out.println(count(n,m));
        out.flush();
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = { 0, 1, 0, -1 };

int main() {

	string str;
	cin >> str;

	int len = str.size();
	int ans = 0;
	rep(i, len - 1) {
		if (str.at(i) != str.at(i + 1)) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int in, out, tmp;

	while (1) {
		if (scanf("%d", &in) == EOF) break;

		tmp = in / 39;
		out = in - (tmp * 39);
		printf("3C");
		if (out == 0) printf("39\n");
		else if (out < 10) printf("0%d\n", out);
		else printf("%d\n", out);
	}
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



int main() {
//    cout << setprecision(100);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;
    cin >> n;
    ll a[n + 1];

    for (ll i = 0; i < n; i++) cin >> a[i + 1];

    map<ll, ll> d;
    ll bot = ceil((double) (n + 1) / 2);
    for (ll i = n; i >= bot; i--) {
        if (a[i]) {
            d[i] = 1;
        }
    }


    for (ll i = bot - 1; i >= 1; i--) {
        ll here = 0;
        for (ll j = i + i; j <= n; j += i) {
            if (d.find(j) != d.end()) here++;
        }

        if (here % 2 != a[i]) {
            d[i] = 1;
        }
    }


    cout << d.size() << '\n';
    for (auto e : d) {
        cout << e.first << ' ';
    }

    
}




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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  int sum = 0;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    sum += A.at(i);
  }
  cout << sum - N << endl;
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))

S1 = 0
S2 = 0
ans = 114514
for T in range(1,N):
    for i in range(T):
            S1 += W[i]
    for i in range(T,N):
            S2 += W[i]
    if abs(S1-S2) < ans:
        ans = abs(S2-S1)
    S1 = 0
    S2 = 0
print(ans)

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var H, N int
	fmt.Scan(&H)
	fmt.Scan(&N)
	damage := 0
	atk := 0
	res := "No"
	for i := 0; i < N; i++ {
		fmt.Scan(&atk)
		damage += atk
		if damage >= H {
			res = "Yes"
		}
	}

	fmt.Println(res)
}


Measured memory_bytes: 5504
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define REP(i,a) for(int i=0;i<(a);i++)
#define REPR(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int main () {
  unsigned ll a[5],n;
  cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  unsigned ll min=a[0],min_num=0;
  for (size_t i = 1; i < 5; i++) {
    if(min> a[i]){
      min=a[i];
      min_num=i;
    }
  }
  unsigned ll num = n%min ? n/min + 1 : n/min;
  num+=4;

  cout << num << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int N,L,ans = 0,E;
  	cin >> N >> L;
  	int T[N];
  	E = 101;
  	//cout << E << endl;
	for (int i = 1;i<=N;i++){
    	T[i] = L + i -1;
    	ans += T[i];
      	//cout << ans << endl;
      	//cout << T[i] << endl;
      	//cout << abs(T[i]) << endl;
      	//cout << T[i+1];
      	if(abs(E) > abs(T[i])){
        	E = T[i];
           
         //cout << T[i] << endl;
         //cout << E << endl;
        }
    }
    	ans = ans - E;
  	cout << ans;
  
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	#S = int(input())
	# = list(input())
	A,B = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	tmp = abs(A) + abs(B)
	tmp = tmp/2

	if tmp.is_integer():
		print(int(tmp))
	else:
		print("IMPOSSIBLE")


if __name__ == "__main__":
	main()


Measured memory_bytes: 38384
#include <iostream>

using namespace std;

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

	for (int i = 1; i <= n; i++) {
		int v = a[i];
		int j;
		for (j = i - 1; j > 0 && a[j] > v; j--)
			a[j + 1] = a[j];
		a[j + 1] = v;
		
		for (int i = 1; i < n; i++)
			cout << a[i] << ' ';
		cout << a[n] << endl;
	}
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) REP(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    cout << (n % k == 0 ? 0 : 1) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000000
#define mod 1000000007
int cnt(ll n){
	int co=0;
	while(n>0){
		n/=10;
		co++;
	}
	return co;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	ll N;
	cin>>N;
	ll ans=cnt(N);
	for(ll A=2;A*A<=N;A++){
		if(N%A!=0)continue;
		const ll B=N/A;
		const int cur=max(cnt(A),cnt(B));
		if(ans>cur)ans=cur;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

a_4 = [val for val in a if val % 4 == 0]
num_4=len(a_4)
a_odd = [val for val in a if val % 2 ==1]
num_odd=len(a_odd)
num_2 = N - num_odd - num_4


if num_odd==0:
    print('Yes')
else:
    if 1<=num_odd<=num_4:
        print('Yes')
    elif num_4+1==num_odd:
        if num_2==0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

const int dh[4] = {1, 0, -1, 0};
const int dw[4] = {0, 1, 0, -1};

int main(void){
    int H, W; cin >> H >> W;
    char field[H][W];
    for (int h = 0; h < H; ++h){
        for (int w = 0; w < W; ++w){
            cin >> field[h][w];
        }
    }

    int dist[H][W];
    memset(dist, -1, sizeof(dist));
    dist[0][0] = 0;

    int route[H][W][2];
    memset(route, -1, sizeof(route));

    queue<P> que;
    que.push(P(0, 0));
    while (!que.empty()){
        P p = que.front();
        que.pop();
        for (int i = 0; i < 4; ++i){
            int nh = p.first + dh[i];
            int nw = p.second + dw[i];

            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (field[nh][nw] == '#') continue;
            if (dist[nh][nw] == -1){
                que.push(P(nh, nw));
                dist[nh][nw] = dist[p.first][p.second] + 1;
                route[nh][nw][0] = p.first;
                route[nh][nw][1] = p.second;
            }
        }
    }
    if (dist[H-1][W-1] == -1) {
        cout << -1 << endl;
        return 0;
    }

    int h = H-1; int w = W-1;
    while (h != -1 && w != -1){
        field[h][w] = 'o';
        int nh, nw;
        nh = route[h][w][0];
        nw = route[h][w][1];
        h = nh;
        w = nw;
    }
    int ans = 0;
    for (int h = 0; h < H; ++h){
        for (int w = 0; w < W; ++w){
            if (field[h][w] == '.'){
                ++ans;
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1e6+10;
int n,a[N],m,b[N],p[3],cnt[3];
char s[N];
bool flag[N];

int main(){
	scanf("%s",s+1),m=strlen(s+1);
	a[n=1]=s[1]-'A';
	For(i,2,m) if (s[i]-'A'!=a[n]) a[++n]=s[i]-'A';
	For(i,1,n) cnt[a[i]]++;
	FOR(i,0,3) p[i]=i;
	sort(p,p+3,[](int a,int b){
		return cnt[a]<cnt[b];
	});
	a[0]=a[n+1]=-1;
	if (cnt[p[2]]>cnt[p[1]]){
		m=0;
		For(i,1,n){
			if (a[i]==p[2]&&a[i-1]!=a[i+1]) --cnt[p[2]];
				else b[++m]=a[i];
			if (cnt[p[2]]==cnt[p[1]]){
				For(j,i+1,n) b[++m]=a[j];
				break;
			}
		}
		n=m;
		For(i,1,m) a[i]=b[i];
		a[0]=a[n+1]=-1;
	}
	if (cnt[p[2]]>cnt[p[1]]){
		For(i,1,n){
			if (a[i]==p[2]&&a[i-1]==p[0]&&a[i+1]==p[0]) flag[i-1]=flag[i]=1,--cnt[p[0]],--cnt[p[2]];
			if (cnt[p[2]]==cnt[p[1]]) break;
		}
		m=0;
		For(i,1,n) if (!flag[i]) b[++m]=a[i];
		n=m;
		For(i,1,m) a[i]=b[i];
		a[0]=a[n+1]=-1;
	}
	if (cnt[p[2]]>cnt[p[1]]) return 0;
	if (cnt[p[1]]>cnt[p[0]]){
		fil(flag,0);
		int l=1+(a[1]==p[0]),r=l;
		while (a[r+1]!=p[0]&&r<n) ++r;
		for (;cnt[p[0]]<cnt[p[1]]&&l<=n;){
			for (int i=l;i<r-((r-l+1)%2==0&&l!=1&&r!=n);i+=2){
				flag[i]=flag[i+1]=1;
				cnt[p[1]]--,cnt[p[2]]--;
				if (cnt[p[1]]==cnt[p[0]]) break;
			}
			l=r=r+2;
			while (a[r+1]!=p[0]&&r<n) ++r;
		}
		m=0;
		For(i,1,n) if (!flag[i]) b[++m]=a[i];
		n=m;
		For(i,1,m) a[i]=b[i];
	}
	For(i,1,n) printf("%c",a[i]+'A');
}

Measured memory_bytes: 13436
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		int S = X + Y + Z;
		int[] A = new int[S];
		int[] B = new int[S];
		int[][] lis = new int[S][2];
		long ADD = 0;
		for (int i = 0; i < S; ++i) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
			int C = sc.nextInt();
			ADD += C;
			A[i] -= C;
			B[i] -= C;
			lis[i] = new int[] { A[i] - B[i], i, A[i], B[i] };
		}
		Arrays.sort(lis, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return -Integer.compare(o1[0], o2[0]);
			}
		});
		for (int i = 0; i < S; ++i) {
			A[i] = lis[i][2];
			B[i] = lis[i][3];
		}
		long[] cum1 = new long[S];
		long[] cum2 = new long[S];
		Arrays.fill(cum1, -Long.MAX_VALUE / 10);
		Arrays.fill(cum2, -Long.MAX_VALUE / 10);
		PriorityQueue<Integer> pq = new PriorityQueue<>();
		long cur = 0;
		for (int i = 0; i < S; ++i) {
			pq.add(A[i]);
			cur += A[i];
			while (pq.size() > X) {
				cur -= pq.peek();
				pq.poll();
			}
			if (pq.size() == X) {
				cum1[i] = Math.max(cum1[i], cur);
			}
		}
		pq.clear();
		cur = 0;
		for (int i = S - 1; i >= 0; --i) {
			pq.add(B[i]);
			cur += B[i];
			while (pq.size() > Y) {
				cur -= pq.peek();
				pq.poll();
			}
			if (pq.size() == Y) {
				cum2[i] = Math.max(cum2[i], cur);
			}
		}
		long ans = -Long.MAX_VALUE / 10;
		for (int i = 0; i + 1 < S; ++i) {
			ans = Math.max(ans, cum1[i] + cum2[i + 1] + ADD);
		}
		System.out.println(ans);
	}

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


Measured memory_bytes: 102860
#include <stdio.h>

int main()
{   long long s;
    scanf("%lld",&s);
    long long a,b;
    for(long long i=1;i<=1000000000;i++){
        if(i*1000000000>=s){
            printf("0 0 1000000000 1 %lld %lld",1000000000*i-s,i);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
//ユーグリッドの互除法による最大公約数を求めるメソッド
ll gcd(ll a, ll b) {
  ll smaller = min(a, b);
  ll bigger = max(a, b);
  ll surplus = bigger % smaller;
  if (surplus == 0) return smaller;
  surplus = gcd(smaller, surplus);
  return surplus;
}

//最小公倍数を求めるメソッド
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

//素数判定
bool isPrime(ll num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
      if (num % i == 0) {
        // 素数ではない
        return false;
      }
    }
    // 素数である
    return true;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll n = gcd(a, b);
  ll ans = 1;
  for(int i = 2; i <= sqrt(n); ++i){
    if(n%i != 0) continue;
    while(n%i == 0) n /= i;
    ++ans;
  }
  if(n > 1) ans++;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
  string S, T, U;
  int A, B;
  
  cin >> S >> T >> A >> B >> U;
  
  if (U == S){ 
    A--;
  } else {
    B--;
  }
  
  cout << A << " " << B << endl;
  
  return 0;
}

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

int N;
int a[2048];

int X_score[2048], Y_score[2048];
int X_score_min[2048], Y_score_max[2048];

int main(void) {
	int i;
	if (scanf("%d%d%d", &N, &a[0], &a[1]) !=3) return 1;
	N += 2;
	for (i = 2; i < N; i++) {
		if (scanf("%d", &a[i]) != 1) return 1;
	}
	X_score[N - 1] = Y_score_max[N - 1] = -1;
	Y_score[N - 1] = X_score_min[N - 1] = 1111111111;
	for (i = N - 2; i >= 0; i--) {
		int candidate = abs(a[i] - a[N - 1]);
		/* Yが最後にiのカードを引いているとき、Xは終わらせるorそれ以外でスコア最大になるようにする */
		X_score[i] = candidate > Y_score_max[i + 1] ? candidate : Y_score_max[i + 1];
		/* Xが最後にiのカードを引いているとき、Yは終わらせるorそれ以外でスコア最小になるようにする */
		Y_score[i] = candidate < X_score_min[i + 1] ? candidate : X_score_min[i + 1];
		/* XやYのスコアの最小・最大を計算する */
		X_score_min[i] = X_score[i] < X_score_min[i + 1] ? X_score[i] : X_score_min[i + 1];
		Y_score_max[i] = Y_score[i] > Y_score_max[i + 1] ? Y_score[i] : Y_score_max[i + 1];
	}
	printf("%d\n", X_score[1]);
	return 0;
}


Measured memory_bytes: 256
n = int(input())

primes = [True for i in range(n+1)]
nums = [1 for i in range(n + 1)]
for i in range(2, n + 1):
    if not primes[i]:
        continue
    for j in range(i * 2, n + 1, i):
        primes[j] = False
    x = i
    while x <= n:
        nums[i] += n//x
        x *= i

from functools import reduce
print(reduce(lambda x, y: x*y,nums)%(10**9+7))

Measured memory_bytes: 3572
l = int(input())
a = [int(input()) for _ in range(l)]

ans = [[0] * 5 for _ in range(l + 1)]
for n in range(1, l + 1):
    c = a[n - 1]
    ans[n][0] = ans[n - 1][0] + c
    ans[n][1] = min(ans[n - 1][:2]) + (c % 2 if c > 0 else 2)
    ans[n][2] = min(ans[n - 1][:3]) + (c + 1) % 2
    ans[n][3] = min(ans[n - 1][:4]) + (c % 2 if c > 0 else 2)
    ans[n][4] = min(ans[n - 1][:5]) + c

print(min(ans[l]))

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

int main() {
	int n;
	while ( cin >> n ) {
		int hei[ n+5 ]; memset( hei, 0, sizeof (hei) );
		
		for (int i = 0; i < n; ++i) cin >> hei[i];
		
		int cost[ n+5 ]; fill( cost, cost+n+5, 1 << 30 );
		cost[0] = 0;
		
		for (int i = 0; i < n-1; ++i) {
			cost[ i+1 ] = min( cost[ i+1 ], cost[i] + abs( hei[i] - hei[ i+1 ] ) );
			cost[ i+2 ] = min( cost[ i+2 ], cost[i] + abs( hei[i] - hei[ i+2 ] ) );
		}
		
		cout << cost[ n-1 ] << '\n';
	}
	return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,q;
  cin >> n >> q;
  vector<vl> edge(n,vl(0));
  REP(i,n-1){
    ll ai,bi;
    cin >> ai >> bi;
    ai--;
    bi--;
    edge[ai].push_back(bi);
    edge[bi].push_back(ai);
  }
  vl counter(n,0);
  REP(i,q){
    ll p,x;
    cin >> p >> x;
    counter[p-1] += x;
  }
  vl value(n);
  vector<bool> visited(n,false);
  queue<pll> que;
  que.push(make_pair(0,0));
  visited[0] = true;
  while(que.size()>0){
    ll node = que.front().first;
    ll given = que.front().second;
    que.pop();
    visited[node] = true;
    value[node] = counter[node]+given;
    REP(i,edge[node].size()){
      ll child = edge[node][i];
      if(visited[child]) continue;
      que.push(make_pair(child,value[node]));
    }
  }
  REP(i,n) cout << value[i] << " ";
  cout << endl;


  return 0;
}


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

namespace A
{
	class Program
	{
		static void Main(string[] args)
		{
			var dts = Console.ReadLine().Split(" ").Select(s => int.Parse(s)).ToArray();
			if (dts[0] > dts[1] * dts[2])
			{
				Console.WriteLine("No");
			}
			else
			{
				Console.WriteLine("Yes");
			}
		}
	}
}


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

int main(){
    int n;
    string s;
    cin>>n;
    cin>>s;
    int lw[n],lb[n],rw[n],rb[n];
    lw[0]=0;
    lb[0]=0;
    rw[n-1]=0;
    rb[n-1]=0;
    for(int i=1;i<n;i++){
        if(s[i-1]=='.'){
            lb[i]=lb[i-1];
            lw[i]=lw[i-1]+1;
        }else{
            lb[i]=lb[i-1]+1;
            lw[i]=lw[i-1];
        }
    }
    for(int i=n-2;i>=0;i--){
        if(s[i+1]=='.'){
            rb[i]=rb[i+1];
            rw[i]=rw[i+1]+1;
        }else{
            rb[i]=rb[i+1]+1;
            rw[i]=rw[i+1];
        }
    }
    int min=1000000;
    for(int i=0;i<n;i++){
        if(s[i]=='.'){
            int mi=rw[i]<rb[i]?lb[i]+rw[i]:lb[i]+rb[i];
            min=min<mi?min:mi;
        }else{
            int mi=lw[i]<lb[i]?lw[i]+rw[i]:lb[i]+rw[i];
            min=min<mi?min:mi;
        }
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 3716
/*
 _ _ _   _    _   _    _   _ _ _   _    _   _ __ _   __       __
|  _ _| | |  | | | |  | | |  _  | | |  | | |  __  | |   \   /   |
| |_ _  | |__| | | |  | | | |_| | | |__| | | |__| | | |\ \_/ /| |
|_ _  | |  __  | | |  | | |  _ <  |  __  | |  __  | | | \   / | |
 _ _| | | |  | | | |__| | | |_| | | |  | | | |  | | | |  \_/  | |  _   _   _
|_ _ _| |_|  |_| |_ __ _| |_ _ _| |_|  |_| |_|  |_| |_|       |_| |_| |_| |_|

*/

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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
const int  MOD=1000000007;
const int N=100010;

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t = 1;
    // cin>>t;
    for (long int tt = 1; tt <= t; tt++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int x, a, b;
  cin >> x >> a >> b;

  if (b - a <= 0) cout << "delicious" << endl;
  else if (b - a <= x) cout << "safe" << endl;
  else cout << "dangerous" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define Maxn 1000005
using namespace std;
int dp[Maxn];
int main(void)
{
	queue<int>q;
	int i,x,n;
	scanf("%d",&n);
	memset(dp,0x3F,sizeof(dp));
	for(i=1;i<=9;++i)
	{
		q.push(i);
		dp[i]=i;
	}
	while(!q.empty())
	{
		x=q.front();q.pop();
		for(i=0;i<=9;++i)
		{
			int num=(x*10+i)%n;
			if(dp[num]>dp[x]+i)
			{
				dp[num]=dp[x]+i;
				q.push(num);
			}
		}
	}
	printf("%d\n",dp[0]);
	return 0;
}


Measured memory_bytes: 5632
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main() => new Program().Solve();

	void Solve()
	{
		var n = ReadLong();
		var a = ReadLongArray();
		var q = ReadLong();

		var cnt = new int[100001];
		var sum = a.Sum();

		foreach (var aa in a) {
			cnt[aa]++;
		}

		for (var i = 0; i < q; i++) {
			var bc = ReadLongArray();
			var b = bc[0];
			var c = bc[1];

			sum += (c - b) * cnt[b];
			cnt[c] += cnt[b];
			cnt[b] = 0;

			Console.WriteLine(sum);
		}

	}

	#region Console.Read 関係
	long[] ReadLongArray() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	long ReadLong() => long.Parse(Console.ReadLine());
	#endregion
}


Measured memory_bytes: 45124
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map(String::toInt)
    val B = readLine()!!.split(" ").map(String::toInt)
    val C = readLine()!!.split(" ").map(String::toInt)

    var pre = -99
    var sti = 0
    for (i in 0 until N) {
        sti += B[A[i]-1]
        if (pre == A[i]-2) {
            sti += C[A[i]-2]
        }
        pre = A[i]-1
    }

    println(sti)
}

Measured memory_bytes: 37992
N=int(input())
S=str(input())
if N%2==1:
  print('No')
else:
  f=True
  h=int(N/2)
  for i in range(0,h):
    if S[i]!=S[h+i]:
      f=False
  if f==True:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 3316
h, w = map(int, input().split())

s = [input() for _ in range(h)]

x_inf = [[0 for i in range(w)] for j in range(h)]
y_inf = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    p = -1
    for j in range(w):
        if s[i][j]=="#":
            p = j
        else:
            x_inf[i][j] = p

for i in range(h):
    p = w
    for j in range(-1,-w-1,-1):
        if s[i][j]=="#":
            p = w+j
        else:
            x_inf[i][j] -= p-1

for i in range(w):
    p = -1
    for j in range(h):
        if s[j][i]=="#":
            p = j
        else:
            y_inf[j][i] = p

for i in range(w):
    p = h
    for j in range(h-1,-1,-1):
        if s[j][i]=="#":
            p = j
        else:
            y_inf[j][i] -= p-1
result = []
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            result.append(x_inf[i][j]+y_inf[i][j]+1)
print(-min(result))

Measured memory_bytes: 227172
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long[] dp;
    long n;
    long S;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        long L = sc.nextLong();
        long R = sc.nextLong();
        long ans = INF;
        if((R-L)>2019){
            System.out.println("0");
            return;
        }
        for (long i = L; i <= R; i++) {
            for(long j = i+1;j<=R;j++){
                ans = Math.min(ans,(i*j)%2019);
                if(ans == 0){
                    break;
                }
            }
        }
        System.out.println(ans);
    }

    int gcd(int m, int n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }
}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

	static int n;
	static int[] a = new int[100_000];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = Integer.parseInt(sc.next());
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		boolean isStairs = true;
		for (int i = n - 1; i > 1; i--) {
			if (a[i] >= a[i - 1]) {
				continue;
			} else if (a[i] + 1 == a[i - 1]) {
				a[i - 1]--;
			} else {
				isStairs = false;
				break;
			}
		}

		if (n == 1)
			isStairs = true;

		String ans = isStairs ? "Yes" : "No";
		System.out.println(ans);

	}

}


Measured memory_bytes: 49068
MOD = 10 ** 9 + 7


def nCr(n, r):
    if r > n - r:
        return nCr(n, n - r)
    numerator = denominator = 1
    for i in range(r):
        numerator = numerator * (n - i) % MOD
        denominator = denominator * (i + 1) % MOD
    return numerator * pow(denominator, MOD - 2, MOD)


n, a, b = map(int, input().split())
ans = (pow(2, n, MOD) - 1 - nCr(n, a) - nCr(n, b)) % MOD
print(ans)

Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
int l,r,d,ans=0;
int main()
{
	scanf("%d%d%d",&l,&r,&d);
	for(int i=l;i<=r;++i)
		if(i%d==0)
			ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3784
//
//  main.cpp
//  1234
//
//  Created by Moha Jain on 14/04/20.
//  Copyright © 2020 Moha Jain. All rights reserved.
//
 
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<math.h>
#include <iomanip>
#include <numeric>
#define _USE_MATH_DEFINES
 
using namespace std;
 

 
int main()
{
   long long int n;cin>>n;
    long long int a[n];
    long long int sum = 0;
    map<long long int,long long int>mp;
    for(long long int i=0;i<n;i=i+1){cin>>a[i];mp[a[i]]++;}
    
    for(auto i : mp)
    {
        long long int x = i.second;
        sum +=x*(x-1)/2;
    }
    
    for(int i=0;i<n;i=i+1)
    {
       long long  int ans = sum - (mp[a[i]]-1);
        cout<<ans<<endl;
    }
}





Measured memory_bytes: 13092
#include <vector>
#include <iostream>
#include <limits>

int main() {
  int n, temp;
  int result = std::numeric_limits<int>::min();
  int min = std::numeric_limits<int>::max();
  
  std::cin >> n;
  
  if (n == 0)
    return 0;
  
  for (auto i=0; i<n; ++i) {
    std::cin >> temp;
    
    if (i != 0 && temp - min > result)
      result = temp - min;
    
    if (temp < min)
      min = temp;
  }
  
  std::cout << result << std::endl;
}


Measured memory_bytes: 3084
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}

int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int x;
	cin>>x;
	
	if(x>=30) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	string s; cin >> s;
	ll kkt; cin >> kkt;
	ll left = s[0] - '0';
	ll ac = 0;
	for (int i = 2; i < s.size(); i += 2) {
		if (s[i - 1] == '+') {
			left += s[i] - '0';
		}
		else {
			left *= s[i] - '0';
		}
	}
	stack<ll> st;
	st.push(s[0] - '0');
	for (int i = 2; i < s.size(); i += 2) {
		if (s[i - 1] == '+') st.push(s[i] - '0');
		else {
			st.top() *= s[i] - '0';
		}
	}
	while (!st.empty()) {
		ac += st.top();
		st.pop();
	}
	if (left == kkt && ac == kkt) {
		puts("U");
	}
	else if (left == kkt) {
		puts("L");
	}
	else if (ac == kkt) {
		puts("M");
	}else{
		puts("I");
	}
	return 0;

}



Measured memory_bytes: 3240
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;

int main()
{

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


	ll n; cin >> n;
	vector<ll> sc(n + 2), ss(n + 2);
	vector<ll> cnt(n + 1);
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		cnt[x]++;
	}
	for (int i = 0; i <= n; i++) sc[cnt[i] + 1] += 1, ss[cnt[i] + 1] += cnt[i];
	for (int i = 0; i <= n; i++) sc[i + 1] += sc[i], ss[i + 1] += ss[i];
	for (int k = 1; k <= n; k++) {
		ll lf = 0;
		ll rg = n + 1;
		while (rg - lf > 1) {
			ll mid = (lf + rg) >> 1;
			ll lm = mid;
			ll sm = lm * (sc.back() - sc[lm + 1]) + ss[lm + 1];
			//cout << lm << " " << sm << endl;
			//if (k == n and mid == 4) cout << "a: "<< sm << endl;
			if (sm >= mid * k) lf = mid;
			else rg = mid;
		}
		//cout << k << " " << lf << endl;
		cout << lf << "\n";
	}
	return 0;
}


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

int dp[3][100005];

int main() {
    int N;
    cin >> N;
    vector<int> a(N), b(N), c(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }

    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];

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

    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;

long long solve(){
    int k,n;
    cin>>k>>n;
    if(k*500>=n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

int main(){
    int T = 1;
    while(T--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))

int n,a[110];
int main(){
	scanf("%d",&n);
	int M=0;
	rep(i,0,n){
		int t;
		scanf("%d",&t);
		a[t]++;
		M=max(M,t);
	}
	
	int ngflag=0;
	if(M%2==0){
		rep(i,0,M/2)ngflag|=a[i]!=0;
		rep(i,M/2+1,M+1)ngflag|=a[i]<=1;
		if(a[M/2]!=1)ngflag=1;
	}else{
		if(n!=2&&M==1)ngflag=1;
		rep(i,0,M/2+1)ngflag|=a[i]!=0;
		rep(i,M/2+2,M+1)ngflag|=a[i]<=1;
		if(a[M/2+1]!=2)ngflag=1;
	}
	puts(ngflag?"Impossible":"Possible");
}

Measured memory_bytes: 128
use std::io::prelude::*;
use std::str::FromStr;
pub struct Scanner<R: Read>(R);
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self(reader)
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| (b as char).is_whitespace())
            .take_while(|&b| !(b as char).is_whitespace())
            .collect::<Vec<u8>>();
        unsafe { std::str::from_utf8_unchecked(token.as_slice()) }
            .parse()
            .ok()
            .expect("Can't parse it.")
    }
    pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut out = std::io::BufWriter::new(stdout.lock());
    solve(&mut sc, &mut out);
    out.flush().ok().unwrap();
}
fn solve(sc: &mut Scanner<std::io::StdinLock>, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let (n, k, c): (usize, usize, usize) = (sc.read(), sc.read(), sc.read());
    let s = sc.chars();

    let mut pos: usize = 0;
    let l: Vec<usize> = (0..k)
        .map(|_| {
            while s[pos] == 'x' {
                pos += 1;
            }
            pos += c + 1;
            pos - c - 1
        })
        .collect();

    let mut pos: usize = n - 1;
    let r: Vec<usize> = (0..k)
        .map(|i| {
            while s[pos] == 'x' {
                pos -= 1;
            }
            if i + 1 < k {
                pos -= c + 1;
                pos + c + 1
            } else {
                pos
            }
        })
        .collect();

    for (x, y) in l.iter().zip(r.iter().rev()) {
        if x == y {
            println!("{}", x + 1);
        }
    }
}


Measured memory_bytes: 5980