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

#define ff              first
#define ss              second
#define ll            long long

#define pb              push_back
#define mp              make_pair
#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 mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)

//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void sb()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
const int N = 100000;
vector<int> dp(N+1);
 vector<vector<int>> graph(N+1,vector<int> (0));
int dfs(int source){


    //cout<<source<<" -> ";
    if(dp[source]!=-1)
    return dp[source];
    
    if(graph[source].size()==0)
    return dp[source]=0;
    for(auto child:graph[source]){
        
       
           
       
       
       dp[source] = max(dp[source],1+dfs(child));
      
    }
    //cout<<endl;

 
return dp[source];
}
int main()
{
	//sb();
    int n,m;
    cin>>n>>m;
   
   
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        graph[u].pb(v);
    }
    for(int i=0;i<N+1;i++)dp[i]=-1;

    int ans =0;

   for(int i=1;i<n+1;i++){
ans = max(ans,dfs(i));
   }
//    for(int i=1;i<dp.size();i++){
//        cout<<i<<" : "<<dp[i];
//        cout<<endl;
//    }
    cout<<ans;




return 0;
}



Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
#define bitCount(num)  __builtin_popcount(num)
#define pb push_back
#define ll long long
#define bye return 0;
#define f(i,a,b) for( long long i=a;i<b;i++)
#define testCases long long t;cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define newLine <<"\n"
#define all(x) (x).begin(), (x).end()
#define vll vector<long long>




ll knapSack_Memo(vector<pair<int,ll>> p,vector<vector<ll>> &dp, int currSum, int n)
{
     

	if(n==0|| currSum==0) 
		return dp[n][currSum]=0;


if(dp[n][currSum]!=-1) return dp[n][currSum];


  if(p[n-1].first<= currSum) 
  	{
  		ll ans1= p[n-1].second+knapSack_Memo(p,dp,currSum-p[n-1].first,n-1);
  		ll ans2=knapSack_Memo(p,dp,currSum,n-1);
  		return dp[n][currSum] =max(ans1,ans2);
  	}

  else return dp[n][currSum]=knapSack_Memo(p,dp,currSum,n-1);

}



int main()
{
    fast

    int n,w;
    cin>>n>>w;
    vector<pair<int,ll>> p_(n);

    f(i,0,n)
    {
    	int a;
    	ll b;
    	cin>>a>>b;
    	p_[i]={a,b};
    }
    // vector<pair<ll,ll>> p;

//     sort(p_.begin(),p_.end());
// // cout<<p.size()<<endl;
//     for(int i=n-1;i>=0;i--)p.pb(make_pair(p_[i].first,p_[i].second));
    // cout<<p.size()<<endl;
    vector<vector<ll>> dp(n+1, vector<ll>(w+1,-1));
    cout<<knapSack_Memo(p_,dp,w,n);
    // cout<<endl;
    // showDP(dp);




   
    bye
}

Measured memory_bytes: 83000
x, k, d = map(int, input().split())
x = abs(x)
if x > k * d:
    ans = x - k * d
else:
    K = x // d
    k -= K
    if k % 2 == 0:
        ans = x - K * d
    else:
        ans = (K+1) * d - x
print(ans)

Measured memory_bytes: 9176
#include <stdio.h>

