akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
//#define Rep(i,a,n)for(LL i=(LL)(a);i<(LL)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Repp(i,l,r,k)for(int i=(int)(l);i<(int)(r);i+=(int)(k))
//#define Repp(i,l,r,k)for(LL i=(LL)(l);i<(LL)(r);i+=(LL)(k))
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007//998244353,1000000007,1000000009 
int upi(const void* a, const void* b) { return*(int*)a<*(int*)b ? -1 : *(int*)a> * (int*)b ? 1 : 0; }
int downi(const void* a, const void* b) { return*(int*)a<*(int*)b ? 1 : *(int*)a> * (int*)b ? -1 : 0; }
void sortupi(int* a, int n) { qsort(a, n, sizeof(int), upi); } //1,2,3,4,...
void sortdowni(int* a, int n) { qsort(a, n, sizeof(int), downi); }
int upLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? -1 : *(LL*)a> * (LL*)b ? 1 : 0; }
int downLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? 1 : *(LL*)a> * (LL*)b ? -1 : 0; }
void sortupLL(LL* a, int n) { qsort(a, n, sizeof(LL), upLL); }
void sortdownLL(LL* a, int n) { qsort(a, n, sizeof(LL), downLL); }
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
LL gcd(LL p, LL q) { while (q) { LL t = p % q; p = q; q = t; }return p; }
LL modpow(LL a,LL n,int m){LL x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invmodpow(b,p)modpow(b,p-2,p)// a/b≡a*b^{-1}(mod p)...return b^{-1}(mod p)
typedef struct fac { LL n, exp; }F;
LL fact(LL n,F*a){LL x,i,j,c=0;x=n;for(i=2;i*i<=x;i++){for(j=1;x%i==0;j++)x/=i;if(j>1){a[c].n=i;a[c++].exp=j-1;}}if(x-1){a[c].n=x;a[c++].exp=1;}return c;}
//snippet
//overflow...char 1e6

#define N 109

int main() {
	int a, b, c, k;
	scanf("%d%d%d%d", &a, &b, &c, &k);
	int f = 0;

	rep(l, 3) {
		rep(m, 3) {
			rep(n, 3) {
				rep(o, 3) {
					rep(p, 3) {
						rep(q, 3) {
							rep(r, 3) {
								int K = k, A = a, B = b, C = c;
								int d[7] = { l,m,n,o,p,q,r };
								while (K--) {
									if (!d[K])A *= 2;
									else if (d[K] == 1)B *= 2;
									else C *= 2;
								}
								if (A < B && B < C)f++;


							}
						}
					}
				}
			}
		}
	}
	printf(f ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 1732
package main

import (
	"fmt"
	"io"
	"os"
)

func run(input io.Reader, output io.Writer) int {
	var n int
	fmt.Scanf("%d\n", &n)

	if n%2 == 0 {
		fmt.Println(n / 2)
	} else {
		fmt.Println(n/2 + 1)
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
string S;
void solve()
{
    int i,j,len=S.length(),ans=0;
    i=len/2;
    while(i--)
    {
        string tmp1,tmp2;
        for (j=0;j<i;j++)
            tmp1.push_back(S[j]);
        for (j=i;j<2*i;j++)
            tmp2.push_back(S[j]);
        if (tmp1==tmp2) {ans=2*i;break;}
    }
    cout<<ans<<endl;
}
int main()
{
    while(cin>>S)
        solve();
}

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

int main() {
  int K, S;
  cin >> K >> S;
  
  int count = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j ++) {
      int z = S - i - j;
      if (z >= 0 && z <= K) count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int[] a = new int[n];
            int[] cnt = new int[110000];
            long sum = 0;
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
                cnt[a[i]]++;
                sum += a[i];
            }
            int q = Integer.parseInt(in.next());
            int[] b = new int[q];
            int[] c = new int[q];
            for (int i = 0; i < q; i++) {
                b[i] = Integer.parseInt(in.next());
                c[i] = Integer.parseInt(in.next());
            }

            for (int i = 0; i < q; i++) {
                long tmp = cnt[b[i]];
                sum -= b[i] * tmp;
                sum += c[i] * tmp;
                cnt[b[i]] = 0;
                cnt[c[i]] += tmp;
                out.println(sum);
            }

        }

    }
}



Measured memory_bytes: 62072
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
#include<set>
using namespace std;
int UF[610000];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);
	if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
int v[210000];
int ans[210000];
pair<int,int>tmp[210000];
vector<int>g[210000];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<a*3;i++)UF[i]=-1;
	while(b--){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		UNION(p,q);
	}
	for(int i=0;i<c;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		g[p].push_back(q);
		g[q].push_back(p);
	}
	for(int i=0;i<a;i++){
		if(v[i])continue;
		queue<int>Q;
		Q.push(i);
		v[i]=1;
		int sz=0;
		tmp[sz++]=make_pair(FIND(i),i);
		while(Q.size()){
			int at=Q.front();Q.pop();
			for(int j=0;j<g[at].size();j++){
				if(v[g[at][j]])continue;
				v[g[at][j]]=1;
				Q.push(g[at][j]);
				tmp[sz++]=make_pair(FIND(g[at][j]),g[at][j]);
			}
		}
		std::sort(tmp,tmp+sz);
		int cnt=0;
		for(int j=0;j<sz;j++){
			cnt++;
			if(j==sz-1||tmp[j].first!=tmp[j+1].first){
				for(int k=j-cnt+1;k<=j;k++)ans[tmp[k].second]=cnt;
				cnt=0;
			}
		}
	}
	for(int i=0;i<a;i++){
		printf("%d\n",ans[i]);
	}
}

