akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
vector<ll>fat;

void fill_fat(int n){
	fat=vector<ll>(n+1,1);
	for(ll i=1;i<=n;i++){
		fat[i]=(fat[i-1]*i)%mod;
	}
}

ll binExp(ll b, ll e){
	ll ret=1;
	while(e){
		if(e&1){
			ret=ret*b%mod;
		}
		b=b*b%mod;
		e/=2;
	}
	return ret;
}

ll comb(ll n, ll k){
	ll ret = fat[n]*binExp(fat[k],mod-2)%mod;
	ret=ret*binExp(fat[n-k],mod-2)%mod;

	return ret;
}
	
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,m;
	cin>>n>>m;

	fill_fat(max(n,m)+1);

	ll ans=0;
	for(ll k=0,op=1;k<=n;k++,op*=-1){
		ll tmp =comb(n,k)*comb(m-k,n-k)%mod;
		ans= (ans+ op*tmp*fat[n-k])%mod;
	}
	ans=ans*comb(m,n)%mod;
	ans=ans*fat[n]%mod;
	ans=(ans+mod)%mod;
	cout<<ans<<'\n';
	
	return 0;
}

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

struct Dset {
  Dset *parent;
  int rank;

  Dset() {
    clear();
  }

  void clear() {
    parent = NULL;
    rank = 0;
  }

  Dset *find() {
    if (!parent) {
      return this;
    } else {
      parent = parent->find();
      return parent;
    }
  }

  bool merge(Dset *a) {
    Dset *myRoot = find();
    Dset *yourRoot = a->find();
    if (myRoot->rank < yourRoot->rank) {
      myRoot->parent = yourRoot;
    } else if (myRoot->rank > yourRoot->rank) {
      yourRoot->parent = myRoot;
    } else if (myRoot != yourRoot) {
      yourRoot->parent = myRoot;
      myRoot->rank++;
    } else {
      return false;
    }
    return true;
  }
};

struct Bridge {
  int a;
  int b;
  int cost;
  
  bool operator<(const Bridge &obj) const {
    return (cost < obj.cost);
  }
};

