akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<tuple>
#include<vector>
#include<algorithm>
using namespace std;
int T,N,M,Q,A,B,C,D;
int b[999],c[999][999],d[999][999];
int main(){
	while(true){
		for(int i=0;i<999;i++){
			for(int j=0;j<999;j++){
				b[i]=0;
				c[i][j]=-1;
				d[i][j]=0;
			}
		}
		cin>>T>>N>>M>>Q;
		if(T==0){break;}
		for(int i=0;i<Q;i++){
			cin>>A>>B>>C>>D;
			if(c[B][C]==-1){
				if(D==0){
					c[B][C]=A;
					b[B]++;
				}
				else{
					d[B][C]+=20;
				}
			}
		}
		vector<tuple<int,int,int>>vec;
		for(int i=1;i<=N;i++){
			int sum=0;
			for(int j=1;j<=M;j++){
				if(c[i][j]>=0){
					sum+=c[i][j]+d[i][j];
				}
			}
			vec.push_back(make_tuple(b[i],-sum,i));
		}
		sort(vec.begin(),vec.end());
		cout<<get<2>(vec[vec.size()-1]);
		for(int i=(int)(vec.size())-2;i>=0;i--){
			if(get<0>(vec[i])==get<0>(vec[i+1]) && get<1>(vec[i])==get<1>(vec[i+1])){
				cout<<"=";
			}
			else{cout<<',';}
			cout<<get<2>(vec[i]);
		}
		cout<<endl;
	}
}

Measured memory_bytes: 10856
#include <cstdio>
 
 
using namespace std;
int lis[100000];
int tim[100000];
int main() {
    int n,r,l;
    scanf("%d %d %d",&n,&r,&l);
 
    int top = 0;
    int id  = 1;
    int nowtime = 0;
    int timemax = 0;
    int timemaxid = 0;
    for(int i = 0; i < r; i++) {
        
        int d,t,x;
        scanf("%d %d %d",&d,&t,&x);
        tim[id] += t - nowtime;
        if(tim[id] > timemax) {
            timemax = tim[id];
            timemaxid = id;
        }
        nowtime = t;
        lis[d] += x;
        if(id == d) {
            top += x;
        }
        if(x < 0 && d == id) {
            for(int j = 1; j < n+1; j++) {
                if(top < lis[j] || (top == lis[j] && j < id)) {
                    top = lis[j];
                    id = j;
                }
            }
             
        }
        if(x > 0 && d != id) {
            if(top < lis[d] || (top == lis[d] && d < id)) {
                top = lis[d];
                id = d;
            }
        }
 
    }
    tim[id] += l - nowtime;
    if(tim[id] > timemax) {
        timemax = tim[id];
        timemaxid = id;
    }
    printf("%d\n",timemaxid);
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+7;
typedef long long ll;
int n, m, k;

char ch[maxn];
multiset<char> ms;
multiset<char>::iterator it;
void dfs(int x, char c){
    ch[x] = c;
    ms.insert(c);
    if(x == n - 1){
        ch[n] = '\0';
        printf("%s\n", ch);
        ms.erase(ms.find(c));
        return ;
    }
    it = ms.end();
    it--;
    char mid_c = *it;
    //cout << "mid_c : " << mid_c << "\n";
    for(char next = 'a'; next <= 'z' && next <= mid_c + 1; next += 1){
        dfs(x + 1, next);
    }
    ms.erase(ms.find(c));
}
int main()
{
    scanf("%d", &n);
    dfs(0, 'a');

    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define mp make_pair
#define ff first
#define pi pair<ll,ll>
#define ss second
#define ll long long
#define MAXN 1000005
using namespace std;
using namespace __gnu_pbds;  

ll n,cnt=1;

void solve()
{
	cin>>n;
	for(ll i=2;i*i<=n;i++)
	{
		ll p=n;
		if(p%i==0)
		{
			while(p%i==0)
			{
				p/=i;
			}
			if(p%i==1) cnt++;
		}
	}
	n--;
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0) 
		{
			if(i==n/i) cnt++;
			else cnt+=2;
		}
	}
	if(n>1) cnt++;
	cout<<cnt<<endl;
}

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


Measured memory_bytes: 256
#include<stdio.h>

int gcd(int a, int b){
    int tmp = a%b;
    if(tmp==0) return b;
    
    a=b;
    b=tmp;
    
    return gcd(a, b);
}

