akhauriyash/Code-Regression huggingface dataset:
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<pint> p(n);
    vector<pint> ch(m);
    REP(i, n){
        cin >> p[i].fst >> p[i].snd;
    }
    REP(i, m){
        cin >> ch[i].fst >> ch[i].snd;
    }
    REP(i, n){
        int ch_num = -1;
        lint min_dist = LINF;
        lint dist;
        int px = p[i].fst;
        int py = p[i].snd;
        REP(j, m){
            int cx = ch[j].fst;
            int cy = ch[j].snd;
            dist = abs(px - cx) + abs(py - cy);
            if(dist < min_dist){
                ch_num = j;
                min_dist = dist;
            }
        }
        cout << ch_num + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
int par[100000];

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}
int dfs(int i) {
	if (par[i] == i) {
		return i;
	}
	else {
		int t=dfs(par[i]);
		return par[i] = t;
	}
}

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	int p[100000];
	REP(i, n) {
		int t;
		scanf("%d", &t);
		p[i] = t - 1;
	}
	REP(i, n)par[i] = i;
	REP(i, m) {
		int x, y;
		scanf("%d %d", &x, &y);
		x--; y--;
		int xp = dfs(x);
		int yp = dfs(y);
		if (xp != yp) {
			par[yp] = xp;
		}
	}
	REP(i, n) {
		dfs(i);
	}
	/*
	REP(i, n) {
		printf("%d ",par[i]);
	}
	puts("");
	REP(i, n) {
		printf("%d ", p[i]);
	}
	puts("");
	*/
	int cnt = 0;
	REP(i, n) {
		if (par[p[i]] != par[i])cnt++;
		//printf("%d %d %d\n", par[p[i]], par[i], cnt);
	}
	PRINTD(n - cnt);
}

Measured memory_bytes: 896
$prev = 0;
$r{"AC"} = 0;
$r{"WA"} = 0;
%ac = ();
%wa = ();
while(<>){
	chomp;
	next if($. == 1);
	($no, $ans) = split(/ /, $_);
	if($ans eq "AC"){
		if($ac{$no} != 1){
			$r{"AC"}++;
			$r{"WA"} += $wa{$no};
		}
		$ac{$no} = 1;
	}else{
		$wa{$no}++;
	}
}

print $r{"AC"} . " " . $r{"WA"} . "\n";


Measured memory_bytes: 11904
#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 ALL(obj) (obj).begin(),(obj).end()
#define SCANF(i) int i;scanf("%d",&i)
typedef long long ll;
using namespace std;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int IINF=100000000;
const int MOD = (int)1e9 + 7;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<int> dx={1,0,-1,0};vector<int> dy={0,-1,0,1};

signed main () {
    ll n,k;cin >> n >> k;
    vector<ll> pl;vector<ll> min;
    REP(i,n){
        ll tmp;cin >> tmp;
        if(tmp<0)min.push_back(tmp);
        else pl.push_back(tmp);
    }
    ll pllen=pl.size();ll minlen=min.size();
    sort(ALL(pl),greater<ll>());
    sort(ALL(min));
    ll ans=1;
    bool is_ans_plus=false;
    if(pllen==0){
        if(k%2==0)is_ans_plus=true;
    } else {
        if(n>k || (n==k && minlen%2==0))is_ans_plus=true;
    }
    if(is_ans_plus){
        ll pindex=0;
        ll mindex=0;
        if(pllen>0 && k%2==1){
            pindex=1;
            ans*=pl[0];
            ans%=MOD;
            k--;
        }
        while(k>0){
            bool canp=(pindex<pllen-1)?true:false;
            bool canm=(mindex<minlen-1)?true:false;
            if(k==1){
                ans*=pl[pindex];
                ans%=MOD;
                pindex++;
                k--;
            } else if(canp && canm){
                ll t1=pl[pindex]*pl[pindex+1];
                ll t2=min[mindex]*min[mindex+1];
                if(t1>t2){
                    t1%=MOD;
                    ans*=t1;
                    ans%=MOD;
                    pindex+=2;
                    k-=2;
                } else {
                    t2%=MOD;
                    ans*=t2;
                    ans%=MOD;
                    mindex+=2;
                    k-=2;
                }
            } else if(canp){
                ll t1=pl[pindex]*pl[pindex+1];
                t1%=MOD;
                ans*=t1;
                ans%=MOD;
                pindex+=2;
                k-=2;
            } else {
                ll t2=min[mindex]*min[mindex+1];
                t2%=MOD;
                ans*=t2;
                ans%=MOD;
                mindex+=2;
                k-=2;
            }
        }
    } else {
        vector<ll> abslist;
        REP(i,pllen)abslist.push_back(pl[i]);
        REP(i,minlen)abslist.push_back(abs(min[i]));
        sort(ALL(abslist));
        REP(i,k)ans*=abslist[i],ans%=MOD;
        ans*=-1;
        ans+=MOD;
    }
    cout << ans << endl;
}//https://atcoder.jp/contests/abc173/tasks/abc173_e

