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

int main() {
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l.at(i);
  }
  int ans = 1e9;
  for (int s = 0; s < 1 << (2 * n); s++) {
    int lx[4] = {}, m[4] = {}, scopy = s;
    for (int i = 0; i < n; i++) {
      lx[scopy % 4] += l.at(i);
      m[scopy % 4]++;
      scopy /= 4;
    }
    if (m[0] == 0 or m[1] == 0 or m[2] == 0) continue;
    ans = min(ans, 10 * (m[0] + m[1] + m[2] - 3) + abs(lx[0] - a) + abs(lx[1] - b) + abs(lx[2] - c));
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;
        for (int i = 0; i < n; i++) {
            switch (sc.next()) {
                case "AC":
                    ac++;
                    break;
                case "WA":
                    wa++;
                    break;
                case "TLE":
                    tle++;
                    break;
                case "RE":
                    re++;
                    break;
            }
        }
        System.out.println("AC x " + ac);
        System.out.println("WA x " + wa);
        System.out.println("TLE x " + tle);
        System.out.println("RE x " + re);
    }
}

Measured memory_bytes: 58212
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    bool ans = false;
    if (w >= v && a != b)
        ans = false;
    else {
        const int dist = abs(a - b);
        const int velo = v - w;
        ans = velo * t >= dist;
    }

    cout << (ans ? "YES" : "NO") << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

bool isSquare(ll x) {
    ll imin = 0;
    ll imax = INF;
    while (imax - imin > 1) {
        ll imid = (imax + imin) / 2;
        if (imid * imid >= x) {
            imax = imid;
        } else {
            imin = imid;
        }
    }
    return imax * imax == x;
}

bool func(vl a, vl b) {
    ll tmp = 0;
    FOR(i, 0, a.size()) {
        tmp += (a[i] - b[i]) * (a[i] - b[i]);
    }
    return isSquare(tmp);
}