int main() {
  int n, m, ans;
  Bridge bridge[6000];
  Dset x[100];
  while (1) {
    cin >> n >> m;
    if (!n && !m) break;
    for (int i=0; i<m; i++) {
      cin >> bridge[i].a >> bridge[i].b >> bridge[i].cost;
    }
    sort(bridge, bridge+m);
    for (int i=0; i<n; i++) {
      x[i].clear();
    }
    ans = 0;
    for (int i=0; i<m; i++) {
      if (x[bridge[i].a].merge(&x[bridge[i].b])) {
        ans += bridge[i].cost;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

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

using namespace std;

long long inf=1000000007;

long long modpow(long long n,long long p,long long mod);

int main(){
	long long x;
	cin>>x;
	long long kizyun=1800;
	for(long long i=1;i<=8;i++){
		if(x>=kizyun){
			cout<<i<<endl;
			return 0;
		}else{
			kizyun-=200;
		}
	}

	return 0;
}

long long modpow(long long n,long long p,long long mod){
	if(p==0) return 1;
	if(p%2==0) return (modpow(n,p/2,mod)*modpow(n,p/2,mod))%mod;
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}


Measured memory_bytes: 3636
import math
from functools import reduce
 
n = int(input())
answer = 0
 
def gcd(*numbers):
    return reduce(math.gcd,numbers)
 
for i in range(n):
    for j in range(n):
        for k in range(n):
            answer += gcd(i+1,j+1,k+1)
print(answer)

Measured memory_bytes: 69764
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pllint a, pllint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, (llint)b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	int x;
	cin >> x;
	for (int i = x;; i++) {
		bool tmp = true;
		for (int j = 2; j * j <= x; j++) {
			if (i % j == 0) {
				tmp = false;
				break;
			}
		}
		if (tmp) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a == 1) {
		a = 14;
	}
	if (b == 1) {
		b = 14;
	}
	if (a > b) {
		cout << "Alice" << endl;
	}
	else {
		if (a < b) {
			cout << "Bob" << endl;
		}
		else {
			cout << "Draw" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long a[410],dp[410][410],sum[410],x = 0,mx = 1000000000000000;
long long solve(int l, int r){
	if(dp[l][r]!=mx) return dp[l][r];
	if(r-l==1){
		dp[l][r] = 0;
		return 0;
	}
	for(int i=l+1;i<r;i++){
		if(l!=0) dp[l][r] = min(dp[l][r],solve(l,i) + solve(i,r) + sum[r-1] - sum[l-1]);
		else dp[l][r] = min(dp[l][r],solve(l,i) + solve(i,r) + sum[r-1]);
	}
	return dp[l][r];
}

int main(){
	int i,j,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		x += a[i];
		sum[i] = x;
	}
	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			dp[i][j] = mx;
		}
	}
	cout << solve(0,n) << endl;
}

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

int main(){
  int n,k,q; cin >> n >> k >> q;
  vector<int> a(q);
  rep(i,q) cin >> a[i];
  vector<int> b(n);
  rep(i,n) b[i]=k-q;
  for(int j=0;j<q;j++){
    b[a[j]-1]++;
  }
  for(int i=0;i<n;i++){
    if(b[i]<=0){
      cout << "No" << endl;
    }
    else{
      cout << "Yes" << endl;
    }
  }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,k,a[300010],flag = 1;
	cin >> k >> n;
	if(k % 2 == 0){
		for(int i = 0;i < n;i++) printf("%s%lld",(i ? " " : ""),(i ? k : k / 2));
		cout << endl;
		return 0;
	}else if(k == 1){
		for(int i = 0;i < (n + 1) / 2;i++) printf("%s%lld",(i ? " " : ""),1);
		cout << endl;
		return 0;
	}
	for(int i = 0;i < n;i++) flag = (flag * k + 1) % 2;
	for(int i = 0;i < n;i++) a[i] = k / 2 + 1;
	flag = (flag + 1) % 2;
	for(int i = 0;i < n / 2;i++){
		int pos = n - 1;
		while(!a[pos]) pos--;
		a[pos]--;
		if(a[pos]){
			pos++;
			while(pos < n) a[pos++] = k;
		}
	}
	for(int i = 0;i < n && a[i];i++) printf("%s%lld",(i ? " " : ""),a[i]);
	cout << endl;
	return 0;
}

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

int main() {
  
  int n; cin >> n;
  
  deque<int> memo;
  
  for (int i = 0; i < n; i++) {
    
    int a; cin >> a;
    
    if (i % 2 == 0) memo.push_back(a);
    
    if (i % 2 == 1) memo.push_front(a);
    
  }
  
  if (n % 2 == 0) {
    
    for (int i = 0; i < n; i++) {
      
      cout << memo.at(i);
      
      if (i != n - 1) cout << " ";
      
    }
    
  }
  
  if (n % 2 == 1) {
    
    for (int i = n - 1; 0 <= i; i--) {
      
      cout << memo.at(i);
      
      if (i != 0) cout << " ";
      
    }
    
  }
  
  cout << endl;
  
}

Measured memory_bytes: 4456
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

int cal(int x) {
  int ret = 0;
  if (x % 2 == 0) ret++;
  if (x % 4 == 0) ret++;
  return ret;
}

void MAIN() {
  int n; cin >> n;
  deque<int> a(n);
  for (auto &i : a) cin >> i;
  sort(all(a), [](int &a, int &b) -> bool {
    return cal(a) > cal(b);
  });
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    if (i % 2) b[i] = a.front(), a.pop_front();
    else b[i] = a.back(), a.pop_back();
  }
  int ans = 1;
  for (int i = 0; i < n - 1; i++) {
    if ((b[i] * b[i + 1]) % 4) ans = 0;
  }
  if (ans) cout << "Yes" << '\n';
  else cout << "No" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 4760
from collections import defaultdict
n,m = map(int,input().split())
a = list(map(int,input().split()))
"""
aの連続列がMの倍数であればいい
dp[j] := jの倍数になる総数.
"""
dp = defaultdict(lambda: 0)
dp[0] = 1
tmp = 0
ans = 0
for i in range(n):
	tmp += a[i]
	ans += dp[tmp%m]
	dp[tmp%m] += 1
print(ans)

Measured memory_bytes: 20992
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main() {
	int n, j, temp;
	pair<int, int>ans(0, 1);
	cin >> n;
	for (int i = 2; i <= n; i++)
	{
		for (j = 0, temp = i; temp % 2 == 0; j++)
		{
			temp /= 2;
		}
		if (ans.first <= j) {
			ans.first = j;
			ans.second = i;
		}
	}
	cout << ans.second << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final Scanner sc    = new Scanner(System.in);
    static final int     MOD   = (int) 1E9 + 7;
    static final long    INF_L = (long) 4E18;

    public static void main(String[] args) {
        int N = nint();
        long[] A = nlongs(N);
        long[] sum = new long[N];
        
        sum[0] = A[0];
        for (int i = 1; i < N; i++) {
            sum[i] = sum[i-1] + A[i];
        }
        long len = sum[N-1];
        
        long minDiffAbs = INF_L;
        for (int i = 0; i <= N - 2; i++) {
            long right = len - sum[i];
            long left = sum[i];
            minDiffAbs = min(minDiffAbs, abs(right - left));
        }
        System.out.println(minDiffAbs);
    }

    @Deprecated
    static int nint() {
        return sc.nextInt();
    }

    @Deprecated
    static int[] nints(int N) {
        return nints(0, N, 0);
    }

    @Deprecated
    private static int[] nints(int padL, int N, int padR) {
        int[] a = new int[padL + N + padR];
        for (int i = 0; i < N; i++)
            a[padL + i] = nint();
        return a;
    }

    static long nlong() {
        return sc.nextLong();
    }

    static long[] nlongs(int N) {
        return nlongs(0, N, 0);
    }

    static long[] nlongs(int padL, int N, int padR) {
        long[] a = new long[padL + N + padR];
        for (int i = 0; i < N; i++)
            a[padL + i] = nlong();
        return a;
    }

    static double ndouble() {
        return sc.nextDouble();
    }

    static double[] ndoubles(int N) {
        return ndoubles(0, N, 0);
    }

    static double[] ndoubles(int padL, int N, int padR) {
        double[] d = new double[N + padL + padR];
        for (int i = 0; i < N; i++) {
            d[padL + i] = ndouble();
        }
        return d;
    }

    static String nstr() {
        return sc.next();
    }

    static char[] nchars() {
        return sc.next().toCharArray();
    }

    static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }

    static char[][] nchars2(int H, int W) {
        return nchars2(H, W, 0, 0);
    }

    static char[][] nchars2(int H, int W, int padLU, int padRD) {
        char[][] a2 = new char[H + padLU + padRD][W + padLU + padRD];
        for (int i = 0; i < H; i++)
            System.arraycopy(nchars(), 0, a2[padLU + i], padLU, W);
        return a2;
    }

    static long min(long... ls) {
        return Arrays.stream(ls).min().getAsLong();
    }

    static long max(long... ls) {
        return Arrays.stream(ls).max().getAsLong();
    }

    static long abs(long a) {
        return Math.abs(a);
    }
}


Measured memory_bytes: 96152
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
         
        int n = stdIn.nextInt();
        int m = stdIn.nextInt();
        int l = stdIn.nextInt();
         
        long[][] A = new long[n][m];
        long[][] B = new long[m][l];
        long[][] C = new long[n][l];
         
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                A[i][j] = stdIn.nextInt();
            }
        }
         
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < l; j++) {
                B[i][j] = stdIn.nextInt();
            }
        }
         
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < l; j++) {
                for(int k = 0; k < m; k++) {
                    C[i][j] += A[i][k] * B[k][j];
                }
            }
        }
         
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < l-1; j++) {
                System.out.print(C[i][j] + " ");
            }
            System.out.println(C[i][l-1]);
        }
    }
}


