akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using  namespace std;
#define ll long long
#define pb push_back
#define sc second
#define fr first
#define mp make_pair
const int N = 3e3 + 10 , Max = 50 + 10;
const int  MOD = 1e9 + 7 ;
double a[N];
double dp[N][N];
int n , m ;
double solve(int i,int s) {
    if(i == n + 1) {
        return s > n/2 ? 1.0 : 0.0;
    }
    double &ret = dp[i][s];
    if(ret == ret)
        return ret;
    double c1 = solve(i + 1,s)*(1.0 - a[i]);
    double c2 = solve(i + 1,s + 1)*a[i];
    return ret = c1 + c2;
}
int main() {
   cin >> n ;
   for(int i = 1;i<=n;++i)
    cin >> a[i];
    memset(dp,-1,sizeof(dp));
    cout << fixed << setprecision(10) << solve(1,0) << endl;
}


Measured memory_bytes: 71296
#include<bits/stdc++.h>
using namespace std;
int n,a,l;
long long ans;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
	n=read(),a=read();
	if(a>0){
		puts("-1");
		return 0;
	}
	l=a;
	for(int i=2;i<=n;++i){
		a=read();
		if(a==l+1) ans++;
		else if(a<l+1) ans+=a;
		else{
			puts("-1");
			return 0;
		}
		l=a;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){ 
  string A,B; cin >> A >> B;
  if( A.size() != B.size()){
    if(A.size() > B.size()){cout << "GREATER"<< endl;}
    else{cout << "LESS" << endl;}}
  else{
    for(int i = 0; i < A.size(); i++){
      if(A[i] == B[i]){continue;}
      else if(A[i] > B[i]){cout << "GREATER" << endl; return 0;}
      else{ cout << "LESS" << endl; return 0;}}
    
    cout << "EQUAL" << endl;
    return 0;} }

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

h = [0] * N 
ans = 0
for i in range(M):
    A,B = list(map(int,input().split()))
    h[A-1] = max(H[B-1],h[A-1])
    h[B-1] = max(H[A-1],h[B-1])

for i in range(N):
    if H[i] >h[i] or h[i] == 0:
        ans += 1
print(ans)

Measured memory_bytes: 20156
#include<bits/stdc++.h>
#pragma GCC optimize(3)
namespace ZDY{
	#define res register
	#define ri res int
	#define ll long long
	#define db double
	#define sht short
	#define il inline
	#define MB template <class T> il T
	#define Fur(i,x,y) for(ri i=x;i<=y;i++)
	#define fur(i,x,y) for(i=x;i<=y;i++)
	#define Fdr(i,x,y) for(ri i=x;i>=y;i--)
	#define clr(x,y) memset(x,y,sizeof(x))
	#define cpy(x,y) memcpy(x,y,sizeof(x))
	#define fl(i,x) for(ri i=head[x],to;to=e[i].to,i;i=e[i].nxt)
	#define inf 21474836470
	#define fin(s) freopen(s".in","r",stdin)
	#define fout(s) freopen(s".out","w",stdin)
	#define l2(n) (ceil(log2(n)))
	il char gc(){static char buf[1000000],*s,*t;return s==t?(((t=(s=buf)+fread(buf,1,1000000,stdin))==s)?-1:*s++) : *s++;}
	il int gi(){int x=0;bool f=0;char c=gc();while(c<'0'||'9'<c){if(c=='-')f=!f;c=gc();}while('0'<=c&&c<='9'){x=x*10+c-48;c=gc();}return f?(-x):x;}
	MB ABS(T x){return x>0?x:-x;}
	MB MAX(T x,T y){return x>y?x:y;}
	MB MIN(T x,T y){return x<y?x:y;}
	MB GCD(T x,T y){return y?GCD(y,x%y):x;}
}using namespace ZDY;using namespace std;
#define N 300010
int a[N],n,p;
db s=0,ans=233333,t=0;
int main(){
	n=gi();
	Fur(i,1,n)a[i]=gi(),s+=a[i];
	s/=n;
	Fur(i,1,n){
		t=abs(s-a[i]);
		if(t<ans)ans=t,p=i;
	}
	printf("%d\n", p-1);
}

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

int N, M, Q;
struct Query {
    int v, d, c;
};
vector<vector<int> > adj, vis;
vector<Query> quer;
vector<int> C;

void dfs(int u, int d, int c) {
    vis[u][d] = 1;
    if(!d) {
        C[u] = c;
        return;
    }
    if(!vis[u][d - 1]) dfs(u, d - 1, c);
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(!vis[v][d - 1]) dfs(v, d - 1, c);
    }
}

