akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p = 0;
		int q = 0;
		int[] usedp = new int[n];
		for (int i = 0; i < n; i++) {
			usedp[i] = 0;
		}
		int[] usedq = new int[n];
		for (int i = 0; i < n; i++) {
			usedq[i] = 0;
		}
		for (int i = 0; i < n-1; i++) {
			int a = sc.nextInt();
			int b = 0;
			for (int j = 0; j < a-1; j++) {
				if(usedp[j] == 0) b++;
			}
			p += b*fact(n-i-1);
			usedp[a-1] = 1;
		}
		sc.next();
		for (int i = 0; i < n-1; i++) {
			int a = sc.nextInt();
			int b = 0;
			for (int j = 0; j < a-1; j++) {
				if(usedq[j] == 0) b++;
			}
			q += b*fact(n-i-1);
			usedq[a-1] = 1;
		}
		p++;q++;
		System.out.println(Math.abs(p-q));
		sc.close();
	}
	private static int fact(int n) {
	    int a = 1;
		while(n != 0) {
			a = a*n;
			n = n-1;
		}
		return a;
	}
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<((ll)n);i++)
#define rep1(i,n) for(ll i=1;i<=((ll)n);i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define meow(a) cout<<a<<" meow\n";
typedef pair<long long,long long> pii;
typedef vector<pii> vii;
const ll maxn=200005;
const ll MOD=998244353;
double mypow(ll a,ll b){
	double res=1;
	while(b){
		if(b&1) res=res*a;
		a=a*a;

		b>>=1;
	}
	return res;
}
ll t,n,m;
ll num[100005];
struct aaa
{
    string city;
    ll score;
    ll id;
}rest[105];
bool cmp(aaa a,aaa b)
{
    if(a.city==b.city) return a.score>b.score;
    return a.city<b.city;
}
int main()
{
    IOS;
    //cin>>t;
    while(cin>>n)
    {
     rep(i,n)
     {
         cin>>rest[i].city>>rest[i].score;
         rest[i].id=i+1;
     }
     sort(rest,rest+n,cmp);
     rep(i,n) cout<<rest[i].id<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll N,M;
ll ans;

void judge(ll x){
    if(x*N > M) return;
    ans = max(ans, x);
}

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

    for(ll x = 1; x*x <= M; x++){
        if(M % x == 0){
            judge(x);   
            if(x != M/x) judge(M/x);
        }
    }
    cout << ans << endl;
    return 0;
}


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

AB = [(a, i, 0) for i, a in enumerate(A)] + [(b, i, 1) for i, b in enumerate(B)]
AB.sort()

X = AB[:N]
Y = AB[N:]

if any(x[0] == y[0] for x, y in zip(X, Y)):
    print('No')
    exit()

swapA = []
swapB = []
ans = [-1] * N

for (_, i, sx), (_, j, sy) in zip(X, Y):
    if sx == sy == 0:
        swapA.append((i, j))
    elif sx == sy == 1:
        swapB.append((i, j))
    else:
        if sx == 0:
            ans[i] = B[j]
        else:
            ans[j] = B[i]

for (i, j), (x, y) in zip(swapA, swapB):
    ans[i] = B[x]
    ans[j] = B[y]

    if A[i] == ans[i] or A[j] == ans[j]:
        ans[i], ans[j] = ans[j], ans[i]

print('Yes')
print(*ans)


Measured memory_bytes: 87892
#define REP(i, t, n)  for (int i = t; i < n; i++)
#define ALL(n)        (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <numeric>

using namespace std;

typedef bool               BOOL;
typedef short              WORD;
typedef unsigned short     U_WORD;
typedef long               DWORD;
typedef unsigned long      U_DWORD;
typedef long long          QWORD;
typedef unsigned long long U_QWORD;

#define V_MAX (10000)
#define E_MAX (100000)
#define INF (100000000)

typedef struct edge{
	DWORD dwTo;
	DWORD dwWeight;
	bool operator > (const edge &e) const {
		return dwWeight > e.dwWeight;
	}
} EDGE;

vector <EDGE> vList[V_MAX];
priority_queue<EDGE, vector<EDGE>, greater<EDGE>> que;

QWORD prim()
{
	BOOL bUsed[V_MAX] = {};
	QWORD qwAns = 0;

	while (!que.empty()) {
		EDGE nowEdge = que.top(); que.pop();
		if (bUsed[nowEdge.dwTo]) continue;
		bUsed[nowEdge.dwTo] = true;
		qwAns += nowEdge.dwWeight;

		for (auto iter : vList[nowEdge.dwTo]) {
			que.push(iter);
		}
	}
	return qwAns;
}

void solve_main()
{
	DWORD V, E;
	EDGE tmp;
	cin >> V >> E;

	REP (i, 0, E) {
		DWORD s, t, w;
		EDGE tmpEdge;
		cin >> s >> t >> w;

		tmpEdge.dwTo = t;
		tmpEdge.dwWeight = w;
		vList[s].emplace_back(tmpEdge);

		tmpEdge.dwTo = s;
		vList[t].emplace_back(tmpEdge);
	}

	tmp.dwTo = 0;
	tmp.dwWeight = 0;
	que.push(tmp);

	cout << prim() << endl;
}

int main()
{
#ifdef FOR_IDE
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
#endif

	solve_main();
	return 0;
}



Measured memory_bytes: 12404
n = int(input())
A = [int(i) for i in input().split()]

ans = []
_max = max(A)
_min = min(A)
_min_ptr = A.index(_min)
_max_ptr = A.index(_max)
if _min == _max:
    print(0)
    quit()

if sorted(A) == A:
    print(0)
    quit()

if _max < 0:
    for i in range(n - 1, 0, -1):
        A[i - 1] += A[i]
        ans.append((i, i - 1))

elif _min >= 0:
    for i in range(0, n - 1):
        A[i + 1] += A[i]
        ans.append((i, i + 1))

elif _min < 0 and _max >= 0 and abs(_min) > abs(_max):
    for i in range(n):
        if A[i] >= 0:
            A[i] += _min
            ans.append((_min_ptr, i))
    for i in range(n - 1, 0, -1):
        A[i - 1] += A[i]
        ans.append((i, i - 1))

elif _min < 0 and _max >= 4 and abs(_min) <= abs(_max):
    for i in range(n):
        if A[i] < 0:
            A[i] += _max
            ans.append((_max_ptr, i))
    for i in range(0, n - 1):
        A[i + 1] += A[i]
        ans.append((i, i + 1))


if len(ans) == 0:
    print(0)
    quit()

print(len(ans))
for i, j in ans:
    print(i + 1, j + 1)


Measured memory_bytes: 62672
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int N;
    cin >> N;
    cout << (N + 1) / 2 << endl;
}


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