Measured memory_bytes: 52608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e5+7;
const int N=1e4+5;

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    ll n=abs(x)/d;
    if(k<n) cout<<abs(abs(x)-k*d)<<endl;
    else if((k-n)%2==0)
        cout<<abs(abs(x)-n*d)<<endl;
    else
        cout<<abs(abs(x)-(n+1)*d)<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    long long ans = 2147483647;
    long long sl = s.length(), tl = t.length();
    for (long long i = 0; i < sl; i++) {
        long long different = 0;
        for (long long j = 0; j < tl; j++) {
            int k = i + j;
            if (k >= sl) {
                printf("%lld\n", ans);
                return 0;
            }
            if (s[k] != t[j])
                different++;
        }
    	ans = min(ans, different);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <string>
#include <bitset>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}
vector<int> era(int n) {vector<bool> is_prime(n+1, true);vector<int> res;for (int i = 2; i <= n; ++i) {if (!is_prime[2]) continue;for (int j = 2; i * j <= n; ++j) is_prime[i*j] = false;}for (int i = 2; i <= n; ++i) {if (is_prime[i]) res.push_back(i);}return res;}
map<int, int> divisor_map(int n) {vector<int> primes = era(n);map<int, int> res;for (auto i: primes) {while (n % i == 0) {n /= i;++res[i];}}return res;}

int main() {
    int N; cin >> N;
    map<int, int> divisor_count;
    for (int i = N; i > 0; --i) {
        for (auto x: divisor_map(i)) divisor_count[x.first] += x.second;
    }

    int count1 = 0;
    int count3 = 0;
    int count5 = 0;
    int count15 = 0;
    int count25 = 0;
    int count75 = 0;
    for (auto x: divisor_count) {
        ++count1;
        if (x.second >= 2) ++count3;
        if (x.second >= 4) ++count5;
        if (x.second >= 14) ++count15;
        if (x.second >= 24) ++count25;
        if (x.second >= 74) ++count75;
    }
    int res = 0;
    res += (count3-2) * (((count5) * (count5-1)) / 2);
    res += (count5-1) * count15;
    res += (count3-1) * count25;
    res += count75;
    cout << res << endl;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  int n; cin >> n;
  cout << n / 2 + (n % 2);
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); 
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}	
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}		    
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}	    	  	
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}		
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}	
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}	    	
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}	    	
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}				
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        
        int T = 1;//in.nextInt();
        for(int t = 1; t <= T; t++)
        {
            int n = in.nextInt();
            String str = in.nextLine();
            if(n%2==1) {out.write("No\n");continue;} 
            int m = n/2;
            int f=0;
            for(int i=0;i<m;i++)
            {
                if(str.charAt(i)!=str.charAt(i+m)) {f=1;break;}
            }
            if(f==0) out.write("Yes\n");
            else out.write("No\n");
        }
    }
    
    /************* SOLUTION ENDS HERE **********/
}

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

