akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap

def eratosthenes(n):
    p = [1]
    t = [True] * n

    t[1] = True
    for i in range(2, int(math.ceil(math.sqrt(n)))):
        if t[i]:
            p.append(i)
            for j in range(2*i, n, i):
                t[j] = False

    for j in range(i+1, n):
        if t[j]:
            p.append(j)

    return p


@mt
def slv(N):
    ps = eratosthenes(100)
    ps.pop(0)
    c = Counter()
    for i in range(2, N+1):
        n = i
        while n not in ps:
            for p in ps:
                if n % p == 0:
                    c[p] += 1
                    n //= p
                    break
        c[n] += 1

    c2 = len(list(filter( lambda x: x>=2, c.values())))
    c4 = len(list(filter( lambda x: x>=4, c.values())))
    c14 = len(list(filter( lambda x: x>=14, c.values())))
    c24 = len(list(filter( lambda x: x>=24, c.values())))
    c74 = len(list(filter( lambda x: x>=74, c.values())))
    ans = 0
    if c2 >= 3 and c4 >= 2:
        ans += (c4*(c4-1)//2) * (c2-2)
    if c4 > 0 and c14 > 0:
        ans += (c4-1) * c14
    if c2 > 0 and c24 > 0:
        ans += (c2-1) * c24
    if c74 > 0:
        ans += c74
    return ans


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5448
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<numeric>
#include<math.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;
    s = '#' + s + '#';

    auto can_reach = [&](int start, int end ) {
        for ( int i = start; i < end; ++i ) {
            if ( s[i] == '#' && s[i+1] == '#' ) return false;
        }
        return true;
    };

    if ( !can_reach(a, c) || !can_reach(b, d) ) {
        cout << "No" << endl;
        return 0;
    }

    if ( c > d ) {
        bool snuke_can_over = false;
        for ( int i = b; i <= d; ++i ) {
            if ( s[i-1] == '.' && s[i] == '.' && s[i+1] == '.' ) {
                snuke_can_over = true;
            }
        }
        if ( !snuke_can_over ) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 772
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll a,b,m; cin >> a >> b >> m;
  vl an(a); vl bn(b);
  rep(i,a){ ll x; cin >> x; an[i] = x; }
  rep(i,b){ ll x; cin >> x; bn[i] = x; }
  
  ll lowcost = 100000000;
  for(ll i=0; i < m; i++){
    ll x,y,c; cin >> x >> y >> c;
    lowcost = min(lowcost,an[x-1]+bn[y-1]-c);
  }
  
  sort(all(an)); sort(all(bn));
  
  lowcost = min(lowcost,an[0]+bn[0]);
  
  cout << lowcost << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
const int MAXN=3300;
double p[MAXN], f[MAXN][MAXN];
int main()
{
//	freopen("I.in", "r", stdin);
//	freopen("I.out", "w", stdout);
	int n;
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%lf", &p[i]);
	f[0][0]=1.0;
	for (int i=1; i<=n; i++)
	{
		f[i][0]=f[i-1][0]*(1.0-p[i]);
		for (int j=1; j<=n; j++)
			f[i][j]=f[i-1][j-1]*p[i]+f[i-1][j]*(1.0-p[i]);
	}
	double ans=0.0;
	for (int i=n/2+1; i<=n; i++) ans+=f[n][i];
	printf("%.10lf\n", ans);
	return 0;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];

    sort(a, a+n, greater<int>());

    int sum = 0;
    for(int i = 0; i < k; i++){
        sum += a[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    map<int,map<int,int>> m;
    rng(i,1,100){
        rng(j,1,100){
            rng(k,1,100){
                int x = pow(i+j+k,2);
                int y = i*j+j*k+k*i;
                m[x][y]++;
            }
        }
    }
    rng(i,1,n+1){
        int ans = 0;
        rng(j,1,150){
            if(j*j <= i) continue;
            ans += m[j*j][j*j-i];
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> cntb(n+1);
  for (int i = 2; i <= n; i++) {
    int boss;
    cin >> boss;
    cntb[boss]++;
  }
  for (int i = 1; i <= n; i++)
    cout << cntb[i] << endl;
}


Measured memory_bytes: 4048
#!/usr/bin/env python3
#AGC24 C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = [I() for _ in range(n)]
if a[0] != 0:
    print(-1)
    quit()
for i in range(1,n):
    if a[i] - a[i-1] > 1:
        print(-1)
        quit()
ans = 0
for i in range(1,n):
    if a[i] <= a[i-1]:
        ans += a[i]
        continue
    if a[i] == a[i-1] + 1:
        ans += 1
        continue
print(ans)


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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;

int main() {
  int N;

  cin >> N;
  vector< pair< pair< int, int >, int > > st(N);
  for(int i = 0; i < N; i++) {
    cin >> st[i].first.second >> st[i].first.first >> st[i].second;
  }
  sort(begin(st), end(st), [&](auto x, auto y) {
    return (x.first.first - y.first.second < y.first.first - x.first.second);
  });


  vector< int64 > dp(10002);
  int ret = 0;
  for(int i = 0; i < N; i++) {
    for(int j = st[i].first.first; j >= 0; j--) {
      int idx = min(j + st[i].first.second, 10001);
      dp[idx] = max(dp[idx], dp[j] + st[i].second);
    }
  }

  cout << *max_element(begin(dp), end(dp)) << endl;
}

Measured memory_bytes: 3700
#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>;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    bool fir, sec;
    rep(i,10)rep(j,10)rep(k,10){
    	fir = sec = false;
    	rep(l,n){
    		if(fir && sec){
    			if((s[l]-'0') == k){
    				ans++;
    				break;
    			}
    		}
    		else if(fir){
    			if((s[l]-'0') == j) sec = true;
    		}
    		else{
    			if((s[l]-'0') == i) fir = true;
    		}
    	}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
n, p = map(int, input().split())
ps = []
for i in range(n):
    ps.append(input().split())
    ps[i][1] = int(ps[i][1])
t = 0
while len(ps) > 0:
    if ps[0][1] > p:
        ps.append([ps[0][0], ps[0][1] - p])
        t += p
        ps.pop(0)
    else:
        t += ps[0][1]
        print("{0} {1}".format(ps[0][0], t))
        ps.pop(0)


Measured memory_bytes: 16848
using System;

namespace abc150_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] KX = Console.ReadLine().Split(" ");
            int K = int.Parse(KX[0]);
            int X = int.Parse(KX[1]);
            int sum = K * 500;

            if(X <= sum)
            {
                Console.WriteLine("Yes");
            }else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define N_MAX 8

// int dat[N_MAX];
void init(vi &dat){
  dat.assign(N_MAX,-1);
}
int root(vi &dat,int x){
  return dat[x]<0 ? x : (dat[x]=root(dat,dat[x]));
}
void unite(vi &dat,int x,int y){
  x=root(dat,x);
  y=root(dat,y);
  if(x!=y){
    if(dat[x]>dat[y])swap(x,y);
    dat[x] += dat[y];
    dat[y] = x;
  }
}
bool same(vi &dat, int x,int y){
  return root(dat,x)==root(dat,y);
}
int size(vi &dat, int x){
  return -dat[root(dat,x)];
}

typedef double Real;
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}
#define EPS 1e-14

int n;
P p[10];
vector<pii> connect[10][10];

int dfs(const int &cnt,vi &uf){
  if(size(uf,0) == n)return cnt;

  int ret = 100;
  REP(to,n){
    if(same(uf,0,to))continue;
    REP(from,n){
      if(!same(uf,0,from))continue;
      vector<pii> con = connect[from][to];
      vi nextuf = uf;
      REP(i,con.size()) unite(nextuf,con[i].first,con[i].second);
      int d = dfs(cnt+1,nextuf);
      if(d==cnt+1)return d;
      ret = min(ret,d);
    }
  }
  return ret;
}

int main(){
  cin>>n;
  REP(i,n){
    int x,y;
    cin>>x>>y;
    p[i] = P((Real)x,(Real)y);
  }
  REP(i,n)REP(j,n){
    if(i==j)continue;
    // make connect[i][j];
    P v = p[i]-p[j];
    P cv = p[j] + v/P(2,0);
    P mirror = v*P(0,1);
    REP(x,n){
      P a = p[x];
      // reflect
      a = conj((a-cv)/mirror)*mirror+cv;
      REP(y,x){
        if(abs(p[y]-a)<EPS)connect[i][j].push_back(make_pair<int,int>(x,y));
      }
    }
  }
  vi beg;
  init(beg);
  cout<<dfs(0,beg)<<endl;
  return 0;
}

Measured memory_bytes: 1240
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(); scan.nextLine();  //個数nを入力

		String v = scan.nextLine();  //入力列
		String[] a = v.split(" "); //" "で区切って配列にする
		int count = 0;
		int[] number = new int[n]; //数字の配列を作る
		
		for(int i = 0; i < n; i++){ //入力列の配列を先ほど作った数字の配列に代入
			number[i] = Integer.parseInt(a[i]);
			//System.out.print(number[i] + " ");
		}
		
		boolean assess = true;
		while(assess){
			for(int i = 0; i < n; i++){
				if((number[i]) % 2 == 0){
					number[i] = number[i] / 2;
					count++;
				}else{
					assess = false;
					break;
				}
			}
		}
		System.out.println(count/n);	
	}
}

Measured memory_bytes: 21588
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    n,k = readInt()
    a = readInt()
    pos = 0
    visit = [0] * n
    move = []
    roop = []
    while visit[pos]!=2:
        if visit[pos]==0:
            move.append(pos)
        else:
            roop.append(pos)
        visit[pos] += 1
        pos = a[pos] - 1
    num = 0
    if len(move)>k:
        print(move[k]+1)
    else:
        num = (k - (len(move)-len(roop))) % len(roop)
        print(roop[num]+1)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 32884
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1160
// How Many Islands?

#define SUBMIT

#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

enum class space_type {
    sea = 0,
    land = 1
};

const int NOT_GROUPED = -1;
const int MAX_SIDE = 50;
space_type field[MAX_SIDE][MAX_SIDE];
int field_id[MAX_SIDE][MAX_SIDE];
int h, w;
int n_groups;

void dfs(int y, int x) {
    if (y < 0 || h <= y || x < 0 || w <= x) return;
    if (field[y][x] == space_type::sea) return;
    if (field_id[y][x] != NOT_GROUPED) return;

    field_id[y][x] = n_groups;

    dfs(y - 1, x - 1);
    dfs(y - 1, x);
    dfs(y - 1, x + 1);

    dfs(y, x - 1);
    dfs(y, x + 1);

    dfs(y + 1, x - 1);
    dfs(y + 1, x);
    dfs(y + 1, x + 1);
}

void start_dfs() {
    for (int y = 0; y < h; ++y) {
        for (int x = 0; x < w; ++x) {
            field_id[y][x] = NOT_GROUPED;
        }
    }

    n_groups = 0;
    for (int y = 0; y < h; ++y) {
        for (int x = 0; x < w; ++x) {
            if (field[y][x] == space_type::land && field_id[y][x] == NOT_GROUPED) {
                dfs(y, x);
                n_groups++;
            }
        }
    }
}

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    string program_input_str = R"(1 1
0
2 2
0 1
1 0
3 2
1 1 1
1 1 1
5 4
1 0 1 0 0
1 0 0 0 0
1 0 1 0 1
1 0 0 1 0
5 4
1 1 1 0 1
1 0 1 0 1
1 0 1 0 1
1 0 1 1 1
5 5
1 0 1 0 1
0 0 0 0 0
1 0 1 0 1
0 0 0 0 0
1 0 1 0 1
0 0
)";
    stringstream stream(program_input_str);
#endif
    while (true) {
        stream >> w >> h;
        if (h == 0 && w == 0) break;

        int c;
        for (int y = 0; y < h; ++y) {
            for (int x = 0; x < w; ++x) {
                stream >> c;
                field[y][x] = static_cast<space_type>(c);
            }
        }

        start_dfs();
        cout << n_groups << endl;
    }

    return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define lli long long int
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define se second;
#define fi first;
#define endl '\n';
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define REP(i,n) for (int i = 1; i <= n; i++)
template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
typedef long long ll;
typedef vector<vector<ll> > matrix;
const ll MOD = 1000000007;
const int K = 9;
const lli mod = 1e9 + 7;
const lli INF = 1e9 + 7;
const lli N=2*1e5;
int main(){
  _
  lli n,a,b,ans1=0,ans2=0,ans3=0,x;
  cin>>n>>a>>b;
  for(lli i=0;i<n;i++){
    cin>>x;
    if(x<=a){
      ans1++;
    }
    else if(x>a and x<=b){
      ans2++;
    }
    else if(x>=b+1){
      ans3++;
    }
  }
  cout<<min(ans1,min(ans2,ans3))<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
const long long int k = 998244353;
int main()
{
    int n;
    cin >> n;
    int d[n];
    long long int a[100010] = {};
    int Max = 0;
    for(int i = 0;i < n;i++)
    {
        cin >> d[i];
        if(d[i] > Max)
        {
            Max = d[i];
        }
        a[d[i]]++;
    }
    if(d[0] != 0 || a[d[0]] != 1)
    {
        cout << "0\n";
        return 0;
    }
    long long int ans = 1;
    for(int i = 1;i <= Max;i++)
    {
        long long int x = 1,y = a[i - 1];
        for(int j = 0;j < a[i];j++)
        {
            x *= y;
            x = x % k;
        }
        ans *= x;
        ans = ans % k;
    }
    cout << ans % k << "\n";
    
    return 0;
}

Measured memory_bytes: 1408
n,a,b = map(int, input().split( ))
h = [int(input()) for _ in range(n)]
mx = 10**10
mn = 0
#2分探索
while mx-mn>1:
    md = (mx+mn)//2
    h2 = [h[i]-md*b for i in range(n)]
    
    tmp = 0
    for i in range(n):
        if h2[i]>0:
            tmp += (h2[i]+(a-b)-1)//(a-b)
    if tmp<=md:
        mx = md
    else:
        mn = md

print(mx)            



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

int main(void){

    int A, B, X;

    scanf("%d%d%d", &A, &B, &X);

    if(A <= X && X <= (A+B)){
        printf("YES\n");
    }else{
        printf("NO\n");
    }

    return 0;
}

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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    int a[100010];
    int b[100010];
    cin >> N;
    rep(i, N) cin >> a[i] >> b[i];
    int64_t plus = 0;
    rep(i, N) {
        int k = N - i - 1;
        int po = b[k] - (a[k] + plus) % b[k];
        if (po < b[k]) plus += po;
    }
    
    cout << plus << endl;
    
    return 0;
}

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

signed main () {
    string s, t;
    cin >> s >> t;
    if (t.size() == s.size() + 1) {
        for (int i = 0; i < int(s.size()); ++i) {
            if (s[i] != t[i]) {
                cout << "No\n";
                return 0;
            }
        }
        cout << "Yes\n";
    }
    else
        cout << "No\n";
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
string s,s1,s2;
cin>>s1>>s2;
s=s1+s1;
for(int i=0;i<s1.size();i++)
{
n=i;
m=0;
for(int j=0;j<s2.size();j++)
{
if(s[n]!=s2[j])
{
m=1;
break;
}
n++;
}
if(m==0)
{
cout<<"Yes"<<endl;
return 0;
}
}
cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())

#各桁の合計を求める
def dsum(n): 
    s = str(n)
    array = list(map(int, s))
    return sum(array)

count = 0   
for i in range(1,N+1):
    if A <= dsum(i) <= B:
        count += i

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n,i,a[200200];
long long s,cur,r;
int main() {
  scanf("%d",&n);
  for (i=0; i<n; i++) {
    scanf("%d",&a[i]);
    s+=a[i];
  }
  r=s;
  for (i=0; i<n; i++) {
    cur+=a[i];
    r=min(r,abs(s-cur-cur));
  }
  printf("%d\n",r);
  return 0;
}


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

int main() {
	int N, K;
	cin >> N >> K;
	// 辺1に辺[2..N]をつなげる(スターグラフにする)
	// この状態で, (N-1)(N-2)/2個の最短距離2の頂点対ができる
	// [2..N]のうち繋がっていない頂点対を(N-1)(N-2)/2 - K(個)繋げる
	// ちなみに, K > (N-1)(N-2)/2 のときは無理
	if(K > (N - 1) * (N - 2) / 2) {
		cout << -1 << endl;
		return 0;
	}

	cout << (N - 1) + (N - 1) * (N - 2) / 2 - K << endl;
	for(int i=2;i<=N;i++) {
		cout << 1 << " " << i << endl;
	}
	int left = 2, right = 3;
	for(int i=0;i<(N-1)*(N-2)/2-K;i++) {
		cout << left << " " << right << endl;
		right++;
		if(right == N + 1) {
			left++;
			right = left + 1;
		}
	}
	return 0;
}

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

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

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N; cin >> N;
	vector<int> a(N);
	for (int& x: a) cin >> x;
	vector<int> A = a;
	sort(A.begin(), A.end());
	for (int& x: a) x = lower_bound(A.begin(), A.end(), x) - A.begin();
	int ans = 0;
	for (int i = 0; i < N; i++)
		if (i % 2 != a[i] % 2)
			ans++;
	cout << ans / 2 << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<queue>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)