using namespace std;

#define read(in) freopen("Input.txt","r",stdin)
#define write(out) freopen("Ouput.txt","w",stdout)
#define Pi 2*acos(0.0)

typedef long long int lli;

lli i,j,k,l,m,n,t,a,b,c,d,x,y,p,q,s,r,f,sum=0,total=0;

int main()
{
    //read(in);

    cin>>k>>a>>b;
    sum=0;
    for(i=a ; i<=b ; i++)
    {
    	if(i%k==0)
    	{
    		sum=1;break;
    	}
    }
    if(sum==1)	cout<<"OK\n";
    else cout<<"NG\n";
}

Measured memory_bytes: 3620
#include <iostream>
#define LLI long long int
using namespace std;
LLI gcd(LLI a,LLI b){
    if(a==0||b==0) return a+b;
    else if(a>=b) return gcd(a%b,b);
    else return gcd(a,b%a);
}
int main(){
    LLI n,x; cin>>n>>x;
    cout<<3*(n-gcd(n,x));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N;cin>>N;
	int k = 2;
	while(k*(k-1) < 2*N) k++;
	if(k*(k-1) == 2*N){
		cout<<"Yes"<<endl;
		cout<<k<<endl;
	}else{
		cout<<"No"<<endl;
		return 0;
	}
	vector<vector<int>> dp(k+1, vector<int>(1,k-1));
	rep(i,2,k+1)rep(j,1,i){
        dp[j-1].push_back(j + (i-1)*(i-2)/2);
        dp[i-1].push_back(j + (i-1)*(i-2)/2);
	}pprint(dp,,k,k);
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

main()
{
    int n,c; cin>>n>>c;
    vv v;
    int s,t,a;
    rep(i,n)
    {
        cin>>s>>t>>a;
        v.push_back({s,t,a});
    }

    vi imos(200200,0);
    rep2(t,1,c+1)
    {
        vi cc(200200,0);
        rep(i,n)
        {
            if(v[i][2]==t)
            {
                cc[2*v[i][0]-1]++;
                cc[2*v[i][1]]--;
            }
        }
        rep2(i,1,cc.size())cc[i]+=cc[i-1];
        //each(it,cc)cout<<it;
        //cout<<endl;
        rep(i,cc.size())
        {
            if(cc[i]>0)imos[i]++;
        }
    }

    //each(it,imos)cout<<it;
    //cout<<endl;

    int mx=0;
    each(it,imos)mx=max(mx,it);
    cout<<mx<<endl;

}

Measured memory_bytes: 7856
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
  ll K,A,B;
  cin >> K >> A >> B;

  if(K >= A + 1 && B > A + 2){
    ll ans = 1 + K - ((K-A+1)/2) * 2 + ((K-A+1)/2) * (B-A);
    cout << ans << endl;
  }
  else cout << K + 1 << endl;
}


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

int main(){
int x1, y1, z1, xa, ya, za;
int x2, y2, z2, xb, yb, zb;
int x3, y3, z3, xc, yc, zc;
cin>>x1>>y1>>z1>>xa>>ya>>za;
cin>>x2>>y2>>z2>>xb>>yb>>zb;
cin>>x3>>y3>>z3>>xc>>yc>>zc;
int r1=(xa-x1)*3600+(ya-y1)*60+za-z1;
int h1=r1/3600;
int m1=(r1/60)%60;
int s1=r1%60;
cout<<h1<<" "<<m1<<" "<<s1<<endl;
int r2=(xb-x2)*3600+(yb-y2)*60+zb-z2;
int h2=r2/3600;
int m2=(r2/60)%60;
int s2=r2%60;
cout<<h2<<" "<<m2<<" "<<s2<<endl;
int r3=(xc-x3)*3600+(yc-y3)*60+zc-z3;
int h3=r3/3600;
int m3=(r3/60)%60;
int s3=r3%60;
cout<<h3<<" "<<m3<<" "<<s3<<endl;

return 0;
}


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

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

  if (b=='A') cout << 'T' << endl;
  else if (b=='T') cout << 'A' << endl;
  else if (b=='G') cout << 'C' << endl;
  else cout << 'G' << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