int main(void){
    int A, B;
    long ans;
    
    scanf("%d %d", &A, &B);
    
    ans = gcd(A, B);
    
    printf("%ld", (A/ans)*B);
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), b = sc.nextInt(),c=sc.nextInt(),k=sc.nextInt();
		int sum=0,count=1,flag=0,max=-999999,min=99999;
		int[] array=new int[10000];
		//String[] array = new String[n];
		//String s=sc.next();//,t=sc.next();
		array[0]=n;
		array[1]=b;
		array[2]=c;
		Arrays.sort(array);
		array[9999]=(int) (Math.pow(2, k)*array[9999]);
		for(int i=9999;i>=0;i--) {
			sum+=array[i];
		}
		System.out.println(sum);
	}
	public static int sample(int n) {
		return n;
	}

}


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

class bitree {
	vector<int> m_tree;

public:
	bitree( int n ):
		m_tree( n+1 )
	{
		m_tree.at( 0 ) = n;
	}

	void add( int i, int x ) {
		while( i <= m_tree.at( 0 ) ) {
			m_tree.at( i ) += x;
			i += i & -i;
		}
	}

	int sum( int i ) const {
		int s = 0;

		while( i > 0 ) {
			s += m_tree.at( i );
			i -= i & -i;
		}

		return s;
	}
};

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;

	vector<int> a( n );
	map<int, int> m;

	for( int i = 0; i < n; ++i ) {
		cin >> a.at( i );
		m[a.at( i )] = 0;
	}

	int x = 1;
	for( auto& p: m ) {
		p.second = x++;
	}

	for( int i = 0; i < n; ++i ) {
		a.at( i ) = m[a.at( i )];
	}

	bitree bit( n );
	int64_t result = 0;

	for( int i = 0; i < n; ++i ) {
		result += i - bit.sum( a.at( i ) );
		bit.add( a.at( i ), 1 );
	}

	cout << result << endl;
}



Measured memory_bytes: 13876
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#include<utility>
#define ll long long
#define mod 1000000000+7
#define rep(i,n) for(int i=0;i<(int) (n);i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
using namespace std;
int main() {
  int n,l;
  cin>>n>>l;
  vector<string>s(n);
  rep(i,n)cin>>s[i];
  sort(s.begin(),s.end());
  rep(i,n)cout<<s[i];
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = Integer.parseInt(s.next());
        int k = Integer.parseInt(s.next());

        boolean[] flag = new boolean[n];
        Arrays.fill(flag, false);

        for (int i = 0; i < k; i++) {

            int d = Integer.parseInt(s.next());
            for (int j = 0; j < d; j++) {
                int dn = Integer.parseInt(s.next());
                flag[dn - 1] = true;
            }
        }

        int count = 0;

        for (int i = 0; i < n; i++) {
            if (!flag[i])
                count++;
        }

        System.out.println(count);
    }
}

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

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var n = input[0];
        var k = input[1];
        var trees = new int[n];
        for (int i = 0; i < n; i++)
        {
            trees[i] = int.Parse(Console.ReadLine());
        }

        Array.Sort(trees);

        var min = int.MaxValue;
        for (int i = 0; i < n - k + 1; i++)
        {
            var val = trees[i + k - 1] - trees[i];
            min = Math.Min(min, val);
        }

        Console.WriteLine(min);
    }
}

Measured memory_bytes: 15584
import java.util.Scanner;