Measured memory_bytes: 13148
#include <iostream>

using namespace std;

int main() {
    //freopen("/home/ngkimbing/Disk_F/CLionProjects/acm/in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    int res = 0;
    for(int i = 0; i < n; ++i){
        int foo;
        cin >> foo;
        if(foo >= k)
            ++res;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n,x;
    scanf("%d",&n);
 
    for(int i = 1; i<= n; i++)
    {
        if(i%3 == 0){
            printf(" %d",i);
        }else{
            x = i;
            do{
                if(x%10 == 3){
                    printf(" %d",i);
                    break;
                }
                x /=10;
            }while(x);
        }
    }
    printf("\n");
}


Measured memory_bytes: 2712
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
int a, b;
cin >> a >> b;
string u;
cin >> u;
if(u==s){
    a--;
}
else{
    b--;
}
cout << a << " " << b << endl;
//system("pause");
return 0;
}

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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(int i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(int i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(int i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    int n;
    cin>>n;
    double p[n+1];
    repA(i,1,n) cin>>p[i];
    double dp[n+1][n+1];
    dp[0][0]=1;
    repA(i,1,n)
    {
        dp[0][i]=0;
        dp[i][0]=dp[i-1][0]*(1-p[i]);
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(j>i) dp[i][j]=0;
            else if(j==i) dp[i][j]=p[i]*dp[i-1][j-1];
            else
            {
                dp[i][j]=p[i]*dp[i-1][j-1] +(1-p[i])*dp[i-1][j];
            }
        }
    }
    double ans=0;
    for(int i=(n/2)+1;i<=n;i++)
    {
        ans+=dp[n][i];
    }
    cout<<fixed<<setprecision(17)<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 70656
import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    N = int(input())
    a_list = list(map(int, input().split()))
    a_list.sort()

    import collections
    c = collections.Counter(a_list)
    keys = sorted(c.keys())
    nk = len(keys)

    dprint(c)
    dprint(keys)

    # a[0] からスタート
    found = False
    start = keys[0]
    ccand = []
    rcand = []
    for i in range(0, nk):

        # 同じ数字を使う場合はcountに気を付ける
        if i == 0 and c[keys[i]] <= 1:
            continue

        center = keys[i]
        max = start + center

        for j in range(i, nk):
            right = keys[j]

            # 同じ数字を使う場合はcountに気を付ける
            if i == j and i == 0 and c[keys[i]] <= 2:
                continue
            if i == j and c[keys[i]] <= 1:
                continue

            if right > max:
                # これより大きいところにはない
                break

            if right == start ^ center:
                found = True
                ccand.append(center)
                rcand.append(right)
                # break
        #
        # if found == True:
        #     break

    if found == False:
        dprint("first pair search failed")
        print("No")
        return

    dprint("first set created")
    dprint(ccand, rcand)
    center = ccand[-1]
    right = rcand[-1]

    c[start] = c[start] - 1
    c[center] = c[center] - 1
    c[right] = c[right] - 1

    # これで、0, second, third が決まったので、あとは順次決める
    left = center
    center = right
    dprint(start, left, center)

    cnt = 3
    while True:
        # N個作ったら終了
        if cnt == N:
            break

        # 次の数字
        right = left ^ center

        # 検索
        rcount = c.get(right, -1)
        if rcount <= 0:
            dprint("break rcount:", rcount)
            print("No")
            return

        dprint("found", right, rcount)

        # update
        c[right] = c[right] - 1
        left = center
        center = right

        cnt += 1
        dprint("next", cnt, left, center)

    if start ^ left == center:
        print("Yes")
    else:
        dprint("last check failed", start, left, center)
        print("No")


solve()

Measured memory_bytes: 14228
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; // trick to explore an implicit 2D grid
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // S,SE,E,NE,N,NW,W,SW neighbors  //GO FOR EVEN FOR 4 moves

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n,i,j,k,t,temp,tc;
    cin>>n;
    LL a[]={400,600,800,1000,1200,1400,1600,1800};
    LL ans=9;
    for(i=0;i<8;i++)
    {
        if(n>=a[i])
        {
            ans--;
        }
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,a[1000];
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	sort(a,a + n);
	cout << a[n - 1] - a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ld long double
#define mod 998244353
long long binpow(long long a, long long b, long long m=mod) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modin(ll n)
{
     return binpow(n,mod-2ll);
}
ll f[1000000];
ll C(ll n,ll r)
{           if(n>=r)
    return (f[n]*((modin(f[n-r])*modin(f[r]))%mod))%mod;
       else
        return 1ll;
}
main()
{    f[0]=1;
     for(ll x=1;x<=400001;x++)
        f[x]=(x*f[x-1])%mod;
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans=0;
    for(ll x=0;x<=k;x++)
    {
        ans=(ans+((C(n-1,n-x-1)*((m*binpow(m-1,n-x-1))%mod))%mod))%mod;
    }
    cout<<ans;
}


Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    int N,K;string S; cin >> N >> S >> K;

    char t = S[K - 1];

    rep(i,N) {
        if(S[i] == t) cout << S[i];
        else cout << '*';
    }
    cout << 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 REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d,n=0,x=0;
    VI m(3);
    string s,s1,s2;
    cin >> a >> b; 
    if(b%a==0)
        cout << a+b <<endl;
    else cout << b-a <<endl;
    return 0;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
struct data{
	int kaisu;
	int num;
}a[100010],b[100010];
int asc(const void*a,const void*b)
{
	return ((data*)b)->kaisu-((data*)a)->kaisu;
}
int main()
{
	static int n,v[100010];
	static int i,amax=0,bmax=0,amaxi,bmaxi,ans=0;
	int ans1=0,ans2=0;
	cin>>n;
	for (i=0;i<n;i++)
	{
		cin>>v[i];
	}
	for (i=0;i<100010;i++)
	{
		a[i].kaisu=b[i].kaisu=0;
		a[i].num=b[i].num=i;
	}
	for (i=0;i<n;i++)
	{
		if (i%2)
		{
			//puts("a");
			a[v[i]].kaisu++;
		}
		else
		{
			
			b[v[i]].kaisu++;
		}
	}
	for (i=0;i<n;i++)
	{
		if (amax<a[i].kaisu)
		{
			amax=a[i].kaisu;
			amaxi=a[i].num;
		}
		if (bmax<b[i].kaisu)
		{
			bmax=b[i].kaisu;
			bmaxi=a[i].num;
		}
	}
	//printf("%d,%d\n",amaxi,bmaxi);
	qsort(a,sizeof(a)/sizeof(a[0]),sizeof(a[0]),asc);
	qsort(b,sizeof(b)/sizeof(b[0]),sizeof(b[0]),asc);
	//printf("%d,%d,%d,%d\n",a[0].kaisu,a[0].num,b[0].kaisu,b[0].num);
	//printf("%d,%d,%d,%d\n",a[1].kaisu,a[1].num,b[1].kaisu,b[1].num);
	if (a[0].num!=b[0].num)
	{
		for (i=0;i<n;i++)
		{
			if (i%2&&v[i]!=a[0].num) ans++;
			if (!(i%2)&&v[i]!=b[0].num) ans++;
		}
		cout<<ans<<endl;
		return 0;
	}
	//aはa0num以外、bはb1num以外の数
	for (i=0;i<n;i++)
	{
		if (i%2&&v[i]!=a[0].num) ans1++;
		if (!(i%2)&&v[i]!=b[1].num) ans1++;
	}
	for (i=0;i<n;i++)
	{
		if (i%2&&v[i]!=a[1].num) ans2++;
		if (!(i%2)&&v[i]!=b[0].num) ans2++;
	}
	cout<<min(ans1,ans2)<<endl;
	return 0;
}


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

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);		
		long a=in.nextLong();
		long b=in.nextLong();
		long q=gcd(a,b);
		int ans=1;
		long temp=q;
		for(long i=2;i*i<=q;i++)
		{
			if(temp%i==0)
			{
				ans++;
				while(temp%i==0)
				{
					temp=temp/i;
				}
			}
			if(temp==1)
				break;
		}
		if(temp!=1)
		{
			ans++;
		}
		System.out.println(ans);
	}
	public static long gcd (long a,long b)
	{
		if(a%b==0)
			return b;
		return gcd(b,a%b);
	}
}
	

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