int main() {
    scanf("%d %d", &N, &M);
    adj.resize(N);
    for(int i = 0; i < M; i++) {
        int u, v; scanf("%d %d", &u, &v);
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    C = vector<int>(N, 0);
    vis = vector<vector<int> >(N, vector<int>(11, 0));

    scanf("%d", &Q);
    for(int i = 0; i < Q; i++) {
        int v, d, c; scanf("%d %d %d", &v, &d, &c);
        v--;
        quer.push_back({v, d, c});
    }
    for(int i = Q - 1; i >= 0; i--) {
        int v = quer[i].v;
        int d = quer[i].d;
        int c = quer[i].c;
        if(!vis[v][d]) dfs(v, d, c);
    }
    for(int i = 0; i < N; i++) {
        printf("%d\n", C[i]);
    }
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)

int N;
int A[200200];
int axor[200200];
int asum[200200];

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> A[i];
        axor[i] = (i ? axor[i - 1] : 0) ^ A[i];
        asum[i] = (i ? asum[i - 1] : 0) + A[i];
    }
    int ans = 0;
    rep(l, N) {
        int rmax = l;
        int cant = N;
        rep(i, 100) {
            int m = (rmax + cant) / 2;
            int x = axor[m] ^(l ? axor[l - 1] : 0);
            int s = asum[m] - (l ? asum[l - 1] : 0);
            if (x == s)rmax = m;
            else cant = m;
        }
        int k = rmax - l + 1;
        ans += k;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
int main(){
	string s; cin>>s;
  int X,Y; cin>>X>>Y;
  vector<int> x(4001,0);
  vector<int> y(4001,0);
  int turn=0,cntx=0,cnty=0;
  for(int i=0;i<s.size();i++){
  	if(turn%2==0){//
    	if(s[i]=='F') x[cntx]++;
        else{
          turn++;
          cntx++;
        }
    }else{//
    	if(s[i]=='F') y[cnty]++;
        else{
          turn++;
          cnty++;
        }
  	}
  }
  
  vector<vector<bool>> dpx(cntx+1,vector<bool>(16001,false));
  vector<vector<bool>> dpy(cnty+1,vector<bool>(16001,false));
  if(s[0]=='F'){
    int tmp=x[0];
    dpx[0][8000+tmp]=true;
    for(int i=1;i<=cntx;i++){
      for(int j=0;j<=16000;j++){
        tmp=x[i];
        if((j-tmp>=0 && dpx[i-1][j-tmp]==true) || (j+tmp<=16000 && dpx[i-1][j+tmp]==true)){
          dpx[i][j]=true;
        }
      }
    }
    tmp=y[0];
    dpy[0][8000+tmp]=true;
    dpy[0][8000-tmp]=true;
    for(int i=1;i<=cnty;i++){
      for(int j=0;j<=16000;j++){
        tmp=y[i];
        if((j-tmp>=0 && dpy[i-1][j-tmp]==true) || (j+tmp<=16000 && dpy[i-1][j+tmp]==true)){
          dpy[i][j]=true;
        }
      }
    }
    if(dpx[cntx][8000+X] && dpy[cnty][8000+Y]) printf("Yes");
    else printf("No");
  }
  else{//最初ターン
  	int tmp=x[0];
    dpx[0][8000+tmp]=true;
    dpx[0][8000-tmp]=true;
    for(int i=1;i<=cntx;i++){
      for(int j=0;j<=16000;j++){
        tmp=x[i];
        if((j-tmp>=0 && dpx[i-1][j-tmp]==true) || (j+tmp<=16000 && dpx[i-1][j+tmp]==true)){
          dpx[i][j]=true;
        }
      }
    }
    tmp=y[0];
    dpy[0][8000+tmp]=true;
    dpy[0][8000-tmp]=true;
    for(int i=1;i<=cnty;i++){
      for(int j=0;j<=16000;j++){
        tmp=y[i];
        if((j-tmp>=0 && dpy[i-1][j-tmp]==true) || (j+tmp<=16000 && dpy[i-1][j+tmp]==true)){
          dpy[i][j]=true;
        }
      }
    }
    if(dpx[cntx][8000+X] && dpy[cnty][8000+Y]) printf("Yes");
    else printf("No");
  }
}


Measured memory_bytes: 16256
#include<cstdio>

#define MOD 1000000007

using ll=long long;


int main(void)
{
	int n;
	char s[2][60];

	while(scanf("%d%s%s", &n, s[0], s[1])==3)
	{
		ll ans=1;
		int x=0;
		int is_vertical=-1;

		for(;;)
		{
			if(s[0][x]==s[1][x])
			{
				switch(is_vertical)
				{
					case  1: ans=(ans*2)%MOD; break;
					case  0: break;
					case -1: ans=3; break;
				}
				x++;
				is_vertical=1;
			}
			else
			{
				switch(is_vertical)
				{
					case  1: ans=(ans*2)%MOD; break;
					case  0: ans=(ans*3)%MOD; break;
					case -1: ans=6; break;
				}
				x+=2;
				is_vertical=0;
			}

			if(x>=n) break;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 128
class UnionFindTree:
    """Disjoint-Set Data Structure
       Union-Find Tree
       complexity: 
          init: O(n)
          find, unite, same: O(alpha(n))
       used in SRM505 div.2 900, 
    """
    def __init__(self, n):
        self.par = list(range(n)) # parent
        self.rank = [0] * n # depth of tree

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)
    
N, Q = map(int, input().split())
DisjointSet = UnionFindTree(N)
for _ in range(Q):
    com, x, y = map(int, input().split())
    if com == 0:
        DisjointSet.unite(x, y)
    elif com == 1:
        print(int(DisjointSet.same(x, y)))

Measured memory_bytes: 7108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    vector<int> A(3);
    REP(i,3)cin >> A[i];
    sort(ALL(A));
    UNIQUE(A);
    cout << A.size() << "\n";
}

Measured memory_bytes: 3620
import java.io.*;
import java.util.*;
public class Main {
  public static void main(String[] args) throws Exception {
    String line = null;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    line = br.readLine();
    char[] charArray = line.toCharArray();
    int firstA = 0;
    int lastZ = 0;
    for (int i = 0; i < charArray.length; i++) {
      //System.out.println(charArray[i]);
      if (charArray[i] == 'A') {
        firstA = i;
        break;
      }
    }
    for (int i = (charArray.length - 1); i > 0 ; i--) {
      //System.out.println(charArray[i]);
      if (charArray[i] == 'Z') {
        lastZ = i;
        break;
      }
    }
    //System.out.println(firstA + "," + lastZ);
    System.out.println(lastZ - firstA + 1);
  }
}

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

#define nax 3009
#define FOR(i,n,m) for(int i =(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())

int main(){
	int n; cin>>n;
	double prob[nax];
	double dp[nax][nax];
	//dp(i,j): probabilidad de obtener j exitos hasta la
	//iesima posicion
	REP(i,n) cin>>prob[i];

	memset(dp,0.0,sizeof dp);
	REP(i,nax) dp[i][0] = 1.0;

	FOR(i,1,n+1){
		FOR(j,1,i+1){
			dp[i][j] = dp[i-1][j-1]*prob[i-1] + dp[i-1][j]*(1-prob[i-1]);
		}
	}

	printf("%.10lf",dp[n][n/2+1]);

	return 0;
}

Measured memory_bytes: 71040
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
s=SI()
n=len(s)
for i in range(n-1):
    if s[i]==s[i+1]:
        print(i+1,i+2)
        sys.exit()
for i in range(n-2):
    if s[i]==s[i+2]:
        print(i+1,i+3)
        sys.exit()
print(-1,-1)
    

Measured memory_bytes: 9536
#include<stdio.h>
static const int N=1000;
int trace(int A[],int n){
	int i;
	for(i=1; i<=n;i++){
		if(i>1)	printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
	return 0;
} 

int main(){
	int n,i,j,key;
	int A[N+1];
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&A[i]);
	for(j=2;j<=n;j++){
		trace(A,n);
		key = A[j];
		i=j-1;
		while(i>0 && A[i]>key){
			A[i+1] = A[i];
			i--;
		}
		A[i+1]=key;
	}
	trace(A,n);
	return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
int main(){
  int q;
  cin>>q;
  set<int> s;
  for(int i=0;i<q;i++){
    int a,b;
    cin>>a>>b;
    if(a==0){
    s.insert(b);
    cout<<s.size()<<endl;
    }
    if(a==1){
      if(s.find(b)!=s.end()) cout<<"1"<<endl;
      else cout<<"0"<<endl;
    }
  }
  return 0;
}




Measured memory_bytes: 12456
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {

	void solve() {
		n = in.nextInt();


		ret = 48 -n ;
		out.println(ret);
	}

	// only call
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	// predefined
	FastScanner in = new FastScanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	int n, m, a, b, c, d, e, f;
	int ret;
	ArrayList<Integer> list = new ArrayList<>();
	ArrayDeque<Integer> q = new ArrayDeque<>();

	// 2D-map
	int H, W;
	final int[] dw = new int[] { 0, 1, 0, -1, 1, 1, -1, -1 };
	final int[] dh = new int[] { 1, 0, -1, 0, 1, -1, 1, -1 };

	boolean inField(int nw, int nh) {
		if (nw < 0 || nw >= W || nh < 0 || nh >= H) {
			return false;
		}
		return true;
	}

	// Yes/No
	static String yesno(boolean f) {
		return yesno(f, "Yes", "No");
	}

	static String yesno(boolean f, String yes, String no) {
		return (f ? yes : no);
	}

	// search
	PriorityQueue<Node> pq = new PriorityQueue<>();

	class Node implements Comparable<Node> {

		double score;

		@Override
		public int compareTo(Node o) {
			return Double.compare(this.score, o.score);
		}
	}

	// library
	class FastScanner {
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		FastScanner(InputStream in) {
			this.in = in;
		}

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

lin a,b;

lin calc(lin n)
{
    if(n < 0)
        return 0;

    lin res = 0;

    lin x1 = n % 4;
    if(x1 == 1 || x1 == 2)
        res += 1;

    lin d = 4;
    while(d / 2 <= n)
    {
        lin x = n % d;

        if(x >= d / 2 && (x - d / 2) % 2 == 0)
        {
            res += d / 2;
        }

        d *= 2;
    }

    return res;
}

int main(void)
{
    cin >> a >> b;

    lin res = calc(a-1) ^ calc(b);
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <unordered_set>
#include <unordered_map>
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
using llong = long long;
#define BUGO(x) cerr << #x << " = " << (x) << '\n';
#define BUGOARR(a) {cerr << #a << ": "; for (auto i: a) cerr << i << ' '; cerr << '\n';}
#ifndef MANSON
#define BUGO(x)
#define BUGOARR(x)
#endif
ostream& operator<<(ostream& out, const pair<auto, auto>& p) {
    return out << "{" << p.first << ", " << p.second << "}";
}
const int mod = 1000'000'007LL;

int n, k, h, ans;
int a[1 << 18];

inline int mul(int a, int b) { return a * (llong)b % mod; }
void DFS(int v, int prod, vector<pair<int, int>>& leaves)
{
    prod = mul(prod, v);
    if (v >= k)
    {
        leaves.push_back({v, prod});
        return;
    }
    DFS(v * 2, prod, leaves);
    DFS(v * 2 + 1, prod, leaves);
}
int main()
{
    scanf("%d", &h);
    k = (1 << (h - 1));
    n = 2 * k - 1;
    vector<int> edges(k);
    for (int& i: edges) scanf("%d", &i), --i;
    int ans = 0;
    vector<int> clean;
    vector<pair<int, int>> l, r;
    for (int root = 1; root < k; ++root)
    {
        l.clear();
        r.clear();
        DFS(root * 2, root, l);
        DFS(root * 2 + 1, 1, r);
        clean.clear();
        for (auto p: l)
            for (int v = edges[p.first - k] + k, prod = p.second; v > 1; v /= 2)
            {
                prod = mul(prod, v);
                clean.push_back(v);
                a[v] += prod;
                if (a[v] >= mod) a[v] -= mod;
            }
        for (auto p: r)
            for (int v = edges[p.first - k] + k, prod = p.second; v > 1; v /= 2)
            {
                prod = mul(prod, v);
                BUGO(v)
                BUGO(prod)
                BUGO(a[v ^ 1])
                ans += mul(mul(a[v ^ 1], prod), v / 2);
                if (ans >= mod) ans -= mod;
            }
        for (int v: clean)
            a[v] = 0;
    }
    printf("%d", ans);
}


Measured memory_bytes: 14248
import java.util.Arrays;

public class Main {
    // field

    // method
    public static void main(String[] args) {
	//System.out.print("> ");
	java.util.Scanner scan = new java.util.Scanner(System.in);
	int arraySize = scan.nextInt();
	String[] input = new String[arraySize];
	int[] array = new int[arraySize];
	//System.out.print("> ");
	for (int i = 0; i < arraySize; i++){
	    array[i] = scan.nextInt();
	}
	
	SelectionSort ss = new SelectionSort(array.clone()); // セレクションソート
	ss.selectionSort(); // ソート
	ss.display();       // 表示
	System.out.println(ss.getCount());
	
    }
}
class SelectionSort {
    // -- Field
    private int[] sort_array;
    protected int count;
    // -- Constructor
    private SelectionSort() {}
    public SelectionSort(int[] sort_array) {
	this.sort_array = sort_array;
    }
    
    // -- Method
    public void display() {
	for (int i = 0; i < this.sort_array.length; i++) {
	    System.out.print(this.sort_array[i]);
	    if(i == this.sort_array.length-1) {
		break;
	    }
	    System.out.print(" ");
	}
	System.out.println();
    }


    public void swap(int x, int y) {
	int temp = this.sort_array[x];
	this.sort_array[x] = this.sort_array[y];
	this.sort_array[y] = temp;
    }

    public void selectionSort() {
	int out, in, min;
	for (out = 0; out < this.sort_array.length - 1; out++) {
	    min = out;
	    for (in = out + 1; in < this.sort_array.length; in++) {
		if (this.sort_array[in] < this.sort_array[min]) {
		    min = in;
		}
	    }
	    if (out != min) this.count++;
	    this.swap(out, min);
	}
    }
    public int getCount() {
	return this.count;
    }
}



Measured memory_bytes: 26504
#include<cstdio>
#include<cstring>
typedef long long ll;
int main(){
	char s[11];
	scanf("%s",s);
	int l = strlen(s);
	ll ans = 0;
	for(int i=0;i<(1<<l-1);i++){
		ll now = s[0] - '0';
		for(int k=0;k<l-1;k++){
			now *= 10;
			if((i>>k)&1){
				now += s[k+1] - '0';
			}else{
				ans += now / 10;
				now = s[k+1] - '0';
			}
		}
		ans += now;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll a,b;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>a>>b;
    cout<<(b % a == 0 ? a + b : b - a);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FI first
#define SE second
//#define DEBUG

struct NODE
{
	int s, e;
	NODE* next;
};

NODE* shuffle(NODE* head, int x, int y, int n);
pair<NODE*, NODE*> S(NODE* now, int num);
int query(int p, int q, int r);

void printdeck(NODE* head);

NODE* shuffle(NODE* head, int x, int y, int n)
{
	pair<NODE*, NODE*> A, B, C;
	  printdeck(head);
	A = S(head, x);
	  printdeck(head);
	B = S(A.SE->next, y - x);
	  printdeck(head);
	C = S(B.SE->next, n - y);
	  printdeck(head);
	
	C.SE->next = B.FI;
	B.SE->next = A.FI;
	A.SE->next = NULL;
	
	return C.FI;
}

pair<NODE*, NODE*> S(NODE* now, int num)
{	
	int m = now->e - now->s + 1;
	
	if (num == m){
		return {now, now};
	}
	else if (num < m){
		NODE* _node = new NODE;
		_node->s = now->s + num;
		_node->e = now->e;
		_node->next = now->next;
		
		now->e = _node->s - 1;
		now->next = _node;
		
		return {now, now};
	}
	else if (num > m){
		return {now, S(now->next, num - m).SE};
	}
}

int query(NODE* head, int p, int q, int r)
{
	pair<NODE*, NODE*> s;
	s = S(S(head, p - 1).SE->next, q - p + 1);
	
	int res = 0;
	for (NODE* _node = s.FI; /*_node != s.SE*/; _node = _node->next){
		//cout << "_" << _node->s << " " << _node->e << endl;
		if (r < _node->s) res += 0;
		else if (r >= _node->e) res += _node->e - _node->s + 1;
		else res += r - _node->s + 1;
		
		if (_node == s.SE) break;
	}
	
	return res;
}

int main()
{
	int n;
	while (cin >> n, n){
		int m;
		cin >> m;
		
		int p, q, r;
		cin >> p >> q >> r;
		
		NODE* head = new NODE;
		head->s = 1;
		head->e = n;
		head->next = NULL;
		
		for (int i = 0; i < m; i++){
			int x, y;
			cin >> x >> y;
			head = shuffle(head, x, y, n);
			  printdeck(head);
		}
		
		cout << query(head, p, q, r) << endl;
	}
	
	return 0;
}

void printdeck(NODE* head)
{
	#ifdef DEBUG
	cout << endl;
	for (NODE* _node = head; _node != NULL; _node = _node->next){
		cout << _node->s << " " << _node->e << endl;
	}
	cout << endl;
	#endif
}

Measured memory_bytes: 2228
S = input()

N = len(S)
tcnt =[0] * 128
for c in S:
    tcnt[ord(c)] += 1 if c != 'x' else 0
odd = 0
for i in range(128):
    if tcnt[i] % 2 == 1:
        if odd != 0:
            print(-1)
            exit()
        else:
            odd = i

cl = -1
cr = -1
cnt = [0] * 128
for i in range(N):
    cnt[ord(S[i])] += 1 if S[i] != 'x' else 0
    if cnt[ord(S[i])] > (tcnt[ord(S[i])] + 1) // 2:
        cr = i
        break
    elif S[i] != 'x':
        cl = i
if cl == -1:
    print(0)
    exit()

if odd != 0:
    cr = cl

ans = 0
while cl >= 0 and cr < N:
    l = cl - 1
    while l >= 0 and S[l] == 'x':
        l -= 1
    lx = cl - l - 1
    r = cr + 1
    while r < N and S[r] == 'x':
        r += 1
    rx = r - cr - 1
    ans += abs(lx - rx)

    a = ord(S[l]) if l >= 0 else 0
    b = ord(S[r]) if r < N else 0
    if a != b:
        print(-1)
        exit()
    else:
        cl = l
        cr = r

print(ans)

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> vec(N);
	for (int i = 0; i < M; i++){
    	int x1, x2;
    	cin >> x1 >> x2;
    	vec.at(x1 - 1) += 1;
    	vec.at(x2 - 1) += 1;
    }
  	for (int i = 0; i < N; i++){
    	cout << vec.at(i) << endl;
    }
}

Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int N;

int sum(int x)
{
	int ret = 0;
	for(; x; x/=10) ret += x%10;
	return ret;
}

int main(void)
{
	cin >> N;
	
	int ans = 1e9;
	for(int i = 1; i <= N-1; i++){
		ans = min(ans, sum(i) + sum(N-i));
	}
	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 all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using vi = vector<int>;
using vv = vector<vi>;
//const int MOD = 1000000007;
//const int MOD = 998244353;
const ll INF = 1001001001001;

int main(){
    int H, W, M;
    cin >> H >> W >> M;
    vector<P> vH(H), vW(W);
    set<P> vB;
    rep(i,H){
        vH[i].first = 0;
        vH[i].second = i;
    }
    rep(i,W){
        vW[i].first = 0;
        vW[i].second = i;
    }
    
    while(M){
        M--;
        int i,j; cin>>i>>j; i--;j--;
        vH[i].first++;
        vW[j].first++;
        vB.insert(P(i,j));
    }
    sort(rall(vH));
    sort(rall(vW));
    
    int nH = vH[0].first;
    int nW = vW[0].first;
    set<int> mH, mW;
    auto itH = &vH[0], itW = &vW[0];
    while((*itH).first == nH){
        mH.insert((*itH).second);
        itH++;
    }
    while((*itW).first == nW){
        mW.insert((*itW).second);
        itW++;
    }
    
    ll count = (ll)mH.size()*mW.size();
    
    if(count>vB.size()){
        cout<< nH+nW <<endl;
        return 0;
    }
    
    for(auto b: vB){
        int h = b.first;
        int w = b.second;
        if(mH.count(h) && mW.count(w))
            count--;
    }
    
    if(!count)
        cout << nH+nW-1 << endl;
    else
        cout << nH+nW << endl;
    return 0;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  int n,m;
  n=s.size(),m=t.size();
  int start=-1;
  rep(i,n-m+1){
    rep(j,m){
      if(s[(n-1)-(i+j)]==t[(m-1)-j] or s[(n-1)-(i+j)] == '?'){
        if(j==m-1) start=(n-1)-(i+j);
      }else break;
    }
    if(start!=-1) break;
  }
  if(start == -1){
    cout << "UNRESTORABLE" << "\n";
    return 0;
  }
  rep(i,m) s[start+i]=t[i];
  rep(i,n) if(s[i]=='?') s[i]='a';
  
  cout << s;
  
  return 0;
}

Measured memory_bytes: 3612
/*
 * atcoder/abc089/b.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
void solve();
int main() { solve(); return 0; }

#define ld long double
void solve() {
  vector<string> S(3);
  loop(i,0,3) cin >> S[i];
  cout << S[0][0] << S[1][1] << S[2][2] << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

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

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

using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;

void ptn(vector<vector<bool>> &ans,ll i,ll j,ll p){
    if(p==1){
        ans[i*4][j*4]=1;ans[i*4+1][j*4]=1;ans[i*4+2][j*4]=1;
        ans[i*4][j*4+1]=1;ans[i*4+2][j*4+1]=1;
        ans[i*4][j*4+2]=1;ans[i*4+1][j*4+2]=1;ans[i*4+2][j*4+2]=1;
    }
    if(p==2){
        ans[i*4+1][j*4+1]=1;
    }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll A,B;
    cin>>A>>B;
    
    bool bo=(A>B);
    if(bo){
        ll tmp=A;
        A=B;
        B=tmp;
    }
    
    vector<vector<bool>> ans(100,vector<bool>(100,0));
    
    if(A<=B){
        ll count=0;
        for(ll i=0;i<100;i++){
            for(ll j=0;j<100;j++){
                ptn(ans,i,j,3);
            }
        }
        for(ll i=0;i<A-1;i++){
            ptn(ans,count/25,count%25,1);
            count++;
        }
        for(ll i=0;i<B-A+1;i++){
            ptn(ans,count/25,count%25,2);
            count++;
        }
    }
    
    printf("100 100\n");
    for(ll i=0;i<100;i++){
        for(ll j=0;j<100;j++){
            if((ans[i][j]==1 && !bo) || (ans[i][j]==0 && bo)) printf("#");
            else printf(".");
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 256
N=int(input())
if N%10==2 or N%10==4 or N%10==5 or N%10==7 or N%10==9:
  print("hon")
elif N%10==0 or N%10==1 or N%10==6 or N%10==8:
  print("pon")
else:
  print("bon")

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

 int main() {
   int n, m;
   cin >> n >> m;
   int s[10];
   char c[10];
   char a[3];
   bool res = true;

   for (int i = 0; i < n; i++) {
     a[i] = '0';
   }
   if (n != 1) {
     a[0] = '1';
   }

    for (int i = 0; i < m; i++) {
      cin >> s[i] >> c[i];
      //std::cout << s[i] << c[i] << '\n';
      a[s[i] -1] = c[i];
      if ((s[i] == 1 && c[i] == '0') && (n != 1)) {
        res = false;
        break;
      }
      for (int j = 0; j < i; j++) {
        if (s[i] == s[j] && c[i] != c[j]) {
          res = false;
        }
      }
    }

    if (res) {
      for (int i = 0; i < n; i++) {
        cout << a[i];
      }
    }else{
      cout << "-1";
    }
    cout <<'\n';

 }


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, a, b int64
	fmt.Scanf("%d %d %d\n", &n, &a, &b)

	fmt.Println(n/(a+b)*a + min(n%(a+b), a))
}

func min(a, b int64) int64 {
	if a <= b {
		return a
	}
	return b
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
typedef long long ll;

ll D;

ll hoge(ll A,ll t,int first) {
	if(t==0) return A==0;
	int v=(A%10+10)%10;
	ll ret=0;
	ret+=(10-v-first)*hoge((A-t*v)/10,t/100,0);
	ret+=(v-first)*hoge((A+(10-v)*t)/10,t/100,0);
	return ret;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>D;
	if(D%9) { cout<<0<<endl; return; }
	D/=9;
	ll ret=0;
	ll p10=10;
	for(i=2;i<=18;i++) {
		p10*=10;
		
		ll tot=(i%2)?10:1;
		ret += tot*hoge(D,p10/10/9,1);
	}
	cout<<ret<<endl;
	
}

int main() {
	solve();
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, a, b, c = map(int, input().split())
query = []
for _ in range(n):
    s = input().rstrip()
    query.append(s)
    
ans = []
for i, s in enumerate(query):
    if s == "AB":
        if a == 0 and b == 0:
            print("No")
            exit()
        elif a == 1 and b == 1:
            if i + 1 < n and "A" in query[i + 1]:
                ans.append("A")
                a += 1; b -= 1
            else:
                ans.append("B")
                b += 1; a -= 1
        elif b >= a:
            ans.append("A")
            a += 1; b -= 1
        else:
            ans.append("B")
            b += 1; a -= 1
    elif s == "AC":
        if a == 0 and c == 0:
            print("No")
            exit()
        elif a == 1 and c == 1:
            if i + 1 < n and "A" in query[i + 1]:
                ans.append("A")
                a += 1; c -= 1
            else:
                ans.append("C")
                c += 1; a -= 1
        elif c >= a:
            ans.append("A")
            a += 1; c -= 1
        else:
            ans.append("C")
            c += 1; a -= 1
    elif s == "BC":
        if b == 0 and c == 0:
            print("No")
            exit()
        elif b == 1 and c == 1:
            if i + 1 < n and "B" in query[i + 1]:
                ans.append("B")
                b += 1; c -= 1
            else:
                ans.append("C")
                c += 1; b -= 1
        elif c >= b:
            ans.append("B")
            b += 1; c -= 1
        else:
            ans.append("C")
            c += 1; b -= 1

print("Yes")
for item in ans:
    print(item)

Measured memory_bytes: 80144
def f(num,N,S):
    alphabet = ["a","b","c","d","e","f","g","h","i","j"]
    if N == num:
        for i in range(len(S)):
            print(S[i])
        return
    else:
        tmp = []
        length = len(S)
        for i in range(length):
            ttmp = sorted(list(S[i]))
            for j in range(alphabet.index(ttmp[-1])+2):
                tmp.append(S[i]+alphabet[j])
        S = tmp
        f(num+1,N,S)
 
N = int(input())
f(1,N,["a"])

Measured memory_bytes: 14552
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<Bint> A(N);
  Bint threshold = 1000000000000000000;
  
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());

  Bint product = 1;
  for (int i = 0; i < N; i++) {
    product *= A.at(i);
    //if (product.str().length() > 19) {
    // cout << product.str().length() << endl;
    //  return 0;
    //}
    if (product > threshold) {
      cout << -1 << endl;
      return 0;
    }
  }
  
  cout << product << endl;
}

Measured memory_bytes: 6504
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
using namespace std;
int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){return x+y-min(x,y);}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
//ARC093D
bool color[10000];//white=true,black=false
void paint(int x)
{
    if(color[x])cout<<".";
    else cout<<"#";
    return;
}
int main()
{
    rep(i,50)
    {
        rep(j,100)
        {
            color[100*i+j]=false;
        }
    }
    rep(i,50)
    {
        rep(j,100)
        {
            color[100*i+j+5000]=true;
        }
    }
    int a,b;
    cin>>a>>b;
    cout<<"100 100"<<endl;
    rep(i,a-1)
    {
        color[7*i]=true;
    }
    rep(i,b-1)
    {
        color[9999-7*i]=false;
    }
    rep(i,100)
    {
        rep(j,100)
        {
            paint(100*i+j);
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

S_xor = 0
ans = []

for a in A_list:
    S_xor ^= a

for a in A_list:
    x = S_xor ^ a
    ans.append(x)

print(*ans)


Measured memory_bytes: 31388
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if (s == "SUN") cout << 7 << endl;
  if (s == "MON") cout << 6 << endl;
  if (s == "TUE") cout << 5 << endl;
  if (s == "WED") cout << 4 << endl;
  if (s == "THU") cout << 3 << endl;
  if (s == "FRI") cout << 2 << endl;
  if (s == "SAT") cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, i := sc.nextInt(), sc.nextInt()

	fmt.Fprintln(wtr, N-i+1)
	wtr.Flush()
}


Measured memory_bytes: 640
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
#

def join(s):
    return ''.join(s)

#iterate macro
def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)

#modulo macro
def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m

#bisect macro
def index(a, x):
    #Locate the leftmost value exactly equal to x
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1

#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

nh=zip([1,0,-1,0],[0,1,0,-1])

###########

n,a,b=ii()
c=a+b
s=slist()
ans=['' for j in range(n)]
ps=0
fr=0
for j in range(n):
    if s[j]=='a':
        if ps<c:
            ps+=1
            print "Yes"
        else:
            print "No"
    elif s[j]=='b':
        if ps<c and fr<b:
            ps+=1
            fr+=1
            print "Yes"
        else:
            print "No"
    else:
        print "No"
        


Measured memory_bytes: 7932
#include <stdio.h>
#include <list>
using namespace std;
const int N=1e5+10;
int main(){
    list<int> l[N];
    int n,q,t;
    scanf("%d%d",&n,&q);
    while(q--){
        scanf("%d%d",&n,&t);
        if(n==0){
            scanf("%d",&n);
            l[t].insert(l[t].end(),n);
        }
        else if(n==1){
            if(!l[t].empty()){
                printf("%d",*l[t].begin());
                for(list<int>::iterator i=++l[t].begin();i!=l[t].end();i++)printf(" %d",*i);
            }
            printf("\n");
        }
        else{
            scanf("%d",&n);
            l[n].splice(l[n].end(),l[t]);
            l[t].clear();
        }
    }
}


Measured memory_bytes: 19828
def soinnsuubunnkai(n):
  ret = []
  for i in range(2, int(n ** (1 / 2)) + 1):
    if i > n:break
    while n % i == 0:
      n //= i
      ret.append(i)
  if n != 1:
    ret.append(n)
  return ret

n = int(input())
print(str(n)+": ",end="")
print(*soinnsuubunnkai(n))


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

#define MOD 1000000007

long long modPow(long long a,long long n){
  if(n==1) return a%MOD;
  if(n%2==1) return (a*modPow(a,n-1))%MOD;
  long long x=modPow(a,n/2);
  return (x*x)%MOD;
}

long long modInv(long long a){
  return modPow(a,MOD-2);
}

long long modFact(long long n){
  if(n==0 || n==1) return 1;
  return (n*modFact(n-1))%MOD;
}

long long modComb(long long n,long long r){
  long long x=1;
  for(int i=n;i>=n-r+1;i--){
    x=(x*i)%MOD;
  }
  return (x*modInv(modFact(r)))%MOD;
}

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  long long x=modPow(2,n)-1;
  x=(x-(modComb(n,a)+modComb(n,b))%MOD)%MOD;
  if(x<0) x+=MOD;
  cout << x << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n; cin>>n;
  int a[n]; rep(i,n) cin>>a[i];
  ll ans = 0;
  if(a[0]) return cout << -1 << endl, 0;
  reps(i,n-1){
    if(a[i]==a[i-1]+1) ans++;
    else if(a[i]>a[i-1]+1) return cout << -1 << endl, 0;
    else ans += a[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string.h>
#define ll long long int
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fr(i,x,n) for(ll i=x;i>=n;i--)
#define mod 1e9+7
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n; i++)a[i]=0;
	while(k--)
	{
	    int d;cin>>d;
	    int de;
	    for(int i=0; i<d; i++)
	    {
	      cin>> de;
	      //cout<<de;
	      a[de-1]++;
	      //cout<<a[de]<<" ";
	    }
	}
	//for(int i=0;i<n; i++)cout<<a[i]<<" ";
	int c=0;
	for(int i=0; i<n;i++)
	{
	    if(a[i]==0)
	    c++;
	}
	cout<<c<<"\n";
	return 0;
}

Measured memory_bytes: 3192
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

n=int(input())
A=[int(input()) for i in range(n)]
C=Counter(A)
print(len([i for i in C.values() if i%2==1]))

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

int i, j, l;

int main()
{
    int k;
    int sum = 0;
    std::cin >> k;

    for (i = 1; i <= k; i++)
    {
        for (j = 1; j <= k; j++)
        {
            for (l = 1; l <= k; l++)
            {
                sum += std::gcd(std::gcd(i, j), std::gcd(j, l));
            }
        }
    }

    std::cout << sum;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int h, w, d;
    cin >> h >> w >> d;
    mat a(h, vec(w));
    vector<P> m(h*w);
    rep(i, h) rep(j, w) {
        cin >> a[i][j];
        --a[i][j];
        m[a[i][j]] = make_pair(i, j);
    }
    int q;
    cin >> q;
    vec l(q), r(q);
    rep(i, q) {
        cin >> l[i] >> r[i];
        --l[i];
        --r[i];
    }

    vec cost(h*w, 0);

    for (int i = d; i < h*w; i++) {
        cost[i] = cost[i-d];
        auto prev = m[i-d], now = m[i];
        cost[i] += abs(prev.first - now.first) + abs(prev.second - now.second);
    }

    rep(i, q) {
        int res = cost[r[i]] - cost[l[i]];
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = (int)2e5 + 5;
const int mod = (int)1e9 + 7;
using namespace std;

int a[maxn];

int main()
{
	int n; scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	ll ans = 0, h = 0;
	int j = 0;
	for(int i = 0; i < n; i++){
		for( ; j < n; j++){
			if((h|a[j]) != h + a[j]) break;
			else{
				h += a[j];
				ans += (j - i + 1);
			}
		}
		h -= a[i];
	}
	printf("%lld\n", ans);
	return 0;
}

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

vector<string> P[100000];

int main(){
  int N, M;
  cin >> N >> M;
  for(int i=0; i<M; i++){
    int p; string s;
    cin >> p >> s;
    P[p-1].push_back(s);
  }
  int ac=0, wa=0;
  for(int i=0; i<N; i++){
    if(P[i].size()==0) continue;
    bool flag = false;
    int w=0;
    for(int j=0; j<P[i].size(); j++){
      if(P[i][j]=="AC"){
        flag=true; ac++; break;
      }else{
        w++;
      }
    }
    if(flag){
      wa+=w;
    }
  }
  cout << ac << ' ' << wa << endl;
  return 0;
}

Measured memory_bytes: 10368