akhauriyash/Code-Regression huggingface dataset:
program answer
  implicit none

  integer :: A, B, C
  read(*,*) A, B, C

  if(A<C.and.C<B) then
     write(*,*) 'Yes'
  else if(B<C.and.C<A) then
     write(*,*) 'Yes'
  else
     write(*,*) 'No'
  end if

  stop
 end program answer


Measured memory_bytes: 2632
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N, A;
    cin >> N >> A;
    cout << (N * N - A) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stack>
#include<string.h>
using namespace std;
int a[105][105];
int tim=0;
int first[105],last[105];
int zhuangtai[105];
int us;
int nex[105];
int findnext(int k)
{
    for(int i=nex[k];i<us;i++)
    {
        nex[k]=i+1;
        if(a[k][i]) return i;
    }
    return -1;
}
void visit(int k)
{
    for(int i=0;i<us;i++)
    {
        nex[i]=0;
    }
    stack<int > s;
    s.push(k);
    first[k]=++tim;
    zhuangtai[k]=1;
    while(!s.empty())
    {
        int n=s.top();
        int ne=findnext(n);
        if(ne!=-1)
        {
            if(zhuangtai[ne]==0){
                zhuangtai[ne]=1;
                first[ne]=++tim;
                s.push(ne);
            }
        }else{
            s.pop();
            zhuangtai[n]=2;
            last[n]=++tim;
        }
    }
}
void dfs()
{
    for(int i=0;i<us;i++)
    {
        zhuangtai[i]=0;
        nex[i]=0;
    }
    for(int i=0;i<us;i++)
    {
        if(zhuangtai[i]==0) visit(i);
    }
    for(int i=0;i<us;i++)
    {
        printf("%d %d %d\n",i+1,first[i],last[i]);
    }
}
int main()
{
    scanf("%d",&us);
    for(int i=0;i<us;i++)
    {
        int p,x;
        scanf("%d%d",&p,&x);
        p--;
        for(int j=0;j<x;j++)
        {
            int y;
            scanf("%d",&y);
            y--;
            a[p][y]=1;
        }
    }
    dfs();
    return 0;
}

Measured memory_bytes: 2756
#include <bits/stdc++.h>
using namespace std;
int main(){
 	vector<int> vec;
 	int n;
  	scanf("%d",&n);
  	//cout<<n<<"\n";
  	int x;
  	for(int i=0;i<n;++i){
    	scanf("%d",&x);
      	vec.push_back(x);
    }
  	vector<int> ans;
  	while(n){
    	int id=n-1;
      	while(id>-1){
        	if(vec[id]==id+1) break;
            --id;
        }
      if(id==-1){
        puts("-1");
        return 0;
      }
      ans.push_back(id+1);
      vec.erase(vec.begin()+id);
      --n;
    }

  reverse(ans.begin(),ans.end());
  for(auto xx:ans) printf("%d\n",xx);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<unordered_map>
#include<vector>

using namespace std;

#define rept(i,a,b) for(int i=a; i<b; i++)
#define rep(i,n) for(int i=0; i<n; i++)
#define ll long long

int main(){
	string S, T;
	string ans;
	cin>>S>>T;
	int R[26];
	int R_p[26];
	bool flag = true;
	rep(i, 26) {
		R[i] = R_p[i] = -1;
	}
	rep(i, S.length()) {
		if (R[S[i] - 'a'] >= 0) {
			if (R[S[i] - 'a'] != T[i] - 'a') {
				flag = false;
			}
		}
		if (R_p[T[i] - 'a'] >= 0) {
			if (R_p[T[i] - 'a'] != S[i] - 'a') {
				flag = false;
			}
		}
		if (R[S[i] - 'a'] < 0) {
			R[S[i] - 'a'] = T[i] - 'a';
		}
		if (R_p[T[i] - 'a'] < 0) {
			R_p[T[i] - 'a'] = S[i] - 'a';
		}
	}
	ans = flag ? "Yes" : "No";
	cout<<ans<<endl;

	return 0;
}


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

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

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

    long long a;
    long long b;
    while (cin >> a >> b)
    {
        long long c = a * b;
        if (c % 2 == 0)
        {
            cout << "Even" << endl;
        }
        else
        {
            cout << "Odd" << endl;
        }

        return 0;
    }
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    ll sum = 0;
    while (A > 0 && K > 0)
    {
        sum++;
        K--;
        A--;
    }
    while (B > 0 && K > 0)
    {
        K--;
        B--;
    }
    while (K > 0 && C > 0)
    {
        sum--;
        K--;
        C--;
    }
    cout << sum << endl;
    return (0);
}