signed main() {
    ll N, D;
    cin >> N >> D;
    vector<vl> v(N, vector<ll>(D));
    FOR(i, 0, N) {
        FOR(j, 0, D) {
            cin >> v[i][j];
        }
    }
    ll ans = 0;
    FOR(i, 0, N) {
        FOR(j, i + 1, N) {
            ans += func(v[i], v[j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s1,s2;
  cin>>s1>>s2;
  bool flag=false;
  int num=stoi((s1+s2));
  for(int i=1;i<1000;i++){
    if(i*i==num)flag=true;
  }
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
a = int(input())
b = list(map(int,input().split()))
r = "APPROVED"
for i in range(a):
  if b[i] % 2 == 0:
    if b[i] % 3 == 0 or b[i] % 5 == 0:
      r = "APPROVED"
    else:
      r = "DENIED"
      break
print(r)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int n, k;
vector<int> s;
vector<vector<int>> dp;

int solve(int x, int rem) {
  if (x == n - 1) return rem % s[x];
  int &ret = dp[x][rem];

  if (ret != -1)  return ret;
  ret = 0;

  ret = solve(x + 1, rem % s[x]);
  ret = (ret + 1ll * (n-1-x) * solve(x + 1, rem) % M) % M;
  return ret;
}

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  cin >> n >> k;
  s.resize(n);
  dp.assign(n, vector<int> (k + 1, -1));
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }

  sort(s.begin(), s.end(), greater<int>());
  cout << solve(0, k) << '\n';
}

Measured memory_bytes: 79104
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>

using namespace std;

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

  int a_min = 1001;
  int a_max = -1;
  while (N--) {
    int x;
    scanf("%d", &x);
    if (x < a_min) a_min = x;
    if (x > a_max) a_max = x;
  }

  printf("%d\n", a_max - a_min);
}


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

int main() {
  int a;
  cin>>a;
  vector<int> vec(a);
  
  for(int i=0;i<a;i++){
    cin>>vec.at(i);
  }
  
  int p=0;
  sort(vec.begin(),vec.end());
  
  for(int i=0;i<a-1;i++){
    p+=vec.at(i);
  }
  
  if(vec.at(a-1)<p){
  cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef vector <int> vi;
typedef vector <vi> vvi;

int addedge(vvi &graph, int y, int x, int val=1){
	graph[y][x] = val;
	return val;
}

int make_graph(vvi &graph, vi &stamp){
	int n1=graph.size(), n2, row, col;

	for (int j=0; j<n1; j++){
		cin>>row;
		cin>>n2;
		for (int i=0; i<n2; i++){
			cin>>col;
			addedge(graph, row-1, col-1);
		}
		stamp[j] = -1;
	}
	return 0;
}

int Breadth_First_Search(vvi &graph, vi &stamp){

	queue <int>qu;
	qu.push(0);
	stamp[0] = 0;
	while (! qu.empty()){
		int tmp = qu.front();
		qu.pop();
		for (int i=0; i<(int)graph[0].size(); i++){
			if (graph[tmp][i]==1 && stamp[i]==-1){
				stamp[i] = stamp[tmp]+1;
				qu.push(i);
			}
		}
	}
	return 0;
}

int resultout(vi &stamp){
	for (int i=0; i<int(stamp.size()); i++){
		cout<<i+1<<" "<<stamp[i]<<endl;
	}
	return 0;
}

int main(void){

	int n, row;
	cin>>n;
	vvi G(n, vi(n));
	vi stamp(n);

	make_graph(G, stamp);

	Breadth_First_Search(G, stamp);

	resultout(stamp);

	return 0;
} 

Measured memory_bytes: 1256
//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 10/01/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,M,T,N;
    cin>>N;
    char a;k=0;l=0;
    for (i=0; i<N; i++) {
        cin>>a;
        if ( a == 'A') {
            k=1;
        }else{
            if ( ( a == 'B') && ( k == 1 ) ) {
                k=2;
            }else{
                if ( ( a == 'C') && ( k == 2 ) ) {
                    k=0;
                    l=l+1;
                }else{
                    k=0;
                }
                k=0;
            }
            
        }
       
    }
    
    cout<<l<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

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

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int k;
	cin >> k;
	while (k--)
		cout << "ACL";
}


Measured memory_bytes: 3612
#include<iostream>
#include<queue>
#include<string>
using namespace std;
int inf=100007;
int map[1005][1005];
struct Point{
    int x;
    int y;
    int turn;
    vector<Point> next;
    void get_next(){
        int px=x+1;int py=y;
        if(map[py][px]==inf){
            Point buf;
            buf.x=px;
            buf.y=py;
            buf.turn=turn+1;
            next.push_back(buf);
            map[py][px]=map[y][x]+1;
        }
        px--;py++;
        if(map[py][px]==inf){
            Point buf;
            buf.x=px;
            buf.y=py;
            buf.turn=turn+1;
            next.push_back(buf);
            map[py][px]=map[y][x]+1;
        }
        py--;px--;
        if(map[py][px]==inf){
            Point buf;
            buf.x=px;
            buf.y=py;
            buf.turn=turn+1;
            next.push_back(buf);
            map[py][px]=map[y][x]+1;
        }
        px++;py--;
        if(map[py][px]==inf){
            Point buf;
            buf.x=px;
            buf.y=py;
            buf.turn=turn+1;
            next.push_back(buf);
            map[py][px]=map[y][x]+1;
        }
    }
};

int main(){
    int h,w;cin>>h>>w;
    vector<string> a(h);
    for(int i=0;i<h;i++){
        cin>>a[i];
    }
    for(int i=0;i<1005;i++){
        for(int j=0;j<1005;j++){
            map[i][j]=inf;
            if(i==0||i==h+1)map[i][j]=0;
            if(j==0||j==w+1)map[i][j]=0;
        }
    }
    queue<Point> q;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]=='#'){
            map[i+1][j+1]=0;
            Point p;
            p.x=j+1;
            p.y=i+1;
            p.turn=0;
            q.push(p);
            }
        }
    }
    while(!q.empty()){
        Point p=q.front();
        q.pop();
        p.get_next();
        int num=p.next.size();
        for(int i=0;i<num;i++){
            q.push(p.next[i]);
            //map[p.next[i].y][p.next[i].x]=p.next[i].turn;
        }
    }
    int max=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(max<map[i+1][j+1])max=map[i+1][j+1];
            //cout<<map[i+1][j+1];
        }
        //cout<<endl;
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 46212
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
		int h = sc.nextInt();
        int w = sc.nextInt();
    
		// 出力
		System.out.println((n - h + 1) * (n - w + 1));
	}
}

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

int main(){
  int n; cin>>n;
  vector<ll> dp(n,0),num(200001,0);
  int log; cin>>log;
  dp[0]=1;
  for(int i=1;i<n;i++){
    int x; cin>>x;
    if(x!=log){
      dp[i]=dp[i-1]+num[log];
      dp[i]%=MOD;
      num[log]=dp[i];
      log=x;
    }else{
      dp[i]=dp[i-1];
    }
    if(i==n-1) dp[i]+=num[x];
  }
  cout<<dp[n-1]%MOD<<endl;
}

