akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.Map.Entry;

import static java.lang.Integer.*;
//import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] v = new int[n];
		HashMap<Integer, Integer> kisu = new HashMap<>();
		HashMap<Integer, Integer> gusu = new HashMap<>();
		for(i=0;i<n;i++) {
			v[i] = parseInt(sc.next());
			if((i&1)==0) {
				Integer va = gusu.get(v[i]);
				if(va == null) {
					va = 0;
				}
				gusu.put(v[i],va.intValue()+1);
			} else {
				Integer va = kisu.get(v[i]);
				if(va == null) {
					va = 0;
				}
				kisu.put(v[i],va.intValue()+1);
			}
		}
//		out.println(n);
//		out.println(Arrays.toString(v));
		sc.close();
		List<Entry<Integer, Integer>> entKisu = new ArrayList<Entry<Integer, Integer>>(kisu.entrySet());
		Collections.sort(entKisu, new Comparator<Entry<Integer, Integer>>(){
			@Override
			public int compare(Entry<Integer,Integer> ent1, Entry<Integer,Integer> ent2) {
                return ent2.getValue().compareTo(ent1.getValue());
            }
		});
		List<Entry<Integer, Integer>> entGusu = new ArrayList<Entry<Integer, Integer>>(gusu.entrySet());
		Collections.sort(entGusu, new Comparator<Entry<Integer, Integer>>(){
			@Override
			public int compare(Entry<Integer,Integer> ent1, Entry<Integer,Integer> ent2) {
                return ent2.getValue().compareTo(ent1.getValue());
            }
		});
		int ans;
		if(entKisu.get(0).getKey().intValue() != entGusu.get(0).getKey().intValue()) {
			ans = n - entKisu.get(0).getValue() - entGusu.get(0).getValue();
		} else {
			if(entKisu.get(0).getKey().intValue() > entGusu.get(0).getKey().intValue()) {
				ans = n - entKisu.get(0).getValue() - entGusu.get(1).getValue();
			} else if(entKisu.get(0).getKey().intValue() < entGusu.get(0).getKey().intValue()) {
				ans = n - entKisu.get(1).getValue() - entGusu.get(0).getValue();
			} else {
				if(entKisu.size() == 1) {
					ans = n - entKisu.get(0).getValue();
				} else {
					ans = n - entKisu.get(0).getValue() - Math.max(entKisu.get(1).getValue().intValue(), entGusu.get(1).getValue().intValue());
				}
			}
		}
		out.println(ans);
	}
}


Measured memory_bytes: 51596
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	uint64_t xxor=0;
	vector<int>arr(n);
	for(int i=0;i<n;i++){
		cin>>arr[i];
		xxor=xxor^arr[i];
	}
	for(int i=0;i<n;i++){
		cout<<(xxor^arr[i])<<" ";
	}
}


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

int num[200][200];

int main()
{
	int n;
	while (scanf("%d", &n), n){
		int w, h;
		scanf("%d %d", &w, &h);
		
		memset(num, 0, sizeof(num));
		for (int i = 0; i < n; i++){
			int x, y;
			scanf("%d %d", &x, &y);
			num[x][y] = 1;
		}
		
		for (int i = 1; i <= w; i++){
			for (int j = 1; j <= h; j++){
				num[i][j] += num[i - 1][j];
				num[i][j] += num[i][j - 1];
				num[i][j] -= num[i - 1][j - 1];
			}
		}
		
		int X, Y;
		scanf("%d %d", &X, &Y);
		
		int maxi = 0;
		for (int i = 0; i + X <= w; i++){
			for (int j = 0; j + Y <= h; j++){
				maxi = max(maxi, num[i + X][j + Y] - num[i + X][j] - num[i][j + Y] + num[i][j]);
			}
		}
		
		printf("%d\n", maxi);
	}
	
	return 0;
}

Measured memory_bytes: 1352
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;

char s[N];
int f[N][2];

bool judge(int i1, int len1, int i2, int len2){
	if (len1 != len2) return 1;
	for (int i = 0; i <= len1; i++){
		if (s[i1 - i] != s[i2 - i]) return 1;
	}
	return 0;
}

int main(){
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	f[1][0] = 1;
	f[2][1] = 1;
	for (int i = 2; i <= n; i++){
		for (int j = 0; j < 2; j++){
			if (i <= j) continue;
			for (int k = 0; k < 2; k++){
				if (i - 1 - j <= k) continue;
				if (judge(i, j, i - 1 - j, k)){
					f[i][j] = max(f[i][j], f[i - 1 - j][k] + 1);
				}
			}
		}
	}
	printf("%d", max(f[n][0], f[n][1]));
	return 0;
}

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

signed main(){
  int A,B,C;
  cin>>A>>B>>C;
  string ans="No";
  if(A<=C&&C<=B)ans="Yes";
  cout<<ans<<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 repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); 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 End '\n'
#define Out(x) cout<<(x)<<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

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

template <typename T>
T Pow(T a, T b) {
	T ret = 1;

	while (0 < b) {
		if (b & 1) ret *= a;

		b >>= 1;
		a *= a;
	}

	return ret;
}

