akhauriyash/Code-Regression huggingface dataset:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

X_high = 0
X_low = 0

for i in range(X, N + 1):
    if i in A:
        X_high += 1

for i in range(0, X + 1):
    if i in A:
        X_low += 1

print(min(X_high, X_low))

Measured memory_bytes: 9084
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let c: Vec<i32> = (0..9)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    for a1 in 1..4 {
        let b1 = c[0] - a1;
        let b2 = c[1] - a1;
        let b3 = c[2] - a1;
        let a2 = c[3] - b1;
        let a3 = c[6] - b1;
        if c[4] == a2 + b2 && c[5] == a2 + b3 && c[7] == a3 + b2 && c[8] == a3 + b3 {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	string t;
	cin >> t;
	int n = 0, w = 0, s = 0, e = 0;
	for(char c:t) {
		if(c == 'N') n = 1;
		if(c == 'W') w = 1;
		if(c == 'E') e = 1;
		if(c == 'S') s = 1;
	}	
	if(n + s == 1 || e + w == 1) cout << "No" << endl;
	else cout << "Yes" << endl;
}





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

//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ms(a, b) memset((a), (b), sizeof(a))
#define len(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define lb lower_bound
#define ub upper_bound
#define fore(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " /";
    __f(comma + 1, args...);
}

template <class T> bool mini(T& a, T b) { return a > b ? (a = b, 1) : 0; }
template <class T> bool maxi(T& a, T b) { return a < b ? (a = b, 1) : 0; }

typedef long long ll;
typedef double db;
typedef pair<int, int> pi;
typedef pair<int, pi> ti;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ti> vti;
typedef vector<vpi> vvpi;

const int inf = (int)0x3f3f3f3f3f3f3f3f;
const int ninf = (int)0xc0c0c0c0c0c0c0c0;
const ll M = (ll)1e9 + 7;

int cnt[10][10];

main() {
    int n; scanf("%d", &n);
    fort(i, 1, n) {
        int x = i;
        int s = i % 10;
        while (x >= 10) x /= 10;
        ++cnt[x][s];
    }
    ll ans = 0;
    fore(i, 0, 10) fore(j, i + 1, 10) ans += 2 * cnt[i][j] * cnt[j][i];
    fore(i, 0, 10) ans += cnt[i][i] * cnt[i][i];
    printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n,k; cin >> n >> k;
  vector<int> h(n);
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> h[i];
    if(h[i] >= k) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
# include <iostream>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

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

const int N = 1e5 + 100;

int n, m, k;
int cnt[N];

int main()
{
	cin >> n >> m;
	k = m;
	while( m -- ){
		int l, r;
		cin >> l >> r;
		cnt[l] ++;
		cnt[r + 1]--;
	}
	
	for ( int i = 1; i <= n; i ++ )cnt[i] += cnt[ i - 1] ;
	int ans = 0;
	
	for ( auto c: cnt ){
		ans += ( c == k);
	}
	cout << ans;

}


Measured memory_bytes: 640
n = list(map(int, input().split()))
n = n[0]

a = list(map(int, input().split()))


if(max(a)>0 and min(a)>0):
    a.sort()
    total = sum(a)-2*a[0]
    print(total)
    temp=a[0]
    for i in range(n-2):
        print(temp,a[i+1])
        temp=temp-a[i+1]
    print(a[n-1],temp)
elif(max(a)<0 and min(a)<0):
    b = [abs(a[i]) for i in range(len(a))]
    b.sort()
    total = sum(b)-2*b[0]
    print(total)
    temp= -b[0]
    for i in range(n-2):
        print(temp,-b[i+1])
        temp=temp+b[i+1]
    print(temp, -b[n-1])
else:
    b = [abs(a[i]) for i in range(len(a))]
    total = sum(b)
    print(total)
    a.sort()
    temp=a[n-1]
    for i in range(n-1):
        if(i==n-2):
            print(max(a[i],temp),min(a[i],temp))
        elif(a[i+1]>=0):
            print(min(a[i],temp),max(a[i],temp))
            temp=min(a[i],temp)-max(a[i],temp)
        else:
            print(max(a[i],temp),min(a[i],temp))
            temp=max(a[i],temp)-min(a[i],temp)
            


Measured memory_bytes: 14008
#define  _CRT_SECURE_NO_WARNINGS
	#include <algorithm>
	#include <iostream>
	#include <iterator>
	#include <numeric>
	#include <sstream>
	#include <fstream>
	#include <cassert>
	#include <climits>
	#include <cstdlib>
	#include <cstring>
	#include <string>
	#include <cstdio>
#include<algorithm>
	#include <vector>
	#include <math.h>
	#include <queue>
	#include<memory>
	#include <deque>
	#include <stack>
	#include <list>
	#include <map>
	#include <set>
	#include <cmath>
	#include <bitset>
	#include<list>
	#include <iomanip>
	using namespace std;
	typedef long long ll;
	

	int dp[(int)1e5 + 10];
	bool vis[(int)1e5 + 10];
	vector<int> graph[(int)1e5 + 10];
	int dfs(int now)
	{
		int l = graph[now].size();
		if (l == 0)return 0;
		if (dp[now] != -1)return dp[now];
		for (int i = 0; i < l; i++)
		{
			dp[now] = max(dp[now], 1 + dfs(graph[now][i]));
		}
		return dp[now];
	}
	
	int main()
	{
		memset(dp, -1, sizeof dp);
		int n, m;
		cin >> n >> m;
		for (int i = 0; i < m; i++)
		{
			int a, b;
			cin >> a >> b;
			graph[a].push_back(b);
		}
		int sol = 0;
		for (int i = 1; i <= n; i++)
		{
			sol = max(sol, dfs(i));
		}
		cout << sol << endl;
		return 0;
	}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll fans=INF;
char C[200005];
ll cnt[200005];
ll ans[200005];

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N>>C;
rep(i,N){
	cnt[i+1]=cnt[i];
	if(C[i]=='R') cnt[i+1]++;
}
if(cnt[N]==N||cnt[N]==0){
	cout<<0<<endl; exit(0);
}
rep1(i,N+1){
	ll Cwhite=i-cnt[i];
	ll Cred=cnt[N]-cnt[i];
	if(Cwhite<=Cred) ans[i]=Cred;
	else ans[i]=Cwhite;
}
rep1(i,N+1) fans=min(fans,ans[i]);
cout<<min(fans,cnt[N])<<endl;

}
	