Measured memory_bytes: 3328
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//読み込む
		int N = int.Parse(Console.ReadLine());
		int[] An = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

		int max = 1000000;

		//昇順にソート
		Array.Sort(An);

		//バケツ
		bool[] bucket = new bool[max+1];

		//割り切れる数があるものをカウント
		int cnt = 0;

		//全探索
		for(int i=0; i<N; i++){
			int Ai = An[i];
			bool found = false;

			//約数がない場合
			if(!bucket[Ai]){
				//この先を埋める
				int j = Ai;
				while(j <= max){
					bucket[j] = true;
					j += Ai;
				}
			}
			//約数がある場合
			else{
				found = true;
			}

			//自分の前後に自身と同じ数がある場合もOK
			if(!found){
				if(i > 0){
					if(An[i-1] == An[i]){
						found = true;
					}
				}
				if(i < N-1){
					if(An[i+1] == An[i]){
						found = true;
					}
				}
			}

			//見つかっている場合、カウント
			if(found){
				cnt ++;
			}
		}

		int ans = N - cnt;

		Console.WriteLine(ans);

	}
}



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

typedef long long ll;
const ll MOD = 1e9 + 7;

const int INF = 1e9;
const int MAX = 2500;

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;    
    return 0;
}

Measured memory_bytes: 3612
/* Author - xorier4104 */

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>


using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define MOD 			(int) 1e9+7
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define mem(a,b)        memset(a,(b),sizeof(a))
#define max(a,b)        ((a)>(b) ? (a):(b))
#define min(a,b)        ((a)<(b) ? (a):(b))
#define abs(a)          ((a)>0 ? (a):(-(a)))
#define sq(a) 			((a)*(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)

int main(){ FastIO;
	
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
return 0;
}

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

int main(void) {
  long long int n;
  scanf("%lld", &n);
  long long int num[n];

  for (long long int i = 0; i < n; i++) num[i] = 0;

  for (long long int i = 0; i < n - 1; i++) {
    long long int person;
    scanf(" %lld", &person);
    num[person - 1]++;
  }

  for (long long int i = 0; i < n; i++) printf("%lld\n", num[i]);

  return 0;
}


Measured memory_bytes: 3288
n = int(input())
a = [int(x) for x in input().split()]
ans = []

a_odd = a[::2]
a_even = a[1::2]

if n % 2 == 0:
	ans.extend(a_even[::-1])
	ans.extend(a_odd)
else:
	ans.extend(a_odd[::-1])
	ans.extend(a_even)

for i in range(n):
	print(ans[i], end=" ")



Measured memory_bytes: 26196
#include <iostream>
#include <algorithm>
#include <cmath>
#define rep(i, a, n) for(int i = a;i < n;++i)
#define repe(i, a, n) for(int i = a;i <= n;++i)
#define repr(i, a, n) for(int i = a;i > n;--i)
#define reper(i, a, n) for(int i = a;i >= n;--i)
using namespace std;


int w, h, n;
int seg[131072*2 - 1];
int N;


int p(int i){
	return (int)((i-1) / 2);
}


void update(int i){
	if(i == 0) return;
	if(seg[p(i)] >= seg[i]) return;
	seg[p(i)] = seg[i];
	update(p(i));
}


void init(){
	rep(i, N-1, h+N-1) update(i);
}
 
 
int qmax(int a, int b, int k = 0, int l = 0, int r = N){
	if(r <= a || b <= l) return -1;
	if(a <= l && r <= b) return seg[k];
	
	int vl = qmax(a, b, 2*k+1, l, (l+r)/2);
	int vr = qmax(a, b, 2*k+2, (l+r)/2, r);
	return max(vl, vr);
}


int solve(){
	int c = 999999999;
	rep(i, 0, h-1){
	    c = min(c, i+qmax(i+1, h));
	}
	c = min(c, h-1);
	return c;
}


int main(){
	cin >> w >> h >> n;
	N = (int)pow(2, (int)floor(log2(h))+1);
	
	rep(i, 0, n){
		int x, y;
		cin >> x >> y;
		seg[y+N-1] = max(seg[y+N-1], x);
	}
	
	init();
	
	cout << solve() << endl;
	
	return 0;
}


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

string FILENAME = "template";
#define io ifstream fin(FILENAME + ".in"); ofstream fout(FILENAME + ".out")
#define fwrite(X) fout << X;
#define fwriteln(X) fout << X << endl;

#define forl(V, N) for(int V = 0; V < N; V++)
#define forll(V, S, E) for(int V = S; V < E; V++)
#define fore(V, N) for(auto &V:N)
#define print(X) cout << X
#define printsp(X) cout << X << " "
#define println(X) cout << X << endl
#define rem(X) X.top(); X.pop()
#define graph unordered_map<int, vector<int>>
#define vi vector<int>
#define pb push_back
#define ll long long

int main() {
    string S;
    cin >> S;
    int sol = 0;
    forl(i, S.size()/2) {
        if(S[i] != S[S.size()-i-1]) sol++;
    }
    println(sol);
}

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