Measured memory_bytes: 6924
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static int mod =1000000007;
	public static void main(String[] args) {
		int v[]=new int[5];
		int maxI=0;
		int g=0;
		for(int i=0;i<5;i++) {
			v[i]=sc.nextInt();
			if(v[i]%10!=0&&10-(v[i]%10)>maxI) {
				maxI=10-(v[i]%10);
				g=i;
			}
		}
		//p(maxI+"    g");
		int ans=0;
		for(int i=0;i<5;i++) {
			if(i==g)continue;
			else if(v[i]%10==0) {
				ans+=v[i];
			}else {
				ans+=v[i]-v[i]%10+10;
			}
		}
		ans+=v[g];
		p(ans);
		
		
		 
		
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define M (ll)1000000007
#define MM (ll)1e8
#define INF (ll)1e18
#define arep(i, x, n) for (long long i = x; i < n; i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001

int main() {
    ll n;
    cin >> n;
    ll a[n];
    ll b[n + 1];
    b[0] = -1;
    b[n] = -1;
    rep(i, n) { cin >> a[i]; }
    arep(i, 1, n) {
        if (a[i] > a[i - 1]) {
            b[i] = 1;
        } else if (a[i] < a[i - 1]) {
            b[i] = -1;
        } else {
            b[i] = b[i - 1];
        }
    }
    ll c[n];
    bool isBuy = true;
    ll money = 1000;
    ll cnt = 0;
    rep(i, n) {
        if (b[i] < b[i + 1] && isBuy) {
            // 買う
            isBuy = false;
            cnt += money / a[i];
            money = money - cnt * a[i];
        } else if (!isBuy) {
            if (b[i] > b[i + 1] || i == n - 1) {
                isBuy = true;
                money = money + cnt * a[i];
                cnt = 0;
            }
        }
    }

    // ll b[n][n];

    // fill(b[0], b[n], 0);
    cout << money << endl;
}

Measured memory_bytes: 3592
#include <math.h>
#include <stdio.h>

int main() {
	int a, b, c, k, max;

	scanf("%d%d%d%d", &a, &b, &c, &k);
	max = a;
	if (max < b)
		max = b;
	if (max < c)
		max = c;
	printf("%d\n", a + b + c - max + (max * (int) pow(2, k)));
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main (){
  string s;
  cin >> s;
  int counter = 0;
  if(s[0] == '1') ++counter;
  if(s[1] == '1') ++counter;
  if(s[2] == '1') ++counter;
    cout << counter << endl;
}
    

Measured memory_bytes: 256
inform = [[[0]*10 for i in range(3)] for j in range(4)]
N = int(input())
for loop in range(N):
    b, f, r, v = map(int, input().split())
    inform[b-1][f-1][r-1] += v
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(end=" ")
            print(inform[i][j][k],end="")
        print()
    if i != 3:print("####################")



Measured memory_bytes: 5628
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
int main(void) {
	float input = 0;
	float output = 0;
	scanf("%f", &input);
	output = 2 * input*M_PI;
	printf("%.2f\n", output);
	return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    char a, b;
    cin >> a >> b;
    if (a == b) {
        cout << "=" << endl;
    }
    else if (a < b) {
        cout << "<" << endl;
    }
    else {
        cout << ">" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  float r;
  cin>>r;
  float ans;
  ans=2*M_PI*r;
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    int N, a[100], t=0;
    cin >> N;
    for(int i=0 ; i<N ; i++) cin >> a[i];
    for(int i=0 ; i<N ; i++){
        int minj = i;
        for(int j=i ; j<N ; j++){
            if(a[j]<a[minj]) minj=j;
        }
        swap(a[i], a[minj]);
        if(i!=minj) t++;
    }
    for(int i=0 ; i < N-1 ; i++) cout << a[i] << " ";
    cout << a[N-1] << endl;
    cout << t << endl;
    return 0;
}


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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int ans = 0;
  if (A>B)
  {
    ans += B;
  }else{
    ans += A;
  }
  if (C>D)
  {
    ans += D;
  }else{
    ans += C;
  }
  cout << ans << endl;
  return 0;
}

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

int main(void){
 int N, x;
  cin >> N >> x;
  long long count = 0, a = 0, a_b = 0;
  cin >> a;
  if(a > x){
    count += a - x;
    a_b = x;
  }
  else a_b = a;
  for(int i = 1; i< N; i++){
    cin >> a;
    if(a_b + a > x){
      count += a_b + a - x;
      a_b = x - a_b;
    }
    else{
      a_b = a;
    }
  }
  cout << count;
  return 0;
}

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

using namespace std;
const int MINF = -(1<<29);

int nbnoeuds,nbarcs;
int dynalong[100000];
vector<int> graph[100000];


int mark(int cible)
{
	if(dynalong[cible]!=MINF)
	{
		return dynalong[cible];
	}
	else
	{
		
		int maxi = -1;
		for(unsigned int i = 0 ; i<graph[cible].size() ; i++)
		{
			maxi = max(maxi,mark(graph[cible][i]));
		}
		dynalong[cible]=maxi+1;
		//cout<<cible<<" : "<<maxi+1<<endl;
		return maxi+1;
	}
}


signed main()
{
	ios::sync_with_stdio(false);
	cin>>nbnoeuds>>nbarcs;
	for(int i = 0 ; i < nbnoeuds ; i++)
	{
		dynalong[i]= MINF;
	}
	for(int i = 0 ; i < nbarcs ; i++)
	{
		int a,b;
		cin>>a>>b;
		graph[a-1].push_back(b-1);
	}
	int grmax=0;
	for(int i = 0 ; i < nbnoeuds ; i++)
	{
		if(dynalong[i]== MINF)
		{
			mark(i);
		}
		grmax = max(grmax,dynalong[i]);

	}
	cout<<grmax;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    repf(i,0,n) cin>>a[i];
    multiset<ll> s;
    ll ans=0;
    s.insert(a[0]);
    ans++;
    repf(i,1,n)
    {
        multiset<ll>::iterator it=s.lower_bound(a[i]);
        if(it==s.begin()) ans++;
        else{
            --it;
            s.erase(it);
        }
        s.insert(a[i]);
    }
    cout<<ans<<endl;
    return 0;
}

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

#define vint vector<int> 
#define vbool vector<bool>
#define vvint vector<vector<int>>

#define rep(a, b, c) for(int (a)=(b); (a)<(c); (a)++)
#define all(a) (a).begin(), (a).end()

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

    string n_str = to_string(n);
    int sum = 0;
    for(int i=0; i<n_str.length(); i++){
        int d = n_str[i]-'0';
        sum += d;
    }
    if(n%sum == 0) cout<<"Yes"; else cout<<"No";
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)


int main() {
    int n,d,a;
    cin >> n >> d >> a;
    vector<pair<ll,ll>> m(n);
    for (int i = 0;i < n;++i) cin >> m[i].first >> m[i].second;
    sort(m.begin(),m.end());
    ll sum = 0,ans = 0;
    vector<ll> b(n+1,0);
    for (int i = 0;i < n;++i) {
        int j = upper_bound(m.begin(),m.end(),make_pair(m[i].first+2*d,(ll)1e9))-m.begin();
        sum -= b[i];
        ll c = max(0LL,(m[i].second-sum+a-1)/a);
        // if (c) {
            ans += c;
            b[j] += c*a;
            sum += c*a;
        // }
        // cout << ans << endl;
    }
    // p_ary(b,0,n+1);
    cout << ans << endl;
}

Measured memory_bytes: 4992
/**
*    created: 03.07.2020 17:37:29
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    cout << a * a - b << endl;
    return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;

long long MOD = 1000000007;
vector<long long> F, RF, R;

void init(long long N) {
	F.resize(N + 1), RF.resize(N + 1), R.resize(N + 1);
	F[0] = F[1] = RF[0] = RF[1] = R[0] = R[1] = 1;
	for (int i = 2; i <= N; i++) {
		F[i] = (F[i - 1] * i) % MOD;
		R[i] = MOD - (R[MOD % i] * (MOD / i)) % MOD;
		RF[i] = (RF[i - 1] * R[i]) % MOD;
	}
	return;
}

long long Comb(long long A, long long B) {
	if (B < 0 || A < B) return 0;
	return (F[A] * ((RF[A - B] * RF[B]) % MOD)) % MOD;
}

int main() {
	long long N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	init(N);
	vector<vector<long long> > DP(N + 1, vector<long long>(B + 1, 0));
	DP[0][A - 1] = 1;
	for (int i = A - 1; i < B; i++) {
		vector<long long> X(D + 1);
		X[0] = 1;
		for (int j = 1; j <= D && j * (i + 1) - 1 <= N; j++) {
			X[j] = (X[j - 1] * Comb(j * (i + 1) - 1, i)) % MOD;
		}
		for (int j = 0; j <= N; j++) {
			DP[j][i + 1] += DP[j][i];
			DP[j][i + 1] %= MOD;
			for (int k = C; k <= D && k * (i + 1) + j <= N; k++) {
				DP[j + k * (i + 1)][i + 1] += (DP[j][i] * ((Comb(N - j, k * (i + 1)) * X[k]) % MOD)) % MOD;
				DP[j + k * (i + 1)][i + 1] %= MOD;
			}
		}
	}
	cout << DP[N][B] << endl;
	return 0;
}

Measured memory_bytes: 8192
import java.util.*;
public class Main {
   public static void main(String[] args) {  
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long z = sc.nextLong();
      long w = sc.nextLong();
      long[] ar = new long[n];
      for(int i = 0; i < n; i++){
         ar[i] = sc.nextLong();
      }
      
      if(n == 1){
         System.out.println(Math.abs(ar[0] - w));
      }
      else {
         long ans = 0;
         for(int i = 1; i < ar.length; i++){
            ans = Math.max(Math.abs(ar[i] - w), Math.abs(ar[i] - ar[i-1]));
         }
         System.out.println(ans);
      } 
   }
}

Measured memory_bytes: 27092
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>

using namespace std;

#define fto(i,a,b) for (int i = (a); i <= b; i++)
#define fdw(i,a,b) for (int i = (a); i >= b; i--)
#define rep(i,a) for(int i = 0; i < a; i++) 
#define read(a) cin >> a
#define read2(a, b) cin >> a >> b
#define read3(a, b, c) cin >> a >> b >> c
#define read4(a, b, c, d) cin >> a >> b >> c >> d
#define write(a, b) cout << a << b
#define writeln(a) cout << a << "\n"

#define PI 3.14159265
#define oo 1000000000
#define ooLL 100000000000000000
#define log(a) cerr << #a << " = " << a << endl

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define next thongdeptrai
#define prev thongbachuthegioi
#define y1 thongsieucapvutru
#define y0 thongnotgay

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

#define maxn 100005


using namespace std;

ll n, m, c = 1, d = 1, res;
ll fac[maxn];
ll MOD = 1000000007;

ll pow(ll x, ll y) {
	if (y == 0) return 1;
	else {
		ll tmp = 1;
		if (y & 1) {
			tmp = pow(x, y / 2);
			return (((tmp * tmp) % MOD) * x) % MOD;
		}
		else {
			tmp = pow(x, y / 2);
			return (tmp * tmp) % MOD;
		}
	}
}

ll P(ll x, ll y) {
	ll tu = fac[y];  
	ll mau = fac[y - x];
	return (tu * pow(mau, MOD - 2)) % MOD;
}

int main() {

    read2(n, m);

    if (abs(n - m) >= 2) {
    	cout << 0;
    	return 0;
    }

    fac[1] = 1;
    fto(i, 2, 100000) fac[i] = (fac[i - 1] * i) % MOD;
    
    fto(i, 1, n) c = (c * i) % MOD;
    fto(i, 1, m) d = (d * i) % MOD;
	
	if (n == m) {
		res = (((d * c) % MOD) * 2) % MOD;
		cout << res;	
		return 0;
	}
	if (n < m) d = P(n, m);
	if (n > m) c = P(m, n);
	
	res += (d * c) % MOD;
    cout << res;
}


Measured memory_bytes: 1024
import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(n,r))

r=input1()
print(2*math.pi*r)















Measured memory_bytes: 27136
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;

int main(){
	LL n;
	cin >> n;
	LL ip[n][3];
	
	for(LL i = 0;i < n; i++)cin>>ip[i][0]>>ip[i][1]>>ip[i][2];
	
	LL dp[n][3];
	
	for(LL i = 0;i < n;i++){
		if(i==0){
			dp[i][0] =  ip[i][0];
			dp[i][1] =  ip[i][1];
			dp[i][2] =  ip[i][2];
			continue;
		}
		
		dp[i][0] =  ip[i][0] + max(dp[i-1][1],dp[i-1][2]);
		dp[i][1] =  ip[i][1] + max(dp[i-1][0],dp[i-1][2]);
		dp[i][2] =  ip[i][2] + max(dp[i-1][1],dp[i-1][0]);
	}
	
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
const int N=505;
int n,s[N],t[N],u[N],v[N],ans[N][N],a[N][N];
vector<pair<int,int>>r,c;
inline void zh(){cout<<-1<<endl;exit(0);}
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>s[i];
	for(int i=1;i<=n;i++)
		cin>>t[i];
	for(int i=1;i<=n;i++)
		cin>>u[i];
	for(int i=1;i<=n;i++)
		cin>>v[i];
	for(int i=0;i<64;i++)
	{
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				a[j][k]=-1;
		r.clear();
		c.clear();
		for(int j=1;j<=n;j++)
		{
			if(!s[j])
			{
				if((u[j]>>i)&1)
					for(int k=1;k<=n;k++)
						a[j][k]=1;
				else
					r.emplace_back(j,0);
			}
			else
			{
				if((~u[j]>>i)&1)
					for(int k=1;k<=n;k++)
						a[j][k]=0;
				else
					r.emplace_back(j,1);
			}
		}
		for(int j=1;j<=n;j++)
		{
			if(!t[j])
			{
				if((v[j]>>i)&1)
				{
					for(int k=1;k<=n;k++)
						if(a[k][j]==0)
							zh();
					for(int k=1;k<=n;k++)
						a[k][j]=1;
				}
				else
					c.emplace_back(j,0);
			}
			else
			{
				if((~v[j]>>i)&1)
				{
					for(int k=1;k<=n;k++)
						if(a[k][j]==1)
							zh();
					for(int k=1;k<=n;k++)
						a[k][j]=0;
				}
				else
					c.emplace_back(j,1);
			}
		}
		if(min(r.size(),c.size())>=2)
		{
			for(int j=0;j<r.size();j++)
				for(int k=0;k<c.size();k++)
					a[r[j].first][c[k].first]=(j+k)&1;
		}
		else if(r.size()==1)
		{
			for(auto p:c)
			{
				int fl=0;
				for(int j=1;j<=n;j++)
					fl|=a[j][p.first]==p.second;
				a[r[0].first][p.first]=fl?r[0].second:p.second;
			}
			int fl=0;
			for(int j=1;j<=n;j++)
				fl|=a[r[0].first][j]==r[0].second;
			if(!fl)
				zh();
		}
		else if(c.size()==1)
		{
			for(auto p:r)
			{
				int fl=0;
				for(int j=1;j<=n;j++)
					fl|=a[p.first][j]==p.second;
				a[p.first][c[0].first]=fl?c[0].second:p.second;
			}
			int fl=0;
			for(int j=1;j<=n;j++)
				fl|=a[j][c[0].first]==c[0].second;
			if(!fl)
				zh();
		}
		else
		{
			for(auto p:r)
			{
				int fl=0;
				for(int j=1;j<=n;j++)
					fl|=a[p.first][j]==p.second;
				if(!fl)
					zh();
			}
			for(auto p:c)
			{
				int fl=0;
				for(int j=1;j<=n;j++)
					fl|=a[j][p.first]==p.second;
				if(!fl)
					zh();
			}
		}
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				ans[j][k]|=(a[j][k]&1)<<i;
	}
	for(int j=1;j<=n;j++)
	{
		for(int k=1;k<=n;k++)
			cout<<ans[j][k]<<' ';
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 9552
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let odds = (n + 1) / 2;
    println!("{}", (odds as f64) / (n as f64));
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];

    rep(i, W + 2) cout << "#";
    cout << endl;
    rep(i, H) cout << "#" << S[i] << "#" << endl;
    rep(i, W + 2) cout << "#";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt64(scanner)
	b := getNextInt64(scanner)
	x := getNextInt64(scanner)
	ans := b / x
	if a == 0 {
		ans++
	}
	if a > 0 {
		ans -= (a - 1) / x
	}
	fmt.Fprintln(writer, ans)
}


Measured memory_bytes: 640
S = [
    (1, 2, 4, 3), # 0
    (0, 3, 5, 2), # 1
    (0, 1, 5, 4), # 2
    (0, 4, 5, 1), # 3
    (0, 2, 5, 3), # 4
    (1, 3, 4, 2), # 5
]

*L, = map(int, input().split())
q = int(input())
for i in range(q):
    a, b = map(int, input().split())
    for i in range(6):
        if L[i] == a:
            for k in range(4):
                if L[S[i][k]] == b:
                    print(L[S[i][k-3]])


Measured memory_bytes: 5604
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

int main(){
	string s;
	cin >> s;
	if (s[s.length()-1] == 's') cout << s << "es" << endl;
	else cout << s << "s" << endl;
	return 0;
}



Measured memory_bytes: 3628
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
  ll N,last;
  cin>>N;
  ll data=N,data2=0;
  int count=1;
  while(true){
    last=N;
    N=N/10;
    if(N>0) {
      count++;
    }
    else break;
  }
  ll ans=(count-1)*9+last-1;
  ll temp=1;
  for(int i=0;i<count;i++){
    if(i==count-1){
      data2+=temp*last;
    }else{
      data2+=temp*9;
    }
    temp*=10;
  }
  if(data2==data) ans++;
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

constexpr ll MOD = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin>>n;
  vecll dp(n+1);
  dp[1] = n;
  dp[2] = n*n%MOD;
  ll sum = dp[1] + dp[2];
  FOR(i,3,n+1) {
    ll cnt = sum + (MOD - dp[i-2]);
    cnt += (n - i + 2) * n % MOD;
    cnt += (i - 3) * (n - 1) % MOD;
    cnt %= MOD;
    dp[i] = cnt;
    sum += dp[i];
    sum %= MOD;
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <string>
using namespace std;
int main(){
string  S,T;
bool frag=true;
int i;
cin>>S;
cin>>T;
i=(int)S.length();
for (int k=0;k<i;k++)
{
if(S[k]!=T[k])
frag = false;

}
if(frag)
cout<<"Yes"<<endl;
else
{
    cout<<"No"<<endl;
}


    
return 0;
}



Measured memory_bytes: 3552
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
 long long int i,n,sl=0,sr=0,d=1000000000;
 cin>>n;
 vector <int> a(n);
 for (i=0;i<n;i++){
  cin>>a[i];
  sr+=a[i];
 }
 for (i=0;i<n;i++){
  sl+=a[i];
  sr-=a[i];
  d=min(d,abs(sl-sr));
 }
 cout<<d;
 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int p=a/(b+c);
	if(a%(b+c)<c)p--;
	cout<<p<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int digit(int n, int d) {
	int m = (int)(n/pow(10,d)) * pow(10,d);
	return (n - m)/pow(10,d-1);
}

int max_deci(int n, int l) {
	int ret = 0;
	vector<int> d(l);

	for (int i = 0; i < l; i++) {
		d[i] = digit(n,i+1);
	}
	sort(d.begin(), d.end(), std::greater<int>());
	for (int i = 0; i < l; i++) {
		ret += d[i] * pow(10,l-i-1);
	}

	return ret;
}

int min_deci(int n, int l) {
	int ret = 0;
	vector<int> d(l);

	for (int i = 0; i < l; i++) {
		d[i] = digit(n,i+1);
	}
	sort(d.begin(), d.end());
	for (int i = 0; i < l; i++) {
		ret += d[i] * pow(10,l-i-1);
	}

	return ret;
}

int check_vec(vector<int> v, int n, int ind) {
	int ret = 0;
	for (vector<int>::iterator itr = v.begin(); itr != v.end() && ret < ind+1; ++itr) {
		if (*itr == n) {
			return ret;
		}
		ret++;
	}
	return -1;
}

int main(void) {
	int N,L;
	cin >> N;
	cin >> L;

	while (N!=0||L!=0) {
		bool find = false;
		int a = N;
		int ind;
		vector<int> dp(21,-1);
		dp[0] = a;
		for (int i = 0; i < 20 && !find; i++) {
			a = max_deci(a,L) - min_deci(a,L);
			ind = check_vec(dp,a,i);
			if (!(ind < 0)) {
				find = true;
				cout << ind << " " << a << " " << i-ind+1 << endl; 
			}
			else {
				dp[i+1] = a;
			}
		}

		cin >> N;
		cin >> L;
	}
	return 0;
}

Measured memory_bytes: 3268
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    int m = kbd.nextInt();
	    if(!(n==0 && m==0)){
		solve(n, m);
	    }
	}
    }

    static void solve(int n, int m){
	int[][] dis = new int[n][2];   // 距離/期待値
	int i, j;
	int ans = 0;
	for(i=0; i<n; i++){
	    dis[i][0] = kbd.nextInt();
	    dis[i][1] = kbd.nextInt();
	    ans += dis[i][0]*dis[i][1];
	}
	//System.out.println("*"+ans);
	sort(dis, n);
	i=0;
	while(i<n && m>0){
	    if(m >= dis[i][0]){
		ans -= dis[i][0]*dis[i][1];
		m -= dis[i][0];
	    }
	    else{
		ans -= m*dis[i][1];
		m = 0;
	    }
	    i++;
	}
	System.out.println(ans);
    }

    static void sort(int[][] d, int n){
	int i, j;
	for(i=0; i<n; i++){
	    for(j=i+1; j<n; j++){
		if(d[i][1]<d[j][1]){
		    int[] w = d[i];
		    d[i] = d[j];
		    d[j] = w;
		}
	    }
	    //System.out.println(d[i][0]+" "+d[i][1]);
	}
    }
}

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

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }
/*
#include <bits/stdc++.h>
using namespace std;
 */
struct BIT {
	vector<int> v;
	int n;

	BIT() { init(); }
	BIT(int size) :n(size){ init(); }

	void init() {
		v.clear();
		v.resize(n + 1, 0);
	}

	int sum(int i, int idx = 1) {
		idx--; idx *= -1; i += idx;
		int ret = 0;
		while (i) {
			ret += v[i];
			i -= i & -i;
		}
		return ret;
	}

	void add(int i, int x, int idx = 1) {
		idx--; idx *= -1; i += idx;
		while (i <= n) {
			v[i] += x;
			i += i & -i;
		}
	}
};

int main() {
	int n = in(), q = in();
	BIT bit(n);

	rep(_, q) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		if (a)
			cout << bit.sum(c) - bit.sum(b - 1) << endl;
		else 
			bit.add(b, c);
	}
}