class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    String A = sc.next();
    String B = sc.next();
    String C = sc.next();

    char mae,usiro;


    if (A.substring(A.length() -1).equals(B.substring(0, 1)) && B.substring(B.length() -1).equals(C.substring(0, 1))){
    System.out.println("YES");
    }
    else {
      System.out.println("NO");
    }
  }
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
	int k, n;
	string s;
	cin >> k >> s;
	n = s.size();
	combination c(n+k);
	mint ans = 0;
	for (int i=0;i<=k;i++) {
		mint now = mint(26).pow(k-i);
		now *= mint(25).pow(i);
		now *= c(i+n-1,n-1);
		ans += now;
	}
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 35568
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
long power(long x,long p){
  if(p==0)return 1;
  if(p%2)return x*power(x,p-1)%M;
  long a=power(x,p/2);return a*a%M;
}
int main(){
  long N;cin>>N;
  vector<long>inv(N+1);
  for(int i=1;i<=N;i++){inv[i]=power(i,M-2);}
  
  vector<long>X(N),C(N-1);for(int i=0;i<N;i++)cin>>X[i];
  for(int i=0;i<N-1;i++)C[i]=X[i+1]-X[i];
  long P=1;
  for(int i=1;i<=N-1;i++)P=(P*i)%M;
  long ans=0;
  vector<long>T(N);T[0]=P;
  for(int i=1;i<N-1;i++)T[i]=(T[i-1]+(P*inv[i+1])%M)%M;
  for(int j=0;j<N-1;j++){
    long tmp=T[j]%M;
    ans=(ans+(tmp*C[j])%M)%M;
    assert(P>=0);assert(tmp>=0);assert(ans>=0);
  }
  cout<<ans%M<<endl;
  
}




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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    int N = S.size();
    int M = T.size();
    vector<string> ans;
    for(int i=0; i<=N-M; i++){
        bool flag = true;
        for(int j=0; j<M; j++){
            if(S[i+j] != '?' && S[i+j] != T[j]){
                flag = false;
                break;
            }
        }
        if(flag){
            string SS = S;
            for(int j=0; j<M; j++)
                SS[i+j] = T[j];
            for(int j=0; j<N; j++)
                if(SS[j] == '?') SS[j] = 'a';
            ans.push_back(SS);
        }
    }
    if(ans.empty()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    sort(ans.begin(), ans.end());
    cout << ans.front() << endl;
    return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main(){
int n;
cin>>n;
ll x;
cin>>x;
ll a[n];
rep(i,n){
    cin>>a[i];
}
sort(a,a+n);
int ans=0;
rep(i,n-1){
    if(x>=a[i]){
        x-=a[i];
        ans++;
    }
}
if(x==a[n-1]){
    ans++;
}
cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    s=input()
    a=""
    for i in range(len(s)):
        a=a+"x"
    print(a)


if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(n);
    string s;
    cin>>s;
    int black=0,white=0;
    vector<int> b(n),w(n);
    rep(i,n){
        black+=(s[i]=='#');
        white+=(s[i]=='.');
        b[i]=black;
        w[i]=white;
    }
    int ans=min(white,black);
    rep(i,n){
        ans=min(ans,b[i]+white-w[i]);
    }
    out(ans);
}

Measured memory_bytes: 5260
using System;

public class hello
{
    public static void Main()
    {
        var L = 0;
        var r = 0;
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Trim();
            var p = s[0];
            var x = int.Parse(s.Substring(1));
            if (p == '(') L += x;
            else r += x;
            L -= r;
            r = 0;
            if (L < 0) { Console.WriteLine("NO"); goto exit; }
        }
        Console.WriteLine(r == L? "YES":"NO");
        exit:;
    }
}



Measured memory_bytes: 17944
n = int(input())
s = input()
ans = 0
for i in range(1000):
    seq = "{:03d}".format(i)
    cnt = 0
    for j in s:
        if seq[cnt] == j:
            cnt += 1
            if cnt == 3:
                break
    if cnt == 3:
        ans += 1
print(ans)

Measured memory_bytes: 41052
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
long long int count;
long long int at(long long int he);
int main()
{
	long long int he;
	cin>>he;
	cout<<at(he)<<endl;
	return 0;
}
long long int at(long long int he)
{
	if(he==1)
		return 1;
	return at(he/2)*2+1;
}


Measured memory_bytes: 256
import collections

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

value, count = list(a.keys()), list(a.values())

if len(value)<3:
    if len(value)==1:
        if sum(a)==0:
            print('Yes')
        else:
            print('No')

    if len(value)==2:
        if 0 in value:
            if count[0]==N/3 or count[1]==N/3:
                print('Yes')
            else:
                print('No')

        else:
            print('No')

if len(value)>=3:
    if count[0]+count[1]+count[2] == N:
        if value[0]^value[1]^value[2] == 0:
            if count[0]==count[1]==count[2]:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')


