akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	int n; scanf("%d", &n);

	auto g = make_v<int>(n, n);
	auto solve = [&g](auto&& solve, int l, int r, int level) {
		if(r - l <= 1) return 0;
		
		int mid = (l + r) >> 1;
		for(int i = l; i < mid; i++)
			for(int j = mid; j < r; j++) g[i][j] = level;
		
		solve(solve, l, mid, level + 1);
		solve(solve, mid, r, level + 1);
	};
	solve(solve, 0, n, 1);
	
	for(int i = 0; i < n - 1; i++, printf("\n")) for(int j = i + 1; j < n; j++) printf("%d ", g[i][j]);
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#include <map>


#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

double x1,y1,x2,y2,x3,y3,x4,y4;
	while(!cin.eof()){
		cin >> x1 >> y1 >> x2 >> y2;
		cin >> x3 >> y3 >> x4 >> y4;
		if( cin.eof()  ) break;
		
		double tc=(x2-x1)*(x4-x3)+(y2-y1)*(y4-y3);
		
		cout << (tc== 0.0 ? "YES": "NO") << endl;
//		printf("%f\n",tc);
	}
	return 0;
	
	
}

Measured memory_bytes: 1216
N,X = map(int,input().split())
a,p = [1],[1]
for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
    if n==0:
        return 0 if x<=0 else 1
    elif x<=1+a[n-1]:
        return f(n-1,x-1)
    else:
        return p[n-1]+1+f(n-1,x-2-a[n-1])
print(f(N,X))

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type node struct {
	weight int
	adj    []int
	parent int
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, q := nextInt(), nextInt()

	tree := make([]node, n+1)
	for i := 0; i < n-1; i++ {
		a, b := nextInt(), nextInt()
		tree[a].adj = append(tree[a].adj, b)
		tree[b].adj = append(tree[b].adj, a)
	}

	for j := 0; j < q; j++ {
		p, x := nextInt(), nextInt()
		tree[p].weight += x
	}

	ans := make([]int, n+1)
	queue := make([]int, 0)
	queue = append(queue, 1)
	for len(queue) > 0 {
		u := queue[0]
		queue = queue[1:]
		ans[u] = ans[tree[u].parent] + tree[u].weight
		for _, v := range tree[u].adj {
			if v == tree[u].parent {
				continue
			}
			tree[v].parent = u
			queue = append(queue, v)
		}
	}

	for i := 1; i < n; i++ {
		fmt.Print(ans[i])
		fmt.Print(" ")
	}
	fmt.Println(ans[n])
}


