akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define pb insert
set<ll> ans ;
ll chk (ll n ,ll k ) {


        while(n%k==0) {
            n/=k ;
        }


    if (n%k==1) return 1 ;
        else return 0 ;

}

void divi (ll n) {
  //  vector<ll> ans ;

    for(ll i =1 ;i*i<=n;i++) {
        if (n%i==0) {
            ans.pb(n/i) ;
            if (i!=n/i) ans.pb(i) ;
        }
    }
  ///  sort(ans.begin(),ans.end()) ;
   // for(auto it : ans) cout << it << ' ' ;
   // cout <<endl ;

}

int main() {
    ll n ;
    cin >> n ;
    ll as = 0 , i ;
    divi(n) ;
    divi(n-1) ;
    for(auto it : ans) {
        if (it!=1)
        as+=chk(n,it) ;
      //  if (chk(n,it)) cout << it << ' ' ;
    }

    cout << as << endl ;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
#define N 3
int big(int a,int b){return a>b?a:b;}
int main(void)
{
	int i,j,k=0;
	int a[3],b[3];
	int max=0,take=0;
	for(i=0;i<N;i++)scanf("%d",&a[i]);
	
	for(i=0;i<N;i++)
	{
		for(j=N-1;j>i;j--,k++)
		{
			b[k]=fabs(a[i]-a[j]);
			max=big(max,b[k]);
			take+=b[k];
		}
	}
	printf("%d\n",take-max);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/#define lli long long int
#define uli unsigned long long int
#define INF 9999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,X,Y,N,num=0,sum=0,flag=0;string S,T;
  cin >> N;
  TV(dp,lli,N+10,3,2,-INF);//dp[i番目までみた][あとj回飛ばせる][1個前を取ったか]
  Vec(P,lli,N,0);
  rep(i,0,N)cin >> P[i];
  if(N&1)dp[0][2][0]=0;
  else dp[0][1][0]=0;
  rep(i,1,N+2)rep(j,0,3){
    chmax(dp[i][j][0],dp[i-1][j][1]);
    if(j)chmax(dp[i][j-1][0],dp[i-1][j][0]);
    if(i!=N+1)chmax(dp[i][j][1],dp[i-1][j][0]+P[i-1]);
  }
  Out(dp[N+1][0][0]);
}

Measured memory_bytes: 43836
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A, B, C, D, L, R;
    cin >> A >> B >> C >> D;
    L = A + B;
    R = C + D;
    if (L == R)
        cout << "Balanced" << endl;
    if (L > R)
        cout << "Left" << endl;
    if (L < R)
        cout << "Right" << endl;
}


Measured memory_bytes: 256
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define MX 10000000000
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

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