Measured memory_bytes: 3388
k = int(input())
if k % 2 == 0 or k % 5 == 0:
  print(-1)
else:
  if k % 7 == 0:
    k /= 7
  m = 1
  m2 = 1
  c = 1
  while m % k != 0:
    m2 = (m2*10)%k
    m = (m+m2)%k
    c += 1
  print(c)

Measured memory_bytes: 9136
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<int> w(n,-1);
    bool flag = false;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        if(w[a-1]==-1){
            w[a-1] = b;
        }
        else{
            if(w[a-1]!=b){
                flag=true;
            }
        }
    }
    if(n==1){
        if(w[0]==0){
            cout << 0;
            return 0;
        }
    }
    if(m==0&&n==1){
        cout << 0;
        return 0;
    }
    rep(i,n){
        if(w[i]==-1){
            if(i==0){
                w[i]=1;
            }
            else{
                w[i] = 0;
            }
        }
    }
    if(flag){
        cout << -1;
        return 0;
    }
    if(w[0]==0){
        cout << -1;
        return 0;
    }
    else{
        rep(i,n){
            cout << w[i];
        }
    }

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{

  string s;
  cin>>s;
  int ans=s.size();
  rep(i,2){
    int cnt=0;
    rep(j,s.size()){
     if(j%2==0 && s[j]!=(char)(i+'0')){
       //char(i+'0')で数字文字列が変わる
       //'0'+1=='1' etc...
      cnt++;
     }
     if(j%2==1 && s[j]==(char)(i+'0')){
       cnt++;
     }
    }
    ans=min(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		long m = Long.parseLong(sc.next());
		sc.close();
		long res=(n*2+m)/4;

		System.out.println(res<n?m/2:res);
	}

}


Measured memory_bytes: 23508
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map> 
#include<vector>
#include<queue>
#include<set>
#include<bits/stdc++.h>
#include<deque> 
#include<bitset>
#include<string>
#define N 40
#define K 300005
#define MOD 1e9+7
#define int long long 
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

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

int32_t main(){
	int n, w;
	cin>>n>>w;
	int we[n], v[n];
	for(int i=0;i<n;i++){
		cin>>we[i]>>v[i];
	}
	int dp[105][100005];
	int maxva = 0;

	//memset(dp, INT_MAX , sizeof(dp));
    for(int i=0;i<=100;i++){
        for(int j=0;j<=1e5;j++){
            dp[i][j] = 1e10;
        }

    }
    dp[0][0] = 0;
	

	for(int it = 0; it<n; it++){
		for(int va = 0; va <= 1e5; va++){
			if(it == 0){
				if(va == 0){
					continue;
				}
				if(va <= v[0]){
                    //cout<<va<<endl;
					dp[it][va] = we[0];
				}
			}
			else{
				dp[it][va] = dp[it - 1][va];
				if(va >= v[it]){
					dp[it][va] = min(dp[it][va], we[it] + dp[it-1][va - v[it]]);
				}
			}
			if(dp[it][va] <= w){
                //cout<<it<<" "<<va<<" "<<dp[it][va]<<endl;
				maxva = max(maxva, va);
			}
		}
	}
    //cout<<dp[0][40]<<endl;
	cout<<maxva<<endl;
	
}

Measured memory_bytes: 81152
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 入力
		int N = sc.nextInt();                
		int M = sc.nextInt();                
		
		ArrayList<ArrayList<Info>> list = new ArrayList<ArrayList<Info>>();
		for (int i = 0; i < N; i++) {
			list.add(new ArrayList<Info>());
		}
		for (int i = 0; i < M; i++) {
			int P = sc.nextInt();                
			int Y = sc.nextInt();
			Info info = new Info();
			info.index = i;
			info.prefecture = P;
			info.year = Y;
			list.get(P-1).add(info);
		}

		// 答えを出力
		String[] ans = new String[M];
		for (ArrayList<Info> inlist : list) {
			Collections.sort(inlist, new PrefectureComparator());
			for (int j = 0; j < inlist.size(); j++) {
				int p = inlist.get(j).prefecture;
				ans[inlist.get(j).index] = String.format("%06d", p)+String.format("%06d", j+1);
			}
		}
		for (int i = 0; i < M; i++) {
			System.out.println(ans[i]);
		}
	}
	
	public static class Info{
		int index = 0;
		int prefecture = 0;
		int year = 0;
		String number = "";
	}
	
	public static class PrefectureComparator implements Comparator<Info> {

		@Override
		public int compare(Info info1, Info info2) {
			return info1.year < info2.year ? -1 : 1;
		}
	}
}