Measured memory_bytes: 6944
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
     
    ans = 0
    for i in range(1, N+1, 2):
        cnt = 0
        for j in range(1, i+1, 2):
            if i%j==0:
                cnt += 1
        if cnt==8:
            ans += 1
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

struct edge { int from, to , cost; };
edge es[2010];
ll d[1010];
int V, E;
void Bellman_Ford(int S)
{
	for (int i = 0; i < V; i++) {
		for (int j = 0; j < E; j++) {
			edge e = es[j];
			if (d[e.from] != -INF && d[e.to] < d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
			}
		}
	}
}

int main()
{
	cin >> V >> E;
	for (int i = 0; i < E; i++) {
		cin >> es[i].from >> es[i].to >> es[i].cost;
		es[i].from--; es[i].to--;
	}
	ll ans;
	for (int i = 0; i < V; i++) d[i] = -INF;
	d[0] = 0;
	Bellman_Ford(0);
	ans = d[V - 1];
	Bellman_Ford(0);
	if (ans != d[V - 1])cout << "inf" << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int f = Integer.parseInt(sc.next());
			if (f >= k)
				ans++;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 43192
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    for i in 0..n {
        if a[i] % 2 == 0 &&  a[i] % 3 != 0 && a[i] % 5 != 0 {
            println!("DENIED");
            return
        }
    }

    println!("APPROVED")
}


Measured memory_bytes: 2136
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> xs(n);
    for (auto &x: xs)
        cin >> x;

    vector<vector<int>> bkt(m);
    for (auto &x: xs) {
        bkt[x % m].push_back(x);
    }
    for (auto &b: bkt) {
        sort(b.begin(), b.end());
    }

    int ans = 0;
    for (int i = 0; i < m; i++) {
        int j = (m - i) % m;

        if (i > j)
            continue;

        if (i == j) {
            ans += bkt[i].size() / 2;
            continue;
        }

        int p = 0;
        for (int k = 0; k + 1 < bkt[i].size(); k++) {
            if (bkt[i][k] == bkt[i][k + 1]) {
                p++;
                k++;
            }
        }
        int q = 0;
        for (int k = 0; k + 1 < bkt[j].size(); k++) {
            if (bkt[j][k] == bkt[j][k + 1]) {
                q++;
                k++;
            }
        }

        int is = bkt[i].size();
        int js = bkt[j].size();

        if (is > js) {
            swap(is, js);
            swap(p, q);
        }

        int sel = min((js - is) / 2, q);

        ans += sel;
        js -= sel * 2;
        ans += min(is, js);
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
	
	int n;
	scanf("%d",&n);
	int h[n];
	int m[n];
	for(int i=0;i<n;i++){
		scanf("%d%d",&h[i],&m[i]);
	}

	int M;
	scanf("%d",&M);
	int k[M];
	int g[M];
	for(int i=0;i<M;i++){
		scanf("%d%d",&k[i],&g[i]);
	}
	
	int p[n+M];
	for(int i=0;i<n;i++){
		p[i] = h[i]*60+m[i];
	}
	for(int i=n;i<n+M;i++){
		p[i] = k[i-n]*60+g[i-n];
	}
	sort(p, p+n+M);

	int z=-114514;
	for(int i=0;i<n+M;i++){
		int min=p[i]%60;
		if(z!=p[i]){
		if(i==0){
		if(min<10) printf("%d:0%d", int(p[i]/60),min);
		if(min>=10) printf("%d:%d", int(p[i]/60),min);
		}else{
		if(min<10) printf(" %d:0%d", int(p[i]/60),min);
		if(min>=10) printf(" %d:%d", int(p[i]/60),min);	
		}
		}
		z=p[i];
	}		
	printf("\n");
}