Measured memory_bytes: 14468
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<stack>
#define ll long long
#define inf 20021225
#define N 300010
#define ls x<<1
#define rs x<<1|1
#define mid (l+r>>1)
#define pa pair<int,int>
#define fs first
#define se second
#define mp make_pair
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
int tag[N<<2],mx[N<<2];
void puttag(int x,int t){tag[x]+=t,mx[x]+=t;}
void pushdown(int x)
{
	if(!tag[x])	return;
	puttag(ls,tag[x]),puttag(rs,tag[x]),tag[x]=0;
}
void pushup(int x){mx[x]=max(mx[ls],mx[rs]);}
void modify(int x,int l,int r,int LL,int RR,int t)
{
	if(l>=LL&&r<=RR)	return void(puttag(x,t)); pushdown(x);
	if(LL<=mid)	modify(ls,l,mid,LL,RR,t);
	if(RR>mid)	modify(rs,mid+1,r,LL,RR,t);
	pushup(x);
}
int query(int x,int l,int r,int LL,int RR)
{
	if(LL<=l&&RR>=r)	return mx[x]; pushdown(x); int ans=0;
	if(LL<=mid)	ans=max(ans,query(ls,l,mid,LL,RR));
	if(RR>mid)	ans=max(ans,query(rs,mid+1,r,LL,RR));
	return ans;
}
struct poi{int x,y;}s[N];
bool operator<(poi a,poi b){return a.x==b.x?a.y<b.y:a.x<b.x;}
int n,w,h,ans; stack<pa> L,R;
void solve()
{
	sort(s+1,s+n+1); while(!L.empty()) L.pop(); while(!R.empty()) R.pop();
	memset(tag,0,sizeof(tag)),memset(mx,0,sizeof(mx));
	for(int i=1;i<=n;i++)
	{
		if(s[i].y<=h/2)
		{
			int nxt=i-1;
			while(!L.empty()&&L.top().se<=s[i].y)
				modify(1,1,n,L.top().fs,nxt,L.top().se-s[i].y),
				nxt=L.top().fs-1,L.pop();
			if(nxt!=i-1)	L.push(mp(nxt+1,s[i].y));
		}
		else
		{
			int nxt=i-1;
			while(!R.empty()&&R.top().se>=s[i].y)
				modify(1,1,n,R.top().fs,nxt,s[i].y-R.top().se),
				nxt=R.top().fs-1,R.pop();
			if(nxt!=i-1)	R.push(mp(nxt+1,s[i].y));
		}
		
		L.push(mp(i,0)); R.push(mp(i,h));
		modify(1,1,n,i,i,h-s[i].x);
		ans=max(ans,s[i+1].x+mx[1]);
	}
}
void init()
{
	w=read(),h=read(),n=read();
	for(int i=1;i<=n;i++)	s[i].x=read(),s[i].y=read();
	s[++n]=poi{0,0}; s[++n]=poi{w,h};
}
void work()
{
	solve();
	for(int i=1;i<=n;i++)	swap(s[i].x,s[i].y); swap(w,h);
	solve(); printf("%d\n",ans*2);
}
int main()
{
	init(); work();
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  string s, t;
  cin >> s >> t;
  int ans = 0;
  rep(i,3) ans += (s[i] == t[i]);
  cout << ans << endl;
}

Measured memory_bytes: 256
"""
方針：

幸福度が一定以上のつなぎ方の数→NlogNで二分探索可能
採用するうち最小の幸福度を NlogNlogNで探索

累積和を用いて合計を算出

2 3
5 2

10 + 7 + 7 = 24

"""

import bisect

def wantover(n): #n以上の幸福度のつなぎ方の数がM以上ならTrueを返す

    ret = 0

    for i in range(N):

        serchnum = n - A[i]

        ret += (N - bisect.bisect_left(A,serchnum))

    #print ("over",n,"is",ret)

    if ret >= M:
        return True
    else:
        return False


N,M = map(int,input().split())

A = list(map(int,input().split()))
A.sort()

#print (wantover(7))

hpl = 0
hpr = A[-1] * 2 + 1

while hpr - hpl != 1:

    mid = (hpr + hpl) // 2

    if wantover(mid):

        hpl = mid

    else:

        hpr = mid

#ここで最小の幸福度はhpl
#print (hpl,hpr)

B = [0] #累積和行列

for i in range(N):

    B.append(B[-1] + A[-1 - i])

#print (A)
#print (B)

ans = 0
plnum = 0 #つないだ手の回数
for i in range(N):

    i = N-i-1

    ind = bisect.bisect_left(A,hpl - A[i])

    #print (hpl,A[i],N-ind)
    
    plnum += N - ind
    
    ans += B[N - ind] + A[i] * (N-ind)