//
// BEGIN Range minimum query
//

struct {
    int N;
    vector<long long> dat;

    void init(int n) {
      N = 1;
      while(N < n) N *= 2;
      dat.resize(2*N-1, LLONG_MAX);
    }

    // update k-th element
    void update(int k, long long a) {
      k += N-1;
      dat[k] = a;
      while(k > 0) {
        k = (k-1)/2;
        dat[k] = min(dat[k*2+1], dat[k*2+2]);
      }
    }

    // add k-th element by a
    void add(int k, long long a) {
      k += N-1;
      dat[k] += a;
      while(k > 0) {
        k = (k-1)/2;
        dat[k] = min(dat[k*2+1], dat[k*2+2]);
      }
    }

    // return k-th element
    long long get(int k) {
      return dat[k+N-1];
    }

    // return min[a, b)
    long long query(int a, int b) {
      return query(a, b, 0, 0, N);
    }
    long long query(int a, int b, int k, int l, int r) {
      if (r <= a || b <= l) return LLONG_MAX;
      if (a <= l && r <= b) return dat[k];
      int m = (l+r)/2;
      return min(query(a, b, k*2+1, l, m), query(a, b, k*2+2, m, r));
    }
} S;

//
// END range_minimum_query
//

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  S.init(n+1);
  vector<int> b(n);
  int zero = 0;
  rep(i, n) {
    cin >> b[i];
    if (b[i]==0) zero++;
  }
  int q; cin >> q;
  vector<P> ra(q);
  rep(i, q) {
    ll l, r; cin >> l >> r;
    ra[i].first = l;
    ra[i].second = r;
  }
  sort(ra.begin(), ra.end());
  S.update(0, 0);
  int j = 0;
  for(int i=1; i<=n; i++) {
    while(j < q && ra[j].first==i) {
      int l = ra[j].first;
      int r = ra[j].second;
      auto mi = S.query(l-1, r);
      if (mi < S.get(r)) {
        S.update(r, mi);
      }
      j++;
    }
    auto p = (b[i-1]==0) ? -1 : 1;
    auto mi = S.get(i-1)+p;
    if (mi < S.get(i)) {
      S.update(i, mi);
    }
  }
  cout << zero+S.get(n) << endl;
}

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

