akhauriyash/Code-Regression huggingface dataset:
import statistics
import math

n = int(input())
 
a = []
for _ in range(n):
    a.append(list(map(int,input().split())))

b = [[],[]]
for i in range(n):
    b[0].append(a[i][0])
    b[1].append(a[i][1])

x = statistics.median(b[0])
y = statistics.median(b[1])

if n % 2 != 0:
    ans = y - x + 1

else:
    ans = round((y - x) * 2) + 1

print(ans)

Measured memory_bytes: 52636
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int N,i,j=-1,Y,cnt=0,f1;
    int m[1000];
  cin>>N;
  i=log(N)/log(2);
  f1=2*pow(2,i)-1;
    cout<<f1<<endl;
     
 
    
    
    

    }

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,x,ans=1;
    map<lli,lli> mp;
    vector<lli> vec;
    lli i,j;
    cin>>n;
    if(n==1){
        cout<<"1"<<endl;
        exit(0);
    }
    rep(i,2,n+1){
        x=i;
        lli sosu=2;
        while(x!=1){
            if(x%sosu==0){
                mp[sosu]++;
                x/=sosu;
            }
            else{
                sosu++;
            }
        }
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        ans*=itr->second+1;
        ans%=N;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100005][2];
int f(int k, int* a, int n, bool p)
{
    // if(k<a[0])return !p;
    // int dp[2][n+2][k+2];
    // for(int i=a[0];i<=k;i++)
    // {
    //     for(int j=0;j<n;j++)
    //     {
    //         if(i<a[j]){
    //             dp[0][j][i]=1;
    //             dp[1][j][i]=0;
    //         }
    //         if(dp[0][j][i]==0 && dp[1][][i-a[j]])
    //     }
    // }
    if(dp[k][p]!=-1)return dp[k][p];
    int ans=(!p);
    for(int i=0;i<n;i++)
    {
        if(k>=a[i])
        {
            if(f(k-a[i],a,n,!p)==p){
                ans=p;
                break;
            };
        }
        // else break;
    }
    dp[k][p]=ans;
    return ans;
}
int main()
{
    int n,k;
    cin>>n>>k;
    int* a=new int[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<100004;i++)
    {
        dp[i][0]=-1;
        dp[i][1]=-1;
    }
    sort(a,a+n,greater<int>());
    if(f(k,a,n,true))cout<<"First";
    else cout<<"Second";

}

Measured memory_bytes: 10368
import java.util.Scanner;
public class Main{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
int i=0;
int c=0;
int a[]=new int[100];
int b[]=new int[100];
int x=0;
int y=0;
do {
	a[i]=scan.nextInt();
	b[i]=scan.nextInt();
	if(b[i]==0&&a[i]==0) {
		break;
	}
	i++;
}while(true);
i=0;
do {
	if(b[i]==0&&a[i]==0) {
		break;
	}
	if(c%2==0) {
	if(x%2==0) {System.out.print("#");x++;}
	else {System.out.print(".");x++;}
	}
	if(c%2==1) {
	if(x%2==0) {System.out.print(".");x++;}
	else {System.out.print("#");x++;}
	}
	if(x==b[i]) {System.out.println();
	y++;
	x=0;
	c++;
	}
	if(y==a[i]) {System.out.print("\n");i++;y=0;x=0;c=0;}
}while(true);
}
}


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

int findthesum(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

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

    if(N % findthesum(N) == 0)cout << "Yes" <<  endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;


int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int start = 0;
	int end = s.size() - 1;
	while (start < s.size() && s[start] == '.')
		start++;
	while (end >= 0 && s[end] == '#')
		end--;
	s = string(s.begin() + start, s.begin() + end + 1);
	
	if (s.size() == 0) {
		cout << 0 << endl;
		return 0;
	}
	vector<int> b, w;
	int index = 0;
	while (index < s.size()) {
		int c = 0;
		if (s[index] == '.') {

			while (index < s.size() && s[index] == '.') {
				index++;
				c++;
			}
			w.push_back(c);
		}
		else {
			while (index < s.size() && s[index] == '#') {
				index++;
				c++;
			}
			b.push_back(c);
		}
	}
	int res = 0x3f3f3f3f;
	for (int i = 1; i < b.size(); i++) {
		b[i] += b[i-1];
	}
	for (int i = w.size() - 2; i >= 0; i--) {
		w[i] += w[i+1];
	}
	for (int i = 0; i < b.size() - 1; i++)
		res = min(res, b[i] + w[i+1]);
	res = min(res, b[b.size() - 1]);
	res = min(res, w[0]);
	cout << res << endl;
}


Measured memory_bytes: 1596
// @author: arch_

#include <bits/stdc++.h>
using namespace std;

array<array<int, 100 + 1>, 100 + 1> t;