queue<int> que;


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

	vector<int> nodes_flag(N,-1);
	vector<vector<int>> graph(N);

	REP(i,M){

		int from,to;
		cin>>from>>to;
		graph[from-1].push_back(to-1);
		graph[to-1].push_back(from-1);
	}
	
	que.push(0);
	nodes_flag[0] = 0;
	int count = 1;
	while(!que.empty()){

		int index = que.front();que.pop();
	
		for(int i = 0; i < graph[index].size();i++){
			if(nodes_flag[graph[index][i]] == -1){
				que.push(graph[index][i]);
				nodes_flag[graph[index][i]] = index;
				count++;
			}
		}
	}
	if(count == N){
		cout<<"Yes"<<endl;

		REP(j,N-1){
			cout<<1 + nodes_flag[j+1]<<endl;
		}
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}



Measured memory_bytes: 10300
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< string > S(N);
	rep(i, N) cin >> S[i];
	int ans = 0;
	rep(k, N) {
		rep(i, N) rep(j, N - 1) swap(S[i][j], S[i][(j + 1) % N]);
		bool f = true;
		rep(i, N) rep(j, N) if (S[i][j] != S[j][i]) f = false;
		if (f)
			ans += N;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
  char s[5];
  int flaga = 0, flagb = 0;
  cin >> s;
  for (int i = 0; i< 3; i++)
  {
    if (s[i] == 'A') flaga = 1;
    else flagb=1;
  }
  if (flaga && flagb) cout << "Yes";
  else cout << "No";
  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 N = sc.nextInt();
    int[] d = new int[N];

    for (int i = 0; i < N; i++) {
      d[i] = sc.nextInt();
    }
    sc.close();

    Arrays.sort(d);

    int[] a = new int[N/2];
    int[] b = new int[N/2];

    for (int i = 0; i < N/2; i++) {
      a[i] = d[i]; 
    }

    int j = 0;
    for (int i = N/2; i < N; i++) {
      b[j] = d[i];
      j++;
    }

    int count = 0;
    if (a[N/2-1] < b[0]){
      count = b[0] - a[N/2-1];
    }

    System.out.println(count);

  }
  
}

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

