akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <queue>
#include <map>

int n, e, p, q;

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

        std::map<int, int> m;
        std::queue<int> que;

        for(int i = 0; i < n; i++){
            scanf("%d %d %d", &e, &p, &q);

            if(m.count(e) != 0){
                m[e] += (p * q);
            }else{
                m[e] = p * q;
                que.push(e);
            }
        }

        bool flag = true;
        while(!que.empty()){
            int tmp = que.front(); que.pop();

            if(m[tmp] >= 1000000){
                printf("%d\n", tmp);
                flag = false;
            }
        }

        if(flag){
            printf("NA\n");
        }
    }

    return 0;
}

Measured memory_bytes: 2748
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;

int N, T, A[100000], B[100000], C[100000], M, ans;
int i;

int main() {

	scanf("%d %d", &N, &T);

	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	B[N - 1] = A[N - 1];
	for (i = N - 2; i >= 0; i--) {
		if (A[i] > B[i+1]) {
			B[i] = A[i];
		}
		else {
			B[i] = B[i + 1];
		}
	}
	M = 0;


	for (i = 0; i < N-1; i++) {
		C[i] = B[i + 1] - A[i];
		if (C[i] > M) { M = C[i]; }
	}
	
	ans = 0;
	for (i = 0; i < N; i++) {
		if (C[i] == M) { ans++; }
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 1280
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

int main(int argc, char **argv)
{
  uint64_t N;
  std::cin >> N;
  
  std::vector<uint64_t> V(N), C(N);
  N_TIMES(n, N) { std::cin >> V[n]; }
  N_TIMES(n, N) { std::cin >> C[n]; }
  
  uint64_t S = 0;
  N_TIMES(n, N) {
    if (V[n] > C[n]) {
      S += V[n] - C[n];
    }
  }
  std::cout << S << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [input() for i in range(n)]
vote=dict()
for i in range(n):
    try:
        vote[s[i]]+=1
    except:
        vote[s[i]]=1

ans=list()
mx=0
for s,c in vote.items():
    if mx<c:
        ans=list()
        ans.append(s)
        mx=c
    elif mx==c:
        ans.append(s)

ans.sort()

for s in ans:
    print(s)




Measured memory_bytes: 97488
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	char c;
	cin >> c;
	c++;
	
	cout << c << endl;
	
	return 0;
}


Measured memory_bytes: 256
#n = int(input())
a,b=map(int,input().split()) #横並び
#x=[int(input()) for i in range(3)] #縦に並んだのを配列に
#y=list(map(int,input().split())) #横に並んだのを配列に
print("{:.9f}".format(a/b))
#print('YNEOS'[1::2])


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    int n = static_cast<int>(s.length());
    ll a = 0;
    for (int i = 0; i < n; ++i) {
        if(s[i] == 'B') a++;
        else ans += a;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 640
if __name__ == '__main__':
    n = int(input())
    xs = [int(x) for x in input().split()]

    c = max(xs)
    sc, best = c, c
    for d in xs:
        if d == c:
            continue
        if abs(d - c / 2) < sc:
            sc = abs(d - c / 2)
            best = d
    print(c, best)


Measured memory_bytes: 62832
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int n; cin >> n;
  int h[n]; for(int i = 0; i < n; i++) cin >> h[i];
  int i, ans = 0;
  for(i = 0; i < n; i++){
    int j;
    for(j = 0; j < i; j++){
      if(h[j] > h[i]) break;
    }
    if(j == i) ans++;
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = list(sr())
for i in range(3):
    if N[i] == '1':
        N[i] = '9'
    elif N[i] == '9':
        N[i] = '1'

print(''.join(N))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i, x, n) for(int i = x; i < n; i++)
#define repr(i, x, n) for(int i = x; i > n; i--)
#define pii pair<int,int>
#define ll long long
const long long iinf = 1e18;
const int inf = 1e9;
const int MOD = (1e6+3);
int dir4[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int knight[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{-1,2},{1,-2},{-1,-2}};

using namespace std;

void solve()
{
    int n; cin >> n;
    vector<int> v;

    for(int i = 1; i <= n; i++) {
        int x; cin >> x;
        v.push_back(x);
    }
    sort(v.begin(), v.end(), greater<int>());
    ll ans = 0;
    ans += v[0];
    int m =n - 2;
    for(int i = 1; i < n && m > 0;i++){
        if(m) ans += v[i];
        m--;
        if(m){
            ans += v[i];
            m--;
        }
    }
    cout << ans;
    
}
//new line is printed in main()

int main()
{
    int t = 1;
        // cin >> t; // comment out if no test case is required
    int i = 1;
    while(t--){
        //cout << "Case " << i++ << ": ";
        solve();
        // printf("\n");
    }
    return 0;
}


Measured memory_bytes: 4316
#include <stdio.h>
#include <string.h>
int main() {
	char s[1000];
	char t[] = "keyence";
	gets(s);
	int n = strlen(s);
	for (int i = 0; i <= 7; i++) {
		int j;
		for (j = 0; j < 7; j++) {
			if (((j < i) ? s[j] : s[n - 7 + j]) != t[j]) break;
		}
		if (j == 7) {
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

string s;
stack<char> stk;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>s;
	for(int i=0;i<s.size();i++){
		if(i+1<s.size() && s[i]!=s[i+1]){
			i++;
		}
		else{
			if(!stk.empty() && stk.top()!=s[i]){
				stk.pop();
			}
			else{
				stk.push(s[i]);
			}
		}
	}

	cout<<s.size()-stk.size();
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define maxn 0x3f3f3f3f
using namespace std;
typedef long long ll;
int num[1000];
int pos[1000];
int main()
{
	std::ios::sync_with_stdio(false);
	
	int x,n,i,ans1,ans2;
	cin>>x>>n;
	int flag1=0;
	int flag2=0;
	for(i=1;i<=n;i++)
	{
		cin>>num[i];
		pos[num[i]]++;
	}
	for(i=x;i>=-1000;i--)
	{
		if(pos[i]==0)
		{
			ans1=i;
			flag1==1;
			break;
		}
	}
	for(i=x+1;i<=1000;i++)
	{
		if(pos[i]==0)
		{
			ans2=i;
			flag2==1;
			break;
		}
	}
	if(flag1==1&&flag2==0)
	{
		cout<<ans1;
		return 0;
	}
	if(flag1==0&&flag2==1)
	{
		cout<<ans2;
		return 0;
	}
	int tmp1=x-ans1;
	int tmp2=ans2-x;
	if(tmp1<tmp2) cout<<ans1;
	else if(tmp2<tmp1) cout<<ans2;
	else if(tmp2==tmp1) cout<<ans1;
	return 0; 
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

struct unionFind{
    int* par;                       //親
    int* rank;                      //木の深さ
    int* scale;
    unionFind(int n);
    ~unionFind();
    int find(int x);                //木の根を求める
    void unite(int x,int y);        //xとyの属する集合を併合
    bool same(int x,int y);         //xとyが同じ集合に属するか否か
    int size(int x);                //xの属する集合のサイズ
};

unionFind::unionFind(int n){
    par=new int[n];
    rank=new int[n];
    scale=new int[n];
    for(int i=0;i<n;i++){
        par[i]=i;
        rank[i]=0;
        scale[i]=1;
    }
}

unionFind::~unionFind(){
    delete[] par;
    delete[] rank;
    delete[] scale;
}

int unionFind::find(int x){
    if(par[x]==x) return x;
    return par[x]=find(par[x]);
}

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

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

int unionFind::size(int x){
    x=find(x);
    return scale[x];
}

int N,M,K;
vector<int> fri[100000];
vector<int> blo[100000];

int main(){
    cin>>N>>M>>K;
    unionFind uf(N);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        fri[a-1].push_back(b-1);
        fri[b-1].push_back(a-1);
        uf.unite(a-1,b-1);
    }
    rep(i,K){
        int c,d;
        cin>>c>>d;
        blo[c-1].push_back(d-1);
        blo[d-1].push_back(c-1);
    }

    rep(i,N){
        int ans=uf.size(i)-fri[i].size()-1;
        rep(j,blo[i].size()){
            if(uf.same(i,blo[i][j])) ans--;
        }
        cout<<ans<<' ';
    }

    cout<<endl;
}

Measured memory_bytes: 13048
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>

using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 ll n, k, sum=0, m=0;
 cin >> n >>k;
 ll p[n];
 for(int i=0;i<n;i++) cin >> p[i];
 for(int i=0;i<k;i++) sum+=p[i];
 for(int i=0; i<n-k;i++){
   m=max(m, sum);
   sum=sum-p[i]+p[i+k];
 }
  m=max(m, sum);
 cout <<std::setprecision(12) << (double)(m+k)/2;
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#define N (1000000000)

using namespace std;

int main(){
        long long s;
        cin >> s;
        cout << 0 << " " << 0 << " ";
        cout << N << " " << 1 << " ";
        cout << ((s % N == 0) ? 0 : N - s % N) << " " << ((s + N - 1) / N) << endl;
}

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

#define forn(i,m,n) for(int i=m;i<n;i++)
#define vv vector
#define vi vv<int>
#define ii pair<int,int>
#define vii vv<ii>
#define mp make_pair
#define pb push_back
#define PI 3.141592653589
#define ll long long
#define pll pair<ll,ll>
#define vl vv<ll>
#define ff first
#define ss second
#define MOD 1000000007


bool is_prime[1000001];
vi prime;
void sieve(int n)
{
	memset(is_prime,true,sizeof(is_prime));
	for(int i=2;i*i<=n;i++)
	{
		if(is_prime[i])
		{
			for(int j=i*i;j<=n;j+=i)
			{
				is_prime[j]=false;
			}
		}
	}
	forn(i,2,n+1)
	{
		if(is_prime[i])
			prime.pb(i);
	}
}

ll ex(ll a,ll b)
{
    ll res=1;
    a=a%MOD;
    while(b)
    {
        if(b%2){res=(res*a)%MOD;b--;}
        b/=2;
        a=(a*a)%MOD;
    }
    return res;
}

ll fermat_inv(ll a){ return ex(a,MOD-2); }
ll max(ll a,ll b){ return a>b?a:b; }
ll min(ll a,ll b){ return a<b?a:b; }

int gcd(int a,int b) { return (a%b==0)?b:gcd(b,a%b); }


int main()
{
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        /*#ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif*/
    //sieve(1000000);

    int te=1;
    //cin>>te;
    while(te--)
    {
        string s;
        cin>>s;
        if(s[s.length()-1]=='s')
            cout<<s+"es";
        else
            cout<<s+"s";
    }
}


Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdlib>
using namespace std;
int a,b;
string s; 
int main(){
	cin>>a>>b>>s;
	for(int i=0;i<a;i++) 
		if(!isdigit(s[i])){
			cout<<"No\n";
			return 0;
		}
	if(s[a]!='-'){
		cout<<"No\n";
		return 0;
	}
	for(int i=a+1;i<s.length();i++) 
		if(!isdigit(s[i])){
			cout<<"No\n";
			return 0;
		}
	cout<<"Yes\n";
 	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush

sys.setrecursionlimit(10**6)
INF = 10**20

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])

N = int(input())
A = lint()
S = set()
pro = 0
for a in A:
    if a//400<8:
        S.add(a//400)
    else:
        pro += 1
print(max(1,len(S)),len(S)+pro)

Measured memory_bytes: 65072
n = gets.chomp.to_i
a = {}
max = 0
max_keys = []

n.times do
  key = gets.chomp.to_sym
  if a[key]
    a[key] += 1
  else
    a[key] = 0
  end

  if max < a[key]
    max = a[key]
    max_keys = [key]
  elsif max == a[key]
    max_keys.push(key)
  end
end

max_keys.sort!

puts max_keys

Measured memory_bytes: 72296
#include <iostream>
#include <cstdio>
#include <cstring>
 
using namespace std;
 
int main() {
    while (1) {
        char str[1200];
        cin >> str;
 
        if (strcmp(str, "0") == 0) {
            break;
        }
 
        int total = 0;
        for (int i = 0; str[i] != NULL; i++) {
            total += (int)(str[i] - '0');
        }
        printf("%d\n", total);
    }
    return 0;
}

Measured memory_bytes: 1124
s = input()
n = len(s)
rl = [0]*n
count_r = 0
count_l = 0
for i in range(n-1):
    # 左からRだけについて考える
    if s[i] == "R":
        count_r += 1
        if s[i+1] == "L":
            if count_r % 2 == 0:
                rl[i] += count_r//2
                rl[i+1] += count_r//2
            else:
                rl[i] += count_r//2 + 1
                rl[i+1] += count_r//2
            count_r = 0
    # 右からLだけについて考える
    if s[n-1-i] == "L":
        count_l += 1
        if s[(n-1-i)-1] == "R":
            if count_l % 2 == 0:
                rl[n-1-i] += count_l//2
                rl[(n-1-i)-1] += count_l//2
            else:
                rl[n - 1 - i] += count_l//2 + 1
                rl[(n - 1 - i) - 1] += count_l//2
            count_l = 0
print(*rl)


Measured memory_bytes: 50876
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define ll long long
//#define scanf scanf_s

int main()
{
	int n, k;
	while (cin >> n >> k)
	{
		if (n == 0 && k == 0) return 0;
		bool f = false;
		vector<int> v;
		int a;
		REP(i, k)
		{
			cin >> a;
			if (a) v.push_back(a);
			else f = true;
		}
		sort(v.begin(),v.end());
		int l = 0; int r = 0; int ans = 0;
		if (f)
		{
			while (1)
			{
				if (v[r] - v[l] == r - l || v[r] - v[l] == r - l + 1)
				{
					ans = max(ans, v[r] - v[l]);
					if(r!=v.size()-1) r++;
					else break;
				}
				else l++;
			}
		}
		else
		{
			while (1)
			{
				if (v[r] - v[l] == r - l)
				{
					ans = max(ans, v[r] - v[l]);
					if (r != v.size() - 1) r++;
					else break;
				}
				else l++;
			}
		}
		cout << ans+1 << endl;
	}
}

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

/**
 * a[i] + a[j] = i - j
 * i - a[i] = a[j] + j
 */

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> v(N);
    unordered_map<int, int> m;
    long long ans = 0;
    for (int i = 0; i < N; ++i) {
        cin >> v[i];
        int b = v[i] + i;
        int a = i - v[i];
        if (m.count(a)) ans += m[a];
        ++m[b];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define PB push_back

map<string,set<string> > memlist;

set<string> dfs(string group){
  stack<string> grname;
  bool cont=false;
  FOR(setp,memlist[group]){
    if(cont)setp=memlist[group].begin();
    if(memlist.count(*setp)){
      set<string> child=dfs(*setp);
      memlist[group].erase(*setp);
      cont=true;
      FOR(childp,child){
        memlist[group].insert(*childp);
      }
    }else cont=false;

  }
  return memlist[group];
}

  
main(){
  int n;
  while(cin>>n,n){
    string ss;
    memlist.clear();
    string ans;
    rep(i,n){
      cin>>ss;
      ss[ss.find(':',0)]=' ';
      ss[ss.size()-1]=' ';
      int cpos=0;
      while(ss.find(',',cpos)!=string::npos){
        cpos=ss.find(',',cpos);
        ss[cpos]=' ';
      }
      stringstream str(ss);
      string group;
      str>>group;
      if(i==0)ans=group;
      string member;
      while(str>>member)memlist[group].insert(member);
    }

    FOR(memiter,memlist){
      dfs(memiter->first);
    }

/*    FOR(memiter,memlist){
      cout<<memiter->first<<":";
      FOR(setiter,memiter->second){
        cout<<*setiter<<" ";
      }
      cout<<endl;
    }*/
    cout<<memlist[ans].size()<<endl;
  }
}

Measured memory_bytes: 1116
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>> 
ld pie=3.141592653589793238462643383279;
int mod=1e9+7;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};


int dig(int a){
  int r=0;
  while(a!=0){
    int xp=a%10;
    a/=10; if(xp==1) ++r;
  }
  return r;
}

int sp(int a){
  int s=0;
  int ano=a-1;
  while(a!=0){
    s+=a%10;
    a/=10;
  }
  while(ano!=0){
    s+=ano%10;
    ano/=10;
  }
  return s;
}

int fun(int a){
  int r=1;
  f(i,0,10) r*=a;
  return r;
}

void q1(){
  int n,b,q; cin>>n>>b>>q;
  int a[n];  f(i,0,n) a[i]=i/b;
  int curr=-1;
  int load=0;
  while(q--){
    int x; cin>>x;
    if(a[x]!=curr){
      curr=a[x];
      load++;
    }
  }
  cout<<load<<"\n";
}
void q2(){
  int t; cin>>t;
  while(t--){
    int n; cin>>n;
    int a[2*n+5];
    f(i,0,2*n) cin>>a[i];
    int o=0,e=0;
    vector<int> odd,even;
    f(i,0,2*n) if(a[i]%2==1) {
      ++o; odd.pb(i+1);
    }
    else {
      ++e; even.pb(i+1);
    }
    vpii vt;
    if(o&1){
      for(int i=0;i<odd.size()-1;i+=2)
        vt.pb({odd[i],odd[i+1]});
      for(int i=0;i<even.size()-1;i+=2)
        vt.pb({even[i],even[i+1]});
    }else{
      if(o>0){
        for(int i=2;i<odd.size();i+=2)
        vt.pb({odd[i],odd[i+1]});
      for(int i=0;i<even.size();i+=2)
        vt.pb({even[i],even[i+1]});
      }else{
          for(int i=2;i<even.size();i+=2)
        vt.pb({even[i],even[i+1]});
      }
    }
    for(auto it : vt) cout<<it.ff<<" "<<it.ss<<"\n";
  }
}
void q3(){
  int t; cin>>t;
  vector<int> xx;
  int pr[100005]={0};
  f(i,2,100005) if(pr[i]==0){
    if(i&1){
      xx.pb(i); for(int j=2*i;j<100005;j+=i) pr[j]=i;
   }
  }
  while(t--){
    int n; cin>>n;
    if(n==1) cout<<"FastestFinger\n";
    else if (n&1) cout<<"Ashishgup\n";
    else{
      int curr=0;
      while(n!=1){
        if(n&1){
          ++curr;
          break;
        }
        int mx=-1;
        for(auto it : xx) if(n%it==0) mx=it;
        if(mx==-1){
          if(n==2){
            break;
          }else{
            ++curr;
            break;
          }
        }else{
          n/=mx;
          curr++;
        }
      }
      if(curr%2==0) cout<<"Ashishgup\n";
      else cout<<"FastestFinger\n";
    }
  }
}
int32_t main(){
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n; cin>>n;
  int a[n],b[n];
  int x=0;
  f(i,0,n){
    cin>>a[i]; x^=a[i];
  }
  f(i,0,n) b[i]=x^a[i];
  f(i,0,n) cout<<b[i]<<" ";
  return 0;
}


Measured memory_bytes: 6760
H,W=map(int,input().split())

def calc(n):
    if n%3==0:
        return True
    else:
        return False

if calc(H) or calc(W):
    print(0)
    exit()

ans=10**10
for h in range(1,H+1):
    Sa=h*W
    h_=(H-h)//2
    Sb=h_*W
    Sc=(H-h-h_)*W
    SM=max(Sa,Sb,Sc)
    Sm=min(Sa,Sb,Sc)
    ans=min(SM-Sm,ans)
    w=W//2
    Sb=(H-h)*w
    Sc=(H-h)*(W-w)
    SM=max(Sa,Sb,Sc)
    Sm=min(Sa,Sb,Sc)
    ans=min(SM-Sm,ans)

tmp=H
H=W
W=tmp
for h in range(1,H+1):
    Sa=h*W
    h_=(H-h)//2
    Sb=h_*W
    Sc=(H-h-h_)*W
    SM=max(Sa,Sb,Sc)
    Sm=min(Sa,Sb,Sc)
    ans=min(SM-Sm,ans)
    w=W//2
    Sb=(H-h)*w
    Sc=(H-h)*(W-w)
    SM=max(Sa,Sb,Sc)
    Sm=min(Sa,Sb,Sc)
    ans=min(SM-Sm,ans)
print(ans)

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

A.append(0)
point = 0
for i in range(N):
    point += B[i]
    if A[i+1]==A[i]+1:
        point += C[A[i]-1]
print(point)

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

int main() {
  int N, B=0, cnt=1;
  cin >> N;
  vector<int> A(N);
  cin >> A.at(0);
  rep(i, N-1){
    cin >> A.at(i+1);
    if(A.at(i+1)>A.at(i)){
      if(B==-1){
        cnt++;
        B=0;
      }
      else if(B==0) B=1;
    }
    else if(A.at(i+1)<A.at(i)){
      if(B==1){
        cnt++;
        B=0;
      }
      else if(B==0) B=-1;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
//#include<>
using namespace std;

typedef long long ll;
#define rep(i,j) for(i=0;i<j;i++)
#define rev_rep(i,j) for(i=j;i>=0;i—-)

int INF=1<<30;

class Path{
public:
  struct Edge{
    int to,cost;
    Edge(int to_,int cost_):to(to_),cost(cost_){;}
  };
  
  vector< vector<Edge> > G;//接続リスト

  Path(int n){
    G.resize(n);
  }
  
  void add_arc(int x,int y,int c)
  {
    G[x].push_back(Edge(y,c));
  }

  struct state{
    int index;
    int cost;
    state(int i,int c):index(i),cost(c){;}
    bool operator<(const state &r)const{return cost<r.cost;}
    bool operator>(const state &r)const{return cost>r.cost;}
  };
  vector<int> dijkstra(int start){
    priority_queue< state ,vector<state>,greater<state> > que;//(sからの距離,インデックス)
    
    vector<int>norm;
    norm.resize(G.size(),INF);
    que.push(state(start,0));
    
    while(!que.empty()){
      state now=que.top();que.pop();
      if(norm[now.index]!=INF)continue;
      norm[now.index]=now.cost;

      for(Edge e : G[now.index]){
	que.push(state(e.to,now.cost+e.cost));
      }
      
    }
    return norm;
  }
  
};

int main()
{
  int n,m,r;
  cin>>n>>m>>r;
  Path map(n);
  int i;
  rep(i,m)
    {
      int a,b,c;
      cin>>a>>b>>c;
      map.add_arc(a,b,c);
      //map.add_arc(b,a,c);
          
    }
  vector<int> ans=map.dijkstra(r);
  rep(i,ans.size())
    if(ans[i]==INF)
      cout<<"INF"<<endl;
    else
      cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 12256
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).ok();

    let mut iter = input.split_whitespace().map(|w| w.parse::<i32>().unwrap());
    let a = iter.next().unwrap();
    let b = iter.next().unwrap();
    let d = a / b;
    let r = a % b;
    let f = (a as f64) / (b as f64);

    println!("{} {} {:.5}", d, r, f);
}



Measured memory_bytes: 5040
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  string s;
  cin >> s;
  if ((s[0] == '9') || (s[1] == '9')){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}


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

using namespace std;

int main() {
  string S; cin >> S;
  long sum = 0;
  for (int bit = 0; bit < (1 << S.size()-1); bit++) {
    long hoge = 0;
    for (int i = 0; i < S.size()-1; i++) {
      hoge += S.at(i) - '0';
      if (bit & (1 << i)) {
        sum += hoge;
        hoge = 0;
      }
      else hoge *= 10;
    }
    sum += hoge;
    sum += S.at(S.size()-1) - '0';
  }
  cout << sum << endl;
  return 0;
}

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

int main() {
	int A, B;
	
	cin >> A >> B;
	string res = "";

	if (A == B) res = "Draw";
	else if (A == 1) res = "Alice";
	else if (B == 1) res = "Bob";
	else if (A < B) res = "Bob";
	else if (A > B) res = "Alice";

	cout << res << endl;
}



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

int main()
{
  int n,a[202],ans=0;

  cin>>n;
  n*=2;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);

  for(int i=0;i<n;i+=2){
    ans+=a[i];
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
const int MAXN=100005;
bool a[MAXN];
int curl[MAXN];
int total=0;
int cur=1;
int ll[MAXN],rr[MAXN];
string s;
int n;
int ans[MAXN];
int main()

{
	ios::sync_with_stdio(false);
	cin>>s;
	n=s.size();
	for (int i=1;i<=n;i++){
		a[i]=(s[i-1]=='R');
		if (!a[i]) curl[++total]=i;
	}

	for (int i=1;i<=n;i++){
		if (!a[i]){
			if (!ll[i])
				ll[i]=ll[i-1];
			continue;
		}
		while (i>curl[cur])
			cur++;
		
		rr[i]=curl[cur];
		ll[curl[cur]]=i;
	}

	for (int i=1;i<=n;i++){
		if (a[i]){
			int len=rr[i]-i;
			if (len%2==0) ans[rr[i]]++;
			else ans[rr[i]-1]++;
		}
		else{
			int len=i-ll[i];
			if (len%2==0) ans[ll[i]]++;
			else ans[ll[i]+1]++;
		}
	}

	for (int i=1;i<=n;i++)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 2128
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
#include<utility>
using namespace std;
using ll = long long;

int main(){
  string str;
  cin >> str;
  if(str[0]==str[1]&&str[1]==str[2])  cout << "No";
  else  cout << "Yes";
  return 0;
}

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

int main(){
    int A, B;
    int p;
    int result = 0;
    cin >> A >> B;
    for (int i = 1; i <= 9; i++) {
        for (int j = 0; j <= 9; j++) {
            for (int k = 0; k <= 9; k++) {
                p = i * 10001 + j * 1010 + k * 100;
                if (p >= A && p <= B) result++;
            }
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> replicateM 5 (getl toInt) >>= print

solve :: [Int] -> Int
solve [l,a,b,c,d] = l - max (f a c) (f b d)
  where
    f x y = let (q,r) = x `divMod` y in if r == 0 then q else q + 1

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

map <string, int> cnt;

int main()
{
  fastio;
  int n; cin >> n;  int mx = 0;
  for (int i = 1; i <= n; i++){
    string s; cin >> s;
    cnt[s]++; mx = max(mx, cnt[s]);
  }          
  for (auto x : cnt){
    if (x.second == mx) cout << x.first << '\n';
  }
  return 0;
}

Measured memory_bytes: 23808
use text_io::*;
use std::process::exit;

fn main() {
    let n:usize = read!();
    let mut a = vec![0; n+1];;
    for i in 1..100 {
        for j in 1..100 {
            for k in 1..100 {
                if i*i + j*j + k*k + i*j + j*k + k*i <= n {
                    a[i*i + j*j + k*k + i*j + j*k + k*i] += 1;
                }
            }
        }
    }
    for i in 1..n+1 {
        println!("{}",a[i]);
    }
}

Measured memory_bytes: 2104
a,b=map(int,input().split())
if a%3==0 or b%3==0:
  print(0)
elif a==2 and b==2:
  print(1)
else:
  c=a//3+((a/3-a//3)>.5)
  d=a-c
  e=b//3+((b/3-b//3)>.5)
  f=b-e
  g=a//2
  h=a-g
  i=b//2
  j=b-i
  m=[b*c,d*i,d*j]
  n=[a*e,f*g,f*h]
  print(min(max(m)-min(m),max(n)-min(n),a,b))

Measured memory_bytes: 3064
n = input()
if int(n) <= 1000:
  print(1000-int(n))
else:
  if int(n) % 1000 == 0:
    print(0)
  else:
    x = 1000-(100 * int(n[1]) + 10 * int(n[2]) + int(n[3]))
    print(x)

Measured memory_bytes: 9176
#include <iostream>
#include <stack>
#include <queue>

using namespace std;

int main()
{
    stack<int> stk;

    // input
    string str;
    int result;
    cin >> str >> result;

    // calc M pattern
    int mresult = 0;
    int n;
    for (int i = 0; i < (int)str.size(); i++) {
        switch (str[i]) {
        case '*':
            n = stk.top(); stk.pop();
            stk.push(n*(str[i+1]-'0'));
            i++;
            break;
        case '+':
            break;
        default:
            stk.push(str[i]-'0');
            break;
        }
    }
    while (!stk.empty()) {
        int a = stk.top(); stk.pop();
        mresult += a;
    }

    // calc L pattern
    int lresult = str[0]-'0';
    for (int i = 1; i < (int)str.size(); i++) {
        switch (str[i]) {
        case '*':
            lresult *= str[i+1]-'0';
            break;
        case '+':
            lresult += str[i+1]-'0';
            break;
        default:
            break;
        }
    }

    // output
    if (result == mresult) {
        if (result == lresult)
            cout << "U" << endl;
        else
            cout << "M" << endl;
    } else {
        if (result == lresult)
            cout << "L" << endl;
        else
            cout << "I" << endl;
    }

    return 0;
}

Measured memory_bytes: 3228
n = int(input())
a = list(map(int,input().split()))

k_y = [1000]
yen = 1000
resyen = 1000
kabu_max = 0
for i in range(n):
	#株を売り払うケース
	newyen = max( yen, kabu_max * a[i] + resyen)
	
	#株を最大買うケース
	kabu_max_new = max( kabu_max + resyen // a[i], yen // a[i] )
	if kabu_max_new == yen // a[i]:
		if kabu_max_new == kabu_max + resyen // a[i]:
			resyen = max( yen % a[i], resyen % a[i])
		else:
			resyen = yen % a[i]
	
	yen = newyen
	kabu_max = kabu_max_new
	#print(kabu_max,yen,resyen)
print( yen )


Measured memory_bytes: 62048
#include<stdio.h>
#include<string.h>
int main(void)
{
	int k=0,w=0,i,j,cnt[100],flg;
	char n[101];
	for(i=0;i<26;i++){
		cnt[i]=0;
	}	
	scanf("%s",n);
	k=strlen(n);
	for(i=0;i<k;i++){
		w=n[i]-'a';
		cnt[w]++;
	}
	flg=0;
	for(i=0;i<26;i++){
		if(cnt[i]%2!=0){
			flg=1;
			break;
		}
	}
	if(flg==0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}	
}

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int n;
	cin>>n;
	vector<P> a(n);
	rep(i, n){
		ll x, y;
		cin>>x>>y;
		a[i] = P(x, y);
	}
	sort(all(a));
	cout<<a.back().fst+a.back().snd<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const pid_t pid = getpid();
// Problem Specific Parameter:

// Description: グラフの型定義
// Verifyed: Many Diffrent Problem

//Appropriately Changed
using edge = struct {int to;};
using G = vector<vector<edge>>;

//Appropriately Changed
void add_edge(G &graph, int from, int to) {
	graph[from].push_back({to});
}

auto topological_sort(const G& graph) {
	const int n = graph.size();
	vector<int> used(n, 0), order;

	auto dfs = [&](int v) {
		auto func = [&](int v, auto func)->void{
			used[v] = true;
			for (auto &e : graph[v]) if (!used[e.to]) func(e.to, func);
			order.push_back(v);
		};
		return func(v, func);
	};

	rep(v, n)if (!used[v]) dfs(v);
	reverse(_all(order));
	return order;
}

int main(void){
	int n,m;
	cin >> n >> m;

	G graph(n);
	G rgraph(n);
	rep(i,n-1+m){
		int a,b;
		cin >> a >> b;
		add_edge(graph,a-1,b-1);
		add_edge(rgraph,b-1,a-1);
	}

	auto order = topological_sort(graph);
	vector<int> visited(n,-1);
	vector<int> ans(n);

	rep(i,n){
		const int v = order[i];
		visited[v] = i;
		if(i == 0){
			ans[v] = 0;
			continue;
		} else {
			int cmax = -1, u = -1;
			for(auto &e:rgraph[v]){
				if(chmax(cmax,visited[e.to])){
					u = e.to;
				}
			}
			ans[v] = u + 1;
 		}
	}

	rep(i,n) cout << ans[i] << endl;

	return 0;
}

Measured memory_bytes: 15220
#include <bits/stdc++.h>
using namespace std;
#define int long long
/*
計算量気にしなければ貪欲に消せばいい
はみ出しているのがあったら消去
非連結になったらはみ出し確認
明らかに計算量が死ぬ
*/
//BEGIN CUT HERE
struct UnionFind{
  int num;//連結成分の数
  vector<int> r,p,w;//そのグループのサイズ,自分の親っぽいやつ
  UnionFind(){}
  UnionFind(int n):num(n),r(n,1),w(n),p(n,0){iota(p.begin(),p.end(),0);}

  int find(int x){//どのグループに所属するか
    return (x==p[x]?x:p[x]=find(p[x]));//xがグループの名前と一致するまでxを親にする
  }

  void init(vector<int> v){
    w=v;
  }

  bool same(int x,int y){//同じグループかどうか
    return find(x)==find(y);
  }

  void unite(int x,int y){//xとyを同じグループにする
    x=find(x);y=find(y);//xとyのグループの名前をどっちかが変える
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);//サイズが大きい方をxとする
    r[x]+=r[y];//yの親をxにする（今までyだったグループ名がxになる）
    p[y]=x;
    w[x]+=w[y];
    num--;
  }

  int size(int x){//グループの大きさ
    return r[find(x)];
  }

  int weight(int x){
    return w[find(x)];
  }

  int count() const{//グループの数
    return num;
  }
};

typedef pair<int,int> P;
typedef pair<P,P> PP;

signed main(){
  int N,M;cin>>N>>M;
  vector<int> w(N);
  for(int i=0;i<N;i++)cin>>w[i];
  vector<PP> e(M);
  vector<P> edge[N];
  for(int i=0;i<M;i++){
    int a,b,c;cin>>a>>b>>c;a--;b--;
    e[i]=PP(P(c,0),P(a,b));
    edge[a].push_back(P(b,c));
    edge[b].push_back(P(a,c));
  }
  sort(e.begin(),e.end());
  UnionFind uf(N);
  uf.init(w);
  for(int i=0;i<M;i++){
    int W=e[i].first.first,U=e[i].second.first,V=e[i].second.second;
    uf.unite(U,V);
    if(W<=uf.weight(U))e[i].first.second=1;
  }
  sort(e.rbegin(),e.rend());
  set<P> s;
  for(int i=0;i<M;i++){
    int W=e[i].first.first,A=e[i].first.second,U=e[i].second.first,V=e[i].second.second;
    if(s.count(P(U,V)))continue;
    if(A==0)continue;
    s.count(P(U,V));
    queue<int> que;
    que.push(U);
    que.push(V);
    while(que.size()){
      int p=que.front();que.pop();
      for(auto q:edge[p]){
        int t=q.first,WE=q.second;
        if(s.count(P(min(p,t),max(p,t))))continue;
        if(WE>W)continue;
        s.insert(P(min(p,t),max(p,t)));
        que.push(t);
      }
    }
  }
  cout<<M-s.size()<<endl;
}


Measured memory_bytes: 20336
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    if (n % 2) {
        cout << "No\n";
        return 0;
    } else {
        for (int i = 0; i < n / 2; i++) {
            if (s[i] != s[i + n / 2]) {
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
}

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

typedef   long long  int ll;
typedef  long double ld;
typedef std::vector<ll> vi;
typedef std::vector<std::vector<ll> > vv;

#define MOD 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,b) for(i=a;i<b;i++)
#define mp make_pair
#define pb(x) push_back(x)
#define fi first
#define se second
#define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" ";cout<<endl;
#define all(a) a.begin(),a.end()
#define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i];
#define ms(a,val) memset(a,val,sizeof(a))
using namespace std;

const int N = 1e5 + 5;
vi adj[N];
ll path = 0;
bool vis[N];
stack<ll> arr;
void top_sort(ll u)
{
    vis[u] = true;
    //cout<<"dfs at"<<u<<endl;
    
    for(int to : adj[u])
    {
		
		if(!vis[to])
			top_sort(to);
	}
	//cout<<u<<" has been pushed"<<endl;
	arr.push(u);

	
}
void solve(){
            ll i,j,n,m;
           cin>>n>>m;
           fo(i,0,m)
           {
			   ll a,b;
			   cin>>a>>b;
			   adj[a].pb(b);
		   }
		   for(i = 1;i<=n;i++)
		   {
			   if(!vis[i])
			   top_sort(i);
		   }
		   vi ord;
		   while(!arr.empty())
		   {
			   ord.pb(arr.top());
			   arr.pop();
		   }
		   //print(ord,0,ord.size());
		   ms(vis,0);
		   ll dis[n+1] ={0}; 
		   for(auto it : ord)
		   {
			   for(auto to : adj[it])
			   {
				   //cout<<it<<" "<<to<<endl;
				   dis[to] = max(dis[to],dis[it]+ 1);
			   }
			     
			}
			//print(dis,1,n+1);
			cout<<*max_element(dis+1,dis+n+1)<<endl;
		   
		   
            
						            









}

int main()
{
    IO;
      ll t=1;
      //cin>>t;


      while(t--)
      {

          solve();
      }
    return 0;
}



Measured memory_bytes: 12580
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long
#define  vi               std::vector<int>
#define  pb               push_back
#define  MAX              100007
#define  End              return 0;
#define                   pi acos(-1)
map<string,int>mp;

int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    int T;  cin>>T;
    ll ans=0;
    while(T--){
        string s;
        cin>>s;
        mp[s]++;
        if(mp[s]==1) ans++;
    }
    cout<<ans<<endl;
    End
}
/* pray for me
Do before die
*/


Measured memory_bytes: 19208
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const n = Number(stdin.split('\n')[0])

const d = stdin
  .split('\n')[1]
  .split(' ')
  .map(Number)

const ans = () => {
  const sorted = d.sort((a, b) => a - b)

  const center = n / 2

  const kMax = sorted[center]
  const kMin = sorted[center - 1]

  console.log(kMax - kMin)
}

ans()


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

int a;
int b;
int product=1;

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

    for (int i=a; i<=b; i++)
    {
        if (i<0)
        {
            product=product*-1;
        }

        if (i==0)
        {
            cout<<"Zero"<<endl;
            return 0;
        }
    }

    if (product>0)
    {
        cout<<"Positive"<<endl;
    }

    else 
    {
        cout<<"Negative"<<endl;
    }
    
}


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

using namespace std;
using ll = long long;

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

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

  for (int i = 0; i <= x; ++i) {
    int j = x - i;
    if (2 * i + 4 * j == y) {
      puts("Yes");
      return 0;
    }
  }

  puts("No");
  return 0;
}


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

using namespace std;

long long LOG(long long base , long long n){
    return (long long)(log(n) / log(base));
}

int main() {
    long long a , b ; scanf("%lld %lld", &a , &b);
    printf("%lld\n" , LOG(b , a) + 1);
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m == -1 && f == -1 && r == -1){
                break;
            }
            else if(m == -1 || f == -1){
                System.out.println("F");
            }
            else if(m+f >= 80){
                System.out.println("A");
            }
            else if(m+f >= 65){
                System.out.println("B");
            }
            else if(m+f >= 50){
                System.out.println("C");
            }
            else if(m+f >= 30){
                if(r >= 50){
                    System.out.println("C");
                }
                else{
                    System.out.println("D");
                }
            }
            else{
                System.out.println("F");
            }
        }
    }
    
}


Measured memory_bytes: 26244
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2*1e5+10;
const int MOD = 1e9 + 7;
const int INF = 1e18 + 10;

void printVector(vector<int> s){
    for(int &x:s){
        cout<<x<<" ";
    }
    cout<<endl;
}

int n;
double arr[3001];
double dp[3001][3001];

void solve(){
    cin>>n;
    for(int i = 1 ; i <= n; i++){
        cin>>arr[i];
    }
    for(int i = 0 ; i< 3001 ; i++){
        for(int j = 0 ; j < 3001 ; j++){
            dp[i][j] = 0.0;
        }
    }
    dp[0][0] = 1.0;
    for(int i = 1; i <= n ; i++){
        for(int j = 0 ; j<= i; j++) {
            if (j == 0) {
                dp[i][j] = dp[i - 1][j] * (1.0 - arr[i]);
            }
            else {
                dp[i][j] = dp[i - 1][j - 1] * arr[i] + dp[i - 1][j] * (1.0 - arr[i]);
            }
        }
    }
    double ans = 0.0;
    for(int i = 0 ; i <= n ; i++){
        if(i>(n-i)){
            ans+=dp[n][i];
        }
    }
    printf("%.11lf",ans);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
//    cin>>t;
    t = 1;
    for(int i = 0 ; i < t ; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 74176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
double ret = 0;
string s;
double table[3000][3000];
bool checked[3000][3000];
double p[3000];

int main(void){
  
  IN(N);
  FOR(i, 0, N) {
    IN(p[i]);
  }

  table[0][0] = 1.0;
  FOR(i, 0, N) {
    FOR(j, 0, i+1) {
      table[i+1][j+1] += table[i][j] * p[i];
      table[i+1][j] += table[i][j] * (1.0 - p[i]);
    }
  }

  for (ll i = (N+1)/2; i<= N; i++) {
    ret += table[N][i];
  }

  cout << setprecision(10) << ret << endl;

}


Measured memory_bytes: 71168
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<ll> L(N);
    rep(i, N) cin >> L[i];

    int ans = 0;
    sort(all(L));

    rep(i, N - 2) {
        repd(j, i + 1, N - 1) {
            repd(k, j + 1, N) {
                if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) continue;
                if ((L[i] + L[j] > L[k]) && (L[j] + L[k] > L[i]) && (L[k] + L[i] > L[j])) {
                    ans++;
                }
            }
        }
    }

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

Measured memory_bytes: 3620
// https://atcoder.jp/contests/abc110/tasks/abc110_b

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 100;
const int M_MAX = 100;
const int Y_MAX = 100;
const int X_I_MAX = 100;
const int Y_I_MAX = 100;

int N, M, X, Y;
int x[N_MAX + 1];
int y[M_MAX + 1];

void solve() {
  x[N] = X;
  y[M] = Y;
  int xx = *max_element(x, x + N + 1);
  int yi = *min_element(y, y + M + 1);
  bool cond = false;
  puts(xx >= yi ? "War" : "No War");
}

void input() {
  scanf("%d%d%d%d", &N, &M, &X, &Y);
  REP(i, N) scanf("%d", x + i);
  REP(i, M) scanf("%d", y + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256