akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
b1=b[0]
res="No"
for i in range(n-m+1):
    if b1 in a[i]:
        x=a[i].index(b1)
        match=1
        for j in range(1,m):
            if a[i+j][x:x+m]!=b[j]:
                match=0
        if match:
            res="Yes"
print(res)

Measured memory_bytes: 62112
n, m = map(int, input().split())
r = {i + 1 : 0 for i in range(n)}
for i in range(m):
    a, b = map(int, input().split())
    r[a] += 1
    r[b] += 1
for i in range(n):
    print(r[i + 1])

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

int main(void)
{
	int h, m, i;
	char str[201], buf1[201], buf2[201];

	while (1) {
		scanf("%s", str);
		sprintf(buf1, "%s", str);
		sprintf(buf2, "%s", str);

		if (strcmp(str, "-") == 0)
			break;

		scanf("%d", &m);

		for (i = 0; i < m; i++) {
			scanf("%d", &h);

			sprintf(buf1, "%s", &str[h]);
			strncpy(buf2, str, h);
			buf2[h] = '\0';
			sprintf(str, "%s%s", buf1, buf2);
		}

		printf("%s\n", str);
	}

	return 0;
}

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

int main() {
   int n,k;
   cin >> n >> k;
   rep(i,2*n-1){
       cout<<k-n+1+i<<" ";
   }
}

Measured memory_bytes: 256
import math
#2つの整数を入力
n, d = map(int, input().split()) 

num = []
for i in range(n):
    s = input().rstrip().split(' ')
    s_num = [int(j) for j in s]
    num.append(s_num)

ans = 0

for i in range(n):
    temp = (num[i][0])**2 + (num[i][1])**2
    temp = math.sqrt(temp)
    if temp <= d:
        ans += 1

print(ans)

Measured memory_bytes: 42260
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 998244353;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	long long a, b, c;
	cin >> a >> b >> c;
	if(c - a - b <= 0){
		cout << "No\n";
		return 0;
	}
	if(4 * a * b < (c - a - b) * (c - a - b)){
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }

ll gcd(ll m, ll n)
{
	ll r;

	do {
		r = m % n;
		m = n;
		n = r;
	} while (r != 0);

	return m;
}

ll lcm( ll m, ll n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

int main() {
  int N;
  scanf("%d", &N);
  ll t[N];
  ll ans = 1LL;
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &t[i]);
    ans = lcm(ans,t[i]);
  }

  cout << ans << endl;



}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,a[100];
	int i,x=0,y=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0){
			x++;
			if(a[i]%3==0||a[i]%5==0){
				y++;
			}
		}
	}
	if(x==y){
		printf("APPROVED\n");
	}
	else{
		printf("DENIED\n");
	}
	return 0;
}


Measured memory_bytes: 1648
N = int(input())
*A, = map(int,input().split())

if N%3:
    ans = True
    for a in A:
        if a:ans=False;break