Measured memory_bytes: 1208
from collections import Counter

n,*l = map(int, open(0).read().split())

c0 = Counter(l[::2]).most_common() + [(0, 0)]
c1 = Counter(l[1::2]).most_common() + [(0, 0)]

if c0[0][0] != c1[0][0]:
  print(n - c0[0][1] - c1[0][1])
else:
  print(n - max(c0[1][1] + c1[0][1], c0[0][1] + c1[1][1]))

Measured memory_bytes: 20524
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
Int n, m;
Int l, r, a;
vector<P> Interval[220000];

struct Seg{
    vector<Int> sum;
    vector<Int> mx;
    Seg(){
        sum.resize(1 << 19, 0);
        mx.resize(1 << 19, 0);
    }

    void add_val(Int l, Int r, Int val, Int bottom = 0, Int top = 1 << 18, Int pos = 1){
        if(l <= bottom && top <= r){
            sum[pos] += val;
            return;
        }
        if(r <= bottom || top <= l){
            return;
        }
        Int mid = (bottom + top) / 2;
        add_val(l, r, val, bottom, mid, pos * 2);
        add_val(l, r, val, mid, top, pos * 2 + 1);
        mx[pos] = max(mx[pos*2] + sum[pos*2], mx[pos*2+1] + sum[pos*2+1]);
    }

    Int max_val(Int l, Int r, Int bottom = 0, Int top = 1 << 18, Int pos = 1){
        if(l <= bottom && top <= r){
            return sum[pos] + mx[pos];
        }
        if(r <= bottom || top <= l){
            return -LINF;
        }
        Int mid = (bottom + top) / 2;
        return max(max_val(l, r, bottom, mid, pos * 2),
                   max_val(l, r, mid, top, pos * 2 + 1)) + sum[pos];
    }    
};

int main(){
    cin >> n >> m;
    for(Int i = 0;i < m;i++){
        cin >> l >> r >> a;
        Interval[r].push_back(P(l, a));
    }
    Seg seg;
    for(Int i = 1;i <= n;i++){
        Int mx = seg.max_val(0,i);
        seg.add_val(i, i+1, mx);
        for(auto p: Interval[i]){
            Int l = p.first;
            Int a = p.second;
            seg.add_val(l, i+1, a);
        }
    }

    cout << seg.max_val(0,n+1) << endl;
    
    return 0;
}

Measured memory_bytes: 19840
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include"time.h"
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl

//毎回変える場所
#define N_MAX 100000


//問題文のとおり
int N;
int p[N_MAX];
int ans = 0;
bool cont = false;

int main() {
	cin >> N;
	REP(i, N)cin >> p[i];

	REP(i, N) {
		if (p[i] == i + 1) {
			ans++;
			if (cont) { ans--; cont = false; }
			else { cont = true; }
		}
		else cont = false;
	}
	cout << ans << endl;
	cin >> N;

	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
int main(){
    int h,n,i,a[1000000];
   
    scanf("%d%d",&h,&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++)
        h-=a[i];
    
    if(h<=0)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

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

void bubbleSort(vector<int>A, int N){
    bool flag = 1;
    int count = 0; 
    for (int i = 0; flag; i++){
        flag = 0;
        for(int j = N-1; j >=i+1; j--){
            if(A.at(j) < A.at(j-1)){
                swap(A.at(j), A.at(j-1));
                count ++;
                flag = 1;
            }
        }
    }
    for(int i = 0; i < N; i++){ 
      if (i > 0) cout << ' ';
      cout << A.at(i);
    }
  	cout << endl;
    cout << count << endl;
}

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A.at(i);
    
    bubbleSort(A, N);
    
}


Measured memory_bytes: 3160
//In the name of He
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
const bool DEBUG = false;
#define cerr if(DEBUG)cerr
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long long maxn = 3e5 + 5 + 1;
const long long INF = 4e18 ;
const long long M = 1e9 + 7;
const int lg = 21;
int n,a[3][maxn],dp[3][maxn];

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[1][i];
		dp[1][i] = dp[1][i-1] + a[1][i];
	}
	for(int i = 1; i <= n; i++){
		cin >> a[2][i];
		dp[2][i] = max(dp[1][i], dp[2][i-1]) + a[2][i];
	}
	cout << dp[2][n];
	return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