int main(void) {
    int r, c;
    cin >> r >> c;
    for (int i = 0; i < r; i++)
        for (int j = 0; j < c; j++) cin >> t[i][j];
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            t[i][c] += t[i][j];
            t[r][j] += t[i][j];
            t[r][c] += t[i][j];
        }
    }
    for (int i = 0; i <= r; i++) {
        for (int j = 0; j <= c; j++) {
            cout << t[i][j];
            if (j != c) cout << " ";
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll rec(ll N, ll X)
{
  if (N == 0) {
    return 1;
  }
  if (X == 1) {
    return 0;
  }
  ll H = pow(2, N + 1) - 3;
  if (H + 2 == X) {
    return pow(2, N);
  }
  if (H + 1 >= X) {
    return rec(N - 1, X - 1);
  }
  else {
    return pow(2, N) + rec(N - 1, X - H - 2);
  }
}

int main()
{
  ll N, X;
  cin >> N >> X;
  cout << rec(N, X) << endl;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int, int> pii;
const int mod = (int)1e9 +7;

map<ll, int> fctm( ll x ){
	map<ll, int> fmp;
	for( ;x>=4 && x%2==0; x/=2)  fmp[2]++;
	for(ll d=3, q=x/d; q>=d ; q=x/d){if(x%d==0) fmp[d]++, x=q; else d +=2;}
	if(x!=1) fmp[x]++;    //note: if x==1: {{1,1}}
	return fmp;
}

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	ll ans = 1LL;
	map<ll, int> mp;
	rep2(i, 2, n+1){
		auto rc = fctm(i);
		for(auto x: rc) mp[x.first] += x.second;
	}
	
	//for(auto x :mp) printf("%lld:%d, ",x.first,x.second); puts("");
	for(auto x :mp) (ans *= x.second+1) %=mod;
	cout << ans<<"\n";
	
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	lnt n;
	std::cin >> n;
	lnt ans=0;
	for(lnt i=1;i<=n;i++) {
		for(lnt j=1;j*i<=n;j++) {
			ans+=i*j;
		}
	}
	print(ans);
}


Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 

 class Main{
             
     static int[] ints=new int[10];
     public static void main2(String[] args) throws IOException {
        BufferedReader reader =
                new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String input = reader.readLine();
            if (input == null || input.equals("0")) {
                break;
            }
            long value = Long.parseLong(input);
            int count = 0;
            for (long i = 5; i <= value; i *= 5) {
                count += value / i;
            }
            System.out.println(count);
        }
    }
     public static void main(String args[]){
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
         try{
             String line;
             while((line=br.readLine())!= null){if(line.isEmpty())break;
             long nn = Long.parseLong(line), count=0;
             if(nn==0)break;
                for(int i=5; i<=nn;i*=5){
                    count+=nn/i;
                }
                System.out.println(count);
             }
             
         }catch(Exception e){}         
     }
   
 }

Measured memory_bytes: 16856
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
vector<int> v[333333];
int seg[333333*4],start = 1;
void upd(int wh,int x){
	wh += start;
	seg[wh] += x;
	for(int e=(wh/2);e>=1;e/=2) seg[e] = max(seg[e*2],seg[e*2+1]);
}
int getn(int l,int r){
	l += start;
	r += start;
	int ans = 0;
	while(l<=r){
		if(l%2){
			ans = max(ans,seg[l]);
			l++;
		}
		if((r%2)==0){
			ans = max(ans,seg[r]);
			r--;
		}
		l/=2;
		r/=2;
	}
	return ans;
}
int main(void){
	while(start<333333) start *= 2;
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int e=0;e<k;e++){
		int a,b;
		scanf("%d%d",&a,&b);
		upd(b,1);
		v[a].push_back(b);
	}
	int ans = 0;
	for(int e=1;e<=n;e++){
		int f1 = sz(v[e]);
		for(int p=0;p<sz(v[e]);p++){
			int nx = v[e][p];
			upd(nx,-1);
		}
		f1 += getn(1,m);
		ans = max(ans,f1);
		for(int p=0;p<sz(v[e]);p++){
			int nx = v[e][p];
			upd(nx,1);
		}
	}
	printf("%d",ans);
	return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, L;
  cin >> N >> L;
  int org = (N * (N + 1) / 2) - N + N * L;
  int ans = 1 << 29;
  REPI(i, 1, N + 1) { ans = min(ans, abs(-L - i + 1)); }
  org >= 0 ? cout << org - ans << endl : cout << org + ans << endl;

  return 0;
}

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