else:
    B = set(A)
    l = len(B)
    ans = True
    if l>3:
        ans = False
    elif l==1:
        for b in B:
            if b:ans=False;break
    else:
        if l==3:
            a,b,c = B
            l,m,n = (A.count(x) for x in (a,b,c))
        if l==2:
            a,b = B
            l,m = (A.count(x) for x in (a,b))
            if l>=m:
                c=a
                n=l//2
                l-=n
            else:
                c=b
                n=m//2
                m-=n
        ans = ans and (l==m==n==N//3) and (a^b==c)
        
if ans:print("Yes")
else:print("No")

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, a[1010], k;
void solve(){
	cin >> n >> k;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		cnt += a[i];
	}
	
	vector<int> v;
	for(int i = 1; i*i <= cnt; i++){
		if(cnt % i == 0){
			v.push_back(cnt/i);
			v.push_back(i);
		}
	}
	
	int ans = 0;
	for(int i = 0; i < v.size(); i++){
		int cc = 0;
		priority_queue<int> q;
		for(int j = 0; j < n; j++){
			cc += a[j] % v[i];
			q.push(a[j]%v[i]);
		}
		int t = cc/v[i];
		for(int j = 0; j < t; j++){
			cc -= q.top();
			q.pop();
		}
		if(cc <= k){
			chmax(ans, v[i]);
		}
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
import sys
import math
import bisect
import re

def solve():
    s = input()
    t = input()
    s = ''.join(sorted(s))
    t = ''.join(sorted(t, reverse=True))
    return s < t

def main():
    if solve():
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <numeric>
#include <iomanip>
#include <climits>
#include <cstring>
#include <cmath>

using namespace std;

#define int long long
#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 rrep(i, n) for (int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for (int i=(int)(n);i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=(int)(r)-1;i>=l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using vpii=vector<pii>;
using ll=long long;

constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}
template<typename T>bool chmin(T&a,T b){return a>b?(a=b,1):0;}
template<typename T>bool chmax(int&a,int b){return a<b?(a=b,1):0;}
int read(){int a;scanf("%lld",&a);return a;}

const double pi = acos(-1);
constexpr int inf = 3*TEN(18) + 10;

signed main()
{
	int ans =-1;
	rep(i, 5) {
		int a; cin >> a;
		if (a==0)ans=i+1; 
	}
	cout<<ans<<endl;
}




Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
int main(){
 string s1,s2;
 cin >> s1 >> s2;
 for(int i = 0; i < s1.length(); i++){

  bool flag = false;

  for(int j = 0; j < s2.length();j++){
   if(s1[(i + j)%s1.length()] != s2[j]){
   flag = true;
   break;
   }
  }
  if(flag == false){
   cout << "Yes" << endl; return 0;
  }
 }
 cout << "No" << endl;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <ll, ll> P;

const ll MOD=1000000007;
ll X,Y,Z;
ll A[100000], B[100000], C[100000];
P p[100000];
ll u[100000], d[100000];
bool comp(const P &x,const P &y){
    return x.fr-x.sc>y.fr-y.sc;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>X>>Y>>Z;
    ll ans=0;
    rep(i,0,X+Y+Z){
        cin>>A[i]>>B[i]>>C[i];
        ans+=C[i];
        A[i]-=C[i];
        B[i]-=C[i];
        p[i]=P(A[i],B[i]);
    }
    sort(p,p+X+Y+Z,comp);
    ll ret=0;
    priority_queue<ll, vector<ll>, greater<ll>> q;
    rep(i,0,X){
        ret+=p[i].fr;
        q.push(p[i].fr);
    }
    u[X-1]=ret;
    rep(i,X,X+Y+Z){
        ret+=p[i].fr;
        q.push(p[i].fr);
        ret-=q.top();
        q.pop();
        u[i]=ret;
    }
    ret=0;
    priority_queue<ll, vector<ll>, greater<ll>> r;
    rer(i,X+Y+Z,X+Z){
        ret+=p[i].sc;
        r.push(p[i].sc);
    }
    d[X+Z]=ret;
    rer(i,X+Z,0){
        ret+=p[i].sc;
        r.push(p[i].sc);
        ret-=r.top();
        r.pop();
        d[i]=ret;
    }
    ll res=-1e17;
    rep(i,X-1,X+Z){
        res=max(res,u[i]+d[i+1]);
    }
    cout <<ans+res<<"\n";
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int a,b; cin>>a>>b;
  if (b%a==0) out(a+b);
  out(b-a);
  

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return kai(n - 1)*n;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int n, m, a, b, cnt1, cnt2;
signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a;
		cnt1 += a;
	}
	for (int i = 0; i < m; i++) {
		cin >> b;
		cnt2 += b;
	}
	cout << cnt1 * cnt2 << endl;
	endre;
}


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

int main(){
	
	int h, m, s, x;
	
	while(cin >> h >> m >> s){
		if(h == -1) break;
		x = 120 * 60 - (3600 * h + 60 * m + s);
		h = x / 3600;
		m = (x - 3600 * h) / 60;
		s = x - 3600 * h - 60 * m;
		
		printf("%02d:%02d:%02d\n", h, m, s);
		
		h = 3 * x / 3600;
		m = (3 * x - 3600 * h) / 60;
		s = 3 * x - 3600 * h - 60 * m;
		
		printf("%02d:%02d:%02d\n", h, m, s);
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using s32 = int32_t;
using u32 = uint32_t;
using u64 = uint64_t;

int main() {
	double A, B;
	cin >> A >> B;
	
	double ansA = floor(A * 100 / 8);
	double ansB = floor(B * 100 / 10);
	
	u32 minA = min(ansA, ansB);
	u32 maxA = max(ansA, ansB);
	
	//cout << minA << " " << maxA << endl;
	
	for(u32 i=1; i<=10000; i++) {
		double i8 = floor((double)i * 1.08);
		double i10 = floor((double)i * 1.1);
		if(i8 == i + A && i10 == i + B) {
			cout << i;
			return 0;
		}
	}	
	
	cout << -1;
	return 0;
}

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

int main() {
  vector<int> a(3);
  ;
  cin >> a.at(0) >> a.at(1) >> a.at(2);

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

  int ans = 0;
  ans += (a.at(2) - a.at(1)) / 2;
  a.at(1) += 2 * ((a.at(2) - a.at(1)) / 2);
  ans += (a.at(2) - a.at(0)) / 2;
  a.at(0) += 2 * ((a.at(2) - a.at(0)) / 2);
  if (a.at(0) == a.at(1) && a.at(1) == a.at(2)) {
    cout << ans;
  } else if (a.at(0) == a.at(1)) {
    cout << ans + 1;
  } else {
    cout << ans + 2;
  }
}


Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a=br.readLine().split(" ");
        int n=Integer.parseInt(a[0]);
        int m=Integer.parseInt(a[1]);
        int l=Integer.parseInt(a[2]);
        int[][] A=new int[n][m];
        int[][] B=new int[m][l];
        for(int i=0;i<n;i++){
        	a=br.readLine().split(" ");
        	for(int j=0;j<m;j++){
        		A[i][j]=Integer.parseInt(a[j]);
        	}
        }
        for(int i=0;i<m;i++){
        	a=br.readLine().split(" ");
        	for(int j=0;j<l;j++){
        		B[i][j]=Integer.parseInt(a[j]);
        	}
        }
        for(int nc=0;nc<n;nc++){
    		String s="";
        	for(int lc=0;lc<l;lc++){
        		long b=0;
            	for(int mc=0;mc<m;mc++){
            		b+=A[nc][mc]*B[mc][lc];
            	}
            	s+=b+" ";
        	}
        	System.out.println(s.substring(0,s.length()-1));
        }
	}
}

Measured memory_bytes: 57636
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;++i)
#define repi(i,n) for(ll i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define slf(n) scanf("%lf", &n);
typedef long long ll;
typedef double lf;
static const ll max_n = 100010;
static const ll mod = 1000000007;
static const ll max_value = 100000000000100;

