akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll N,K;cin >> N >> K;
  vector<PLL> v(N);
  rep(i,N)cin >> v[i].first >> v[i].second;
  sort(all(v));
  rep(i,N){
    K -= v[i].second;
    if(K<=0){
      cout << v[i].first << endl;
      break;
    }
  }
  return 0;
}


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

int main() 
{
	int p,x[1005];
	scanf("%d",&p);
	for(int i=0;i<p;i++)
	{
		scanf("%d",&x[i]);
	}
	sort(x,x+p);
	int g=x[p-1]-x[0];
	printf("%d\n",g);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    char x,y;
    cin >> x >> y;
    string ans;
    ans = x > y ? '>' : x == y ? '=' : '<';
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#define ll long long int
using namespace std;

int main() {
	int N, AC=0, WA=0, TLE=0, RE=0;

	cin >> N;
	vector<string> str(N);

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

	for (int i = 0; i < N; i++){
		if (str[i] == "AC"){
			AC++;
		}
		else if (str[i] == "WA"){
			WA++;
		}
		else if (str[i] == "TLE"){
			TLE++;
		}
		else{
			RE++;
		}
	}

	cout << "AC x " << AC << endl;
	cout << "WA x " << WA << endl;
	cout << "TLE x " << TLE << endl;
	cout << "RE x " << RE << endl;

	return 0;
}

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

int main(){
    char b;
    cin >> b;

    map<char, char> m;
    m['A'] = 'T';
    m['T'] = 'A';
    m['C'] = 'G';
    m['G'] = 'C';
    cout << m[b] << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    let p: Vec<f64> = (0..n).map(|_| read()).collect();
    let mut kitaich: Vec<f64> = Vec::new();
    let mut ans : f64 = 0.0;
    let mut sum : f64 = 0.0;

    for i in 0..n {
        kitaich.push(p[i] / 2.0 + 0.5);
    }
    //累積和を使って、計算を短くする
    for i in 0..n - k + 1 {
        //let sum = (i..i+k).fold(0.0, |sum, x| sum + kitaich[x]);
        if i == 0 {
            sum = (i..i+k).fold(0.0, |sum, x| sum + kitaich[x]);
        }else {
            sum = sum - kitaich[i-1] + kitaich[i+k-1];
        }
        if sum > ans {
            ans = sum;
        }
    }
    println!("{:.012}", ans);
}


Measured memory_bytes: 8444
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define d double
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin>>n;
  string s;
  cin>>s;
  int i;
  int count=0;
  for(i=0;i<n-2;i++){

  	if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
  	   count++;	
  	   i+=2;
	}

  }
  
  cout<<count<<endl;
  
  return 0;
}

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

#define ll long long
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define vii vector<int,int>
#define vvi vector<vector<int>>
#define umii unordered_map<int,int>
#define mii map<int,int>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a ; i<b ; i++)

const long long MOD = 1e9+7;

void solve() {
	string s;
	cin>>s;
	int cr=0, mx_cr=0;
	for(int i=0; i<s.size(); i++) {
		if(s[i]=='R') {
			cr++;
			mx_cr=max(mx_cr,cr);
		}
		else {
			cr=0;
		}
	}
	cout << mx_cr << endl;
}

signed main() 
{
	int t=1;
	// cin>>t;
	for(int i=1; i<=t; i++) {
		solve();
	}
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include<cmath>
#include<numeric>

using namespace std;
unsigned long long int gcd(int, int);

int main(void) {
	int n;
	cin >> n;
	vector<int> a;


	unsigned long long int ans = 0;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				ans += gcd(gcd(i, j), k);
			}
		}
	}

	cout << ans<<endl;

	return 0;
}

unsigned long long int gcd(int a,int b) {

	if (a < b) {
		int tmp = a;
		a = b;
		b = tmp;
	}

	int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}


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

// ?????£??????????????°???????±???????
int fibonacci(int n);
int fib[45];

int main()
{
    int num;
    cin >> num;
    int res = 0;

    res = fibonacci(num);
    cout << res << endl;

    //getchar();
    //getchar();

    return 0;
}

int fibonacci(int n)
{
    if(n == 0 || n == 1) { return 1; }
    //return fibonacci(n - 1) + fibonacci(n - 2);
    if(fib[n]) { return fib[n]; }
    return fib[n] = fibonacci(n-1) + fibonacci(n-2);
}

Measured memory_bytes: 3084
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }


/*
<url:https://onlinejudge.u-aizu.ac.jp/services/room.html#RitsCamp18Day1/problems/E>
問題文============================================================
 あなたはグラフのアルゴリズムとして典型であるフローの問題を解いていた。
 その問題で与えられるグラフは、頂点 N 個、辺 M 本であり、
 頂点 xi から 頂点 yi に容量 zi 、コスト di の辺が張られている。
 ところが、AORイカちゃんが入力ケースにいたずらした。
 その結果、 xi,yi,zi の順序がシャッフルされ、頂点の情報と容量の情報が区別できなくなってしまった。
 
 そこで、あなたは s−t 間のフローを求めることを諦め、 s−t 間の最短距離を求めることにした。
 あなたは、 xi,yi,zi の順序がシャッフルされた入力ケース ai,bi,ci のうちから二つを頂点情報にし、
 コスト di の辺を張ることにした。
 つまり、ai から bi, ai から ci, bi から ci の三つの候補のうち一つにコスト di の辺を張る。
 
 考えられるグラフのうち、 「s から t への最短距離」の最小値を求めよ。
=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N,M,s,t; cin >> N >> M >> s >> t;
    s--; t--;
    vector<ll> a(M),b(M),c(M),d(M);
    for(int i = 0; i < M;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--; c[i]--;
    }
    vector<vector<pll>> G(N);
    for(int i = 0; i < M;i++){
        G[a[i]].push_back({b[i],d[i]});
        G[b[i]].push_back({a[i],d[i]});
        
        G[a[i]].push_back({c[i],d[i]});
        G[c[i]].push_back({a[i],d[i]});
        
        G[b[i]].push_back({c[i],d[i]});
        G[c[i]].push_back({b[i],d[i]});
    }
    
    vector<ll> dist(N,LINF);
    dist[s] = 0;
    priority_queue<pll,vector<pll>,greater<pll>> pq;
    pq.push({0,s});
    while(pq.size()){
        ll d,n; tie(d,n) = pq.top(); pq.pop();
        if(dist[n] < d) continue;
        for(auto e:G[n]){
            ll next = e.first,cost = e.second;
            if(dist[next] > dist[n] + cost){
                dist[next] = dist[n] + cost;
                pq.push({dist[next],next});
            }
        }
    }
    cout << dist[t] << endl;
	return 0;
}



Measured memory_bytes: 26764
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 100005 ;
using namespace std ;
int n, d[N << 1] ; 
map <int, map<int, int> > cnt ;
multiset <int> E[N] ;
set <pair<int, int> > Q ;

void add(int x, int y) {
	E[x].insert(y) ;
	int tmp = ++ cnt[x][y] ;
	if (tmp > 1) Q.insert(make_pair(min(x, y), max(x, y))) ;
}

void del(int x, int y) {
	E[x].erase(E[x].find(y)) ;
	int tmp = -- cnt[x][y] ;
	if (tmp < 2) Q.erase(make_pair(min(x, y), max(x, y))) ;
}

bool check() {
	rep(k, 1, n - 1) {
		if (Q.empty()) return false ;
		pair <int, int> u = *Q.begin() ;
		Q.erase(u) ;
		int x = u.first, y = u.second ;
		del(x, y), del(x, y), del(y, x), del(y, x) ;
		if (E[x].size() > E[y].size()) swap(x, y) ;
		std :: multiset <int> :: iterator it ;
		d[0] = 0 ;
		for (it = E[x].begin() ; it != E[x].end() ; it ++) {
			int v = *it ;
			add(y, v), add(v, y) ;
			d[++ d[0]] = v ;
		}
		rep(i, 1, d[0]) {
			del(x, d[i]), del(d[i], x) ;
		}

	}
	return true ;
}

int main() {
	scanf("%d", &n) ;
	int x, y ;
	rep(i, 1, n - 1) {
		scanf("%d%d", &x, &y) ;
		add(x, y), add(y, x) ;
	}
	rep(i, 1, n - 1) {
		scanf("%d%d", &x, &y) ;
		add(x, y), add(y, x) ;
	}
	if (check()) printf("YES\n") ;
		else printf("NO\n") ;
	return 0 ; 
}

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

int count(int n, int x){
  int cnt=0;
  for(int i=1; i<=n-2; i++){
    for(int j=i+1;j<=n-1;j++){
      for(int k=j+1; k<=n; k++){
        if(i+j+k==x) cnt++;
      }
    }
  }
  return cnt;
}

int main(){
  int n, x;

  while(1){
    cin >> n >> x;
    if(n==0 && x==0)break;
    cout << count(n, x) <<endl;
  }
  return 0;
}


Measured memory_bytes: 3052
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,k;
int dp[105][2][33333],cf[105][2][33333];
int cnt[33333]; 
inline void add(int &x,int y){
	(x+=y)%=mod;
}
inline int mul(int x,int y){
	return (ll)x*y%mod;
}
int main(){
	cin>>n>>k;
	int S=(int)sqrt(n);
	for(int i=1;i<=S;i++){
		cnt[i]=n/i-max(S,n/(i+1));
	}
	dp[0][0][1]=1;
	for(int i=0;i<=k;i++){
		if(i){
			int cur=cf[i][0][0];
			for(int j=1;j<=S;j++){
				add(cur,cf[i][0][j]);
				dp[i][0][j]=cur;
//				cerr<<"0:"<<j<<" "<<dp[i][0][j]<<endl;
			}
			cur=cf[i][1][0];
			for(int j=1;j<=S;j++){
				add(cur,cf[i][1][j]);
				dp[i][1][j]=mul(cur,cnt[j]);
//				cerr<<"1:"<<j<<" "<<dp[i][1][j]<<endl;
			}
		}
		for(int j=1;j<=S;j++){
			add(cf[i+1][0][0],dp[i][0][j]);
			add(cf[i+1][1][j],dp[i][0][j]);
			add(cf[i+1][0][0],dp[i][1][j]);
			add(cf[i+1][0][j+1],mod-dp[i][1][j]);
		}
	}
	int ans=0;
	for(int i=0;i<=1;i++)for(int j=1;j<=S;j++)add(ans,dp[k][i][j]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 53760
#include<bits/stdc++.h>
using namespace std;
long s,a[300010],n,i;
main(){
  cin>>n;
  for(i=3*n;i;i--)cin>>a[i];
  sort(a+1,a+3*n+1);
  for(i=n;i;--i)s+=a[3*n-2*i+1];
  cout<<s;
}


Measured memory_bytes: 2560
n,m = list(map(int, input().split()))

a = [[0 for j in range(m)] for i in range(n)]
b = [0 for i in range(m)]
for i in range(n):
    lst = list(map(int, input().split()))
    for j in range(m):
        # print(i, j)
        a[i][j] = lst[j]

for j in range(m):
    b[j] = int(input())

for i in range(n):
    c = 0
    for j in range(m):
        c += a[i][j] * b[j]
    print(c)



Measured memory_bytes: 5952
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
int main() {
	int n, ans = 2000000000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		if (ans > a + b)ans = a + b;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

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

void warshall_floyd(vector<vector<int>> &d) {
    int n = d.size();
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> d(10, vector<int>(10));
    for (int i = 0; i <= 9; i++) {
        for (int j = 0; j <= 9; j++) {
            cin >> d[i][j];
        }
    }

    warshall_floyd(d);

    vector<int> a(10, 0);
    for (int i = 0; i < h * w; i++) {
        int tmp;
        cin >> tmp;
        if (tmp != -1) a[tmp]++;
    }
    int ans = 0;
    for (int i = 0; i <= 9; i++) {
        ans += a[i] * d[i][1];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;
 
int main(){
 
	int n, l;
	cin >> n >> l;
	
	vector<string> s(n);
	rep(i, n) cin >> s[i];
	
	SORT(s);
	
	rep(i, n) cout << s[i];
	cout << endl;
	
	return 0;
}

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

class UnionFind {
	vector<int> data;
	int root(int a) {
		return data[a] < 0 ? a : data[a] = root(data[a]);
	}
public:
	UnionFind(int n) : data(n, -1) {}
	bool Find(int a, int b) {
		return root(a) == root(b);
	}
	void Union(int a, int b) {
		int ra = root(a), rb = root(b);
		if (ra == rb) return;
		if (data[ra] < data[rb]) {
			data[ra] += data[rb];
			data[rb] = a;
		}
		else {
			data[rb] += data[ra];
			data[ra] = b;
		}
	}
};

int main()
{
	int n, m, q;
	cin >> n >> m;
	UnionFind uf(n);
	for (int i = 0, s, t; i < m;i++) {
		cin >> s >> t;
		uf.Union(s, t);
	}
	cin >> q;
	for (int i = 0, s, t; i < q; i++) {
		cin >> s >> t;
		if (uf.Find(s, t))
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N): a.append(a[i] + A[i])
for i in range(M): b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)



Measured memory_bytes: 47376
from collections import defaultdict
N, = map(int, input().split())

def normal(xs):
    return tuple(min((xs[j:] + xs[:j] for j in range(1, 5))))

dd = defaultdict(int)
cc = dict()
norm = dict()
ss = []
for _ in range(N):
    xs = list(map(int, input().split()))
    cnd = [tuple(xs[j:] + xs[:j]) for j in range(1, 5)]
    x = min(cnd)
    for item in cnd:
        norm[item] = x
    dd[x] += 1
    cc[x] = (4 if x[0] == x[1] else 2)if x[0] == x[2] and x[1] == x[3] else 1
    ss.append(x)

def icr(x):
    dd[x] += 1

def dcr(x):
    dd[x] -= 1

def f(ff, gg):
    a,b,c,d=ff
    e,h,g,f=gg
    tl = [(a,e,f,b), (b,f,g,c), (c,g,h,d), (d,h,e,a)]
    for cp in tl:
        if cp not in norm:
            return 0
    r = 1
    for cp in tl:
        cp = norm[cp]
        r *= dd[cp]*cc[cp]
        dcr(cp)
    for cp in tl:
        cp = norm[cp]
        icr(cp)
    return r

r = 0
for i in range(N):
    ff = ss[i]
    dcr(ff)
    for j in range(i+1, N):
        sl = ss[j]
        dcr(sl)
        x, y, z, w = sl
        sls = [(x,y,z,w), (y,z,w,x), (z,w,x,y), (w,x,y,z)]
        for s in sls:
            r += f(ff, s)
        icr(sl)
    icr(ff)
print(r//3)


Measured memory_bytes: 51160
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define fi first
#define se second
//#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;

int res;

int main(){
	char c;
	scanf("%c",&c);
	while(c != '\n'){
		res = (res + (c - '0')) % 9;
		scanf("%c",&c);
	}
	if(res){
		cout<<"No\n";
	}
	else
		cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 1e5 + 44;
const int X[] = {1,0,-1,0,1,-1,1,-1};
const int Y[] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1e9 + 7;
const long long INF = 1e18;
const int inf = 1e9;

vector <int> g[N], f[N];

int deg[N];

int dp[N];

queue <int> s;

int main () {
	boost;
	int n, m;
	cin >> n >> m;
	for (int i = 0 ; i < m ; ++ i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		g[a].push_back (b);
		f[b].push_back (a);
	}
	for (int i = 0 ; i < n ; ++ i) {
		deg[i] = g[i].size();
		if (!deg[i])
			s.push (i);
	}
	int mx = 0;
	while (s.size()) {
		int v = s.front(); s.pop();
		for (int j : f[v]) if (deg[j] > 0) {
			--deg[j];
			dp[j] = max (dp[j], dp[v] + 1);
			if (!deg[j])
				s.push (j);
		}
		mx = max (mx, dp[v]);
	}
	cout << mx;
}

Measured memory_bytes: 12032
A,B,C=map(int,input().split())
if A==B==C and A%2==0:
  print(-1)
elif A%2==1 or B%2==1 or C%2==1:
  print(0)
else:
  c=0
  while A%2==B%2==C%2==0:
    A0=A
    B0=B
    C0=C
    A=(B0+C0)/2
    B=(C0+A0)/2
    C=(A0+B0)/2
    c+=1
  print(c)
  

Measured memory_bytes: 3060
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-03-17 13:07:16
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++)
        cin >> d[i];

    sort(all(d));

    int a, b;
    a = d[n/2-1];
    b = d[n/2];

    int ans = b - a;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
int n,k=0,i=-1,c=0,a[10000];
cin>>n;
while(n)
{
    k=n%10;
    n=n/10;
    a[++i]=k;
}
if(a[0]==a[1]&&a[1]==a[2]||a[1]==a[2]&&a[2]==a[3])
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;


return 0;}


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

using namespace std;

#define int long long 
#define MOD 1000000007


signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int d[401][401];
	for(int i=0;i<401;i++){
		d[i][0] = 1;
		for(int j=1;j<401;j++){
			d[i][j] = d[i][j-1] * i;
			d[i][j] %= MOD;
		}
	}
	int f[401][401];
	for(int i=0;i<401;i++) for(int j=0;j<401;j++) f[i][j] = 0;
	for(int i=0;i<401;i++){
		for(int j=1;j<401;j++){
			f[j][i] = f[j-1][i] + d[j][i];
			f[j][i] %= MOD;
		}
	}
	int n,c;
	cin >> n >> c;
	int a[n],b[n];
	for(int i=0;i<401;i++) for(int j=0;j<401;j++) d[i][j] = 0;
	d[0][0] = 1;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++) cin >> b[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<=c;j++){
			int cur = f[b[i]][j] - f[a[i]-1][j] + MOD;
			cur %= MOD;
			for(int k=j;k<=c;k++){
				d[i+1][k] += d[i][k-j] * cur;
				d[i+1][k] %= MOD;
			}
		}
	}
	cout << d[n][c] << "\n";
	return 0;
}


Measured memory_bytes: 2816
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

class Segment_Tree {
	vector<long long int>v;
	int num;
	long long int ret;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		v[place] = min(Update(place * 2), Update(place * 2 + 1));
		return v[place];
	}
public:
	Segment_Tree(int n) {
		n++;
		num = 1;
		while (num < n * 2) {
			num *= 2;
		}
		v.resize(num, MOD * MOD);
	}
	void Insert(int place, long long int num) {
		place += v.size() / 2;
		v[place] = num;
		place /= 2;
		while (place) {
			v[place] = min(v[place * 2], v[place * 2 + 1]);
			place /= 2;
		}
	}
	long long int RMQ(int a, int b) {
		ret = INT_MAX;
		b++;
		for (a += num/2, b += num / 2; a < b; a >>= 1, b >>= 1) {
			if (a & 1)ret = min(ret, v[a++]);
			if (b & 1)ret = min(ret, v[--b]);
		}
		return ret;
	}
};

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

	cin >> N;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	Segment_Tree lsg(N);
	Segment_Tree rsg(N);
	for (int i = 0; i < N; i++) {
		if (v[i] < 0) {
			lsg.Insert(i, abs(v[i]) - i);
			rsg.Insert(i, abs(v[i]) + i);
		}
	}
	vector<int>lexit(N, -1);
	vector<int>rexit(N, -1);
	for (int i = 0; i < N; i++) {
		if (i) {
			lexit[i] = lexit[i - 1];
		}
		if (v[i] == 0) {
			lexit[i] = i;
		}
	}
	for (int i = N - 1; i >= 0; i--) {
		if (i + 1 != N) {
			rexit[i] = rexit[i + 1];
		}
		if (v[i] == 0) {
			rexit[i] = i;
		}
	}
	long long int ans = 0;
	for (int i = 0; i < N; i++) {
		if (v[i] <= 0)continue;
		long long int add = 0;
		//cout << i << " " << lexit[i] << " " << rexit[i] << endl;
		if (lexit[i] != -1)add = max(add, min(rsg.RMQ(lexit[i], i) - i, v[i]));
		//cout << lsg.RMQ(i, rexit[i]) << endl;
		if (rexit[i] != -1)add = max(add, min(lsg.RMQ(i, rexit[i]) + i, v[i]));
		ans += add;
		//cout << i << " " << ans << endl;
	}
	cout << ans << endl;
}



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

	#define mainspring cout<<"mainspring\n";
	#define barrel cout<<"barrel\n";
	#define escapement cout<<"escapement\n";

	#define pb push_back
	#define eb emplace_back
	#define all(v) (v).begin(), (v).end() 
	#define sz(v) (int)((v).size())
	#define fs first
	#define sd second
	#define tik(i,a,b) for(int i = a; i < b; i++)
	#define tok(i,a,b) for(int i = a; i >= b; i--)
	#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

	typedef long long ll;
	typedef unsigned long long ull;

	#define int ll 

	typedef pair < int, int > pi;
	typedef pair < pi, int > ppi;

	typedef vector < int > vi;
	typedef vector < vector < int > > vvi;
	typedef vector < pi > vpi;
	typedef vector < vpi > vvpi;
	typedef vector < ppi > vppi;

	void fast() {
	    ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	}

	void err(istream_iterator<string> it) {cout << endl;}
	template<typename T, typename... Args>
	void err(istream_iterator<string> it, T a, Args... args) {
	    cerr << *it << " = " << a << " ";
	    err(++it, args...);
	}

	ll pow(ll x, ll y) {
		if(y == 0)
		return 1;
		ll temp = pow(x, y/2);
		temp = (temp*temp);
		if(y%2 == 1)
			temp *= x;
		return temp;
	}

	int32_t main() {
		int n, k;
		cin >> k >> n;
		int a[2*n];
		for(int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);
		a[n] = a[0] + k;
		int large_arc = 0;
		for(int i = 0; i < n; i++) {
			large_arc = max({large_arc, a[i + 1] - a[i]});
		}
		cout << k - large_arc;
	}


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

int main(void)
{
	cin.tie(0);	ios_base::sync_with_stdio(0);
	int x;	cin >> x;
	int ans = 0;
	ans += (x/500)*1000;
	x = x %500;
	ans += (x/5)*5;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
// *start on @date: 2020-03-01 20:08 
using namespace std;
typedef long long ll;
const int maxn = 1000 + 5;
const int inf  = 0x3f3f3f3f;



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

    int n;
    cin>>n;
    cout<<(n+1)/2<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;

int i, j, n, k, s[100], b[100][100];

int main(void) {
    while(1) {
        scanf("%d%d", &n, &k);
        if(!n && !k) break;

        for(i = 0; i < k; i++) scanf("%d", &s[i]);

        for(i = 0; i < n; i++) {
            for(j = 0; j < k; j++) {
                scanf("%d", &b[i][j]);
                s[j] -= b[i][j];
            }
        }
        bool ok = true;
        for(i = 0; i < k; i++) if(s[i] < 0) ok = false;
        if(ok) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long ll;

const int maxn = 200010;

ll sum = 0, xr = 0;
int a[maxn], nxt[maxn], n;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    ll ans = 0;
    for (int i = n; i >= 1; i--) {
        nxt[i] = nxt[i+1];
        if (a[i+1]) nxt[i] = i+1;
    }
    for (int i = 1; i <= n; i++) {
        sum = xr = a[i];
        int cur = i;
        while (nxt[cur]) {
            if (sum+a[nxt[cur]] == (xr^(a[nxt[cur]]))) {
                cur = nxt[cur];
                sum += a[cur];
                xr ^= a[cur];
            } else break;
        }
        if (nxt[cur]) ans += nxt[cur]-i;
        else ans += n-i+1;
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main() {
    int n;
    cin>>n;
    int p[n];
    for(int i=0;i<n;i++) cin>>p[i];
  	vector<int> s(n);
  	for(int i=0;i<n;i++) s.at(i)=p[i];
  	int cnt=0;
  	sort(s.begin(), s.end());
  	for(int i=0;i<n;i++) if(p[i]!=s.at(i)) cnt++;
  	cnt>2? cout<<"NO"<<endl: cout<<"YES"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
typedef long long ll;
int const N_MAX=50;
int N;
ll X;
vector<ll> f(N_MAX),p(N_MAX);

ll G(int n,ll x){
    if(x==0){
        return 0;
    }else if(n==0){
        return 1;
    }
    if(x>=f[n-1]+2) return 1+p[n-1]+G(n-1,x-(f[n-1]+2));
    return G(n-1,x-1);
}

int main(){
    cin >> N >> X;
    
    f[0]=1;
    p[0]=1;
    rep2(i,1,N){
        f[i]=2*f[i-1]+3;
        p[i]=2*p[i-1]+1;
    }

    cout << G(N,X) << endl;
    

}

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


int main()
{
	int a,b;
	cin>>a>>b;
	int max1=max(a+b,a-b);
	int max2=max(a-b,a*b);
	int max3=max(max1,max2);
	cout<<max3;
}

Measured memory_bytes: 256
l = gets.to_i
ans = []

i = 1
while l >= (1 << i)
  ans << "#{i} #{i+1} #{0}"
  ans << "#{i} #{i+1} #{1 << i-1}"
  i += 1
end

sum = 1 << i-1
(i-1).downto(0) do |j|
  if l[j-1] == 1
    ans << "#{j} #{i} #{sum}"
    sum += 1 << j-1
  end
end

puts "#{i} #{ans.size}",ans

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();

		if(n%k == 0) {
			System.out.println("0");
		}else{
			System.out.println("1");
	}
	}
}


Measured memory_bytes: 19924
require 'prime'
n,m=gets.split.map &:to_i
a=gets.split.map &:to_i
c=%w(IMPOSSIBLE POSSIBLE)
rest=nil
if a.include?(m)
  puts c[1]
else
if a.max<m
  puts c[0]
else
  a.sort!
  if a.size == 1
    if a[0]==m
      puts c[1]
    else
      puts c[0]
    end
  else
    g=(a[0]-a[-1]).abs
    if g==0
      puts c[0]
    else
      

    h=Prime.prime_division(g)
    cc=true
    h.each do |e|
      cc=true
      (a.size-1).times do |i|
        if (a[i]-a[i+1]).abs % e[0] != 0
          cc=false
          break
        end
      end
      if cc
        rest = e[0]
        break
      end
    end
    if cc
      if (a[0]-m).abs % rest != 0
        puts c[0]
      else
        puts c[1]
      end
    else
      puts c[1]
    end
  end
  end
end
end
   



Measured memory_bytes: 9760
#include <iostream>
using namespace std;
int main()
{
    int H,W;
    cin>>H>>W;
    char s[H][W];
    for(int i=0;i<H;i++)
    {
        cin>>s[i];
    }
    for(int i=0;i<H;i++)
    {
        for(int j=0;j<W;j++)
        {
            if(s[i][j]!='#')
                {
                    int c=0;
                    if(i>0&&j>0&&s[i-1][j-1]=='#')c++;
                    if(j>0&&s[i][j-1]=='#')c++;
                    if(i<H-1&&j>0&&s[i+1][j-1]=='#')c++;
                    if(i>0&&s[i-1][j]=='#')c++;
                    if(i<H-1&&s[i+1][j]=='#')c++;
                    if(i>0&&j<W-1&&s[i-1][j+1]=='#')c++;
                    if(j<W-1&&s[i][j+1]=='#')c++;
                    if(i<H-1&&j<W-1&&s[i+1][j+1]=='#')c++;
                    cout<<c;
                }
            else cout<<'#';
        }
        if(i<H-1)cout<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define r(i, n) for (int i = 0; i < n; i++)
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main() {
  int h, w;
  cin >> h >> w;
  string s[h];
  r(i, h) cin >> s[i];
  r(i, h) r(j, w) if (s[i][j] == '#') {
    int cnt = 0;
    r(k, 4) {
      int y = i + dy[k];
      int x = j + dx[k];
      if (y < 0 || x < 0 || y >= h || x >= w) continue;
      if (s[y][x] == '#') cnt++;
    }
    if (!cnt) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

int main() {
    int n;
    string s;
    cin>>n >>s;
    rep(i,s.length()){
        if(s[i]+n>'Z'){
            int a;
            rep(k,n){
                if(s[i]+k=='Z'){
                    a=n-k-1;
                }
            }
            printf("%c",('A'+a));
        }else{
            printf("%c",(s[i]+n));
        }
    }
}

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

public class Main {
	private static void solve(){
		//Implement solution here.
		int[] n = na(4);		
		List<Integer> l = new ArrayList<Integer>();
		Arrays.stream(n).forEach(v -> l.add(v));
		if(l.indexOf(1) != -1 && l.indexOf(9) != -1 && l.indexOf(7) != -1 && l.indexOf(4) != -1) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 27988
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define vec vector<ll>
#define ms multiset<ll>
#define f(i,x,n) for(int i=x;i<n;i++)
#define int long long
#define mod 998244353
#define endl "\n"
void fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
int32_t main()
{
	fastio();
	int n;
	cin>>n;
	int a[n],b[n];
	f(i,0,n)
	{
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+n);
	int df=0;
	f(i,0,n)
	{
		if(a[i]!=b[i])
			df++;
	}
	if(df<=2)
		cout<<"YES";
	else
		cout<<"NO";
}

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

int n;
int colors[10];
int in[107];

int main()
{
    cin >> n;
    int cnt_red = 0;
    bool flg = false;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &in[i]);
        if (in[i] < 3200) flg = true;
        else cnt_red++;

        if (in[i] >= 1 && in[i] <= 399) colors[1]++;
        if (in[i] >= 400 && in[i] <= 799) colors[2]++;
        if (in[i] >= 800 && in[i] <= 1199) colors[3]++;
        if (in[i] >= 1200 && in[i] <= 1599) colors[4]++;
        if (in[i] >= 1600 && in[i] <= 1999) colors[5]++;
        if (in[i] >= 2000 && in[i] <= 2399) colors[6]++;
        if (in[i] >= 2400 && in[i] <= 2799) colors[7]++;
        if (in[i] >= 2800 && in[i] <= 3199) colors[8]++;
    }

    int cnt = 0;
    if (flg) {
        for (int i = 1; i <= 8; i++) if (colors[i]) cnt++;
        cout << cnt << " ";
    } else {
        cout << 1 << " ";
    }

    //if (cnt + cnt_red >= 8) cout << 8;
    cout << cnt + cnt_red;
}


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

typedef long long LL;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;

const int INF = 1000000007;
const LL INFLL = 1000000000000000007;

#define st first
#define nd second
#define pb push_back
#define _boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

// ***************************** CODE ***************************** //

const int MAX = (1 << 16) + 7;
const int SIZE = 17;

LL tab[SIZE][SIZE];
LL dp[MAX], Cost[MAX];

LL cost(LL mask)
{
    LL res = 0;
    for(int i = 0; i < SIZE; i++)
        if((mask&(1<<i)) == (1<<i))
            for(int j = i+1; j < SIZE; j++)
                if((mask&(1<<j)) == (1<<j))
                    res += tab[i][j];

    return res;
}

int main() {
    _boost;

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

    for(int i = 0; i < MAX; i++)
        Cost[i] = cost(i);

    for(int i = 0; i < MAX; i++)
        for(int j = i; j >= 0; j = ((j-1)&i))
        {
            dp[i] = max(dp[i], (Cost[j] + dp[i^j]));
            if(j == 0) break;
        }

    cout << dp[((1<<n)-1)];
    return 0;
}


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

typedef long long LL;
typedef unsigned long long ULL;

#define debug printf("fuck %d\n", __LINE__);

inline LL read() {
	LL res = 0, bo = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') bo = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		res = (res << 1) + (res << 3) + ch - '0';
		ch = getchar();
	}
	return bo * res;
}

template <typename T>
void read(T &x) {
	x = read();
}

template <typename T, typename... Argv>
void read(T &a, Argv &... argv) {
	read(a);
	read(argv...);
}

const int N = 1e6 + 100, p = 998244353;
int fac[N], inv[N], _n[N], _m[N];

template <typename T>
T mul(T x, T y) {
	return 1LL * x * y % p;
}

template <typename T, typename... Argv>
T mul(T x, Argv... argv) {
	return mul(x, mul(argv...));
}

int ksm(int x, int y) {
	int res = 1;
	for (; y; y >>= 1, x = mul(x, x))
		if (y & 1) res = mul(res, x);
	return res;
}

void init(int n, int m) {
	int M = std::max(n, m);
	fac[0] = _n[0] = _m[0] = 1;
	for (int i = 1; i <= M; ++i) fac[i] = mul(fac[i - 1], i);
	inv[M] = ksm(fac[M], p - 2);
	for (int i = M; i >= 1; --i) inv[i - 1] = mul(inv[i], i);
	for (int i = 1; i <= M; ++i) _n[i] = mul(_n[i - 1], n + 1);
	for (int i = 1; i <= M; ++i) _m[i] = mul(_m[i - 1], m + 1);
}

int C(int n, int m) {
	return m > n || m < 0 ? 0 : mul(fac[n], inv[m], inv[n - m]);
}

int main() {
	int n = read(), m = read(), ans = 0;
	init(n, m);
	for (int i = 0, opt = 1; i <= n; ++i, opt = p - opt) {
		(ans += mul(opt, C(n, i), C(m, i), fac[i], _m[n - i], _n[m - i])) %= p;
	}
	std::cout << ans << std::endl;
	return 0;
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int n;
	cin >> n;
	if(n/100 == n%10)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>


using namespace std;
struct point
{
	int key;
	point *l, *r;
};

int N;
point *nil;
void init()
{
	nil = (point*)malloc(sizeof(point));
	nil->l = nil;
	nil->r = nil;
}

void insert(int k)
{
	point *p;
	p = (point*)malloc(sizeof(point));;
	p->key = k;
	nil->r->l = p;
	p->r = nil->r;
	nil->r = p;
	p->l = nil;

}

point* find(int k)
{
	point *p = nil->r;
	while (p->key != k&&p != nil)
	{
		p = p->r;
	}
	return p;

}

void ddelete(point *p, int k)
{
	if (p->key == k)
	{
		p->r->l = p->l;
		p->l->r = p->r;
		free(p);
	}
	else
		return;

}

void deletefirst()
{
	ddelete(nil->r,nil->r->key);
}

void deletelast()
{
	ddelete(nil->l,nil->l->key);
}

int main()
{
	cin >> N;
	string s;
	int k;
	init();
	for (int i = 0; i < N; i++)
	{
		cin >> s;
		if (s[0] == 'i')
		{
			cin >> k;
			insert(k);
		}
		else if (s[0] == 'd'&&s[6] == 'F')
		{
			deletefirst();
		}
		else if (s[0] == 'd'&&s[6] == 'L')
		{
			deletelast();
		}
		else
		{
			cin >> k;
			ddelete(find(k),k);
		}
	}
	point*p = nil->r;
	while (p->r != nil)
	{
		cout << p->key << ' ';
		p = p->r;
	}
	if (p != nil)
	{
		cout << p->key << endl;
	}

	return 0;

}


Measured memory_bytes: 34356
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));

 
int main() {
	int N;
	cin>>N;
	int k=111;
	fyg(10,1){
		if(N<=k*y){
			ce(k*y)
			break;
		}
	}
	
}

Measured memory_bytes: 256
function Main(input) {

  var input = input.split("\n");
  var arya = input[0].split(" ").map(val => parseInt(val, 10)).slice(0, 2);
  var aryb = input[1].split(" ").map(val => parseInt(val, 10)).slice(0, arya[0]);
  var counter = 1;
  var sum = 0;
  aryb.forEach(function(e, i) {
    sum = sum + aryb[i];
    if(sum > arya[1]){
      return true;
    }
    counter++;
  })

  console.log(counter);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main()
{
  string S;
  cin >> S;

  bool alp[26];
  for (int i = 0; i < 26; i++) {
    alp[i] = false;
  }
  for (int i = 0; i < S.size(); i++) {
    alp[S[i] - 'a'] = true;
  }
  for (int i = 0; i < 26; i++) {
    if (!alp[i]) {
      cout << (char)(i + 'a') << endl;
      return 0;
    }
  }

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

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string a, b, c;
    cin >> a >> b >> c;
    int cha = 'a' - 'A';
    printf("%c%c%c", a[0] - cha, b[0] - cha, c[0] - cha);
}


Measured memory_bytes: 256
import math
N,K=map(int,input().split())
ans=[]
for st in range(1,N+1):
    if st<=K:
        x =math.ceil((math.log(K/st,2)))
    else:
        x=0
    ans.append((1/2)**x)
print(sum(ans)/N)

    
    
    

Measured memory_bytes: 6296
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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;
}

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

ll factrial(ll n){
    if(n == 0) return 1;
    ll p = factrial(n-1)*n%MOD;
    return p;
}

//MOD逆元
ll farmat(ll n,ll p){    
    if(p == 0) return 1;
    else if(p == 1) return n%MOD;
    ll d = farmat(n,p/2);
    if(p%2 == 0){
        return (d*d)%MOD;
    }else{
        return ((n*d)%MOD*d)%MOD;
    }
}

ll conbination(ll n,ll k){
    ll a = factrial(n);
    ll b = factrial(k);
    ll c = factrial(n-k);
    return (a*farmat(b,MOD-2)%MOD*farmat(c,MOD-2))%MOD;
}


void solve() {
   int n;
   cin >> n;
   vector<int> v(n);
   for(int i = 0;i < n;i++){
       cin >> v[i];
   }
   sort(v.begin(),v.end());

   double avg = 0;
   for(int i = 0;i < n;i++){
       if(i == 0){
           avg += (v[0]+v[1])*pow(0.5,n-1);
           i++;
       }else{
           avg += v[i]*pow(0.5,n-i);
       }
   }
   
   cout << avg << endl;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}


Measured memory_bytes: 256
module Main where

import Control.Applicative
import Text.Printf
import Numeric

main :: IO ()
main = do
  { _ <- getLine
  ; xs <- getInts
  ; let mx = maximum xs
  ; let mn = minimum xs
  ; let sm = sum xs
  ; putInts [mn, mx, sm]
  }
  
--

getInts :: IO[Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble x = showFFloat Nothing x ""

getStrings :: IO [String]
getStrings = words <$> getLine

readInt' :: String -> Int
readInt' = read 



Measured memory_bytes: 11360
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<(int)n;i++)
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define int long long
using ll = long long;

const int maxn = 405;
ll arr[maxn];
ll dp[maxn][maxn];
ll sum[maxn];

int32_t main(){
    IOS;
    int n;
    cin>>n;
    rep(i,n)
        cin>>arr[i];
    memset(sum,0,sizeof(sum));
    rep(i,n)
        dp[i][i]=0;
    rep1(i,n+1)
        sum[i]=sum[i-1]+arr[i-1];
    for(int i=1;i<n;i++){
        for(int j=i-1;j>=0;j--){
            dp[j][i]=1e18;
            for(int k=j;k<i;k++){
                dp[j][i]=min(dp[j][i],dp[j][k]+dp[k+1][i]);
            }
            dp[j][i]+=(sum[i+1]-sum[j]);
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;

struct UnionFind {
    vector<int> parent; // parent[root] is the negative of the size.
    UnionFind(int n) : parent(n, -1) { };
    bool unite(int u, int v) { 
        u = root(u); v = root(v);
        if (u == v) return false;
        if (parent[u] > parent[v]) swap(u, v);
        parent[u] += parent[v]; parent[v] = u;
        return true;
    }
    bool find(int u, int v) { return root(u) == root(v); }
    int root(int u) { return parent[u] < 0 ? u : parent[u] = root(parent[u]); }
    int size(int u) { return -parent[root(u)]; }
};

signed main(){
    int n, m, r = 0;
    cin >> n >> m;
    UnionFind uf(n);
    vector<int> p(n);
    for (int& i : p) cin >> i, --i;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        uf.unite(x-1, y-1);
    }
    for(int i=0;i<n;++i){
        if (uf.find(p[i], i)) ++r;
    }
    cout << r;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

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

  ll ans = min(N % K, K - N % K);
  cout << ans << endl;
}


Measured memory_bytes: 3632