Measured memory_bytes: 175148
#include <iostream>
using namespace std;
#define NIL -1

int D[100000];

struct Node
{
	int parent;
	int left;
	int right;
};

Node T[100000];

void setDepth(int u, int p) {
	D[u] = p;
	if (T[u].right != NIL) {
		setDepth(T[u].right, p);
	}
	if (T[u].left != NIL) {
		setDepth(T[u].left, p + 1);
	}
}

void print(int u) {
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].parent << ", ";
	cout << "depth = " << D[u] << ", ";

	if (T[u].parent == NIL) {
		cout << "root, ";
	}
	else if (T[u].left == NIL) {
		cout << "leaf, ";
	}
	else {
		cout << "internal node, ";
	}

	cout << "[";
	int c = T[u].left;
	while (c != NIL)
	{
		cout << c;
		c = T[c].right;
		if (c != NIL) {
			cout << ", ";
		}
	}
	cout << "]" << endl;
}

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		T[i].parent = T[i].left = T[i].right = NIL;
	}

	for (int i = 0; i < n; i++) {
		int v, d, l;
		cin >> v >> d;
		for (int j = 0; j < d; j++) {
			int c;
			cin >> c;
			if (j == 0) {
				T[v].left = c;
			}
			else {
				T[l].right = c;
			}
			l = c;
			T[c].parent = v;
		}
	}
	int r;
	for (int i = 0; i < n; i++) {
		if (T[i].parent == NIL)
			r = i;
	}
	setDepth(r, 0);
	for (int i = 0; i < n; i++) {
		print(i);
	}
	return 0;
}