ll N, M;


void Main(){
    // bool is_ok = true;
    // printf("------------- V=%lld---------\n", V);
    ll N;
    sll(N);
    ll left = N % 10;
    if(left == 3){
        cout << "bon" <<endl;
    }else if(left == 0 || left == 1 || left == 6 || left==8){
        cout << "pon" <<endl;
    }else{
        cout << "hon" <<endl;
    }


    // cout<<fixed<<setprecision(10)<<num<<endl;
    // cout << num << endl;

}

int main(){
    Main();

    return 0;

}

Measured memory_bytes: 3172
import numpy as np
N, M, X = map(int, input().split())

#print(N,M,X)

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

#A = []
#for i in range(M):
#    A.append(input()) # ３度の入力に対して、1, 2, 3 と入力。
#print(A) # ['1', '2', '3']


A = [int(i) for i in input().split()]


S = np.zeros((N + 1))
for i in range(M):
    S[A[i]] = 1

#print(S)

ans1 = 0
ans2 = 0

for i in range(0 , X + 1):
    if S[i] == 1:
        ans1+=1

for i in range(X , N + 1):
    if S[i] == 1:
        ans2+=1
#print(ans1,ans2)
print(min(ans1,ans2))

Measured memory_bytes: 12408
import java.util.Arrays;
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    double n=sc.nextLong(),a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong(),e=sc.nextLong(),min=n,res=0;
    double[] in=new double[6];
    in[0]=n;
    in[1]=a;
    in[2]=b;
    in[3]=c;
    in[4]=d;
    in[5]=e;
    Arrays.sort(in);
    System.out.println((long)Math.ceil(n/in[0])+4);
  }
}


Measured memory_bytes: 21972
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
#define __int64 long long

struct Mat{
	public:
	vector<vector<ll> >t;
	int g;//行
	int r;//列
	Mat(int a,int b){
		t.resize(a);
		for(int i=0;i<a;i++)t[i].resize(b);
		g=a;
		r=b;
	}

	Mat kakeru(Mat a,Mat b){
		if(a.r!=b.g)return Mat(0,0);//異常終了
		
		Mat ret(a.g,b.r);

		for(int i=0;i<a.g;i++){
			for(int j=0;j<b.r;j++){
				ll tmp=0;
				for(int k=0;k<a.r;k++){
					tmp=tmp+a.t[i][k]*b.t[k][j];

				}
					//cout<<i<<" "<<j<<endl;
				ret.t[i][j]=tmp;
			}
		}
		return ret;
	}

};



int n,m,l;

int main(){
	cin>>n>>m>>l;
	Mat a(n,m),b(m,l);	
	rep(i,n){
		rep(j,m)cin>>a.t[i][j];
	}
	
	rep(i,m){
		rep(j,l)cin>>b.t[i][j];
	}
	Mat c(n,l);

	c=c.kakeru(a,b);
	
	rep(i,n){
		rep(j,l){
			cout<<c.t[i][j];
			if(j<l-1)cout<<" ";
		}	
		cout<<endl;
	}
	
	return 0;
}