#define ll long long
#define mod 1000000007
#define inf 1000000000000000000
#define fr first
#define sc second
#define pb push_back
#define pf push_front
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,a,n) for(ll i=n-1;i>=a;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define umap unordered_map<ll,ll>
#define lpq priority_queue<ll,vector<ll>,greater<ll>>
ll powe(ll n,ll r){if(!r)return 1;else if(r%2==0)return powe(n*n,r/2);else return n*powe(n*n,(r-1)/2);}

int main(){
	/*
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/

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

	ll t=1;
	//cin>>t;
	while(t--){
		ll n;
		cin>>n;
		vector<ll> h(n);
		vector<ll> dp(n);
		for(ll i=0;i<n;i++)
			cin>>h[i];
		dp[0]=0;
		dp[1]=abs(h[1]-h[0]);
		for(ll i=2;i<n;i++)
			dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
		cout<<dp[n-1]<<endl;
	}

	return 0;

}

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

int main(){
	int n,x;
	cin>>n;
	x=(int)n/1.08;
	//if(n==(int)x*1.08||n==(int)x*1.08+1)cout<<x<<endl;
	bool flag=false;
	for(int i=1;i<n+6;i++){
		if((int)(i*1.08)==n){
			cout<<i<<endl;
			flag=true;
			break;
		}
	}
	if(flag==false) cout<<":("<<endl;
}


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

int main()
{
  int l,r,n,res=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
     cin>>a[i];
     if(i%2==0 && a[i]%2!=0)
     {
         res++;
     }
  }
  cout<<res<<"\n";
  return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		int a[];
		int s;
		int count;

		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}

			a = new int[n];
			count = 0;
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
			}
			s = sc.nextInt();

			int low = 0;
			int high = n - 1;
			int mid;
			while (low <= high) {
				mid = (low + high) / 2;
				count++;
				if (a[mid] == s) {
					break;
				} else if (a[mid] < s) {
					low = mid + 1;
				} else {
					high = mid - 1;
				}
				mid = (low + high) / 2;
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 12000
r_p_s_sum, K = map(int, input().split())
R,S,P = map(int, input().split())
enemy = input()
enemy_list = list(enemy)

# 全勝のポイント
max_points = enemy.count('r')*P + enemy.count('p') * S + enemy.count('s') * R

for i in range(K,len(enemy_list),1):
    if (enemy_list[i] == enemy_list[i-K]):
        if enemy_list[i] == 'r':
            max_points -= P
        elif enemy_list[i] == 'p':
            max_points -= S
        else:
            max_points -= R
        enemy_list[i] = 'NULL'
print(max_points)



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

int main() {
	int n = 0;
	int a[10000];
	int ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		for (int j = 0; j < 1000000000; j++) {
			if (a[i] % 2)break;
			else {
				ans++;
				a[i] /= 2;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
table = [i for i in range(n+1)]
mod = 10**9 + 7
mx, mn = int((1/2)*k*(table[-k] + table[-1])), int((1/2)*k*(table[0] + table[k-1]))
ans = mx - mn + 1

for i in range(k+1, n+2):
    mx += table[-i]
    mn += table[i-1]
    ans += mx - mn + 1
print(ans%mod)


Measured memory_bytes: 16784
from collections import deque
n = int(input())
a = [int(i) for i in input().split()]

d = deque()
for i in range(n):
    if i % 2 == 0:
        d.appendleft(a[i])
    else:
        d.append(a[i])
if n % 2 == 0:
    d.reverse()

for i in range(n):
    print(d.popleft(),end=' ')

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

using namespace std;

#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const ll MOD = 1e9+7;
const ll INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){
    return (a%b+b)%b;
}
ll gcd(ll a, ll b){
    return b ? gcd(b, a%b) : a;
}
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}
void Yes(){
    cout << "Yes" << endl;
}
void No(){
    cout << "No" << endl;
}
void Judge(bool b){
    b ? Yes() : No();
}
void YES(){
    cout << "YES" << endl;
}
void NO(){
    cout << "NO" << endl;
}
void JUDGE(bool b){
    b ? YES() : NO();
}
ll powmod(ll b, ll e){
    ll r = 1; while(e > 0) {if(e&1) r = (r%MOD)*(b%MOD)%MOD; b = (b%MOD)*(b%MOD)%MOD; e >>= 1;} return r;
}
double distance(ll x1, ll y1, ll x2, ll y2){
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

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;
}
template<typename T>
void ppp(T n){
    cout << n << endl;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    ll len = v.size();
    s << '[';
    for(ll i = 0; i < len; ++i) {
        s << v[i]; if(i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa {
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    }
} fastio;


vector<ll> dijkstra(ll s, ll n, vector<vector<pll> > G){
    vector<ll> dis(n, LINF);
    priority_queue<pll, vector<pll>, greater<pll> > q;
    dis[s] = 0;
    q.push(make_pair(0, s));
    while(!q.empty()) {
        ll d, v;
        tie(d, v) = q.top(); q.pop();
        if(dis[v] < d) continue;
        for(pll e : G[v]) {
            if(dis[e.second] > dis[v]+e.first) {
                dis[e.second] = dis[v]+e.first;
                q.emplace(dis[e.second], e.second);
            }
        }
    }
    return dis;
}

vector<vector<pll> > G;
int main(){

    ll n, m; cin >> n >> m;
    G.resize(3*n);
    rep(i, m){
        ll u, v;
        cin >> u >> v;
        --u; --v;
        rep(j, 3){
            G[j*n+u].emplace_back(1, (j+1)%3*n+v);
        }
    }
    ll s, t;
    cin >> s >> t;
    --s; --t;
    vector<ll> dis = dijkstra(s, 3*n, G);

    if(dis[t] == LINF) ppp(-1);
    else ppp(dis[t]/3);

    return 0;
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int n,L=(1<<9)-1;
vector<vector<pair<int,int>>> Q;
vector<int> ans;
vector<pair<int,int>> E[20];
vector<int> v,w;

void rec(int i,int d){
    E[d].emplace_back(0,0);
    if(d==10){
        E[d].emplace_back(w[i],v[i]);
    }
    else{
        int s{},t{},N=E[d-1].size();
        while(t<N){
            if(s>=N or E[d-1][t].first+w[i]<E[d-1][s].first){
                if(E[d-1][t].first+w[i]>100000) break;
                if(E[d].back().second<E[d-1][t].second+v[i]){
                    E[d].emplace_back(E[d-1][t].first+w[i],E[d-1][t].second+v[i]);
                }
                ++t;
            }
            else{
                if(E[d-1][s].first>100000) break;
                if(E[d].back().second<E[d-1][s].second){
                    E[d].push_back(E[d-1][s]);
                }
                ++s;
            }
        }
    }
    for(auto&[l,id]:Q[i]){
        if(d<10){
            ans[id]=(lower_bound(E[d].begin(),E[d].end(),make_pair(l+1,0))-1)->second;
        }
        else{
            for(auto&[W,V]:E[d]){
                if(W>l) break;
                chmax(ans[id],V+
                (lower_bound(E[9].begin(),E[9].end(),make_pair(l-W+1,0))-1)->second);
            }
        }
    }
    if(i*2<=n) rec(i*2,d+1);
    if(i*2+1<=n) rec(i*2+1,d+1);
    E[d].clear();
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>n;
    Q.resize(n+1);
    v.resize(n+1);
    w.resize(n+1);
    Fr(i,n) cin>>v[i]>>w[i];
    int q;
    struct qu{
        int i,v,l;
    };
    cin>>q;
    ans.resize(q);
    fr(i,q){
        int x,l;
        cin>>x>>l;
        Q[x].emplace_back(l,i);
    }
    E[0].emplace_back(0,0);
    rec(1,1);
    for(auto&i:ans) cout<<i<<'\n';
}

Measured memory_bytes: 15016
#include <bits/stdc++.h>
using namespace std;
char a,b,c,d;
int main(){
  cin >> a >> b >> c >> d;
  if(a==b){
    if(c==d && a!=c){
      cout << "Yes" << endl;
      return 0;
    }
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  if(a==c)
  {
    if(b==d && b!=c){
      cout << "Yes" << endl;
      return 0;
    }
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  if(a==d)
  {
    if(c==b && a!=c){
      cout << "Yes" << endl;
      return 0;
    }
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  if(b==c)
  {
    if(a==d && a!=c){
      cout << "Yes" << endl;
      return 0;
    }
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  if(b==d)
  {
    if(a==c && a!=b){
      cout << "Yes" << endl;
      return 0;
    }
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  if(c==d)
  {
    if(a==b && a!=c){
      cout << "Yes" << endl;
      return 0;
    }
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main( ) {
    //freopen("A.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, d;
    cin >> a >> b >> d;
    cout<< ((b-a)/d + ((a%d==0 || b%d==0)?1:0)) <<endl;
    return 0;
}

Measured memory_bytes: 3640
import math
a,b=map(int,input().split())
num = 0
unchi = -1
while num < 10500:
	num = num + 1
	if math.floor(num*0.08)==a:
		if math.floor(num*0.10)==b:
			unchi = num
			num = 12345
print(unchi)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)

struct TREE{
    int N;
    vector<vector<int> >path;
    queue<int>Q;
    vector<int>depth;
    vector<int>A;
    vector<int>B;
    void init(int n){
        N = n;
        path = vector<vector<int> >(N);
        depth = vector<int>(N, 0);
        A.clear();
        B.clear();
    }
    TREE(int n){
        init(n);
    }
    void addPath(int a, int b){
        A.push_back(a);
        B.push_back(b);
        path[a].push_back(b);
        path[b].push_back(a);
    }
    void resetDepth(){
        for(int i=0; i<N; i++)depth[i] = -1;
    }
    void addRoot(int id){
        depth[id] = 0;
        Q.push(id);
    }
    void calcDepth(){
        while(!Q.empty()){
            int id = Q.front();
            Q.pop();
            for(int i=0;i<path[id].size();i++){
                int nxt = path[id][i];
                if(depth[nxt] < 0){
                    depth[nxt] = depth[id] + 1;
                    Q.push(nxt);
                }
            }
        }
    }
};

int main(){

    int N, K;
    cin >> N >> K;
    TREE tree(N+1);
    for(int i=0;i<N-1;i++){
        int a, b;
        cin >> a >> b;
        tree.addPath(a, b);
    }

    int mx = 0;
    if(K%2 == 0){
        K/=2;
        for(int i=1; i<=N; i++){
            tree.resetDepth();
            tree.addRoot(i);
            tree.calcDepth();
            int cnt = 0;
            for(int i=1;i<=N;i++){
                if(0<=tree.depth[i] && tree.depth[i]<=K)cnt++;
            }
            mx = max(mx, cnt);
        }
    }
    else{
        K/=2;
        for(int i=0;i<tree.A.size();i++){
            tree.resetDepth();
            tree.addRoot(tree.A[i]);
            tree.addRoot(tree.B[i]);
            tree.calcDepth();
            int cnt = 0;
            for(int i=1;i<=N;i++){
                if(0<=tree.depth[i] && tree.depth[i]<=K)cnt++;
            }
            mx = max(mx, cnt);
        }
    }
    cout << N - mx << endl;

    return 0;
}

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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ちゃんとユニークな配列にする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int N;
  cin >> N;
  map<int, ll> lmap;
  lmap.insert(make_pair(0, 2));
  lmap.insert(make_pair(1, 1));
  for(int i = 2; i <= N; i++) {
    ll l = lmap.at(i - 1) + lmap.at(i - 2);
    lmap.insert(make_pair(i, l));
  }
  cout << lmap.at(N) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
     int x,y;
     while(1){
     scanf("%d",&x);
     scanf("%d",&y);
     if(x==0&&y==0){break;}
     else if(x<y){
       printf("%d %d\n",x,y);}
     else {
       printf("%d %d\n",y,x);}
     }
     return 0;
}


Measured memory_bytes: 2104
def primes(n):
    is_prime = [-1] * (n + 1)
    is_prime[0] = 0
    is_prime[1] = 1
    for i in range(2, n + 1):
        if is_prime[i] != -1:
            continue
        for j in range(i, n + 1, i):
            if is_prime[j] == -1:
                is_prime[j] = i
    return is_prime

n = int(input())
a = list(map(int,input().split()))
s = primes(max(a))
d = {}
for i in a:
    now = i
    while s[now] != 1:
        t = s[now]
        d[t] = d.get(s[now],0) + 1
        while now % t == 0:
            now //= t
            
                
            
    
flag = True
for v in d.values():
    if v == n:
        print("not coprime")
        exit()
    elif v > 1:
        flag = False

if flag:
    print("pairwise coprime")
else:
    print("setwise coprime")
        

Measured memory_bytes: 189392
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    string S, T;
    cin >> S >> T;
    ll count=0;
    rep(i,S.size()){
        if(S[i]!=T[i]){
            count++;
        }
    }
    cout << count << endl;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var cnt = new int[50, 26];
            String str;
            for (int i = 0; i < n; i++)
            {
                str = Console.ReadLine();
                for (int j = 0; j < str.Count(); j++)
                {
                    cnt[i, (int)str[j] - (int)'a']++;
                }
            }
            var cntmin = new int[26];

            for (int i = 0; i < 26; i++)
            {
                cntmin[i] = cnt[0, i];
            }

            for (int i = 0; i < 26; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (cntmin[i] > cnt[j, i]) cntmin[i] = cnt[j, i];
                }
            }
            for (int i = 0; i < 26; i++)
            {
                for (int j = 0; j < cntmin[i]; j++) Console.Write((char)(i + 'a'));
            }
        }
    }
}


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

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

    vector<int> L(N);
    for (int i=0; i<N; i++) {
        cin >> L[i];
    }

    sort(L.begin(), L.end());
//    for (int i=0; i<N; i++) {
//        cout << L[i] << ' ';
//    }
//    cout << endl;

    int numTriangle = 0;
    int a, b, c;
    for (int i=0; i<N; i++) {
        a = L[i];
        for (int j=i+1; j<N; j++) {
            b = L[j];
            for (int k=j+1; k<N; k++) {
                c = L[k];
                if (c < (a +b)) {
                    numTriangle++;
                }
                //numTriangle += isTriangle(a, b, c);
            }
        }
    }

    cout << numTriangle << endl;
    return 0;
}


Measured memory_bytes: 384
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;

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

int main() {
	int n;
	cin >> n;
	VI a(n);
	VI b(n);
	VI diff(n);
	int ans = 0;
	long long sum=0;


	REP(i, n) {
		cin >> a[i];
	}
	REP(i, n) {
		cin >> b[i];
	}

	REP(i, n) {
		diff[i] = a[i] - b[i];
		if (diff[i] < 0) {
			sum += abs(diff[i]);
			ans++;
		}
	}
	VI copy(diff);
	SORT(copy);
	reverse(copy.begin(), copy.end());
	int i = 0;
	while (sum > 0 && i<n) {
		sum -= copy[i];
		ans++;
		i++;
	}
	if (sum > 0) {
		ANS(-1);
	}
	else {
		ANS(ans);
	}
	



	return 0;
}


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

typedef struct node *link;
struct node {
	int item;
	link next;
	link back;
};

void printlist(link h) {
	link t;
	for (t = h; t != NULL; t = t->next) {
		printf("%d", t->item);
		if (t->next != NULL) printf(" ");
	}
	printf("\n");
}


int main(void) {
	int n, i, d;
	link t, head = NULL;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		char comm[20];
		scanf("%s", comm);
		if (strlen(comm) < 7) scanf("%d", &d);

		if (comm[0] == 'i') {
			//printf("Command[%d] is insert %d => ", i + 1, d);
			link new = malloc(sizeof(link));
			new->item = d;
			new->next = head;
			if (head == NULL) new->back = new;
			else {
				new->back = head->back;
				head->back = new;
			}
			head = new;
		}
		else if (comm[0] == 'd') {
			if (comm[6] == 'F' || (strlen(comm) < 7 && head->item == d)) {
				//printf("deleteFirst => ");
				if (head->next == NULL) {
					free(head);
					head = NULL;
				}
				else {
					t = head;
					head = head->next;
					head->back = t->back;
					free(t);
				}
			}
			else if (comm[6] == 'L') {
				//printf("deleteLast => ");
				if (head->back == head) {
					free(head);
					head = NULL;
				}
				else {
					t = head->back;//??????????±?
					head->back = t->back;
					t->back->next = NULL;
					free(t);
				}
			}
			else {
				//printf("Command[%d] is delete %d => ", i + 1, d);
				link prev;
				t = head;//??????????±?
				while (t->item != d && t->next != NULL) {
					prev = t;
					t = t->next;
				}
				if (t->item == d) {
					prev->next = t->next;
					if (t->next == NULL) t->next = head;
					t->next->back = prev;
					free(t);
				}
			}
		}
		//printlist(head);
	}

	printlist(head);

	return 0;
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i <= max_i; i++)
using namespace std;
typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N; cin >> N;
  vector<int> v(N);
  REP(i,N) cin >> v[i];
  sort(v.begin(), v.end());
  
  int ans = v[N/2] - (v[N/2-1]);  
  cout << ans << endl;
   
  return 0;
}


Measured memory_bytes: 640
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
t = [T - 0.006*H[i] for i in range(N)]

d0 = 10000
r = -1
    
for i in range(N):
    d = abs(t[i]-A)
    if d < d0:
        d0 = d
        r = i
print(r+1)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

bool cmp(int a, int b){
  return a < b;	
}

void solve(){
   int a, b;
   cin >> a >> b;
   int v1 = a + b;
   int v2 = a - b;
   int v3 = a * b;
   int ret = max ({v1, v2, v3}, cmp);
   cout << ret << endl;	
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long int
#define mod 1000000007
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    ll n, a[100005] = {}, b[100005] = {}, z = 0;
    cin >> n;
    fr(n) cin >> a[i] >> b[i];
    for (ll i = n - 1; i >= 0; i--) {
        a[i] += z;
        if (a[i] % b[i] != 0) z += b[i] - a[i] % b[i];
        //cout << z << ' ';
    }
    cout << z << '\n';
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll 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;
}
int main(){
    ll N;
    cin>>N;
    
    map<ll,ll> a;
    VEC(ll,A,N);
    ll ans=0;
    REP(i,N){
        ll h;
        cin>>h;
        A[i]=h;
        if(a.count(h)==0)a[h]=1;
        else a[h]++;
    }
    for (const auto vv : a){
        ll v=vv.second;
        ans+=v*(v-1)/2;
    }
    REP(i,N){
        ll t=a[A[i]];
        if(t>=2)
        cout<<ans-(t*(t-1)/2)+((t-1)*(t-2)/2)<<endl;
        else cout<<ans<<endl;
    }
    //ll t=N*M;
    //cout<<fixed<<setprecision(20)<<N*M<<endl;
    //cout<<fixed<<setprecision(0)<<floor(t);
    //N-=F;
    //cout<<N/(M+F);
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 11008
a = int(input())
if a < 10:
  print(a)
elif a >= 10 and a < 100:
  print(9)
elif a >= 100 and a < 1000:
  print(9 + a - 100 + 1)
elif a >= 1000 and a < 10000:
  print(909)
elif a >= 10000 and a < 100000:
  print(909 + a - 10000 + 1)
else:
  print(90909)


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
map<string,int> mp;
int n;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    int mx=-1;
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        mp[s]++;
        mx=max(mx,mp[s]);
    }   
    for(map<string,int>::iterator it=mp.begin(); it!=mp.end();it++){
        if(it->second==mx)
            cout<<it->first<<endl;
    }
    return 0;
}

Measured memory_bytes: 23808
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define rep(i, j, k) for (auto i = j; i < k; i++)
#define rrep(i, j, k) for (auto i = j; i > k; i--)
using namespace std;

void solve(int &h, int &w) {
  int a[11][11];
  rep(i, 0, h) rep(j, 0, w) cin >> a[i][j];
  int ans = 0;
  rep(starti, 0, h - 2) rep(startj, 0, w - 2) {
    rep(leni, 3, h + 1 - starti) rep(lenj, 3, w + 1 - startj) {
      int _min = 100;
      rep(i, 0, leni) _min = min(_min, a[starti + i][startj]);
      rep(i, 0, leni) _min = min(_min, a[starti + i][startj + lenj - 1]);
      rep(j, 0, lenj) _min = min(_min, a[starti][startj + j]);
      rep(j, 0, lenj) _min = min(_min, a[starti + leni - 1][startj + j]);
      int _max = -1;
      int res = 0;
      rep(i, 0, leni - 2) rep(j, 0, lenj - 2) {
        _max = max(_max, a[starti + 1 + i][startj + 1 + j]);
        res += _min - a[starti + 1 + i][startj + 1 + j];
      }
      if (_min > _max) ans = max(ans, res);
    }
  }
  cout << ans << endl;
}

int main() {
  int h, w;
  while (cin >> h >> w, h) {
    solve(h, w);
  }
}



Measured memory_bytes: 3016
N, M, K = map(int, input().split())

mod = 998244353
f = [1]
for i in range(1,N+1):
    f.append((f[-1] * i) % mod)
def comb(n,r):
    return f[n] * (pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod) % mod

ans = 0

for i in range(K+1):
    k = ((M * pow((M-1), N-1-i, mod)) % mod) * comb(N-1,i)
    k %= mod
    ans += k
    ans %= mod
    
print(ans)
    
    
    


Measured memory_bytes: 81340
(def parse-input
  (fn [s]
    (mapv #(Integer/parseInt %) (clojure.string/split s #" "))))

(defn res [hs]
  (fn [k]
    (apply +' (drop k (sort > hs)))))

(def nk (parse-input (read-line)))
(def hs (parse-input (read-line)))

(def drop-hs-fn (res hs))
(println (drop-hs-fn (last nk)))

Measured memory_bytes: 97568
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif
            var line1 = Console.ReadLine();
            var line2 = Console.ReadLine();
            var solver = new Solver(line1, line2);
            var answer = solver.Solve();
            Console.WriteLine(answer);
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public Solver(string line1, string line2)
        {
            this.S = line1;
            this.T = line2;
        }

        public string S { get; set; }

        public string T { get; set; }

        public string Solve()
        {
            var ret = 0;

            foreach (var i in Enumerable.Range(0, S.Length))
            {
                if (this.S[i] != this.T[i])
                {
                    ret++;
                }
            }

            return ret.ToString();
        }
    }
}


Measured memory_bytes: 28332
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,m,ans=0;
  cin >> n >> m;
  vector<int> a(m),vec(m-1);
  rep(i,m){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  rep(i,m-1){
    vec.at(i)=abs(a.at(i+1)-a.at(i));
    ans+=vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  if(n>m){
    cout << 0;
    return 0;
  }
  rep(i,n-1){
    ans-=vec.at(i);
  }
  cout << ans;
}
    

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;




int n;
string s;
long long r,g,b;
long long res;
  
int main() {



  cin >>n>> s;

  
  for(char c : s){
    switch(c){
    case 'R': r++;break;
    case 'G': g++;break;
    case 'B': b++;break;
    }
  }

  res = r*g*b;

  
  for(int i=0 ; i<n ; i++){
    for(int j=i+1 ; j<n ; j++){
      
      int k = 2*j-i;
      
      /*
      if((j-i==k-j) && (s[i]^s[j]^s[k]) == ('R'^'G'^'B'))
	res--;
      */
      if(k<n && s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i])
	res--;
   
    }
  }

  cout << res << endl;
  
  return 0;
}



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