Measured memory_bytes: 7764
n = int(input())
str = input()
all = str.split()
L_all= [int(s) for s in all]
L_all = sorted(L_all)
other = L_all[:n-1]
L_sum=sum(other)
last = L_all[n-1]
if L_sum > last:
    print("Yes")
if L_sum <= last:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(i) sort((i).begin(),(i).end())
#define INF 2000000000
constexpr ll mod = 1000000007;

int main() {
	int N;
	cin >> N;
	cout << "ABC" << N << "\n";

	return 0;
}

Measured memory_bytes: 256
import sys
import itertools

N, M = [int(i) for i in sys.stdin.readline().split()]
edges = [[] for _ in range(N)]
for l in sys.stdin.readlines():
  a, b = [int(i)-1 for i in l.strip().split()]
  edges[a].append(b)
  edges[b].append(a)

def flatten(l):
  return list(itertools.chain.from_iterable(l))

def is_spanning_tree(edges):
  # list of tuple to 2d-list
  new_edges = [[] for _ in range(N)]
  for a, b in edges:
    new_edges[a].append(b)
    new_edges[b].append(a)
  edges = new_edges
  nodes = set([0])
  next_node_candidates = set(flatten([edges[n] for n in nodes]))
  while next_node_candidates:
    nodes.add(list(next_node_candidates)[0])
    next_node_candidates = set(flatten([edges[n] for n in nodes]))
    next_node_candidates = [x for x in next_node_candidates if x not in nodes] #まだ追加されていないcandidate
  return True if len(nodes) == N else False