typedef unsigned long long ull;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ull X,Y=100,count=0;	cin>>X;
	while(1){
		count++;
		Y*=1.01;
		if(Y>=X) break;
	}
	
	cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n; cin >>n; int ans=0; vector<int>a(n);
  vector<bool>ok(1e6+1,1); vector<bool>rec(1e6+1,0);
  for(int i=0; i<n; i++) cin >>a[i];
  sort(a.begin(),a.end());
  for(int i=0; i<n; i++){
    if(rec[a[i]]){ok[a[i]]=0; rec[a[i]]=0;}
    else if(ok[a[i]]){
      int j=2;
      while(j*a[i]<=1e6){
        ok[j*a[i]]=0; j++;
      }
      rec[a[i]]=1;
    }
  }  
  for(int i=0; i<n; i++) if(ok[a[i]]) ans++;
  cout <<ans;
return 0;}

Measured memory_bytes: 4276
from operator import mul
from functools import reduce

def cmb(n, r, mod,g1,g2):

    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


def solve():
    X,Y=[int(x) for x in input().split()]
    if (2*Y-X)%3 or (2*X-Y)%3:
        return 0
    
    a=(2*X-Y)//3
    b=(2*Y-X)//3
    

    n=a+b
    r=a

    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    mod = 10**9+7
    N = 10**6
    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )
        
    return cmb(n,r,mod,g1,g2)

    
print(solve())


Measured memory_bytes: 122368
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

typedef long long li;
typedef unsigned long long uli;
typedef pair<int, int> pii;
typedef long double ld;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fr first
#define sc second
#define pb push_back
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forb(i, n) for(int i = int(n) - 1; i >= 0; --i)

const int INF = 1e9 + 1000;
const li INF64 = 1e15 + 1000;
const int M = 26;
const int N = 100 + 100;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = 3.14159265359;