Measured memory_bytes: 3632
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long 
#define ll long long 
#define pre(a,b) cout<<fixed<<setprecision(a)<<b<<"\n";//a for precision b for answer
#define mp make_pair
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define pb push_back 
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b) 
#define forn(n) for(ll i=0;i<n;i++) 
#define ff first
#define ss second
#define MAX 1e18;
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
const int MOD = 1e9 + 7;
const int v1=1e5+5;
#define pi 3.141592653589793238
const int N=3e5+5;
 
 
//cout<<"Case #"<<p<<": "<<;
//file input  freopen("input.txt","r",stdin); 
//file output freopen("output.txt","w",stdout);
 
using namespace std;

int32_t main()
{
  IOS
  ll n=0;
  cin>>n;
  cout<<n+n*n+n*n*n<<"\n";
}





Measured memory_bytes: 3580
//b.c -- Buffet
#include<stdio.h>

int main(void){
    int n,manzoku=0;
    scanf("%d",&n);
    int a[100],b[100],c[100];
    for(int i=0;i<n;++i){
        scanf("%d",&a[i]);
    }
    for(int j=0;j<n;++j){
        scanf("%d",&b[j]);
    }
    for(int k=0;k<n-1;++k){
        scanf("%d",&c[k]);
    }
    for(int l=0;l<n;++l){
        int m = a[l];
        if(l!=0 && a[l] - a[l-1] == 1){
            manzoku += b[m-1];
            manzoku += c[a[l-1]-1];
        }else{
            manzoku += b[m-1];
        }
    }


    printf("%d",manzoku);
    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
A, B = map(int,input().split())

temp = B - A

if B == 1:
    print(0)
elif temp <= 0:
    print(1)
else:
    total = temp/(A-1)
    if temp%(A-1)==0:
        print(int(total)+1)
    else:
        print(int(total)+2)


Measured memory_bytes: 3060
import math

N = int(input())

def main():
    curr = math.ceil(math.sqrt(N))
    while True:
        m, r = divmod(N, curr)
        if r == 0:
            ans = [m, N // m]
            break
        curr -= 1
    print(sum(ans) - 2)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll N, ans=0;
    string S;
    char c='0';

    cin >> N;
    cin >> S;

    REP(i,N){
        if(S[i] != c){
            ans++;
            c=S[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
	int d, e;
	while (cin >> d >> e) {
		if (d == 0 && e == 0) {
			break;
		}
		double MIN = abs(d-e);
		for (int i = 0; i <= d; i++) {
			MIN = min(MIN, abs(sqrt(i*i+(d-i)*(d-i))-e));
		}
		printf("%.10f\n", MIN);
	}
	return 0;
}

Measured memory_bytes: 1196
#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()
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n){
        cin>>v[i];
    }
    int ans =0;
    for(int i=1;i<n-1;i++){
        if(v[i-1]<v[i]&&v[i]<v[i+1]){
            ans++;
        }
        else if(v[i-1]>v[i]&&v[i]>v[i+1]){
            ans++;
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    k = I()
    print(a[k-1])
    return

if __name__=='__main__':
    Main()

Measured memory_bytes: 27124
import sys
n, m = map(int, input().split())
mod = 10**9 + 7

if abs(n-m) > 1:
    print(0)
    sys.exit(0)

ans = 1
for i in range(2,n+1):
    ans = (ans * i) % mod
for i in range(2,m+1):
    ans = (ans * i) % mod
if n == m:
    ans = (ans * 2) % mod
print(ans)


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
from collections import deque 
n = int(input())
es=[[] for i in range(n)]
for i in range(n - 1):
   a, b = map(int, input().split())
   es[a - 1].append(b - 1)
   es[b - 1].append(a - 1)
INF = 1 << 32
d = [INF] * n
d[0] = 0
q = deque([0])
while q:
    v = q.popleft()
    for e in es[v]:
        if d[e] == INF:
            d[e] = d[v] + 1
            q.append(e)
d2 = [INF] * n
q.append(n - 1)
d2[n - 1] = 0
while q:
    v = q.popleft()
    for e in es[v]:
        if d2[e] == INF and d2[v] + 1 < d[e]:
            d2[e] = d2[v] + 1
            q.append(e)

print("Fennec" if 2 * sum(1 for i in d2 if i < INF) < n else "Snuke")

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	int cnt = 0;
	rep(i, n) if (a[i] < 0) cnt++;

	ll ans = 0;
	if (cnt % 2 == 0) {
		rep(i, n) ans += abs(a[i]);
	}
	else {
		priority_queue<int> q;
		rep(i, n) q.push(abs(a[i]));
		rep(i, n - 1) {
			ans += q.top();
			q.pop();
		}
		ans -= q.top();
	}
	cout << ans << endl;

}

Measured memory_bytes: 1276
n,t=map(int,input().split())
tici=[]
for i in range(n):
    ci,ti=map(int,input().split())
    if(ti<=t):
        tici.append([ci,ti])
if(len(tici)==0):
    print('TLE')
else:
    tici.sort()
    print(tici[0][0])


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

ll mod = 1e9 + 7;

// a^n mod を計算する(二分累乗法)
ll modpow(ll a, ll n){
    ll res = 1;
    while(n > 0){
        if(n&1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} modを計算する
ll modinv(ll a){
    return modpow(a,mod-2);
}

// com mod を計算する
ll com(ll x,ll y){
    ll ans = 1;
    for(int i = 1;i <= x;++i){
        ans = ans * i % mod;
    }
    for(int i = 1;i <= y;++i){
        ans = ans * modinv(i) % mod;
    }
    for(int i = 1;i <= x-y;++i){
        ans = ans * modinv(i) % mod;
    }
    return ans;
}

int main(){
    int X,Y; cin >> X >> Y;
    if((2*Y-X)%3 == 0 && 2*Y-X>= 0 && (2*X-Y)%3 == 0 && 2*X-Y>= 0){
        int a = (2*Y-X)/3;
        int b = (X+Y)/3;
        cout << com(b,a) << endl;
    }else cout << 0 << endl;
}

Measured memory_bytes: 256
using System;

public class Test
{
	public static void Main()
	{
		// your code goes here
		string[] s = Console.ReadLine().Split(' ');
		double[] n = new double[s.Length];
		for(int i = 0; i < s.Length; i++) {
			n[i] = double.Parse(s[i]);
		}
		
		var r = n[0];
		double area = r * r * Math.PI;
		double circumference = 2 * r * Math.PI;

		Console.WriteLine(string.Format("{0:f6} {1:f6}", area, circumference));
	}
}

Measured memory_bytes: 9324
/** e==m*pow(c,2) **/
#include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define LL long long
#define int long long
#define pii pair<int, int>
#define SQR(n) (n*n)
#define pb push_back
#define endl '\n'
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define INF 100000000000
#define PI (acos(0.0) * 2.0)
#define time_start clock_t tStart = clock()
#define time_end (double)(clock() - tStart)/CLOCKS_PER_SEC
#define maxn 100009
//#pragma GCC diagnostic warning "-std=c++11"
#define check(n, i) (int)(bool(!((n)&(1<<(i)))))
#define set(n, i) (((n)|(1<<(i))))
#define mod 1000000007
 
#define dbg(a) cout << #a << " = " << a << endl;

 
void faster(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
 
int lcm(int a, int b)
{
    return (a*b) / __gcd(a, b);
} 
 

int i, j, ara[105], n, k;
int dp[105][100005];

int cumsum(int v, int st, int en)
{
    if(!st) return dp[v][en];
    return dp[v][en]-dp[v][st-1];
}

int fak(int x, int y)
{
    if(y>ara[x]) return 0;
    int sum=cumsum(x-1, max(0LL, y-(ara[x]-ara[x-1])), y);
    //cout<<x<<' '<<y<<' '<<ara[x]<<" ST "<<max(0LL, y-(ara[x]-ara[x-1]))<<' '<<"EN "<<y<<' '<<sum<<endl;
    return sum;
}


int32_t main()
{
    #ifdef ONPC
      freopen("in.txt", "r", stdin);
      freopen("out.txt", "w", stdout);
    #endif
    faster();
    cin >> n >> k;
    for(i=0;i<=100;i++) dp[i][0]=1;
    for(i=1;i<=n;i++) cin>>ara[i];
    for(j=1;j<=k;j++) dp[0][j] += dp[0][j-1];
    for(i=1;i<=n;i++)
    {
        ara[i]+=ara[i-1];
        for(j=1;j<=k;j++)
        {
            dp[i][j] = fak(i, j)%mod;
        }
        //cout<<i<<endl<<flush;
        //for(j=1;j<=k;j++) cout<<dp[i][j]<<' ';
            //cout<<endl;
        for(j=1;j<=k;j++) dp[i][j] += dp[i][j-1], dp[i][j]%=mod;
    }
    if(DEBUG)
    {
        for(i=0;i<=n;i++)
        {
            for(j=0;j<=k;j++) cout<<dp[i][j]<<' ';
            cout<<endl;
        }
        cout<<endl;
    }
    cout<<((dp[n][k]-dp[n][k-1])%mod+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 80128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

def T(k):
    orig_k = k
    sk = 0
    while k > 0:
        sk += k % 10
        k //= 10
    return orig_k / sk

d = {}
MAX = int(1e15) + 1e9
for i in range(1, 999):
    t = i
    while t < MAX:
        d[t] = T(t)
        t = t * 10 + 9

keys = sorted(list(d.keys()))

# for k in keys:
#     print(k, d[k])

mn = None
ans = []
for k in reversed(keys):
    if mn == None:
        ans.append(k)
        mn = d[k]
    else:
        if mn >= d[k]:
            ans.append(k)
            mn = min(mn, d[k])

ans.reverse()

K = int(input())
ans = ans[:K]
for a in ans:
    print(a)


Measured memory_bytes: 70764
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    bool ans = true;
    REP(i,N-1) if(A[i]==A[i+1]) ans = false;
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 4048
import sys
N = int(input())
A =[int(i) for i in input().split()]
a = max(A)
if a%2==0:
    seco=0
    s =a//2
    for i in A:
        if i <=s:
            seco=max(seco,i)
        else:
            seco=max(seco,a-i)
else:
    seco=0
    s = a//2 +1
    for i in A:
        if i <=s:
            seco=max(seco,i)
        else:
            seco=max(seco,a-i)

for i in A:
    if i==seco:
        print(a,seco)
        sys.exit()
print(a,a-seco)

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  vector<int> cnts;
  
  char prev = '1';
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (S[i] != prev) {
      cnts.push_back(cnt);
      cnt = 1;
      prev = S[i];
    } else {
      cnt++;
    }
  }
  if (cnt != 0) cnts.push_back(cnt);

  if (S[N - 1] != '1') cnts.push_back(0);

  vector<int> sums(cnts.size() + 1);
  sums[0] = 0;

  for (int i = 0; i < (int)cnts.size(); ++i) {
    sums[i + 1] = sums[i] + cnts[i];
  }

  int to = 2 * K + 1;
  int ans = 0;
  for (int i = 0; i < (int)sums.size(); i += 2) {
    int right = min(i + to, (int)sums.size() - 1);
    ans = max(ans, sums[right] - sums[i]);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1272
s = input()
t = s[::-1]
 
for i in range(len(s)):
  if s[i] == "A":
    break
for j in range(len(t)):
  if t[j] == "Z":
    break
if j != 0:
  print(len(s[i:-j]))
if j == 0:
  print(len(s[i:]))

Measured memory_bytes: 3560
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a, sum = 2001, num = 2001;
	for (int h = 0; h < 3; h++) {
		cin >> n;
		sum = min(sum, n);
	}
	for (int h = 0; h < 2; h++) {
		cin >> a;
		num = min(num, a);
	}
	cout << sum + num - 50 << endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 1e6 + 10;
int lp[MAXN];
int cnt[MAXN];
void solve() {
    for(ll i = 2; i < MAXN; i += 2)
        lp[i] = 2;
    for(ll i = 3; i * i < MAXN; i += 2) {
        if(lp[i]) continue;
        lp[i] = i;
        for(ll j = i * i; j < MAXN; j += (i + i))
            if(!lp[j]) lp[j] = i;
    }
    for(ll i = 2; i < MAXN; ++i) if(!lp[i]) lp[i] = i;
    int n, gc = 0;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        gc = __gcd(x, gc);
        unordered_set <int> ws;
        while(x > 1) {
            if(!ws.count(lp[x])) cnt[lp[x]]++;
            ws.insert(lp[x]);
            x /= lp[x];
        }
    }
    bool ch = 0;
    for(int i = 1; i < MAXN; ++i) if(cnt[i] > 1) {
        ch = 1;
        break;
    }
    if(!ch) cout << "pairwise coprime";
    else if(gc == 1) cout << "setwise coprime";
    else cout << "not coprime";
}


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}


Measured memory_bytes: 11468
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}
template<class T>inline void outs(vector<T> V){int n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}
//const long mod=(long)1e9+7;
inline void solve(void){
  string S,T,U;
  int A,B;
  in(S,T);
  in(A,B);
  in(U);
  if(S==U)out(A-1,B);
  else out(A,B-1);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
ll n, q;
ll score[200001];
bool c[200001];
vector<int> G[200001];
void dfs(int n)
{
    c[n] = true;
    for (int i = 0; i < G[n].size(); i++)
    {
        if (c[G[n][i]] == false)
        {
            score[G[n][i]] += score[n];
            dfs(G[n][i]);
        }
    }
    return;
}

void add_edge(int u, int v)
{
    G[u].push_back(v);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<p> qu;
    cin >>
        n >> q;
    int a, b;
    for (int i = 0; i < n - 1; i++)
    {
        score[i + 1] = 0;
        c[i + 1] = false;
        cin >> a >> b;
        add_edge(a, b);
        add_edge(b, a);
    }
    ll ca;
    for (int i = 0; i < q; i++)
    {
        cin >> a >> ca;
        score[a] += ca;
    }
    dfs(1);
    for (int i = 0; i < n; i++)
    {
        cout << score[i + 1] << "\n";
    }
}

Measured memory_bytes: 24504
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

s = input()

a = 500000000000
z = -1

for i in range(len(s)):
    if s[i] == "A":
        a = min(a,i)
    elif s[i] == "Z":
        z = max(z,i)
print(z-a+1)


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


int main(){
	char g[42] = {0,0,0,0,0,0,0,0,97,102,107,112,117,122,0,98,103,108,113,118,46,0,99,104,109,114,119,63,0,100,105,110,115,120,33,0,101,106,111,116,121,32};
	string s,a;
	while(cin >> s,!cin.eof()){
		a = "";
		if(s.size() % 2)a = "NA";
		else{for(int i = 0;i < s.size();i += 2){
				int l = s[i] - '0', r = s[i+1] - '0';
				if(l <= 0 || r <= 0 || l > 6 || r > 5){a = "NA";break;}
			a += g[r * 7 + l];
		}
		}
		cout << a << endl;
	}	
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

bool isPrime(int N){
  FOR(i,2,min((int)sqrt(N)+1,N)){
    if(N%i==0)return false;
  }
  return true;
}

int main(){
  int X;
  cin>>X;
  while(!isPrime(X))X++;
  cout<<X<<endl;
  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/agc025/tasks/agc025_a

import itertools
import collections
import bisect

def main():
    N = int(input())
    if N % 10 == 0:
        print(10)
    else:
        print(sum(map(int, list(str(N)))))


if __name__ == '__main__':
    main()
    

Measured memory_bytes: 3444
N,*xs = `dd`.split.map(&:to_i)
xn = Hash.new(0)
xs.each{ |x| xn[x] = (xn[x] || 0) + 1 }
xs.sort!.reverse!
ans = 0
P = (0..xs[0].bit_length).map{ |b| 1 << b }
xs.each{ |x|
  next if xn[x] == 0
  xn[x] -= 1
  m = x.bit_length
  y = P[m] - x
  if xn[y] > 0
    ans += 1
    xn[P[m] - x] -= 1
  end
}
p ans


Measured memory_bytes: 32264
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;


import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int LIMIT = 100000;
			
			long[] counts = new long[LIMIT + 1];
			for(int i = 0; i < N; i++) {
				counts[sc.nextInt()]++;
			}
			
			final int Q = sc.nextInt();
			long answer = 0;
			for(int i = 0; i <= LIMIT; i++) {
				answer += counts[i] * i;
			}
			
			for(int q = 0; q < Q; q++) {
				final int B = sc.nextInt();
				final int C = sc.nextInt();
				
				answer -= counts[B] * B;
				answer += counts[B] * C;
				System.out.println(answer);
				
				counts[C] += counts[B];
				counts[B] = 0;
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 59868
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>
#include <cmath>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 1000000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */

/* main */
int main(){

    string S, T; cin >> S >> T;

    map<string, int> mp;
    int x, y; cin >> x >> y;
    mp[S] = x;
    mp[T] = y;
    string U; cin >> U;
    mp[U]--;
    cout << mp[S] << ' ' << mp[T] << '\n';
    return 0;
}


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

using namespace std;
const int N = 1e5+100;
void Create_InFiles(int i){
	char c[100];
	int cnt=0;
	if(i<10){
		c[cnt++]=(i+'0');
	}
	else{
		c[cnt++]=(i/10+'0');
		c[cnt++]=(i%10+'0');
	}
	c[cnt++]='.';c[cnt++]='i';c[cnt++]='n';c[cnt++]='\0';
	freopen(c,"r",stdin);
}
void Create_OutFiles(int i){
	char c[100];
	int cnt=0;
	if(i<10){
		c[cnt++]=(i+'0');
	}
	else{
		c[cnt++]=(i/10+'0');
		c[cnt++]=(i%10+'0');
	}
	c[cnt++]='.';c[cnt++]='o';c[cnt++]='u';c[cnt++]='t';c[cnt++]='\0';
	freopen(c,"w",stdout);
}
long long a[N];
long long b[N];
int main(){
	// for(int it=1;it<=40;it++){
	// 	Create_InFiles(it);
	// 	Create_OutFiles(it);
		int n;
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		for(int i=1;i<=n;i++){
			if(i&1) b[1]+=a[i];
			else b[1]-=a[i];
		}
		for(int i=2;i<=n;i++){
			b[i]=2*a[i-1]-b[i-1];
		}
		for(int i=1;i<=n;i++) cout<<b[i]<<' ';
		cout<<endl;
	// }
	return 0;
}

Measured memory_bytes: 2816
N, K = gets.split.map &:to_i
A = gets.split.map &:to_i

ans = 0
63.downto(0){|i|
	b = 2**i
	next if ans + b > K
	cnt = A.count{|a| a[i] != 0 }
	ans += b if cnt < N/2.0
}
p A.map{|a| a^ans }.inject:+


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

public class Main{
  public static void main(String[] args){
    try {
      Scanner sc = new Scanner(System.in);
      int n, ans=0;
      n=Integer.parseInt(sc.next());
      int[] h = new int[n];
      for(int i=0; i<n; i++){
        h[i]=Integer.parseInt(sc.next());
      }

      for(int i=0; i<n-1; i++){
        if(h[i]>h[i+1]){
          ans=ans+h[i]-h[i+1];
        }
      }

      System.out.println(ans+h[n-1]);
      
                
      }catch (Exception e) {
      System.out.println("out");
    }
  }
}


Measured memory_bytes: 23764
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	vector<vector<int>> f(n, vector<int>(10));
	vector<vector<int>> p(n, vector<int>(11));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 10; ++j) {
			cin >> f[i][j];
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 11; ++j) {
			cin >> p[i][j];
		}
	}
	int ans = -(1 << 30);
	for (int b = 1; b < (1 << 10); ++b) {
		int sum = 0;
		for (int i = 0; i < n; ++i) {
			int c = 0;
			for (int j = 0; j < 10; ++j) {
				c += f[i][j] && ((1 << j) & b);
			}
			sum += p[i][c];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  while (true) {
    int m, f, r;
    cin >> m >> f >> r;
    if (m == -1 && f == -1 & r == -1) {
      break;
    }
    int total = m + f;
    if (m == -1 || f == -1) {
      cout << "F" << endl;
    }
    else if (total >= 80) {
      cout << "A" << endl;
    }
    else if (total >= 65) {
      cout << "B" << endl;
    }
    else if (total >= 50) {
      cout << "C" << endl;
    }
    else if (total >= 30) {
      if (r >= 50) {
        cout << "C" << endl;
      }
      else {
        cout << "D" << endl;
      }
    }
    else {
      cout << "F" << endl;
    }
  }
}



Measured memory_bytes: 3084
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
using namespace std;

int minimum(int *numArray,int n){
	int minimumNum = numArray[0];
	for(int i = 0; i < n; i++){
		if( numArray[i] < minimumNum){
			minimumNum = numArray[i];
		}
	}
	return minimumNum;
}

int maximum(int *numArray,int n){
	int maximumNum = numArray[0];
	for(int i = 0; i < n; i++){
		if( numArray[i] > maximumNum){
			maximumNum = numArray[i];
		}
	}
	return maximumNum;
}

int main()
{
	int N,M,X,Y;
	cin>>N>>M>>X>>Y;
	int *xArray = new int[N];
	int *yArray = new int[M];
	for(int i = 0; i < N; i++){
		cin>>xArray[i];
	}

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

	int minY,maxX;
	minY = minimum(yArray,M);
	maxX = maximum(xArray,N);
	
	if( maxX >= minY){
		cout<<"War"<<endl;
	}else{
		bool war = true;
		for(int z = maxX + 1; z <= minY; z++){
			if( X < z && z <= Y){
				war = false;
				break;
			}
		}
		if(war == true){
			cout<<"War"<<endl;
		}else{
			cout<<"No War"<<endl;
		}
	}
	
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv,  digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q; ll A, B;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, D; vll path;
//***********//
int main() {
	cin >> N;
	vl C(N);
	vll L(200000);
	for (i = 0; i < N; i++) {
		cin >> C[i];
		C[i]--;
		L[C[i]].push_back(i);
	}
	vl dp(N);
	dp[0] = 1;
	vl now(200000);
	for (i = 0; i < N-1; i++) {
		(dp[i + 1] += dp[i])%=MOD;
		if (now[C[i]] < L[C[i]].size() - 1) {
			if (L[C[i]][now[C[i]]] + 1 < L[C[i]][now[C[i]] + 1]) {
				(dp[L[C[i]][now[C[i]] + 1]] += dp[i]) %= MOD;
			}
			now[C[i]]++;
		}
	}
	
	cout << dp[N - 1];
}

Measured memory_bytes: 15872
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  ll res = 0;
  for(ll i = 2;i <= sqrt(n);i++){
    if(n % i == 0){
      ll j = 0;
      j = n / i;
      if(n / (i-1) == n % (i-1))res += i-1;
      if(n / (j-1) == n % (j-1))res += j-1;
    } 
  }
  if(n > 1)if(n / (n-1) == n % (n-1))res += n-1;
  cout << res << endl;
}

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

int main() {
    int K,A,B;
    cin >> K >> A >> B;

    bool state=false;
    for (int i=A;i<=B;i++) {
        if (i%K==0) {
            state=true;
            break;
        }
    }
    if (state) cout << "OK" << endl;
    else cout << "NG" << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "

int main(){
    char a;cin>>a;
    co((isupper(a))?'A':'a');
    return 0;
}

Measured memory_bytes: 3632
from itertools import product, combinations_with_replacement
H, W, K = map(int, input().split())
S = tuple(tuple(map(int, list(input()))) for _ in range(H))

choko = [[0]*W for _ in range(H)]

ans = 10**18

for divide in product(range(2), repeat=H - 1):
    cut = sum(divide)
    row = [0]
    for d in divide:
        if d:
            row.append(row[-1] + 1)
        else:
            row.append(row[-1])

    r = row[-1] + 1
    for i in range(r):
        for j in range(W):
            choko[i][j] = 0
    for i in range(H):
        for j in range(W):
            choko[row[i]][j] += S[i][j]

    if any(choko[i][0] > K for i in range(r)):
        continue

    now = [0] * r
    for j in range(W):
        if any(now[i] + choko[i][j] > K for i in range(r)):
            cut += 1
            now = [choko[i][j] for i in range(r)]
        else:
            for i in range(r):
                now[i] += choko[i][j]

    ans = min(ans, cut)

print(ans)

Measured memory_bytes: 48220
<?php
list($r, $c) = explode(" ", trim(fgets(STDIN)));
$sheet = array();

for ($i = 0; $i < $r; $i++)
  $sheet[$i] = explode(" ", trim(fgets(STDIN)));

for ($i = 0; $i < $c; $i++) {
  $sum = 0;
  for ($j = 0; $j < $r; $j++) $sum += $sheet[$j][$i];
  $sheet[$r][$i] = $sum;
}

for ($i = 0; $i <= $r; $i++) {
  $sum = array_sum($sheet[$i]);
  echo implode(" ", $sheet[$i]) . " $sum\n";
}



Measured memory_bytes: 10968
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

const int MAX_N =510000;

int par1[MAX_N], par2[MAX_N];
int depth1[MAX_N], depth2[MAX_N];
int size[MAX_N];

void init1(int n){
    for(int i=0; i<n; i++){
        par1[i]=i;
        depth1[i]=0;
    }
}

void init2(int n){
    for(int i=0; i<n; i++){
        par2[i]=i;
        depth2[i]=0;
        size[i]=1;
    }
}

int find1(int x){
    if(par1[x]==x) return x;
    par1[x] =find1(par1[x]);
    return par1[x];
}
int find2(int x){
    if(par2[x]==x) return x;
    par2[x] =find2(par2[x]);
    return par2[x];
}

void unite1(int x, int y){
    x = find1(x); y = find1(y);
    if(x==y) return;
    if(depth1[x]<depth1[y]) {par1[x]=y;  return;}
    if(depth1[x]>depth1[y]) {par1[y]=x;  return;}
    par1[y]=x; depth1[x]++;
    return;
}

void unite2(int x, int y){
    x = find2(x); y = find2(y);
    if(x==y) return;
    int s=size[x]+size[y];
    size[x]=s; size[y]=s;
    if(depth2[x]<depth2[y]) {par2[x]=y;  return;}
    if(depth2[x]>depth2[y]) {par2[y]=x;  return;}
    par2[y]=x; depth2[x]++;
    return;
}

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

map <P,int> mp;

int main(){
    int N; cin >> N; init1(N);
    int K, L; cin >> K >> L;
    for(int i=0; i<K; i++){
        int p, q; cin >> p >> q; p--; q--;
        unite1(p,q);
    }
    init2(N);
    for(int i=0; i<L; i++){
        int r,s; cin >> r >> s; r--; s--;
            unite2(r,s);
    }

    for(int i=0; i<N; i++){
        mp[P(find1(i),find2(i))]++;
    }
    for(int i=0; i<N; i++){
        cout << mp[P(find1(i),find2(i))] << " ";
    }
    cout<< endl;
}



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

int main(){
	int n;
	int t[110000],x[110000],y[110000];
	cin >> n;
	t[0] = x[0] = y[0] = 0;
	for(int i=0;i<n;++i) cin >> t[i+1] >> x[i+1] >> y[i+1];
	
	bool can = true;
	for(int i=0;i<n;++i){
		int dt = t[i+1] - t[i];
		int dist = abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
		if(dt<dist) can = false;
		if(dt%2 != dist%2) can = false;
	}
	if(can) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define MOD 1000000007
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<=n;i++)

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll a, b; cin >> a >> b;

	cout << max(max((a + b), (a - b)), (a * b));

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n_town = Integer.parseInt(sc.next());
        int[][] xys= new int[n_town][2];
        
        for(int i=0;i<n_town;i++){
            xys[i][0] = Integer.parseInt(sc.next());
            xys[i][1] = Integer.parseInt(sc.next());
        }
        
        
        //String s = sc.next();
        
        
        ArrayList<Integer> a_perm = new ArrayList<Integer>(n_town);
        
        for(int i=1; i<=n_town; i++){
            a_perm.add(i);
        }
        
        double sum=0;
        int a=0, b=0;
        for(int j=1; j<n_town; j++){
            a = a_perm.get(j-1)-1;
            b = a_perm.get(j)-1;
            sum+=Math.sqrt((xys[a][0]-xys[b][0])*(xys[a][0]-xys[b][0]) + (xys[a][1]-xys[b][1])*(xys[a][1]-xys[b][1]));
        }
        
        for(int i=1; i<factorial(n_town); i++){
            a_perm = nextPerm(a_perm);
            
            for(int j=1; j<n_town; j++){
                a = a_perm.get(j-1)-1;
                b = a_perm.get(j)-1;
                sum+=Math.sqrt((xys[a][0]-xys[b][0])*(xys[a][0]-xys[b][0]) + (xys[a][1]-xys[b][1])*(xys[a][1]-xys[b][1]));
            }
        }
        sum /= factorial(n_town);
        System.out.println(sum);
    }
    
    private static ArrayList<Integer> nextPerm(ArrayList<Integer> former){
        int pivot=-1;
        int ln = former.size();
        for(int i = ln; i>1; i--){
            if(former.get(i-2) < former.get(i-1)){
                pivot = i-2;
                break;
            }
        }
        if(pivot==-1) return null;
        int pivot_fig = former.get(pivot);
        
        int min_pos=pivot+1;
        int min=former.get(min_pos);
        for(int i=ln-1; i > pivot+1; i--){
            if((former.get(i) < min)&&(former.get(i) > pivot_fig)){
                min_pos=i;
                min=former.get(min_pos);
            }
        }
        Collections.swap(former, pivot, min_pos);
        Collections.sort(former.subList(pivot+1, ln));
        return former;
        
    }
    
    private static int factorial(int n) {
        int ans=1;
        for(int i=n; i>0; i--){
            ans*=i;
        }
        return ans;
    }
}

Measured memory_bytes: 30868
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int d = n;
  vector<string>a(n);
  for(int i = 0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  for(int i = 0;i<n-1;i++) {
    if(a[i]==a[i+1]) d--;
  }
  cout << d << endl;
  return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	if (x == 1 || x == 2 * N - 1)
	{
		cout << "No" << endl;
	}
	else
	{
		set<int> s;
		vector<int> result(2 * N - 1);
		result[N - 1] = x;
		s.insert(x);
		result[N - 2] = x - 1;
		s.insert(x - 1);
		result[N] = x + 1;
		s.insert(x + 1);
		if (N > 2 && x < 2 * N - 2)
		{
			result[N - 3] = x + 2;
			s.insert(x + 2);
		}
		if (N > 2 && x > 2)
		{
			result[N + 1] = x - 2;
			s.insert(x - 2);
		}

		auto count = 0;
		for (auto i = 1; i <= result.size(); ++i)
		{
			if (s.find(i) != s.end())
			{
				continue;
			}

			while (count < result.size() && result[count] != 0)
			{
				++count;
			}
			if (count < result.size())
			{
				result[count] = i;
			}
		}

		cout << "Yes" << endl;
		for (auto i = 0; i < result.size(); ++i)
		{
			cout << result[i] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    fastio;
    ll ans=0;
    string s;
    cin >> s;
    map<int,int> r;
    int n = 0;
    int p = 1;
    revrep(i, s.size()) {
        n = (s[i]-'0')*p + n;
        p *= 10;
        p %= 2019;
        n %= 2019;
        r[n]++;
    }
    for (auto [_,c] : r) {
        ans += c * (c-1)/2;
    }
    ans += r[0];
    cout << ans << endl;
}

Measured memory_bytes: 3780
from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    # A, B = [int(a) for a in input().split()]
    # H = [int(a) for a in input().split()]
    A = {
        i: list(reversed([int(a) - 1 for a in input().split()]))
        for i in range(N)
    }

    Q = set(range(N))

    count = 0
    while True:
        pool = []
        for i in Q:
            ai = A[i]
            if len(ai) == 0:
                continue
            target = ai[-1]
            # if target < i:
            #     continue
            target_q = A[target]
            if target_q[-1] == i:
                # print(i,target)
                pool.append(i)
                pool.append(target)

        if len(pool) == 0:
            if len(Q) != 0:
                print(-1)
                return
            else:
                raise ValueError("test")

        qq = []
        for i in set(pool):
            A[i].pop()
            if len(A[i]) != 0:
                qq.append(i)
        Q = set(qq)

        count += 1
        if len(Q) == 0:
            print(count)
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 62684
#include <iostream>

using namespace std;

int main()
{

    unsigned long long int a, b, r, x, tmp;

    cin >> a >> b;

    x = a * b;

    /* 自然数 a > b を確認・入替 */
    if(a<b){
    tmp = a;
    a = b;
    b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while(r!=0){
    a = b;
    b = r;
    r = a % b;
    }

    cout << x / b << endl;

    return 0;
}

Measured memory_bytes: 256