int main(){
	int n, m;
	int i, j;
	int A[100][100], B[100], C[100] = {0};
	
	cin >> n >> m;
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			cin >> A[i][j];
		}
	}
	
	for(j = 0; j < m; j++){
		cin >> B[j];
	}
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			C[i] += A[i][j] * B[j];
		}
	}

	for(i = 0; i < n; i++){
		cout << C[i] << endl;
	}

	
	return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N;
ll A[100010];

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

  cin>>N;
  rep(i,N)cin>>A[i];
  ll crt;
  crt=A[0];
  repl(i,1,N){
    if(A[i]<crt){
      cout<<"No"<<endl;
      return 0;
    }
    if(A[i]>crt){
      crt=A[i]-1;
    }else{
      crt=A[i];
    }
  }
  cout<<"Yes"<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(){
    string S;
    //入力
    cin>>S;
    
    int mode = 0;
    if(S[0] == '0'){
        mode = 1;
    }else if(S[0] == '1'){
        mode = 2;
    }
    
    int res = 0;
    switch(mode){
        case 1:
            for(int i =1;i < S.size();i++){
                if(i%2 != 0){
                    if(S[i] == '0'){
                        res++;
                    }
                }else{
                    if(S[i] == '1'){
                        res++;
                    }
                }
            }
        
        
        break;
        
        case 2:
             for(int i =1;i < S.size();i++){
                if(i%2 != 0){
                    if(S[i] == '1'){
                        res++;
                    }
                }else{
                    if(S[i] == '0'){
                        res++;
                    }
                }
            }
        
        break;
        
        
    }
    
    
    cout<<res;
    
    return 0;
}


Measured memory_bytes: 512
n,l = map(int,input().split())