#print (ans,plnum)
print (ans - hpl * (plnum - M))
        


Measured memory_bytes: 60044
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  rep(i,h){
    string s;
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 5e5+7;
int n;
int a[N],h[N],pos[N];
bool cmp(int i,int j) {
    return a[i] < a[j];
}
void nhap()
{
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        h[i] = i;
    }
    sort(h + 1,h + 1 + n,cmp);
    for (int i = 1; i <= n; i++) {
        pos[h[i]] = i;
    }
}
void solve()
{
    int mid = n >> 1;
//    for (int i = 1; i <= n; i++) {cout << h[i] << " ";}
//    cout << '\n';
    for (int i = 1; i <= n; i++) {
        if (pos[i] <= mid) {
            cout << a[h[mid + 1]] << '\n';
        }
        else {
            cout << a[h[mid]] << '\n';
        }
    }
}
int main()
{
    nhap();
    solve();
}


Measured memory_bytes: 5760
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		if ((r * 100 + g * 10 + b) % 4 == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 22604
using System; 
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq; 
using E = System.Linq.Enumerable; 


class Program {
    static void Main(string[] args) {
        
        var NM = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var N = NM[0];
        var M = NM[1];
        
        var isl = new int[N+1];
        
        for(int i = 0;i < N+1 ;i++){
            isl[i] = N+1;
        }
       // 
        for(int i = 0;i < M ;i++){
            var AB = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var A = AB[0];
            var B = AB[1];
            if(isl[A] > B){
                isl[A] = B;
            }
        }
        //Console.WriteLine(22);
        var tmp = N+1;
        var ans = 0;
        for(int i = N;i > 0 ;i--){
            if(isl[i] < tmp){
                tmp = i+1;
                ans++;
            }
        }
        
        Console.WriteLine(ans);
     }
     
}
     
     
                   
public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) { } public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) { } public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); }