typedef complex<double> Point;
typedef Point Vector;
typedef pair<Point, Point> Segment;
typedef Segment Line;
typedef pair<Point, double> Circle;
typedef vector<Point> Polygon;
double dot(Vector a, Vector b){
	return real(a) * real(b) + imag(a) * imag(b);
}
double cross(Vector a, Vector b){
	return real(a) * imag(b) - imag(a) * real(b);
}
Point project(Line l, Point p){
	Vector base = l.second - l.first;
	base /= abs(base);
	double r = dot(p - l.first, base);
	return l.first + r * base;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Point p1, p2;
	double x, y;
	cin >> x >> y;
	p1 = Point(x, y);
	cin >> x >> y;
	p2 = Point(x, y);
	Line l(p1, p2);
	int q;
	cin >> q;
	while(q--){
		cin >> x >> y;
		Point z = project(l, Point(x, y));
		cout << setprecision(15) << real(z) << " " << imag(z) << "\n";
	}
}


Measured memory_bytes: 3380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1e9+7
#define ALL(v) v.begin(), v.end()

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

    char march[] = {'M', 'A', 'R', 'C', 'H'};
    ll count[5]  = {0};

    ll sum = 0;
    REP(i, N) {
        string s;
        cin >> s;

        REP(j, 5) {
            if (s[0] != march[j]) continue;
            count[j]++;
            sum++;
        }
    }

    ll ans  = 0;
    REP(bit, 1<<5) {
        int bitcount = 0;
        ll cur = 1;
        REP(i, 5) {
            if (bit>>i&1) {
                cur *= count[i];
                bitcount++;
            }
        }
        if (bitcount  == 3) {
            ans += cur;
        }
    }

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

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
  //ok
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;
  //ok
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
    return u;
  }
  if(k<u->key){
    return treeSearch(u->left,k);
      }
  else{
    return treeSearch(u->right,k);
      }
  //ok
}

Node treeSuccessor(Node x){
  Node y;
  
  if(x->right!=NIL){
    return treeMinimum(x->right);
      }
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
//treeSearch(root,x)を使っている
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;

  if(y==NIL){
    root=z;
  }else if(z->key < y->key){
    y->left=z;
  }else{
    y->right=z;
  }
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
      printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u==NIL){
    return;
  }
    printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20552
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const int N = 505;
const double eps = 1e-9;
ll a[N][N], dp[N][N], mx[N][N];
ll pos[N][N], neg[N][N];