def taste(x,l):
    return x+l-1
tastes=[]
for i in range(1,n+1):
    tastes.append(taste(i,l))
min = 0
cnt=0
for i in range(0,n):
    if abs(tastes[min]) >= abs(tastes[i]):
        min=i
del tastes[min]
# print(min)
# print(tastes)
print(sum(tastes))

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

int main(){
    int a, b;
    cin >> a >> b;
    if ( b == 1 ) cout << 0 << endl;
    else {
        cout << max(0, ( b + a - 2 - a )) / ( a - 1 ) + 1 << endl; 
    }
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  vector<int> c(1000000, 0);
  for(int i = 0; i < n; i++) c.at(a.at(i))++;
  
  vector<int> ans(10000000, 0);
  for(int i = 1; i < 100010; i++){
    ans.at(i) = c.at(i - 1) + c.at(i) + c.at(i + 1);
  }
  
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  cout << ans.at(0) << endl;
  
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, p;
    long long an = 0;
    string s;
    cin >> n >> p >> s;
    if (p == 2 || p == 5) {
        for (int j = n-1; j >= 0; --j) {
            if ((s[j]-'0') % p == 0) {
                an += j+1;
            }
        }
    } else {
        vector<long long> cnt(p);
        long long val = 0;
        cnt[0] = 1;
        for (int j = n-1, b = 1; j >= 0; --j, b = (10*b)%p) {
            val += b * (s[j]-'0');
            val %= p;
            an += cnt[val];
            cnt[val]++;
        }
    }
    cout << an << '\n';
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int n;
   cin>>n;
   bool yes=false;
   while(n>0)
   {
   	if(n%10==7)
   	{yes=true;
   	break;
	   }
	   n=n/10;
   }
   if(yes)
   cout<<"Yes"<<endl;
   else
   cout<<"No"<<endl;
return 0;
}



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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,q;cin>>n>>q;
  vector<ll>a(n),b(n);
  vector<P>x(q);
  vector<ll>ret(q);
  rep(i,0,n)cin>>a[i];
  b[0]=a[0],b[1]=a[1];
  rep(i,2,n)b[i]=b[i-2]+a[i];
  rep(i,0,q){
    cin>>x[i].fi;
    x[i].se=i;
  }
  sort(ALLR(x));
  ll limit=0,pt=0,sumbuf=0;
  rep(i,1,n){
    sumbuf+=a[n-i];
    if(n-2*i-1<0)limit=0;
    else limit=(a[n-i-1]+a[n-2*i-1])/2;
    //cout<<i spa limit spa pt spa sumbuf<<endl;
    while(pt<q&&x[pt].fi>limit){
      ret[x[pt].se]=sumbuf;
      if(n-2*i-1>=0)ret[x[pt].se]+=b[n-2*i-1];
      pt++;
    }
    if(pt>=q)break;
  }
  rep(i,0,q)cout<<ret[i]<<endl;
  return 0;
}

Measured memory_bytes: 5632
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node list;

struct node {
    int key;
    list *next;
    list *prev;
};

list *head, *tail;

void insert(int key) {
    list *new;
    new = (list*)malloc(sizeof(list));
    new->key = key;
    new->next = head->next;
    new->prev = head;
    head->next = new;
    new->next->prev = new;
}

void del(int key) {
    list *t = head->next, *prev = head;
    while(t != tail && t->key != key) {
        prev = t;
        t = t->next;
    }

    if (t != tail) {
        prev->next = t->next;
        t->next->prev = prev;
        free(t);
    }
}

void del_first() {
    list *first = head->next;
    head->next = first->next;
    first->next->prev = head;
    free(first);
}

void del_last() {
    list *last = tail->prev;
    tail->prev = last->prev;
    last->prev->next = tail;
    free(last);
}

void show() {
    list *t = head->next;
    while(t != tail) {
        printf("%d%c", t->key, ((t->next == tail) ? '\n' : ' '));
        t = t->next;
    }
}

int main() {
    int i, n;
    char command[20];
    int key;

    scanf("%d", &n);

    head = (list*)malloc(sizeof(list));
    tail = (list*)malloc(sizeof(list));
    head->key = tail->key = -1;
    head->next = tail;
    tail->prev = head;
    head->prev = tail->next = NULL;

    for(i = 0; i < n; i++) {
        scanf("%s", command);
        if (strcmp(command, "insert") == 0) {
            scanf("%d", &key);
            insert(key);
        } else if (strcmp(command, "delete") == 0) {
            scanf("%d", &key);
            del(key);
        } else if (strcmp(command, "deleteFirst") == 0) {
            del_first();
        } else if (strcmp(command, "deleteLast") == 0) {
            del_last();
        }
    }

    show();
    return 0;
}