cnt = 0
edges = flatten([[(i, j) for j in edges[i] if i>=j] for i in range(N)])
incomplete_graphs = [[edges[j] for j in range(len(edges)) if i != j] for i in range(len(edges))]
spanning_trees = [1 if not is_spanning_tree(graph) else 0 for graph in incomplete_graphs]
print(sum(spanning_trees))

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

struct P {
  string s;
  int n;
};

int main(){
  vector<P> v;
  string s,d="";
  P p;
  int f=0, l=0;

  getline( cin,s );
  //  cout << "input : "<< s << endl;

  for( unsigned int i=0;i<s.length();i++ ){
    if( s[i]==' ' || i==s.length()-1 ){
      if( s[i]!=' ' ) d += s[i];
      p.s = d;

      //      cout << d << endl;
      unsigned int j;
      for( j=0;j<v.size();j++ ){
	if( v[j].s==d ){
	  v[j].n++;
	  f = max( f,v[j].n ); break;
	}
      }
      if( j==v.size() ){
	p.s = d; p.n=1;
	v.push_back( p );
	l = max( l,(int)d.length() );
      }
      d="";
    }else{
      d = d + s[i];
    }
  }

  for( unsigned int i=0;i<v.size();i++ ){
    if( v[i].n==f ){
      cout << v[i].s << " "; break;
    }
  }
  for( unsigned int i=0;i<v.size();i++ ){
    if( (int)v[i].s.length()==l ){
      cout << v[i].s << endl; break;
    }
  }

  return 0;
}