#define M 1046527 /* your task*/
#define L 14
#define NIL (-1)

char H[M][L]; /* Hash Table */

int getChar(char ch) {
	if (ch == 'A') return 1;
	else if (ch == 'C') return 2;
	else if (ch == 'G') return 3;
	else if (ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
	long long sum = 0, p = 1, i;
	for (i = 0; i < strlen(str); i++) {
		sum += p * (getChar(str[i]));
		p *= 5;
	}
	
	return sum;
}

int h1(int key) { return key % M ; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
	long long key, i = 0, h;
	key = getKey(str);
	while (1) {
		h = (h1(key) + i * h2(key)) % M;
		i++;
		if (strcmp(H[h], str) == 0) return 1;
		else if (strlen(H[h]) == 0) return 0;
	}
	return 0;
}

int insert(char str[]) {
	long long key, i = 0, h;

	key = getKey(str);
	while (1) {
		h = (h1(key) + i * h2(key)) % M;
		i++;
		if (strcmp(H[h], str) == 0) return 1;
		else if (strlen(H[h]) == 0) {
			strcpy(H[h], str);
			return 0;
		}
	}

	return 0;

}

int main() {
	int i, n, h;
	char str[L], com[9];
	for (i = 0; i < M; i++) H[i][0] = '\0';

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%s %s", com, str);

		if (com[0] == 'i') {
			insert(str);
		}
		else {
			if (find(str)) {
				printf("yes\n");
			}
			else {
				printf("no\n");

			}
		}
	}

	return 0;
}