void solve()
{
	int n;
	cin >> n;
	vector<vector<int>>G(n);
	vector<pair<int, int>>vp;
	for (int i = 0; i < n - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
		vp.emplace_back(a, b);
	}
	vector<int>cs(n, 0);//storing parent-this node colour
	vector<int>used(n, 0);
	queue<int>q;
	q.emplace(0);
	used[0] = 1;

	int k = 0;
	map<pair<int, int>, int>I;
	while (!q.empty())
	{
		int v = q.front();
		q.pop();
		if (k < (int)G[v].size())k = G[v].size();
		int cur = 1;
		for (int u : G[v])
		{
			if (used[u])continue;
			if (cs[v] == cur)cur++;
			cs[u] = I[MP(u, v)] = I[MP(v, u)] = cur++;
			used[u] = 1;
			q.emplace(u);
		}
	}
	cout << k << endl;
	for (auto p : vp)
	{
		cout << I[p] << endl;
	}
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


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

int main(){
    int N; cin >> N;
    int M; cin >> M;
    int a[200010], b[200010];
    bool c[200010]={}, d[200010]={};
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i];
        if(a[i] == 1) c[b[i]]++;
        if(b[i] == N) d[a[i]]++;
    }
    for(int i = 0; i <= N; i++){
        if(c[i] == 1 && d[i] == 1){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;


    return 0;
}
/*
3 2

1 2
2 3
*/

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a[a.size()-1]==b[0] && b[b.size()-1]==c[0]) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3524
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	f := true
	a := make([]int,4)
	for i, e := range s {
		for _, d := range s {
			if e == d {
				a[i]++
			}
		}
	}
	for _, e := range a {
		if e != 2 {
			f = false
		}
	}

	if f {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<stdio.h>

int main()
{
	int A, B;
	
	scanf("%d %d", &A, &B);
	
	if(A+B >= 10)
	{
		printf("error\n");
	}
	else
	{
		printf("%d", A+B);
	}
	
	
	return 0;
}


Measured memory_bytes: 128
N, M = map(int,input().split())
Hs = list(map(int,input().split()))
L = [[] for i in range(N)]
count = 0
for i in range(M):
    A, B = map(int,input().split())
    (L[A-1]).append(Hs[B-1])
    (L[B-1]).append(Hs[A-1])
for i in range(N):
    if not L[i]:
        count+=1
        continue
    if Hs[i] > max(L[i]):
        count += 1
print(count)


Measured memory_bytes: 94584
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
struct block
{
	int w,s,v,idx;
};
bool cmp(block &a, block &b)
{
	return p64(a.s+a.w,a.idx) < p64(b.s+b.w,b.idx);
}
int MAX=3e4;
void solve()
{
	int n;
	cin>>n;
	vector<block> arr(n+1);
	for (int i=1; i<=n; i++)
	{	
		cin>>arr[i].w>>arr[i].s>>arr[i].v;
		arr[i].idx=i;
	}
	sort(arr.begin()+1,arr.end(),cmp);
	vv64 dp(n+1,v64(MAX+100,-INF));
	dp[0][0]=0;
	for (int i=1; i<=n; i++)
	{
		dp[i][0]=0;
		for (int j=1; j<=MAX; j++)
		{
			dp[i][j]=dp[i-1][j];
			if (j>=arr[i].w && j-arr[i].w <= arr[i].s) 
			{
				dp[i][j]=max(dp[i][j],dp[i-1][j-arr[i].w]+arr[i].v);
			}
		}
	}
	ll ans=0;
	for (int i=0; i<=MAX; i++)
	{
		ans=max(ans,dp[n][i]);
	}
	cout<<ans<<endl;
}
int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t=1;
    while (t--)
    {
        solve();
    }
    return 0;   
} 

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

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

    int ans = 0;
    for (int i = 0; 2*i + 1 <= n; i++){
        int num_divider = 0;
        for (int j = 1; j <= 2*i + 1; j++){
            if ((2*i + 1)%j == 0){
                num_divider++;
            }
        }

        if (num_divider == 8){
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S(vector).size()
using namespace std;
typedef long long ll;

int main(void){
  int d, g;
  cin >> d >> g;
  vector<int> p(d), c(d);
  rep(i, d) cin >> p[i] >> c[i];

  int ans = MOD;
  for(int bit = 0; bit < (1<<d); bit++){
    int sum = 0;
    int cnt = 0;
    for(int i = 0; i < d; i++){
      if(bit & (1<<i)){
        sum += p[i] * (i + 1) * 100 + c[i];
        cnt += p[i];
      }
    }
    if(sum >= g){
      ans = min(ans, cnt);
    }
    else{
      for(int i = d - 1; i >= 0; i--){
        if(bit & (1<<i)) continue;
        for(int j = 0; j < p[i]; j++){
          sum += (i + 1) * 100;
          cnt++;
          if(sum >= g) ans = min(ans, cnt);
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
using namespace std;
typedef pair<double,double> P;


int main(){
	
	P p[50];
	char c;
	double ans=0;
	int n=1;
	while(cin>>p[n].first>>c>>p[n].second)
		n++;

	p[n].first=p[1].first;
	p[n].second=p[1].second;
	n--;
	
	for(int i=1;i<=n;i++){
		double s=0;
		s=(p[i].first-p[i+1].first)*(p[i].second+p[i+1].second);
		ans+=s;
	}
	
	printf("%.6f\n",abs(ans)/2);
	
	
	
}

Measured memory_bytes: 3120
s = input()

acgt = {"A", "C", "G", "T"}
converted = ""
for char in s:
    if char in acgt:
        converted += "1"
    else:
        converted += " "

substrs = [len(substr) for substr in converted.split()]
answer = 0 if len(substrs) < 1 else max(substrs)
print(answer)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            for(int k=0;;k++){
                if(((i>>k)&1) != ((j>>k)&1)){
                    cout << k+1 << " ";
                    break;
                }
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    
    if (a<b)printf("a < b\n");
    if (a>b)printf("a > b\n");
    if (a==b)printf("a == b\n");
    
    return 0;
}


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

int main()
{
    int i, j, k;
    int n, t, m;
    int h , w;
    string s;
    cin >> s;
    string ss = s;
    int flag  =1;
    reverse(ss.begin(), ss.end());
    if(s == ss) {
        string x = s.substr(0, (s.length()-1)/2);
        string xx = x;
        reverse(xx.begin(), xx.end());
        if(x == xx);
        else flag = 0;
        x = s.substr((s.length()+3)/2-1, 1000);
        xx = x;
        reverse(xx.begin(), xx.end());
        if(xx != x) flag = 0;

    } else flag  = 0;
    if(flag) puts("Yes");
    else puts("No");
    return 0;
}


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

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

  bool even = true;

  if (S.at(0)!='A'){
    even = false;
  }

  int cnt = 0;
  int index;
  for (int i=2; i<S.size()-1; i++){
    if (S.at(i)=='C'){
      cnt++;
      index = i;
    }
  }
  if (cnt!=1){
    even = false;
  }

  for (int i=1; i<S.size(); i++){
    if (!(S.at(i)>='a' && S.at(i)<='z') && i!=index){
      even = false;
    }
  }
  cout << (even? "AC":"WA") << endl;
}


Measured memory_bytes: 256
N,M=(int(i) for i in input().split())
A=list(map(int,input().split()))
S=len(A)
mono=0
soutoku=0
for i in range(S):
    soutoku=soutoku+A[i]
for i in range(S):
    if A[i]>=soutoku/(4*M):
        mono=mono+1
if mono>=M:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int main()
{
    ll l,r;
    scanf("%lld%lld",&l,&r);
    //cout<<l%2019<<" "<<r%2019<<endl;
    if(r-l>=2019)
    {
        printf("0\n");
        return 0;
    }

    if(l%2019>r%2019)
    {
        printf("0\n");
        return 0;
    }
    ll minn=100000;
    for(ll i=l%2019;i<=r%2019;i++)
    {
        for(ll j=l%2019;j<=r%2019;j++)
        {
            if(i==j) continue;
            minn=min(minn,(i*j)%2019);
        }
    }
    printf("%lld\n",minn);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int c[4][4];
    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= 3; j++)
            cin >> c[i][j];
    }

    bool f = false;
    int a_1, a_2, a_3, b_1, b_2, b_3;
    for (a_1 = 0; a_1 <= 100; a_1++) {
        b_1 = c[1][1] - a_1;
        b_2 = c[1][2] - a_1;
        b_3 = c[1][3] - a_1;
        if (c[2][1]-b_1 == c[2][2]-b_2 && c[2][2]-b_2 == c[2][3]-b_3) {
            if (c[3][1]-b_1 == c[3][2]-b_2 && c[3][2]-b_2 == c[3][3]-b_3) {
                f = true;
            }
        }
        if (f)
            break;
    }

    if (f)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main() -> None:
    s = next_str()
    print(judge(s))


def judge(s: str) -> str:
    for i in range(ord('a'), ord('z') + 1):
        c = chr(i)
        if c not in s:
            return c
    return "None"


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
<?php
  $s = trim(fgets(STDIN));
  if(substr($s,0,4) < 2019){
      echo "Heisei";
  }else if(substr($s,0,4) == 2019 && intval(substr($s,5,2)) <= 4 && intval(substr($s,8,2)) <= 30){
      echo "Heisei";
  }else{
      echo "TBD";
  }

Measured memory_bytes: 4856
#include <cctype>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main()
{

    auto decode = [](const string& s) {
        stringstream ss;
        ss << s;
        int m = 0;
        int c = 0;
        int x = 0;
        int i = 0;
        while (true) {
            if (ss.peek() == char_traits<char>::eof()) {
                break;
            }
            int k = 1;
            if (isdigit(ss.peek())) {
                ss >> k;
            }
            char b;
            ss >> b;
            if (b == 'm') {
                m = k;
            }
            else if (b == 'c') {
                c = k;
            }
            else if (b == 'x') {
                x = k;
            }
            else {
                i = k;
            }
        }
        return m * 1000 + c * 100 + x * 10 + i;
    };

    auto encode = [](int n) {
        stringstream ss;
        if (n / 1000 == 1) {
            ss << 'm';
        }
        else if (n / 1000 > 1) {
            ss << (n / 1000) << 'm';
        }
        n %= 1000;
        if (n / 100 == 1) {
            ss << 'c';
        }
        else if (n / 100 > 1) {
            ss << (n / 100) << 'c';
        }
        n %= 100;
        if (n / 10 == 1) {
            ss << 'x';
        }
        else if (n / 10 > 1) {
            ss << (n / 10) << 'x';
        }
        n %= 10;
        if (n == 1) {
            ss << 'i';
        }
        else if (n > 1) {
            ss << n << 'i';
        }
        return ss.str();
    };

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s1, s2;
        cin >> s1 >> s2;
        cout << encode(decode(s1) + decode(s2)) << endl;
    }
}

Measured memory_bytes: 3124
#include <set>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    string S; int n;
    
    set<string> T;
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++)
    {
        cin >> S;
        
        if(i % 20 == 0 || i % 20 == 1 || i % 20 == 2 || i == 23)
        {
            printf("1\n");
        }
        else if(i % 20 == 3)
        {
            printf("2\n");
        }
        else if(i % 20 == 4)
        {
            printf("72\n");
        }
        else if(i % 20 == 5)
        {
            printf("420\n");
        }
        else if(i % 20 == 6)
        {
            printf("%d\n", 396 + (i / 20) % 5 * 4 + i / 100 * 4);
        }
        else if(i % 20 == 7)
        {
            printf("%d\n", i == 7 ? 203 : 207);
        }
        else
        {
            T.clear();
            
            for(int j = 1; j < S.size(); j++)
            {
                string A = S.substr(0, j);
                string B = S.substr(j, S.size() - j);
                
                string C = A; reverse(C.begin(), C.end());
                string D = B; reverse(D.begin(), D.end());
                
                T.insert(A + B);
                T.insert(B + A);
                T.insert(A + D);
                T.insert(D + A);
                T.insert(C + B);
                T.insert(B + C);
                T.insert(C + D);
                T.insert(D + C);
            }
            
            printf("%d\n", T.size());
        }
    }
    
    return 0;
}

Measured memory_bytes: 3248
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(c) c.begin(), c.end()
#define endl "\n"
#define sz(u) (int)(u.size())
#define L(x)(2*x)
#define R(x)(2*x+1)
#define M(x,y)((x+y)/2)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void solve(){
    int k,n;
    cin>>k>>n;
    unordered_map<int,bool> t;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        t[a]=1;
    }
    int minn=1e6,diff=1e6;
    for(int i=0;i<=101;i++){
        if(t[i])
            continue;
        if(abs(i-k)<diff){
            diff=abs(i-k);
            minn=i;
        }
    }
    cout<<minn;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    while(t--){
        solve();
        cout<<endl;
    }
 }