int a[202020];
bool can(int x)
{
    for(int i=0; i<N-1; ++i)
    {
        if((a[N-1-i]>=x) == (a[N-1-i-1]>=x))
            return a[N-1-i]>=x;
        if((a[N-1+i]>=x) == (a[N-1+i+1]>=x))
            return a[N-1+i]>=x;
    }
    return a[0] >= x;
}
int main()
{
    scanf("%d", &N);
    for(int i=0; i<2*N-1; ++i)
        scanf("%d", a+i);
    int lo = 0; //true
    int hi = 2*N; //false
    while(lo+1!=hi)
    {
        int mi = (lo+hi)/2;
        if(can(mi))
            lo = mi;
        else
            hi = mi;
    }
    printf("%d\n", lo);
    return 0;
}

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

const int N = 300000;
#define debug(a) cout << #a << " = " << a << endl;
#define pii pair<int,int>

int ara[1000000];

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d",&n);
	for(int i = 0; i < n;i++)scanf("%d",&ara[i]);

	sort(ara,ara+n);
	double age = ara[0]*1.,now = 0.0;

	for(int i = 1; i < n;i++){
		now = (ara[i]+age)/2.0;
		age  = now;
	}
	cout << age << endl;
	
	return 0;
}

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

using namespace std;

int main(){

	int a,b,table[17][17],row,col,n;

	while(true){
		scanf("%d %d",&a,&b);
		if(a ==b && b == 0)break;

		for(int i=0; i <= 16; i++){
			for(int k=0; k <= 16; k++)table[i][k] = 0;
		}

		table[1][1] = 1;

		scanf("%d",&n);

		for(int i=0; i < n; i++){
			scanf("%d %d",&col,&row);
			table[row][col] = -1;
		}

		for(int i = 1; i <= b; i++){
			for(int k=1; k<= a; k++){
				if(table[i][k] != -1){
					if(table[i][k-1] != -1)table[i][k] += table[i][k-1];
					if(table[i-1][k] != -1)table[i][k] += table[i-1][k];
				}
			}
		}

		printf("%d\n",table[b][a]);
	}

    return 0;
}

Measured memory_bytes: 2576
using System;
using System.Collections.Generic;

namespace MyProgram{
    class AtCoder{
        static void Main(string[] args){
            long[] input = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            long N = input[0];
            long X = input[1];
            long[] x = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            for(var i=0;i<N;i++){
                x[i] += -X;
            }
            long temp = Math.Abs(x[0]);
            for(var i=1;i<N;i++){
                temp = Gcd(Math.Abs(temp),Math.Abs(x[i]));
            }
            Console.WriteLine(temp);
        }
        static long Gcd(long m,long n){
            long temp;
            while(m%n!=0){
                temp =n;
                n = m%n;
                m = temp;
            }
            return n;
        }
    } 
}

Measured memory_bytes: 20960
#include<cstdio>
#include<map>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>

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

using namespace std;

int main(){
	int n;cin>>n;
	cout<<"ABC"<<n<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=998244353;
#define N 432
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N],b[N],dp[N][N][N],sumA,sumB,fac[N],inv[N],ans;
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i){
		fac[i]=1LL*fac[i-1]*i%mod;
	}
	inv[n]=qpow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i){
		inv[i]=1LL*inv[i+1]*(i+1)%mod;
	}
}
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read(),b[i]=read();
	}
	init(400);
	dp[0][0][0]=-1;
	for(int i=1;i<=n;++i){
		sumA+=a[i];
		sumB+=b[i];
		for(int j=0;j<=sumB;++j){
			for(int k=0;k<=sumA;++k){
				dp[i][j][k]=dp[i-1][j][k];
			}
			for(int k=sumA;k>=a[i];--k){
				for(int p=0,tmp=1;p<=min(b[i]-1,j);++p,tmp=1LL*tmp*a[i]%mod){
					dp[i][j][k]=(dp[i][j][k]-1LL*dp[i-1][j-p][k-a[i]]*tmp%mod*inv[p])%mod;
				}
			}
		}
	}
	for(int j=0;j<=sumB;++j){
		for(int k=0;k<=sumA;++k){
			ans=(ans+1LL*sumA*dp[n][j][k]%mod*fac[j]%mod*qpow(qpow(k,j+1),mod-2))%mod;
		}
	}
	printf("%d\n",(ans+mod)%mod);
	return 0;
}



Measured memory_bytes: 140964
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    rep(i,n){
      double a,b,c,d,e,f,g,h;
      cin>>a>>b>>c>>d>>e>>f>>g>>h;
      cout<<a*e-b*f-c*g-d*h<<" "<<a*f+b*e+c*h-d*g<<" "
	  <<a*g-b*h+c*e+d*f<<" "<<a*h+b*g-c*f+d*e<<endl;
    }
  }
}

Measured memory_bytes: 1288
#include <iostream>

#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
using namespace std;

template<class T>
void in(vector<T>& V) {
	for (auto itr = V.begin(); itr != V.end(); itr++)cin >> *itr;
	return;
}