Measured memory_bytes: 16044
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }

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

	int n;
	cin >> n;

	vector<int> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	int k = n / 2;
	if(n % 2 == 1){
		int k = n / 2;
		cout << b[k] - a[k] + 1 << endl; 
	}else{
		cout << b[k-1] - a[k-1] + b[k] - a[k] + 1 << endl;
	}
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define mm 1000000007
#define pb push_back
									//nestedcode
ll dp[200005] , vis[200005] ,aa[200005];
vector<ll> adj[200005]; 									
void dfs(ll n){
    ll i;
	vis[n] = 1;
	
	for(i=0;i<adj[n].size();i++){
		if(vis[ adj[n][i] ]== 0){
			dp[ adj[n][i] ] = dp[n] + aa[ adj[n][i] ];
			dfs(adj[n][i]);
		}
	}
}


 int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0); cout.tie(0);
  	ll n,q,i,a,b,p,v;
 	cin>>n>>q;
 	for(i=0;i<n-1;i++){
 		cin>>a>>b;
 		adj[a].pb(b);
 		adj[b].pb(a);
	 }
	 for(i=0;i<q;i++){
	 	cin>>p>>v;
	 	aa[p]+=v;
	 }
	 dp[1] = aa[1];
	 dfs(1);
	 for(i=1;i<=n;i++){
	 	cout<<dp[i]<<" ";
	 }
}