Measured memory_bytes: 17620
#include <bits/stdc++.h>
using namespace std;
int main(){
	int r;
	
	cin>>r;
	if(r < 1200){
		cout<<"ABC"<<endl;
	}
	else if(r < 2800){
		cout<<"ARC"<<endl;
	}
	else{
		cout<<"AGC"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    int a,b,i,ans=0;
    scanf("%d%d",&a,&b);
    if(b==1)
    i=0;
    else
    for(i=0;ans<b;++i)
    ans=a+a*i-i;
    printf("%d",i);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans=0,n;
    cin >>n;
    ll a[n];
    ll m=MAX;
    ll k=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(m>abs(a[i])){
            k=i;
            m=abs(a[i]);
        }
    }
    for(int i=0;i<k;i++){
        ans+=abs(a[i]);
        if(a[i]<0)a[i+1]*=-1;
    }
    for(int i=n-1;i>k;i--){
        ans+=abs(a[i]);
        if(a[i]<0)a[i-1]*=-1;
    }
    ans+=a[k];


    dbg{
        if(true)cout <<"YES"<<endl;
        else cout <<"NO"<<endl;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int MAXN=3e5+7;
const int inf=1e9+7;
int k;
inline int read()
{
    int x=0,c=1;
    char ch=' ';
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    while(ch=='-')c*=-1,ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*c;
}
int main()
{
	k=read();
	while(k!=0){
		k--;
		cout<<"ACL";
	}
	return 0;
}

Measured memory_bytes: 3584
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
#include <limits>
using namespace std;
int gcd(int a, int b)//最大公約数
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}
vector<int> divisor(int n) {//約数発見
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    std::sort(ret.begin(), ret.end());
    return ret;
}
long nc2(long n){
    return n*(n-1)/2;
}
int main(){
    //std::stack<int> stack;
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> cnt(1000001);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        cnt[a[i]] ++;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        bool jud = true;
        vector<int> yaku = divisor(a[i]);
        for(int j = 0; j < yaku.size()-1; j++){
            if(cnt[yaku[j]] != 0){
                jud = false;
            }
        }
        if(cnt[a[i]] != 1){
            jud = false;
        }
        if(jud){
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 7984
s = int(input())

values = set()

values.add(s)
ans = 1
while True:
    if s % 2 == 0:
        s = s //2
    else:
        s = 3*s + 1
    ans += 1

    if s in values:
        break
    else:
        values.add(s)

print(ans)

Measured memory_bytes: 2940
import java.util.Stack
import java.util.LinkedList

fun main(args : Array<String>) {
    val s = readLine()!!
    val stack = Stack<Int>()
    val a = LinkedList<Int>()

    a.push(1)
    stack.push(1)


    if (s.length == 2) {
        println(s)
    } else {
        println(s.reversed())
    }
}


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



int main(void){
    int x;
    cin >> x;
    if(x>=30)
        cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<string> bl(n);
	for (int i = 0; i < n; i++) {
		cin >> bl.at(i);
	}
	int m;
	cin >> m;
	vector<string> rd(m);
	for (int i = 0; i < m; i++) {
		cin >> rd.at(i);
	}
	int l;
	l = 0;//最大値
	for (int i = 0; i < n; i++) {//全ての青の単語に関して
		int k = 0;//挑戦者の結果
		for (int j = 0; j < n;j++) {//他の青単語と一致か確認
			if (bl.at(i) == bl.at(j)) {//青と一致してたら加算
				k++;
			}
		}
		for (int j = 0; j < m; j++) {//赤単語と一致か確認
			if (bl.at(i) == rd.at(j)) {
				k--;
			}
		}
		if (k > l) {
			l = k;
		}
	}
	cout << l << endl;
	return 0;
}


Measured memory_bytes: 256
#five antennas

#入力
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())

antennas=[a,b,c,d,e]
#判定

for x in antennas:
    for y in antennas:
        if y-x > k:
            print(":(")
            break
    else:
        continue
    break
else:
    print("Yay!")

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>


struct Node{
    int key;
    Node *prev, *next;
};

Node *nil;

Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    // 番兵の直後に要素を追加
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}



void deleteNode(Node *t){
    if( t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur == nil) break;
        if( isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

int main(){
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for(i = 0; i < n; i++){
        scanf("%s%d", com, &key);
        if ( com[0] == 'i'){ insert(key); np++; size++; }
        else if(com[0] == 'd'){
            if( strlen(com) > 6){
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            } else {
                deleteKey(key); nd++;
            }
            size--;
        }
    }
    printList();
    return 0;
}


Measured memory_bytes: 33832
// http://koturn.hatenablog.com/entry/2016/02/04/050000#cpp
#include <cstdlib>
#include <iostream>
#include <memory>

using namespace std;

int isZero(char c)
{
  return c == '0';
}

int isEven(int num)
{
  return num % 2 == 0;
}

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

  string S;
  cin >> S;
  int len = S.length();

  int zeroFirst = 0;
  for (int index = 0; index < len; index++)
  {
    if (!isZero(S[index]) && !isEven(index))
    {
      zeroFirst++;
    }
    else if (isZero(S[index]) && isEven(index))
    {
      zeroFirst++;
    }
  }
  int oneFirst = 0;
  for (int index = 0; index < len; index++)
  {
    if (isZero(S[index]) && !isEven(index))
    {
      oneFirst++;
    }
    else if (!isZero(S[index]) && isEven(index))
    {
      oneFirst++;
    }
  }
  cout << (zeroFirst < oneFirst ? zeroFirst : oneFirst) << endl;
  return EXIT_SUCCESS;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    cout << (a-b)%c << endl;
    return 0;
}


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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
  int n, k;
  cin >> n >> k;
  if (n > k)
    n %= k;
  cout << min(n, k - n) << endl;
}

Measured memory_bytes: 256
from collections import deque
 
d = deque()
q = int(raw_input())
 
for i in range(q):
    query = [int(j) for j in raw_input().split()]
    if query[0] == 0:
        if query[1] == 0:
            d.appendleft(query[2])
        else:
            d.append(query[2])
    elif query[0] == 1:
        print  d[query[1]]
    elif query[0] == 2:
        if query[1] == 0:
            d.popleft()
        else:
            d.pop()


Measured memory_bytes: 30412
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      	if(a%3==0 || b%3==0 || (a+b)%3==0){
        	System.out.println("Possible");
        }else{
        	System.out.println("Impossible");
        }
    }
}

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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int ans1 = 0, ans2 = 0;
	string S;
	
	cin >> S;
	
	for(int i=0; i<S.size(); i++){
		if(i%2 == 0){
			if(S[i] == '0')
				ans1++;
			else
				ans2++;
		}else{
			if(S[i] == '1')
				ans1++;
			else
				ans2++;
		}
	}
	
	cout << min(ans1, ans2);
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <math.h>
#include <set>