template<class T>
void out(vector<T>& V) {
	for (T& itr : V)cout << itr << endl;
	return;
}

//空vectorを要素数NのsegTreeとしてzで初期化
template<class T>
void segTree_init(vector<T>& vec, int N, T z) {
	int RN = 1;
	while (RN < N)RN *= 2;
	vec.resize(2 * RN, z);
}

//vecをsegTreeとしてn番目をxに
template<class T>
void segTree_set(vector<T>& vec, int n, T x, function<T(T, T)> f,int k  = -1) {
	int RN = (vec.size() + 1) / 2;
	if (k == -1) {
		k = n + RN;
		vec[k] = x;
		segTree_set(vec, n, x, f, k / 2);
	}
	else if(k != 0){
		vec[k] = f(vec[2 * k], vec[2 * k + 1]);
		segTree_set(vec, n, x, f, k / 2);
	}
}

//vecがsegTreeの時の、n番目の要素
template<class T>
T segTree_at(vector<T>& vec, int n) {
	int RN = (vec.size()) / 2;
	return vec[RN + n];
}

//get [a,b]
template<class T>
T segTree_get(vector<T>& vec, int a, int b, function<T(T, T)> f, T e, int k = 1, int l = 0, int r = -1) {
	if (r == -1)r = vec.size() / 2 - 1;
	if (b < l || r < a)return e;
	else if (a <= l && r <= b)return vec[k];
	else return f(
		segTree_get(vec, a, b, f, e, 2 * k, l, (l + r) / 2),
		segTree_get(vec, a, b, f, e, 2 * k + 1, (l + r) / 2 + 1, r)
	);
}

int N, M;
vector<vector<int>> V;
vector<int> Vin;
typedef pair<int, int> seg;
vector<seg> seg0;

int main() {
	cin >> N >> M;
	V.resize(N);
	Vin.resize(N);
	for (int n = 0; n < N + M - 1; n++) {
		int a, b;
		cin >> a >> b;
		V[--a].push_back(--b);
		Vin[b]++;
	}
	segTree_init(seg0, N, seg(-1, INT_MAX));
	function<seg(seg,seg)> lambda = [](seg a, seg b) {
		if (a.second < b.second)return a;
		else return b;
	};
	for (int n = 0; n < N; n++) {
		segTree_set(seg0, n, seg(n, Vin[n]), lambda);
	}
	vector<int> parent(N, -1);
	for (int n = 0; n < N; n++) {
		int cur = segTree_get(seg0, 0, N - 1, lambda, seg(-1, INT_MAX)).first;
		segTree_set(seg0, cur, seg(n, INT_MAX), lambda);
		for (int c : V[cur]) {
			int now = segTree_get(seg0, c, c, lambda, seg(-1, INT_MAX)).second;
			segTree_set(seg0, c, seg(c, now - 1), lambda);
			parent[c] = cur;
		}
	}
	for (int n = 0; n < N; n++)cout << parent[n] + 1 << endl;
	return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, ans = 0;
    cin >> n;
    vll a(n), neg, pos;
    for(i = 0; i < n; i++)
    {
        cin >> a[i];
        if(a[i] > -1)
            pos.pb(a[i]);
        else
            neg.pb(a[i]);
    }
    sort(all(a));
    if(n == 2)
    {
        cout << a[1] - a[0] << endl;
        cout << a[1] << ' ' << a[0] << endl;
        return 0;
    }
    sort(all(neg));
    sort(all(pos));
    vector <pll> b;
    i = neg.size() - 2;
    if(pos.size())
    {
        i = pos.size() - 2;
        if(neg.size())
        {
            while(i >= 0)
            {
                b.pb({neg[neg.size() - 1], pos[i]});
                ans = (neg[neg.size() - 1] -= pos[i]);
                i--;
            }
            for(i = neg.size() - 1; i >= 0; i--)
            {
                b.pb({pos[pos.size() - 1], neg[i]});
                ans = pos[pos.size() - 1] = pos[pos.size() - 1] - neg[i];
            }
        }
        else
        {
            ans = a[0];
            for(i = 1; i < pos.size() - 1; i++)
                b.pb({ans, pos[i]}), ans -= pos[i];
            b.pb({pos[pos.size() - 1], ans});
            ans = pos[pos.size() - 1] - ans;
        }
    }
    else
    {
        ans = neg[neg.size() - 1];
        i = neg.size() - 2;
        while(i >= 0)
        {
            b.pb({ans, neg[i]});
            ans -= neg[i];
            i--;
        }
    }
    cout << ans << endl;
    for(auto x : b)
        cout << x.F << ' ' << x.S << endl;
    return 0;
}

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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << '\n';
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var abx = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = abx[0];
            var b = abx[1];
            var x = abx[2];

            Console.WriteLine(a <= x && a + b >= x ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 28192
use std::io;

fn main() {
    let mut input_txt = String::new();
    io::stdin().read_line(&mut input_txt).expect("Invalid");
    let mut num = 0;
    let mut i = 0;
    match input_txt.trim().parse::<i32>() {
        Ok(i) => num = i,
        Err(_) => println!("Error"),
    }

    while num > 1 {
        num /= 2;
        i += 1;
    }
    num = 1;
    for _ in 0..i {
        num *= 2;
    }
    println!("{:?}", num);
}


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

//累積和の問題
//R-L % D == 0であるから，R%D ≡ L%D = xとおく
//クエリは，（xからRに行くためにかかるコスト）-（xからLに行くためにかかるコスト）に単純化される
//即ち，y = 0~D-1において，xからyまでDずつ移動するのにかかるコストをtableで保持し，table[x][y]をもとにクエリ処理する
//計算量は，(D*(H*W) + Q)で，十分間に合う

int H, W, D;
vector<pair<int, int>> idx;
vector<int> memo;

int f(int x) {
    if (0 < memo[x]) return memo[x];
    if (x < D) return 0;
 
    int y = x - D;
    int cost = abs(idx[x].first - idx[y].first) + abs(idx[x].second - idx[y].second);
    int res = cost + f(y);
    return memo[x] = res;
}

int main() {
    cin >> H >> W >> D;
    idx.resize(H*W);
    memo.resize(H*W);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int a; cin >> a; a--;
            idx[a] = make_pair(i, j);
        }
    }
    int Q; cin >> Q;
    for (int i = 0; i < Q; i++) {
        int L, R; cin >> L >> R; L--; R--;
        int dist = f(R)-f(L);
        cout << dist << endl;
    }
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
typedef long long ll;