Measured memory_bytes: 33044
import scala.collection.mutable.ListBuffer

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val Vs, Es = sc.nextInt()
    val E = Array.fill[Boolean](Vs, Vs)(false)
    (0 until Es) foreach { _ =>
      val u, v = sc.nextInt()
      E(u)(v) = true
    }
    val visited = new Array[Boolean](Vs)

    val topologicalSorted = new ListBuffer[Int]()
    // 全ての頂点からスタートし, uから繋がっている全てのvについて探索, 帰ってくるタイミングで
    def dfs(u: Int): Unit =
      if (!visited(u)) { // 訪れていない時
        visited(u) = true // 訪れた.
        (0 until Vs) foreach { v => // 全ての頂点について
          if (E(u)(v)) { // 辺が繋がっているv
            dfs(v) // vについてdfs
          } // 辺が繋がっていない頂点には移動しない.
        }
        topologicalSorted.prepend(u)
      } // 訪れているなら何もしない.

    (0 until Vs) foreach dfs

    topologicalSorted.foreach(println)
  }
}



Measured memory_bytes: 215680
N = int(input())
A = [int(x) for x in input().split()]

half = (N+1)//2
A.sort(reverse = True)

ans = sum(A[:(half-1)])

if (N-half) != half:
    ans += sum(A[1:half])
else:
    ans += sum(A[1:half]) + A[half-1]

print(ans)

Measured memory_bytes: 31572
c = input()

alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

for i in range(len(alphabet)):
  if c == alphabet[i]:
    ans = alphabet[i+1]
    break

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };



int main() {
	int n, m;
	cin >> n >> m;
	hei(int) cont(n, 0);
	hei(int) a(m),s(n,0);
	hei(string) b(m);
	int ac = 0, wa = 0;
	rep(i, 0, m) {
		cin >> a[i] >> b[i];
		if (b[i] == "WA")cont[a[i] - 1]++;
		if (b[i] == "AC") {
			if (s[a[i] - 1] == 0) {
				s[a[i] - 1] = 1;
				ac++;
				wa += cont[a[i] - 1];
			}
		}
	}
	cout << ac << " " << wa << endl;
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
void ii(ll &x){ cin >> x; }
void is(string &x){ cin >> x; }
void oi(ll x){ cout << x << " "; }
void os(string x){ cout << x; }
void oie(ll x){ cout << x << endl; }
void ose(string x){ cout << x << endl; }
void oe(){ cout << endl; }

int main(){
    ll N, M;
    ii(N);
    ii(M);
    oie(N*(N-1)/2+M*(M-1)/2);

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int sum = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			sum+=(d-1)/a[i]+1;
		}
		System.out.print(sum);

	}

}


Measured memory_bytes: 23764
n, m = map(int, input().split())
votes = list(map(int, input().split()))
k = (1/(4*m))*sum(votes)
 
items = []
 
for i in range(n):
  if votes[i] >= k:
    items.append(i)
 
if len(items) >= m:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e9 + 15;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    ll ans=0;
    map<ll,ll> cont;
    rep(i,1,n+1){
        ll a;
        cin>>a;
        ans+=cont[i-a];
        cont[i+a]++;
    }
    cout<<ans<<'\n';
    return 0;   
}

Measured memory_bytes: 26324
#include<bits/stdc++.h>
using namespace std;
int n,k,a[1000005];
int mx[1000005][36],mi[1000005][36];
int d[1000005];
inline int Max(int x,int y)
{
	int l=(int)(log(y-x+1)/log(2));
	return max(mx[x][l],mx[y-(1<<l)+1][l]);
}
inline int Min(int x,int y)
{
	int l=(int)(log(y-x+1)/log(2));
	return min(mi[x][l],mi[y-(1<<l)+1][l]);
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;)
	{
		int x1=i;
		while(a[x1+1]>a[x1])
			x1++;
		while(i<=x1)
			d[i++]=x1;
	}
	for(int i=1;i<=n;i++)
		mx[i][0]=mi[i][0]=a[i];
    for(int l=1;(1<<l)<=n;l++)
        for(int i=1;i+(1<<l)-1<=n;i++)
			mi[i][l]=min(mi[i][l-1],mi[i+(1<<(l-1))][l-1]),
            mx[i][l]=max(mx[i][l-1],mx[i+(1<<(l-1))][l-1]);
	int ans=1;
	bool f1=0;
	if(d[1]>=k)
		f1=1;
	for(int i=2;i+k-1<=n;i++)
	{
		if((Max(i,i+k-2)<a[i+k-1]&&Min(i,i+k-2)>a[i-1]))
			continue;
		if(d[i]>=i+k-1)
		{
			if(f1)
				continue;
			f1=1;
		}
		ans++;
	}
	printf("%d",ans);
}

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

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