string S[1000006];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> S[i];
    }

    bool e = false;
    REP(i, N) {
        if (S[i][S[i].length() - 1] == ')')
            e = true;
    }
    if (!e) {
        cout << "No" << endl;
        return 0;
    }

    vector<pll> v, t, u;
    REP(i, N) {
        ll d = 0;
        pll tmp(0, 0);
        REP(j, S[i].length()) {
            if (S[i][j] == '(')
                d++;
            else
                d--;
            tmp.first = std::min(tmp.first, d);
        }
        tmp.second = d;
        if (tmp.second >= 0)
            v.push_back(tmp);
        else if (S[i][S[i].length() - 1] == '(')
            u.push_back(tmp);
        else
            t.push_back(tmp);
    }

#if false
    REP(i, v.size()) {
        cout << v[i].first << " " << v[i].second << endl;
    }
    REP(i, t.size()) {
        cout << t[i].first << " " << t[i].second << endl;
    }
#endif
    sort(v.begin(), v.end(),
         [](pll a, pll b) { return a.first == b.first ? a.second > b.second : a.first > b.first; });

    sort(t.begin(), t.end(),
         [](pll a, pll b) { return a.first < b.first; });
    {
        ll d = 0;
        REP(i, v.size()) {
            if (d + v[i].first < 0) {
                cout << "No" << endl;
                return 0;
            }
            d += v[i].second;
        }
        REP(i, u.size()) {
            if (d + u[i].first < 0) {
                cout << "No" << endl;
                return 0;
            }
            d += u[i].second;
        }
        REP(i, t.size()) {
            if (d + t[i].first < 0) {
                cout << "No" << endl;
                return 0;
            }
            d += t[i].second;
        }
        if (d != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 50316
#include<stdio.h>
int main(void){
	int N,i,x=0,ans=0;
	char s[256],els;
	
	scanf("%d",&N);
	els=getchar();
	for(i=0;i<N;i++){
		s[i]=getchar();
	}
	for(i=0;i<N;i++){
		if(s[i]=='I'){
			x+=1;
			if(ans<x){
				ans=x;
			}
		}
		else{
			x-=1;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N;
  cin >> N;

  vector<pair<pair<string,int>,int>> vec(N);
  for(int i = 0;i < N;i++) {
    vec.at(i).second = i+1;
    cin >> vec.at(i).first.first;
    int P;
    cin >> P;
    P *= (-1);
    vec.at(i).first.second = P;
  }

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

  for(int i = 0;i < N;i++) {
    cout << vec.at(i).second << endl;
  }


}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#ifdef DEBUG
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)\
	{cerr << #a << " = {";\
	for(int qwq = (st); qwq <= (n); ++qwq) {\
		if(qwq == (st)) cerr << a[qwq];\
		else cerr << ", " << a[qwq];\
	} cerr << "}" << endl;}
#define displayv(v) displaya(v, 0, (int)(v).size() - 1)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define display(x) ;
#define displaya(a, st, n) ;
#define displayv(v) ;
#define eprintf(...) if(0) fprintf(stderr, "...")
#endif
template<typename T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template<typename T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; }

const int maxN = 100 + 5;
int n, m;
int G[maxN][maxN];
vector<int> q[maxN][maxN];
int link[maxN];
bool vis[maxN];

int x[maxN * maxN], y[maxN * maxN], col[maxN * maxN];

int dfs(int u) {
	for(int v = 1; v <= n; ++v) if(G[u][v] && !vis[v]) {
		vis[v] = true;
		if(link[v] == 0) link[v] = u;
		else if(dfs(link[v])) {
			link[v] = u;
		} else {
			continue;
		}
		return true;
	}
	return false;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#endif
	cin >> n >> m;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j) {
			int p; cin >> p;
			x[p] = i;
			y[p] = (p - 1) / m + 1;
			G[x[p]][y[p]]++;
			q[x[p]][y[p]].push_back(p);
		}
	for(int i = 1; i <= m; ++i) {
		memset(link, 0, sizeof(link));
		for(int u = 1; u <= n; ++u) {
			memset(vis, 0, sizeof(vis));
			if(!dfs(u)) assert(false);
		}
		for(int v = 1; v <= n; ++v) {
			int u = link[v];
			col[q[u][v].back()] = i;
			q[u][v].pop_back();
			G[u][v]--;
		}
	}
	for(int i = 1; i <= n * m; ++i) {
		G[x[i]][col[i]] = i;
	}
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			printf("%d%c", G[i][j], " \n"[j == m]);
	for(int i = 1; i <= n * m; ++i) {
		G[y[i]][col[i]] = i;
	}
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			printf("%d%c", G[i][j], " \n"[j == m]);
	return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
int main() {
	char b;
		scanf("%c", &b);
	if (b == 'A') {
		printf("T\n");
	}
	else if (b == 'T') {
		printf("A\n");
	}
	else if (b == 'C') {
		printf("G\n");
	}
	else if (b == 'G') {
		printf("C\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n, r;
    cin >> n >> r;
    if ( n >= 10 ) cout << r << endl;
    else           cout << r + 100 * (10 - n) << endl;
    return 0;
}


Measured memory_bytes: 256
MOD = 2019

L, R = map(int, input().split())
minx = float("inf")
for i in range(L, R):
    im = i % MOD
    if i != L and im == L % MOD:
        break
    for j in range(i + 1, R + 1):
        jm = j % MOD
        if j != i + 1 and jm == (i + 1) % MOD:
            break
        minx = min(minx, im * jm % MOD)
print(minx)


Measured memory_bytes: 41308
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
int x[5];
  rep(i,0,5) cin>>x[i];
  rep(i,0,5) {
   if(x[i]==0) cout<<i+1<<endl; 
  }
}









Measured memory_bytes: 3620
import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
struct Reader {
    char[][] inputs;
    ulong idx;
    bool nextLine() {
        char[] buf;
        if(readln(buf)==0) return 0;
        inputs=split(buf);
        idx=0;
        return 1;
    }
    char[] nextItem() {
        if(idx==inputs.length) {
            nextLine();
            idx=0;
        }
        return inputs[idx++];
    }
    int nxtInt() {
        return to!int(nextItem());
    }
    double nxtDouble() {
        return to!double(nextItem());
    }
    char[] nxtStr() {
        return nextItem();
    }
}
void main() {
    Reader r;
    int N=r.nxtInt();
    int Y=r.nxtInt();
    for(int i=0;i<=N;i++) {
        for(int j=0;i+j<=N;j++) {
            if(10000*i+5000*j+1000*(N-i-j)==Y) {
                writefln("%d %d %d",i,j,N-i-j);
                return;
            }
        }
    }
    writeln("-1 -1 -1");
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);

    for(int i = 0;i < n; i++){
        int m;
        scanf("%d",&m);
        int stage[10010] = {0};
        int x = 0,u = 0;
        for(int j = 0;j < m; j++){
            scanf("%d",&stage[j]);
        }
        int d = 0;
        for(int j = m-1;j > 0; j--){
            x = stage[j]- stage[j-1];
            if(u < x)u = x;
        }
        x = 0;
        for(int j = 0;j < m; j++){
            if(j == m-1)continue;
            x = stage[j]- stage[j+1];
            if(d < x)d = x;
        }
        printf("%d %d\n",u,d);
    }
    return 0;
}

Measured memory_bytes: 1068
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

#define rep(i,n) for(int64_t i = 0;i < n;i++)

template<class T> bool chmin(T& a,T b){
    if(a > b){ a = b; return true; }else return false;
}
template<class T> bool chmax(T& a,T b){
    if(a < b){ a = b; return true; }else return false;
}
template<class T> void debug_array(vector<T> a){
    int size = min(15,(int)a.size());
    cout << "{";
    for(int i = 0;i < size;i++){
        cout << a[i] << (i < size - 1 ? "," : "}\n");
    }
}
template<class T> void debug_array(vector<vector<T>> a){
    int n = min(15,(int)a.size()),m = min(10,(int)a[0].size());
    cout << "{\n";
    for(int i = 0;i < n;i++){
        debug_array(a[i]);
    }
    cout << "}\n";
}
vector<vector<int64_t >> dp(3030,vector<int64_t >(3030,0));
class FLCS {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);

        rep(i,3030)rep(j,3030)dp[i][j] = 0;

        string s,t;cin >> s >> t;
        int64_t n = s.size(), m = t.size();

        for(int i = 1;i <= n;i++)for(int j = 1;j <= m;j++){
            if(s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
            chmax(dp[i][j],dp[i - 1][j]);
            chmax(dp[i][j],dp[i][j - 1]);
        }

        string ans = "";

        int x = n,y = m,now = dp[n][m];

        for(int val = now;val > 0;val--){
            for(;y > 0;y--){
                if(dp[x][y] == dp[x][y-1] + 1)break;
            }
            for(;x > 0;x--){
                if(dp[x][y] == dp[x-1][y] + 1)break;
            }
            //cout << x << ' ' << y << '\n';
            ans += (char)s[x - 1];
            x--,y--;
        }
        //debug_array(dp);
        reverse(ans.begin(),ans.end());
        cout << ans << '\n';

	}
	void main2(istream& cin,ostream& cout){

	}
};


int main() {
	FLCS solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 72192
#include<iostream>
#include<string>
using namespace std;
int main(){
string S;
  string T;
  cin>>S>>T;
  if(T==S+"a"||T==S+"b"||T==S+"c"||T==S+"d"||T==S+"e"||T==S+"f"||T==S+"g"||T==S+"h"||T==S+"i"||T==S+"j"||T==S+"k"||T==S+"l"||T==S+"m"||T==S+"n"||T==S+"o"||T==S+"p"||T==S+"q"||T==S+"r"||T==S+"s"||T==S+"t"||T==S+"u"||T==S+"v"||T==S+"w"||T==S+"x"||T==S+"y"||T==S+"z"){
  cout<<"Yes";
  }
  else{
  cout<<"No";
  }
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

// x^n
ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

// x^{-1}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }

vector<ll> fact;
vector<ll> fact_inv;

void init_fact(int n) {
  fact.resize(n + 1);
  fact_inv.resize(n + 1);
  fact[0] = fact_inv[0] = 1;
  for (int i = 0; i < n; ++i) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
    fact_inv[i + 1] = fact_inv[i] * mod_inv(i + 1) % MOD;
  }
}

ll nCr(ll n, ll r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

ll nPr(ll n, ll r) { return nCr(n, r) * fact[r] % MOD; }

int main() {
  int x, y;
  cin >> x >> y;
  if ((x + y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  if ((2 * y - x) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  if ((2 * x - y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  int a = (2 * y - x) / 3;
  int b = (2 * x - y) / 3;
  if (a < 0 || b < 0) {
    cout << 0 << endl;
    return 0;
  }
  init_fact(a + b);
  ll ans = nCr(a + b, a);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#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 A first
#define B second
#define make_pair MP
#define MOD 1000000007
#define MAXM 100005
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;

}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res,x);
        y = y>>1;
        x = mulmd(x,x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a-b;
    if(ret<0){
        ret+=MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int phi(int n){
    int result = n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n=n/i;
            }
            result-=result/i;
        }
    }
    if(n>1) result-=result/n;
    return result;
}

int gcd(int a, int b, int& x, int& y){
    if(a==0){
        x=0;
        y=1;
        return b;
    }
    int x1,y1;
    int d = gcd(b%a, a, x1, y1);
    x = y1 - (b/a)*x1;
    y = x1;
    return d;
}

int arr[100005];
int b[100005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    REP(i, n + 1){
        cin >> arr[i];
    }
    REP(i, n){
        cin >> b[i];
    }
    ll ans = 0;
    REP(i, n){
        if(b[i] > arr[i]){
            b[i] -= arr[i];
            ans += arr[i];
            int t = min(b[i], arr[i + 1]);
            ans += t;
            arr[i + 1] -= t;
        }
        else {
            arr[i] -= b[i];
            ans += b[i];
        }
    }
    cout << ans;

}



Measured memory_bytes: 1024
package main

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

func main() {
	n := nextInt()
	paper := map[int]bool{}
	for i := 0; i < n; i++ {
		a := nextInt()
		paper[a] = !paper[a]
	}
	c := 0
	for _, v := range paper {
		if v {
			c++
		}
	}
	fmt.Println(c)
}

func lcm(a, b int64) int64 {
	return (a / gcd(a, b)) * b
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

const size = 1000000

var reader = bufio.NewReaderSize(os.Stdin, size)

func nextLine() string {
	var line, buffer []byte
	isPrefix := true
	var err error
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
	}
	return string(buffer)
}
func nextStringArray() []string {
	return strings.Split(nextLine(), " ")
}
func nextInt() int {
	n, _ := strconv.Atoi(nextLine())
	return n
}

func nextIntArray() []int {
	s := strings.Split(nextLine(), " ")
	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

func max(i, j int) int {
	if i < j {
		return j
	}
	return i
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    if (n == 2) {
        cout << -1 << endl;
        return 0;
    }
    if (n & 1) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n-1; j++) {
                if (j) cout << " ";
                cout << (i+j+1) % n + 1;
            }
            cout << endl;
        }
    } else {
        int t = n/2;
        for (int i = 0; i < n; i++) {
            if (i < t) cout << (i+1) % n + 1 << " " << (i+t) % n + 1;
            else cout << (i+t) % n + 1 << " " << (i+1) % n + 1;
            for (int j = 1; j < n-1; j++) {
                if (j == t-1) continue;
                cout << " ";
                cout << (i+j+1) % n + 1;
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

struct UnionFind{
  vector<int> data;

  UnionFind(int N){
    data.assign(N,-1);
  }

 bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  int a[n];
  rep(i,n){cin>>a[i];a[i]--;}
  UnionFind UF=UnionFind(n);
  rep(i,m){
    int x,y;
    cin>>x>>y;
    x--;y--;
    UF.unite(x,y);
  }
  int ans=0;
  rep(i,n){
    if(UF.find(i)==UF.find(a[i])){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  if(a<b) swap(a,b);
  if(a<c) swap(a,c);

  int ans=0;
  for(int i=0;i<k;i++) a*=2;
  ans=a+b+c;

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


Measured memory_bytes: 256
N, Q = map(int,input().split())
S = list(input())
S.append(0)
par = [0]*(N+1)#par[0]は無視
Ans = []
for i in range(N):
        par [i+1]=par[i]+(1 if (S[i]=='A') & (S[i+1]=='C') else 0)
for i in range(Q):
        x,y = map(int,input().split())
        print(par[y-1]-par[x-1])
        


Measured memory_bytes: 8436
#include<iostream>
#include<string>
using namespace std;
string s[4];
int main()
{
	cin>>s[1];
	cin>>s[2];
	cin>>s[3];
	int po[4]={0},now=1;
	while(po[now]<s[now].length())
	{
		int to=s[now][po[now]++]-'a'+1;
		now=to;
	}
	cout<<(char)('A'+now-1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
int n, A, B;
int cal[101];
int acal;

int main(int argc, char const* argv[])
{
  cin >> n >> A >> B;
  cin >> acal;
  for(int i = 0; i < n; i++){
    cin >> cal[i];
  }
  sort(cal, cal + n);
  int curr = acal / A;
  int sum = acal;
  int dsum = A;
  for(int i = n - 1; i > 0; i--){
    sum += cal[i];
    dsum += B;
    if(curr < sum / dsum){
      curr = sum / dsum;
    }
  }
  cout << curr << endl;
	return 0;
}



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

int main(){
    rep(i,3){
        string s; cin >> s;
        transform(s.begin(), s.end(), s.begin(), ::toupper);
        cout << s[0];
    }
}


Measured memory_bytes: 256
N = int(input())

cnt = 0
n = 0
while n >= 0:
    if N > cnt:
        n += 1
        cnt += 26**n
    else:
        break
aToz = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
        'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

number = N - (cnt - 26**n) - 1
ans = ""
for i in range(n):
    str = aToz[number % 26]
    ans += str
    number = number // 26
print(ans[::-1])

Measured memory_bytes: 61928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200010;
map<int,int> mp;
ll n,s[N],sum[N],k;
int main()
{
	cin>>n>>k;
	ll mx=0,l;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		sum[i]=sum[i-1]+s[i];
	}
	for(int i=k;i<=n;i++)
	{
		if(sum[i]-sum[i-k]>mx) mx=sum[i]-sum[i-k],l=i; 
	}
	double ans=0;
	for(int i=l-k+1;i<=l;i++)
		ans+=(((s[i]+1)*s[i])/(2.0*s[i]));
	printf("%.10lf",ans);
	return 0;
 } 

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int d[4],i;
    for(i=0;i<3;i++)
        cin>>d[i];
    sort(d,d+3,greater<int>());
    cout<<(d[0]*10+d[1])+d[2]<<endl;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  //A高橋HP　B高橋攻撃力　C青木HP　D青木攻撃力
  while (C > 0 && B > 0) {
  C -= B;
  A -= D;
    if (C < 1) {
    cout << "Yes" << endl;
      break;
    }
   if(A < 1) {
      cout << "No"<< endl;
     break;
    }
  }
}
 
 

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
  int X; cin >> X;
  int ans = 0;
  int now = 0;
  repr(i,1,100000000){
    if(now + i < X){
      now += i;
      ans++;
    }
    else{
      ans++;
      break;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

int main(){
    string s;
    string in[2] = {"ABC","ARC"};
    cin >> s;
    if(s==in[0]) cout << in[1] << endl;
    else if(s==in[1]) cout << in[0] << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3592
/*   _ _ _                     
    | | | | ___  ___           
    | | | || . ||  _|          
    |_____||_  ||_|  _____     
             |_|    |_____|  */
// Time : 19/10/20
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
const int nmax = 300 + 30;
int dis1[nmax][nmax], dis2[nmax][nmax];
int main(){
#ifdef Wqr_
    freopen("in.txt","r",stdin);
#endif
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n, m, l;
    cin >> n >> m >> l;
    int a, b, c;
    memset(dis1, inf, sizeof(dis1));
    memset(dis2, inf, sizeof(dis2));
    for(int i = 0; i < m; ++i){
        cin >> a >> b >> c;
        --a, --b;
        dis1[a][b] = c;
        dis1[b][a] = c;
    }
    for(int i = 0; i < n; ++i){
        dis1[i][i] = dis2[i][i] = 0;
    }
    for(int k = 0; k < n; ++k){
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                dis1[i][j] = min(dis1[i][j], dis1[i][k] + dis1[k][j]);
            }
        }
    }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(dis1[i][j] <= l){
                dis2[i][j] = 1;
                dis2[j][i] = 1;
            }
        }
    }
    for(int k = 0; k < n; ++k){
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                dis2[i][j] = min(dis2[i][j], dis2[i][k] + dis2[k][j]);
            }
        }
    }
    int q;
    cin >> q;
    for(int i = 0; i < q; ++i){
        cin >> a >> b;
        --a, --b;
        if(dis2[a][b] == inf) dis2[a][b] = 0;
        cout << (dis2[a][b] - 1) << endl;
    }
    return 0;
}

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


using namespace std ; 

int main ( ) 
{
	int a , b , c ,d  ;
	scanf ("%d%d%d%d" , &a , &b , &c , &d) ; 
	int area1 = a * b , area2 = c * d ; 
	if ( area1 >= area2)
	printf("%d", area1) ; 
	else 
	printf("%d", area2) ; 

	
		return 0 ; 
} 

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    string s;
    cin>>n>>s;
    int a=0,b=0;
    int l=0,r=0;
    rep(i,n){
        if(s[i]=='('){
            a++;
            if(b){
                l+=b;
                b=0;
            }
        }
        else{
            if(a)a--;
            else b++;
        }
        // cout<<a<<" "<<b<<endl;
    }
    if(b)l+=b;
    r=a;
    // cout<<l<<" "<<r<<endl;
    rep(i,l)cout<<"(";
    cout<<s;
    rep(i,r)cout<<")";
    cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  string key = "2019/04/30";
  
  cin >> s;

  if(s > key)cout << "TBD" << endl;
  else       cout << "Heisei" << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i]:
        if ((l[i]) + (l[j])) > (l[k]) and ((l[k]) + (l[j])) > (l[i]) and ((l[i]) + (l[k])) > (l[j]):
          count += 1
print(count)
      

Measured memory_bytes: 9168
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n = inp[0]
ans = 0
te = n-1
lis = te.prime_division
c= 1
lis.each do |a|
  c *= a[1]+1
end
(2..(n**0.5)).each do |d|
  nk = n
  while nk%d == 0
    nk /= d
    if(nk%d==1)
      ans += 1
      break
    end
  end
end
p ans+c



Measured memory_bytes: 4092
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repri(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define repr(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define reprs(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;
typedef vector<int> VI;
typedef vector<ll> VL;

const int N = 1e7 + 5;
int d[N];
 
int ans[N];
 
vector<PII> g[N];

void dfs (int v = 1, int p = -1, int c = -1) {
	int cur = 1;
	for (auto to : g[v]) if (to.first != p) {
		if (cur == c) cur++;
		ans[to.second] = cur;
		cur++;
		dfs (to.first, v, ans[to.second]);
	}
}

void Main() {
	int n, mx = 0;
	cin >> n;
	for (int i = 1 ; i < n ; ++ i) {
		int a, b;
		cin >> a >> b;
		d[a]++;
		d[b]++;
		g[a].push_back ({b, i});
		g[b].push_back ({a, i});
		mx = max (mx, d[a]);
		mx = max (mx, d[b]);
	}
	dfs();
	cout << mx << "\n";
	for (int i = 1;  i < n ; ++ i) cout << ans[i] << "\n";
}

int main(){
	FAST;
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 244352
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var xyh = new int[num][];
        for (var i = 0; i < num; i++)
            xyh[i] = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        for (var i=0;i<101;i++)
            for(var j = 0; j < 101; j++)
            {
                var minh = int.MaxValue;
                for(var k = 0; k < num; k++)
                    minh = Min(minh, calc(i, j, xyh[k]));
                var isTh = true;
                for (var k = 0; k < num; k++)
                    if (isTh)
                        isTh = xyh[k][2] == Max(0, minh - Abs(i - xyh[k][0]) - Abs(j - xyh[k][1]));
                    else break;
                if (isTh)
                {
                    WriteLine($"{i} {j} {minh}");
                    return;
                }
            }
    }
    private static int calc(int i,int j,int[] vex)
    {
        return Abs(i - vex[0]) + Abs(j - vex[1]) + vex[2];
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 13396