inline ll sum(int i1, int j1, int i2, int j2) {
  return a[i2][j2] - a[i1-1][j2] - a[i2][j1-1] + a[i1-1][j1-1];
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; cin >> n;
  if (n <= 2) {
    cout << "0\n";
    return 0;
  }
  ll tot = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (j != i)
        cin >> a[i][j];
      tot += a[i][j];
      a[i][j] = a[i-1][j] + a[i][j-1] - a[i-1][j-1] + a[i][j];
      dp[i][j] = mx[i][j] = -inf;
    }
  for (int i = 1; i <= n; i++) {
    for (int j = i+1; j <= n; j++) {
      pos[i][j] = pos[i][j-1] + sum(j, i, j, j);
      neg[i][j] = neg[i][j-1] + sum(i, j, j, j);
    }
  }
  ll ans = inf;
  for (int r = 2; r <= n; r++) {
    dp[2][r] = pos[1][r] + neg[1][n] - neg[1][r] - neg[r+1][n];
    ans = min(ans, tot - pos[1][n] - neg[1][n] + neg[1][r] + neg[r+1][n]);
  }
  for (int r = 2; r <= n; r++) {
    for (int i = r+1; i <= n; i++) {
      ll& val = dp[r+1][i];
      for (int l = r; l > 2; l--) {
        mx[r][i] = max(mx[r][i], pos[l][i] - pos[l][r]);
        val = max(val, dp[l][r] + neg[r+1][n] - neg[r+1][i] - neg[i+1][n] + mx[r][i]);
      }
      ll tmp = dp[2][r] + neg[r+1][n] - neg[r+1][i] - neg[i+1][n] + neg[1][r];
      for (int j = 2; j <= r; j++)
        val = max(val, tmp + pos[j][i] - pos[j][r] - neg[1][j-1] - neg[j][r]);
    }
    ans = min(ans, tot - dp[r+1][n]);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 13496
def main():
    _ = int(input())
    H = [int(i) for i in input().split()]
    cur_h = 0
    ans = 0
    for h in H:
        if cur_h < h:
            ans += h - cur_h
        cur_h = h
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
from collections import Counter
N,K = map(int,input().split())
src = list(map(int,input().split()))
ctr = Counter(src)

ans = 0
kind = len(ctr)
for k,v in reversed(ctr.most_common()):
    if kind <= K:
        break
    ans += v
    kind -= 1
print(ans)


Measured memory_bytes: 39344
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
const int mxN=1e9;
const ll mod = 1e9+7;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,k;
    cin>>n>>k;

    vector<int> v(n);

    for(int i=0;i<n;i++) cin>>v[i];

    bool dp[k+1][2];

    for(int i=0;i<=k;i++){
        dp[i][0]=0;
        dp[i][1]=1;
    }
    
    for(int i=0;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i<v[j]) continue;
            if(dp[i-v[j]][1]){
                dp[i][0]=1;
                dp[i][1]=0;
            }
        }
    }

    if(dp[k][0]) cout<<"First";
    else cout<<"Second";
}

Measured memory_bytes: 3852
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;


	
	public static void Main(string[] args)
	{
		var u = Input().ToInt();
		var n = u[0];
		var m = u[1];
		var p = Input().ToInt();
		
		var tree = new UnionFind(n);
		for(int i = 0; i < m; i++)
		{
			u = Input().ToInt();
			var x = u[0];
			var y = u[1];
			
			tree.Unite(x-1, y-1);
		} 
		var wa = 0;
		for(int i = 0; i < n; i++)
		{
			if(tree.InSameTree(i, p[i]-1))
				wa++;
		}
		Console.WriteLine(wa);
	}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}

public class UnionFind
{
	private int[] par;
	public UnionFind(int n)
	{
		par = new int[n];
		for(int i = 0; i < n; i++)
			par[i] = i;
	}
	
	public int Root(int x)
	{
		if(par[x] == x) return x;
		return par[x] = Root(par[x]);
	}
	public void Unite(int x, int y)
	{
		int rx = Root(x);
		int ry = Root(y);
		if(rx == ry) return;
		par[rx] = ry;
	}
	public bool InSameTree(int x, int y)
	{
		return Root(x) == Root(y);
	}
}

Measured memory_bytes: 26564
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e15;
const int MOD = 1e9 + 7;

#define MAX_V 100000

struct edge { int to; ll cost; };

int V;//頂点数