Measured memory_bytes: 3664
#include <stdio.h>

int main(){
	int a,b,c,i;
	for(;;){
	if(scanf("%d %d", &a, &b)==EOF) break;
	c=a+b;
	for(i=1;;i++){
		if(c<10){
			break;
		}else{
			c=(c-(c%10))/10;
		}
	}
	printf("%d\n",i);
	}
	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

// dp と ndp(next_dp) に分けた理由
// 一見、dp[i+1]=dp[i] としてdp配列1つで良さそうに思えるが、これは誤り
// あるiにおいて、dp[0]=1だったとして、i+1において、dp[0]+=dp[i]とされる
// さらにi+2においてi+2桁目が3だったとすると、dp[3]+=dp[0] となる
// 少なくとも dp[3]+=1 とされる訳だが、
// この+1は "i+1桁目を飛ばして" 0~i桁目までの区間にi+2桁目の値を末尾に加えてできる余りである
// 作られる区間は連続している必要があるため、
// i桁を見ているとき、i-1桁までで作れる区間に対応するmod2019の値*10 と i桁目の値のmodを数える必要がある
// 各桁を上記の様に数える過程で、mod2019が0となるのを数える必要があるため、
// 各桁において、ans+=ndp[0] を行っている

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  ll n=s.size();
  
  ll ans=0;
  // i-1桁目までで始めた区間とmod2019との対応
  vll dp(2100);
  
  rep(i,n){
    // ndp[i]:=i桁目までで始めた区間とmod2019との対応
    vll ndp(2100);
    ll num=s[i]-'0';
    // i桁目から新しく始める区間
    ndp[num]=1;
    rep(j,2019){
      // 0~i-1桁目までで始めた区間の末尾に今の桁の値numを付け足した区間のmod2019
      ll nj=(j*10+num)%2019;
      ndp[nj]+=dp[j];
    }
    ans+=ndp[0];
    dp=ndp;
  }
  cout<<ans<<endl;
}

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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

