akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define F(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define FD(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define pii pair<int,int>
#define reset(x,y) memset(x, y,sizeof(x))
#define MIN(x,y) if (x > (y)) x = (y)
#define MAX(x,y) if (x < (y)) x = (y)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define EL putchar('\n');
#define mod 1000000007
#define oo 3003
int read()
{
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
void write(int x)
{
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
int n;
int a[oo],mina=1e6;
int f[oo][oo];
void ReadInPut()
{
    n=read();
    F(i,1,n)a[i]=read();
}
int tinh(int i,int j)
{
	if(f[i][j]!=-1) return f[i][j];
	if(i>j)return 0;
    int res;
    if((i-1+n-j)%2)res=min(tinh(i+1,j)-a[i],tinh(i,j-1)-a[j]);
    else res=max(tinh(i+1,j)+a[i],tinh(i,j-1)+a[j]);
    f[i][j]=res;
    return res;
}
void Solve()
{
    reset(f,-1);
    cout<<tinh(1,n);
}
main()
{
//    freopen("t.INP","r",stdin);
  //  freopen(".OUT","w",stdout);
    int sotest=1;
    //cin>>sotest;
    for(int i=1;i<=sotest;i++)
    {
        ReadInPut();
        Solve();
    }
}


Measured memory_bytes: 70784
z[4000],*a=z,*b=z+2000,m,i,j;main(n){for(;scanf("%d",&n),i=n;printf("%d\n",m))for(memset(a,m=0,8e3);i--;j=a,a=b,b=j)for(j=n+1;j--;)m=fmax(m,b[j]=getchar()>45?1+fmin(fmin(b[j+1],a[j+1]),a[j]):0);}

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

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

    long long x[100], y[100];
    pair<int, int> p[100];

    for(int i = 0;i < n;i++){
        cin >> x[i] >> y[i];
        p[i].first = x[i];
        p[i].second = y[i];
    }

    sort(x, x+n);
    sort(y, y+n);
    long long ans = LLONG_MAX;
    for(int i = 0;i < n;i++){
        for(int j = i+1;j < n;j++){
            for(int k = 0;k < n;k++){
                for(int l = k+1;l < n;l++){
                    int cnt = 0;
                    for(int z = 0;z < n;z++){
                        if(x[i] <= p[z].first && p[z].first <= x[j]
                                && y[k] <= p[z].second && p[z].second <= y[l]){
                            cnt++;
                        }
                    }
                    if(cnt >= kk){
                        ans = min(ans, (x[j]-x[i])*(y[l]-y[k]));
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1147&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(ll n){
    vector<ll> score(n); for(auto& in:score) cin >> in;
    sort(score.begin(),score.end());
    return accumulate(score.begin()+1,score.end()-1,0LL)/(n-2);
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n;
    while(cin >> n,n){
        cout << solve(n) << endl;
    }
    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool isPalindrome(string S, int N) {
for (int i = 0; i < N; i++){
    if (S[i] != S[N-i-1]) return false;
}
return true;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string S;
    int N;
    cin >> S;
    N = S.length();
    if (isPalindrome(S, N) == false) cout << "No";
    else {
    int NA = (N-1) / 2;
    string A = S.substr(0, NA);
    if (isPalindrome(A, NA)) {
    int NB = (N + 3) / 2;
    string B = S.substr(NB - 1, N - 1);
    if (isPalindrome(B, N - NB + 1)) cout << "Yes";
    else cout << "No";
    }
    else cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll q, h, s, d;
    ll n;
    cin >> q >> h >> s >> d >> n;
    ll ans = 0;
    if (n > 2) {
        ll q_2l = q * 8;
        ll h_2l = h * 4;
        ll s_2l = s * 2;
        ll min_2l = min({q_2l, h_2l, s_2l, d});
        ans += (n / 2) * min_2l;
        n -= n / 2 * 2;
    }
    if (n != 0) {
        ll q_1l = q * 4;
        ll h_1l = h * 2;
        ll min_1l = min({q_1l, h_1l, s});
        ans += min_1l;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll H, W, K;
string S[15];

ll solve(ll div) {
    vector<vector<string>> v;
    vector<string> t;
    REP(i, H) {
        t.push_back(S[i]);
        if (i == H - 1 || ((div >> i) & 1) == 1) {
            v.push_back(t);
            t.clear();
        }
    }

    ll ret = v.size() - 1;
    vector<ll> s(v.size(), 0);
    REP(w, W) {
        vector<ll> ss(v.size(), 0);
        REP(i, v.size()) {
            REP(j, v[i].size()) {
                ss[i] += v[i][j][w] - '0';
            }
            if (ss[i] > K)
                return INF;
        }

        bool over = false;
        REP(i, v.size()) {
            if (s[i] + ss[i] > K)
                over = true;
        }

        if (over) {
            REP(i, v.size()) {
                s[i] = 0;
            }
            ret++;
        }

        REP(i, v.size()) {
            s[i] += ss[i];
        }
    }

    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W >> K;
    REP(i, H) {
        cin >> S[i];
    }

    ll ans = INF;
    REP(i, pow(2, H - 1)) {
        ans = std::min(ans, solve(i));
    }
    cout << ans << endl;
    return 0;
}

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

const int N=100100;
int n,u,v,a[N],b[N],c[N],d[N],D,nx,ny;
vector<int>vx[N],vy[N];
set<pair<int,int> >sx[N],sy[N];
long long ans;
queue<int>Q;
void calcX(int X,int yl,int yr){
	int x=lower_bound(c+1,c+nx+1,X)-c;if(x>nx||c[x]!=X)return;
	ans+=upper_bound(vx[x].begin(),vx[x].end(),yr)-lower_bound(vx[x].begin(),vx[x].end(),yl);
	for(auto it=sx[x].lower_bound(make_pair(yl,0));it!=sx[x].end()&&it->first<=yr;it=sx[x].erase(it)){
		Q.push(it->second);sy[b[it->second]].erase(make_pair(X,it->second));
	}
}

void calcY(int Y,int xl,int xr){
	int y=lower_bound(d+1,d+ny+1,Y)-d;if(y>ny||d[y]!=Y)return;
	ans+=upper_bound(vy[y].begin(),vy[y].end(),xr)-lower_bound(vy[y].begin(),vy[y].end(),xl);
	for(auto it=sy[y].lower_bound(make_pair(xl,0));it!=sy[y].end()&&it->first<=xr;it=sy[y].erase(it)){
		Q.push(it->second);sx[a[it->second]].erase(make_pair(Y,it->second));
	}
}


int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>u>>v;
	for(int i=1;i<=n;++i){
		cin>>a[i]>>b[i];
		c[i]=a[i]+b[i];d[i]=a[i]-b[i];
		a[i]=c[i];b[i]=d[i];
	}
	sort(c+1,c+n+1);sort(d+1,d+n+1);
	nx=unique(c+1,c+n+1)-c-1;ny=unique(d+1,d+n+1)-d-1;
	D=max(abs(a[u]-a[v]),abs(b[u]-b[v]));
	for(int i=1;i<=n;++i){
		int s=lower_bound(c+1,c+nx+1,a[i])-c,
			t=lower_bound(d+1,d+ny+1,b[i])-d;
		vx[s].push_back(b[i]);if(i!=u&&i!=v)sx[s].emplace(b[i],i);
		vy[t].push_back(a[i]);if(i!=u&&i!=v)sy[t].emplace(a[i],i);
		a[i]=s;b[i]=t;
	}
	for(int i=1;i<=nx;++i)sort(vx[i].begin(),vx[i].end());
	for(int i=1;i<=ny;++i)sort(vy[i].begin(),vy[i].end());
	for(Q.push(u),Q.push(v);!Q.empty();){
		int x=Q.front();Q.pop();
		int dx=c[a[x]],dy=d[b[x]];
		calcX(dx+D,dy-D+1,dy+D-1);
		calcX(dx-D,dy-D+1,dy+D-1);
		calcY(dy+D,dx-D,dx+D);
		calcY(dy-D,dx-D,dx+D);
	}
	cout<<(ans/2)<<'\n';
	return 0;
}


Measured memory_bytes: 30720
void main()
{
    long h, w;
    rdVals(h, w);
    string[] s = h.rdCol!string;

    long[][] dp = new long[][](h, w);
    dp[0][0] = (s[0][0] == '#');
    foreach (i; 1 .. h)
    {
        dp[i][0] = dp[i-1][0];
        if (s[i][0] == '#' && s[i-1][0] != '#') ++dp[i][0];
    }
    foreach (i; 1 .. w)
    {
        dp[0][i] = dp[0][i-1];
        if (s[0][i] == '#' && s[0][i-1] != '#') ++dp[0][i];
    }
    foreach (i; 1 .. h)
    {
        foreach (j; 1 .. w)
        {
            long x = dp[i][j-1] + (s[i][j] == '#' && s[i][j-1] != '#');
            long y = dp[i-1][j] + (s[i][j] == '#' && s[i-1][j] != '#');
            dp[i][j] = min(x, y);
        }
    }

    dp[h-1][w-1].writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 380
#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);
    for(int i=n-1;i>0;i--)cout<<a.at(i)<<" ";
    cout<<a.at(0)<<endl;
}


Measured memory_bytes: 3072
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		int h, m, s;
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		h = a / 3600;
		m = (a - (h * 3600)) / 60;
		s = a - ((h * 3600) + (m * 60));
		System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 26224
#include<stdio.h>

int main(void){
    int N, X, T, time = 0;
    scanf("%d %d %d", &N, &X, &T);
    time = (N/X)*T;
    if(N%X > 0){
        time += T;
    }
    printf("%d\n",time);
    return 0;
}

Measured memory_bytes: 1684
/*
t.me/ivanesipovvpered
*/
#pragma ARCENIY_KIRILLOV_POVELITEL_KROKODILOV
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;

const double EPS = 1e-5;
const int mod = 1e9 + 7;
const ll INFLL = 1e18;
const int INF = 1e9;
const int maxn = 1e6 + 3;

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

ll lcm(ll a, ll b){
    return (a / gcd(a, b) )* b;
}

bool is_prime(ll a){
    if (a == 2 | a == 3 || a == 5 || a == 7) return true;
    if (a % 2 == 0 || a%3 == 0 || a%5 == 0 || a%7 == 0)
        return false;
    for (ll i = 11; i * i <= a; i += 2){
        if (a % i == 0)
            return false;
    }
    return true;
}

ll binpow(ll a, int n){
    if (a == 0)
        return 1;
    if (a % 2 == 0){
        ll q = binpow(a, n / 2);
        return (q * q)  ;
    }else return (a * binpow(a, n - 1) ) ;
}





















main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n)
        cin >> a[i];
    vi dp(n);
    dp[n - 2] = abs(a[n - 1] - a[n - 2]);
    for (int i = n - 3; i > -1; i--){
        dp[i] = min(dp[i+1] + abs(a[i] - a[i+1]), dp[i+2] + abs(a[i+2] - a[i]));
    }
    cout << dp[0];




}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define bit(x) (1<<(x))
using namespace std;

int n,m,p;
int a[15][15];

using R=long double;
R dp[1<<14];

int main(void){
	cin >> n >> m >> p;
	rep(i,m){
		int u,v;
		cin >> u >> v;
		a[u-1][v-1]++;
		a[v-1][u-1]++;
	}

	rep(mask,1,1<<n){
		dp[mask]=1.0;		
		if(__builtin_popcount(mask)==1) continue;
		for(int add=(mask-1)&mask;add>=1;add=(add-1)&mask){
			int root=add^mask;
			if(add<root) break;
			double cur=dp[add];
			rep(i,n)rep(j,n) if(root&bit(i)) if(add&bit(j)) rep(loop,a[i][j]) cur*=1.0*p/100.0; 
			dp[mask]-=cur;	
		}
	}

	cout.precision(20);
	cout << fixed << dp[bit(n)-1] << endl;
	return 0;
}

Measured memory_bytes: 3536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var b = Console.ReadLine().Split().ToArray();
            foreach (var i in Enumerable.Range(0, a / 2))
            {
                var X = b[a-1-i];
                b[a-1-i] = b[i];
                b[i] = X;
            }
            //Console.WriteLine(b);
            foreach (var i in Enumerable.Range(0, a - 1))
            {
                Console.Write("{0} ",b[i]);
            }
            Console.WriteLine(b[a-1]);
        }
    }
}

Measured memory_bytes: 9228
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    d = defaultdict(lambda: 0)
    B = []
    for a in A:
        d[a] += 1

        if d[a] % 2 == 0:
            B.append(a)


    B = sorted(B, key=lambda x: -x)
    if len(B) < 2:
        return 0
    else:
        return B[0] * B[1]


if __name__ == '__main__':
    print(main())


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

int main() {
	int e, ans;

	while (1) {
		cin >> e;

		if (e == 0) break;
		ans = e;

		for (int i = 0; i * i * i <= e; i++) {
			for (int j = 0; j * j + i * i * i <= e; j++) {
				if (ans > i + j + (e - i * i * i - j * j)) ans = i + j + (e - i * i * i - j * j);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3000
import sys
n, k = map(int, input().split(' '))
s = str(input())

i = 0
counter = 1
assyuku = [1]
while i+counter < n:
    if s[i] == s[i+counter]:
        assyuku[-1] += 1
        counter += 1
    else:
        assyuku.append(1)
        i += counter
        counter = 1
assyuku = [x-1 for x in assyuku]
if len(assyuku) > k*2:
    print(sum(assyuku)+2*k)
else:
    print(n-1)

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

int divide2(int number) {
	int count = 0;
	while (number % 2 == 0) {
		number /= 2;
		count++;
	}
	return count;
}

int min(int a, int b) {
	if (a > b) {
		return b;
	}
	return a;
}

int main() {
	int try_num, min_count=1000000000, number;
	cin >> try_num;

	for (int i = 0; i < try_num; i++) {
		cin >> number;
		min_count = min(divide2(number), min_count);
	}

	cout << min_count << endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
A = []

for i in range(h):
    line = list(map(int, input().split()))
    A.append(line)

for i in range(h):
    line = list(map(int, input().split()))
    for j, num in enumerate(line):
        A[i][j] = abs(A[i][j] - num)

const = 6400
mask = 1 << const
DP = [0]*w
DP[0] = mask >> A[0][0]


def slide_down(y, x):
    bit = DP[x]
    delta = A[y+1][x]
    new1 = bit << delta
    new2 = bit >> delta
    DP[x] = new1 | new2


def slide_right(y, x):
    bit = DP[x]
    delta = A[y][x+1]
    new1 = bit << delta
    new2 = bit >> delta
    DP[x+1] |= new1 | new2


for y in range(h):
    for x in range(w):
        if x < w-1:
            slide_right(y, x)
        if y < h-1:
            slide_down(y, x)

pattern = DP[w-1]
for i in range(81):
    if (pattern >> const+i) & 1 or (pattern >> const-i) & 1:
        print(i)
        exit()


Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
static class Program
{
	static int[] ReadInts(this TextReader reader) => reader.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
	static IEnumerable<int[]> ReadInts(this TextReader reader, int count)
	{
		for (long i = 0; i < count; ++i)
			yield return reader.ReadInts();
	}

	static IEnumerable<long[]> ReadLongs(this TextReader reader, long count)
	{
		for (long i = 0; i < count; ++i)
			yield return reader.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
	}
	static int gcd_(int a, int b)
	{
		// a >= b
		var n = a % b;
		if (n == 0) return b;
		else return gcd_(b, n);
	}
	static int gcd(int a, int b) {
		if (a >= b) return gcd_(a,b);
		else return gcd_(b,a);
	}
	
	public static void Main(string[] args)
	{
		var k = Console.In.ReadInts()[0];
		var sum = 0;
		for (var a = 1; a <= k; ++a)
			for (var b = 1; b <= k; ++b)
				for (var c = 1; c <= k; ++c)
					sum += gcd(gcd(a, b), c);
		Console.WriteLine(sum);
	}
}

Measured memory_bytes: 19108
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 998244353;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

int main(){
  ll n; cin >> n; ll ans = 111;
  
  rep(i,8){
    if(n - ans <= 0) break;
    else ans += 111;
  }
  
  cout << ans << endl;
  
}
  
  

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean can=true;

        while(can){
            int n=sc.nextInt();
            int x=sc.nextInt();
            int num=0;
            if((n==0)&&(x==0))can=false;
            else{
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            }
            System.out.println(num);
        }
        }
    }
}


Measured memory_bytes: 26540
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
using namespace std;

typedef vector <string> VS;
typedef vector <int> VI;
typedef vector <VI> VVI;

const int inf = 1<<24;

typedef pair <int, int> PII;
typedef pair <int, PII> Node;
typedef priority_queue <Node, vector<Node>, greater<Node> > Queue;

const int dr[4] = { 0, 0, 1, -1 };
const int dc[4] = { 1, -1, 0, 0 };

int main() {
    int n, m;
    while ( cin >> n >> m ) {
        if ( n == 0 && m == 0 ) break;

        VS lines(m);
        for ( int i = 0; i < m; i++ ) {
            cin >> lines[i];
        }
        VVI O(m, VI(n, inf));
        for ( int i = 0; i < m; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                O[i][j] = lines[i][j] == '#' ? 1 : 0;
            }
        }
        int sr, sc;
        for ( int i = 0; i < m; i++ ) {
            for ( int j = 0; j < n; j++ ) {
                if ( lines[i][j] == '&' ) {
                    sr = i;
                    sc = j;
                }
            }
        }

        VVI D(m, VI(n, inf));
        Queue Q;
        Node start( 0, PII( sr, sc ) );
        Q.push( start );
        D[sr][sc] = 0;

        while ( !Q.empty() ) {
            Node node = Q.top();
            Q.pop();

            int cost = node.first;
            int r = node.second.first;
            int c = node.second.second;

            if ( r == 0 || r == m-1 || c == 0 || c == n-1 ) {
                cout << cost << endl;
                break;
            }

            for ( int i = 0; i < 4; i++ ) {
                int nr = r + dr[i];
                int nc = c + dc[i];
                if ( nr < 0 || nr >= m || nc < 0 || nc >= n ) continue;
                int ncost = cost + ( !O[r][c] && O[nr][nc] ? 1 : 0 );
                if ( ncost >= D[nr][nc] ) continue;
                D[nr][nc] = ncost;
                Node nnode( ncost, PII( nr, nc ) );
                Q.push( nnode );
            }
        }
    }
    return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(A: int, B: int):
    if A > B:
        print("GREATER")
    elif A < B:
        print("LESS")
    else:
        print("EQUAL")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace kyoupuro
{
    class MainClass
    {
        public static void Main()
        {
            MainClass mainClass = new MainClass();
            mainClass.Start();
        }

        void Start() {
            String line = Console.ReadLine();
            int z = 0, o = 0;
            for (int i = 0; i < line.Length; i++) {
                if (line[i] == '0') z++;
                else o++;
            }
            Console.WriteLine(Math.Min(z, o) * 2);
        }
    }
}


Measured memory_bytes: 11232
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main(){
    int h, w;
    cin >> h >> w;

    char maze[h][w];

    set<int> ex_x;
    set<int> ex_y;

    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            cin >> maze[y][x];
            if(maze[y][x] == '#'){
                ex_x.insert(x);
                ex_y.insert(y);
            }
        }
    }

    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            if(ex_x.find(x) != ex_x.end() and ex_y.find(y) != ex_y.end()){
                printf("%c", maze[y][x]);
            }
        }
        if(ex_y.find(y) != ex_y.end()){
            printf("\n");
        }

    }

    


    return 0;


}

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

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

#define DIVIDER 998244353

ll solve(ll N, ll K, vector<ll>& L, vector<ll>& R) {
  // vector<ll> num_list;
  // for (size_t i = 0; i < K; i++) {
  //   for (size_t j = L[i]; j <= R[i]; j++) {
  //     num_list.push_back(j);
  //   }
  // }
  vector<ll> pattern_count(N, 0);
  vector<ll> pattern_count_sum(N, 0);
  pattern_count[0] = 1;
  pattern_count_sum[0] = 1;

  for (ll i = 1; i <= N - 1; i++) {
    for (size_t j = 0; j < K; j++) {
      ll l = L[j];
      ll r = R[j];

      if (l > i) {
        continue;
      }
      if (r > i) {
        r = i;
      }

      pattern_count[i] += (pattern_count_sum[i - l] -
                           (r != i ? pattern_count_sum[i - r - 1] : 0)) +
                          DIVIDER;
    }

    pattern_count[i] %= DIVIDER;
    pattern_count_sum[i] =
        (pattern_count[i] + pattern_count_sum[i - 1]) % DIVIDER;
  }

  return pattern_count[N - 1];
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N, K;
  cin >> N >> K;

  std::vector<ll> L(K, 0), R(K, 0);
  for (size_t i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }

  // main procedure
  ll ans = solve(N, K, L, R);

  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6344
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector <int> edges[180000];
double expectedValue[605];
double newValue[605];
bool vis[605];

double calculate1(int v){
    if (vis[v]) return expectedValue[v];
    vis[v] = true;
    double ans = 0;
    double out = edges[v].size();
    for (int e: edges[v]){
        ans += 1 / out * calculate1(e);
    }
    if (out > 0) ans++;
    return expectedValue[v] = ans;
}

double calculate2(int v){
    if (vis[v]) return newValue[v];
    vis[v] = true;
    double ans = 0;
    double out = edges[v].size();
    for (int e: edges[v]){
        ans += 1 / out * calculate2(e);
    }
    if (out > 0) ans++;
    return newValue[v] = ans;
}

int main() {
    cin >> N >> M;
    int s, t;
    for (int i=1; i<=M; i++){
        scanf("%d %d", &s, &t);
        edges[s].push_back(t);
    }
    memset(vis, false, sizeof(vis));
    double ans = calculate1(1);

    for (int i=1; i<N; i++){
        int largestIdx = 0, node;
        if (edges[i].size() > 1){
            for (int j=0; j<edges[i].size(); j++){
                if (expectedValue[edges[i][j]] > expectedValue[edges[i][largestIdx]]){
                    largestIdx = j;
                }
            }
            node = edges[i][largestIdx];
            edges[i].erase(edges[i].begin()+largestIdx);
            memset(vis, false, sizeof(vis));
            ans = min(ans, calculate2(1));
            edges[i].push_back(node);
        }
    }
    printf("%.6lf\n", ans);
    return 0;
}

Measured memory_bytes: 5632
#include <stdio.h>

int main(void) {
	int H, W;
	char a[128][128];
	int i;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 0; i < H; i++) {
		if (scanf("%127s", a[i]) != 1) return 1;
	}
	for (i = 0; i < W + 2; i++) putchar('#'); putchar('\n');
	for (i = 0; i < H; i++) printf("#%s#\n", a[i]);
	for (i = 0; i < W + 2; i++) putchar('#'); putchar('\n');
	return 0;
}


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

int N;
string S, T;

int main() {
    cin >> N >> S >> T;

    for (int i = 0; i < N; i++) {
        cout << S[i] << T[i];
    }
    cout << endl;

    return 0;
}


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


public class Main {

	public static void main(String[] args) throws Exception {
		new Main().solve();
	}
	@SuppressWarnings("unchecked")
	void solve() throws Exception {
		FastScanner in = new FastScanner(System.in);

		int n = in.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextLong();
		}
		long[] b = a.clone();
		for (int i = 0; i < b.length; i++) {
			b[i] = -b[i];
		}

		System.out.println(Math.min(f(a), f(b)));

	}
	long f(long[] a) {
		int n = a.length;

		long sum = 0;
		long ret = 0;
		for (int i = 0; i < n; i++) {
			sum += a[i];
			if (i % 2 == 0) {
				// +
				long d = Math.max(0, 1 - sum);
				sum += d;
				ret += d;

			} else {
				// -
				long d = Math.max(0, sum + 1);
				sum -= d;
				ret += d;
			}
		}

		return ret;
	}
	//
	//
	//
	//
	//
	//
	//
	//
	//
	//
	//
	//
	class FastScanner {

		private InputStream _stream;
		private byte[] _buf = new byte[1024];
		private int _curChar;
		private int _numChars;
		private StringBuilder _sb = new StringBuilder();

		FastScanner(InputStream stream) {
			this._stream = stream;
		}

		public int read() {
			if (_numChars == -1) throw new InputMismatchException();
			if (_curChar >= _numChars) {
				_curChar = 0;
				try {
					_numChars = _stream.read(_buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (_numChars <= 0) return -1;
			}
			return _buf[_curChar++];
		}

		public String next() {
			int c = read();
			while (isWhitespace(c)) {
				c = read();
			}
			_sb.setLength(0);
			do {
				_sb.appendCodePoint(c);
				c = read();
			} while (!isWhitespace(c));
			return _sb.toString();
		}

		public int nextInt() {
			return (int) nextLong();
		}
		public long nextLong() {
			int c = read();
			while (isWhitespace(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9') throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isWhitespace(c));
			return res * sgn;
		}

		public boolean isWhitespace(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//


Measured memory_bytes: 24308
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    string s;
    cin >> s;
    int ret1 = 0;
    int ret2 = 0;
    for(int i = 0; i < s.length(); ++i) {
        if(i%2 == 0 && s[i] == '0')
            ret1++;
        else if(i%2 == 1 && s[i] == '1')
            ret1++;
        else if(i%2 == 0 && s[i] == '1')
            ret2++;
        else if(i%2 == 1 && s[i] == '0')
            ret2++;
    }
    cout << min(ret1, ret2) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0){
      break;
    }
    vector<int> a(n);
    for (int i = 0; i < n; i++){
      cin >> a[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++){
      for (int j = i + 1; j < n; j++){
        if (a[i] + a[j] <= m){
          ans = max(ans, a[i] + a[j]);
        }
      }
    }
    if (ans == 0){
      cout << "NONE" << endl;
    } else {
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 3108
N,A,B=map(int,input().split())
S=input()
a=b=0
for s in S:
    if s=="a" and a+b<A+B:
        a+=1
        print("Yes")
    elif s=="b" and a+b<A+B and b<B:
        b+=1
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4016
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

class dijkstra{
  constructor(n){
    this.graph = Array(n).fill().map(a=>[]);
  }
  add(u,v,cost){
    this.graph[u].push(v,cost);
  }
  add2(u,v,cost){
    this.graph[u].push(v,cost);
    this.graph[v].push(u,cost);
  }
  solve(start){
    const INF = 1e18;
    const g = this.graph;
    var pq = new priorityQueue();
    pq.push(0,start);
    var dp = Array(g.length).fill(INF);
    dp[start] = 0;
    while(pq.size){
      var [t,v] = pq.pop();
      if(dp[v] < t)continue;
      for(var i = 0; i < g[v].length; i+=2){
        var V = g[v][i], c = g[v][i+1] + t;
        if(dp[V] <= c)continue;
        dp[V] = c;
        pq.push(c,V);
      }
    }
    return dp;
  }
}

class priorityQueue{
  constructor(){
    this.a=[];
    this.map = new Map();
  }
  push(num,inc){
    const a = this.a, map = this.map;
    for(var i = a.length, j; i; i = j){
      j = i - 1 >> 1;
      if(num >= a[j])break;
      a[i] = a[j];
    }
    a[i] = num;
    if(map.has(num))map.get(num).push(inc);
    else map.set(num, [inc]);
  }
  pop(){
    const a = this.a, map = this.map, l = a.length, x = a.pop();
    if(l < 2){
      if(l === 0)return;
      return [x, map.get(x).pop()];
    }
    for(var r = a[0], i = 0, j; i < l-1 >> 1; i = j){
      j = i + i + 1;
      if(a[j] > a[j+1])j++;
      if(a[j] >= x)break;
      a[i] = a[j];
    }
    a[i] = x;
    return [r, map.get(r).pop()];
  }
  get size(){
    return this.a.length;
  }
  get top(){
    return this.a[0];
  }
}

const mx = 2500;

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var [n,m,s] = nexts(3);
  var g = new dijkstra(mx * n);
  for(var i = 0; i < m; i++){
    var [u,v,a,b] = nexts(4);
    u--,v--;
    u *= mx, v *= mx;
    for(var j = mx; j-- > a;){
      g.add(u+j,v+j-a,b);
      g.add(v+j,u+j-a,b);
    }
  }
  for(var i = 0; i < n; i++){
    var [c,d] = nexts(2);
    var v = i * mx;
    for(var j = 0; j < mx-1; j++)g.add(v+j,v+Math.min(mx-1,j+c),d);
  }
  var dp = g.solve(Math.min(mx-1,s));
  var ans = xArray(1e18,n);
  for(var i = 1; i < n; i++){
    var v = i*mx;
    for(var j = 0; j < mx; j++){
      ans[i] = Math.min(ans[i],dp[v+j]);
    }
  }
  return ans.slice(1).join("\n");
}

Measured memory_bytes: 130496
#include    <iostream>
#include    <cmath>
#include    <cstdio>

static double PI = 3.14159265;

using namespace std;

double dtor(double);

int main() {
    int d, a;
    double f = 90.0, x = 0.0, y = 0.0;

    while(true) {
        scanf("%d,%d", &d, &a);
        if(d == 0 && a == 0) { break; }

        x += d * cos(dtor(f));
        y += d * sin(dtor(f));

        f -= a;
    }
    printf("%d\n%d\n", (int)x, (int)y);
}

double dtor(double deg) {
    return (deg * PI) / 180;
}


Measured memory_bytes: 3356
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
 
int main(){
    vector<int> num(3);
    for(int i = 0; i < 3; i++){
        cin >> num[i];
    }
    sort(num.begin(), num.end());
    cout << num[0] * num[1] * 0.5 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

const ll INF = 1LL << 50;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> X(N);
    rep(i, 0, N) {
        cin >> X[i];
    }
    ll ans = INF;
    rep(p, 1, 101) {
        ll now_ans = 0;
        rep(i, 0, N) {
            now_ans += (ll)(p - X[i]) * (ll)(p - X[i]);
        }
        chmin(ans, now_ans);
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
	int N;
	cin >> N;
	string S, T;
	cin >> S >> T;
	rep(i, N) {
		cout << S[i];
		cout << T[i];
	}
}

Measured memory_bytes: 256
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(A[K-1])


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
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<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n,k;
    cin>n>k;
    string s;
    cin>s;
    vl rl;
    int last=0;
    if(s[0]=='0')rl.push_back(0);
    REP(i,1,n){
        if(s[i]!=s[i-1]){
            rl.push_back(i-last);
            last=i;
        }
    }
    rl.push_back(n-last);
    if(!(rl.size()%2))rl.push_back(0);
    cerr<rl<endl;
    int le=(rl.size()+1)/2;
    vl cs(le+1);
    vl csr(le+1);
    int c=0;
    REP(i,le){
        csr[i]+=c;
        cerr<c<endl;
        cs[i]=c+=rl[i*2];
        if(i+1<le){
            c+=rl[i*2+1];
        }
    }
    cs[le]=cs[le-1];
    //csr[le]=csr[le-1];
    cerr<<cs<<endl;
    cerr<csr<endl;
    ll ma=0;
    chmin(k,le-1);
    REP(i,le-k+1){
        chmax(ma,cs[i+k]-csr[i]);
    }
    cout<ma<endl;

    return 0;
}


Measured memory_bytes: 1988
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M=5e5+5;
int bit[M],c[M],l[M],r[M],ans[M],ind[M];
stack<int> st[M];
bool cmp(int x,int y)
{
	return r[x]>r[y];
}
int query(int x)
{
	int ans=0;
	while(x)
	{
		ans+=bit[x];
		x-=(x&(-x));
	}
	return ans;
}
void update(int x,int z,int n)
{
	for(;x<=n;x+=(x&(-x)))
	{
		bit[x]+=z;
	}
}
int main()
{
	int n,q;
	cin>>n>>q;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
		st[c[i]].push(i);
	}
	for(int i=1;i<=n;i++)
	{
		if(sz(st[i]))
		{
			int z = st[i].top();
			update(z,1,n);
		}
	}
	for(int i=1;i<=q;i++)
	{
		cin>>l[i]>>r[i];
		ind[i]=i;
	}
	sort(ind+1,ind+q+1,cmp);
	int j=1;
	for(int i=n;i>=1;i--)
	{
		while(j<=q && r[ind[j]]==i)
		{
			ans[ind[j]] = query(i)-query(l[ind[j]]-1);
			j++;
		}
		update(i,-1,n);
		st[c[i]].pop();
		if(sz(st[c[i]]))
		{
			int x = st[c[i]].top();
			update(x,1,n);
		}
	}
	for(int i=1;i<=q;i++)
		cout<<ans[i]<<"\n";
	return 0;
}

Measured memory_bytes: 353176
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

class BIT:
    """
    a[1]~a[n]の数列を想定
    """

    def __init__(self,n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def add(self,index,x):
        """
        a[index]にxを加算
        """
        while index <= self.size:
            self.tree[index] += x
            index += index & (-index)
 
    def sum(self,index):
        """
        a[1]~a[index]の和
        """
        s = 0
        while index:
            s += self.tree[index]
            index -= index & (-index)
        return s
 
    def search(self,value):
        """
        sum(index) >= value を満たす最小のindex
        sum(n) < value のとき n+1 を返す
        """
        i = 0
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i+step <= self.size and s + self.tree[i+step] < value:
                i += step
                s += self.tree[i]
            step >>= 1
        return i + 1

N,Q = LI()
c = LI()
l,r = LIR(Q,2)

x = []
for i in range(Q):
    x.append((i,l[i],r[i]))
x.sort(key=lambda x: x[2])

bit = BIT(N)

ans = [0]*Q
last = [-1]*(N+1)
right = -1 # 確認し終わった右端
for i in range(Q):
    for j in range(right+1,x[i][2]):
        bit.add(j+1,1)
        if last[c[j]] != -1:
            bit.add(last[c[j]]+1,-1)
        last[c[j]] = j
    right = x[i][2]-1
    ans[x[i][0]] = bit.sum(x[i][2]) -  bit.sum(x[i][1]-1)

for a in ans:
    print(a)

Measured memory_bytes: 239964
#include <iostream>

using namespace std;

int freq[100000 + 5];

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

    for (int i = 1; i <= N; ++ i) {
        int val;
        cin >> val;
        ++ freq[val];
    }

    int evens = 0;
    for (int i = 1; i <= 100000; ++ i) {
        while (freq[i] > 2) {
            freq[i] -= 2;
            N -= 2;
        }

        if (freq[i] == 2)
            ++ evens;
    }

    if (evens % 2 == 0)
        N -= evens;
    else
        N -= (evens + 1);

    cout << N << '\n';
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main()
{
  int A,B,C;

  scanf("%d %d",&A,&B);
  C=A+B;

  if(A%3==0 ||B%3==0 ||C%3==0)printf("Possible\n");
  else printf("Impossible\n");

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Deque;
import java.util.LinkedList;
import java.lang.StringBuilder;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		Deque<Byte> train = new LinkedList<>();
		while (sc.hasNext()) {
			byte n;
			if((n = sc.nextByte()) != 0){
				train.push(n);
			}else{
				sb.append(train.poll());
				sb.append('\n');
			}
		}
		System.out.print(sb.toString());
	}
}



Measured memory_bytes: 26020
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
#include <list>
#include <iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
typedef pair<string,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
const ll MODatc = 1000000007;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
bool pairCompare2(P firstElof,P secondElof){
    return (firstElof.second)%1000>(secondElof.second)%1000;
}
bool less_mod1000(int lhs, int rhs) {
  if ((lhs - rhs) % 1000 != 0)
    return lhs % 1000 < rhs % 1000;
  else // 5で割った余りが等しいなら普通に大小比較する
    return lhs < rhs;
}
string Alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alpha="abcdefghijklmnopqrstuvwxyz";
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll a,b;cin>>a>>b;
    if(a>b*2)cout<<a-b*2<<endl;
    else cout<<0<<endl;
}


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 t = sc.nextInt();
        int a = sc.nextInt();
        int[] hArr = new int[n];

        for (int i = 0; i < n; i++) {
            hArr[i] = sc.nextInt();
        }

        double diff = Math.abs((double) a - ((double)t - (double)hArr[0] * 0.006));
        int ans = 1;
        for (int i = 1; i < hArr.length; i++) {
            double tmpDiff = Math.abs((double) a - ((double)t - (double)hArr[i] * 0.006));
            if (diff > tmpDiff) {
                diff = tmpDiff;
                ans = i + 1;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 22608
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                count += 1
print(count)

Measured memory_bytes: 3064
/* Binary Search */
#include <stdio.h>

int A[1000000], n;

int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;

    while(left < right){
        mid = (left + right) / 2;
        if(key == A[mid]){ return 1; }
        if(key > A[mid]){ left = mid + 1; }
        else if(key < A[mid]){ right = mid;}
    }
    return 0;
}

int main()
{
    int i, q, k, sum=0;
    
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &A[i]);
    }

    scanf("%d", &q);
    for(i=0; i<q; i++){
        scanf("%d", &k);
        if(binarySearch(k)){ sum++; }
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 2100
N,K,Q=map(int, input().split())
A=[]
for i in range(Q):
    a=int(input())
    A.append(a)
points=[0]*N
for i in range(Q):
    points[A[i]-1]+=1
for p in points:
    if p+K-Q>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 8632