akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    int x, a;
    cin >> x >> a;
    cout << (x < a ? 0 : 10) << endl;    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
const int mod=10007;

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  int sum=1;
  for(int i=0;i<N-1;i++){
    if(S[i]!=S[i+1]){sum++;}
  }
  cout<<sum<<endl;
  return 0;  
}

Measured memory_bytes: 3700
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
struct node{
	double v,t;
}a[500010];
node q[500010];int n,L,head,tail;
double tot=0,totv=0;
int main(){
	n=read();L=read();int i;ll lim;
	for(i=1;i<=n;i++) a[i].t=read(),a[i].v=read();
	tot+=(a[1].v*a[1].t);totv+=a[1].v;
	q[tail++]=(node){a[1].v,a[1].t};
//	cout<<"first "<<tot<<' '<<totv<<'\n';
	printf("%.10lf\n",tot/totv);
	for(i=2;i<=n;i++){
		lim=a[i].v;
		while(head<tail&&lim>=q[head].v){
			lim-=q[head].v;
			tot-=q[head].v*q[head].t;
			totv-=q[head].v;
			head++;
		}
		q[head].v-=lim;
		tot-=lim*q[head].t;
		totv-=lim;
//		cout<<"after dec "<<i<<' '<<tot<<' '<<totv<<' '<<lim<<' '<<q[head].t<<'\n';
		q[tail]=(node){a[i].v,a[i].t};
		tot+=a[i].v*a[i].t;
		totv+=a[i].v;
//		cout<<"after add "<<i<<' '<<tot<<' '<<totv<<'\n';
		while(head<tail&&q[tail].t<q[tail-1].t) 
			q[tail-1]=(node){q[tail].v+q[tail-1].v,(q[tail].t*q[tail].v+q[tail-1].t*q[tail-1].v)/(q[tail].v+q[tail-1].v)},tail--;
		printf("%.10lf\n",tot/totv);
		tail++;
	}
}

Measured memory_bytes: 26112
#include <stdio.h>

int main(void)
{
	int i,j,a;
	for(i=1; i<=9; i++){
		for(j=1;j<=9;j++){
			a=i*j;
			printf("%dx%d=%d\n",i,j,a);
		}
	}
	return 0;
}



Measured memory_bytes: 2012
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 2929000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1234567890


int main(){
    ll i,j;
	ll n,a,b;
	cin>>n>>a>>b;
	ll x[n];
	ll ans=0;
	for(i=0;i<n;i++) cin>>x[i];
	for(i=1;i<n;i++){
		ans+=min(b,a*(x[i]-x[i-1]));
	}
	cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define MAX_N 10000

bool search(vector<int>& A, int n, int key) {
  int i = 0;
  A[n] = key;
  while( A[i] != key )
    i++;
  return i != n;
}

int main() {
  int n, q, key, sum = 0;
  vector<int> A;
  cin >> n;
  A.reserve(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> key;
    if (search(A, n, key))
      sum++;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3132
import java.io.*;
import java.util.*;
//import java.util.stream.*;;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        StringBuilder a = new StringBuilder(br.readLine());
        StringBuilder b = new StringBuilder(br.readLine());
        StringBuilder c = new StringBuilder(br.readLine());
        String s = "";
        char x = a.charAt(0);
        while (true) {
            if (x == 'a') {
                if (a.length() == 0) {
                    s = "A";
                    break;
                } else {
                    x = a.charAt(0);
                    a.delete(0, 1);
                }
            } else if (x == 'b') {
                if (b.length() == 0) {
                    s = "B";
                    break;
                } else {
                    x = b.charAt(0);
                    b.delete(0, 1);
                }
            } else if (x == 'c') {
                if (c.length() == 0) {
                    s = "C";
                    break;
                } else {
                    x = c.charAt(0);
                    c.delete(0, 1);
                }
            }
        }
        System.out.println(s);
        bw.flush();
    }
}


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

class Program
{
    static void Main(string[] args)
    {
        var S = Console.ReadLine();

        var condition1Array = new char[] { 'R', 'U', 'D' };

        var condition2Array = new char[] { 'L', 'U', 'D' };

        var evenArray = S.Select((item, index) => new { Item = item, Index = index })
            .Where(x => x.Index % 2 == 0)
            .Select(x => x.Item)
            .ToArray();

        var oddArray = S.Select((item, index) => new { Item = item, Index = index })
            .Where(x => x.Index % 2 == 1)
            .Select(x => x.Item)
            .ToArray();

        var isCondition1 = evenArray.All(x => condition1Array.Contains(x));
        var isCondition2 = oddArray.All(x => condition2Array.Contains(x));

        if(isCondition1 && isCondition2)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13524
#include <iostream>

using namespace std;

int main()
{
   char ch;
   cin>>ch;
   if(ch>='a'&&ch<='z')
   {
       switch (ch)
           {
           case 'a':
            cout<<"vowel"<<endl;
            break;
           case 'e':
            cout<<"vowel"<<endl;
            break;
           case 'u':
            cout<<"vowel"<<endl;
            break;
           case 'i':
            cout<<"vowel"<<endl;
            break;
           case 'o':
            cout<<"vowel"<<endl;
            break;
           default:
            cout<<"consonant"<<endl;
            break;
           }
   }
    return 0;
}


Measured memory_bytes: 3604
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){function t(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=[],n=!0,o=!1,u=void 0;try{for(var i,f=e[Symbol.iterator]();!(n=(i=f.next()).done)&&(t.push(i.value),!r||t.length!==r);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==f.return||f.return()}finally{if(o)throw u}}return t}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}e.exports=function(e){for(var r=t(e.split("\n")[0].split(" ").map(function(e){return Number(e)}),2),n=r[0],o=r[1],u=o,i=0;i<n-1;i++)u*=o-1;console.log(u)}},function(e,r){e.exports=require("fs")}]);

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