Measured memory_bytes: 27392
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    K, X = list(map(int, sys.stdin.readline().split()))

    ret = []
    for i in range(X-K+1, X+K):
        ret.append(i)

    print(*ret)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <vector>
#define int long long
typedef long long ll;
using namespace std;

ll n, m, q;
vector<ll> a, b, c, d;
ll ans=0;

void dfs(ll id, vector<ll> v) {
    //if(v[id-1]>m) return;
    if(id==n+1) {
        //for(int i=1;i<=n;i++) cout << " " << v[i];
        //cout << endl;
        //cout << endl;
        ll maxv=0;
        for(int k=0;k<q;k++) {
            if(v[b[k]]-v[a[k]]==c[k]) maxv += d[k];
        }
        ans = max(ans, maxv);
        return;
    }
    for(int i=v[id-1];i<=m;i++) {
        v[id]=i;
        dfs(id+1, v);
    }
    //v[id]=v[id-1];
    //dfs(id+1, v);
    //v[id]=v[id-1]+1;
    //dfs(id+1, v);
}

signed main(){
    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    for(int i=0;i<q;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    vector<ll> v(n+1, 1);
    //cout << ans << endl;
    dfs(1, v);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  cin>>n;
  ll a[n],b[n];
  
  for(ll i=0;i<n;i++)
  {
  	cin>>a[i];
    b[i]=a[i];
  }
  sort(b,b+n);
  ll max1 = b[n-1];
  ll max2 = b[n-2];
  
  for(ll i=0;i<n;i++)
  {
  	if(a[i]!=max1)
      cout<<max1<<endl;
    else
      cout<<max2<<endl;
  }
	return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>

#define endl "\n"

using namespace std;

template<typename T>
void printArray(T a) {
    for(auto i : a)
        cout << i << " ";

    cout << endl;
}

template<typename T>
void print2DArray(T a) {
    for(auto i : a) {
        for(auto j : i)
            cout << j << " ";

        cout << endl;
    }
    cout << endl;
}

int main(int argc, char *argv[])
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n = 1;
    cin >> n;
    vector<int> h = vector<int>(n);
    vector<int> m = vector<int>(n);

    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    for (int i = n-2; i >= 0; i--) {
        if (h[i] >= h[i+1]) {
            m[i] = m[i+1] + 1;
        }
    }
    if (n != 1 && h[0] >= h[1]) {
        m[0] = m[1] + 1;
    }
    else {
        m[0] = 0;
    }

    /* cout << n */
    /* printArray(m); */

    int max = *max_element(m.begin(), m.end());

    cout << max << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int X;
  cin>>X;
  int i = 0;
  while(i < 1001){
    if(X >= 100 * (i + 1) && X <= 105 * (i + 1)){
      cout<<1<<endl;
      break;
    }
    else if(i == 1000){
      cout<<0<<endl;
    }
    i++;
  }
}


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



#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    llong N,K;
    cin >> N;
    llong A[N];
    llong ng=0,nk=0;
    for(int i=0;i<N;i++){
        scanf("%lld",&A[i]);
        if(A[i]%2==0)ng++;
        else nk++;

    }
    if(nk%2==1){
        cout <<"NO"<<endl;
    }else{
        cout << "YES"<<endl;
    }
    
    
    
    return 0;
}

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