int main(void){

    int N, T;

    scanf("%d%d", &N, &T);

    int A[N];

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

    int max = 0, c = 0, u = 0, min = A[0];

    for(int i = 1; i < N; i++){
        if(A[i] > A[i-1]){
            u++;
        }else{
            if(A[i-1] - min > max){
                max = A[i-1] - min;
                c = 1;
            }else if(A[i-1] - min == max){
                c++;
            }
            u = 0;
        }
        if(A[i] < min){
            min = A[i];
        }
    }
    if(A[N-1] - min > max){
        c = 1;
    }else if(A[N-1] - min == max){
        c++;
    }

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

    return 0;
}

Measured memory_bytes: 2064
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

int main() {
	ll H, W;
	cin >> H >> W;

	ll ans = LINF;
	// H固定
	// s2,s3:残ったwを半分に
	for (ll i = 1; i < W; i++) {
		ll s1 = H * i;
		ll s2 = H * ((W-i)/2);
		ll s3 = H * (W-i-(W-i)/2);
		ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
	}

	// s2,s3:Hを半分に
	for (ll i = 1; i < W; i++) {
		ll s1 = H * i;
		ll s2 = H/2 * (W-i);
		ll s3 = (H-H/2) * (W-i);
		ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
	}
	// W固定
	// s2,s3:残ったhを半分に
	for (ll i = 1; i < H; i++) {
		ll s1 = i * W;
		ll s2 = (H-i)/2 * W;
		ll s3 = (H-i-(H-i)/2) * W;
		ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
	}

	// s2,s3:Wを半分に
	for (ll i = 1; i < H; i++) {
		ll s1 = i * W;
		ll s2 = (H-i) * (W/2);
		ll s3 = (H-i) * (W-W/2);
		ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
	}

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


Measured memory_bytes: 256
$n, $m, $q = gets.chomp.split.map(&:to_i)

$t = []
$q.times do
  a, b, c, d = gets.chomp.split.map(&:to_i)
  a -= 1
  b -= 1
  $t.push [a, b, c, d]
end

$res = 0

def f(i, s)
  if s.size == $n
    r = 0
    $t.each do |a, b, c, d|
      r += d if s[b] - s[a] == c
    end
    $res = [$res, r].max
    return
  end

  i.upto($m) do |j|
    ss = s.clone
    ss.push j
    f(j, ss)
  end
end


f(1, [])

puts $res

Measured memory_bytes: 15668
#include<bits/stdc++.h>
using namespace std;
#define repeat(i, n) for(int i = 0; i < (n); i++)

int main() {
	string S;
	long long K;
	cin >> S;
	cin >> K;
	
	int saigo = 100;
	int atai;

	repeat(i,S.length()) {
		if (S[i] != '1') {
			saigo = i;
			atai = stoi(S.substr(i, 1));
			break;
		}
	}
	if (K < saigo + 1) {
		cout << S[K - 1ll] << endl;
	}
	else {
		cout << atai << endl;
	}
	return 0;
}

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

int k;
int x[10],y[10];

double dist(int i,int j){
  double dx = x[i]-x[j];
  double dy = y[i] -y[j];
  return pow(dx*dx+dy*dy,0.5);

}

int main() {
    cin >> k;
    for(int i = 0;i<k;i++){
     cin >> x[i]>>y[i];
    }
    double g;
    vector<int> jun;
    for (int i = 0; i < k; i++) { // one_case = {0,1,2,3,...n-1} とする
        jun.push_back(i);
    }
    do {
      for(int i= 0;i<k-1;i++){
        g+=dist(jun[i],jun[i+1]);
      }
    } while (next_permutation(jun.begin(), jun.end()));
    double wa =1;
    for(double o = 1;o<=k;o++){wa*=o;}
    double ko = g/wa;
    cout << fixed << setprecision(10) << ko<< endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int int64_t

int32_t main() {
	int n , i , j , k, l;
	cin >> n >> k;
	int c[n];
	for(i=0;i<n;i++) cin >> c[i];
	int dp[k+1] = {0};
	for(i=1;i<=k;i++) {
		for(j=0;j<n;j++) {
			if(c[j] <= i) {
				if(dp[i-c[j]] == 0) {
					dp[i] = 1;
					break;
				}
			}
		}
	}
	// for(i=0;i<=k;i++) cout << dp[i] << ' ';cout << endl;
	puts(dp[k]?("First"):("Second"));
	return 0;
}

Measured memory_bytes: 1024
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
l = LI()
max_l = max(l)
max_i = l.index(max(l))
l.pop(max_i)
if max_l < sum(l):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9092
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    string s; cin >> s;
    int q; cin >> q;
    string mae, ushiro;
    bool b = false; // false : 普通
    for (int _ = 0; _ < q; _++) {
        int p; cin >> p;
        if (p == 1) {
            b ^= true;
        }
        else {
            int f; cin >> f;
            char c; cin >> c;
            if ((f == 1) ^ (b)) {
                mae += c;
            }
            else {
                ushiro += c;
            }
        }
    }
    reverse(mae.begin(), mae.end());
    s = mae + s + ushiro;
    if (!b) {
        cout << s << endl;
    }
    else {
        reverse(s.begin(), s.end());
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 1348