int main(void){
	int A, B, C;
  
  	scanf("%d %d %d", &A, &B, &C);
  	
  	if((A+B+C) == 17){
  		if(A == 5){
     		if((B == 5) || (B == 7)){
				printf("%s%s%s", "Y", "E", "S");
      		}else{
             	printf("%s%s", "N", "O");
            }
    	}else if(A == 7){
        	if(B == 5){
             	printf("%s%s%s", "Y", "E", "S");
            }else{
              	printf("%s%s", "N", "O");
            }
        }else{
         	printf("%s%s", "N", "O");
        }
    }else{
    	printf("%s%s", "N", "O");
    }
  
	return 0; 
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>

using namespace std;

int main(){	
	int N;
	int K;
	cin>>N>>K;
	long long ans=1;
	for(int i=1;i<N;++i){
		ans*=K-1;
	}
	cout<<ans*K<<endl;
	return 0;
}

Measured memory_bytes: 384
'use strict';
(function(stdin) {
  var inputs = stdin.toString().trim().split('\n');
  var params = inputs[0].split(' ').map(Number);

  (function(a, b) {
      console.log(f(a,b));
      function f(a,b){
        if (a > b){return 'a > b';}
        if (a < b){return 'a < b';}
        return 'a == b';
      }
  }(params[0], params[1]));

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_V = 15;
const int MAX_E = MAX_V * MAX_V / 2;
int s, t;
int d[MAX_E][MAX_E];
int V, E;
int dp[1 << MAX_V][MAX_V];

int main()
{
  cin >> V >> E;
  rep(i, V) rep(j, V) d[i][j] = -1;
  rep(i, E){ cin >> s >>t; cin >> d[s][t]; }

  rep(S, 1<<V) rep(v, V) dp[S][v] = INF;
  dp[(1 << V) - 1][0] = 0;
  rev(S, (1<<V)-1) rep(v, V) rep(u, V) if(d[v][u]>=0 && !(S & (1 << u)))
    minup(dp[S][v], dp[S | 1 << u][u] + d[v][u]);

  cout << ((dp[0][0] >= INF) ? -1 : dp[0][0]) << endl;

  return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main() {
    ll n,m;
  cin>>n>>m;  //入力
  vector<ll> broken(n + 1);  //壊れた段を記録する配列
   rep(i,m){
    ll a;
     cin>>a;
    broken[a]++;
 } //壊れた段を1として記録
  vector<ll> dp(n+1); //DP配列
    dp[1]=1; dp[2]=2;   //1、2段目が壊れていないときの初期条件
if(broken[1]!=0){
  dp[1]=0;
  dp[2]=1;
}  //1段目が壊れているときの初期条件
if(broken[2]!=0) dp[2]=0; //2段目が壊れているときの初期条件
rep2(i,3,n+1){
if(broken[i]==0) dp[i]=(dp[i-1]+dp[i-2])%MOD;
else dp[i]=0;
    } //3段目以降DPをする
    cout<<dp[n]%MOD<<endl;  //出力
    
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<ios>
#include<cmath>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<assert.h>
#include<bitset>
#include<tuple>
#include<climits>
#include<deque>
#include<utility>
#include<unordered_map>
#include<unordered_set>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<ext/pb_ds/assoc_container.hpp>
#include<chrono>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define int            int64_t
#define double         long double
#define nitro          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi             vector<int64_t>
#define pub            push_back
#define puf            push_front
#define pob            pop_back
#define pof            pop_front
#define PI             3.1415926535897932384626433832795
#define read(a)        for(auto& x : a) cin>> x
#define endl           '\n'
#define gap            ' '
#define min3(a,b,c)    min(a, min(b, c))
#define max3(a,b,c)    max(a, max(b, c))
#define MOD            1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
bool confirm (string s)
{
	string s1=s;
	reverse (s1.begin(),s1.end());
	return s1==s;
}
int32_t main()
{
    nitro
    string s,s1,s2;cin>>s;
    s1=s.substr(0,(s.size()-1)/2);
    s2=s.substr((s.size()-1)/2+1,s.size()-s1.size()-1);
    if(confirm(s) and confirm(s1) and confirm(s2)) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

ll LCM(ll x , ll y){
	return (x*y) / __gcd(x,y) ;
}

ll NumOfDiv(ll a , ll b , ll k){
	return b/k - a/k + (a%k == 0) ;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// ----------------------
	int n , t , a; 
	cin >> n >> t ; 
	pair<int , int > x[n] ;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i].f >> x[i].s ;
		
	}
	sort(x , x+n) ;
	for (int i = 0; i < n; ++i)
	{
		if(x[i].s <= t){
			cout << x[i].f << endl ;
			return 0;
		}
	}
	cout << "TLE" << endl ;
	return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <tuple>
#include <queue>
using namespace std;

typedef long long ll;

#define INF 100000000;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define eps 1.0e-14;
#define mod 1e9 + 7;

int main(){
	string S; cin >> S;
	cout << S[0] << S[1] << S[2] << endl;
	return 0;
}

Measured memory_bytes: 3624
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		int a = in.nextInt();
		if (n + m + a == 0) return false;
		a--;

		int[][] e = new int[m][3];

		for (int i=0; i<m; i++) {
			for (int j=0; j<3; j++) {
				e[i][j] = in.nextInt() - 1;
			}
		}

		Arrays.sort(e, new Comparator<int[]>(){
			public int compare(int[] a, int[] b) {
				return b[0] - a[0];
			}
		});

		int[] p = new int[n];
		for (int i=0; i<n; i++) {
			p[i] = i;
		}

		for (int i=0; i<m; i++) {
			int t = p[e[i][1]];
			p[e[i][1]] = p[e[i][2]];
			p[e[i][2]] = t;
		}

		for (int i=0; i<n; i++) {
			if (p[i] == a) {
				out.println((i+1));
			}
		}

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 70860
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long N,A,B;
  int ans=0;
  bool prime=true;
  cin>>N;
  if(N%2==0){
    prime=false;
  }else{
    for(long i=3;i<=(long)sqrt(N);i+=2){
      if(N%i==0){
        prime=false;
        break;
      }
    }
  }
  if(prime){
    while(N!=0){
      ans++;
      N=N/10;
    }
  }else{
    for(long i=(long)sqrt(N);i>3;i--){
      if(N%i==0){
        A=N/i;
        while(A!=0){
      		ans++;
      		A=A/10;
    	}
        break;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
	int a, b, c, d, e, k, deter = 0;
	cin >> a >> b >> c >> d >> e >> k;
	if(e-a > k)deter = 1;
	//if(c-b > k)deter = 1;
	//if(d-c > k)deter = 1;
	//if(e-d > k)deter = 1;
	if(deter)cout << ":(";
	else cout << "Yay!";
	
	
return 0;
}


Measured memory_bytes: 256
def resolve():
    def f(mid):
        return sum([(x - mid * b + a - b - 1) // (a - b) for x in h if x > mid * b]) <= mid
    n, a, b = map(int, input().split())
    h = [int(input()) for _ in range(n)]
    ok, ng = 10 ** 10, 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if f(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 11060
from math import sqrt
 
n, m = map(int, input().split())
l = []
for i in range(1, int(sqrt(m)) + 1):
	if m % i == 0:
		l.append(i)
		l.append(m // i)
 
ans = 1
for d in l:
	if d * n <= m:
		ans = max(ans, d)
 
print(ans)

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

int main(){
    int a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>


// I/O
int get_int() {
    int n = 0;
    int c = getchar_unlocked();
    if(c == 45) {
        c = getchar_unlocked();
        while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
        return -n;
    } else if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}
void put_int(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    if(n < 0) n = -n, putchar_unlocked('-');
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
void put_str(char *str) { while(*str) putchar_unlocked(*str++); }
//


int main(int argc, char **argv) {
    int h = get_int();
    int a[h + 1];
    for(int i = 1; i <= h; ++i) a[i] = get_int();
    for(int i = 1; i <= h; ++i) {
        put_str("node "), put_int(i);
        put_str(": key = "), put_int(a[i]), put_str(", ");
        if(i / 2) put_str("parent key = "), put_int(a[i / 2]), put_str(", ");
        if(i * 2 <= h) put_str("left key = "), put_int(a[i * 2]), put_str(", ");
        if(i * 2 + 1 <= h) put_str("right key = "), put_int(a[i * 2 + 1]), put_str(", ");
        putchar_unlocked('\n');
    }
    return 0;
}



Measured memory_bytes: 2104
import java.util.*; 
	public class Main {
	public static void main( String[] args) {			
					
					Scanner in = new Scanner(System.in);
					long h = in.nextLong();
					long w = in.nextLong();
					long u = h*w;
					if(h==1||w==1) {
						System.out.println(1);
					}
					else if(u%2 ==0) {
						System.out.println(u/2);
					}
					else if(u%2!=0){
						long y = u/2;
						System.out.println(y+1);
						
						
					}
		
					
			}}

Measured memory_bytes: 22740
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 500
// max: 250000 * 1000
#define INF (1e+9)
#define COLOR_MAX 30
#define GROUPS 3

int calc(int group[][COLOR_MAX+1], int *cs, int ds[][COLOR_MAX+1], int colors) {
    int i, c;
    int disorder = 0;
    for(i = 0; i < GROUPS; i++) {
        for(c = 1; c <= colors; c++) {
            int before = c;
            int after = cs[i];
            disorder += ds[before][after] * group[i][c];
        }
    }
#ifdef DEBUG
    printf("%d, %d, %d -> %d\n", cs[0], cs[1], cs[2], disorder);
#endif
    return disorder;
}

int main(void) {
    int num, colors;
    get_int2(&num, &colors);
    // 1-indexed
    static int ds[COLOR_MAX+1][COLOR_MAX+1];
    static int mat[NUM_MAX+1][NUM_MAX+1];
    int i, j;
    for(i = 1; i <= colors; i++) {
        fget_array(&ds[i][1], colors);
    }

    for(i = 1; i <= num; i++) {
        fget_array(&mat[i][1], num);
    }

    static int group[3][COLOR_MAX+1];
    for(i = 1; i <= num; i++) {
        for(j = 1; j <= num; j++) {
            int c = mat[i][j];
            group[(i+j)%3][c]++;
        }
    }

    int c0, c1, c2; // c_(mod)
    int ans = INF;
    for(c0 = 1; c0 <= colors; c0++) {
        for(c1 = 1; c1 <= colors; c1++) {
            if(c0 == c1) continue;
            for(c2 = 1; c2 <= colors; c2++) {
                if(c1 == c2) continue;
                if(c0 == c2) continue;
                int cs[3] = {c0, c1, c2};
                int res = calc(group, cs, ds, colors);
                ans = min(ans, res);
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

int main() { 	
 int A,B;
 cin >>A>>B;
 int C=A+B;
	if(C%2==0){
		cout << C/2 <<endl;
	}else if(C%2==1){
		cout << "IMPOSSIBLE"<<endl;
	}
}

Measured memory_bytes: 256
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     .      '                    Udit Gupta @luctivud         ,              
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            ##      ##  #######  # #  ######
                            ##      ##  ##   ##  ###    ##
                            ##      ##  ##    #  # #    ##
                            ####### ##  #######  # #    ##
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| WORSHIPPER OF GREED |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

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

const long long int MODPRIME {1000000007};

#define FASTINPUTOUTPUTLIKELIGHT()    ios_base::sync_with_stdio(false);
#define TESTCASES()                   long long int TestCases; cin>>TestCases; while(TestCases--)
#define mems(arr,val)                 memset((arr), val, sizeof((arr)))
#define endl                          "\n"

// ///////////////////////////////////////////////////////////////////////////////////////////////
//               : AREA TO DEFINE ALL THE HELPER FUNCTIONS USED IN THE PROGRAM :                //
// ///////////////////////////////////////////////////////////////////////////////////////////////


// ///////////////////////////////////////////////////////////////////////////////////////////////
//                                 : MAIN PROGRAM STARTS HERE :                                 //
// ///////////////////////////////////////////////////////////////////////////////////////////////

void solve() {
    long int radius;
    cin >> radius;
    long double circumference = (22 * 2 * (long double)radius) / 7;

    cout << circumference << endl;
    return;
}

signed main() {
    FASTINPUTOUTPUTLIKELIGHT()
    // TESTCASES()
        solve();
    return 0;
}
/*
THE LOGIC AND APPROACH WAS DEVELOPED BY ME @luctivud.
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
PLEASE DO NOT PLAGIARISE.
*/

Measured memory_bytes: 3820
def trace(A: list):
    print(*A)

def insertionSort(A: list, N:int) -> list:
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and v < A[j]:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        trace(A)

    return A


N = int(input())
A = list(map(int, input().split()))

trace(A)
insertionSort(A, N)






Measured memory_bytes: 5980
x1, y1, x2, y2 = map(int, input().split())

x3 = x2 - y2 + y1
y3 = y2 + x2 - x1
x4 = x1 - y2 + y1
y4 = y1 + x2 - x1

print(x3, y3, x4, y4)

Measured memory_bytes: 2940
N = int(input())
play_list = []
time_sum = 0
sleep = 0
l = 51

for i in range(N):
    for j in range(1):
        song = input().split()
        play_list.append(song)

last_song = input()

for i in range(N):
    if last_song in play_list[i][0]:
        sleep = int(play_list[i][1])
        l = i
    if i >= l:
        time_sum += int(play_list[i][1])

print(time_sum - sleep)


Measured memory_bytes: 3060
from math import ceil


def main():
    length = int(input())
    sequence = [0 for _ in range(length)]
    target = [0 for _ in range(length)]
    for i in range(length):
        a, b = map(int, input().split())
        sequence[i] = a
        target[i] = b
    answer = 0
    cumulative_push = 0
    for i in range(-1, -length - 1, -1):
        sequence[i] += cumulative_push
        now_push = ceil(sequence[i] / target[i]) * target[i] - sequence[i]
        cumulative_push += now_push
        answer += now_push
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 15016
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


signed main(void) 
{
    ll n;
    cin >> n;
    ll r = 0;
    rrep (i, n) {
        if (i < 10 || (i >= 100 && i <= 999) || (i >= 10000 && i <= 99999)) r++;
    }
    mes(r);
    
    


}


Measured memory_bytes: 3604
#include <cmath>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 200005
#define mod 1000000007ll
using namespace std;
typedef long long ll;

inline int rd() {
  int x = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return x;
}

int n, c[N], f[N], pos[N], lst[N];

int main() {
  n = rd();
  f[0] = 1;
  for (int i = 1; i <= n; ++i) {
    c[i] = rd();
    if (lst[c[i]] < i - 1) pos[i] = lst[c[i]];
    lst[c[i]] = i;
    f[i] = (f[i - 1] + (pos[i] ? f[pos[i]] : 0)) % mod;
  }
  printf("%d\n", f[n]);
  return 0;
}


Measured memory_bytes: 3456
from collections import Counter
import math
def nCr(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, a, b = map(int, input().split())

values = [int(i) for i in input().split()]
values.sort(reverse=True)

MAX = sum(values[:a]) / a
print(MAX)
e = a + 1
use_nums = []
for i in range(a, b + 1):
    v = sum(values[:i]) / i
    if v == MAX:
        use_nums.append(Counter(values[:i]))

cd = Counter(values)
ans = 0
for nums in use_nums:
    t = 1
    for k, v in nums.items():
        m = cd.get(k)
        t = t * nCr(m, v)
    ans += t
print(ans)

Measured memory_bytes: 39280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  string s;
  cin >> s;
  cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
  return 0;
}


Measured memory_bytes: 3592
N,M = map(int,input().split())
A = list(map(int,input().split()))
C = [0,1,4,4,3,4,5,2,6,5]
dp = N*[0]+9*[-1]

for n in range(N):
  dp[n+1] = max(a+10*dp[n-C[a]] for a in A)

print(dp[N])

Measured memory_bytes: 20348
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[40000],a[200000],b[200000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<LL>vec;
vector<edge>ed;
vector<Pll>v;
map<LL,LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> h >> w >> n >> m;
	if ((h*w) % 2 == 1 && (n + m) % 2 == 1) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}



Measured memory_bytes: 3164
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M = map(int, input().split())
lamps = [list(map(lambda x:int(x)-1, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))

ans = 0

for i in range(1 << N):
    for r in range(M):
        on_sum = 0
        for j in range(N):
            if (i >> j)&1 and j in lamps[r]:
                on_sum += 1
        if on_sum % 2 != p[r]:
            break
    else:
        ans += 1
        
print(ans)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

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

    int n;
    while(cin >> n) {
        vi a(n);
        rep(i, n)cin >> a[i];
        sort(all(a));
        // rep(i, n)cout << a[i] << ' ';
        // cout << endl;
        int l = 0, r = n - 1;
        vi cnt(100001);
        rep(i, n)cnt[a[i]]++;

        int ans = n;
        while(l < r) {
            while(l < n && cnt[a[l]] < 2)l++;
            if(l == n)break;
            while(r > 0 && cnt[a[r]] < 2)r--;
            // debug(a[l]);
            // debug(a[r]);
            
            cnt[a[l]]--;
            cnt[a[r]]--;
            ans -= 2;
            l++; r--;
        }
        // debug(l);
        // debug(r);
        cout << ans << endl;
    }
}


Measured memory_bytes: 1024
X = int(input())
flag = 0
if X == 2 or X == 3:
    flag = 1
    print(X)
while flag == 0 :
    for i in range(2,int(X**0.5)+1):
        if X%i == 0:
            X += 1
            break
        else:
            if i == int(X**0.5):
                flag = 1
                print(X)

Measured memory_bytes: 80304
/*
ID: jerrywcy
TASK: AtCoder ABC 102 Problem B
LINK: https://abc102.contest.atcoder.jp/tasks/abc102_b
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int n;
int maxv=0,minv=INT_MAX;

int main()
{
	cin>>n;
	int i,j;
	for (i=1;i<=n;i++){
		int a;
		cin>>a;
		maxv=max(maxv,a);
		minv=min(minv,a);
	}
	cout<<maxv-minv<<endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}

ll h, n;
ll tmp;
ll su=0;
int main() {
    cin >> h >> n;

    rep(i, n) {
        cin >> tmp;
        su += tmp;

    }

    if (h <= su) {
        cout << "Yes";
    } else { 
        cout << "No";
    }

    cout << endl;

}



Measured memory_bytes: 256
import sys
import numpy as np
import string

N = int(input())
S = [input() for i in range(N)]

dict = string.ascii_lowercase#abc...xyz

data_list = np.zeros((N,26))

for i in range(0,N):
	list = []
	for j in range(0,26):
		list.append(S[i].count(str(dict[j])))
	data_list[i] = np.array(list)
data_min = data_list.min(axis = 0)

a = np.nonzero(data_min)
size = np.nonzero(data_min)[0].size
b = a[0]
kotae = ""
for i in range(size):
	Moji = dict[b[i]]*int(data_min[b[i]])
	kotae = kotae + Moji
	pass
print(kotae)



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

const vector<int> dr={-1,0,1,0};
const vector<int> dc={0,1,0,-1};

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  for(int i=0;i<H;i++){
    cin >> S[i];
  }
  vector<vector<int>> d(H,vector<int>(W,1e6));
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j]=='#'){
        continue;
      }
      vector<vector<int>> dist=d;
      queue<pair<int,int>> que;
      que.push(make_pair(i,j));
      dist[i][j]=0;
      while(!que.empty()){
        pair<int,int> state=que.front();
        que.pop();
        int count=dist[state.first][state.second];
        for(int k=0;k<4;k++){
          int nr=state.first+dr[k];
          int nc=state.second+dc[k];
          if(nr<0 || nr>=H || nc<0 || nc>=W){
            continue;
          }
          if(S[nr][nc]=='#'){
            continue;
          }
          if(dist[nr][nc]<=count+1){
            continue;
          }
          que.push(make_pair(nr,nc));
          dist[nr][nc]=count+1;
        }
      }
      int cans=0;
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          if(S[i][j]=='#'){
            continue;
          }
          cans=max(cans,dist[i][j]);
        }
      }
      ans=max(ans,cans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')

def main():
  s = input()
  count = Counter(s)
  ans = 'Yes'
  for i in count.values():
    if i != 2:
      ans = 'No'
  print(ans)
  
  
  
  
  
if __name__ == '__main__':
  main()

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

using namespace std;

#define fo(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define lli long long int
#define all(c) c.begin(),c.end()
#define lower(c) tolower(c)
#define upper(c) toupper(c)
#define max(c) *max_element(c.begin(),c.end())
#define min(c) *min_element(c.begin(),c.end())
#define len(c) c.size()
const int MOD = 1000000007;
const int MX = 2e5 + 5;
const int INF = 1e9 + 10;
const lli LINF = 1e18;
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
void solve() {
	int N, M; 
	cin >> N >> M;
    lli K; cin >> K;
    lli A[N], B[M]; fo(i, N) cin >> A[i];
    fo(i, M) cin >> B[i];
    lli as = 0; fo(i, N) as += A[i];
    lli bs = 0;
    int bp = 0;
    int ans = 0;
    for (int i = (N+1)-1; i >= 0; i--) {
        if (i < N) as -= A[i];
        if (as <= K) {
            while (bp < M && as + bs + B[bp] <= K) {
                 bs += B[bp]; bp++;
            }
            ckmax(ans, i + bp);
        }
    }
    cout << ans << endl;
}


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


    return 0;
}






Measured memory_bytes: 6776
import numpy as np
ans = 'YES'
a = np.array([])
for i in range(3):
    b, c = input().split()
    a = np.append(a, [b, c])
a = a.astype(np.int32)
for i in range(4):
    count = np.sum(a == i + 1)
    if count > 2:
        ans = 'NO'
        break
print(ans)

Measured memory_bytes: 14544
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
#define er erase
#define in insert
#define pi pair <int, int>
# define sz(x) (int)((x).size())
#define int long long

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

const ll inf = 0x3f3f3f3f3f3f3f;
const ll mod = 1999999973;
const int N = 2e5 + 11;

int dp[N],v,w,n,k,x;
//vector<int>v[N];

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cerr.tie(0); cout.tie(0);

    cin >> n >> k;

    memset(dp,0x3f,sizeof(dp));

    dp[0] = 0;

    forn(i,1,n){
        cin >> w >> v;
        for(int j = 1e5 + 5; j >= v; j--){
            dp[j] = min(dp[j] , dp[j-v] + w);
        }
    }

    for(int i = 1e5 + 5; i > 0; i--){
        if(dp[i] <= k){
            cout << i;
            break;
        }
    }
return 0;
}


Measured memory_bytes: 1792
A, B, C = map(int, input().split())

if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
    print(0)
    exit()

if A == B and B == C:
    print(-1)

else:
    step = 0
    while True:
        step += 1
        nA = B // 2 + C // 2
        nB = A // 2 + C // 2
        nC = A // 2 + B // 2
        A, B, C = nA, nB, nC
        if A % 2 != 0 or B % 2 != 0 or C % 2 != 0:
            print(step)
            break

Measured memory_bytes: 3064
//                                              Question ki ma ki chut !!
#include<bits/stdc++.h>
using namespace std;
#define Going_supersonic ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(a) a.begin(),a.end()
#define allr(v) v.rbegin(),v.rend()
#define sz() size()
#define l() length()
#define lli long long int
#define ed endl
#define iv vector<lli>
#define bg() begin()
#define e() end()
#define ff first
#define ss second
lli sti(string s)
{
    lli num=0;
    lli p=1;
    for(lli it=s.l()-1;it>=0;p*=10)
        num+=(s[(it--)]-48)*p;
    return num;
}
lli n,m,cnt,mx,mn,l,sm,r;
map<pair<lli,lli>,lli> dp;
lli solve(iv &a,iv &b ,iv &c, lli pos,lli alpha)
{
    if(pos==n-1)
    {
        if(alpha==0)
            return a[pos];
        else if(alpha==1)
            return b[pos];
        else
            return c[pos];
    }
    if(dp[{pos,alpha}])
        return dp[{pos,alpha}];

    if(alpha==0)
    {
        return (dp[{pos,alpha}]=max(a[pos]+solve(a,b,c,pos+1,2),a[pos]+solve(a,b,c,pos+1,1)));
    }
    else if(alpha==1)
    {
        return (dp[{pos,alpha}]=max(b[pos]+solve(a,b,c,pos+1,0),b[pos]+solve(a,b,c,pos+1,2)));
    }
    else
    {
        return (dp[{pos,alpha}]=max(c[pos]+solve(a,b,c,pos+1,1),c[pos]+solve(a,b,c,pos+1,0)));
    }

}
int main(){
    Going_supersonic
    lli T=1;
    //cin>>T;
    while(T--){
            lli i,j,k,p;
            cin>>n;
            iv a(n),b(n),c(n);
            mx=-1;
            for(i=0;i<n;i++)
            {
                cin>>a[i]>>b[i]>>c[i];
            }
            for(i=0;i<3;i++)
                mx=max(mx,solve(a,b,c,0,i));
            cout<<mx;


    }

    return 0;
}


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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}

ll INF=1e9+10;

int main(){
	startTime=clock();
	int n;
	cin >> n;
	int f[n][5][2];
	FOR(i,n)
		FOR(j,5)
			FOR(k,2)
				cin >> f[i][j][k];	
	int p[n][11];
	FOR(i,n)
		FOR(j,11)
			cin >> p[i][j];
	int match[n]={};
	ll profit=-INF;
	for(int i=1;i<1024;i++){
		int j=i;
		FOR(t,n) match[t]=0;
		FOR(t,10){
			if(j%2==1)
				FOR(i,n) if(f[i][t/2][t%2]) match[i]++;
			j/=2;
		}
		ll auxprofit=0;
		FOR(i,n) auxprofit+=p[i][match[i]];
		profit=max(profit,auxprofit);
	}	
	cout << profit;

	return 0;
		
}

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

typedef long long LL;

const LL INF = 1e18 + 7;

int n, zap, k;
vector<pair<int, int>> g[100007];
LL d[100007];
priority_queue<pair<LL, LL>> q;

void djk(int s)
{
    for(int i = 0; i <= n; i++) d[i] = INF;
    d[s] = (LL)0;
    q.push({0, s});
    while(!q.empty())
    {
        pair<LL, LL> v = q.top();
        q.pop();
        for(int i = 0; i < (int)g[v.second].size(); i++)
        {
            int u = g[v.second][i].first;
            int c = g[v.second][i].second;
            if(d[v.second] + c < d[u])
            {
                d[u] = d[v.second] + c;
                q.push({-d[u], u});
            }
        }
    }
}

void read()
{
    cin >> n;
    for(int i = 1; i < n; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }
    cin >> zap >> k;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    read();
    djk(k);
    for(int i = 0; i < zap; i++)
    {
        int a, b; cin >> a >> b;
        cout << d[a] + d[b] << "\n";
    }


    return 0;
}


Measured memory_bytes: 10096
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

struct Edge {
  int to;
  i64 cost;

  Edge(int _to, i64 _cost) : to(_to), cost(_cost) {}
};

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

  int n;
  cin >> n;
  vt<int> h(n);
  rep(i, 0, n) cin >> h[i];

  vt<int> dp(n);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  rep(i, 2, n) {
    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;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	string s;
	cin>>s;
	sort(all(s));
	if(s[0]==s[2])cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> > 
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 1e3 + 5;
int id[MAX][MAX];
char arr[MAX][MAX];
bool vis[MAX][MAX];

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
void flood(int x, int y, int n, int m, int cnt)
{
    if(x <= 0 || y <= 0 || x > n || y > m || arr[x][y] == '#' || vis[x][y]) return;
    vis[x][y] = 1;
    id[x][y] = cnt;
    
    for(int i = 0; i < 4; i++)
    flood(x + dx[i], y + dy[i], n, m, cnt);
}
int main()
{
	boost;
	int n, m, i, j, i1, j1;
	cin >> n >> m;
	
	int ch, cw;
	cin >> ch >> cw;
	
	int dh, dw;
	cin >> dh >> dw;
	
	foe(i, 1, n) {
	    foe(j, 1, m)
	    cin >> arr[i][j];
	}
	
	int cnt = 0;
	foe(i, 1, n) {
	    foe(j, 1, m) {
	        if(arr[i][j] == '#' || vis[i][j]) continue;
	        ++cnt;
	        flood(i, j, n, m, cnt);
	    }
	}
	
	vector <int> adj[cnt + 1];
	foe(i, 1, n) {
	    foe(j, 1, m) {
	        if(arr[i][j] == '#') continue;
	        
	        foe(i1, max(1, i - 2), min(n, i + 2)) {
	            foe(j1, max(1, j - 2), min(m, j + 2)) {
	                if(arr[i1][j1] == '#' || id[i1][j1] == id[i][j]) continue;
	                int x = id[i][j], y = id[i1][j1];
	                adj[x].pb(y);
	                adj[y].pb(x);
	            }
	        }
	    }
	}
	
	int st = id[ch][cw], en = id[dh][dw];
	bool vs[cnt + 1];
	int dist[cnt + 1];
	fill(dist, dist + cnt + 1, inf);
	memset(vs, 0, sizeof vs);
	
	queue <int> q;
	dist[st] = 0;
	q.push(st);
	vs[st] = 1;
	
	while(!q.empty()) {
	    int p = q.front();
	    q.pop();
	    
	    for(int v : adj[p]) {
	        if(!vs[v]) {
	            vs[v] = 1;
	            dist[v] = dist[p] + 1;
	            q.push(v);
	        }
	    }
	}
	cout << (dist[en] == inf ? -1 : dist[en]);
}

Measured memory_bytes: 33256
from statistics import median
N = int(input())
A = [int(i) for i in input().split()]

def k(A, b):
    return sum([abs(a - (b+i+1)) for i,a in enumerate(A)])

a = [a - (i+1) for i,a in enumerate(A)]
b = int(median(a))
print(k(A,b))

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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



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

const int N = 500005;
const int M = 1000000007;

int fact[N + 1];
int ifact[N + 1];

int add(int a, int b)
{
	if (a + b < 0) return a + b + M;
	if (a + b >= M) return a + b - M;
	return a + b;
}
int mul(int a, int b)
{
	return (a * b) % M;
}

int pwr(int a, int b)
{
	if (b == 0) return 1;
	int c = pwr(a, b / 2);
	if (b % 2 == 1) return mul(a, mul(c, c));
	return mul(c, c);
}

int inv(int a, int m)
{
	return pwr(a, m - 2);
}
void cal()
{
	fact[0] = 1;
	loop(i, 1, N + 1) fact[i] = mul(i, fact[i - 1]);

	ifact[N] = inv(fact[N], M);

	rloop(i, N - 1, 0) ifact[i] = mul(ifact[i + 1], i + 1);

}

int ncr(int n, int r)
{

	if (r > n) return 0;
	else
	{
		return mul(fact[n], mul(ifact[r], ifact[n - r]));
	}
}


void solve()
{
	cal();
	int n, m;
	cin >> n >> m;
	int ans = 1;

	loop(i, 0, n) ans = mul(ans, m - i);
	ans = mul(ans, ans);
	vi a(n + 1, 1);

	a[n - 1] = m - (n - 1);
	rloop(i, n - 2, 0) a[i] = mul(a[i + 1], m - i);

	loop(i, 1, n + 1)
	{
		int x = mul(ncr(n, i), mul(ncr(m, i), fact[i]));

		int y = mul(a[i], a[i]);

		x = mul(x, y);

		if (i % 2 == 0) ans = add(ans, x);
		else ans = add(ans, -x);

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

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt",  "r",  stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

Measured memory_bytes: 14648