int main(){
    int X;
    cin >> X;
    int maxi = 0;
    for(int i = 2;i<=X;i++){
        int total = 0;
        total = i*i;
        while (total<=X){
            total = total*i;
            if(total > X){
                    total = total/i;
                    maxi = max(total,maxi);
                    break;
                }
            }
            
        }
    if(X==1){
        cout << 1;
        return 0;
    }
    cout << maxi;
    }



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

int main() {
  int N, K, x;
  x = 1;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    if(x >= K){
      x += K;
    }
    else{
      x *= 2;
    }
  }
  cout << x << endl;   
}


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

typedef pair<pair<int,int>,int> State;

int w,h;
const int INF=1e8;

bool isrange(pair<int,int> x){
	return (0<=x.first && x.first<h && 0<=x.second && x.second<w);
}

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


int main(){
	while(cin>>w>>h,w){
		vector<string> c(h);
		for(int i=0;i<h;i++) cin>>c[i];
		vector<pair<int,int>> dust;
		pair<int,int> robot;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				auto place=make_pair(i,j);
				if(c[i][j]=='o'){
					robot=place;
				}
				if(c[i][j]=='*'){
					dust.push_back(place);
				}
			}	
		}
		State tate=make_pair(robot,0);
		pair<State,int> first_state=make_pair(tate,0);
		int res=INF;
		map<State,int> dp;
		queue<pair<State,int>> q;
		q.push(first_state);
		while(!q.empty()&& res==INF){
			auto pstate=q.front();
			q.pop();
			State state=pstate.first;
			auto now=state.first;
			for(int i=0;i<4;i++){		
				pair<int,int> to=make_pair(now.first+dx[i],now.second+dy[i]);
				if(isrange(to) && c[to.first][to.second]!='x'){
					int bit=state.second;
					if(c[to.first][to.second]=='*'){
						for(int i=0;i<dust.size();i++){
							if(dust[i]==to && ((~bit) & (1<<i))){
								bit+=(1<<i);
							}
						}

					}
					auto tostate=make_pair(to,bit);
					if(dp.count(tostate)) continue;
					dp[tostate]=pstate.second+1;
					if(bit==(1<<dust.size())-1){
						res=pstate.second+1;
					}
					q.push(make_pair(tostate,pstate.second+1));
				}
			}


		}
		if(res==INF) res=-1;
		cout<<res<<endl;
	}


}

Measured memory_bytes: 8548
#include <iostream>
#include <stdio.h>
using namespace std;
static const int LEN = 100000;

struct Queue {
	char name[10];
	int time;
};

struct Queue Q1[LEN];
int head, tail;

bool isEmpty() {
	return head == tail;
}

bool isFull() {
	return head == ((tail + 1) % LEN);
}

void enqueue(struct Queue q1) {
	Q1[tail] = q1;
	if (tail == (LEN - 1)) {
		tail = 0;
	}
	else {
		tail++;
	}
}

struct Queue dequeue() {
	if (head == (LEN - 1)) {
		head = 0;
		return Q1[LEN - 1];
	}
	else {
		return Q1[head++];
	}
}