Measured memory_bytes: 3484
int preorder[40],inorder[40];
void recover(int fp,int lp,int fi,int li){
    int root=fi;
    for(;root<li;root++)if(preorder[fp]==inorder[root])break;
    if(fi<root)recover(fp+1,fp+(root-fi)+1,fi,root);
    if(root<li-1)recover(fp+(root-fi)+1,lp,root+1,li);
    printf(inorder[root]==preorder[0]?"%d\n":"%d ",inorder[root]);
}
main(){
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",preorder+i);
    for(i=0;i<n;i++)scanf("%d",inorder+i);
    recover(0,n,0,n);
    return 0;
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ll l,r,mn=1e9;
    cin>>l>>r;
    if(r-l>2020)
    {
        cout<<0<<endl;
        return 0;
    }
    l%=2019;
    r%=2019;
    for(ll i=l;i<=r;i++)
    {
        for(ll j=i+1;j<=r;j++)
        {
            mn=min((i*j)%2019,mn);
        }
    }
    cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repf(i, from, to) for(int i = (from); i < (to); ++i)
#define repr(i, from, to) for(int i = (from); i >= (to); --i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << setprecision(16);
    string s; cin >> s;
    string ans;
    for(char c: s){
        if(c == '0') ans += '0';
        else if(c == '1') ans += '1';
        else{
            if(ans == "") continue;
            else{
                ans = ans.substr(0,SIZE(ans)-1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int
#define Vec vector
template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }


class UnionFind{
private:
	vector<int> parent;
	vector<int> mem;
	int compo;
	int N;
public:
	UnionFind(int n_){
		Initialize(n_);
	}
	
	void Initialize(int n_){
		N=n_;
		parent.resize(N);
		mem.resize(N);
		for(int i=0;i<N;i++){
			parent[i]=i;
			mem[i]=1;
		}
		compo = N;
	}
	
	int Parent(int a){
		if(parent[a] == a)return a;
		return parent[a] = Parent(parent[a]);
	}
	
	bool IsUnited(int a, int b){
		return Parent(a) == Parent(b);
	}
	
	void Unite(int a, int b){
		a = Parent(a); b = Parent(b);
		if(a == b) return;
		parent[a] = b;
		mem[b] += mem[a];
		compo -= 1;
	}
	
	bool IsRoot(int x){
		return x == parent[x];
	}
	int MemCnt(int x){
		return mem[Parent(x)];
	}
	
	int Compo(){
		return compo;
	}
	
};


int main(){
	
	int N,M;
	cin >> N >> M;
	Vec<int> A(M),B(M);
	for(int i=0;i<M;i++) cin >> A[i] >> B[i];
	for(int i=0;i<M;i++) { A[i]--; B[i]--; }
	
	Vec<ll> ans(M);
	ll tot = (ll) N * (N - 1) / 2;
	
	UnionFind UF(N);
	for(int i=M-1;i>=0;i--){
		if(UF.IsUnited(A[i], B[i])){
			ans[i] = tot;
			continue;
		}
		ans[i] = tot;
		ll ca = UF.MemCnt(A[i]);
		ll cb = UF.MemCnt(B[i]);
		tot += ca * (ca - 1) / 2;
		tot += cb * (cb - 1) / 2;
		tot -= (ca + cb) * (ca + cb - 1) / 2;
		UF.Unite(A[i], B[i]);
	}
	
	for(int i=0;i<M;i++) printf("%lld\n",ans[i]);
	
	
	return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;
class Main{


	static char[][] map;

	static long[][] c;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(Math.min(a*n, b));
		
		

		
	}


	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   end- otherpair.end;
	}







	static int find(int index,int current,int[] students,int ans,int[][] memo){
		if(current == index){
			return 1;
		}

		if(memo[current][index] != 0){
			return memo[current][index];
		}

		memo[current][index] = find(index, students[current]-1, students, ans+1, memo)+1;

		return memo[current][index];
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}






Measured memory_bytes: 21972
#include <iostream>
#define	OPEN 0
using namespace std;
int main() {
#if OPEN
	freopen("input.txt", "r", stdin);
#endif
	int R, G, B, N;
	//int count = 0;
	while (cin >> R >> G >> B >> N) {
		long long count = 0;
		for (int r = 0; r <= 3000; r++) {
			if (N - r*R < 0)break;
			for (int g = 0; g <= 3000; g++) {
				if (N - r* R - g*G < 0)break;
				if ((N - r* R - g*G) % B == 0)count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// Copyright (C) 2017 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>
#include <string.h>
#include <random>
#include <numeric>
#include <tuple>


using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::min;
using std::abs;
using std::max;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

#define pb push_back
#define eb emplace_back


int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    // code here.
    int n = input<int>();
    for (int a = 1; a <= 3500; ++a)
        for (int b = a; b <= 3500; ++b) {
            int64_t top = 4 * int64_t(a) * b - int64_t(n) * (a + b);
            int64_t btm = int64_t(n) * a * int64_t(b);

            if (top >= 1 and btm % top == 0) {
                cout << a << " " << b << " " << btm / top << "\n";
                return 0;
            }   
        }

    assert(false);
    
    return 0;
}


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

using namespace std;
char a[200005];
char b[200005];
int main()
{
    cin>>a;
    cin>>b;
    int num=0;
    for (int i=0;i<strlen(a);i++)
    {
        if (a[i]!=b[i])
            num++;
    }
    cout<<num<<endl;
}


Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,w;
  cin >> n >> w;
  vector<int> wei(n);
  vector<int> pri(n);
  for(int i=0;i<n;i++)
    cin >> wei.at(i) >> pri.at(i);
  vector<vector<long long>> dp(n+1,vector<long long>(w+1,0));
  for(int i=1;i<n+1;i++){
    for(int j=1;j<w+1;j++){
      if(j>=wei.at(i-1)){
        dp.at(i).at(j)=
          max(dp.at(i-1).at(j-wei.at(i-1))
            +pri.at(i-1),dp.at(i-1).at(j));
      }
      else
        dp.at(i).at(j)=dp.at(i-1).at(j);
    }
  }
  cout << dp.at(n).at(w) << endl;
  /*for(int i=0;i<n+1;i++){
    for(int j=0;j<w+1;j++){
      cout << dp.at(i).at(j) << " ";
    }
    cout << endl;
  }*/
}

Measured memory_bytes: 80256
from heapq import *
n = int(input())
A = list(map(int,input().split()))
leftq = []
rightq = []
heapify(leftq)
heapify(rightq)
left = [0]*(3*n)
right= [0]*(3*n)

leftsum = 0
for i,a in enumerate(A):
    if i < n:
        leftsum += a
        heappush(leftq,a)
    else:
        if leftq[0] < a:
            leftsum += a
            leftsum -= heappushpop(leftq,a)
    if i >= n-1:
        left[i] = leftsum
rightsum = 0
for j,a in enumerate(A[::-1]):
    i = 3*n - 1 - j
    if i > 2*n-1:
        rightsum += a
        heappush(rightq,-a)
    else:
        if rightq[0] < -a:
            rightsum += a
            rightsum += heappushpop(rightq,-a)
    if i <= 2*n:
        right[i] = rightsum
ans = -float('inf')
for i in range(n-1,2*n):
    ans = max(ans,left[i]-right[i+1])
print(ans)


Measured memory_bytes: 121360
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	S := sc.NextLine()
	x, y := sc.NextInt(), sc.NextInt()

	types := make([][]int, 2)
	types[0] = make([]int, 0)
	types[1] = make([]int, 0)

	mode := 0
	count := 0
	for i := 0; i < len(S); i++ {
		if S[i] == 'T' {
			if count > 0 || i == 0 {
				types[mode] = append(types[mode], count)
			}
			mode = 1 - mode
			count = 0
		} else {
			count++
		}
	}
	if count > 0 || len(S) == 1 {
		types[mode] = append(types[mode], count)
	}
	//fmt.Printf("%+v\n", types)
	geta := 8000

	for p := 0; p < 2; p++ {
		dp := make([]bool, 16000+1)

		v := x
		if p == 1 {
			v = y
		}

		if len(types[p]) == 0 {
			if v != 0 {
				fmt.Println("No")
				return
			}
		} else {
			start := 0
			if p == 0 {
				dp[types[p][0]+geta] = true
				start = 1
			} else {
				dp[geta] = true
			}

			for i := start; i < len(types[p]); i++ {
				ndp := make([]bool, 16000+1)

				for l := 0; l < len(dp); l++ {
					if !dp[l] {
						continue
					}

					if l+types[p][i] < len(dp) {
						ndp[l+types[p][i]] = true
					}
					if l-types[p][i] >= 0 {
						ndp[l-types[p][i]] = true
					}
					dp[l] = false
				}
				dp = ndp
			}

			if !dp[v+geta] {
				fmt.Println("No")
				return
			}
		}

	}
	fmt.Println("Yes")
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 7424
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long DP[101][100000];
void Calc(){
	long N = rei();
	int K = rei();
	vector<long> C;
	{
		int i;
		int sq;
		for(i=1;i*i<=N;i++){
			C.push_back(1);
		}
		sq = i-1;
		if(N/sq-sq != 0){
			C.push_back(N/sq-sq);
		}
		for(i=sq;i>=2;i--){
			C.push_back(N/(i-1)-N/i);
		}
	}
	DP[0][0] = 1;
	for(int i=1;i<=K;i++){
		long sum = 0;
		for(int j=C.size()-1;j>=0;j--){
			sum += DP[i-1][C.size()-1-j];
			sum %= mod;
			DP[i][j] = sum * C[j] % mod;
		}
	}
	long ans = 0;
	for(int i=0;i<C.size();i++){
		ans += DP[K][i];
	}
	ans %= mod;
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 78200
n, m = map(int, input().split())
students = []
for _ in range(n):
    students.append(list(map(int, input().split())))

points = []
for i in range(m):
    c, d = map(int, input().split())
    points.append([c, d, i + 1])


for s in students:
    tmp_d, tmp_i = 10 ** 18, -1
    for p in points:
        dif = abs(s[0] - p[0]) + abs(s[1] - p[1])
        if dif < tmp_d:
            tmp_d = dif
            tmp_i = p[2]
    print(tmp_i)


Measured memory_bytes: 3064
n = gets.to_i
d = Array.new(n+1){Array.new(n+1)}

1.upto(n) do |i|
    a = gets.to_i
    a.times do 
        x,y = gets.split.map(&:to_i)
        d[i][x] = y
    end
end

ans = 0

(2**n).times do |i|
    x = i.to_s(2)
    y = x.size
    x = "0" * (n-y+1) + x
    s = 0
    c = 0

    1.upto(n) do |k|
        next if x[k] == "0"
        c += 1

        1.upto(n) do |j|
            next if d[k][j] == nil
            if d[k][j] != x[j].to_i 
                s = 1
                break
            end
        end
        break if s == 1
    end
    next if s == 1
    ans = c if ans < c
end

puts ans


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

struct data{
    int p, d;
    data(int person, int dist) : p(person), d(dist) {}
    bool operator<(const data other) const{
        return d < other.d;
    }
};

int main(){
    while(1){
        int n;
        cin >> n;

        if(n == 0)  break;

        vector<data> score;
        int p, d1, d2;
        for(int i = 0; i < n; i++){
            cin >> p >> d1 >> d2;
            score.push_back(data(p, d1+d2));
        }

        sort(score.begin(), score.end());
        reverse(score.begin(), score.end());

        cout << score[0].p << " " << score[0].d << endl;
    }
    return 0;
}


Measured memory_bytes: 3208
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	double a = sc.nextDouble();
    	double b = sc.nextDouble();
    	double c = sc.nextDouble();
    	sc.close();
    	BigDecimal aa = sqrt(new BigDecimal(a), 50);
    	BigDecimal bb = sqrt(new BigDecimal(b), 50);
    	BigDecimal cc = sqrt(new BigDecimal(c), 50);
    	boolean ans = false;
    	if(aa.add(bb).compareTo(cc) == -1){
    		ans = true;
    	}
    	System.out.println(ans?"Yes":"No");
    }

	public static BigDecimal sqrt(BigDecimal a, int scale){
        BigDecimal x = new BigDecimal(
                Math.sqrt(a.doubleValue()), MathContext.DECIMAL64);
        if(scale < 17) return x;

        BigDecimal b2 = new BigDecimal(2);
        for(int tempScale = 16; tempScale < scale; tempScale *= 2){
            x = x.subtract(
                    x.multiply(x).subtract(a).divide(
                    x.multiply(b2), scale, BigDecimal.ROUND_HALF_EVEN));
        }
        return x;
    }
}

Measured memory_bytes: 23380
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

template<typename T>
struct SegmentTree {
    int N;
    vector<T> node;

    SegmentTree() = default;
    SegmentTree(vector<T> &v) {init(v);}

    void init(vector<T> &v) {
        N = 1;
        int sz = v.size();
        while (N < sz) N *= 2;
        node.assign(2*N,0);
        for (int i = 0; i < sz; i++) node[i+N] = v[i];
        for (int i = N-1; i >= 1; i--) node[i] = node[i<<1|0] + node[i<<1|1];
    }

    void update(int x, T val) { // (0-indexed)
        x += N;
        node[x] += val;
        while (x > 1) {
            x >>= 1;
            node[x] = node[x<<1|0] + node[x<<1|1];
        }
    }

    T get(int a, int b, int k = 1, int l = 0, int r = -1) { // [a, b) (0-indexed)
        if (r < 0) r = N;

        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return node[k];
        T vl = get(a, b, k<<1|0, l, (l+r)/2);
        T vr = get(a, b, k<<1|1, (l+r)/2, r);
        return vl + vr;
    }

    T operator[](int x) {return node[x+N];} 
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    string S; cin >> S;
    vector<int> B(N);
    vector<SegmentTree<int>> A(26,B);
    rep(i,N) {
        int k = S[i] - 'a';
        A[k].update(i,1);
    }
    int Q; cin >> Q;
    while (Q--) {
        int com; cin >> com;
        if (com==1) {
            int num;
            char c;
            cin >> num >> c;
            --num;
            int l = S[num] - 'a';
            int k = c - 'a';
            A[l].update(num,-1);
            A[k].update(num,1);
            S[num] = c;
        } else {
            int l,r; cin >> l >> r;
            --l;
            int ans = 0;
            rep(i,26) {
                if (A[i].get(l,r)) ans++;
            }
            cout << ans << ln;
        }
    }
}

Measured memory_bytes: 113564
//***Faithless is he that says farewell when the road darkens***

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[1000002];
ll b[1000002];
int main(){
	sync
	ll n,cn=0;
	cin>>n;
	forn(i,n){
		ll c;
		cin>>c;
		b[c]++;
	}
	for(ll i=1;i<=1e6;i++){
		if(b[i]==0) continue;
		for(ll j=i;j<=1e6;j+=i){
			if(((i==j)&&(b[j]==1))||((i!=j)&&(b[j]==0))) continue; 
			a[j]=1;
		}
	}
	for1(i,1e6){
		if((a[i]==0)&&(b[i]==1)) cn++;
	}
	cout<<cn;
}


Measured memory_bytes: 19280
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 3003
#define MOD 1000000007

int n;
int h, w;
int r[N], c[N];
vector<int> g[N];

#define L 100007
ll fact[2*L], rfact[2*L];

ll fast_pow(ll x, ll k) {
  ll r = 1;
  while(k) {
    if(k & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    k >>= 1;
  }
  return r;
}

ll memo[N];
ll dfs(int v) {
  if(memo[v] != -1) {
    return memo[v];
  }
  ll res = fact[(h - r[v]) + (w - c[v])];
  res = res * rfact[h - r[v]] % MOD;
  res = res * rfact[w - c[v]] % MOD;
  repe(w, g[v]) {
    int dr = r[w] - r[v], dc = c[w] - c[v];
    ll x = fact[dr+dc];
    x = (x * rfact[dr]) % MOD;
    x = (x * rfact[dc]) % MOD;
    res = (res + MOD - (x * dfs(w)) % MOD) % MOD;
  }
  return memo[v] = res;
}

int main() {
  cin >> h >> w >> n;
  rep(i, n) cin >> r[i] >> c[i];
  rep(i, n) {
    rep(j, n) {
      if(i != j && r[i] <= r[j] && c[i] <= c[j]) {
        g[i].push_back(j);
      }
    }
  }
  rep(i, n) memo[i] = -1;
  fact[0] = rfact[0] = 1;
  rep(i, h+w) {
    fact[i+1] = fact[i] * (i+1) % MOD;
    rfact[i+1] = fast_pow(fact[i+1], MOD-2);
  }
  ll ans = fact[h+w-2];
  ans = (ans * rfact[h-1]) % MOD;
  ans = (ans * rfact[w-1]) % MOD;
  rep(i, n) {
    ll x = fact[r[i]+c[i]-2];
    x = (x * rfact[r[i]-1]) % MOD;
    x = (x * rfact[c[i]-1]) % MOD;
    ans = (ans + MOD - (x * dfs(i)) % MOD) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 28032
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s;
  VI cnt;
  rep(i,3) cnt.PB(0);
  rep(i,s.size()){
    if(s[i]=='a') cnt[0]++;
    else if(s[i]=='b') cnt[1]++;
    else cnt[2]++;
  }
  sort(RALL(cnt));
  if(cnt[0]-cnt[2]>=2) return cout<<"NO"<<endl, 0;
  cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e,f;
  cin >> a>>b>>c;
  if(a-b>=0)
    d=a-b;
  else
    d=b-a;
  if(a-c>=0)
    e=a-c;
  else
    e=c-a;
  if(b-c>=0)
    f=b-c;
  else
    f=c-b;
  int max1=max(max(d,e),max(e,f));
  cout<<d+e+f-max1<<endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
    int a,b; cin >> a >> b;
    string s; cin >> s;

    int count = 0;
    for (char i : s) if(i == '-')count++;
    if(count == 1 && s[a] == '-')print("Yes");
    else print("No");
}

Measured memory_bytes: 256
w,h,n=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]

mydic={}
mydic[1]=[0];mydic[2]=[w];mydic[3]=[0];mydic[4]=[h]
for i in range(n) :
  elem=li[i]
  x=elem[0];y=elem[1];a=elem[2]
  l=mydic[a]
  if a==1 or a==2:
    l.append(x)
  if a==3 or a==4:
    l.append(y)
x1=max(mydic[1])
x2=min(mydic[2])
y3=max(mydic[3])
y4=min(mydic[4])
#print(mydic)
if (x2-x1)<=0 or (y4-y3)<=0 :
  print(0)
else :
  print((x2-x1)*(y4-y3))



Measured memory_bytes: 3188
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<map>
using namespace std;
#define MAX_N 100001
#define INF 2147483647
#define REP(i,COUNT) for(int i=0;i<(int)(COUNT);i++)
struct edge{
  int to, cost;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;
typedef long long int ll;
typedef pair<ll, ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
vector<int> dist;
vector<int> prever;
void dijkstra(int n,int s){
  dist = vector<int>(n,INF);
  prever = vector<int>(n,-1);
  dist[s] = 0;
  priority_queue<P, vector<P> , greater<P> > que;
  que.push(P(0,s));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    int d = p.first;
    REP(i,graph[v].size()){
      edge e = graph[v][i];
      if(dist[e.to] > dist[v] + e.cost){
        dist[e.to] = dist[v] + e.cost;
        que.push(P(dist[e.to],e.to));
      }

    }

  }
}

int main()
{
  int N,M,a,b,c;
  cin >> N >> M;
  graph = vector<vector<edge> >(N+1,vector<edge>(0));
  vector<P> ver(0);
  map<P,bool> mp;
  map<P,ll> mps; 
  REP(i,M){
    cin >> a >> b >> c;
    a--;b--;
    graph[a].push_back((edge){b,c});
    graph[b].push_back((edge){a,c});
    ver.push_back(P(a,b));
    mps[P(a,b)]  = c;
  }
  for(int i=0;i<N;i++){
    dijkstra(N,i);
    for(int j=0;j<ver.size();j++){
      for(int k=0;k<N;k++){
        if(dist[ver[j].second] == dist[ver[j].first] + mps[P(ver[j].first,ver[j].second)])
          mp[P(ver[j].first,ver[j].second)] = true;
      }
    }
  }
  int res=0;
  REP(i,ver.size()){
    if(!mp[P(ver[i].first,ver[i].second)])
      res++;
  }
  
  
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 384
//2018-1-19
//miaomiao
//
#include <bits/stdc++.h>
using namespace std;

#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)

#define N (50+5)
const int P = 1e9 + 7;

inline void Get(int &a, int b){
	a += b; if(a >= P) a -= P;
}

int a[N<<1], f[N][N<<1][N<<1];

int main(){
	int n, m;

	scanf("%d", &n); m = (n<<1) - 1;

	For(i, 1, m) scanf("%d", &a[i]);
	sort(a+1, a+m+1, greater<int>());
	
	int me, l, r, nj, nk;
	f[1][1][1] = 1;

	For(i, 1, n-1){
		l = a[n-i] != a[n-i+1]; r = a[n+i] != a[n+i-1];

		For(j, 1, m) For(k, 1, j) if(f[i][j][k]){
			me = f[i][j][k];
			nj = j+l+r, nk = k+l;

			For(t, 1, nk-1) Get(f[i+1][nj-(nk-t-1)][t], me);
			Get(f[i+1][nj][nk], me);
			For(t, nk+1, nj) Get(f[i+1][nj-(t-nk-1)][nk+1], me);
		}
	}

	int ans = 0;
	For(i, 1, m) For(j, 1, i) Get(ans, f[n][i][j]);
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
vector<string>arr;
typedef long long ll;
ll solve(ll a){
	if(a==1){
		return 0;
	}
	return a*(a-1)/2;
	
}

int main(){
	string s;
	ll n,num=1,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s;
		sort(s.begin(),s.end());
		arr.push_back(s);
	}
	sort(arr.begin(),arr.end());
	s=arr[0];
//	cout<<endl;
//	for(int i=0;i<n;i++){
//		cout<<arr[i]<<endl;
//	}
	for(int i=1;i<n;i++){
		if(s==arr[i]){
			num++;
		}
		else{
			ans+=(solve(num));
			//cout<<num<<endl;
			s=arr[i];
			num=1;
		}
	}
	ans+=(solve(num));
	cout<<ans<<endl;

	
	return 0;
}

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

int main(void){
  string s;
  string yaki = "YAKI";
  bool ok = true;
  cin >> s;
  if( s.size() > 3){
    for(int i = 0; i < 4; ++i){
      ok &= s[i] == yaki[i];
    }
  }else{
    ok = false;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
import functools
from math import gcd


def lcm2(x, y):
    return x * y // gcd(x, y)


def lcm(x):
    return functools.reduce(lcm2, x)


def resolve(in_):
    N, M = map(int, next(in_).split())
    A = tuple(map(lambda x: int(x) // 2, next(in_).split()))

    a0 = A[0]
    x = 0
    while True:
        a0, b = divmod(a0, 2)
        if b:
            break
        x += 1
    x = 2 ** x
    for a in A[1:]:
        d, m = divmod(a, x)
        if m != 0 or not d % 2:
            return 0 

    l = lcm(A)
    l2 = l + l

    answer = len(range(l, M + 1, l2))

    return answer


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 91544