Measured memory_bytes: 256
using System;

namespace ALDS1_10A{
    public class Program{
        public static void Main(string[] args){
            var res = new[]{
                1,
                1,
                2,
                3,
                5,
                8,
                13,
                21,
                34,
                55,
                89,
                144,
                233,
                377,
                610,
                987,
                1597,
                2584,
                4181,
                6765,
                10946,
                17711,
                28657,
                46368,
                75025,
                121393,
                196418,
                317811,
                514229,
                832040,
                1346269,
                2178309,
                3524578,
                5702887,
                9227465,
                14930352,
                24157817,
                39088169,
                63245986,
                102334155,
                165580141,
                267914296,
                433494437,
                701408733,
                1134903170,
                1836311903,
                2971215073,
                4807526976,
                7778742049,
                12586269025,
            };

            Console.WriteLine(res[int.Parse(Console.ReadLine())]);
        }
    }
}

Measured memory_bytes: 9240
a,b,c,d=map(int,input().split())
countc=(b//c)-((a-1)//c)
countd=(b//d)-((a-1)//d)

def gcd_strategy():
    import math
    import fractions
    return math.gcd if hasattr(math, "gcd") else fractions.gcd
gcd = gcd_strategy()

cd=c*d//gcd(c,d)
countcd=(b//cd)-((a-1)//cd)
print(1+b+countcd-(a+countc+countd))

Measured memory_bytes: 5100
N=int(input())
h=list(map(int,input().split()))
dp=[0]*(N)
dp[1]=abs(h[0]-h[1])
for i in range(2,N):
    dp[i]=min((dp[i-2]+abs(h[i-2]-h[i])),(dp[i-1]+abs(h[i-1]-h[i])))
print(dp[N-1])

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

long long N, K;
vector<long long> A;
vector<long long> F;

bool possible(long long maxi){
	long long num = K;
	for(long long i = 0; i < N; i++){
		long long needa = maxi/F[i];
		num -= max(0LL, A[i] - needa);
	}
	return num >= 0;

}

int main(){
	cin >> N >> K;
	for(long long i = 0; i < N; i++){
		long long tmp;
		cin >> tmp;
		A.push_back(tmp);
	}
	for(long long i = 0; i < N; i++){
		long long tmp;
		cin >> tmp;
		F.push_back(tmp);
	}

	sort(A.begin(), A.end());
	sort(F.begin(), F.end(), greater<long long>());

	long long start = -1;
	long long end = LONG_MAX/3;

	while(start + 1 < end){
		long long mid = (start + end)/2;
		if(possible(mid)){
			end = mid;
		}else{
			start = mid;
		}
	}
	cout << end << endl;
}


Measured memory_bytes: 4848
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <vector>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  if (x[0] >= 0) {
    cout << x[k - 1] << endl;
    return 0;
  } else if (x[n - 1] <= 0) {
    cout << abs(x[n - k]) << endl;
    return 0;
  }

  int s = 0;
  for (; s < n - 1; ++s) {
    if (x[s] < 0 && x[s + 1] >= 0) {
      break;
    }
  }
  int ans = numeric_limits<int>::max();
  for (int i = 1; i <= k; ++i) {
    const int m = k - i;
    const int l = s + 1 - m;
    const int r = s + i;
    if (l < 0) continue;
    if (n <= r) continue;
    ans = min({ans, 2 * abs(x[l]) + abs(x[r]), abs(x[l]) + 2 * abs(x[r])});
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 100010
#define mod 1000000007
int ans,sum[N],n;
int qpow(int x,int y)
	{int tmp=1;while(y) {if(y&1) tmp=1ll*tmp*x%mod;y>>=1,x=1ll*x*x%mod;}return tmp;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) sum[i]=(sum[i-1]+qpow(i+1,mod-2))%mod;
	for(int i=1,x;i<=n;i++) scanf("%d",&x),(ans+=1ll*(sum[i-1]+sum[n-i])%mod*x%mod)%=mod,(ans+=x)%=mod;
	for(int i=1;i<=n;i++) ans=1ll*ans*i%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        char[] S = sc.next().toCharArray();
        char[] T = sc.next().toCharArray();
        System.out.println(possible(S, S, T) || possible(S, T, S) ? "Yes" : "No");
    }

    static boolean possible(char[] target, char[] s1, char[] s2) {
        int[] pos = {0, 0};
        for (int i = 0; i < target.length; i++) {
            char[] s = i % 2 == 0 ? s1 : s2;
            while (pos[i % 2] < s.length && s[pos[i % 2]] != target[i]) {
                pos[i % 2]++;
            }
            if (pos[i % 2] == s.length || s[pos[i % 2]] != target[i]) {
                return false;
            }
            pos[i % 2]++;
        }
        return true;
    }
}

Measured memory_bytes: 26292
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int n,m,l,r,ans,q;
int a[1000][1000];
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for (int i=1;i<=m;++i){
		scanf("%d%d",&l,&r);
		a[l][r]++;
	}
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j) a[i][j]+=a[i][j-1];
		
	for (int i=1;i<=q;++i){
		scanf("%d%d",&l,&r);
		int ans=0;
		for (int j=l;j<=r;++j){
			ans+=a[j][r];
		}
		printf("%d\n",ans);
	}
}

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