li gcd(li a, li b) {
    return a == 0 ? b : gcd(b % a, a);
}

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

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

    int n, k;
    cin >> n >> k;

    vector<int> h(n);
    forn(i, n) {
        cin >> h[i];
    }

    vector<int> dp(n, INF);
    dp[0] = 0;

    fore(i, 1, n) {
        for (int j = 1; j <= k && i - j >= 0; j++) {
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }

    cout << dp[n - 1] << '\n';
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
//set<pair<ll,ll>> spll;
//map<string,ll> mp;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<ll> deq;
//vector<ll> vll;
ll num[ten5],pp[ten52],mm[ten52];
//priority_queue<ll> pq;          //decreasing

int f(int n) {
    int ret = 0;
    while (n!=0) {
	int pc = __builtin_popcount(n);
	n %= pc;
	ret++;
    }
    return ret;
}

int main(void)
{
    ll m,n,i,j,k,l,r;
    int ones=0;
    string s;
    cin>>n;
    cin>>s;
    reverse(all(s));
    for(i=0;i<n;i++)
    {
        if(s[i]=='1')
            ones++;
    }
    pp[0]=mm[0]=1;
    for(i=0;i<n;i++)
    {
        pp[i+1]=pp[i]*2%(ones+1);
        mm[i+1]=mm[i]*2%(max(1,ones-1));
    }
    ll psum=0,msum=0;
    for(i=0;i<n;i++)
    {
        if(s[i]=='1')
        {
            psum+=pp[i];
            msum+=mm[i];
        }
    }
    psum%=(ones+1);
    msum%=max(1,ones-1);
    int ans,cur;
    for(i=n-1;i>=0;i--)
    {
        ans=cur=0;
        if(s[i]=='0')
        {
            cur=(psum+pp[i])%(ones+1);
            ans=1+f(cur);
        }
        else if(ones==1)
            ans=0;
        else
        {
            cur=(msum-mm[i])%(ones-1);
            if(cur<0) cur+=ones-1;
            ans=1+f(cur);
        }
        cout<<ans<<endl;
    }
    return 0;
}





Measured memory_bytes: 6852
x1,y1,x2,y2 = map(int,input().split())
x3 = x2 - (y2 - y1)
y3 = y2 + x2 - x1
x4 = x3 - (x2 - x1)
y4 = y3 - (y2 - y1)
print(str(x3) + " " + str(y3) + " " + str(x4) + " " + str(y4))

Measured memory_bytes: 3060
#include<stdio.h>

using namespace std;
int main(void)
{
    int A,B,C;
 
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    if(A+B+C<22)
    {
        printf("win");
    }
    else
    {
        printf("bust");
    }

    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<vector<ll>> dp(10, vector<ll>(10, 0));
    reps(i, 1, n + 1) {
        string s = to_string(i);
        dp[s[0] - '0'][s[len(s) - 1] - '0']++;
    }
    ll ans = 0;
    rep(i, 10) {
        rep(j, 10) {
            ans += dp[i][j] * dp[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(void)
{
	LL n,k; scanf("%lld%lld",&n,&k);
	LL a1=n/k; LL a2=n/k+1;
	LL d1=n-a1*k; if(d1<0) d1=-d1;
	LL d2=n-a2*k; if(d2<0) d2=-d2;
	LL res=min(d1,d2);
	printf("%lld\n",res);
	return 0;
}

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

int main(){
  string str;
  cin>> str;
  bool A  = false;
  bool B = false;
  for(int i = 0; i<str.length();i++){
  	if(str[i] == 'A'){
      A = true;
    }
    if(str[i] == 'B'){
      B = true;
    }
  }
  if(A and B){
    cout<<"Yes"<<'\n';
  }else{
  	cout<<"No"<<'\n';
  }
  return 0;
}

Measured memory_bytes: 256
def main():
    x, n = map(int,input().split())
    li = list(map(int,input().split()))
    li2 = []
    ans = 0
    for i in range(102):
        check = True
        for j in li:
            if j == i:
                check = False
        if check:
            li2.append(i)
    for i in li2:
        if abs(ans - x) > abs(i - x):
            ans = i
    print(ans)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 9200
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
    int a,b,r,s,i;
    cin >> a >> b;
    if(a>b)
    {
        r=a;
        s=b;
    }
    else
    {
        r=b;
        s=a;
    }
    stringstream ss;
ss << s;
string str = ss.str();
string k;
    for(i=0;i<r;i++)
    {
        k+=str;
    }
    cout << k ;
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        char ch = buffer.readLine().charAt(0);
        if (Character.isUpperCase(ch))
            sb.append("A\n");
        else
            sb.append("a\n");
        System.out.println(sb);
    }
}


Measured memory_bytes: 32416
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>
int main(){
    int i,j,n,k,r,s,p,ans=0;
    char t[100010]={};
    scanf("%d %d %d %d %d %s",&n,&k,&r,&s,&p,t);
    for(i=0; i<k; i++){
        if(t[i]=='r')ans+=p;
        if(t[i]=='s')ans+=r;
        if(t[i]=='p')ans+=s;
    }
    for(i=k; i<n; i++){
        if(t[i]!=t[i-k]){
            if(t[i]=='r')ans+=p;
            if(t[i]=='s')ans+=r;
            if(t[i]=='p')ans+=s;
        }
        else t[i]='m';
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1824
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

//Stopped Watches
public class Main{

	class R implements Comparable<R>{
		int h, m, s;
		public R(int h, int m, int s) {
			this.h = h;
			this.m = m;
			this.s = s;
		}
		public int compareTo(R o) {
			return h!=o.h?h-o.h:m!=o.m?m-o.m:s-o.s;
		}
		public int val(){
			return 3600*h+60*m+s;
		}
		@Override
		public boolean equals(Object obj) {
			R r = (R)obj;
			return h==r.h&&m==r.m&&s==r.s;
		}
		@Override
		public String toString() {
			return String.format("%02d:%02d:%02d", h, m, s);
		}
	}

	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		int[][] p = {{0,1,2},{0,2,1},{1,0,2},{1,2,0},{2,0,1},{2,1,0}};
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int[][] a = new int[n][3];
			for(int i=0;i<n;i++)for(int j=0;j<3;j++)a[i][j]=sc.nextInt();
			List<R>[] l = new ArrayList[n];
			for(int i=0;i<n;i++){
				l[i] = new ArrayList<R>();
				for(int d=0;d<60;d++){
					for(int k=0;k<6;k++){
						int h = (a[i][p[k][0]]+d)%60;
						int m = (a[i][p[k][1]]+d)%60;
						int s = (a[i][p[k][2]]+d)%60;
						if(h%5!=m/12)continue;
						R r = new R(h/5, m, s);
						if(!l[i].contains(r))l[i].add(r);
					}
				}
				Collections.sort(l[i]);
			}
			int min = 3600*12;
			R s, e;
			s = null;
			e = null;
			for(int i=0;i<n;i++){
				for(R r:l[i]){
					int m = 0;
					R end = null;
					for(int j=0;j<n;j++){
						if(i==j)continue;
						boolean exist = false;
						for(R t:l[j]){
							if(t.compareTo(r)>=0){
								exist = true;
								int v = t.val()-r.val();
								if(m<=v){
									m = v;
									end = t;
								}
								break;
							}
						}
						if(!exist){
							end = null;
							break;
						}
					}
					if(end==null)continue;
					if(m<min){
						min = m;
						s = r;
						e = end;
					}
					else if(m==min&&r.compareTo(s)<0){
						s = r;
						e = end;
					}
				}
			}
			System.out.println(s+" "+e);
		}
	}

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

Measured memory_bytes: 13000
use std::io;
use std::cmp;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let n:usize = read_line().trim().parse().unwrap();

    let mut ans = 100000000;

    for i in 1..n/2+1 {
        let mut tmp = 0;
        let mut a = i;
        let mut b = n - i;
        while a > 0 {
            tmp += a % 10;
            a /= 10;
        }
        while b > 0 {
            tmp += b % 10;
            b /= 10;
        }
        ans = cmp::min(ans, tmp);
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX

int solve() {
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	int i;
	for (i = 0; i < n; i++)cin >> a[i] >> b[i] >> c[i];
	int dp[n][3];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (i = 1; i < n; i++) {
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + c[i];
	}

	return max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]);
}




int32_t main() {
	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	cout << solve();
	return 0;
}

Measured memory_bytes: 5968
#pragma GCC optimize("Ofast")
#include  "bits/stdc++.h"
using namespace std;
#define I_AM_SPEED  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define printclock  cerr <<"Time : "<<(double)clock()/(double)CLOCKS_PER_SEC<<" sec\n";
#define mp(a , b)   make_pair(a , b)
#define eb(a)       emplace_back(a)
#define SZ(n)       ((int)(n).size())
#define all(n)      (n).begin(), (n).end()
#define anal           '\n'
#define mod         1000000007
#define fst         first
#define sec         second
#define pr(n)       cerr << n  << " ";
#define pfor(a)     for(auto (w) : (a)) pr(w)
//const double PI = acos(-1.0);
typedef long long ll;
typedef unsigned long long ull;

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-


//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
int main(){
I_AM_SPEED;
#ifndef ONLINE_JUDGE  
        freopen("input.in", "r", stdin);
        freopen("output.in", "w", stdout);
#endif 
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
     
      double d, t, s; cin >> d >> t >> s;
      double tt = d/s;
      if(tt <= t) cout << "Yes\n";
      else cout << "No\n";

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
//printclock; 
return  0 ;      
}        



      

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

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

    vector<ll> A(N);
    rep (i, N) {
        cin >> A[i];
    }

    vector<ll> diff(N);
    diff[0] = K - A[N-1] + A[0];
    for (int i = 1; i < N; i++) {
        diff[i] = A[i]-A[i-1];
    }

    ll m = 0;
    rep(i, N) {
        m = max(m, diff[i]);
    }

    ll ans = 0;
    rep (i, N) {
        ans += diff[i];
    }

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

Measured memory_bytes: 3456
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

class Permutation : public vi{
public:
  Permutation( int n ){
    resize( n );
    REP( i , n ) at(i) = i;
  }
  Permutation(){}
};

Permutation identity_permutation( int n ){
  Permutation e( n );
  REP( i , n ) e[i] = i;
  return e;
}

Permutation inv( const Permutation &a ){
  Permutation c( a.size() );
  REP( i , a.size() ) c[ a[i] ] = i;
  return c;
}

Permutation operator * ( Permutation a  , Permutation b ){
  assert( a.size() == b.size() );
  Permutation c( a.size() );
  REP( i , a.size() ) c[i] = b[a[i]];
  return c;
}

Permutation operator *=( Permutation &a , Permutation b ){
  return a = a * b;
}

Permutation operator ^ ( Permutation x , ll k ){
  Permutation res = identity_permutation( x.size() );
  while( k ){
    if( k & 1 ) res *= x;
    k /= 2;
    x *= x;
  }
  return res;
}

Permutation operator ^=( Permutation &x , ll k ){
  return x = x ^ k;
}


ll n, m, k;
ld x[100010];
ld d[100010];
ld ad[100010];
ld ans[100010];

Permutation p;

int main(){

  n = in();
  REP( i , n ){
    x[i] = in();
  }
  REP( i , n-1 ){
    d[i] = x[i+1] - x[i];
  }
  m = in();
  k = in();
  p = identity_permutation( n - 1 );
  REP( i , m ){
    int a = in() - 1;
    swap( p[a-1] , p[a] );
  }
  p ^= k;
  REP( i , n-1 ){
    ad[i] = d[ p[i] ];
  }
  ans[0] = x[0];
  REP( i , n-1 ){
    ans[i+1] = ans[i] + ad[i];
  }
  REP( i , n ){
    printf( "%.18lf\n", (double)ans[i] );
  }
  
  return 0;
}


Measured memory_bytes: 11076
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>

using namespace std;

#define abs(a) ((a) < 0 ? - (a) : (a))

int main(){

    int N,Z,W;
    int a[2345];

    scanf("%d %d %d", &N, &Z, &W);

    for(int i = 0; i< N; i++) scanf("%d", &a[i]);

    if(N == 1) printf("%d\n", abs(a[0] - W));

    else if(abs(a[N-2] - a[N-1]) > abs(a[N-1] - W)) printf("%d\n", abs(a[N-2] - a[N-1]));

    else printf("%d\n", abs(a[N-1] - W));

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define all(x) x.begin(), x.end()
#define ed cout << "\n"
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define ar array
#define sz(x) (int)x.size()
#define forn(a,b,c) for(int a = b; a < c; a++)
#define rfor(a,b,c) for(int a = b; a >= c; a--)
#define fors(a,b,c,d) for(int a = b; a < c; a+=d)
#define rfors(a,b,c,d) for(int a = b; a >= c; a-=d)
#define yes cout << "Yes"
#define no cout << "No"
#define NAME ""
bool isFile = 0;
 
typedef long long ll;
typedef long double ld;
 
const ll INF=1e9+1234;                                                   
const int N = 4e5 + 5; 
const ll MOD=998244353;
const ll mod=1e9+7;                                            
double EPS = 3e-18;
const double PI = acos(-1);  
 
 
void faster()
{
	if(isFile)
	{
		freopen(NAME".in","r",stdin);
		freopen(NAME".out","w",stdout);
	}
	ios_base::sync_with_stdio(false);        
    cin.tie(NULL);                                         
    cout.tie(NULL);                                
}                                                     

int d[71234],s[71234],q[71234];


void solve() 
{			  			 																	 									 	  	                      
	string s;
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5]) yes;
	else no;	
}                         
                           
int main()                                     
{                            
	faster();                 
	int t = 1;
	//cin >> t;	
	while(t--)
	{               	
		solve();
		ed;
	}
	return 0;
}

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

using namespace std;

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

  string s;
  cin >> s;
  int n = s.size();
  int cnt = 0;
  for (int i = 0; i < n; ++i) 
    if (s[i] == '0') cnt++;
  cout << 2*min(cnt, n-cnt) << endl;

  return 0;
}



Measured memory_bytes: 512
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

struct edge {
	ll v1, v2, w;

	edge(ll tv1 = 0, ll tv2 = 0, ll tw = 0) {
		v1 = tv1;
		v2 = tv2;
		w = tw;
	}

	bool operator<(const edge & e) const {
		return w < e.w;
	}

	void read() {
		cin >> v1 >> v2 >> w;
	}
};

#define MAXN (1 << 10)

ll n, m, x;
vector<edge> e;
ll p[MAXN];
ll e1 = 0, e2 = 0, e3 = 0;

ll get(ll k) {
	if (k == p[k]) {
		return k;
	}
	ll ret = get(p[k]);
	p[k] = ret;
	return ret;
}

bool merge(ll v1, ll v2) {
	ll p1 = get(v1);
	ll p2 = get(v2);
	if (p1 == p2) {
		return false;
	}
	p[p1] = p2;
	return true;
}

int main() {
	cin >> n >> m;
	cin >> x;
	for (ll i = 0; i < m; i++) {
		edge t;
		t.read();
		e.push_back(t);
	}
	sort(e.begin(), e.end());
	for (ll i = 0; i < m; i++) {
		for (ll j = 1; j <= n; j++) {
			p[j] = j;
		}
		ll cur = 0;
		merge(e[i].v1, e[i].v2);
		cur += e[i].w;
		for (ll j = 0; j < m; j++) {
			if (merge(e[j].v1, e[j].v2)) {
				cur += e[j].w;
			}
		}
		if (cur == x) {
			e2++;
		} else if (cur < x) {
			e1++;
		} else {
			e3++;
		}
	}
	if (!e2) {
		cout << 0 << endl;
		return 0;
	}
	mod ret = 2;
	ret = ret.mypow(e2);
	ret = ret - mod(1);
	mod two = mod(2).mypow(e3);
	if (!e1) {
		ret = ret - mod(1);	
	} else {
		ret *= 2;
	}
	ret *= two;
	cout << ret << endl;
	return 0;
}




Measured memory_bytes: 3732
/******************************************

******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define vll vector<ll>
#define fo(i, n) for(int i=0;i<n;i++)
#define MOD 1000000007

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ios_base& scientific (ios_base& str);
	ll N=0, K=0;;
	cin >> N >> K;
	cout << min (N% K, K-N% K) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct Line{ ll n,k;ll Get(ll x){ return x*k+n;}Line(ll a, ll b):k(a),n(b){}Line(){}};
const int N=200050;
const int lim=1e6;
int ls[N],rs[N],tsz,root;
Line line[N];
void AddLine(int &c, int ss, int se, Line k)
{
	if(!c){ c=++tsz,line[c]=k;return;}
	ll A=line[c].Get(ss),B=k.Get(ss),C=line[c].Get(se),D=k.Get(se);
	if(A<=B && C<=D) return;
	if(A>=B && C>=D){ line[c]=k;return;}
	if(A>B) swap(line[c],k);
	int mid=ss+se>>1;
	if(line[c].Get(mid)<=k.Get(mid)) AddLine(rs[c],mid+1,se,k);
	else swap(line[c],k),AddLine(ls[c],ss,mid,k);
}
ll Get(int c, int ss, int se, int qi)
{
	ll ans=line[c].Get(qi);
	if(ss==se) return ans;
	int mid=ss+se>>1;
	if(qi<=mid && ls[c]) ans=min(ans,Get(ls[c],ss,mid,qi));
	if(qi>mid && rs[c]) ans=min(ans,Get(rs[c],mid+1,se,qi));
	return ans;
}
ll dp[N];
int h[N];
int main()
{
	int n;ll c;
	scanf("%i %lld",&n,&c);
	for(int i=1;i<=n;i++) scanf("%i",&h[i]);
	AddLine(root,1,lim,Line(-2*h[1],(ll)h[1]*h[1]));
	for(int i=2;i<=n;i++)
	{
		dp[i]=Get(root,1,lim,h[i])+(ll)h[i]*h[i]+c;
		AddLine(root,1,lim,Line(-2*h[i],dp[i]+(ll)h[i]*h[i]));
	}
	printf("%lld\n",dp[n]);
	return 0;
}

Measured memory_bytes: 7296
from collections import defaultdict
from heapq import heappop, heappush


class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    def __init__(self, graph, start):
        self.g = graph.graph
        self.dist = defaultdict(lambda: 10 ** 18)
        self.dist[start] = 0

        self.prev = defaultdict(lambda: None)

        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        return self.dist[goal]

    def shortest_path(self, goal):
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]



n,m = map(int, input().split())
uv = [list(map(int, input().split())) for i in range(m)]
s,t = map(int, input().split())
g = Graph()
for u,v in uv:
  g.add_edge(u*3-3,v*3-2)
  g.add_edge(u*3-2,v*3-1)
  g.add_edge(u*3-1,v*3-3)
dist = Dijkstra(g,(s-1)*3)
ans = dist.shortest_distance((t-1)*3)
if ans == 10 ** 18:
  print(-1)
else:
  print(ans // 3)

Measured memory_bytes: 157308
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

ll n,m,d;

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

    double x=(m-1)*(n-d);
    if(d!=0) x*=2;
    double y=n*n;

    double ans=x/y;
    cout<<setprecision(16)<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int x=scan.nextInt();
        int y=scan.nextInt();
        while(x>0||y>0){
            int ans=0;
            for(int bit =0;bit<(1<<10);bit++){
                int cnt=0;
                int sum=0;
                for(int i=0;i<10;i++){
                    if((1 & (bit>>i))==1){
                        sum+=i;
                        cnt++;
                    }
                }
                if(cnt==x && sum==y){
                    ans++;
                }
            }
            System.out.println(ans);
            x=scan.nextInt();
            y=scan.nextInt();
        }
    }
}


Measured memory_bytes: 26584
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f first
#define s second
using namespace std;

int main(){
   int n; cin >> n;
   string s; s = to_string(n);
   int temp = 0;
   for(int i  = 0; i < s.length(); i++){
    	temp += (int)s[i]-'0';
   }
   if(n%temp)cout << "No" << endl;
   else cout << "Yes" << endl;
   return 0;
}                  


Measured memory_bytes: 3676
import math

n = (int)(input())

#
remain = []
while n > 0:
    re = n % 26
    if re == 0:
        re = 26
    remain.append(re)
    n = math.floor(n / 26)
    if re == 26:
        n -= 1
remain.reverse()

#
ret = ""
for i in remain:
    ret += chr(i + 96)

print("{}".format(ret))

Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
using namespace std;
typedef long long int ll;


int main() {

	int n;
	cin >> n;

	for (int i = 1; i <= 9; i++) {
		if (n<=100*i+10*i+i) {
			cout << 100 * i + 10 * i + i << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k;
    cin>>n>>k;
    ll N=n;
    if(k>((N-1)*(N-2)/2)) cout<<-1;
    else
    {
        cout<<((N*(N-1))/2)-k<<endl;
        for(int i=2;i<=n;i++) cout<<1<<" "<<i<<endl;
        int rem=(((N-1)*(N-2))/2)-k, cnt=0;
        for(int i=2;i<=n && cnt<rem;i++)
        {
            for(int j=i+1;j<=n && cnt<rem;j++,cnt++)
            {
                cout<<i<<" "<<j<<endl;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Main myself = new Main();
		int answer = myself.execute();

		System.out.print(answer);
	}

	/**
	 * 実処理メソッド
	 */
	public int execute() {

		try (Scanner scanner = new Scanner(System.in)) {

			final int N = scanner.nextInt();

			double sqrt = Math.sqrt(N);

			// iはテスト数
			for (int i = N; 0 < i; i--) {

				for (int j = (int) sqrt + 1; 0 < j; j--) {

					if (j * j == i) {
						return i;
					}
				}
			}

			return 0;
		}

	}

}


Measured memory_bytes: 22100