#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);

    int a[3];
    int k;

    cin >> a[0] >> a[1] >> a[2];
    cin >> k;

    sort(a, a + 3);

    a[2] *= Pow<int>(2, k);

    Out(a[0] + a[1] + a[2]);

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    static tree[] wd;
    static int root =-1;
	public static void main(String[] args) {
	    int i=0,j,n;
	    String x;
	// TODO Auto-generated method stub
     Scanner sca = new Scanner(System.in);
     n=sca.nextInt();
     wd=new tree[n];
    for(j=0;j<n;j++){
       x=sca.next();
    	if(x.equals("insert")){
	    wd[i]=new tree(sca.nextInt());
	    insert(i);
	    i++;
	 }
    	if(x.equals("print")){
    	    inorder(root);
    	    System.out.println("");
    	    preorder(root);
    	    System.out.println("");  		
    	}
    }
   }
    public static void preorder(int nd){
	System.out.print(" "+wd[nd].getnode());
	if(wd[nd].getleft()!=-1)preorder(wd[nd].getleft());
	if(wd[nd].getright()!=-1)preorder(wd[nd].getright());
    }
    public static void inorder(int nd){
	if(wd[nd].getleft()!=-1)inorder(wd[nd].getleft());
	System.out.print(" "+wd[nd].getnode());
	if(wd[nd].getright()!=-1)inorder(wd[nd].getright());
    }
    public static void insert(int data){//NIL->-1
     int y=-1,x=root;//parent of x
     while(x!=-1){
    	y=x;
    	if(wd[data].getnode()<wd[x].getnode()){
    		x=wd[x].getleft();
    	}else{
    		x=wd[x].getright();
    	}
    }
     if (y==-1){//it is root
    	 root=data;
     }else if(wd[data].getnode()<wd[y].getnode()){
    	 wd[y].setleft(data);
     }else{
    	 wd[y].setright(data);
     }
    }
}
class tree{
    int node,par,n,i,degree=0;
    int left=-1,right=-1;
    tree(int node){
	this.node=node;
    }
    public int getnode(){
	return node;
    }
    public void setleft(int c){
	left=c;
	if(left!=-1) degree++;
    }
    public int getleft(){
	return left;
    }
    public void setright(int c){
	right=c;
	if(right!=-1) degree++;
    }
    public int getright(){
	return right;
    }
}



Measured memory_bytes: 229340
#include "bits/stdc++.h"
using namespace std;