#define pll pair<ll,ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 2e5+1;
pll req[N];
ll n;

bool myCompare(const pll &a, 
              const pll &b) 
{ 
    if(a.ff!=b.ff)         
    return (a.ff < b.ff);
    
    return a.snd<b.snd;
}

bool sortbysec(const pll &a, 
              const pll &b) 
{ 
    return a.snd<b.snd;
}


void solve()
{
    cin>>n;
    
    for(int i=0;i<n;i++)
        cin>>req[i].ff>>req[i].snd;    
    
    if(n==1)
    {
            cout<<req[0].snd - req[0].ff+1;
            return;
    }
    
    if(n & 1)
    {
        sort(req,req+n,myCompare);
        
        ll st = req[n/2].ff;

        sort(req,req+n,sortbysec);
        
        ll end = req[n/2].snd;
        
        cout<<end-st+1<<endl;
        return;
    }
    
    sort(req,req+n,myCompare);
    double st = (double(req[n/2].ff + req[(n/2)-1].ff)/2.0);        
    
    sort(req,req+n,sortbysec);
    double end = (double(req[n/2].snd + req[(n/2)-1].snd)/2.0);

    double p = end - st + 1;
    
    ll k = p;
    if(p==k)
    {
        cout<<k+k-1;    
    }
    else
    {
        cout<<k+k;
    }
    
}
 
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
	    int t=1;
//	    cin>>t;
	    while(t--)
	    {
	            solve();
	    }
	    return 0;
}

Measured memory_bytes: 6768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int st = 0;
		int end = 0;
		int x = 0;
		int cnt = 0;

		Scanner sc= new Scanner(System.in);

		st = sc.nextInt();
		end = sc.nextInt();
		x = sc.nextInt();

		for ( int i = st ; i <= end ; i++ ) {
			if ( x % i == 0) {
				cnt++;
			}
				}
		System.out.println( cnt );
		sc.close();
	}
}



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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
    char c; cin>>c;
    if(c=='a' || c=='i' || c=='u' || c=='e' || c =='o')cout<<"vowel"<<endl;
    else cout<<"consonant"<<endl;
	return 0;
}

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

int main(int argc, const char * argv[]) {
    int n,m;
    int T=0,H=0;
    
    char t[101];
    char h[101];
    
    scanf("%d",&n);
    
    for(m=0;m<n;m++){
        scanf("%s %s",t,h);
        
        if (strcmp(t,h)==0){
            T++;
            H++;
        }else if(strcmp(t,h)>0){
            T+=3;
        }else if(strcmp(t,h)<0){
            H+=3;
        }
        
        
    }
    
    printf("%d %d\n",T,H);
    
    return 0;
}


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

int main() {
	int A,B,M,AB,ans;
    cin>>A>>B>>M;
    vector<int> a(A);
    vector<int> b(B);
    vector<int> x(M);
    vector<int> y(M);
    vector<int> c(M);
    vector<int> c_val(M);
    for(int i=0;i<A;i++)cin>>a.at(i);
    for(int i=0;i<B;i++)cin>>b.at(i);
    for (int i = 0; i < M ; i++)cin>>x.at(i)>>y.at(i)>>c.at(i);

    AB= *min_element(a.begin(),a.end())+*min_element(b.begin(),b.end());
    
    for (int i = 0; i < M; i++)
    {
            c_val.at(i) = a.at(x.at(i)-1)+ b.at(y.at(i)-1)-c.at(i);
    }
    
    ans=min(AB,*min_element(c_val.begin(),c_val.end()));

	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 2688
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        m: usize,
        es: [(Usize1, Usize1); m],
    }

    let mut uf = UnionFind::new(n);
    for (u, v) in es {
        uf.unite(u, v);
    }

    let mut res = 0;
    for i in 0..n {
        res = res.max(uf.count(i));
    }

    println!("{}", res);
}

pub trait DisjointSet {
    fn new(len: usize) -> Self;
    fn representative(&mut self, id: usize) -> usize;
    fn equivalent(&mut self, lhs: usize, rhs: usize) -> bool {
        self.representative(lhs) == self.representative(rhs)
    }
    fn unite(&mut self, lhs: usize, rhs: usize) -> bool;
    fn count(&mut self, id: usize) -> usize;
}

