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


using namespace std;
typedef pair<int,int> P;
int n;
P x[100001];
P y[100001];
int p[100001];
int r[100001];

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

int Find(int x) {
  return p[x] == x ? x : (p[x] = Find(p[x]));
}

void Union(int x, int y) {
  int a = Find(x);
  int b = Find(y);
  if(a == b) return;
  if(r[x] > r[y])  p[y] = x;
  else {
    p[x] = y;
    if(r[x] == r[y]) r[x]++;
  }
}
    
				 
			  
struct edge{
  int cost,from,to;

  edge(int c, int f, int t) : cost(c),from(f),to(t) {}
    
};

bool operator < (const edge& x, const edge& y) {
    return x.cost < y.cost;
  }

vector<edge> e;
int main() {
  cin >> n;
  init(n);
  for(int i = 0; i < n; i++) {
    int xx, yy;
    cin >> xx >> yy;
    x[i] = P(xx,i);
    y[i] = P(yy,i);
  }
  sort(x,x+n);
  sort(y,y+n);
  for(int i = 1; i < n; i++) {
    e.push_back(edge(abs(x[i].first - x[i-1].first),x[i-1].second,x[i].second));
    e.push_back(edge(abs(x[i].first - x[i-1].first),x[i].second,x[i-1].second));    e.push_back(edge(abs(y[i].first - y[i-1].first),y[i-1].second,y[i].second));
    e.push_back(edge(abs(y[i].first - y[i-1].first),y[i].second,y[i-1].second));
  }

  sort(e.begin(),e.end());
      

  /*for(int i = 0; i < e.size();i++) {
    cout << e[i].cost <<"   "<<e[i].from<<"   "<<e[i].to<<endl;
    }*/
  long long int ans = 0;

  for(int i = 0; i < e.size(); i++) {
    if(Find(e[i].from) != Find(e[i].to)) {
      //cout << Find(e[i].from) <<"   "<<Find(e[i].to)<<endl;
      // cout << e[i].cost <<"   "<<e[i].from<<"   "<<e[i].to<< endl;
      ans += e[i].cost;
      //cout << ans << endl;
      Union(Find(e[i].from),Find(e[i].to));
    }
  }

  cout << ans << endl;
  
}

  
    
  


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

bool flag[5];
int x[1010],y[1010],d[50];

int main(){
	int n;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d",&x[i],&y[i]);
		flag[abs(x[i] + y[i]) % 2] = true;
	}
	if (flag[0] && flag[1]) { puts("-1"); return 0; }
	int m = 0;
	if (flag[0]) d[++m] = 1;
	for (int i = 30; i >= 0; i--) d[++m] = (1 << i);
	printf("%d\n" , m);
	for (int i = 1; i <= m; i++) printf("%d%s" , d[i] , i == m ? "\n" : " ");
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++)
			if (abs(x[i]) > abs(y[i])) {
				if (x[i] > 0) { x[i] -= d[j]; printf("R"); }
				else { x[i] += d[j]; printf("L"); }
			}
			else {
				if (y[i] > 0) { y[i] -= d[j]; printf("U"); }
				else { y[i] += d[j]; printf("D"); }
			}
		puts("");
	}
} 

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

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        int s[3];
        for(int j=0;j<3;j++)
            cin >> s[j];
        sort(s,s+3);
        int lo = s[2]*s[2];
        int sh = s[0]*s[0]+s[1]*s[1];
        if(lo==sh){cout << "YES" << endl;
        }else{cout << "NO" << endl;}
    }

    return 0;
}

Measured memory_bytes: 3096
#include<cstdio>
#include<vector>
#include<set>

using namespace std;

const long long mod = 998244353;

vector<int> A[330];
int N, M;

void input(){
	scanf("%d%d", &N, &M);
	for(int i = 0; i < N; ++i){
		for(int j = 0; j < M; ++j){
			int x;
			scanf("%d", &x);
			A[i].push_back(x);
		}
	}
}

int get(vector<int> v){
	for(int i = 0; i < v.size(); ++i) if(v[i] != 0) return i;
	return -1;
}

vector<int> er(vector<int> v, vector<int> e){
	int i1 = get(v);
	int i2 = get(e);
	if(i1 != i2) return v;
	for(int i = 0; i < v.size(); ++i){
		v[i] ^= e[i];
	}
	return v;
}

set<vector<int> > se;

long long pw[330];

long long mul(long long a, long long b){
	return (a * b) % mod;
}

long long solve(){
	pw[0] = 1;
	for(int i = 1; i < 330; ++i){
		pw[i] = (pw[i - 1] * 2) % mod;
	}
	for(int i = 0; i < N; ++i){
		int id = get(A[i]);
		if(id == -1) continue;
		vector<int> v = A[i];
		for(set<vector<int> >::reverse_iterator it = se.rbegin(); it != se.rend(); ++it){
			v = er(v, *it);
		}
		if(get(v) != -1){
			se.insert(v);
		}
	}
	long long ans = pw[N - se.size()];
	ans = mul(ans, pw[se.size()] - 1);
	ans = mul(ans, pw[M - 1]);
	ans += mod;
	ans %= mod;
	return ans;
}