//始点sから各頂点への最短距離を求める
void dijkstra(int s, vector<edge> G[], ll d[]){
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));
	
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
	int m,s,t;
	cin >> V >> m >> s >> t;
	s--;
	t--;
	int u,v;
	ll a,b;
	vector<edge> G1[MAX_V], G2[MAX_V];//辺の張り方 : G[from].push_back((edge){to, cost});
	REP(i,m){
		cin >> u >> v >> a >> b;
		u--;
		v--;
		G1[u].push_back((edge){v, a});
		G1[v].push_back((edge){u, a});
		G2[u].push_back((edge){v, b});
		G2[v].push_back((edge){u, b});
	}
	ll d1[MAX_V], d2[MAX_V];
	dijkstra(s,G1,d1);
	dijkstra(t,G2,d2);
	ll mx = 0;
	ll ans[V];
	for(int i = V - 1; i >= 0; i--){
		mx = max(mx, 1000000000000000 - (d1[i] + d2[i]));
		ans[i] = mx;
	}
	REP(i,V){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 19600
#include <bits/stdc++.h>
#include <string>
using namespace std;
int N;
vector<int> h;
int dp[100010];

int takasa(int i){
    int ans;
    if(dp[i]>=0) return dp[i];
    else if(i==N-1) dp[i]=0;
    else if(h[i]>=h[i+1]) dp[i] = takasa(i+1)+1;
    else dp[i]=0;
    return dp[i];
}
int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        h.push_back(a);
    }
    memset(dp,-1,sizeof(dp));
    int max = 0;
    int now;
    for(int i=0;i<N;i++){
        now=takasa(i);
        if(now > max) {
            // cout << "when" << i <<endl;
            max = now;
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 2680
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;

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

    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);i++)
using namespace std;
     
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> P(m), Y(m);
  rep(i, m) {
    cin >> P[i] >> Y[i];
    P[i]--;
  }

  vector<vector<int>> vals(n);
  rep(i, m) vals[P[i]].push_back(Y[i]);
  rep(i, n) sort(vals[i].begin(), vals[i].end());
  rep(i, m) {
    int v = P[i];
    printf("%06d", v + 1);
    int id = lower_bound(vals[v].begin(), vals[v].end(), Y[i]) - vals[v].begin();
    printf("%06d\n", id + 1);
  }
}


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

constexpr int prep = 10;
int64_t dp[(1<<prep)+2][100001];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    static int64_t v[(1<<18)+2], w[(1<<18)+2];
    static int depth[(1<<18)+2];
    depth[0] = 0;
    for(int i=1;i<=n;++i) depth[i] = depth[i/2] + 1;

    for(int i=1;i<=n;++i){ cin >> v[i] >> w[i]; }

    for(int i=1;i<=min(n,(1<<prep)-1);++i){
        for(int j=0;j<=100000;++j) dp[i][j] = dp[i/2][j];
        for(int j=0;j<=100000;++j){
            if(j + w[i] <= 100000) dp[i][j + w[i]] = max(dp[i][j+w[i]], dp[i/2][j] + v[i]);
        }
        for(int j=1;j<=100000;++j) if(dp[i][j-1] > dp[i][j]) dp[i][j] = dp[i][j-1];
    }

    int q;
    cin >> q;
    while(q--){
        int vv, ll;
        cin >> vv >> ll;
        if(vv < (1<<prep)){ cout << dp[vv][ll] << endl; continue; }
        int64_t cand = 0;
        for(int ptn=0;ptn<(1<<depth[vv]-prep);++ptn){
            int ii = vv, p = ptn;
            int64_t we = 0, vl = 0;
            while(depth[ii] > prep){
                if(p & 1){ we += w[ii]; vl += v[ii]; }
                ii /= 2; p /= 2;
                if(we > ll) goto l_ng;
            }
            cand = max(cand, dp[ii][ll-we] + vl);
            l_ng:;
        }
        cout << cand << endl;
    }
    return 0;
}

Measured memory_bytes: 808012
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d;
    if(c > b){
      d = b;
      b = c;
      c = d;
    }
    if(b > a){
      d = a;
      a = b;
      b = d;
    }
    if(c > b){
      d = b;
      b = c;
      c = d;
    }
    System.out.println(c + " " + b + " " + a);
  }
}