int main() {
    int N,D;
    cin>>N>>D;
    D=2*D+1;
    if(N%D==0){
        cout<<N/D<<endl;
    }else{
        cout<<(N/D)+1<<endl;
    }
return 0;}
/*
g++ code.cpp
./a.out
*/

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

using namespace std;





int main(){
    int a[21]={0},l;
    while(cin>>a[0]>>l){
        if(a[0]==0&&l==0)break;
        
        int arr[l];
        int now=0;
        while(1){
            int flag=0;
            int temp = a[now];
            for(int i=l-1; i>=0; i--){
                arr[i]=temp%10;
                temp/=10;
            }
            
            sort(arr, arr+l);
            
            int max=0;
            int min=0;
            for(int i=0; i<l; i++){
                min*=10;
                max*=10;
                min+=arr[i];
                max+=arr[l-1-i];
            }
            temp= max-min;
            now++;
            a[now]=temp;
            //cout<<now<<" "<<a[now]<<endl;

            for(int i=0; i<now; i++){
                if(a[i]==a[now]){
                    cout<<i<<" "<<a[i]<<" "<<now-i<<endl;
                    flag++;
                    break;
                }
            }
            if(flag!=0)break;
            
        }
        
        
        //        for(int i=0; i<l; i++){
        //            cout<<a[i];
        //        }
        
        
    }
    
}

Measured memory_bytes: 1180
# -*- coding: utf-8 -*-
import itertools
def to_bool(i):
    if i == '1':
        return True
    return False

# 整数の入力
n = int(input())
f = []
for i in range(n):
    f.append(list(to_bool(i) for i in input().split()))

p = []
for i in range(n):
    p.append(list(int(i) for i in input().split()))

result = None
for eigyou in itertools.product((True,False), repeat=10):
    if sum(1 for a in eigyou if a) == 0:
        continue
    goukei = None
    for i in range(n):
        if goukei is None:
            goukei = p[i][sum(1 for a,b in zip(eigyou,f[i]) if a and b)]
        else:
            goukei += p[i][sum(1 for a,b in zip(eigyou,f[i]) if a and b)]
    if result is None:
        result = goukei
    if result < goukei:
        result = goukei
    
print(result)


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
vector<int> a[N];
int d[N * 3];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int k = 0; k < m; ++k) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    a[x].push_back(y);
  }
  int s, t;
  scanf("%d%d", &s, &t);
  --s; --t;
  priority_queue<ii, vector<ii>, greater<ii>> Q;
  fill(d, d + n * 3, INF);
  d[s * 3] = 0;
  Q.push({d[s * 3], s * 3});
  while (!Q.empty()) {
    int dd = Q.top().first, u = Q.top().second;
    Q.pop();
    if (dd != d[u]) continue;
    int x = u / 3, k = u % 3;
    for (auto& y : a[x]) {
      int v = y * 3 + (k + 1) % 3;
      if (d[v] > d[u] + 1) {
        d[v] = d[u] + 1;
        Q.push({d[v], v});
      }
    }
  }
  int ret = d[t * 3] == INF ? -1 : d[t * 3] / 3;
  printf("%d\n", ret);
  return 0;
}


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