int main(){
	input();
	long long ans = solve();
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
const int mod = 1e9 + 7;
int n , m;
int inp;
int sum;
int val1 , val2;
int ans;
int main(){
	scanf("%d %d" , &n , &m);
	val1 = 0;
	val2 = 0;
	sum = 0;
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , &inp);
		val1 = (val1 + 1LL * inp * (i - 1LL)) % mod;
		val1 = (val1 + mod) % mod;
		val1 = (val1 - sum + mod) % mod;
		sum = (sum + inp) % mod;
		sum = (sum + mod) % mod;
	}
	sum = 0;
	for(int i = 1 ; i <= m ; ++i){
		scanf("%d" , &inp);
		val2 = (val2 + 1LL * inp * (i - 1LL)) % mod;
		val2 = (val2 + mod) % mod;
		val2 = (val2 - sum + mod) % mod;
		sum = (sum + inp) % mod;
		sum = (sum + mod) % mod;
	}
	ans = (1LL * val1 * val2) % mod;
	printf("%d\n" , ans);
}

Measured memory_bytes: 256
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1e5+10
#define mod 1e9 + 7
#define pii pair<int,int>
using namespace std;
/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;
	cin>>n;
	int ans = 1e18;
	for(int i=1;i*i<=n;i++){
		int x = 0;
		if(n%i == 0){
			x = i + n/i - 2;
			ans = min(x,ans);
		}
	}
	cout<<ans;
    return 0;
}
//.........

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

#define ll long long
#define N 200050

struct cline
{
    ll M, C;
    cline() {}
    cline(ll m, ll c): M(m), C(c) {}
};
cline line[N];
ll H[N];

bool bad(const cline & l1,const cline & l2,const cline & l3)
{
    return (l3.C-l1.C)*(l1.M-l2.M)<=(l2.C-l1.C)*(l1.M-l3.M);///(slope dec+query min),(slope inc+query max)
}

void add(cline l,int &last)
{
    line[last++]=l;
    while(last>=3&&bad(line[last-3],line[last-2],line[last-1]))
    {
        line[last-2]=line[last-1];
        last--;
    }
}


///works for random query x
long long bs(int st,int ed,long long x,int last)
{
    int mid=(st+ed)/2;
    ///for min
    if(mid+1<last && line[mid+1].M*x+line[mid+1].C <line[mid].M*x+line[mid].C)
        return bs(mid+1,ed,x,last);
    if(mid-1>=0 && line[mid-1].M*x+line[mid-1].C<line[mid].M*x+line[mid].C)
        return bs(st,mid-1,x,last);
    return line[mid].M*x+line[mid].C;
}