Measured memory_bytes: 26296
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
	int N,T,tmp=0,ans=0;
	cin>>N>>T;
	vector<int> A(N),max(N);
	for(int i=0;i<N;i++) cin>>A[i];

	reverse(A.begin(),A.end());
	for(int i=0;i<N;i++){
		if(A[i]>tmp) tmp=A[i];
		max[i]=tmp;
	}
	reverse(A.begin(),A.end());
	reverse(max.begin(),max.end());

	tmp=-1;
	for(int i=0;i<N-1;i++){
		if(max[i+1]-A[i]==tmp) ans++; 
		if(max[i+1]-A[i]>tmp){
			tmp=max[i+1]-A[i];
			ans=1;
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int i, n, a;
    long min, max, sum = 0;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &a);
        sum += a;
        if(i ==0){    //?????§???????°????????????????
            min = a;
            max = a;
        }
        else{
            if(max < a){
                max = a;
            }
            if(a < min){
                min = a;
            }
        }
    }
    printf("%ld %ld %ld\n", min, max, sum);
    
    
    return 0;
}

Measured memory_bytes: 600
def f():
    n=int(input())
    l=[0,0,0]
    ans=1
    mod=10**9+7
    for i in list(map(int,input().split())):
        if i not in l:print(0);exit()
        ans=ans*l.count(i)%mod
        l[l.index(i)]+=1
    print(ans)
if __name__ == "__main__":f()

Measured memory_bytes: 13964
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

// }}}

const int N=1e5+10;
int n;
LL a[N];
void main() {
    R(n);
    REP1(i,1,n) R(a[i]);
    if ( a[n]!=2 ) {
        W(-1);
        return;
    }
    LL l=1,r=1;
    for ( int i=n-1; i>=1; i-- ) {
        // [ l*a[i+1], (r+1)*a[i+1] )
        LL lv=l*a[i+1];
        LL rv=(r+1)*a[i+1]-1;
        l=(lv+a[i]-1)/a[i];
        r=rv/a[i];
        if ( l>r ) {
            W(-1);
            return;
        }
    }
    W(l*a[1],(r+1)*a[1]-1);
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}


Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb(a) push_back(a)
using namespace std;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=1e3+5,M=2e5+5;

int n,m,u[M],v[M],p[N],mn[N],mx[N],id;
vector<int> to[N];
bool vis[N],can[N][N],path[N][N];

void dfs(int x) {
	vis[x]=1;
	for(int y:to[x]) if (!vis[y]) dfs(y);
}

void dfs_mn(int x) {
	if (mn[x]) return;
	mn[x]=id;for(int y:to[x]) dfs_mn(y);
}

void dfs_mx(int x) {
	if (mx[x]) return;
	mx[x]=id;for(int y:to[x]) dfs_mx(y);
}

int main() {
	n=read();m=read();
	fo(i,1,m) {
		u[i]=read();v[i]=read();
		to[u[i]].pb(v[i]);
	}
	fo(i,1,n) {
		fo(j,1,n) vis[j]=0;
		dfs(i);
		fo(j,1,n) can[i][j]=vis[j];
	}
	fo(i,1,n) {
		fo(j,1,n) mn[j]=mx[j]=0;mn[i]=mx[i]=1;
		int t=0;for(int x:to[i]) p[++t]=x;
		fo(j,1,t) id=j,dfs_mn(p[j]);
		fd(j,t,1) id=j,dfs_mx(p[j]);
		fo(j,1,t) path[i][p[j]]=mn[p[j]]<mx[p[j]];
	}
	fo(i,1,m) puts(can[v[i]][u[i]]^path[u[i]][v[i]]?"diff":"same");
	return 0;
}

Measured memory_bytes: 6400
def main():
    S = input()
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    #print(alphabet)
    #com = S + alphabet
    #print(sorted(set(com), key=com.index))
    dic = str.maketrans("", "", S)
    ans = alphabet.translate(dic)
    if(len(ans) > 0):
        print(ans[0])
    else:
        print("None")
    
    
if __name__=="__main__":
    main()

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
static const int MAX = 100;


void fill(int field[][MAX], int x1, int x2, int y1, int y2) {
    for (int x = x1; x < x2; x++) {
        for (int y = y1; y < y2; y++) {
            field[y][x] = 1;
        }
    }
}

int main() {
    int w, h, n, field[MAX][MAX];

    cin >> w >> h >> n;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) field[i][j] = 0;
    }
    for (int i = 0; i < n; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) fill(field, 0, x, 0, h);
        else if (a == 2) fill(field, x, w, 0, h);
        else if (a == 3) fill(field, 0, w, 0, y);
        else fill(field, 0, w, y, h);
    }
    
    int s = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) if (field[i][j] == 0) s++;
    }
    
    cout << s << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
	
	ll inf=1e9+5;
	ll n,k; cin>>n>>k;
	ll a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	vector<ll> dp(n,inf);
	dp[0]=0;
	for(int i=0;i<n;++i){
		for(int j=i+1;j<i+k+1;++j){
		if(j<n) dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
		}
	}
	cout<<dp[n-1];
	//for(int i=0;i<n;i++) { cout<<dp[i]<<" "; }