int main() {
	string n;
  	cin>>n;
  	int count=0;
  	if(n[0]=='2') count++; 
  	if(n[1]=='2') count++;
  	if(n[2]=='2') count++;
  	if(n[3]=='2') count++;
  	cout<<count<<endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc146/tasks/abc146_e

#include "algorithm"
#include "cmath"
#include "functional"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, K;
  cin >> N >> K;

  VL as(N);
  rep(i, N) cin >> as[i];

  VL rems(N + 1);
  rep(i, N) rems[i + 1] = rems[i] + as[i];
  rep(i, N + 1) rems[i] = (rems[i] - i + K) % K;

  map<ll, ll> m;

  ll res = 0;

  // i を右端とするものの個数を足していく
  rep(i, N + 1) {
    res += m[rems[i]];

    m[rems[i]]++;

    if (i - K + 1 >= 0) {
      m[rems[i - K + 1]]--;
    }
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 15872
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 24 21:18:05 2019

@author: yuta
"""

S = input()

def main(s):
    max_count = 0
    for i in range(len(s)):
        if s[i] == "A" or s[i] == "T" or s[i] == "G" or s[i] == "C":
            count = 1
        else:
            continue
        for j in range(1,len(s)-i):
            if s[i+j] == "A" or s[i+j] == "T" or s[i+j] == "G" or s[i+j] == "C":
                count += 1
            else:
                break
        if max_count <= count:
            max_count = count
    print(max_count)
main(S)

Measured memory_bytes: 3064
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

//最大公約数
	long long GCD(long long a, long long b) {
		if (a < b)
			swap(a, b);
		if (b == 0) return a;
		else return GCD(b, a % b);
	}
	//素数判定
	bool sosuu_check(int num) {
		int i;
		for (i = 2; i <= sqrt(num); ++i) {
			if (num%i == 0)
				return false;
		}
		return (num < 2) ? false : true;
	}
	
	int check(int N, int a, int b) {
		int A,B,i;
		if (a > b) {
			A = a;
			B = b;
		}
		else {
			A = b;
			B = a;
		}
		for (i = N / b; i > 0; i--) {
			if ((N - b * i) % a == 0) {
				return i;
			}
		}
		return 0;
	}
	//コンビネーション(n,r)
	ull combination(int n, int r) {
		if (r * 2 > n) r = n - r;
		ull dividend = 1;
		ull divisor = 1;
		for (int i = 1; i <= r; ++i) {
			dividend *= (n - i + 1);
			divisor *= i;
		}
		return dividend / divisor;
	}

int main() {
	ll N, M, i, ans, sum, A, B;
	cin >> N >> M;
	vector<pair<ull, ull>> P(100000);
	REP(i, N) {
		cin >> A >> B;
		P[i] = make_pair(A, B);
	}
	sort(P.begin(), P.begin() + N);
	sum = 0;
	ans = 0;
	REP(i, N) {
		if ((sum + P[i].second) >= M) {
			ans += (M - sum)*P[i].first;
			cout << ans <<endl;
			return 0;

		}
		else {
			sum += P[i].second;
			ans += P[i].first*P[i].second;
		}
	}
	return 0;
}

Measured memory_bytes: 1792