using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;
int main() {
	ll A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	ll t1 = ((X > Y) ? X : Y) * C * 2;
	ll t2 = X * A + Y * B;;
	ll t3 = ((X > Y) ? Y : X) * C * 2 + ((X > Y) ? (X - Y) * A : (Y - X) * B);

	cout << min(min(t1, t2), t3) << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
public class Hello{
    public static void Main(){
        string[] a = ReadLine().Split(' ');
        int x = int.Parse(a[0]);
        int y = int.Parse(a[1]);
        if(x%2==1&&y%2==1){
            WriteLine("Odd");
        }else{
            WriteLine("Even");
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

int get(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

int main() {
    int A, B, N;
    int min = 1000000;
    cin >> N;
    for (A = 1; A <= N / 2; A++) {
        B = N - A;
        int sum   = get(A) + get(B);
        if (sum < min) {
            min = sum;
        }
    }
    cout << min << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){
    int k,s,ans=0;
    cin>>k>>s;

    for(int a=0; a<=k; a++){
        for(int b=0; b<=a; b++){
            for(int c=0; c<=b; c++){
                if(a+b+c==s){
                    if(a==b&&b==c)ans++;
                    else if(a==b||b==c||c==a)ans += 3;
                    else ans += 6;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = (a), i_len = (b); i < i_len; ++i)

int main()
{
    int K, S;
    cin >> K >> S;
    int res = 0;
    REP(Z, 0, K + 1) if(S - Z >= 0 && S - Z <= 2*K) {
        int a = S - Z;
        res += min(2*K - a, a) + 1;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main() {
  int n;
  cin>>n;
  bool ex=true;
  long at=0;
  long bt=0;
  vector<int>a(n),b(n);
  rep(i,n){
    cin>>a.at(i);
  }
  rep(i,n){
    cin>>b.at(i);
  }
  rep(i,n){
    at+=a.at(i);
    bt+=b.at(i);
    if(a.at(i)<b.at(i)){
      ex=false;
    }
  }
  if(at<bt){
    cout<<-1<<endl;
  }
  else if(ex){
    cout<<0<<endl;
  }
  else{
    int co=0;
    long to=0;
    vector<int>c(n);
    rep(i,n){
      c.at(i)=a.at(i)-b.at(i);
      if(a.at(i)<b.at(i)){
        co++;
        to+=b.at(i)-a.at(i);
      }
    }
    sort(c.begin(),c.end());
    reverse(c.begin(),c.end());
    int k=0;
    while(to>0){
      to-=c.at(k);
      k++;
      co++;
    }
    cout<<co<<endl;
  }
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    int X, Y;
    cin >> X >> Y;
    bool p = false;
    REP(i, X + 1) {
        int y = i*2 + (X - i)*4;
        p = p || y == Y;
    }
    if(p) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
 
int main(void)
{
 int a,b,c,d,cnt,n;
 while(scanf("%d",&n)!=EOF)
 {
  cnt = 0;
  for(a = 0; a <= 9; a++)
  for(b = 0; b <= 9; b++)
  for(c = 0; c <= 9; c++)
  for(d = 0; d <= 9; d++)
  if(a+b+c+d == n) cnt++;
  printf("%d\n",cnt);
 }
 return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

int main() {
 int n; cin >> n;
 vector<int> w(n);
  int sum = 0;
 REP(i, n){
   cin >> w[i];
   sum += w[i];
 }

  int ans = 100000;
 REP(i, n){
   int sum1 = 0;

   REP(j, i+1){
     sum1 += w[j];
   }
   int tmp = abs(2*sum1 -sum);

  if(ans > tmp) ans = tmp;
 }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
/**
* ????????????temp.
*/
#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
typedef pair<int,int> pii;
typedef pair<int,char> pic;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m[100005];stack<pii> num;
    while(1){
    cin >> n;
    if(n==0)break;
    rep(i,0,n){
        cin >> m[i];
    }
    int mae=m[0],len=1;
    rep(i,1,n){
        if(mae!=m[i]){
            if(i%2){
                while(!num.empty()){
                    pii y=num.top();
                    if(y.second!=m[i]){
                        num.pop();
                        len+=y.first;
                    }else{
                        break;
                    }
                }
                num.push(make_pair(len+1,m[i]));
                len=0;
            }else{
                if(len)num.push(make_pair(len,mae));
                len=1;
                if(i==(n-1)){
                    num.push(make_pair(len,m[i]));
                }
            }
        }else{
            len++;
            if(i==(n-1)){
               // cout << "a";
                num.push(make_pair(len,m[i]));
            }
        }
        mae=m[i];
    }
    int ans=0;
    while(!num.empty()){
        pii a=num.top();num.pop();
        //cout << a.first << endl;
        if(a.second==0){
            //cout << a.first << endl;
            ans+=a.first;
        }
    }
    if(n==1&&m[0]==0)ans++;
    cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3812
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;

class Nums {
public:
		int a, b, c;
		Nums (int _a, int _b, int _c) {
				a = _a;
				b = _b;
				c = _c;
		}

		bool operator<(const Nums& other) const{
				 return a < other.a;
		}
};

int main() {
		int X, Y, Z;
		int K;
		cin >> X >> Y >> Z >> K;
		vector<ll> A(X), B(Y), C(Z);
		for (int i = 0; i < X; i++) cin >> A[i];
		for (int i = 0; i < Y; i++) cin >> B[i];
		for (int i = 0; i < Z; i++) cin >> C[i];
		A.push_back((ll)-1e17);
		B.push_back((ll)-1e17);
		C.push_back((ll)-1e17);
		
		sort(A.begin(), A.end());
		reverse(A.begin(), A.end());
		sort(B.begin(), B.end());
		reverse(B.begin(), B.end());
		sort(C.begin(), C.end());
		reverse(C.begin(), C.end());

		priority_queue<pair<ll, Nums>> pq;
		pq.push(make_pair(A[0] + B[0] + C[0], Nums(0, 0, 0)));
		set<int> s;
		s.insert(0);

		vector<ll> ans;

		while (ans.size() < K) {
				auto v =pq.top(); pq.pop();
				ans.push_back(v.first);

				for (int i = 0; i < 3; i++) {
						int a = v.second.a;
						int b = v.second.b;
						int c = v.second.c;
						if (i == 0) a++;
						if (i == 1) b++;
						if (i == 2) c++;

						// isUsed[1000][1000][1000]はダメなのでhashを作る
						int hash = (a<<20) + (b<<10) + c;
						if (s.find(hash) == s.end()) {
								s.insert(hash);
								pq.push(make_pair(A[a] + B[b] + C[c], Nums(a, b, c)));
						}
				}
		}

		for (int i = 0; i < K; i++) cout << ans[i] << endl;

		return 0;
}


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

int main() {
  int a;
  int b;
  int c;
  int d;
  
  cin >> a;
  cin >> b;
  cin >> c;
  d = 0;
  
  for (int i = a; i <= b; i++) {
    if (i%c == 0) {
      d++; 
    }
  }
  
  cout << d;
   
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>

using namespace std;

int n;
long long t;
long long lc;

long long gcd(long long p, long long q)
{
    if(!p || !q)return max(p, q);
    if(p > q) return gcd(p % q, q);
    return gcd(q % p, p);
}

long long lcm(long long p, long long q)
{
    return p / gcd(p, q) * q;
}

int main()
{
    scanf("%d", &n);
    scanf("%lld", &t);
    lc = t;
    for(int i = 1; i < n; i++) scanf("%lld", &t), lc = lcm(lc, t);
    printf("%lld", lc);
    return 0;
}


Measured memory_bytes: 256
S = input()
N = len(S)

A1 = '0'
A2 = '1'
for i in range(1, N):
  if i % 2 == 0:
    A1 = A1 + '0'
    A2 = A2 + '1'
  else:
    A1 = A1 + '1'
    A2 = A2 + '0'
S = int(S, 2)
A1 = int(A1, 2)
A2 = int(A2, 2)
n1 = bin(S ^ A1).count('1')
n2 = bin(S ^ A2).count('1')
print(min(n1, n2))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s;
    cin>>t;
    int min_string=10000;
    for(int i=0;i<s.length()-t.length()+1;i++){
        int min_for_sublen=0;
        for(int j=0;j<t.length();j++){
            if(s[i+j]!=t[j]){
                min_for_sublen++;
            }
        }
        min_string=min(min_for_sublen,min_string);

    }
    cout<<min_string<<"\n";
}

Measured memory_bytes: 3612