struct UnionFind {
    par: Vec<usize>,
    size: Vec<usize>,
}

impl DisjointSet for UnionFind {
    fn new(len: usize) -> Self {
        Self {
            par: (0..len).collect(),
            size: vec![1; len],
        }
    }
    fn representative(&mut self, id: usize) -> usize {
        if self.par[id] != id {
            self.par[id] = self.representative(self.par[id])
        }
        self.par[id]
    }
    fn unite(&mut self, lhs: usize, rhs: usize) -> bool {
        let mut lhs = self.representative(lhs);
        let mut rhs = self.representative(rhs);
        if lhs == rhs {
            return false;
        }
        if self.size[lhs] > self.size[rhs] {
            std::mem::swap(&mut lhs, &mut rhs);
        }
        self.size[rhs] += self.size[lhs];
        self.par[lhs] = rhs;
        true
    }
    fn count(&mut self, id: usize) -> usize {
        let id = self.representative(id);
        self.size[id]
    }
}


Measured memory_bytes: 10844
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

struct vec
{
    double x, y;
    vec (const double& x0 = 0, const double& y0 = 0) : x(x0), y(y0) {}
    vec operator + (const vec& t) const {return vec(x+t.x, y+t.y);}
    vec operator - (const vec& t) const {return vec(x-t.x, y-t.y);}
    vec operator * (const double& t) const {return vec(x*t, y*t);}
    vec operator / (const double& t) const {return vec(x/t, y/t);}
    const double len2 () const {return x*x + y*y;}
    const double len () const {return sqrt(len2());}
    vec norm() const {return *this/len();}
    vec rotate_90_c () {return vec(y, -x);}
};

double dot(const vec& a, const vec& b) {return a.x*b.x + a.y*b.y;}
double crs(const vec& a, const vec& b) {return a.x*b.y - a.y*b.x;}

vec lin_lin_int(const vec& p0, const vec& v0, const vec& p1, const vec& v1)
{
    double t = crs(p1-p0, v1) / crs(v0, v1);
    return p0 + v0 * t;
}

vec circle(const vec& a, const vec& b, const vec& c)
{
    return lin_lin_int((a+b)/2, (b-a).rotate_90_c(), (a+c)/2, (c-a).rotate_90_c());
}

int n;
vec pot[100005];

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%lf%lf", &pot[i].x, &pot[i].y);
    random_shuffle(pot+1, pot+n+1);
    vec o;
    double r2 = 0;
    for(int i=1; i<=n; i++)
    {
        if((pot[i]-o).len2() > r2)
        {
            o = pot[i], r2 = 0;
            for(int j=1; j<i; j++)
            {
                if((pot[j]-o).len2() > r2)
                {
                    o = (pot[i]+pot[j])/2, r2 = (pot[j]-o).len2();
                    for(int k=1; k<j; k++)
                    {
                        if((pot[k]-o).len2() > r2)
                        {
                            o = circle(pot[i], pot[j], pot[k]), r2 = (pot[k]-o).len2();
                        }
                    }
                }
            }
        }
    }
    printf("%.10lf\n", sqrt(r2));
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
#define lg 18
//<<fixed << setprecision(9)
vector<pii> G[space][3];
int dis[space][3];
int main()
{
    int n,i,j,t;
    boost;
    int m;
    cin>>n>>m;
    int u,v;
    rep(i,0,m)
    {
        cin>>u>>v;
        G[u][0].pb({v,1});
        G[u][1].pb({v,2});
        G[u][2].pb({v,0});
    }
    int S,T;
    cin>>S>>T;
    rep(i,1,n+1)
    {
        dis[i][0]=dis[i][1]=dis[i][2]=-1;
    }
    dis[S][0]=0;

    queue<pii>q;
    q.push({S,0});
    pii w;
    while(!q.empty())
    {
        w=q.front();
        q.pop();
        for(auto z:G[w.F][w.S])
        {
            if(dis[z.F][z.S]==-1)
            {
                dis[z.F][z.S]=1+dis[w.F][w.S];
                q.push(z);
            }
        }

    }
    if(dis[T][0]==-1) cout<<"-1";
    else cout<<dis[T][0]/3;

    return 0;
}



Measured memory_bytes: 17792
import string
S = input()
T = input()
L = len(S)

s_hash = {}
t_hash = {}
for i in string.ascii_lowercase:
  s_hash[i] = -1
  t_hash[i] = -1

s = []
t = []
for i in range(L):
  if s_hash[S[i]] == -1:
    s_hash[S[i]] = i
  if t_hash[T[i]] == -1:
    t_hash[T[i]] = i
  s.append(s_hash[S[i]])
  t.append(t_hash[T[i]])

#print(s)
#print(t)
if s == t:
  print('Yes')
else:
  print('No')


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