int main(){
    int n,tmp;
    
    cin >> n;
    vector<int> l(n);

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

    int max = *max_element(l.begin(),l.end());
    int sum = accumulate(l.begin(),l.end(),0) - max;
    
    if(max<sum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	int n, k;
	cin >> n >> k;
	vi a(n);
	loop(n) {
		cin >> a[i];
		if (i >= k) {
			cout << (a[i] > a[i - k] ? "Yes" : "No") << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3980
n,k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
mod = 10**9+7
ans = 0
for i in range(n):
    cnt = 0
    cnt2  =0
    for j in range(i):
        if a[i]>a[j]:
            cnt += 1
    for j in range(i+1,n):
        if a[i]>a[j]:
            cnt2+=1
    ans = (ans+cnt2*k*(k+1)//2+(cnt*k*(k-1)//2)%mod)%mod
print(ans)

Measured memory_bytes: 42348
#include <stdio.h>

int main(void)
{
	float a, b, max, min, e;
	
	e = 1;
	
	while (scanf("%f", &a) != EOF){
		if (e == 1) {
			max = a;
			min = a;
		}
		else if (max < a) {
			max = a;
		}
		else if (min > a) {
			min = a;
		}
		e++;
	}
	
	printf("%f\n", max - min);
	
	return (0);
}	

Measured memory_bytes: 644
A,B,C,X,Y = map(int,raw_input().split())
miny=0
if A+B < 2*C:
    miny=A*X+B*Y
else:
    if X<Y:
        if 2*C>B:
            miny=2*C*X + B*(Y-X)
        else:
            miny=2*C*Y
    else:
        if 2*C>A:
            miny=2*C*Y + A*(X-Y)
        else:
            miny=2*C*X

print miny

Measured memory_bytes: 2568
module Main where

import Data.Functor

main :: IO ()
main = do
  { [x,y] <- getInts
  ; if x == 0 && y == 0 then done
    else do
      { case compare x y of
          LT -> putInts [x,y]
          GT -> do putInts [y,x]
          EQ -> do putInts [x,y]
        ; main
      }
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

done :: IO ()
done = return ()

Measured memory_bytes: 4136
import java.math.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    sc.close();
    
    boolean ans = (S.charAt(2) == S.charAt(3) 
        && S.charAt(4) == S.charAt(5));
    System.out.println(ans ? "Yes" : "No");
  }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
typedef long long ll;
typedef pair<int,int> P;
int main() {
    ll a,b,c;
    int n;
    cin>>a>>b>>c>>n;
    ll ans=2*(a*b+b*c+c*a)+6*n;
    set<pair<int,P> > st;
    REP(i,n){
        int x,y,z;
        cin>>x>>y>>z;
        st.insert(make_pair(x,P(y,z)));
    }
    int dx[]={1,-1,0,0,0,0},dy[]={0,0,1,-1,0,0},dz[]= {0,0,0,0,1,-1};
    for (auto p:st){
        int x=p.first,y=p.second.first,z=p.second.second;
        REP(k,6){
            int xx=x+dx[k],yy=y+dy[k],zz=z+dz[k];
            if(xx<0||yy<0||zz<0||xx>=a||yy>=b||zz>=c)ans-=2;
            else if (st.find(make_pair(xx,P(yy,zz)))!=st.end())ans-=1;
        }
    }
    cout<<ans<<endl; 
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
int a[110][110];
int x,y;
int flag;
int h,w;

void solve(int num,int cnt)
{
    while(cnt--)
    {
        a[x][y] = num;

        if(flag) y++;
        else y--;

        if(y > w || y < 1)
        {
            x++;
            if(flag)
            {
                flag = 0;
                y = w;
            }
            else
            {
                flag = 1;
                y = 1;
            }
        }
    }
}

int main()
{
    int n;
    int i,j,cnt;

    while(scanf("%d%d",&h,&w) != EOF)
    {
        scanf("%d",&n);
        x = 1,y = 1;
        flag = 1;
        for(i = 1;i <= n;i++)
        {
            scanf("%d",&cnt);
            solve(i,cnt);
        }
        for(i = 1;i <= h;i++)
        {
            for(j = 1;j <= w;j++)
            {
                if(j == 1)
                printf("%d",a[i][j]);
                else printf(" %d",a[i][j]);
            }
            printf("\n");
        }
    }

    return 0;
}




Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
	int S, h, m, s;
	cin >> S;
	h = S / 3600;
	m = (S % 3600) / 60;
	s = S % 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;

int main(){

  ll n,q;
  cin >> n>> q;
  string s;
  cin >> s;

  ll a[n]={};
  for(int i=0;i<n-1;i++){
    if(s[i]=='A' && s[i+1]=='C')a[i]=1;
  }

  ll b[n+1]={};

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

  ll l,r;
  for(int i=0;i<q;i++){
    cin >> l >> r;
    ll m=b[r]-b[l-1];
    if(a[r-1]==1)m--;
    cout << max((ll)0,m) << endl;
  }
  
  


}

Measured memory_bytes: 5332
#coding=UTF-8

S=input()
Slen=len(S)

for idx in range(Slen-2,0-1,-2):
    T=S[0:idx]

    Tlen=len(T)
    #hantei
    for idy in range(0,Tlen//2,1):
        if T[idy] !=T[Tlen//2+idy]:
            break
    else:
        ans=idx
        break

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

//エラトステネスの篩 n以下の素数を列挙
vector<int> sieve(int n){
	vector<int> prime;
	bool is_prime[n+1];
	for(int i=0;i<=n;i++) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime.push_back(i);
			for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
		}
	}
	return prime;
}

int main(){
	int N;
	cin>>N;
	vector<int> A(sieve(55555));
	vector<int> ans;
	for(int i=0;i<A.size();i++){
		if(A[i]%5==1) ans.push_back(A[i]);
	}
	for(int i=0;i<N;i++){
		cout<<ans[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 384
n,m=map(int,input().split())
s=[0]*n
max_=1
min_=n
for _ in range(m):
    b,c=map(int,input().split())
    if b>max_:
        max_=b
    if c<min_:
        min_=c
if min_<max_:
  print('0')
else:
  print(min_-max_+1)

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

using namespace std;

#define long long long
#define INF ((long) 2e18)
#define MOD ((long) (1e9 + 7))
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long n, k;
        cin >> n >> k;

        vector<long> a(n), f(n);
        for (auto &x : a) cin >> x;
        for (auto &x : f) cin >> x;

        sort(a.begin(), a.end());
        sort(f.begin(), f.end(), greater<long>());

        long l = 0;
        long r = INF;
        long best = INF;
        while (l < r) {
            long mid = (l + r) / 2;
            long aux = k;
            bool ok = true;
            for (long i = 0; i < n; i++) {
                long mult = a[i] * f[i];
                long diff = max(mult - mid, 0LL);
                long count = (diff + f[i] - 1) / f[i];
                aux -= count;
                if (aux < 0) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                best = min(best, mid);
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        printf("%lld\n", best);
    }
}


Measured memory_bytes: 6364
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int num;
vector<int> vec(201);

int main()
{
  // まずは数値の読み込み
  cin >> num;
  for(int i=0; i<num; ++i) cin >> vec.at(i);

  
  int counter = 0;  // 操作が行える回数を記録する
  
  // 対象のベクトルに奇数が含まれるかを調べる
  while(true){
    bool exist_odd = false;  // 奇数があるかないかを示すフラグ
    for(int i=0; i<num; ++i){
      if(vec.at(i)%2==1) exist_odd = true;
    }
    
    if(exist_odd) break;  // 奇数があったらbreak

    // 操作を実際にやる
    for(int i=0; i<num; ++i){
      vec.at(i) /= 2;
    }
    ++counter;
    
  }

  cout << counter << endl;

}


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



int main(){
    double n,a,ans,b;
    //string m;
    cin >> n;
    //vector<string> s(n);
    rep(i,n){
        cin >> a;
        b+=1/a;
    }
    ans = 1/b;
    //cout << ans << endl;
    printf("%.6lf",ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N, M; cin >> N >> M;
		string S; cin >> S;
		vector<vector<UL>> E(N * 2);
		rep(i, M) {
			UL a, b; cin >> a >> b; a--; b--;
			if (S[a] == S[b]) {
				E[2 * a].push_back(2 * b + 1);
				E[2 * b].push_back(2 * a + 1);
			}
			else {
				E[2 * a + 1].push_back(2 * b);
				E[2 * b + 1].push_back(2 * a);
			}
		}
		vector<UL> F(N * 2);
		rep(i, E.size()) for (UL e : E[i]) F[e]++;
		queue<UL> Q; rep(i, N * 2) if (F[i] == 0) Q.push(i);
		vector<UL> tol;
		while (Q.size()) {
			UL p = Q.front(); Q.pop();
			tol.push_back(p);
			for (UL e : E[p]) { F[e]--; if (F[e] == 0) Q.push(e); }
		}
		if (tol.size() == 2 * N) cout << "No" << endl;
		else cout << "Yes" << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 21116
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, k, a[100002], b[100002], c[100002], ans;
signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) 
		cin >> a[i];
	b[0] = max(0LL, a[0]);
	for (int i = 1; i < n; i++) 
		b[i] = b[i - 1] + max(0LL, a[i]);
	c[n - 1] = max(0LL, a[n - 1]);
	for (int i = n - 2; i >= 0; i--)
		c[i] = c[i + 1] + max(0LL, a[i]);
	for (int i = 0; i <= n - k; i++) {
		int sum = 0, sum2 = 0;
		for (int j = i; j < i+k; j++)
			sum += a[j];
		if (i != 0)
			sum2 += b[i - 1];
		if (i != n - k)
			sum2 += c[i + k];
		ans = max(ans, max(sum + sum2, sum2));
	}
	cout << ans << endl;
	getchar(); getchar();
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  double ans;
  ans = 0;
  for (int i = 1; i < N + 1; i++) {
    int score, count;
    score = i;
    count = 0;
    while (score < K) {
      score *= 2;
      count++;
    }
    ans += 1.0 / N * pow(1.0 / 2, (double)count);
  }
  
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
from functools import reduce
from operator import xor


N = int(input())
a = list(map(int, input().split()))


# 右の箱から順に詰める
dp = [0 for _ in range(N + 1)]
for i in range(N, 0, -1):
    dp[i] = reduce(
        xor,
        (dp[j] for j in range(2 * i, N + 1, i)),
        a[i - 1]
    )
b = [i for i in range(1, N + 1) if dp[i]]
ans = (
    '0' if len(b) == 0 else
    '{}\n{}'.format(
        len(b),
        ' '.join(map(str, b))
    )
)

print(ans)


Measured memory_bytes: 20392
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>

using namespace std;
typedef long long ll;

int main() {
   ll N, M;
   cin >> N >> M;
   ll ans = 0;
   if (N != 1 && M != 1) ans = (N - 2) * (M - 2);
   else if (N == 1 && M == 1) ans = 1;
   else if (N == 1 ) ans = M - 2;
   else ans = N - 2;
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(void){
    // Your code here!
   string c;
   cin >> c;
   if(c == "a" || c == "i")
   cout << "vowel" << endl;
   
    else if(c == "u" || c == "e")
   cout << "vowel" << endl;
   
  else if(c == "o")
   cout << "vowel" << endl;
   
   else
   cout << "consonant" << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
    cin >> n;
    vector<int>v(n);
    vector<int> dp(n, 0); // dp[i] : Minimum cost for the frog to reach position i.
    for (int i = 0; i < n; i++) cin >> v[i];
    dp[1] = abs(v[1] - v[0]); // Base value
    for (int i = 2; i < n; i++)
        dp[i] = min(abs(v[i] - v[i - 1]) + dp[i - 1], abs(v[i] - v[i - 2]) + dp[i - 2]);
    cout << dp[n - 1];
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;

int n;
int l,r, tar, fin;
int mem[100001] = {}, somem[100001] = {};
queue<int> que;
vector<int> so;

int main(){
    int upper = 100000;
    for(int i = 2; i <= upper; i++){
        que.push(i);
    }
    for(int i = 2; i <= upper; i++){
        if(que.size() != 0){
            so.push_back(que.front());
            somem[que.front()] = 1;
            tar = que.front();
            que.pop();
        }
        fin = que.size();
        for(int j = 0; j < fin; j++){
            if(que.front() % tar != 0){
                que.push(que.front());
                que.pop();
            }
            else    que.pop();
        }
    }
    so.push_back(0);
    int vecpos = 0;
    for(int i = 1; i < 100001; i++){
        if(i == so[vecpos]){
            mem[i] = mem[i-1];
            if(somem[(so[vecpos]+1)/2] == 1){
                mem[i]++;
            }
            vecpos++;
        }
        else    mem[i] = mem[i-1];
    }
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> l >> r;
        cout << mem[r] - mem[l-1] << '\n';
    }
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define FOR(i,k,n) for((i)=(k);(i)<(n);(i)++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define pb push_back
//#define all(a) (a).begin(),(a).end()
using namespace std;

int main(){
   string line;

   getline(cin,line);
   while (line.find(",") != string::npos) {
      line.replace(line.find(","), 1, " ");
   }
   cout<<line<<endl;

   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
signed main(){
  ll n;
  cin >> n;
  double p[n];
  vector<vector<double>> dp(3000,vector<double>(3000,0));
  double ans=0;
  for(int i=0;i<n;i++){
    cin >> p[i];
  }
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<=n;j++){
      if(j==0){
        dp[i+1][j]=dp[i][j]*(1-p[i]);
      }else{
        dp[i+1][j]=dp[i][j]*(1-p[i])+dp[i][j-1]*p[i];
      }
    }
  }
  for(int i=n/2+1;i<=n;i++){
    ans += dp[n][i];
  }
  printf("%.10lf\n",ans);
}


Measured memory_bytes: 70784
L, R = map(int, input().split())
if L == 0 or R - (L-1) >= 2019 or L%2019==0 or R%2019==0:
  print(0)
  exit()

ans = 2019
for i in range(L,R):
  for j in range(i+1,R+1):
    mod = (i*j)%2019
    if ans > mod:
      ans = mod
    if ans == 0:
      print(ans)
      exit()
print(ans)

Measured memory_bytes: 3060
# https://atcoder.jp/contests/agc002/tasks/agc002_b
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


N, M = read_ints()
X, Y = read_col(M)
X = mina(*X)
Y = mina(*Y)
# 有向グラフでつないで1からbfsで到達するノードの数を記録する？#順序情報が消えてしまう
# ただ単純に赤の可能性のある配列を用意しておけばいいんじゃない？
# ボールの個数も管理しないと
prob = [False] * N
n_balls = [1] * N
prob[0] = True

for x, y in zip(X, Y):
    prob[y] = prob[y] or prob[x]
    n_balls[x] -= 1
    n_balls[y] += 1
    if n_balls[x] == 0:
        prob[x] = False


print(sum(prob))


Measured memory_bytes: 115300
k=gets.chars
a=k[0].to_i
b=k[1].to_i
c=k[2].to_i
d=k[3].to_i
if a+b+c+d==7
  print(a,"+",b,"+",c,"+",d)
elsif a+b+c-d==7
  print(a,"+",b,"+",c,"-",d)
elsif a+b-c+d==7
  print(a,"+",b,"-",c,"+",d)
elsif a+b-c-d==7
  print(a,"+",b,"-",c,"-",d)
elsif a-b+c+d==7
  print(a,"-",b,"+",c,"+",d)
elsif a-b+c-d==7
  print(a,"-",b,"+",c,"-",d)
elsif a-b-c+d==7
  print(a,"-",b,"-",c,"+",d)
else
  print(a,"-",b,"-",c,"-",d)
end
print("=7")

Measured memory_bytes: 1788
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    ll n; cin >> n;

    for(ll h=1; h<=3500 ; h++){
        for(ll w=1; w<=3500; w++){
            ll c = n * h * w;
            ll d = 4*h*w - n*w - n*h;
            if(d <= 0) continue;
            if(c%d==0){
                cout << h << " " << w << " " << c/d << endl;
                return 0;
            }
        }
    }
    return 0;}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc054/tasks/abc054_c

int path[100][100];

int main() {
    int N, M; cin >> N >> M;
    REP(i, M) {
        int a, b; cin >> a >> b;
        path[a][b] = 1;
        path[b][a] = 1;
    }

    vector<int> perm(N-1);
    REP(i, N-1) perm[i] = i+2;
    sort(perm.begin(), perm.end());

    int cnt = 0;
    do {
        int now = 1;
        for (int i = 0; i < perm.size(); i++) {
            if (!path[now][perm[i]]) break;
            now = perm[i];
            if (i == perm.size()-1) cnt++;
        }
    } while(next_permutation(perm.begin(), perm.end()));

    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math

def position(l, d):
    x = l * math.sin(math.radians(d))
    y = l * math.cos(math.radians(d))
    return x, y

def solve(A: int, B: int, H: int, M: int):
    hour_deg = ((H*60+M)/720)*360
    min_deg = (M/60)*360

    hour_x, hour_y = position(A, hour_deg)
    min_x, min_y = position(B, min_deg)

    ans = math.sqrt((hour_x-min_x)**2+(hour_y-min_y)**2)

    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(A, B, H, M)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;

const ll N = 1e6+1;
const ll inf = 0x7fffffff;
ll s1,s2,t1,t2,arr[N],ans[N],len,n;
struct nd{ll x,y;}a[N];
bool cmp(nd a,nd b){return a.x<b.x;}
ll abs1(ll a){return a>0?a:-a;}
ll binary_search(ll i)
{
    ll left,right,mid;
    left=0,right=len;
    while(left<right)
	{
        mid = left+(right-left)/2;
        if(ans[mid]>=arr[i])right=mid;
        else left=mid+1;
    }
    return left;
}

int main()
{
	cin>>s1>>s2>>t1>>t2;
	if(s1>=t1)swap(s1,t1),swap(s2,t2);
	cin>>n;
	for(ll i=1,x,y;i<=n;++i)
	{
		cin>>x>>y;
		if(x>=s1&&x<=t1&&y>=min(s2,t2)&&y<=max(s2,t2))
		++arr[0],a[arr[0]].x=x,a[arr[0]].y=y;
	}
	n=arr[0];arr[0]=0;
	if(t2<s2)for(int i=1;i<=n;++i)a[i].y*=-1;
	sort(a+1,a+n+1,cmp);
	for(ll i=1;i<=n;++i)arr[++arr[0]]=a[i].y;
	if(!arr[0])printf("%.16Lf",((db)t1-s1+abs1(s2-t2))*(db)100);
	else
	{
		if(t2<s2)memset(ans,-0x3f,sizeof(ans));
		ans[1]=arr[1];
	    len=1;
	    for(ll i=2;i<=n;++i)
		{
	        if(arr[i]>ans[len])ans[++len]=arr[i];
	        else
			{
	            ll pos=binary_search(i);
	            ans[pos]=arr[i];
	    	}
	    }
	    db k=acos(-1)*(db)5;
		db rk=20;
		db ans=(t1-s1+abs1(s2-t2))*100ll;
	    if(len==abs1(s1-t1)+1||len==abs1(s2-t2)+1)
	    {
	    	ans+=(db)len*(k-rk);
	    	ans+=k;
	    	printf("%.16Lf",ans);
	    }
	    else
	    {
	    	ans+=(db)len*(k-rk);
	    	printf("%.16Lf",ans);
		}
	}
}
/*
1 6 6 2
3
3 2
5 3
2 4
*/

Measured memory_bytes: 16640
#include <iostream>
#include <algorithm>
#define MAX 2000
#define INF 999999

using namespace std;

int COST[MAX + 1][MAX + 1];
int TIME[MAX + 1][MAX + 1];
int v[MAX + 1];
bool visit[MAX + 1];
int n,m,k,p,q,r,ti,co;
int from,too;
int MI,mi;

int get_time(void){ // ダイクストラ法

  for( int i = 0 ; i <= MAX ; i++ ){ // 初期化
    visit[i] = false;
    v[i] = INF;
  }


  v[p] = 0; // 最初の位置を0にする

  while(1){

    mi = INF;

    for( int i = 1 ; i <= m ; i++ ){ // 訪れていない最小時間とその添字を求める
      if( !visit[i] && v[i] < mi ){
	MI = i;
	mi = v[i];
      }
    }

    if( mi == INF ) break;
    visit[MI] = true; // 訪れたことにする

    for( int i = 1 ; i <= m ; i++ ){
      if( TIME[MI][i] + v[MI] < v[i] ){
	v[i] = TIME[MI][i] + v[MI];
      }
    }
  }
  return v[q];
}

int get_cost(void){

  for( int i = 0 ; i <= MAX ; i++ ){
    v[i] = INF;
    visit[i] = false;
  }

  v[p] = 0; 

  while(1){

    mi = INF;

    for( int i = 1 ; i <= m ; i++ ){
      if( !visit[i] && v[i] < mi ){
	MI = i;
	mi = v[i];
      }
    }

    if( mi == INF ) break;
    visit[MI] = true;

    for( int i = 1 ; i <= m ; i++ ){
      if( COST[MI][i] + v[MI] < v[i] ){
	v[i] = COST[MI][i] + v[MI];
      }
    }
  }
  return v[q];
}



int main(void){

  while( cin >> n >> m , n || m ){

    for( int i = 0 ; i <= MAX ; i++ ){
      for( int j = 0 ; j <= MAX ; j++ ){ // 初期化
	TIME[i][j] = INF;
	COST[i][j] = INF;
      }
    }

    for( int i = 0 ; i < n ; i++ ){
      cin >> from >> too >> co >> ti;
      COST[from][too] = COST[too][from] = co;
      TIME[from][too] = TIME[too][from] = ti;
    }

    cin >> k; // 問い合わせの数

    for( int i = 0 ; i < k ; i++ ){
      cin >> p >> q >> r;

      switch(r){
      case 0: // 最小金額
	cout << get_cost() << endl;
	break;
      case 1: // 最小時間
	cout << get_time() << endl;
      }

    }

  }
  return 0;
}

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

c = input()
c = c[:len(c)-1]
q = int(input())

num = len(c)
c_mae = ''
c_ato = ''

hantei = 1

for i in range(q):
    q_i= list(input())
    #print(q_i)
    if q_i[0] == '1':
        hantei *= -1
    elif (q_i[2] =='1' and hantei == 1) or (q_i[2] == '2' and hantei == -1):
        c_mae = q_i[4] + c_mae
    else:
        c_ato += q_i[4]

print(c_mae+c+c_ato if hantei == 1 else (c_mae+c+c_ato)[::-1])


Measured memory_bytes: 9844
/*
	ID: sixathofpain
	TASK: friday
	LANG: C++   

*/


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

// int bet(int x,int y,int p){

// 	if(x<=p and p<=y)


// }

int32_t main(){
    IOS;
	
    // freopen("friday.in","r",stdin);
    // freopen("friday.out","w",stdout);

    int n,x,y;
    cin>>n>>x>>y;

    if(x>y)
    	swap(x,y);

    int ans[n]={};

    for(int i=1;i<n;i++){
    	for(int j=i+1;j<=n;j++){
    		int t = j-i;
    		t = min(t,abs(x-i)+1+abs(y-j));
    		t = min(t,abs(y-i)+1+abs(x-j));
    		ans[t]++;
    	}
    }

    for(int i=1;i<=n-1;i++)
    	cout<<ans[i]<<endl;
    // cout<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <map>
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	int w, s, anss, ans;
	double r=0,ar=-1;

	for (int i = 0; 100 * a*i+1 <= f; i++) {
		for (int j = 0; 100 * a*i +100*b*j+1<= f; j++) {
			for (int z = 0; 100 * a*i + 100 * b*j + c * z +1<= f; z++) {
				if (i == 0 && j == 0)break;
				for (int l = 0; 100 * a*i + 100 * b*j + c * z + d * l <= f&&i+j+z+l!=0; l++) {
					s = c * z + d * l;
					w = 100 * a*i + 100 * b*j;
					r = (double)s / (double)(w + s);
					if (r<=e/(double)(100+e)) {
						if (r > ar) {
							ar = r;
							anss = s;
							ans = s + w;
						}

					}
				}
			}
		}
	}

	
	cout << ans << " " << anss << endl;

}


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

#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define endl '\n'
#define mod 1000000007
#define INF64 1e18

void solve(){
  int n ;cin>>n;
  vi h(n),a(n);
  for(int i=0;i<n;i++)
    cin>>h[i];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int ans=0;
  map<int,int> dp;
  dp.insert({0,0});
  for(int i=0;i<n;i++){
    auto it=dp.lb(h[i]);
    it--;
    int x=it->se+a[i];
    it++;
    vi b;
    while(it!=dp.end()&&x>=it->se){
      b.pb(it->fi);
      it++;
    }
    for(int j:b)
      dp.erase(j);
    dp.insert({h[i],x});
    ans=max(ans,x);
  }
  cout<<ans;
}

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int T=1;
  //cin>>T;
  for(int TT=1;TT<=T;TT++){
    solve();
  }
}

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

int main() {
  int N, D, X;
  cin >> N >> D >> X;
  
  int A;
  int ans = 0;
  int nissu = 0;
  for( int i = 0; i < N; i++ ){
    nissu = 1;
    cin >> A;
    while( true ){
      ans++;
      nissu += A;
      if( nissu > D ) break;
    }
  }
  cout << ans + X << endl;
      
}


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

const int MAXH = 1000000;
int L, H;
string s[MAXH];
int h[MAXH], b[MAXH], o[MAXH];
int bit[MAXH];
string t;
string ans;

void rec(int k, int used) {
  if(k == L) {
    for(int j = 0; j < H; ++j) {
      if(h[j]|b[j]|o[j]) return;
    }
    if(ans != "") throw 0;
    ans = t;
    return;
  }
  for(int i = 0; i < 10; ++i) {
    if((used >> i) & 1) continue;
    char c = i + '0';
    bool flag = true;
    for(int j = 0; j < H; ++j) {
      if(s[j][k] == c) {
        h[j] -= 1;
      } else if((bit[j] >> i) & 1) {
        b[j] -= 1;
      } else {
        o[j] -= 1;
      }
      if(h[j] < 0 || b[j] < 0 || o[j] < 0) {
        flag = false;
      }
    }
    if(flag) {
      t[k] = c;
      rec(k+1, used|(1<<i));
    }
    for(int j = 0; j < H; ++j) {
      if(s[j][k] == c) {
        h[j] += 1;
      } else if((bit[j] >> i) & 1) {
        b[j] += 1;
      } else {
        o[j] += 1;
      }
    }
  }
}

int main() {
  while(cin >> L >> H && (L|H)) {
    for(int i = 0; i < H; ++i) {
      cin >> s[i] >> h[i] >> b[i];
      o[i] = L - h[i] - b[i];
      bit[i] = 0;
      for(int j = 0; j < s[i].size(); ++j) {
        bit[i] |= 1<<(s[i][j]-'0');
      }
    }
    t.resize(L);
    try {
      ans = "";
      rec(0,0);
      if(ans == "") {
        cout << "NO" << endl;
      } else {
        cout << ans << endl;
      }
    } catch(...) {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 16532
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    string s;
    cin >> s;

    string ss[] = {"eraser", "erase", "dreamer", "dream"};
    while ( s.length() != 0 ) {
        bool flag = false;
        REP(i, 4) {
            int pos = s.rfind(ss[i]);
            if ( pos != string::npos && pos == s.length() - ss[i].length() ) {
                flag = true;
                s.erase(pos, ss[i].length());
            }
        }
        if ( !flag ) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define INF (1e18)

struct UnionFind {
private:
    ll N;
    vector<ll> parent;
    vector<ll> num;

public:
    UnionFind(ll n){
        N = n;
        rep(i,0,N) parent.push_back(i);
        rep(i,0,N) num.push_back(1);
    }

    ll root(ll x){
        if(x == parent[x]) return x;
        else return parent[x] = root(parent[x]);
    }

    void unite(ll a, ll b){
        a = root(a); b = root(b);
        if(a == b) return;
        parent[a] = b;
        ll sum = num[a] + num[b];
        num[a] = sum;
        num[b] = sum;
    }

    bool same(ll a, ll b){
        return root(a) == root(b);
    }

    ll sz(ll x){
        return num[x];
    }
};
int main(){   
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    ll A[100010], B[100010];
    rep(i,0,M){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }
    UnionFind uf(100010);
    ll v = N*(N-1)/2;
    vector<ll> ans;
    ans.push_back(v);
    rrep(i,M-1,0){
        if(uf.same(A[i], B[i])){
            ans.push_back(v);
        }else{
            v -= uf.sz(uf.root(A[i])) * uf.sz(uf.root(B[i]));
            uf.unite(A[i], B[i]);
            ans.push_back(v);
        }
    }
    rrep(i,M-1,0){
        print(ans[i]);
    }
}


Measured memory_bytes: 5364
#include <iostream>

using namespace std;

int main(){
  int n;
  cin>>n;
  n = n % 10;
  if (n==3) {
    cout<<"bon"<<endl;
  } else if (n==0 || n==1 || n==6 || n==8) {
    cout<<"pon"<<endl;
  } else {
    cout<<"hon"<<endl;
  }
  return 0;
}

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

int main(){
    string abcd;
    cin >> abcd;

    int s[4];

    rep(i,4) s[i] = abcd[i] - '0';

    for (int bit = 0; bit < (1 << 3); ++bit){
        int sum = 0;
        sum += (int)s[0];
        char c[4];
        for (int i = 0; i < 3; ++i){
            if (bit & (1<<i)){
                sum += (int)s[i+1];
                c[i] = '+';
            }
            if (!(bit & (1<<i))){
                sum -= (int)s[i+1];
                c[i] = '-';
            }
        }
        if (sum == 7) {
            cout << s[0] << c[0] << s[1] << c[1] << s[2] << c[2] << s[3] << "=7" << endl;
            return 0;
        }

    }
    cout << "err" << endl;

    return 0;
    
}

Measured memory_bytes: 256
n, *a = map(int, open(0).read().split())
cnt = 0
a = [0] + a
i = 1
while 1:
    tmp = i
    i = a[i]
    cnt += 1
    if tmp == i:
        print(-1)
        break
    elif i == 2:
        print(cnt)
        break
    elif cnt > n:
        print(-1)
        break

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

using namespace std;
typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	string s; cin >> s;
  	if (s[(int)(s.size()) - 1] == 's') {
      	cout << s + "es" << endl;
    }
  	else {
      	cout << s + "s" << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
#define R register

int n;
char w[111][111];
bool ans;
bool sam(R int pos1,R int pos2)
{
	if(strlen(w[pos1]+1) != strlen(w[pos2]+1)) return 0;
	for (R int i=1;i<=strlen(w[pos1]+1); ++i) if(w[pos1][i] != w[pos2][i]) return 0;
	return 1;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",w[1]+1);
	for (R int i=2;i<=n;++i)
	{
		scanf("%s",w[i]+1);
		for (R int j=1;j<i;++j) ans |= sam(i,j);
		ans |= (w[i][1] != w[i-1][strlen(w[i-1]+1)]);
	}
	ans ? puts("No") : puts("Yes");
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;

	vector<int> arr(n);

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

	int sum = 0;
	for (int i = 0; i < n - 1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			sum += arr[i] * arr[j];
		}
	}

	cout << sum << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC054_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ab = Console.ReadLine().Split(' ');
            int a = int.Parse(ab[0]);
            int b = int.Parse(ab[1]);

            if(a != 1 && b != 1)
            {
                if(a > b)
                {
                    Console.WriteLine("Alice");
                }
                else if(a < b)
                {
                    Console.WriteLine("Bob");
                }
                else
                {
                    Console.WriteLine("Draw");
                }
            }
            else
            {
                if(a == b)
                {
                    Console.WriteLine("Draw");
                }
                else if(a == 1)
                {
                    Console.WriteLine("Alice");
                }
                else
                {
                    Console.WriteLine("Bob");
                }
            }
            Console.Read();
        }
    }
}


Measured memory_bytes: 11092
n, m = map(int, input().split())
edges = []
forward_edges = [[] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges.append((a, b, -c))
    forward_edges[a].append(b)

stack = [0]
can_reach = [0]*n
while stack:
    v = stack.pop()
    if can_reach[v]:
        continue
    can_reach[v] = 1
    for v2 in forward_edges[v]:
        if can_reach[v2]:
            continue
        stack.append(v2)

INF = 10**18
dist = [INF]*n
dist[0] = 0
for i in range(n):
    for v, v2, c in edges:
        if dist[v2] <= dist[v]+c:
            continue
        dist[v2] = dist[v]+c

negative = [0]*n
for i in range(n*2):
    for v, v2, c in edges:
        if dist[v2] <= dist[v]+c:
            continue
        if not can_reach[v2]:
            continue
        dist[v2] = -INF
        negative[v2] = 1

if negative[-1]:
    print('inf')
else:
    print(-dist[-1])


Measured memory_bytes: 46316