int main() {
	int n, q, elaps = 0;
	struct Queue x;

	scanf("%d %d", &n, &q);
	for (int i = 1; i < n + 1; i++) {
		scanf("%s %d", Q1[i].name, &Q1[i].time);
	}
	head = 1;	tail = n + 1;

	while (!isEmpty()) {
		//cout << "head:" << head << "   tail:" << tail << endl;
		if (Q1[head].time > q) {
			Q1[head].time = Q1[head].time - q;
			enqueue(Q1[head]);
			dequeue();
			elaps += q;
		}
		else {
			x = dequeue(); 
			elaps += x.time;
			cout << x.name << " " << elaps << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 4708
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<sstream>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 1000000000+7
using namespace std;
typedef long long ll;

int mini = INF;
int N, K;
vector<int> like;

void solve(string s){
  int num = stoi(s);
  if(num>=N){
    mini = min(mini, num);
    return;
  }
  for(int n:like){
    solve(s+to_string(n));
  }
}

int main(){
  cin >> N >> K;
  set<int> hate;
  rep(i, 0, K){
    int n;  cin >> n;
    hate.insert(n);
  }
  rep(i, 0, 10) if(hate.find(i)==hate.end())  like.push_back(i);
  for(int n:like){
    if(n!=0)  solve(to_string(n));
  }
  cout << mini << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	double r;
	while(cin>>r>>n,r||n){
		double h[50]={0};
		rep(i,n){
			int a,b;
			double c;
			cin>>a>>b>>c;
			a+=25;b+=25;
			for(int i=a;i<b;i++)h[i]=max(h[i],c);
		}
		//loop(i,20,30)cout<<" "<<h[i];
		//cout<<endl;
		double t=0;
		while(1){
			t+=0.0001;
			bool ans=true;
			rep(i,49){
				if((double)(i-25)*(i-25)+(r+h[i]-t)*(r+h[i]-t)<r*r){
					ans=false;
					break;
				}
				if((double)(i-24)*(i-24)+(r+h[i]-t)*(r+h[i]-t)<r*r){
					ans=false;
					break;
				}
			}
			if(!ans)break;
		}
		cout<<t-0.0001<<endl;
	}
	
}

Measured memory_bytes: 1288
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

n,m = map(int,input().split())
kss=[]
ans = 0
for i in range(m):
    ks = list(map(int,input().split()))
    kss.append(ks)
p = list(map(int,input().split()))
for i in range(2**n):
    switch = set()
    for j in range(n):
        if (i>>j)&1:
            switch.add(j+1)

    bool = True
    for k in range(m):
        if len(set(kss[k][1:])&switch)%2 == p[k]:
            continue
        else:
            bool = False
    if bool:
        ans += 1
print(ans)


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

int		main(void)
{
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	if (K <= A)
	{
		cout << K << endl;
	}
	else if (K <= A + B)
	{
		cout << A << endl;
	}
	else
	{
		cout << 2 * A + B - K << endl;
	}

	return (0);
}

Measured memory_bytes: 3612
#include<stdio.h>
int main(){
    int n ,a[1001]={}, i, j, tmp, k;
    scanf("%d", &n);
    for( i = 0; i < n ; i++){
        scanf("%d", &a[i]);
        if( i == n -1 ){
        printf("%d", a[i]);
        }else printf("%d ", a[i]);
    }
    printf("\n");
    for( i = 1; i < n; i++ ){
        tmp = a[i];
        j = i - 1;
        while( j >= 0 && a[j] > tmp ){
            a[j+1] = a[j];
            j--;
            a[j+1] = tmp;
        }
        for( k = 0; k < n; k++ ){
            if( k == n-1 ){
                printf("%d", a[k]);
            }else{
                printf("%d ", a[k]);
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int l=s.length(),p=0,r=0,tot=0;
	for(int i=0;i<l;i++){
		if(s[i]=='G'||s[i]=='g')
		{
			if(p<=r)p++;
			else r++,tot++;
		}
		else{
			if(p<=r)p++,tot--;
			else r++;
		}
	}
	cout<<tot;
	return 0;
}

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

const int INF = 1<<29;

int main(){
    int w, d;
    while(true){
        scanf("%d%d", &w, &d);
        vector<int> h1(w), h2(d);
        if(w == 0 && d == 0) break;
        for(int i = 0; i < w; i++){
            scanf("%d", &h1[i]);
        }
        for(int i = 0; i < d; i++){
            scanf("%d", &h2[i]);
        }
        sort(h1.begin(), h1.end());
        sort(h2.begin(), h2.end());
        vector<int> mul(w);
        fill(mul.begin(), mul.end(), 1);
        vector<int>::iterator left;
        left = h1.begin();
        int ans = 0;
        for(int i = 0; i < d; i++){
            ans += h2[i];
            vector<int>::iterator lb = lower_bound(left, h1.end(), h2[i]);
            if(*lb == h2[i]){
                mul[lb++ - h1.begin()] = 0;
            }
            left = lb;
        }
        for(int i = 0; i < w; i++){
            ans += mul[i] * h1[i];
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1208
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var len = Number(lines[0]);
 var s = lines[1].split('');
 var x = 0;
 var ar = [];
 ar.push(x);
 for(i=0; i<len; i++){
   if(s[i] == 'I'){
     x++;
     ar.push(x);
   }else if(s[i] == 'D'){
     x--;
     ar.push(x);
   }
 }

 console.log(Math.max(...ar));
});

Measured memory_bytes: 11724
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  bool flag1, flag2, flag3, flag4;
  flag1 = false;
  flag2 = false;
  flag3 = false;
  flag4 = false;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'N') flag1 = true;
    else if (s[i] == 'S') flag2 = true;
    else if (s[i] == 'W') flag3 = true;
    else if (s[i] == 'E') flag4 = true;
  }
  if (flag1 == flag2 && flag3 == flag4) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define opr iterator
#define pii pair<int,int>
typedef long long ll;
using namespace std;
int deg[100001],q[100001],head,tail,n,m,d[100001];
vector<int> e[100001];
int main()
{
	int a,b;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		e[a].pb(b);
		deg[b]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(!deg[i])
		{
			q[++tail]=i;
		}
	}
	int res=0;
	while(head<tail)
	{
		int x=q[++head];
		res=max(res,d[x]);
		for(int i=0;i<e[x].size();i++)
		{
			int y=e[x][i];
			deg[y]--;
			d[y]=max(d[y],d[x]+1);
			if(!deg[y])
			{
				q[++tail]=y;
			}
		}
	}
	cout<<res<<endl;
	return 0;
}

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

int main() {
  int i,j,k,n;
  long long y,total;
  int flg=0;
  
  cin >> n >> y;
  
  for (i=0;i<=n;++i)
  {
    	for (j=0;j<=n-i;++j)
        {
          	k = n - i - j;
          	total = (long long)i * 10000LL + (long long)j * 5000LL + (long long)k *1000L;
          	if ( total == y)
            {
              	++flg;
              	goto OWARI;
            }
        }
  }
OWARI:
  if (flg==0)
    i=j=k=-1;
  
  cout << i << " " << j << " " << k << endl;
}


Measured memory_bytes: 256
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
string s,t;
cin>>s>>t;
int c=0;
for(int i=0;i<3;i++)
{
	if(s[i]==t[i])
		c++;
}	
cout<<c;
}
int main()
{
//code

fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


Measured memory_bytes: 256
X,Y=gets.split.map(&:to_i)
MOD=10**9+7

def pow(a,b,mod)
    res = 1
    while 0 < b
        res = res * a % mod if b & 1 == 1
        a = a * a % mod
        b >>= 1
    end
    res
end

def inv(a,mod)
    pow(a,mod-2,mod)
end

def comb(a,b,mod)
    x = (a-b+1..a).inject(1) {|n,x| n*x%mod }
    y = (1..b).inject(1) {|n,x| n*x%mod }
    x * inv(y,mod) % mod
end

if (X+Y)%3 != 0 || X*2 < Y || X > Y*2
    puts 0
    exit
end

y = (X*2 - Y) / 3
x = X - y
# xCy

# p [x,y]
p comb(x,y,MOD)

Measured memory_bytes: 1788
#include <stdio.h>
#include <ctype.h>

int main() {
	int i, c, cnt[26] = {0};
	while((c = getchar()) != EOF) {
		c = tolower(c) - 'a';
		cnt[c]++;
	}
	for(i = 0; i < 26; i++) printf("%c : %d\n", 'a' + i, cnt[i]);
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  string S;
  cin >> S;
  ll mod = 1e9+7;
  int const r = 13;
  ll dp[100005][r];
  // dp[i][r]: 下i桁の数字であまりがrになる場合の数

  ll len = S.size();
  for(int i=0; i<=len; i++) for(int j=0; j<r; j++) dp[i][j] = 0;
//  for(int i=0; i<r; i++) dp[0][i] = 1;
  dp[0][0] = 1;
  
  // 各位にかける単位。まずは1
  ll unit = 1;

  // 下1桁目から見ていく
  for(int i=len-1; i>=0; i--){
    char dig = S[i];
    // ? だった場合
    if(dig == '?'){
      for(int j=0; j<10; j++){
        int inum = j*unit;
//        if(i == len-2) cout << inum << endl;
        for(int ii = 0; ii < r; ii++){
//          cout << ii << ", " << (inum +ii)%r << endl;
          dp[len - i][(inum +ii)%r] += dp[len -i -1][ii];
          dp[len - i][(inum +ii)%r] %= mod;
        }
      }      
    }else{
      ll inum = (ll)(dig - '0');
      inum *= unit;
//      cout << inum << endl;
      for(int ii = 0; ii < r; ii++){
//        if(ii == 0) cout << dp[len-i-1][ii] << endl;
        dp[len - i][(inum +ii)%r] += dp[len -i -1][ii];
        dp[len - i][(inum +ii)%r] %= mod;
//        if(ii == 0) cout << dp[len-i-1][(inum +ii)%mod] << endl;
      }
    }  
    unit *= 10;
    unit %= r;
  }
/*
  for(int i=0; i<10; i++){
    cout << i << ": ";
    for(int j=0; j<r; j++){
      cout << dp[i][j] << ", ";    
    }
    cout << endl;
  }
*/
  cout << dp[len][5] << endl;
  

  return 0;
}


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

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    int p[A], q[B], r[C];
    rep(i, A) cin >> p[i];
    rep(i, B) cin >> q[i];
    rep(i, C) cin >> r[i];
    sort(p, p + A, greater<int>());
    sort(q, q + B, greater<int>());
    sort(r, r + C, greater<int>());

    int xi = X - 1, yi = Y - 1;
    for (int i = 0; i < C; i++) {
        int xnum = xi >= 0 ? p[xi] : 1e9;
        int ynum = yi >= 0 ? q[yi] : 1e9;
        if (xnum < ynum) {
            if (p[xi] > r[i]) break;
            p[xi] = r[i];
            xi--;
        } else {
            if (q[yi] > r[i]) break;
            q[yi] = r[i];
            yi--;
        }
    }
    int64_t ans = 0;
    rep(i, X) ans += p[i];
    rep(i, Y) ans += q[i];
    cout << ans << endl;
}

Measured memory_bytes: 1408