int main()
{
    int last = 0;
    int n;
    ll c;
    scanf("%d %lld",&n,&c);
    for(int i=1; i<=n; i++) scanf("%lld",&H[i]);
    cline ln(-H[1],H[1]*H[1]);
    add(ln,last);
    ll ret;
    for(int i=2; i<=n; i++)
    {
        ret=bs(0,last-1,2*H[i],last);
        ret+=H[i]*H[i]+c;

        ln.M=-H[i],ln.C=ret+H[i]*H[i];
        add(ln,last);
    }
    printf("%lld\n",ret);
    return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

string S;
int cnt[26];

int main(){
  cin >> S;
  for (int i = 0; i < 4; i++) cnt[S[i] - 'A']++;

  for (int i = 0; i < 26; i++){
    if (cnt[i] == 0 || cnt[i] == 2) continue;
    No();
    return 0;
  }
  Yes();

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    bool asc = true, check = false;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int ans = 1;
    for (int i = 1; i < N; i++) {
        if (!check && A[i] != A[i-1]) {
            check = true;
            if (A[i-1] > A[i]) asc = false;
            else asc = true;
        }
        if (check && asc && A[i-1] > A[i]) {
            ans++;
            check = false;
        }else if (check && !asc && A[i-1] < A[i]) {
            ans++;
            check = false;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, l;
    cin >> n >> l;
    vec a(n);
    rep(i, n) cin >> a[i];

    int i = -1;
    rep(j, n-1) {
        if (a[j] + a[j+1] >= l) {
            i = j;
            break;
        }
    }
    if (i == -1) {
        cout << "Impossible" << endl;
        exit(0);
    }
    else {
        cout << "Possible" << endl;
    }

    rep(j, i) {
        cout << j + 1 << endl;
    }

    for (int j = n-2; j >= i; j--) {
        cout << j+1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0;i<n;i++) cin >> a[i];
    bool flag=true;
    if (n%3==0) {
        int k=n/3;
        sort(a.begin(),a.end());
        vector<int> m;
        for (int i=0;i<3;i++) {
            m.push_back(a[k*i]);
            for (int j=1;j<k;j++) {
                if (a[j+k*i]!=m[i]) flag=false;
            }
        }
        int mm=m[0]^m[1];
        if (mm!=m[2]) flag=false;
    } else {
        for (int i=0;i<n;i++) {
            if (a[i]!=0) flag=false;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

#define rep(i, a, b)  for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define sq(x) ((x) * (x))
#define bit(x) bitset<32>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<llint>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


template<typename Tn> Tn __lcm(Tn a, Tn b)
{
    return a / __gcd(a, b) * b;
}

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

int main()
{
    int n, k;
    string s;

    ci >> n >> k >> s;

    s[k - 1] += 'a' - 'A';
    
    co << s << en;
  
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

bool ac[100010];
ll wa[100010];
int main() {
	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<m;i++){
		ll x;
		string y;
		cin>>x>>y;
		x--;
		if(y=="WA"){
			if(ac[x]==false){
				wa[x]++;
			}
		}
		else{
			ac[x]=true;
		}
	}
	ll cnt=0,ans=0;
	for(ll i=0;i<n;i++){
		if(ac[i]){
			cnt++;
			ans+=wa[i];
		}
	}
	cout << cnt << " "<<ans;
	// your code goes here
	return 0;
}

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

using namespace std;


int main(int argc, char *argv[])
{
    
    
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    
    int n, m, l;
    long a[110][110] = {0};
    long b[110][110] = {0};
    long c[110][110] = {0};
    
    cin >> n >> m >> l;
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> b[i][j];
        }
    }
    
    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; j++) {
            cout << c[i][j];
            if (j != l-1) {
                cout << " ";
            }
        }
        cout << endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 3428
import java.util.Scanner;
class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
        		int a = sc.nextInt();
        		int b = sc.nextInt();
        		int c = sc.nextInt();
        		if (a==-1 && b==-1 && c==-1) break;
        		if (a==-1 || b==-1 || a+b < 30) {
        			System.out.println("F");
        		} else if (a+b >= 80) {
        			System.out.println("A");
        		} else if (a+b >= 65) {
        			System.out.println("B");
        		} else if (a+b >= 50) {
        			System.out.println("C");
        		} else {
        			if(c >= 50) {
        				System.out.println("C");
        			} else {
        				System.out.println("D");
        			}
        		} 
        }
    }
}



Measured memory_bytes: 26196
import sys
sys.setrecursionlimit(10**5)

N, M = map(int, input().split())

graph = [ [] for _ in range(N) ]

for i in range(M):
    x, y = map(int, input().split())
    graph[x-1].append(y-1)

dp = [-1] * N
length = [0] * N

def cnt(j):
    if dp[j] != -1:
        return(dp[j])
    else:
        dp[j] = 0
        for k in graph[j]:
            dp[j] = max(cnt(k)+1, dp[j])
        return dp[j]

for i in range(N):
    length[i] = cnt(i)

print(max(length))


Measured memory_bytes: 124188
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_A = 100;

/* typedef */

typedef deque<int> dqi;

/* global variables */

dqi cs[MAX_A + 1];

/* subroutines */

/* main */

int main() {
  int k, t;
  cin >> k >> t;

  int maxa = 0;
  for (int i = 0; i < t; i++) {
    int ai;
    cin >> ai;
    cs[ai].push_back(i);
    if (maxa < ai) maxa = ai;
  }

  int prv = -1;
  while (maxa > 0) {
    bool cont = true;
    for (int a = maxa; cont && a > 0; a--) {
      dqi &ca = cs[a];
      for (dqi::iterator dpt = ca.begin(); dpt != ca.end(); dpt++)
	if(*dpt != prv) {
	  prv = *dpt;
	  ca.erase(dpt);
	  if (a > 1) cs[a - 1].push_back(prv);
	  cont = false;
	  break;
	}
    }
    if (cont) break;
    while (maxa > 0 && cs[maxa].empty()) maxa--;
  }

  printf("%d\n", maxa);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	cin >> N;
	vector<ll> A(N);
	for(int i=0; i<N; i++) cin >> A[i];

	vector<ll> cum(N);
	cum[0] = A[0];
	for(int i=1; i<N; i++) cum[i]=A[i]+cum[i-1];

	int n=0;
	while(n<N && cum[n]<cum[N-1]/2) n++;
	if(n < N && cum[n]==cum[N-1]/2){
		cout << 0 << endl;
		return 0;
	}
	ll a = n == N ? cum[N-1] : cum[n];
	ll b = n > 0 ? cum[n-1] : 0;


	cout << min(a-(cum[N-1]-a), cum[N-1]-b-b) << endl;

	return 0;
}


Measured memory_bytes: 3328
#[int(i) for i in input().split()]
"""
1,2,3,4,5,6,7,8,9,10,11,12,21,22,23,32,33,34...100,101,110,111,112,121,122,123,210,211,212,321,322,323,332,333,334,343,
"""

"""
最大の位
1のとき、100とか120とかある
9のとき、987,989,998,999
...狭い
"""
import time
t = time.time();
k = int(input())
if k <= 9:
    print(k)
else:
    ls = []
    ls_str = ["0","1","2","3","4","5","6","7","8","9"]
    ls.append(ls_str)
    #累積和
    len_ls = [9]
    dic = {"0":["0","1"],"9":["8","9"]}

    for i in range(1,9):
        dic[str(i)] = [str(i-1),str(i),str(i+1)]
    for i in range(9):
        ls_tmp = []
        ls_former = ls[-1]
        for j in range(len(ls_former)):
            for l in dic[ls_former[j][0]]:
                ls_tmp.append(l+ls_former[j])
        ls.append(sorted(ls_tmp))
    ls_ans = []
    for i in range(len(ls)):
        ls_ans.append([j for j in ls[i] if j[0] != "0"])

    for i in range(1,len(ls_ans)):
        len_ls.append(len_ls[-1] + len(ls_ans[i]))

    for i in range(len(len_ls)):
        if i != 0 and len_ls[i] >= k:
            k -= (len_ls[i-1]+1)
            break

    #print(k)
    #print(i)
    print(ls_ans[i][k])
    #print(ls_ans[i][:20])

    #print(time.time()-t)


Measured memory_bytes: 21076
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;

  vector< vector<int> > G(n);
  for(int i=1;i<n;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  using M = Mint<int>;
  vector<M> po(n+1,1);
  for(int i=0;i<n;i++) po[i+1]=po[i]*M(2);

  M ans(0);
  vector<int> sz(n,0);
  MFP([&](auto dfs,int v,int p)->void{
        sz[v]=1;

        M res=po[n-1]-M(1);
        for(int u:G[v]){
          if(u==p) continue;
          dfs(u,v);
          res-=po[sz[u]]-M(1);
          sz[v]+=sz[u];
        }

        res-=po[n-sz[v]]-M(1);
        ans+=res;
      })(0,-1);

  ans/=po[n];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 23040
#include<stdio.h>
int main()
{
    unsigned long long int k, a, b;
    scanf("%lld %lld %lld", &k, &a, &b);
    if (a <= b)
    {
        if (k <= a)
            printf("1\n");
        else
            printf("-1\n");
        return 0;
    }
    k -= b;
    a -= b;
    printf("%lld\n", 2 * ((k + a - 1) / a) - 1);
    return 0;
}

Measured memory_bytes: 128
def gcd(a, b):
    if a < b:
        temp = a
        a = b
        b = temp
    if b == 0:
        return a
    else:
        r = a % b
        if r == 0:
            return b
        else:
            return gcd(b, r)

def lcm(a, b):
    g = gcd(a, b)
    return (a*b) // g

def count_baisuu(A, B, x): #AからBまでにxで割り切れる個数はどれだけか
    start = A
    stop = B
    modx_a = A % x
    if modx_a == 0:
        start = 0
        stop = B-A
    else:
        start = A-modx_a+x
        stop = B-start
        start = 0
    if stop < 0:
        return 0
    else:
        return 1 + stop // x 

A, B, C, D = map(int,input().split())
afromb = B-A+1 #B-A+1個の整数がある
cd_lcm = lcm(C, D)
#cの倍数,dの倍数, lcm(c,d)の倍数は最低でもいくつあるか
divc = count_baisuu(A, B, C)
divd = count_baisuu(A, B, D)
divcd = count_baisuu(A, B, cd_lcm)
print(str((B-A+1)-(divc+divd-divcd)))

Measured memory_bytes: 38384
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

N, M = MAP()
S = input()
T = input()

lcm = lcm_base(N, M)
N_gap = lcm // N
M_gap = lcm // M
for i in range(0, lcm, lcm//gcd(N, M)):
    if i % N_gap == 0 and i % M_gap == 0:
        if S[i//N_gap] != T[i//M_gap]:
            print(-1)
            exit()
print(lcm)


Measured memory_bytes: 5328
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

x = int(input())

cnt = (x // 11)*2

if x % 11 == 0:
    ans = cnt
elif x % 11 > 6:
    ans = cnt + 2
else:
    ans = cnt + 1

print(ans)


Measured memory_bytes: 5460
from enum import IntEnum


class Position(IntEnum):
    TOP = 0
    FORESIDE = 1
    RIGHTSIDE = 2
    BACKSIDE = 3
    LEFTSIDE = 4
    BOTTOM = 5


class Dice:
    def __init__(self, v1, v2, v3, v4, v5, v6):
        self.values = {v1: [v1, v2, v3, v5, v4, v6],
                       v2: [v2, v6, v3, v1, v4, v5],
                       v3: [v3, v6, v5, v1, v2, v4],
                       v4: [v4, v6, v2, v1, v5, v3],
                       v5: [v5, v6, v4, v1, v3, v2],
                       v6: [v6, v5, v3, v2, v4, v1]}
        self.set_top(v1)

    def set_top(self, v):
        if v not in self.values:
            raise ValueError()

        self.top = v
        self.status = self.values[v]

    def rotate(self):
        (self.status[Position.FORESIDE], self.status[Position.RIGHTSIDE],
         self.status[Position.BACKSIDE], self.status[Position.LEFTSIDE]) \
         = (self.status[Position.LEFTSIDE], self.status[Position.FORESIDE],
            self.status[Position.RIGHTSIDE], self.status[Position.BACKSIDE])

    def __getitem__(self, side):
        return self.status[side]


def run():
    sides = [int(v) for v in input().split()]
    dice = Dice(*sides)
    cnt = int(input())

    for i in range(cnt):
        v1, v2 = [int(v) for v in input().split()]
        dice.set_top(v1)
        for j in range(4):
            if v2 == dice[Position.FORESIDE]:
                break
            dice.rotate()
        else:
            raise ValueError()

        print('{}'.format(dice[Position.RIGHTSIDE]))


if __name__ == '__main__':
    run()


Measured memory_bytes: 6348
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
 
// using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define mp make_pair
#define x first
#define y second
typedef long long int ll;
// typedef tree< ll, null_type, less_equal< ll >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define pii pair<ll,ll>
const ll N = 3e5 +9;
// const ll m = 1e9 + 7;
const ll inf= 1e16;
const ll mod = 1e9 + 7;


int main() {   
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     ll t=1;
     // cin>>t;
     while(t--){
     	ll n,k;cin>>n>>k;
     	ll a[n];
     	for(int i = 0;i<n;i++){
     		cin>>a[i];
     	}
     	if(k==0){
     		cout<<1<<'\n';
     		return 0;
     	}
     	ll dp[n+1][k+1];
     	ll pres[n+1][k+1];
     	dp[0][0] = 1;
     	for(int i = 1;i<=k;i++){
     		dp[0][i] = 0;
     	}
     	for(int i = 1;i<n+1;i++){
     		pres[i-1][0] = dp[i-1][0];
     		for(int j = 1;j<=k;j++){
     			pres[i-1][j] =( pres[i-1][j-1]+dp[i-1][j])%mod;
     			// cout<<dp[i-1][j]<<" ";
     		}
     		// cout<<'\n';
     		for(int j = 0;j<=k;j++){
     			dp[i][j] = pres[i-1][j];
     			if(j-a[i-1]-1>=0){
     				dp[i][j]  = (dp[i][j] -pres[i-1][j-a[i-1]-1]+mod)%mod;
     			}
     			// cout<<dp[i][j]<<" ";
     		}
     		// cout<<'\n';
     		
     	}
     	cout<<dp[n][k];

     }     
}

Measured memory_bytes: 157312
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
long bignum = 1_000_000_007;
alias Works = Tuple!(long, "limit", long, "require");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto n = lread();
    auto w = new Works[](n);
    foreach (i; 0 .. n)
    {
        long a, b;
        scan(a, b);
        w[i] = Works(b, a);
    }
    w.sort();
    long timesum;
    bool check = true;
    foreach (e; w)
    {
        timesum += e.require;
        if(timesum > e.limit)
            check = false;
    }
    if(check)
        writeln("Yes");
    else
        writeln("No");
}


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


int main(){

   char s[10010];
   int n;
   cin >> n;
   cin>>s;

    for(int i=0;i<strlen(s);i++){
        int diff = s[i] - 'A';
        putchar('A' + (diff+n)%26);
    }

    putchar('\n');


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep (i, N) cin >> A[i];
  int max = *max_element(A.begin(), A.end());
  vector<int> nums(1e7);
  for (auto v : A) {
    for (int i = 1; v * i <= max; i++) {
      nums[v * i]++;
    }
  }

  int ans = 0;
  for (auto v : A) {
    if (nums[v] != 1) continue;
    ans++;
  }

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


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

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int k,a,b,br;
    cin >> k >> a >> b;
    br=a/k*k;
    if(a%k!=0)
        br+=k;
    if(br<=b)
        cout << "OK";
    else
        cout << "NG";
}


//freopen("testcases/17.in", "r", stdin);
//freopen("output.txt", "w", stdout);


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)

using namespace std;

typedef long long LL;

const int INF=0x3f3f3f3f;

map<string,bool> mp;

int main(){
    int n,ans=0;
    scanf("%d",&n);
    rep(i,1,n){
        string s;
        cin>>s;
        if(mp.count(s))continue;
        else{
            ans++;
            mp[s]=1;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 19308
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  int64_t ans = 1e18;
  for(int i=1; i<=100; i++){
    int64_t x = 0;
    for(int j=0; j<N; j++){
      x += (vec.at(j)-i)*(vec.at(j)-i);
    }
    ans = min(ans,x);
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){
  int N; cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  int ans=0;
  for(auto it=a.begin();it!=a.end();it++){
    ans+=(*it)-1;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;cin>>n;
    string s;cin>>s;
    int y = s.size();
    for(int i=0;i<y;i++){
       char r = s.at(i);
       int x = r - 'A';
       x+=n;
       x%=26;
       char res = x + 'A';
       cout<<res;
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define endl "\n"

int32_t main()
{

   int n ;
   cin >> n; 
   string s ;
   cin >> s ;
   int red = 0 , b = 0 ;
   for(int i = 0 ; i < n ; i++ )
   {
      if(s[i] == 'R') red++;
      else b++;
   }
   if(red > b ) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define       inf                  1<<30
#define       p5                   100007
#define       p6                   1000007
#define       PI                   acos(-1)
#define       M                    1000000007
#define       sc                   scanf
#define       ss                   second
#define       ff                   first
#define       pf                   printf
#define       scin(x)              sc("%d",&(x))
#define       scin2(x,y)            sc("d",&(x),&(y))
#define       READ(f)              freopen(f, "r", stdin)
#define       WRITE(f)             freopen(f, "w", stdout)
#define       ll                   long long
#define       ull                  unsigned long long
#define       pii                  pair < int, int>
#define       pp                  pair < ll, ll>
#define       pq                   priority_queue
#define       pb                   push_back
#define       FastRead             ios_base::sync_with_stdio(0);cin.tie(0)
//int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
//int dx[5] = {1, -1, 0, 0 };
//int dy[5] = {0, 0, 1, -1};
using namespace std;
int main()
{
    int n,m,c,i,j;
    cin>>n>>m>>c;
    int ar[m];
    for(j=0; j<m; j++)
    {
        cin>>ar[j];
    }
    int cnt=0;
    for(i=0; i<n; i++)
    {
        int s=0;
        for(j=0; j<m; j++)
        {
            int a;
            cin>>a;
            s=s+ar[j]*a;
        }
        s=s+c;
        if(s>0)
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}
//CsE91971@%Cou




Measured memory_bytes: 256
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, K = LI()
A = LI()

tel = [-1] * N
flag = True
i = 0
time = 1
while True:
    # print(i, end=" ")
    if time == K:
        print(A[i])
        flag = False
        break
    
    if tel[i] == -1:
        tel[i] = [time, A[i]-1]
        i = A[i]-1
    else:
        # i = A[i]-1
        break
        # pass
    
    time += 1
    # print(time, tel)
# print()
# print(time-1)
# print(time - tel[i][0])
# print((K - (time-1)) % (time - tel[i][0]))

if flag:
    for _ in range((K - (time-1)) % (time - tel[i][0])):
        i = A[i]-1

    print(i+1)


Measured memory_bytes: 92384
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val H, W = sc.nextInt()
    sc.nextLine()
    val A: Array[Array[Char]] = Array.fill(H)(sc.nextLine().toCharArray)

    // 各i について, ai,j = ai,W+1-j = aH+1-i,j = aH+1-i,W+1-j
    // つまり, 各文字について四隅に文字列を配置する必要がある
    def solve(H: Int, W: Int, A: Array[Array[Char]]): Boolean = {
      // mod % 4に対するカウント, % 4 != 0の時のみ, % 4の値を最後に+1する
      val charSizes =
        A.flatten.groupBy(identity).map(_._2.length)
      val groupCounts = new Array[Int](4)
      for (elem <- charSizes) {
        groupCounts(0) += elem / 4
        if (elem % 4 != 0) groupCounts(elem % 4) += 1
      }

      if (H % 2 == 0 && W % 2 == 0) {
        4 * groupCounts(0) == H * W
      } else if (H % 2 == 0 && W % 2 == 1) {
        (4 * groupCounts(0)) >= (H * (W - 1)) && {
          val twoCounts = (if ((4 * groupCounts(0)) > (H * (W - 1))) 2 * ((4 * groupCounts(0)) - (H * (W - 1))) / 4 else 0) + (groupCounts(2))
          2 * twoCounts == H
        }
      } else if (H % 2 == 1 && W % 2 == 0) {
        (4 * groupCounts(0)) >= (W * (H - 1)) && {
          val twoCounts = (if ((4 * groupCounts(0)) > (W * (H - 1))) 2 * ((4 * groupCounts(0)) - (W * (H - 1))) / 4 else 0) + (groupCounts(2))
          2 * twoCounts == W
        }
      } else {
        (4 * groupCounts(0)) >= ((W - 1) * (H - 1)) && {
          {
            val twoCounts = (if ((4 * groupCounts(0)) > ((W - 1) * (H - 1))) 2 * ((4 * groupCounts(0)) - ((W - 1) * (H - 1))) / 4 else 0) + (groupCounts(2))
            2 * twoCounts == (H - 1) + (W - 1) && groupCounts(1) == 1
          } || {
            val twoCounts = (if ((4 * groupCounts(0)) > ((W - 1) * (H - 1))) 2 * ((4 * groupCounts(0)) - ((W - 1) * (H - 1))) / 4 else 0) + (groupCounts(2))
            2 * twoCounts == (H - 1) + (W - 1) - 1 && groupCounts(3) == 1
          }
        }
      }
    }

    val res = if (solve(H, W, A)) "Yes" else "No"
    println(res)
  }

}


Measured memory_bytes: 56012
#include <iostream>

using namespace std;

int main() {
  int r;
  cin >> r;
  if (r < 1200)
    cout << "ABC" << endl;
  else if (1200 <= r && r < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int n, l[2001];
  scanf("%d", &n);

  // int tmp, uni[1001] = {0}, times[1001] = {0};
  rep(i, n)
  {
    scanf("%d", &l[i]);
    // if (uni[tmp])
    //   times[tmp]++;
    // else
    //   uni[tmp] = 1;
  }

  qsort(l, n, sizeof(int), acs);

  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      for (int k = j + 1; k < n && l[k] < l[i] + l[j]; k++)
      {
        if (l[k] < l[i] + l[j])
          ans++;
        else
          break;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
int main(){
  int n, now, last = 0;
  long long ans = 0;
  scanf("%d", &n);
  for(int i = 0 ; i < n ; i++){
    scanf("%d", &now);
    if(now){
      if(last){
        now--;
        ans++;
        ans += (long long)now / 2;
        last = now % 2;
      }else{
        ans += (long long)now / 2;
        last = now % 2;
      }
    }else last = 0;
  }
  printf("%lld\n", ans);
  return 0;
}


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


int n, a[100005], ans, d;
int main(){
    cin >> n;

    int x;
    for(int i=1; i<=n; ++i){
        cin >> x;
        if(x > n) ++d;
        else  ++a[x];
    }

    for(int i=1; i<=n; ++i){
        if(a[i] < i) ans += a[i];
        else{
            ans += a[i] - i;
        }
    }

    cout << ans + d << endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e5+100;
int main()
{
	int n,m,l=0,r=maxn;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		l=max(l,x);
		r=min(r,y);
	}
	if(l>r)printf("0");
	else printf("%d",r-l+1);
	return 0;
} 

Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = rr()
print(s[0] + str(len(s) - 2) + s[-1])









Measured memory_bytes: 27212
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int v[3];
    for (auto& i : v) cin >> i;
    sort(v, v + 3);
    cout << (v[0] != v[2] && (v[0] == v[1] || v[1] == v[2]) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <iomanip> //cout << fixed << setprecision(12) << ans << endl;
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define rloop(i, l, r) for(int i = l; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vec_i;
typedef pair<int,int> pair_ii;
typedef pair<ull,ull> pair_ull;
 
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e9;
const int MOD = 1e9+7;
 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, k;
	cin >> n >> k;

	string str;
	cin >> str;
	int a=0, b=0;
	rep(i,n-1){
		if(str[i]==str[i+1]){
			a++;
		}else{
			b++;
		}
	}
	cout << a+min(2*k, b) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, M; 
  cin >> N >> M;

  vector<vector<int>> A(N, vector<int>(M));
  REP(i, N) REP(j, M){
    cin >> A[i][j];
    A[i][j]--;
  }

  vector<bool> used(M, true);

  int ans = INF;
  REP(k, M){
    vector<int> cnt(M, 0);
    REP(i, N) REP(j, M){
      if(used[A[i][j]]){
        cnt[A[i][j]]++;
        break;
      }
    }
    int ret = 0;
    int max = 0, pos;
    REP(i, M){
      if(cnt[i] != 0){
        if(chmax(ret, cnt[i])) pos = i;
      }
    }
    used[pos] = false;
    chmin(ans, ret);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 1024
n = int(input())

cards = {

"S" : list(0 for q in range(13)),
"H" : list(0 for w in range(13)),
"C" : list(0 for e in range(13)),
"D" : list(0 for r in range(13)),

}

for _ in range(n):
	a,b = input().split()
	cards[a][int(b)-1] = 1
for a in ("S", "H", "C", "D"):
	for b in range(13):
		if cards[a][b] == 0:
			print(a,b+1)

Measured memory_bytes: 7764
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {



    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] s = in.readLine().split(" ");
        long A = Long.parseLong(s[0]);
        long B = Long.parseLong(s[1]);
        long C = Long.parseLong(s[2]);
        long K = Long.parseLong(s[3]);
        long ans = 0;
        boolean flag = false;
        if(A > K) {
            System.out.println(K);
        } else {
            K -= A;
            if(K == 0) {
                System.out.println(A);
            } else {
                if(B > K) {
                    System.out.println(A);
                } else {
                    K -= B;
                    if(K == 0) {
                        System.out.println(A);
                    } else {
                        if(C > K) {
                            System.out.println(A - K);
                        } else {
                            System.out.println(A - C);
                        }
                    }
                }
            }
        }
    }

}


Measured memory_bytes: 25396
#include <bits/stdc++.h>
    using namespace std;
    #define INF 2000000000
    typedef long long int ll;
    typedef pair<ll,ll> ii;
    typedef pair<ii,ll> iii;
    typedef vector<ll> vi;
    typedef vector<ii> vii;
    #define getbit(n,i) (((n)&(1<<(i)))!=0)
    #define setbit0(n,i) ((n)&(~(1<<(i))))
    #define setbit1(n,i) ((n)|(1<<(i)))
    #define togglebit(n,i) ((n)^(1<<(i)))
    #define lastone(n) ((n)&(-(n)))
    #define read freopen("debug\\in.txt","r",stdin)
    #define write freopen("debug\\out.txt","w",stdout)
    #define fi first
    #define se second
    #define getI(a) scanf("%d",&a)
    #define getII(a,b) scanf("%d%d",&a,&b)
    #define PI (acos(-1))
    #define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
    #define mod (1000000007)
    #define asz 500005
    #define pb push_back
    #define ppf pop_front
    #define ppb pop_back
    #define pf push_front
    ll ispos(ll n,ll num,ll m){
    	ll res=num;
    	if(m%(num+1)==0)
    	res+=(m/(num+1));
    	else
    	res+=(m/(num+1)+1);
    	return res;
	}
    int main()
    {
        fastread;
        ll t,i,j,k,l,n,m;
        cin>>n;
        string s;
        cin>>s;
        ll co=0;
        for(i=0;i<=n-3;i++){
        	if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
        	co++;
		}
		cout<<co;
		
    	return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int f(int x) {
  int res = 0;
  while (x%2 == 0) {
    res++;
    x /= 2;
  }
  return res;
}

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i] /= 2;
  }
  int t = f(a[0]);
  rep(i, n) {
    if(t != f(a[i])) {
      puts("0");
      return 0;
    }
    a[i] >>= t;
  }
  m >>= t;

  int l = 1;
  rep(i, n) {
    l = lcm(l, a[i]);
    if (l > m) {
      puts("0");
      return 0;
    }
  }
  int ans = m / l;
  ans = (ans + 1) / 2;
  cout << ans << endl;

}

Measured memory_bytes: 640
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long int MOD = 1000000007;


int main()
{
	long long int n, cnt = 0;

	cin >> n;

	vector<long long int> a(n + 1), b(n);

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

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

	for (int i = 0; i < n; i++) {
		if (a[i] >= b[i]) {
			cnt += b[i];
		}
		else {
			cnt += a[i];
			b[i] -= a[i];

			if (a[i + 1] >= b[i]) {
				cnt += b[i];
				a[i + 1] -= b[i];
			}
			else {
				cnt += a[i + 1];
				a[i + 1] = 0;
			}
			
		}

	}
	cout << cnt << endl;

	return 0;

}

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

int main() {
  string n;
  cin >> n;
  if((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]))
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,c=0;
    cin>>a>>b;
    int d[100];
    for(int i=0;i<b;i++){
        cin>>d[i];
        c=c+d[i];
    }
    if(c%(a+1)==0){cout<<c/(a+1)<<endl;}else{cout<<c/(a+1)+1<<endl;}
}


Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;
  int ans = 0;
  for (int d = 1; d * d <= M; d++) {
    if (M % d == 0) {
      if (M / d >= N) ans = max(ans, d);
      if (M / (M / d) >= N) ans = max(ans, M / d);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N=int(input())
b=[int(i) for i in input().split()]
ans=[0]*N
for i in range(N)[::-1]:
  for k in range(i+1)[::-1]:
    if b[k]==k+1:
      ans[i]=b[k]
      break
    if k==0:
      print(-1)
      exit()
  b.pop(k)
for i in ans:
  print(i)
    

Measured memory_bytes: 38768
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template<typename T> void print(const T & v);


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

    int N;
    cin >> N;
    vector<ll> v(3 * N);
    rep(i, 3 * N) cin >> v[i];
    sort(v.begin(), v.end());
    ll ans = 0;
    for(int i = 1; i <= N; i++){
        ans += v[(3 * N) - (2 * i)];
    }
    cout << ans << endl;
    return 0;
}


// Use For Debug
template <typename T>
void print(T const & v){
    for(int i = 0; i < v.size(); i++){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 2560