Measured memory_bytes: 0
n = int(input())
arr = list(map(int,input().split()))
d = {}
for i in arr:
	if i not in d:
		d[i] = 1
	else:
		d[i] += 1
q = int(input())
summ=sum(arr)
for _ in range(q):
	a,b = map(int,input().split())
	if a in d:
		summ = summ - (a*d[a]) + (b*d[a])
		print(summ)
		if b in d:
			d[b] += d[a]
			d[a] = 0
		else:
			d[b] = d[a]
			d[a] = 0
	else:
		print(summ)


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

int main(){
    int w, h, n;
    cin >> w >> h >> n;
    int A[2] = {0, h};
    int B[2] = {w, h};
    int C[2] = {w, 0};
    int D[2] = {0, 0};
    vector<int> x(n,0), y(n,0), a(n,0);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> a[i];
    }

    for(int i = 0; i < n; i++){
        switch (a[i]){
            case 1:
                if(A[0] < x[i]){
                    A[0] = x[i];
                    D[0] = x[i];
                }
                break;
            case 2:
                if(B[0] > x[i]){
                    B[0] = x[i];
                    C[0] = x[i];
                }
                break;
            case 3:
                if(C[1] < y[i]){
                    C[1] = y[i];
                    D[1] = y[i];
                }
                break;
            case 4:
                if(A[1] > y[i]){
                    A[1] = y[i];
                    B[1] = y[i];
                }
                break;
        }
    }

    int hight = (B[1] - C[1]);
    int width = (B[0] - A[0]);
    if(hight > 0 && width > 0){
        cout << hight * width << endl;
    }else{
        cout << 0 << endl;
    }

}

Measured memory_bytes: 256