cout<<"\n";
return 0;
}

Measured memory_bytes: 1792
/*input
12
100 104 102 105 103 103 101 105 104 102 104 101
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

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

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 1e6+1;
int pref[N];

void solve(){
  	int totsum = 0;
  	int n;cin >> n;
  	RE(i,n){
  		cin >> pref[i];
  		pref[i] += pref[i-1];
  	}
  	totsum = pref[n];
  	int ans = INF;
  	RE(i,n-1){
  		int one = pref[i];
  		int two = totsum-pref[i];
  		ans = min(ans,abs(one-two));
  	}
  	cout << ans;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<vector<int> > C(3, vector<int>(3));
    int k;
    bool flag=true;
    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            cin >> C[i][j];
            if(i>0) {
                if(j==0) {
                    k = C[i][j]-C[i-1][j];
                } else {
                    if(k != C[i][j]-C[i-1][j]) {
                        flag=false;
                    }
                }
            }
        }
    }
    
    if(flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    
    cin >> n;
    
    int sum = 0;
    int max = 0;
    int wk = 0;
    for(int i = 0; i < n; i ++){
        cin >> wk;
        sum += wk;
        if(wk > max)max = wk;
    }
    
    sum -= (max / 2);
    
    cout << sum << endl;
    
    
}


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


int main(void)
{
	int i;
	char ch,str[101] = {0};
	int dice[6],temp,n;

	for(i = 0; i < 6; i++)
	{
		scanf("%d", &dice[i]);
	}

	scanf("%s", str);
	n = strlen(str);


	for(i = 0; i < n; i++)
	{
		ch = str[i];

		if (ch == '\n')
		{
			break;
		}

		if (ch == 'N')
		{
			temp = dice[4];
			dice[4] = dice[0];
			dice[0] = dice[1];
			dice[1] = dice[5];
			dice[5] = temp;
		}
		if (ch == 'S')
		{
			temp = dice[1];
			dice[1] = dice[0];
			dice[0] = dice[4];
			dice[4] = dice[5];
			dice[5] = temp;
		}
		if (ch == 'W')
		{
			temp = dice[3];
			dice[3] = dice[0];
			dice[0] = dice[2];
			dice[2] = dice[5];
			dice[5] = temp;
		}
		if (ch == 'E')
		{
			temp = dice[2];
			dice[2] = dice[0];
			dice[0] = dice[3];
			dice[3] = dice[5];
			dice[5] = temp;
		}


	}

	printf("%d\n", dice[0]);

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll Abs(ll x,ll y){
    if(x>=y)return x-y;
    else return y-x;
}
 
 
int main(void){
    string s,t;
    cin>>s>>t;
    ll ssize = s.length();
    ll tsize = t.length();
    vector<ll>pos[26];
    for(ll i=0;i<ssize;i++){
        pos[s[i]-'a'].push_back(i+1);
    }
    for(ll i=0;i<tsize;i++){
        ll x = t[i]-'a';
        auto itr = lower_bound(pos[x].begin(),pos[x].end(),0);
        if(itr==pos[x].end()){
            cout<<-1<<endl;
            return 0;
        }
    }
    ll ans = 0;
    ll now = 0;
    ll cnt = 0;
    for(ll i=0;i<tsize;i++){
        ll x = t[i]-'a';
        auto itr = upper_bound(pos[x].begin(),pos[x].end(),now);
        if(itr!=pos[x].end()){
            ans = ssize*cnt+(*itr);
            now = (*itr);
        }
        else{
            cnt++;
            ans = ssize*cnt+pos[x][0];
            now = pos[x][0];
        }
        //cout<<now<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

ll XOR(ll a){
    if(a % 4 == 1)return 1;
    else if(a % 4 == 3)return 0;
    else if(a == 0)return 0;
    else return (XOR(a-1)^a);
}
signed main()
{   
    gearup;
    string s; cin >> s;
    int n = s.size();
    int a=0,b=0;
    rep(i,n){
        if(s[i] == '0')a++;
        else b++;
    }
    cout << min(a,b)*2 << endl;
}


Measured memory_bytes: 512