int main(){
  int k, s;
  int x, y, z;
  int ans = 0;
  cin >> k >> s;
  for (x = 0; x <= k; x++) {
    for (y = 0; y <= k; y++) {
      z = s - x - y;
      if (0 <= z && z <= k) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<iomanip>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
struct matrix{
	int n,m;
	ll a[5][5];
	matrix operator *(const matrix &b){
		matrix ret;ret.n=n;ret.m=b.m;
		memset(ret.a,0,sizeof(ret.a));
		for(int i=1;i<=n;i++)	
			for(int j=1;j<=b.m;j++){
				for(int k=1;k<=m;k++){
					ret.a[i][j]+=(a[i][k]*b.a[k][j])%mod;
					ret.a[i][j]%=mod;
				}
			}
		return ret; 
	}
};
int n,m,bl=0;
ll k;
ll pow1(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1==1)
			ret=ret*a%mod;
		a=a*a%mod;
		b=b>>1;
	}
	return ret%mod;
}
matrix pow1(matrix a,ll b){
	matrix ret;
	ret.n=ret.m=2;memset(ret.a,0,sizeof(ret.a));ret.a[1][1]=ret.a[2][2]=1;
	while(b){
		if(b&1==1)
			ret=ret*a;
		a=a*a;
		b=b>>1;
	}
	return ret;
}
bool ch[1010][1010];
int line(){
	int ret=0;
	for(int i=1;i<=n;i++){
		if(ch[i][1]&&ch[i][m])
			ret++;
	}
	return ret;
}
int row(){
	int ret=0;
	for(int i=1;i<=m;i++){
		if(ch[1][i]&&ch[n][i])
			ret++;
	}
	return ret;
}
int num_line(){
	int ret=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m-1;j++){
			if(ch[i][j]&&ch[i][j+1])
				ret++;
		}
	}
	return ret;
}
int num_row(){
	int ret=0;
	for(int i=1;i<=n-1;i++)
		for(int j=1;j<=m;j++)
			if(ch[i][j]&&ch[i+1][j])
				ret++;
	return ret;
}
int ad_l,ad_r;
int main(){
	cin>>n>>m>>k;
	if(k==0||k==1){
		cout<<1;
		return 0;
	}
	for(int i=1;i<=n;i++){
		string s;
		cin>>s;
		for(int j=1;j<=m;j++){
			if(s[j-1]=='.')
				ch[i][j]=false;
			else{
				bl++;
				ch[i][j]=true;
			}
		}
	}
	ad_l=line(),ad_r=row();
	if(ad_l&&ad_r){
		cout<<1;
	}
	else if(!ad_l&&!ad_r){
		cout<<pow1(bl,k-1);
	}
	else if(!ad_l&&ad_r){
		matrix cur,ans;
		cur.n=cur.m=2;
		cur.a[1][1]=bl;
		cur.a[1][2]=-num_row();
		cur.a[2][1]=0;
		cur.a[2][2]=ad_r;
		ans.n=2;ans.m=1;
		ans.a[1][1]=1;
		ans.a[2][1]=1;
		cur=pow1(cur,k-1);
		ans=cur*ans;
		cout<<(ans.a[1][1]+2*mod)%mod;
	}
	else{
		matrix cur,ans;
		cur.n=cur.m=2;
		cur.a[1][1]=bl;
		cur.a[1][2]=-num_line();
		cur.a[2][1]=0;
		cur.a[2][2]=ad_l;
		ans.n=2;ans.m=1;
		ans.a[1][1]=1;
		ans.a[2][1]=1;
		cur=pow1(cur,k-1);
		ans=cur*ans;
		cout<<(ans.a[1][1]+2*mod)%mod;
	}
	return 0;
}/*
4 4 10000000000
....
.##.
.##.
....
*/


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

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};


mint fact(ll n, ll r){
    mint res = n;
    for(ll i = n - 1; i >= n - r + 1; i--){
        res *= i;
    }
    return res;
}

int main() {
    ll n,a,b;
    cin >> n >> a >> b;

    mint ans(2);
    ans = ans.pow(n) - 1;
    mint A = fact(n,a) / fact(a,a);
    mint B = fact(n,b) / fact(b,b);
    ans = ans - A - B;
    cout << ans.x << endl;
}