Measured memory_bytes: 30976
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n,m;
	cin>>n>>m;
	vector<pii> v;
	FOR(i,0,n){
		int a,b;
		cin>>a>>b;
		if(a<=m){
			v.PB(MP(a,b));
		}
	}
	v.PB(MP(mod,mod));
	sort(v.begin(),v.end());
	priority_queue<int> pq;
	int idx=0;
	LL ans=0;
	FOR(i,1,m+1){
		while(v[idx].ST==i){
			pq.push(v[idx].ND);
			idx++;
		}
		while(pq.size()){
			int t=pq.top();
			pq.pop();
			ans+=t;
			break;
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 1908
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

const int MAX_PRIME = 1000000;
bool isPrime[MAX_PRIME+1];
// sieve of Erastosthenes
inline void prime_list(){
  const int sz = MAX_PRIME;
  fill(isPrime, isPrime+sz+1, true);
  isPrime[0]=isPrime[1]=false;
  for(int i=4;i<=sz;i+=2) isPrime[i]=false;
  for(int i=3; i*i<=sz; i+=2){
    if(isPrime[i]){
      for(long j=(long)i*i; j<=sz; j+=i) isPrime[j]=false;
    }
  }
}

int main(){
  prime_list();
  int n,x;
  while(cin>>n>>x, n|x){
    vector<int> dish(n);
    rep(i,n) scanf("%d", &dish[i]);
    vector<bool> dp(x+1, false);
    dp[0]=true;
    rep(i,n){
      rep(j,x) if(dp[j]){
        if(j+dish[i]<=x) dp[j+dish[i]]=true;
      }
    }
    int res = -1;
    repl(i,2,x+1) if(isPrime[i] && dp[i]) res = i;
    if(res == -1 ) cout<<"NA" << endl;
    else cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 4224
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
int get() { int r; cin >> r; return r; }
string s; int k, ans;
signed main() {
	cin >> s >> k;
	if (k == 1) {
		cout << s[0] - '0' + (s.size() - 1) * 9 << endl;
		return 0;
	}
	else if (k == 2) {
		string s1;
		int ans = 0;
		for1(i, s.size())s1 += '0';
		for0(i, s.size()) {
			for (int j = i + 1; j < s.size(); j++) {
				for (char c1 = '1'; c1 <= '9'; c1++)for (char c2 = '1'; c2 <= '9'; c2++) {
					s1[i] = c1; s1[j] = c2;
					if (s >= s1)ans++;
					s1[i] = '0'; s1[j] = '0';
				}
			}
		}
		cout << ans << endl;
		return 0;
	}
	else {
		int ans = (s.size() - 1)*(s.size() - 2)*(s.size() - 3) / 6 * 9 * 9 * 9;
		ans += (s[0] - '1')*(s.size() - 1)*(s.size() - 2) / 2 * 9 * 9;
		string s1; s1 += s[0];
		for1(i, s.size() - 1)s1 += '0';
		for1(i, s.size() - 1) {
			for (int j = i + 1; j < s.size(); j++) {
				for (char c1 = '1'; c1 <= '9'; c1++)for (char c2 = '1'; c2 <= '9'; c2++) {
					s1[i] = c1; s1[j] = c2;
					if (s >= s1)ans++;
					s1[i] = '0'; s1[j] = '0';
				}
			}
		}
		cout << ans << endl;
	}
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// テーブルを作る前処理
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        ll num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int d[90005];
int X[90005];
int Y[90005];

int main() {
    int H,W,D;
    cin >> H >> W >> D;

    REP(i,H) REP(j,W) {
        int a;
        cin >> a;
        X[a] = i;
        Y[a] = j;
    }

    int Q;
    cin >> Q;

    vector<int> L(Q);
    vector<int> R(Q);
    REP(i,Q) cin >> L[i] >> R[i];

    for(int i=D+1;i<=H*W;i++)
        d[i] = d[i-D] + abs(X[i] - X[i-D]) + abs(Y[i] - Y[i-D]);

    REP(i,Q) pl(d[R[i]]-d[L[i]])

    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 1;
    repl(i, 1, s.size() / 2 + 1) {
        if (i * 2 < s.size()) {
            string tmp = s.substr(0, i);
            if (s.substr(0, i * 2) == (tmp + tmp)) ans = i * 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using llong = long long;

const int INF = 100100100;
const int MOD = 1e9 + 7;

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

    string str;
    cin >> str;

    vector<int> ans(str.length(), 0);
    REP(i, str.length() - 1) {
        if(str[i] == 'R' && str[i + 1] == 'L') {
            int right = 1;
            int tmp = i - 1;
            while(tmp >= 0) {
                if(str[tmp] == 'R') {
                    right++;
                } else {
                    break;
                }
                tmp--;
            }
            int left = 1;

            tmp = i + 2;
            while(tmp < str.length()) {
                if(str[tmp] == 'L') {
                    left++;
                } else {
                    break;
                }
                tmp++;
            }
            ans[i] = (right + 1) / 2 + (left / 2);
            ans[i + 1] = right / 2 + (left + 1) / 2;
        }
    }

    REP(i, str.length()) { cout << ans[i] << ' '; }
    return 0;
}


Measured memory_bytes: 1104
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

const int H = 19;
const int W = 15;
char board[H+2][W+2];

int solve(int x, int y) {
    if(x == H - 1 and 0 <= y and y < W) return 0;
    if(x > H - 1) return 0;
    if(y < 0 or y >= W or x < 0) return INF;
    assert(board[x][y] == '.');
    
    int ans = INF;
    for(int k=0; k<8; k++) {
        int nx = x + dx[k], ny = y + dy[k];
        if(nx < 0 or nx >= H or ny < 0 or ny >= W) continue;
        if(board[nx][ny] != 'X') continue;
        
        vector< pair<int, int> > black_pos;
        while(nx >= 0 and nx < H and ny >= 0 and ny < W and board[nx][ny] == 'X') {
            black_pos.emplace_back(nx, ny);
            board[nx][ny] = '.';
            nx += dx[k];
            ny += dy[k];
        }

        int nxt_val = solve(nx, ny);
        for(auto b : black_pos) {
            int bx, by; tie(bx, by) = b;
            board[bx][by] = 'X';
        }
        
        if(nxt_val == INF) continue;
        ans = min(ans, nxt_val + 1);
    }
    return ans;
}

signed main() {
    int x = -1, y = -1;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            cin >> board[i][j];
            if(board[i][j] == 'O') {
                x = i, y = j;
                board[i][j] = '.';
            }
        }
    }

    int ans = solve(x, y);
    if(ans >= INF) ans = -1;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3108
#include <stdio.h>
int main(){
    while (1) {
        int n;
        long m,i;
        char c[128];
        scanf("%d",&n);
        if(n==0) return 0;
        for (i=0; i<128; i++) {
            c[i]=i;
        }
        for (i=0; i<n; i++) {
            char s;
            scanf(" %c",&s);
            scanf(" %c",&c[s]);
        }
        scanf("%ld",&m);
        for (i=0; i<m; i++) {
            char C;
            scanf(" %c",&C);
            printf("%c",c[C]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define int long long 
typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int N,A[MAXN],Q;
int freq[MAXN];

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	int ans = 0;
	FOR(i,1,N){
		cin>>A[i];
		freq[A[i]]++;
		ans += A[i];
	}
	cin>>Q;
	FOR(i,1,Q){
		int b, c; cin>>b>>c;
		ans += (c-b)*freq[b];
		freq[c] += freq[b];
		freq[b] = 0;
		cout<<ans<<"\n";
	}
}


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

int main() {
  int N;
  cin >> N;
  multiset<long> A;
  long temp;
  for (int i = 0; i < N; i++) {
    cin >> temp;
    A.insert(temp);
  }
  int count;
  long j;
  for (j = *(++A.begin()); j > 0; j--) {
    count = 0;
    for (auto a : A) {
      if (a % j != 0) count++;
      if (count > 1) break;
    }
    if (count < 2) break;
  }
  cout << j;
  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int main(){
	DRI(n);
	int ans=0;
	REP(i,n){
		DRI(x);
		ans+=x%2;
	}
	if(ans%2==0)printf("YES");
	else printf("NO");
}


Measured memory_bytes: 764
inputs = input().split(' ')
town_cnt = int(inputs[0])
trans_cnt = int(inputs[1])

towns = input().split(' ')
towns = [int(x) - 1 for x in towns]

king = 0
loop_dic = {}
loop_diff = 0
loop_cyc = 0
is_loop = False
for i in range(trans_cnt):
    if loop_dic.get(king) is None:
        loop_dic[king] = i
        king = towns[king]
    else:
        loop_diff = loop_dic.get(king)
        loop_cyc = i - loop_dic.get(king)
        is_loop = True
        break

if is_loop:
    trans_cnt = ((trans_cnt - loop_diff) % loop_cyc) + loop_diff
    king = 0
    for i in range(trans_cnt):
        king = towns[king]

print(king + 1)

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,ans=0,ab=0,a=0,b=0;
	string s;
	cin >> n;
	rep(i,n){
		cin >> s;
		ll m=(int)s.size();
		rep(j,m-1){
			if(s[j]=='A' && s[j+1]=='B') ans++;
		}
		if(s[0]=='B' && s[m-1]=='A') ab++;
		else if(s[0]=='B') b++;
		else if(s[m-1]=='A') a++;
	}
	if(ab==0) ans+=min(a,b);
	else{
		if(a==0 && b==0) ans+=ab-1;
		else ans+=ab+min(a,b);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  int yon = (r*100) + (g*10) + b;
  if (yon % 4 == 0) {
      cout << "YES" << endl;
  }
  else {
      cout << "NO" << endl;
  }
}

Measured memory_bytes: 2988
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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(){ 
  string s; cin >> s;
  int cnt = 0, res = 0;
  set<char> st{'A','T','C','G'};
  for(char c:s){
    if(st.find(c)==st.end()){
      cnt=0;
    }else cnt++;
    chmax(res, cnt);
  }
  cout << res << ln;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N;
	scanf("%d",&N);

	vector<int> V;
	int tmp;

	for(int loop = 0; loop < N; loop++){
		scanf("%d",&tmp);
		V.push_back(tmp);
	}

	int num_query;
	scanf("%d",&num_query);

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&tmp);

		printf("%lld\n",lower_bound(V.begin(),V.end(),tmp)-V.begin());
	}

	return 0;
}




Measured memory_bytes: 3508
from typing import Callable, Sequence, Union, List


class SegmentTree:
    __slots__ = ["default_value", "seg_func", "size", "tree"]

    def __init__(
        self,
        initial_values: Sequence,
        default_value: Union[int, str],
        seg_func: Callable,
    ) -> None:
        self.default_value = default_value
        self.seg_func = seg_func
        self.size = 1 << (len(initial_values) - 1).bit_length()
        self.tree = self._build(initial_values)

    def _build(self, initial_values) -> List:
        tree = [self.default_value] * (2 * self.size)

        for idx, val in enumerate(initial_values):  # set
            # modify val if needed (e.g. str -> ord())
            tree[idx + self.size - 1] = val

        for idx in range(self.size - 2, -1, -1):  # build
            tree[idx] = self.seg_func(tree[2 * idx + 1], tree[2 * idx + 2])
        return tree

    def update(self, idx: int, val: int) -> None:
        idx += self.size - 1
        # modify val if needed as same as in _build()
        self.tree[idx] = val
        while idx:
            idx = (idx - 1) // 2
            x, y = 2 * idx + 1, 2 * idx + 2
            self.tree[idx] = self.seg_func(self.tree[x], self.tree[y])

    def query(self, left: int, right: int) -> Union[int, str]:
        if left > right:  # corner case
            return self.default_value

        left += self.size
        right += self.size
        result = self.default_value
        while left < right:
            if left & 1:
                result = self.seg_func(result, self.tree[left - 1])
                left += 1
            if right & 1:
                right -= 1
                result = self.seg_func(result, self.tree[right - 1])
            left >>= 1
            right >>= 1
        return result


def main():
    N, Q = map(int, input().split())
    tree = SegmentTree([2 ** 31 - 1] * N, 2 ** 31 - 1, min)
    ans = []
    for _ in range(Q):
        com, x, y = map(int, input().split())
        if com:
            ans.append(tree.query(x, y + 1))
        else:
            tree.update(x, y)
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()



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

int main()
{
    int n;
    cin>>n;
    int arr[n+5];
    map<int,int>mp;
    for(int i=0;i<n-1;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    for(int i=1;i<=n;i++)cout<<mp[i]<<endl;

}


Measured memory_bytes: 13756
def check(a):
    a = sorted(a)
    d = {}
    for x in a:
        if x not in d.keys():
            d[x] = 1
        else:
            d[x] += 1
    if (a[-1]+1)>>1 != a[0]:
        return False
    if (a[-1]&1) != 1 and d[a[0]]!=1:
        return False
    if (a[-1]&1) == 1 and d[a[0]]!=2:
        return False
    for i in xrange(a[-1], a[0], -1):
        if i not in d.keys() or d[i]<2:
            return False
    return True

def main():
    n = int(raw_input().strip())
    a = [int(x) for x in raw_input().strip().split()]
    if check(a):
        print 'Possible'
    else:
        print 'Impossible'

if __name__ == '__main__':
    main()

Measured memory_bytes: 2696
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		
		H -= sc.nextInt();
		W -= sc.nextInt();
		
		System.out.println(H * W);
		sc.close();
	}

}


Measured memory_bytes: 21716
#include <cstdio>
using namespace std;
int main(){
	int m1,d1,m2,d2;
	scanf("%d %d %d %d",&m1,&d1,&m2,&d2);
	if(m1 != m2) printf("1\n");
	else printf("0\n");
	return 0;
}

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

int main()
{
  ll n;
  cin>>n;
  double d;
  cin>>d;
  ll c=0;
  for(ll i=0;i<n;i++)
  {
     double a,b;
     cin>>a>>b;
     a=sqrt((a*a)+(b*b));
     if(a<=d)
        c++;
  }
  cout<<c;
}


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



int abs(int n){
	if(n > 0){
		return n;
	}else{
		return -n;
	}
}

int min(int ary[],int n){
	int min = abs(ary[0]);
	int i;
	
	for(i = 0 ; i < n; i++){
		ary[i] = abs(ary[i]);
		if(min > ary[i]){
			min = ary[i];
		}
	}
	
	return min;
}

int sum(int ary[],int n){
	int sum = 0;
	
	for(int i = 0; i < n; i++){
		sum += ary[i];
	}
	
	return sum;
}

int main(void)
{
	int n,l;
	
	scanf("%d%d",&n,&l);
	
	int taste[n],i,flag = 0;
	
	for(i = 0; i < n; i++){
		taste[i] = l + i;
	}
	
	int total = sum(taste,n);
	
	if(total < 0){
		flag = 1;
	}
	
	int a = min(taste,n);
	
	if(flag){
		printf("%d\n",total + a);
	}else{
		printf("%d\n",total - a);
	}
	
	
	return 0;
}
	
	
	
	
	
	
	
	
	
	

Measured memory_bytes: 128
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line,   int.Parse);
        var b = Array.ConvertAll(line, int.Parse);
        Array.Sort(a);
        var s = a[n / 2 - 1];
        var L = a[n / 2];
        for (int i = 0; i < n; i++)
        {
            if (b[i] <= s) Console.WriteLine(L);
            else Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 34012
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  cin >> a >> b >> c;
  if(a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int factorial_2(int i){
  if(i==0) return 1;
  return factorial_2(i-1)*2;
}

int main(void){
  int n,i;
  while((scanf("%d",&n))!=EOF){
    i=0;
    while(n>0){
      if((n%2)==1){
        printf("%d",factorial_2(i));
        if(n/2>0) printf(" ");
      }
      n/=2;
      i++;
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 1924
#include <iostream>
using namespace std;
int main(){
        int a,b,c,x,sum;
        int ans=0;
        cin >> a >> b >>c >>x;
        for(int i=0; i<=a; i++) {
                for(int j=0; j<=b; j++) {
                        for(int k=0; k<=c; k++) {
                                sum=(i*500)+(j*100)+(k*50);
                                if(sum==x) ans++;
                        }
                }
        }
        cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
 
public class Main {
	
	private class Map {
		int H, W;
		String[] lines = null;
		
		public Map(int H, int W, String[] lines) {
			this.H = H;
			this.W = W;
			this.lines = lines;
		}
		
		public boolean isFloor(int x, int y) {
			if (x < 0 || x >= W || y < 0 || y >= H) {
				return false;
			} else if (lines[y].charAt(x) == '#') {
				return false;
			}
			return true;
		}
		
	}
	
	public int get(int[][] map, int x, int y) {
		if (y < 0 || y >= map.length || x < 0 || x >= map[0].length) {
			return -1;
		} else {
			return map[y][x];
		}
	}
	
	private void debugPrint(int[][] map) {
		System.err.println("-------------------");
		for (int y=0; y<map.length; y++) {
			for (int x=0; x<map[y].length; x++) {
				System.err.print(String.format("%3d ", map[y][x]));
			}
			System.err.println();
		}
	}
	
	public void solve() {
		Scanner in = new Scanner(System.in);
		int H = in.nextInt();
		int W = in.nextInt();
		String[] lines = new String[H];
		for (int i=0; i<H; i++) {
			lines[i] = in.next();
		}
		in.close();
		
		Map map = new Map(H, W, lines);
		
		int[][] top = new int[H][W];
		for (int x=0; x<W; x++) {
			for (int y=0; y<H; y++) {
				if (map.isFloor(x, y)) {
					top[y][x] = get(top, x, y-1) + 1;
				} else {
					top[y][x] = -1;
				}
			}
		}
		int[][] bottom = new int[H][W];
		for (int x=0; x<W; x++) {
			for (int y=H-1; y>=0; y--) {
				if (map.isFloor(x, y)) {
					bottom[y][x] = get(bottom, x, y+1) + 1;
				} else {
					bottom[y][x] = -1;
				}
			}
		}
		
		int[][] right = new int[H][W];
		for (int y=0; y<H; y++) {
			for (int x=W-1; x>=0; x--) {
				if (map.isFloor(x, y)) {
					right[y][x] = get(right, x+1, y) + 1;
				} else {
					right[y][x] = -1;
				}
			}
		}
		
		int[][] left = new int[H][W];
		for (int y=0; y<H; y++) {
			for (int x=0; x<W; x++) {
				if (map.isFloor(x, y)) {
					left[y][x] = get(left, x-1, y) + 1;
				} else {
					left[y][x] = -1;
				}
			}
		}

		int max = 0;

		//debugPrint(top);
		//debugPrint(bottom);
		
		for (int y=0; y<H; y++) {
			for (int x=0; x<W; x++) {
				if (map.isFloor(x, y)) {
					int count = top[y][x] + bottom[y][x] + left[y][x] + right[y][x] + 1;
					if (max < count) {
						max = count;
						//System.err.println(x + "," + y + ":" + count + "(" + top[y][x] + "," + bottom[y][x] + "," + left[y][x] + "," + right[y][x]);
					}
					
				}
			}
		}

		System.out.println(max);
		
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}
 
}


Measured memory_bytes: 122400
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long[] b = new long[n];
		b[0] = a[0];
		for (int i = 1; i < n; i++) {
			b[i] = b[i - 1] + a[i];
		}

		long[] p = new long[4];
		long ans = Long.MAX_VALUE;
		for (int i = 1; i < n - 2; i++) {
			int start = 0;
			int end = i;
			while (Math.abs(end - start) > 1) {
				int mid = (end + start) / 2;
				long c = b[i] - b[mid] * 2;
				if (c < 0) {
					end = mid;
				} else {
					start = mid;
				}
			}
			long val1 = Long.MAX_VALUE;
			p[0] = b[start];
			p[1] = b[i] - b[start];
			if (p[0] > 0 && p[1] > 0) {
				val1 = Math.abs(p[0] - p[1]);
			}
			p[0] = b[end];
			p[1] = b[i] - b[end];
			long val2 = Math.abs(p[0] - p[1]);
			if (p[0] > 0 && p[1] > 0 && val1 > val2) {
			} else {
				p[0] = b[start];
				p[1] = b[i] - b[start];
				if (val1 == Long.MAX_VALUE) {
					throw new RuntimeException();
				}
			}

			start = i;
			end = n - 1;
			while (Math.abs(end - start) > 1) {
				int mid = (end + start) / 2;
				long c = b[n - 1] - b[mid] * 2 + b[i];
				if (c < 0) {
					end = mid;
				} else {
					start = mid;
				}
			}
			val1 = Long.MAX_VALUE;
			p[2] = b[start] - b[i];
			p[3] = b[n - 1] - b[start];
			if (p[2] > 0 && p[3] > 0) {
				val1 = Math.abs(p[2] - p[3]);
			}
			p[2] = b[end] - b[i];
			p[3] = b[n - 1] - b[end];
			val2 = Math.abs(p[2] - p[3]);
			if (p[2] > 0 && p[3] > 0 && val1 > val2) {
			} else {
				p[2] = b[start] - b[i];
				p[3] = b[n - 1] - b[start];
				if (val1 == Long.MAX_VALUE) {
					throw new RuntimeException();
				}
			}

			long val = max(p) - min(p);
			ans = Math.min(ans, val);
		}
		System.out.println(ans);
	}

	static long max(long[] p) {
		long ret = p[0];
		for (int i = 1; i < p.length; i++) {
			ret = Math.max(ret, p[i]);
		}
		return ret;
	}

	static long min(long[] p) {
		long ret = p[0];
		for (int i = 1; i < p.length; i++) {
			ret = Math.min(ret, p[i]);
		}
		return ret;
	}
}


Measured memory_bytes: 51668
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>

#ifdef _MSC_VER
#pragma warning(disable:4996)
#endif

using namespace std;


int main() {

	int n, m, tmp;

	cin >> n >> m;


	for (int i = 0; i < m; i++) {
		cin >> tmp;
		n -= tmp;
	}

	if (n < 0)	n = -1;
	cout << n;


	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s,t;
    vector<string> ans;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    if(m>n){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        if(s[i]=='?'||s[i]==t[0]){
            //ここで条件に一致するかどうかを調べる
            bool ok = 1;
            for(int j=0;j<m;j++){
                if(i+j>=n){
                    ok = 0;
                    break;
                }
                if(s[i+j]=='?'||s[i+j]==t[j])continue;
                else ok = 0;
            }
            if(ok){
                string tmp = "";
                rep(k,i)tmp.push_back(s[k]=='?'?'a':s[k]);
                tmp = tmp + t;
                for(int k=i+m;k<n;k++)tmp.push_back(s[k]=='?'?'a':s[k]);
                ans.push_back(tmp);
            }
        }
    }
    if(ans.size()==0){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }else{
        sort(ALL(ans));
        cout << ans[0] << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
char c1[3],c2[3];

scanf("%s",c1);

scanf("%s",c2);

if(c1[0]==c2[2] && c1[1]==c2[1] && c1[2]==c2[0]){
    printf("YES");
}
 else
    printf("NO");


}



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;
int main()
{
    string A, B;
    cin >> A;
    cin >> B;
    if(A.size()>B.size()) cout << "GREATER" << endl;
    else if(A.size()<B.size()) cout << "LESS" << endl;
    else {
        if(A > B) cout << "GREATER" << endl;
        else if(A < B) cout << "LESS" << endl;
        else cout << "EQUAL" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeSearch(Node u, int k){
  if(u==NIL || k ==u->key) return u;
  if(k< u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y==NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}
void inorder(Node u){
  if(u !=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");  
    } 
  }
  return 0;
}

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

#include <boost/algorithm/string/classification.hpp>  // is_any_of
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/math/tools/minima.hpp>
#include <boost/multi_array.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

const int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)

namespace adaptor = boost::adaptors;
using namespace std;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::algorithm::split;
using boost::math::tools::brent_find_minima;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;
// TOP
void Main()
{
	int d, w;
	cin >> d >> w;
	vector<string> V(d + 2);
	string e = "......................................................";
	V.at(0) = e;
	V.at(d + 1) = e;
	for (int i = 1; i < d + 1; i++)
	{
		string s;
		cin >> s;

		V.at(i) = "." + s + ".";
	}
	for (int i = 1; i < d + 1; i++)
	{
		for (int j = 1; j < w + 1; j++)
		{
			if (V.at(i).at(j) == '#')
			{
				bool flag;
				flag = false;
				if (V.at(i - 1).at(j) == '#')
					flag = true;
				else if (V.at(i).at(j - 1) == '#')
					flag = true;
				else if (V.at(i).at(j + 1) == '#')
					flag = true;
				else if (V.at(i + 1).at(j) == '#')
					flag = true;
				if (flag == false)
				{
					cout << "No" << endl;
					return;
				}
			}
		}
	}
	cout << "Yes" << endl;
}
// END

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


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

#define ll long long
#define sz(x) (int)x.size();

using namespace std;

const int maxN=2e5+5;
int n,a[maxN];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int cur=1;
	for(int i=0;i<n;i++){
		if(a[i]==cur)cur++;
	}
	cout<<(cur==1?-1:n-cur+1);
	
}

Measured memory_bytes: 4440
a,b=map(int,input().split())

if a>b:
    if a%b==0:
        gcd=b
    else:
        p=a
        q=b
        r=p%q
        while r!=0:
            p=q
            q=r
            r=p%q
            if r==0:
            	gcd=q
            	break
elif a<b:
    if b%a==0:
    	gcd=a
    else:
        p=b
        q=a
        r=p%q
        while r!=0:
            p=q
            q=r
            r=p%q
            if r==0:
            	gcd=q
            	break
A=a//gcd
B=b//gcd
print(A*B*gcd)

Measured memory_bytes: 3064
import heapq as hq
n,m = map(int,input().split())
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append((a,-b))
ab.sort()
ans = 0
idx = 0
q = []
for i in range(1,m+1):
    while idx<n and ab[idx][0] ==i:
        a,mb = ab[idx]
        hq.heappush(q,mb)
        idx+=1
    if q!=[]:
        ans += -1*hq.heappop(q)

print(ans)


Measured memory_bytes: 17660
// https://atcoder.jp/contests/abc124/tasks/abc124_a
#include <bits/stdc++.h>
using namespace std;

int main(void){
  int A, B;
  cin >> A >> B;
  int coins = 0;
  for (int i = 0; i < 2; i++){
    if (A > B){
      coins += A;
      A--;
    }else{
      coins += B;
      B--;
    }
  }
  cout << coins << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    ll a, b;

	cin >> a >> b;

	if ((a * b) % 2 == 0) Out("Even");
	else Out("Odd");
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e3+1;

int vis[maxn][maxn],ans[maxn][maxn];
int res,H,W;
queue<pair<int,int>>q;
char S[maxn];

int main(){
	scanf("%d%d",&H,&W);
	for (int i=1;i<=H;++i){
		scanf("%s",S+1);
		for (int j=1;j<=W;++j)
		if (S[j]=='#') q.push(make_pair(i,j)),vis[i][j]=1;
	}
	while(!q.empty()){
		pair<int,int>u=q.front();
		q.pop();
		int x=u.first,y=u.second;
		res=max(res,ans[x][y]);
		if (x>1) if (!vis[x-1][y])
		vis[x-1][y]=1,q.push(make_pair(x-1,y)),
		ans[x-1][y]=ans[x][y]+1;
		if (y>1) if (!vis[x][y-1])
		vis[x][y-1]=1,q.push(make_pair(x,y-1)),
		ans[x][y-1]=ans[x][y]+1;
		if (x<H) if (!vis[x+1][y])
		vis[x+1][y]=1,q.push(make_pair(x+1,y)),
		ans[x+1][y]=ans[x][y]+1;
		if (y<W) if (!vis[x][y+1])
		vis[x][y+1]=1,q.push(make_pair(x,y+1)),
		ans[x][y+1]=ans[x][y]+1;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h,w; cin >> h >> w;
    string s;
    rep(i,h){
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
}


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

int main(){
  long long K, A, B;
  cin >> K >> A >> B;

  if((B - A <= 2) || (K <= A - 1)){
    cout << K + 1 << endl;
  }else{
    // 1 -> A
    // A -> _1 -> B
    // +1
    int ba_op = K - (A - 1);
    cout << A + (B - A) * (ba_op / 2) + (ba_op % 2) << endl;
  }
}


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

using namespace std;

long long sqrtt(long long ii){
	long long ret=0;
	for(int i=62; i>=0; i--){
		ret=ret+(1<<i);
		if(ret*ret>ii) ret-=(1<<i);
	}
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int q;
	cin >> q;
	while(q--){
		long long a, b, res, f;
		cin >> a >> b;
		f=a*b;
		f--;
		res=sqrtt(f);
		if(res*(res+1)>f) res=res*2-1;
		else res*=2;
		if(a<=sqrtt(f)) res--;
		if(b<=sqrtt(f)) res--;
		if(a>sqrtt(f) && f/a>0 &&(f/a)*(a+1)>f) res--;
		if(b>sqrtt(f) && f/b>0 && (f/b)*(b+1)>f) res--;
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner rv=new Scanner(System.in);
        int n ,m;
        n=rv.nextInt();
        m=rv.nextInt();
        int a[]=new int[m];
        int i;
        long sum=0;
        for(i=0;i<m;i=i+1)
        {
            a[i]=rv.nextInt();
            sum=sum+a[i];
        }
        if(sum<=n)
            System.out.println(n-sum);
        else
            System.out.println("-1");
    }
}


Measured memory_bytes: 46464
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def k_cut(k, nums):
    return nums[k:] + nums[:k]

def riffle_shuffle(n, nums):
    return [nums[i//2 + n*(i%2)] for i in range(2*n)]

n = int(input())
nums = [i + 1 for i in range(2*n)]

m = int(input())
for i in range(m):
    k = int(input())
    if k == 0:
        nums = riffle_shuffle(n, nums)
    else:
        nums = k_cut(k, nums)

print('\n'.join([str(num) for num in nums]))

Measured memory_bytes: 6724
#include<cstdio>
#include<iostream>
#include<set>

#include<cstdlib>
#include<cstring>
#include<utility>
#ifdef XS
	#include<De>
#endif
using namespace std;
#define MS(m) memset(m,0,sizeof(m))

typedef unsigned U;
typedef pair<int,int > P;
typedef long long ll;
void inp();
int main(){
#ifdef XS
	//freopen(".in","r",stdin);
#endif
	try{
		//while(1)
		//int n;scanf("%d",&n);for(int i=1;i<=n;i++)
		inp();
	}
	catch(... ){
#ifdef XS
		printf("%s","exception");
#endif
	}//for compatibility with cygwin c++ runtime
	return 0;
}
void inp(){
	set<int> s1;
	set<int> s2;
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i = 0;i<m;i++){
		int a,b;scanf("%d%d",&a,&b);
		if(a>b)swap(a,b);
		if(a == 1)s1.insert(b);
		if(b == n)s2.insert(a);
	}
	char ans[2][20]={
		"IMPOSSIBLE",
		"POSSIBLE"
	};
	for(auto x:s1){
		if(s2.count(x)){
			cout<<ans[1];
			return; 
		}
	}
	cout<<ans[0];
}
//A.cc by xsthunder at Sat Jul 29 20:02:43 2017


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define RER(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin() v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, x, a[MAX_N];
signed main(){
    cin >> n >> x;
    REP(i, n) cin >> a[i];
    ll ret = 0, pre = 0;
    REP(i, n){
        if(pre + a[i] >= x){
            ret += pre + a[i] - x;
            pre = x - pre;
            // cout << pre << endl;
        }else{
            pre = a[i];
            // cout << pre << endl;

        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1024