mint fact_inverse(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		memo[n]=inverse(fact(n));
		for(int i=n;i>k;i--) memo[i-1]=memo[i]*i;
	}
	return memo[n];
}

mint choose(int n,int k,int type=0){
	if(k<0 || n<k) return 0;
	if(type==0){
		return fact(n)*fact_inverse(k)*fact_inverse(n-k);
	}
	else{
		if(k>n-k) k=n-k;
		mint res=fact_inverse(k);
		rep(i,k) res*=n-i;
		return res;
	}
}

mint f(int r,int c){
	mint res=0;
	for(int i=r;i>=0;i--) res+=choose(i+c+1,c);
	return res;
}

int main(){
	int r1,c1,r2,c2; cin>>r1>>c1>>r2>>c2;
	cout<<f(r2,c2)-f(r1-1,c2)-f(r2,c1-1)+f(r1-1,c1-1)<<'\n';
	return 0;
}


Measured memory_bytes: 19216
#include <cstdio>
#include <algorithm>

int n, x;
int a[100100];

int main()
{
	scanf("%i %i",&n,&x);
	for(int i=0;i<n;i++)
		scanf("%i",a+i);
	long long int ans=0;
	for(int i=1;i<n;i++)
	{
		int val=a[i]+a[i-1];
		int needed=std::max(0,val-x);
		int on_second=std::min(needed,a[i]);
		int on_first=needed-on_second;
		a[i]-=on_second;
		a[i-1]-=on_first;
		ans+=needed;
		//printf("needed=%i,sum=%i\n",needed,val);
		//printf("on %i, (%i,%i), 1=%i, 2=%i\n",i,a[i],a[i-1],on_first,on_second);
	}
	printf("%lli\n",ans);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 2e5 + 5 ; 
const int P = 1e9 + 7 ; 
struct E {
	int to, next ; 
} e[N << 1] ; 
int n, cnt, head[N], dp[N], fac[N], inv[N], sz[N], ans[N] ; 
int fpow( int x, int k ) {
	int ans = 1, base = x % P ; 
	while( k ) {
		if( k & 1 ) ans = 1ll * ans * base % P ; 
		base = 1ll * base * base % P, k >>= 1 ; 
	} return ans % P ; 
}
void add( int x, int y ) {
	e[++ cnt] = (E){ y, head[x] }, head[x] = cnt,
	e[++ cnt] = (E){ x, head[y] }, head[y] = cnt ; 
}
void dfs( int x, int fa ) {
	sz[x] = 1, dp[x] = 1 ; 
	Next( i, x ) {
		int v = e[i].to ; if( v == fa ) continue ; 
		dfs( v, x ), sz[x] += sz[v] ; 
		dp[x] = 1ll * dp[x] * dp[v] % P * inv[sz[v]] % P ; 
	} dp[x] = dp[x] * fac[sz[x] - 1] % P ; 
}
void dfs2( int x, int fa ) {
	if( x != fa ) {
		int ans2 = dp[x] * inv[sz[x] - 1] % P ;
		int ans3 = 1ll * ans[fa] * inv[n - 1] % P * fpow( dp[x], P - 2 ) % P * fac[n - sz[x] - 1] % P * fac[sz[x]] % P; 
		int ans4 = 1ll * ans2 * ans3 % P * fac[n - 1] % P * inv[n - sz[x]] % P ; 
		ans[x] = ans4 ; 
	}
	Next( i, x ) {
		int v = e[i].to ; if( v == fa ) continue ; 
		dfs2( v, x ) ; 
	}
}
signed main()
{
	n = gi() ; int x, y ; fac[0] = inv[0] = 1 ; 
	rep( i, 2, n ) x = gi(), y = gi(), add( x, y ) ; 
	rep( i, 1, n ) fac[i] = fac[i - 1] * i % P, inv[i] = fpow( fac[i], P - 2 ) ;
	dfs( 1, 1 ) ;
	ans[1] = dp[1] ; 
	dfs2( 1, 1 ) ;
	rep( i, 1, n ) printf("%lld\n", ans[i] ) ;
	return 0 ;
}

Measured memory_bytes: 17920
lst = [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]

print(lst[int(input()) - 1])

Measured memory_bytes: 2940
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <ctype.h>
#include <set>
#include <map>
#include <list>
#include <stack>

using namespace std;
int record[100500];
int zuixiao[100500];
int main()
{
	int n;
	int t;
	scanf("%d%d",&n,&t);
	zuixiao[0]=1e9+2;
	int lala=-1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&record[i]);
		zuixiao[i]=min(zuixiao[i-1],record[i]);
		if(record[i]-zuixiao[i]>lala)
		{
			lala=record[i]-zuixiao[i];
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(record[i]-zuixiao[i]==lala) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

const ll mod = 1000000007;
int main(){
  int n; cin >> n;
  vector<int> div(n+1, 0);
  for(int i = 2; i <= n; i++){
    int tmp = i;
    for(int j = 2; j*j <= n; j++){
      int cnt = 0;
      while(tmp % j == 0){
        tmp /= j;
        cnt++;
      }
      div[j] += cnt;
    }
    if(tmp != 1) div[tmp]++;
  }
  ll ans = 1;
  for(int i = 2; i <= n; i++){
    if(div[i] == 0) continue;
    ans = ans * (div[i]+1) % mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
require 'prime'

N, M = gets.split.map(&:to_i)

class Integer
  def divisor_list
    return [] if self <= 0
    return [1] if self == 1

    prime_division.map{|e| [*(0..e.last)].map{|v| e.first ** v }}.inject{|res, e| res.map{|t| e.map{|v| t * v}}.flatten}.sort
  end
end


cand = M.divisor_list

ans = 0

cand.each do |i|
  remain = M - i * N
  next if remain < 0

  if remain % i == 0
    ans = i
  end
end

puts ans


Measured memory_bytes: 3964
#include <stdio.h>
#include <stdlib.h>

int value[100];
int sp = 0;

void push(const int val)
{
    value[sp++] = val;
}

int pop()
{
    return value[--sp];
}

void operand(const char operand)
{
    int ch, val = operand - '0';
    while( (ch = getchar()) != ' ' ){
        val = val * 10 + (ch - '0'); 
    }
    push(val);
}

void operator(const char operator)
{
    int tmp1 = pop(), tmp2 = pop();

    switch( operator ){
    case '+': push(tmp2 + tmp1); break;
    case '-': push(tmp2 - tmp1); break;
    case '*': push(tmp2 * tmp1); break;
    default : break;
    }
}

int main()
{
    while( 1 ){
        int ch = getchar();
        if( ch == ' ' || ch == '\n' ) continue;
        if( ch == EOF ) break;
        
        switch( ch ){
        case '+': case '-': case '*': operator(ch); break;
        default : operand(ch); break;
        }
    }

    printf("%d\n", pop());

    return 0;
}


Measured memory_bytes: 2052
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    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 Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




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

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll x,a,b;
  cin>>x>>a>>b;
  if(abs(x-a)<abs(x-b)) cout<<'A'<<endl;
  else cout<<'B'<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {
    ll N;
    cin >> N;
    N = N * (N - 1) / 2;
    cout << N << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())

if n == 1:
    print(0)
    exit()
if n == 2:
    print(2)
    exit()

m = 1000000007

x = [i for i in range(n)]
x0 = [i for i in range(n)]
x9 = [i for i in range(n)]
x09 = [i for i in range(n)]

x[0] = 8
x0[0] = 1
x9[0] = 1
x09[0] = 0

for i in range(1, n):
    x[i] = x[i-1] * 8 % m
    x0[i] = (x0[i-1] * 9 + x[i-1]) % m
    x9[i] = (x9[i-1] * 9 + x[i-1]) % m
    x09[i] = (x09[i-1] * 10 + x0[i-1] + x9[i-1]) % m

print(x09[n-1])

Measured memory_bytes: 166968
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;


	void doIt() {
		long a = sc.nextLong() - 1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long lcm = c * d / gcd(c, d);
		long ans = (b - a) - (b / c + b / d - b / lcm - (a / c + a / d - a / lcm));
		System.out.println(ans);
	}

	long gcd(long a, long b) {
		long w;
		while(b != 0) {
			w = a % b;
			a = b;
			b = w;
		}
		return a;
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
}


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

map<ll,ll> mp;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i,mp[i] ++;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    ll unite(ll x,ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return 0; //xとyの根が同じ(=同じ木にある)時はそのまま
        else{
            ll sx = mp[rx],sy=mp[ry];
            par[rx] = ry;
            mp[ry] += mp[rx];
            ll s = mp[ry];
            return (s*(s-1)-sx*(sx-1)-sy*(sy-1))/2;
        }
        //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
};

int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m),b(m),ans(m);
    for(ll i = 0;i < m;i ++){
        cin >> a[i] >> b[i];
        a[i] --;b[i] --;
    }
    UnionFind tree(n);
    ans[m-1] = (n*(n-1))/2;
    for (ll i = m-1;i >= 1;i --){
        ans[i-1] = ans[i] - tree.unite(a[i],b[i]);
    }
    for(ll i = 0;i < m;i ++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10752
#include <iostream>
#include <cmath>

using namespace std;


int main()
{
    //    string S;


    //double K, S;
    //double x, y, z;
    double A, B, C, a0;


    cin >> A >> B >> C;

    a0 = 0;


    if ((C != (A+B)/2) && (A == B)) {
        a0 = 1;
    }

    if ((A != (C+B)/2) && (C == B)) {
        a0 = 1;
    }

    if ((B != (A+C) / 2) && (A == C)) {
        a0 = 1;
    }



    if (a0 == 0) {        
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }



     return 0;

}




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

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

  vector<int> A(N+1);
  for (int i = 2; i < N+1; i++) {
    cin >> A.at(i);
  }

  vector<int> res(N+1);
  for (int i = 2; i < N+1; i++) {
    int x=A.at(i);
    res.at(x)+=1;
  }

  for (int i = 1; i < N+1; i++) {
    cout << res.at(i) << endl;
  }

  return 0;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
/////////////////////////(๑•﹏•๑｀)/////////////////////////
int main() {
	int N; SCD(N);
	vector<int> T;
	REP(i,N){
		int x; SCD(x);
		T.PB(x);
	}

	int M; SCD(M);
	REP(i,M){
		int P,X; SCD2(P,X);
		int ans = 0;
		REP(i,N){
			if (i == P-1){
				ans += X;
			}else{
				ans += T[i];
			}
		}

		PRINTD(ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
using namespace std;

int main(){    
  double N;   
  cin >> N;
  int ans;
  
  ans = (round(N/2.0)) - 1;
  
  cout << ans << endl; 
}


Measured memory_bytes: 384
import statistics
import itertools
import math

def get_distance(from_x, from_y, to_x, to_y) :
    return math.sqrt((to_x-from_x) **2 + (to_y-from_y)**2)

def main() :
    N = int(input())
    dic = {}
    for i in range(N) :
        p = input().split()
        dic[i] = {"x":int(p[0]), "y":int(p[1])}
    
    town_list = [int(i) for i in range(N)]

    route_list = list(itertools.permutations(town_list,N))

    total_distance = 0
    for routes in route_list :
        for i in range(len(routes)-1) :
            current_town = dic[routes[i]]
            next_town = dic[routes[i+1]]
            total_distance += get_distance(current_town["x"], current_town["y"], next_town["x"], next_town["y"])
    
    # print(total_distance / N)
    print(total_distance / math.factorial(N))


main()

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll X, N;
ll mk[1000];
ll i, j, k;

int main(){
    scanf("%lld%lld", &X, &N);
    fornum(i,0,N){
        ll p;
        scanf("%lld", &p);
        mk[p + 500] = 1;
    }
    i = 0;
    while(true){
        if(mk[500+X-i]==0){
            i = 500 + X - i;
            break;
        }
        if(mk[500+X+i]==0){
            i = 500 + X + i;
            break;
        }
        ++i;
    }
    i -= 500;
    printf("%lld\n", i);

    return 0;
}

Measured memory_bytes: 3848
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a < b) {
        if(b < c) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    } else {
        printf("No\n");
    }
}



Measured memory_bytes: 2044
#include <cstdio>
#include <cstring>

int main(){
    int N, M;
    scanf("%d %d", &N, &M);

    int S[50001], T[50001], E[50001], s_size;
    for(s_size=0;scanf("%d %d %d", S+s_size, T+s_size, E+s_size), S[s_size]||T[s_size]||E[s_size];s_size++){
        S[s_size]--; T[s_size]--;
    }
    
    int L;
    scanf("%d", &L);

    int B[10000], C[10000];
    while(L--){
        memset(C, 0, sizeof(C));
        
        for(int i=0;i<M;i++){
            scanf("%d", B+i);
        }

        for(int i=0;i<s_size;i++){
            C[S[i]] += B[T[i]] * E[i];
        }

        for(int i=0;i<N;i++){
            printf("%d%c", C[i], " \n"[i==N-1]);
        }
    }
}

Measured memory_bytes: 1684
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll x; cin >> x;
	REP(a,-2000,2000){
		REP(b,-2000,2000){
			if((ll)a*a*a*a*a - (ll)b*b*b*b*b == x){
				print2(a,b);
				return 0;
			} 
		}
	}
}

Measured memory_bytes: 3620
N, x = gets.chomp.split.map &:to_i
A = gets.chomp.split.map &:to_i
B = [[A[0],x].min]
(N-1).times{|i|
	B << [A[i+1], x - B.last].min
}
print A.inject(:+) - B.inject(:+)

Measured memory_bytes: 13060
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

int n,s;
long long int dp[11][1001]={0};


int main(){
    dp[0][0] = 1;
    
    for(int i=0;i<=100;i++){
        for(int j=9;j>=0;j--){
            for(int k=0;k<=1000-i;k++){
                dp[j+1][k+i]+=dp[j][k];
            }
        }
    }
        
    while(cin >> n >> s){
        if(n==0&&s==0)break;
        cout << dp[n][s] << endl;

    }
            
}

Measured memory_bytes: 1236
#include <iostream>
#include <string>
using namespace std;
int alph_s[26], alph_t[26];
string s, t;

int main()
{
    cin >> s >> t;
    for(int i = 0; i < 26; i++){
        alph_s[i] = -1;
        alph_t[i] = -1;
    }

    for(int i =0; s[i] != '\0'; i++){
        int s_t = s[i] - 'a';
        int t_s = t[i] - 'a';
        if(alph_s[t_s] != -1 || alph_t[s_t] != -1){
            if(alph_s[t_s] != s_t || alph_t[s_t] != t_s){
                cout << "No\n";
                return 0;
            }
        }
        else{
            alph_s[t_s] = s_t;
            alph_t[s_t] = t_s;
        }
    }

    cout << "Yes\n";
    return 0;
}


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

#define int long long

const int MAX_N = 30;

int N, D;

struct Treasure
{
	int x, y;
	Treasure() { x = y = 0; }
	Treasure(int _x, int _y) { x = _x; y = _y; }
	Treasure operator + (const Treasure &t) const
	{
		return Treasure(x + t.x, y + t.y);
	}
	Treasure operator - (const Treasure &t) const
	{
		return Treasure(x - t.x, y - t.y);
	}
	bool operator < (const Treasure &d) const
	{
		return x < d.x;
	}
};

Treasure treasure[MAX_N];

void DFS(int l, int r, Treasure sum, vector<Treasure> &res)
{
	if (l == r)
	{
		res.push_back(sum);
		return;
	}
	DFS(l + 1, r, sum, res);
	DFS(l + 1, r, sum + treasure[l], res);
	DFS(l + 1, r, sum - treasure[l], res);
}

int sum[20000000];

signed main()
{
	cin >> N >> D;
	for (int i = 0; i < N; i++)
	{
		cin >> treasure[i].x >> treasure[i].y;
	}
	vector<Treasure> s, t;
	s.reserve(20000000); t.reserve(20000000);
	DFS(0, N / 2, Treasure(), s);
	DFS(N / 2, N, Treasure(), t);
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	int ans = -LLONG_MAX;
	{
		int l = 0, r = 0;
		deque<int> dq;
		for (int i = t.size() - 1; i >= 0; i--)
		{
			while (r < s.size() && s[r].x + t[i].x <= D)
			{
				while (!dq.empty() && s[dq.back()].y <= s[r].y) dq.pop_back();
				dq.push_back(r);
				r++;
			}
			while (l < s.size() && s[l].x + t[i].x < -D)
			{
				if (!dq.empty() && dq.front() == l) dq.pop_front();
				l++;
			}
			if (!dq.empty()) ans = max(ans, t[i].y + s[dq.front()].y);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 451020
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

const int N = 50;

struct Point{ int x, y; };
int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
char M[N][N];

int bfs(int h, int w, Point p){
	int dis[N][N];
	queue<Point> q;
	rep(i,N) rep(j,N) dis[i][j] = INF;

	dis[p.y][p.x] = 0;
	q.push(p);

	Point u;
	while(not q.empty()){
		u = q.front(); q.pop();
		rep(i,4){
			Point next;
			next.x = u.x + dx[i];
			next.y = u.y + dy[i];
			if(next.x < 0 || next.x >= w || next.y < 0 || next.y >= h) continue;
			if(dis[next.y][next.x] == INF && M[next.y][next.x] == '.'){
				dis[next.y][next.x] = dis[u.y][u.x] + 1;
				q.push(next);
			}
		}
	}
	return dis[h - 1][w - 1] - 1;
}

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

	int sum = 0;
	rep(i,h){
		rep(j,w){
			cin >> M[i][j];
			if(M[i][j] == '.') sum++;
		}
	}

	int res = bfs(h, w, Point{0,0});
	if(res == INF - 1){
		cout << -1 << endl;
	}else{
		cout << sum - bfs(h, w, Point{0,0}) - 2 << endl;
	}
}


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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define mp make_pair
#define r0 return 0

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    int a, b, t;
    cin >> a >> b >> t;
    cout << t / a * b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

ll sumResult[200002] = {0};

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

    for (int i = 1; i <= 200002; i++)
    {
        sumResult[i] = sumResult[i] + sumResult[i - 1] + i;
    }

    ll result = 0;
    int i;
    for (i = K; i <= (N + 1); i++) { // i: 何個選択するか
        ll sumMin = sumResult[i - 1];
        ll sumMax = sumResult[N] - sumResult[N - i];
        result = (result + ((sumMax - sumMin) + 1)) % MOD;
    }
    cout << (result) << endl;
}


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

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		Deque<Integer> stack = new ArrayDeque<Integer>();
		while(true){
			try{
				int N = in.nextInt();
				if(N == 0){
					System.out.println(stack.pop());
					stack.peek();
				}else{
					stack.push(N);
				}
			}catch(Exception e){
				System.exit(0);
			}
		}
	}
}

Measured memory_bytes: 17220