Measured memory_bytes: 256
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for i, d in enumerate(zip(*a)):
        s = "".join(d).count("1")
        ans += s * (n - s) * pow(2, 59 - i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

int main() {
    int n;
    long ans=1;
    cin >> n;
    for (long i = 1; i <= n; i++) {
        ans *= i;
        ans %= ((long)pow(10, 9.0)+7);
    }
    cout << ans << endl;
}

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

int main() {
  int N , A , B;
  cin >> N >> A >> B;
  
  if ( N * A > B ){
    cout << B << endl;
  }
   else if ( N * A == B ){
    cout << B << endl;
  }
   else if ( N * A < B ){
    cout << N * A << endl;
  }
  
 
}

Measured memory_bytes: 256
#include<stdio.h>
int main (void){
  int a,b,c,d;
  scanf("%d %d %d",&a,&b,&c);
  if(a>b){
    d=a;
    a=b;
    b=d;
  }
  if(b>c){
    d=b;
    b=c;
    c=d;
  }
  if(a>b){
    d=a;
    a=b;
    b=d;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
import java.util.*;
import java.math.BigInteger;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) A[i] = sc.nextLong();
        int[] digit = new int[60];
        for (long a: A) {
            char[] binary = Long.toBinaryString(a).toCharArray();
            for (int i = 0; i < binary.length; i++) {
                digit[i] += (long) (binary[binary.length-1-i] - '0');
            }
        }
        BigInteger ans = BigInteger.ZERO;
        BigInteger mod = new BigInteger((int)(1e9+7) + "");
        BigInteger pow = BigInteger.ONE;
        BigInteger n = new BigInteger(N+"");
        for (int i = 0; i < 60; i++) {
            BigInteger d = new BigInteger(digit[i] + "");
            ans = ans.add(d.multiply(n.subtract(d)).multiply(pow));
            ans = ans.mod(mod);
            pow = pow.multiply(new BigInteger("2"));
            pow = pow.mod(mod);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 100424
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vl a(n);
	cin>>a;
	int v=INF,l=0,r=sum(a);
	rep(i,n-1){
		l+=a[i];
		r-=a[i];
		chmin(v,abs(l-r));
	}
	puta(v);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	cin >> A >> B;
	for (int i = A; i < B+1; i++) {
		S = to_string(i);
		bool flag = 1;
		for (int i = 0; i < S.size(); i++) {
			if (S[i] != S[S.size() - 1 - i]) {
				flag = 0;
				break;
			}
		}
		if (flag)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int t[105] = {};
    for( int i = 0; i < 105; ++i ) {
        if( a <= i && i < b ) ++t[i];
        if( c <= i && i < d ) ++t[i];
    }
    int cnt = 0;
    for( int i = 0; i < 105; ++i ) {
        if( t[i] == 2 ) ++cnt;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
A,B,C = map(int,input().split())
a = max(A,B,C)
c = min(A,B,C)
b = A+B+C-a-c
ans = a-b
if (b-c)%2==0:
    print(ans + (b-c)//2)
else:
    print(2 + ans + (b-c)//2)

Measured memory_bytes: 61840
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/26/20 20:17:32
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll n,m,s; cin>>n>>m>>s;
  struct Train {
    ll s, c, d;
    Train(ll s,ll c,ll d):s(s),c(c),d(d){}
    bool operator>(const Train& x) const {return d>x.d;}
  };
  vector<Train> graph[n];
  for (int i = 0; i < m; i++) {
    ll u,v,a,b; cin>>u>>v>>a>>b; u--; v--;
    graph[u].emplace_back(v,a,b);
    graph[v].emplace_back(u,a,b);
  }
  for (int i = 0; i < n; i++) {
    int c,d; cin>>c>>d;
    graph[i].emplace_back(i,-c,d);
  }
  constexpr ll MAX = 250;
  constexpr ll INF = 1e18;
  vector<array<ll, MAX+1>> dp(n);
  for (auto& arr:dp) arr.fill(INF);
  dp[0][min(s,MAX)] = 0;
  priority_queue<Train, vector<Train>, greater<>> qs;
  qs.emplace(0,s,0);
  while (not qs.empty()) {
    auto [s,c,d] = qs.top(); qs.pop();
    if (d > dp[s][min(c,MAX)]) continue;
    for (auto t:graph[s]) {
      if (c-t.c<0) continue;
      if (d+t.d >= dp[t.s][min(c-t.c,MAX)]) continue;
      dp[t.s][min(c-t.c,MAX)] = d+t.d;
      qs.emplace(t.s, c-t.c, d+t.d);
    }
  }
  for (int i = 1; i < n; i++) {
    cout << *min_element(dp[i].begin(), dp[i].end()) << endl;
  }

  return 0;
}


Measured memory_bytes: 3816
#include<stdio.h>

int main(){
    int i,n,d=0;
    scanf("%d",&n);
    int a[n],b[n-1];
    for (i = 0; i < n; i++){
        a[i]=10000000;
    }
    for (i = 0; i < n - 1; i++){
        scanf("%d",&b[i]);
    }
    for (i = 0; i < n - 1; i++){
        if(a[i]>b[i]){
            a[i]=b[i];
        }
        if(a[i+1]>b[i]){
            a[i+1]=b[i];
        }
    }
    for (i = 0; i < n; i++){
        d=d+a[i];
    }
    printf("%d\n",d);
}


Measured memory_bytes: 128
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<set>
#define N 10005
#define mod 1000000007
typedef long long ll;
using namespace std;

int main()
{
    string s;
    cin>>s;
    int cnt0=0,cnt1=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='0')cnt0++;
        if(s[i]=='1')cnt1++;
    }
    cout<<min(cnt1,cnt0)*2<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long
#define ld long double
#define vi vector<int>
#define si set<int>
#define pb push_back
#define lp(i,a,b) for(int i = a ; i <= b ; i ++)
#define rlp(i,a,b) for(int i = b ; i >= a ; i --)
#define a_sort(v) sort(v.begin(), v.end())
#define d_sort(v) sort(v.rbegin(), v.rend())
#define pii pair<int,int>
#define pi 3.14159265358979323846264338327950
using namespace std ;
// #define debug

const int MOD = 1E9 + 7 ;
const int N = 1E5 ;

int main() {
    #ifdef debug
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif // debug
    optimize

    int sum = 15 , n ;
    lp(i, 1, 5) {
        cin >> n ;
        sum -= n ;
    }
    cout << sum << endl ;
}


Measured memory_bytes: 3600
#include <iostream>
int main() {
  int a, b;
  std::cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a+b) % 3 ==0)
    std::cout << "Possible" << std::endl;
  else
    std::cout << "Impossible" << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

int main(){
    ll N;
    cin >> N;   
    deque<ll> deq;
    for(ll i=1;i<10;i++){
        deq.emplace_back(i)
    ;}
    ll ans=0;
    for(ll i=0;i<N;i++){
        ans=deq.front();
        deq.pop_front();
        ll k=ans%10;
        if(1<=k&&k<=8){
            deq.emplace_back(ans*10+k-1);
            deq.emplace_back(ans*10+k);
            deq.emplace_back(ans*10+k+1);
        }
        else if(k==0){
            deq.emplace_back(ans*10+k);
            deq.emplace_back(ans*10+k+1);
        }
        else if(k==9){
            deq.emplace_back(ans*10+k-1);
            deq.emplace_back(ans*10+k);
        }
    ;}
    cout<<ans<<endl;


return 0;
}


Measured memory_bytes: 1792
//Day dreamer
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
string divide[4] = {"dream","dreamer","erase","eraser"};
int main()
{
    string S;
    cin >> S;

    //後ろから確認する
    reverse(S.begin(),S.end());
    for(int i = 0; i<4;++i) reverse(divide[i].begin(),divide[i].end());

    //端から切っていく
    bool can = true;
    for ( int i =0;i < S.size();){

        //切り分けられるか判定
        bool can_divide = false; 
        for (int j = 0; j< 4;++j){
            string d= divide[j];
            if(S.substr(i,d.size())==d){
                can_divide = true;
                i += d.size();
            }
        }
        if (!can_divide) {
            can = false;
            break;
        }
    }

    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
import Control.Applicative
import qualified Control.Monad as Monad

main = calculator

calculator :: IO ()
calculator = do
    [a, op, b] <- words <$> getLine
    Monad.when (op /= "?") $ do
        print $ calculate (read a) op (read b)
        calculator

calculate :: Int -> String -> Int -> Int
calculate a op b = interpret op
    where interpret "+" = a + b
          interpret "-" = a - b
          interpret "*" = a * b
          interpret "/" = a `div` b

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

my_list = [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(my_list[K-1])


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(){
  int n, m, d;
  cin >> n >> m >> d;
  if(d) printf("%.12f\n",(double)(n-d)*2/n/n*(m-1));
  else printf("%.12f\n",(double)(n-d)/n/n*(m-1));
  return 0;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ll n,A,B;
  cin >> n;
  cin >> A >> B;
  VI P(n);
  int a,b,c;
  a = b = c = 0;
  rep(i,n){
    cin >> P[i];
    if(P[i] <= A) a++;
    if(A+1 <= P[i] && P[i] <= B) b++;
    if(B+1 <= P[i]) c++;
  }
  cout << min(a,min(b,c)) << endl;

  return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
alpha = 0
m = str(A)[-1]
menu = [[A, int(str(A)[-1])], [B, int(str(B)[-1])],
        [C, int(str(C)[-1])], [D, int(str(D)[-1])],
        [E, int(str(E)[-1])]]
menu.sort(key = lambda x:x[1])
f = False
ans = 0
for time, i in menu:
    if i != 0 and not f:
        ans += time
        f = True
    else:
        ans += (time + 9) // 10 * 10
print(ans)


Measured memory_bytes: 3064
// Problem : D - Checker
// Contest : AtCoder Regular Contest 089
// URL : https://atcoder.jp/contests/arc089/tasks/arc089_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define cerr if(1)cerr
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define sort(a, n) sort(a + 1, a + n + 1)
#define temptts template <class T, class... Ts>

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;

int n, k, ans = 0, dp[2002][2002];

int sum(int x1, int y1, int x2, int y2) {
	return dp[x2][y2] - dp[x1][y2] - dp[x2][y1] + dp[x1][y1];
}

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n >> k;
	for (int i = 1, x, y; i <= n; i++) {
		char c;
		cin >> x >> y >> c;
		if (c == 'W') {
			x += k;
		}
		x %= k << 1;
		y %= k << 1;
		dp[x + 1][y + 1]++;
	}
	for (int x = 1; x <= k << 1; x++) {
		for (int y = 1; y <= k << 1; y++) {
			dp[x][y] += dp[x - 1][y] + dp[x][y - 1] - dp[x - 1][y - 1];
		}
	}
	for (int x = 1; x <= k; x++) {
		for (int y = 1; y <= k; y++) {
			int csum = sum(x + k, y + k, k << 1, k << 1);
			csum += sum(0, 0, x, y) + sum(x, y, x + k, y + k);
			csum += sum(0, y + k, x, k << 1) + sum(x + k, 0, k << 1, y);
			ans = max({ans, csum, n - csum});
		}
	}
	cout << ans;
}


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

class Program
{
    static void Main(string[] args)
    {
        // 入力
        var n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var b = new List<int>() { };
        if (n % 2 == 0)
        {
            for (int i = n - 1; i >= 0; i--)
            {
                if (i % 2 == 1)
                {
                    b.Add(a[i]);
                }
            }
            for (int i = 0; i < n; i++)
            {
                if (i % 2 == 0)
                {
                    b.Add(a[i]);
                }
            }
        }
        else
        {
             for (int i = n - 1; i >= 0; i--)
            {
                if (i % 2 == 0)
                {
                    b.Add(a[i]);
                }
            }
            for (int i = 0; i < n; i++)
            {
                if (i % 2 == 1)
                {
                    b.Add(a[i]);
                }
            }
        }

        for (int i = 0; i < n; i++)
        {
            Console.Write(b[i]);
            Console.Write(" ");
        }
    }
}


Measured memory_bytes: 39224
N = int(input())
B = list(map(int, input().split()))
A = []
A.append(B[0])
for i in range(1, N-1):
    A.append(B[i])
    if A[i]>B[i-1]:
        A[i] = B[i-1]
A.append(B[-1])
print(sum(A))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;
int n,k;
llong T[MAX];
int check(llong P)
{
    int i=0;
    for(int j=0;j<k;j++)
    {
        llong s=0;
        while(s+T[i]<=P)
        {
            s+=T[i];
            i++;
            if(i==n)return n;
        }
    }
    return i;
}
int solve()
{
    llong left=0;
    llong right=100000*10000;
    llong mid;
    while(right-left>1)
    {
        mid=(left+right)/2;
        int v=check(mid);
        if(v>=n)right=mid;
        else left=mid;
    }
    return right;
}
main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>T[i];
    llong ans=solve();
    cout<<ans<<endl;
}

Measured memory_bytes: 3852
import numpy as np
K=int(input())

n=np.zeros((10,11),dtype=int)
for i in range(9):
	n[i+1,1]=1
	n[i+1,2]=3
n[9,2]=2

for i in range(3,11):
	n[1,i]=n[2,i-1]+np.sum(n[1,:])+1
	n[2,i]=n[1,i-1]+n[2,i-1]+n[3,i-1]
	n[3,i]=n[4,i-1]+n[2,i-1]+n[3,i-1]
	n[4,i]=n[4,i-1]+n[5,i-1]+n[3,i-1]
	n[5,i]=n[4,i-1]+n[5,i-1]+n[6,i-1]
	n[6,i]=n[5,i-1]+n[6,i-1]+n[7,i-1]
	n[7,i]=n[7,i-1]+n[8,i-1]+n[6,i-1]
	n[8,i]=n[7,i-1]+n[8,i-1]+n[9,i-1]
	n[9,i]=n[8,i-1]+n[9,i-1]

i=1
j=1

def ninecheck(i,j,K,ans):
	for k in range(2):
		K-=n[i-1+k,j]
		if K<=0:
			K+=n[i-1+k,j]
			ans+=(i-1+k)*(10**(j-1))
			if j==1:
				a=ans
				return a
			j-=1
			i=i-1+k
			if i==1:
				a=onecheck(i,j,K,ans)
				return a
			elif i==9:
				a=ninecheck(i,j,K,ans)
				return a
			else:
				a=normalcheck(i,j,K,ans)
				return a

def onecheck(i,j,K,ans):
	K-=1
	if K==0:
		a=ans
		return a
	for k in range(1,j+1):
		K-=n[1,k]
		if K<=0:
			K+=n[1,k]
			ans+=10**(k-1)
			j=k
			if j==1:
				a=ans
				return a
			j-=1
			a=onecheck(i,j,K,ans)
			return a
	i=2
	ans+=i*(10**(j-1))
	j-=1
	a=normalcheck(i,j,K,ans)
	return a

def normalcheck(i,j,K,ans):
	for k in range(3):
		K-=n[i-1+k,j]
		if K<=0:
			K+=n[i-1+k,j]
			ans+=(i-1+k)*(10**(j-1))
			if j==1:
				a=ans
				return a
			j-=1
			i=i-1+k
			if i==1:
				a=onecheck(i,j,K,ans)
				return a
			elif i==9:
				a=ninecheck(i,j,K,ans)
				return a
			else:
				a=normalcheck(i,j,K,ans)
				return a



ans=0
while True:
	K-=n[i,j]
	if K<=0:
		ans+=i*(10**(j-1))
		K+=n[i,j]
		if j==1:
			b=ans
			break
		j-=1
		if i==1:
			b=onecheck(i,j,K,ans)
			break
		elif i==9:
			b=ninecheck(i,j,K,ans)
			break
		else:
			b=normalcheck(i,j,K,ans)
			break
	if i==9:
		i=1
		j+=1
	else:
		i+=1
		continue




print(b)

Measured memory_bytes: 22052
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
ans1=0
for i in range(n):
  for j in a:
    if a[i]<j:
      ans+=1
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]>a[j]:
      ans1+=1
print((ans1*k+ans*(k*(k-1)//2))%(10**9+7))

Measured memory_bytes: 3188
#include<stdio.h>

int main(void){
    int N,M;
    scanf("%d%d",&N,&M);
    int i,a[M],b[M];
    int B[N];
    for(i=0;i<N;i++) B[i] = 0;

    int j;
    for(j=0;j<M;j++){
        scanf("%d%d",&a[j],&b[j]);
    }
    
    for(i=0;i<M;i++){
        B[a[i]-1]++;
        B[b[i]-1]++;
    }

    for(i=0;i<N;i++) printf("%d\n",B[i]);

    return 0;


}

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

int main(){
  cout << fixed << setprecision(10);
  int N;cin>>N;
  double happy=0;
  for(int i=0;i<N;i++){
    double X;string U;cin>>X>>U;
    if(U=="JPY") happy+=X;
    else happy+=X*380000.0;
  }
  cout<<happy<<endl;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
 
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i] & 1 && i & 1)
            sum++;
    }
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 3604
N=int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
    S=input()
    if S =='AC':
        AC += 1
    elif S =='TLE':
        TLE += 1
    elif S =='WA':
        WA += 1
    else:
        RE += 1
print(f"AC x {AC}\nWA x {WA}\nTLE x {TLE}\nRE x {RE}")

Measured memory_bytes: 69972
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val a, b = sc.nextLong
  println(lcm(a, b))

  def lcm(a: Long, b: Long): Long = {
    if (a == 0 || b == 0) 0 else (a * b) / gcd(a, b)
  }

  def gcd(a: Long, b: Long): Long = {
    if (b == 0) a else gcd(b, (a % b))
  }
}


Measured memory_bytes: 27348
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    int sum=0,N;cin>>N;
    vector<int> d(N);
    REP(i,N)cin>>d[i];
    REP(i,N-1)for(int j=i+1;j<N;j++)sum+=(d[i]*d[j]);
    cout<<sum<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
        public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			double i = sc.nextDouble();
			double f1, f2;
			double p = Math.PI;
			f1 = i * i * p;
			f2 = 2 * p * i;
			System.out.printf("%.6f %.6f\n", f1, f2);
	  }
}



Measured memory_bytes: 28420
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<string>
using namespace std;

int main()
{
    int p = 0, i, n;
    string s;
    int t[20];
    cin >> s;
    n = s.size();
    for(i=0;i<n;i++)
    {
        if(s[i] == '0')
        {t[p] = 0;
            p++;
        }
        else if(s[i] == '1')
        {t[p] = 1;
            p++;
        }
        else if(p>0)
        p--;
    }
    for(i=0;i<p;i++)
    {
        cout << t[i];
    }
    // cout << t;
    return 0;
}


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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b){
        cout << c << endl;
    }
    else if(b == c){
        cout << a << endl;
    }
    else{
        cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
if N == 10**5:
  res = 90909
elif 10**4 <= N < 10**5:
  res = N-9090
elif 10**3 <= N < 10**4:
  res = 909
elif 10**2 <= N < 10**3:
  res = N-90
elif 10 <= N < 10**2:
  res = 9
elif 1 <= N < 10:
  res = N
print(res)

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

using namespace std;

int main() {
	int n, k, x[101];
	cin >> n >> k;
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> x[i];
		ans += min(abs(k - x[i]), x[i]) * 2;
	}
	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;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define queue QQQ
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RAnK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn = 1e5+233;
vector<int> edge[maxn];
int n,bit[maxn],f[maxn],ans=0;
void dfs(int u,int fa){
	int l = 0;
	for(auto v:edge[u]){
		if(v==fa) continue;
		dfs(v,u);
		l |= bit[u] & bit[v];
		bit[u] |= bit[v];
	}
	if(!bit[u]) bit[u] = 1;
	else{
		while ((1<<f[u])<l || (1<<f[u])&bit[u]) f[u]++;
		bit[u]=(bit[u]>>f[u]<<f[u])|(1<<f[u]);
    }
    ans=max(ans,f[u]);
}
int main(){
	n = rd();
	Rep(i,1,n) edge[i] . clear();
	rep(i,1,n){
		int a = rd(),b = rd();
		edge[a] . push_back(b);
		edge[b] . push_back(a);
	}
	dfs(1,-1);
	writeln(ans);
	return 0;
}

Measured memory_bytes: 12160
from collections import deque
import sys
input = sys.stdin.readline

mod = 10**9+7
N, K = map(int, input().split())
G = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
visited = [False] * (N+1)
visited[1] = True
queue = deque()
queue.append(1)
ans = K
while queue:
    u = queue.popleft()
    n = K - 1 if u == 1 else K - 2
    for v in G[u]:
        if not visited[v]:
            queue.append(v)
            visited[v] = True
            ans = ans * n % mod
            n -= 1
print(ans)

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

using ll = long long;

int first(int n) {
	while (n > 9) n /= 10;
	return n;
}

int last(int n) {
	return n % 10;
}

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

	ll a[10][10] = {0};
	for (int i = 1; i <= n; i++)
		a[first(i)][last(i)]++;

	int ans = 0;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			ans += a[i][j] * a[j][i];
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
N,M,dp[5001],x,i,j,a;
main(){scanf("%d%d",&N,&M);dp[0]=1;for(;i<N-1;i++){x=i+1>N-i?N-i:i+1;for(j=x;j<=N;j++)dp[j]=(dp[j]+dp[j-x])%M;}for(i=0;i<=N;i++)a=(a+(N-i)*(long long)dp[i])%M;printf("%d\n",a);}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
    int x, ans = 0;

    if(scanf("%d", &x) == 1);

    for(int i = 1; i < x; i++)
    {
        for(int j = 2; j < x; j++)
        {
            if(pow(i,j) <= x && pow(i,j) > ans)
            ans = pow(i,j);
        }
    }

    if(x == 1)
    ans = 1;
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 384
// inputに入力データ全体が入る
function Main(input) {

	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");

	//文字列から10進数に変換するときはparseIntを使います
	var N = parseInt(tmp[0], 10);
	var A = parseInt(tmp[1], 10);
	var B = parseInt(tmp[2], 10);

	var count=0;
	var sum=0;

	var iti;
	var zyuu;
	var hyaku;
	var sen;
	var man;


	for(i=1; i<=N; i++){
		
		iti = i % 10;
		zyuu = (i % 100 - iti)/10 ;
		hyaku = (i % 1000 - iti - zyuu*10)/100;
		sen = (i % 10000 - iti - zyuu*10 - hyaku*100)/1000;
		man = (i - iti - zyuu*10 - hyaku*100 -sen * 1000)/10000;
		
		sum = iti + zyuu + hyaku + sen + man;
		
		if(sum <= B && sum >= A){
		
			count = count +i;
		
		}
		
	}


	//出力
	console.log(count);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7496
n = int(input())
a = list(map(int, input().split()))

def check(tmp, x):
    for i in range(20):
        if (x >> i) & 1 and (tmp >> i) & 1:
            return False
    return True

ans = 0
tmp = 0
r = 0
for l in range(n):
    if r < l:
        r = l
    while r < n and check(tmp, a[r]):
        tmp += a[r]
        r += 1

    ans += r - l
    tmp -= a[l]

print(ans)

Measured memory_bytes: 101028
#include<bits/stdc++.h>
#define N 2000005
int a[N],tr[N];
inline void add(int l,int r,int x,int i,int t) {
	if(l==r) {
		tr[i]=std::max(tr[i],t);
		return ;
	}
	int mid=(l+r)/2;
	if(x<=mid) add(l,mid,x,i<<1,t);
	else add(mid+1,r,x,(i<<1)+1,t);
	tr[i]=std::max(tr[(i<<1)],tr[(i<<1)+1]);
}
inline int query(int l,int r,int L,int R,int i) {
	if(L<=l && r<=R) return tr[i];
	if(R<l || L>r) return 0;
	int mid=(l+r)/2;
	return std::max(query(l,mid,L,R,i<<1),query(mid+1,r,L,R,(i<<1)+1));
}
int main() {
	int n, k;
	std::cin>>n>>k;
	for(int i=1; i<=n; i++) std::cin>>a[i], ++a[i];
	for(int i=1; i<=n; i++)
		add(1,300001,a[i],1,query(1,300001,std::max(1,a[i]-k),std::min(300001,a[i]+k),1)+1);
	printf("%d\n",query(1,300001,1,300001,1));
	return 0;
}

Measured memory_bytes: 9048
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			a.begin(), a.end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define	MAX_QWORD		((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	
	ll ans = 0;
	ll cNum = min(X, Y);
	if (A + B < 2 * C) {
		ans = cNum * (A + B);
	} else {
		ans = cNum * C * 2;
	}

	X -= cNum;
	Y -= cNum;
	if (0 < X) {
		ans += min(X * A, X * C * 2);
	}
	if (0 < Y) {
		ans += min(Y * B, Y * C * 2);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(5*1e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
struct edge { int to, cost; };
int dx[5] = { 0,1,0,-1 }, dy[5] = { 1,0,-1,0 };
map<int, int>factor(int x) {
	map<int, int>res;
	for (int i = 2; i*i <= x; i++) {
		while (x%i == 0) {
			x /= i;
			res[i]++;
		}
	}
	if (x != 1)res[x]++;
	return res;
}
/*--------Library Zone!--------*/

int n, a[214514];
signed main() {
	cin >> n;
	rep(i, n) {
		int b; cin >> b;
		a[b] = i;
	}
	int ans = 0, cnt = 1;
	REP(i, n) {
		if (a[i] < a[i + 1]) {
			cnt++;
		}
		else {
			ans = max(ans, cnt);
			cnt = 1;
		}
	}
	cout << n - max(ans, cnt) << endl;
	endre;
}


Measured memory_bytes: 1792