int main() {
  int A,B,C,D;
  cin >> A>>B>>C>>D;

  if (A-C/B*D>0 ||C%B==0) {
    cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
}
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

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

int main()
{
	int a,b;
	cin >> a >> b;
	cout << a*b - a - b + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#gets.to_i
#gets.split.map &:to_i
x, k, d = gets.split.map &:to_i
x = x.abs
if x >= k*d
	p x-k*d
	exit
end
k = (k-x/d) % 2
x %= d
if k == 1
	x = (x-d).abs
end
p x

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

using namespace std;

int main()
{
  int Q;
  cin >> Q;
  while(Q--){
    int N;
    cin >> N;
    for(int i = 0; i <= 1000000; i++){
      if(N / 10 == 0){
	cout << i << endl;
	break;
      } else if(i == 1000000){
	cout << -1 << endl;
	break;
      }
      int fore, back;
      int next = -1;
      for(int j = 10; j <= N; j *= 10){
	fore = N / j;
	back = N % j;
	next = max(next, fore*back);
      }
      N = next;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

  static int[] FACTORIALS = {1, 1, 2, 6, 24, 120, 720, 5040};

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int max = sc.nextInt();
    int sum1 = permutation(max, sc);
    int sum2 = permutation(max, sc);
    System.out.println(Math.abs(sum1 - sum2));
  }

  private static int permutation(int max, Scanner sc) {
    int ret = 0;
    boolean[] used = new boolean[max + 1];
    for (int i = max; i > 0; i--) {
      int value = sc.nextInt();
      int num = 0;
      for (int j = 1; j <= max; j++) {
        if (value == j) {
          used[j] = true;
          break;
        } else if (used[j]) {
          // do nothing
          continue;
        } else {
          num++;
        }
      }
      ret += FACTORIALS[i - 1] * num;
    }
    return ret;
  }
}


Measured memory_bytes: 23764
import java.util.*;
class Main {
  public static void main(String[] args){
    System.out.println(Mountain());
  }
  public static int Mountain() {
    Scanner scanner = new Scanner(System.in);
    int x = scanner.nextInt();
    int maxNum = 0;
    int result = 0;

    for(int i = 0; i < x; i++){
      int num =  scanner.nextInt();
      maxNum = Math.max(maxNum, num); 
      if(maxNum == num) result++;
    }
    return result;
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()

int main() {
	int N, nw = 1;
	cin >> N;
	int A, B;
	ll ans = 0;
	for (int i = 0;i < N;i++) {
		cin >> A;
		if (i == 0) {
			ans += A - 1;
			continue;
		}
		if (A == nw + 1) {
			nw++;
		}
		else if (A > nw) {
			B = A - nw;
			ans += B / (nw + 1);
			B %= (nw + 1);
			if (B > 1)ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] t = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			t[i] = sc.nextInt();
			sum += t[i];
		}
		
		int m = sc.nextInt();
		for (int i = 0; i < m; i++) {
			int p = sc.nextInt();
			p--;
			int x = sc.nextInt();
			
			System.out.println(sum - t[p] + x);
		}
		
		sc.close();
	}
	
}




Measured memory_bytes: 27736
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}



const int N = 2003;
int r, c, arr[N][N], same_conseq[N][N][2];

int getMaxArea(const vector<int> &hist, int n)
{
    // Create an empty stack. The stack holds indexes of hist[] array
    // The bars stored in stack are always in increasing order of their
    // heights.
    stack<int> s;
 
    int max_area = 0; // Initalize max area
    int tp;  // To store top of stack
    int area_with_top; // To store area with top bar as the smallest bar
 
    // Run through all bars of given histogram
    int i = 0;
    while (i < n)
    {
        // If this bar is higher than the bar on top stack, push it to stack
        if (s.empty() || hist[s.top()] <= hist[i])
            s.push(i++);
 
        // If this bar is lower than top of stack, then calculate area of rectangle 
        // with stack top as the smallest (or minimum height) bar. 'i' is 
        // 'right index' for the top and element before top in stack is 'left index'
        else
        {
            tp = s.top();  // store the top index
            s.pop();  // pop the top
 
            // Calculate the area with hist[tp] stack as smallest bar
            area_with_top = hist[tp] * (s.empty() ? i+1 : i - s.top() - 1+1);
 
            // update max area, if needed
            if (max_area < area_with_top)
                max_area = area_with_top;
        }
    }
 
    // Now pop the remaining bars from stack and calculate area with every
    // popped bar as the smallest bar
    while (s.empty() == false)
    {
        tp = s.top();
        s.pop();
        area_with_top = hist[tp] * (s.empty() ? i+1 : i - s.top() - 1+1);
 
        if (max_area < area_with_top)
            max_area = area_with_top;
    }
 
    return max_area;
}


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

    cin>>r>>c;
    char str[N];
    for(int i=1;i<=r;i++){
    	cin>>(str+1);
    	for(int j=1;j<=c;j++)
    		arr[i][j] = (str[j] == '.' ? 0 : 1);
    }


    for(int j=c;j>=1;j--)
    	same_conseq[1][j][0] = same_conseq[1][j][1] = c-j+1;
    for(int i=2;i<=r;i++)
    	for(int j=c;j>=1;j--){
    		same_conseq[i][j][0] = (arr[i][j] == arr[i-1][j]) * (1 + same_conseq[i][j+1][0]);
    		same_conseq[i][j][1] = (arr[i][j] != arr[i-1][j]) * (1 + same_conseq[i][j+1][1]);
    	}

    int ans = max(r, c);
    for(int j=1;j<=c;j++){
    	vector<int> vals;
    	// vals.pb(c-j+1);
    	for(int i=2;i<=r;i++)
    		if(arr[i][j] == arr[i-1][j])
    			vals.pb(same_conseq[i][j][0]);
    		else
    			vals.pb(same_conseq[i][j][1]);

    	ans = max(ans, getMaxArea(vals, r));
    }

    cout<<ans;
    return 0;
}







 




Measured memory_bytes: 47360
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 13;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    map<string, int> cnt;
    string s;
    while (n--){
        cin >> s;
        cnt[s]++;
    }
    vector<pair<int, string> >v;
    for (auto p : cnt){
        v.pb({-p.y, p.x});
    }
    sort(all(v));
    int mx = v[0].x;
    for (auto p : v){
        if (mx != p.x){
            break;
        }
        cout << p.y << endl;
    }
    return 0;
}


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

IL int gi(){
	int data = 0 , m = 1; char ch = 0;
	while(ch!='-' && (ch<'0'||ch>'9')) ch = getchar();
	if(ch == '-'){m = 0 ; ch = getchar() ; }
	while(ch >= '0' && ch <= '9'){data = (data<<1) + (data<<3) + (ch^48) ; ch = getchar(); }
	return (m) ? data : -data ; 
}

int n,lst,lst_n,oo,fa[1000005] ; char s[1000000] ;

int main() {
	scanf("%s" , s + 1) ;
	n = strlen(s + 1) ; 
	if(s[1] == '0' || s[n] == '1') return puts("-1") , 0 ;
	for(int i = 1; i <= n-1; i ++)
		if(s[i] != s[(n-i)]) return puts("-1") , 0 ; 
	++ oo ;
	lst = 1 ;
	int rt = oo ; 
	for(int i = 2; i <= n / 2; i ++) {
		if(s[i] == '0') continue ;
		++ oo ;
		fa[rt] = oo ;
	    rt = oo ;
		for(int j = lst + 1; j <= i-1; j++) {
			fa[++oo] = rt ;
		}
		lst = i ; 
	}
	//cout << n << ": oo = "<<oo<<endl ;
	fa[rt] = oo + 1 ; 
	int root = ++ oo ;
	for(int j = oo + 1; j <= n; j ++) fa[j] = root ;
	for(int i = 1; i <= n; i ++)
		if(i != root) printf("%d %d\n" , i , fa[i]) ;
	return 0 ; 
}


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

void row (long long int n,long long int num[]){
    long long int save;
    for (int a=0;a<n;a++){
        for (int b=a+1;b<n;b++){
            if(num[a]>num[b]){
                save=num[a];
                num[a]=num[b];
                num[b]=save;
            }
        }
    }
}

int main(){
    long long int n , sum;
    cin>>n;
    long long int num[n];
    for (int i=0;i<n;i++){
        cin>>num[i];
    }

    for (int i=0;i<n;i++){
        sum+=num[i];
        
    }
    
    row(n,num);
    
    cout<<num[0]<<" "<<num[n-1]<<" "<<sum<<endl;
    return 0;
    
}


Measured memory_bytes: 3172
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {
    
    
    int x,a;
    cin>>x>>a;
    if(x<a)fin(0);
    else fin(10);
}


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

int main(){
	int A,B,C,X,Y;
	cin >> A >> B >> C >> X >> Y;

	int p = min(X,Y);

	int ans = min(2*C*p+A*(X-p)+B*(Y-p), A*X+B*Y);
	ans = min(ans, 2*C*max(X,Y));

	cout << ans << endl;


}

Measured memory_bytes: 256
main = do
  x <- readLn
  print (if dp x then 1 else 0)

dp x = (head . (foldl f [])) [0..x]
  where
    f xs x | x == 0 = True : xs
           | x < 100 = False : xs
           | x <= 105 = True : xs
           | otherwise = if (foldr (||) False (map (\x -> xs!!(x-1)) [100..105])) then True:xs else False:xs

Measured memory_bytes: 15740
N = int(input())
info = []
for _ in range(N):
    A = int(input())
    tmp = []
    for _ in range(A):
        x, y = map(int,input().split())
        x -= 1
        tmp.append([x, y])
    info.append(tmp)

ans = 0

for S in range(1<<N):
    cnt = 0
    flag = True
    for j in range(N):
        if (S >> j) & 1 == 0:
            continue
        cnt += 1
        res = info[j]
        for x, y in res:
            if (S >> x) & 1 != y:
                flag = False
                break
    if flag:
        ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 43500
#include <stdio.h>

int main(int argc, char *args[])
{
	int r,c;
	int i;
	int a,b;

	scanf("%d %d", &r, &c);

	int elem[r][c];
	int sum_r[r];
	int sum_c[c];
	int sum_all = 0;

	for( i=0; i<r; i++ ) {
		sum_r[i] = 0;
	}
	for( i=0; i<c; i++ ) {
		sum_c[i] = 0;
	}

	for( a=0; a<r; a++ ) {
		for( b=0; b<c; b++ ) {
			scanf("%d", &elem[a][b]);
			sum_r[a] += elem[a][b];
			sum_c[b] += elem[a][b];
			sum_all += elem[a][b];
		}
	}

	for( a=0; a<r; a++ ) {
		for( b=0; b<c; b++ ) {
			printf("%d ", elem[a][b]);
		}
		printf("%d\n", sum_r[a]);
	}

	for( b=0; b<c; b++ ) {
		printf("%d ", sum_c[b]);
	}

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

	return 0;

}

Measured memory_bytes: 640