akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

long N;
vector<vector<long>> dp(10, vector<long>(10));

double Distance(long x_1, long x_2, long y_1, long y_2){
	return sqrt( pow(x_1-x_2, 2) + pow(y_1-y_2, 2)) ;
}

long facctorialMethod(long k){
    long sum = 1;
    for (long i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main(){
	
	cin >> N;
	vector<long> x(N);
	vector<long> y(N);
	rep(i, N) cin >> x.at(i) >> y.at(i);
  
    vector<long> N_perm(N);
    rep(i, N) N_perm.at(i) = i;
  
  	double dis_total = 0.0;

	do {
		rep(i, N-1){
			int start = N_perm.at(i);
			int goal = N_perm.at(i+1);
			//cout << "start: " << start << endl;
			//cout << "goal: " << goal << endl;
			dis_total += Distance(x.at(start), x.at(goal), y.at(start), y.at(goal));
		}
		//cout << endl;
	}while (next_permutation(N_perm.begin(), N_perm.end()));
	
	//cout << "dis_total: " << dis_total << endl;
    cout << fixed;
	cout << setprecision(6) <<dis_total/facctorialMethod(N) << endl;

}

Measured memory_bytes: 256
import collections

SA = collections.deque(input())
SB = collections.deque(input())
SC = collections.deque(input())

i = SA.popleft()

while True:
    if i == 'a':
        if len(SA) == 0:
            ans = 'A'
            break
        i = SA.popleft()
    elif i == 'b':
        if len(SB) == 0:
            ans = 'B'
            break
        i = SB.popleft()
    else:
        if len(SC) == 0:
            ans = 'C'
            break
        i = SC.popleft()

print(ans)

Measured memory_bytes: 3316
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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







int main() {
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> dark(n, -1);
	vector<ll> d(m);
	REP(i, m) {
		cin >> d[i];
		d[i]--;
		dark[d[i]] = i;
	}
	vector<vector<ll>> v(n, vector<ll>(k));
	REP(i, n) {
		REP(j, k) {
			cin >> v[i][j];
			v[i][j]--;
		}
	}

	vector<bool> used(1 << m);
	queue<pair<ll, ll>> que;
	que.push({ (1 << m) - 1, 0 });
	while (!que.empty()) {
		auto tmp = que.front(); que.pop();
		ll now = tmp.first, cnt = tmp.second;
		if (used[now]) continue;
		used[now] = true;
		if (now == 0) {
			cout << cnt << endl;
			return 0;
		}
		REP(j, k) {
			ll next = 0;
			REP(i, m) {
				if (now & (1 << i) && dark[v[d[i]][j]] >= 0) {
					next |= 1 << dark[v[d[i]][j]];
				}
			}
			que.push({ next, cnt + 1 });
		}
	}
}


Measured memory_bytes: 61868
#include <bits/stdc++.h>
using namespace std;
int main()
{
 	int count[26] = {0}; 
  	string s;
  	cin>>s;
  	for(int i=0; i<s.length(); i++)
      count[s[i] - 'a']++;
  	for(int i=0; i<26; i++)
    {
     	if(count[i] % 2 != 0)
        {  cout<<"No";
      	  return 0;
	}
    }
  	cout<<"Yes";
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main()
{
	ll x, y;
	
	scanf("%lld%lld", &x, &y);
  	printf("%s\n", abs(x - y) > 1? "Alice" : "Brown");
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

int A[109];

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

	int N; cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	bool flag = true;
	for (int i = 0; i < N; i++) {
		if (A[i] % 2 == 0) {
			if (A[i] % 3 != 0 && A[i] % 5 != 0) flag = false;
		}
	}
	if (flag) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;

	return 0;
}

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

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
    	int n;
    	string s;
    	cin >> n >> s;

    	int ans = 0;
    	for(int i=0;i+2<n;i++)
    	{
    		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
    			ans++;
    	}

    	cout << ans << '\n';
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};



int N;

int main () {
  cin >> N;

  int tmp = 1;

  while ((tmp*2) <= N) {
    tmp *= 2;
  }

  cout << tmp << "\n";
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    int x= 0;
    for(int i = 1; i < n; i++) {
       x = x^a[i];
    }
    cout << x;

    for(int i = 1; i < n; i++) {
        int y=x;
        y= y^a[0];
        y= y^a[i];
        cout << ' ' << y;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 3944
#include <iostream>

#include <map>
#include <string>

#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cinttypes>


using namespace std;

int main()
{
	map<string,int> counter;

	int n;
	cin >> n;

	int maxCount = 0;

	for (int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;

		maxCount = max(maxCount, ++counter[s]);
	}
		
	for (auto kv : counter)
	{
		if (kv.second == maxCount)
			cout << kv.first << endl;
	}

	return 0;
}


Measured memory_bytes: 26496
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 2019;
ll power(ll a, ll n) {
    if(n == 0) return 1;
    else if(n%2 == 0) {
        return power((a%mod*a%mod)%mod, n/2)%mod;
    }
    else return (a%mod * power((a%mod * a%mod), (n-1)/2)%mod)%mod;
}

ll add(ll a, ll b) {
    ll ans = (a%mod + b%mod)%mod;
    return ans;
}

ll mul(ll a, ll b) {
    ll ans = (a%mod * b%mod)%mod;
    return ans;
}
int main(){
    string s;
    cin>>s;
    map<ll,ll>mp;
    mp[0]++;
    ll  n=  s.length();
    ll ee = 0LL;
    ll ans = 0;
    for(int i = n-1; i >= 0 ; i--){
        ll e = s[i] - '0';
        ans = add(ans,mul(power(10LL,ee),e));
       // cout<<ans<<endl;
        mp[ans]++;
        ee++;
    }
    ans = 0;
    for(auto it : mp){
        ans += (it.second*(it.second-1))/2;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<n;(i)++ )
#define FOR(i,n,m) for(int (i)=m;(i)<n;(i)++)


int main(){
    int n;
    cin>>n;
    int a[n];
    int dp[n];
    rep(i,n){
        cin>>a[i];
    }
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    FOR(i,n,2){
        dp[i]=min((dp[i-2]+abs(a[i]-a[i-2])),(dp[i-1]+abs(a[i]-a[i-1])));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

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

int main(void){
    int n;
    while(cin>>n,n){
        double s=0;
        int a[n];
        int ans=0;
        for(int i=0;i<n;i++) cin>>a[i],s+=a[i];
        s/=n;
        for(int i=0;i<n;i++){
            if(a[i]<=s) ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

int main() {
    long long n, a, b;
    cin >> n >> a >> b;

    long long sum = a + b;
    long long x = n / sum;

    long long ans = x * a;
    ans += min(n % sum, a);
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
// Skill Up

func sumVector(_ a: [Int], _ b: [Int]) -> [Int] {
    return (0..<a.count).map{i in
        a[i] + b[i]
    }
}

func main() {
    // n冊の本、m個のスキル、目標x
    let nmx = readLine()!.split(separator: " ").map{Int($0)!}
    let (n,m,x) = (nmx[0], nmx[1], nmx[2])

    var results: [[Int]] = [Array<Int>(repeating: 0, count: m+1)]

    for _ in 1...n {
        let ca = readLine()!.split(separator: " ").map{Int($0)!}
        let selected = results.filter{result in
            result[1...m].contains{$0 < x}
        }.map{result in
            sumVector(result, ca)
        }
        results += selected
    }
    let cleared = results.filter{$0[1...m].allSatisfy{$0 >= x}}
    if cleared.isEmpty {
        print(-1)
    }else {
        print(cleared.map{$0[0]}.min()!)
    }
}

main()

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

int tradeAB(int n, int a[], int b[])
{
  int ans = n;
  for (int i = 0; i * a[0] <= n; i++)
    for (int j = 0; i * a[0] + j * a[1] <= n; j++)
    {
      int k = 0, remain = n - i * a[0] - j * a[1];
      if (a[2] < b[2])
      {
        k = remain / a[2];
        remain %= a[2];
      }

      ans = max(ans, i * b[0] + j * b[1] + k * b[2] + remain);
    }

  return ans;
}

long long tradeBA(int n, int a[], int b[])
{
  long long ans = n;
  int lim0 = (a[0] <= b[0] ? 0 : n / b[0]);
  for (int i = 0; i <= lim0; i++)
    for (int j = 0; i * b[0] + j * b[1] <= n; j++)
    {
      int k = 0, remain = n - i * b[0] - j * b[1];
      if (b[2] < a[2])
      {
        k = remain / b[2];
        remain %= b[2];
      }

      ans = max(ans, 1LL * i * a[0] + 1LL * j * a[1] + 1LL * k * a[2] + remain);
    } 

  return ans;
}

int main()
{
  int n, a[3], b[3];
  cin >> n;
  for (int i = 0; i < 3; i++)
    cin >> a[i];
  for (int i = 0; i < 3; i++)
    cin >> b[i];

  for (int i = 0; i < 3; i++)
    for (int j = i + 1; j < 3; j++)
      if (a[i] - b[i] > a[j] - b[j])
      {
        swap(a[i], a[j]);
        swap(b[i], b[j]);
      }

  cout << tradeBA(tradeAB(n, a, b), a, b) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>
#include <queue>
const int maxn = 200005;
std::vector<int> G[maxn];
int typ[maxn]; int deg[maxn][2];
inline void add_edge(int u, int v) {
  G[u].push_back(v);
}
inline void ins_edge(int u, int v) {
  add_edge(u, v); add_edge(v, u);
  deg[u][typ[v]] ++; deg[v][typ[u]] ++;
}

bool can_del(int x) {
  return (deg[x][0] == 0 || deg[x][1] == 0);
}
bool vis[maxn]; int n;
bool check() {
  std::queue<int> Q;
  for(int i = 1; i <= n; i ++) {
    if(can_del(i)) {
      Q.push(i); vis[i] = true;
    }
  }
  int cnt = 0;
  while(!Q.empty()) {
    int u = Q.front(); Q.pop(); cnt ++;
    for(int v : G[u]) {
      deg[v][typ[u]] --;
      if(!vis[v] && can_del(v)) {
        Q.push(v); vis[v] =  true;
      }
    }
  }
  return (cnt < n);
}

char buf[maxn];
int main() {
  int m; scanf("%d%d", &n, &m);
  scanf("%s", buf + 1);
  for(int i = 1; i <= n; i ++) typ[i] = buf[i] - 'A';
  for(int i = 1; i <= m; i ++) {
    int u, v; scanf("%d%d", &u, &v);
    ins_edge(u, v);
  }
  if(check()) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 13312
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

// UnionFind（１）
type UnionFind struct {
	par []int
}

/* コンストラクタ */
func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.par = make([]int, N)
	for i := range u.par {
		u.par[i] = -1
	}
	return u
}

/* xの所属するグループを返す */
func (u UnionFind) root(x int) int {
	if u.par[x] < 0 {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}

/* xの所属するグループ と yの所属するグループ を合体する */
func (u UnionFind) unite(x, y int) {
	xr := u.root(x)
	yr := u.root(y)
	if xr == yr {
		return
	}
	u.par[yr] += u.par[xr]
	u.par[xr] = yr
}

/* xとyが同じグループに所属するかどうかを返す */
func (u UnionFind) same(x, y int) bool {
	if u.root(x) == u.root(y) {
		return true
	}
	return false
}

/* xの所属するグループの木の大きさを返す */
func (u UnionFind) size(x int) int {
	return -u.par[u.root(x)]
}

type edge struct {
	x, y int
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M := getInt(), getInt()
	e := make([]edge, M)
	for i := 0; i < M; i++ {
		f, t := getInt()-1, getInt()-1
		e[i] = edge{f, t}
	}
	u := newUnionFind(N)
	size := N * (N - 1) / 2
	// out(0)
	cnt := 0
	ans := make([]int, 0)
	ans = append(ans, size)
	for i := M - 1; i > 0; i-- {
		if !u.same(e[i].x, e[i].y) {
			x := u.size(e[i].x)
			y := u.size(e[i].y)
			if x > 1 {
				cnt -= x * (x - 1) / 2
			}
			if y > 1 {
				cnt -= y * (y - 1) / 2
			}
			u.unite(e[i].x, e[i].y)
			z := u.size(e[i].x)
			cnt += z * (z - 1) / 2
			// out(x, y, z)
		}
		// out(size - cnt)
		ans = append(ans, size-cnt)
	}
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(w, ans[i])
	}
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 1000003
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define sumall(v) accumulate(all(v),(ll)0)
#define suma accumulate
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define br "\n"
#define sp " "
#define zero (ll)0
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
ll n,m,k,x,y;
bool ok = false;
int main()
{
    FastIO ;
    PRECISION(10) ;
    ll a,b,c,d,i,j,t;//,x,y,z;//,x1,y1,z1,e,f;
    ll p,q,r,u,w ;
    char ch,chr ;
    string str,st,str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU  +  Graph Theory + Math + DP + Bitmasks + Geometry + Brute Force + Implementation + Binary Search
    cin>>n>>k;
    vll v(n+1,0);
    while(k--)
    {
        cin>>m;
        while(m--)
        {
            cin>>a;
            v[a]++;
        }
    }
    c = 0;
    for(i=1 ; i<=n ; i++)
    {
        if(!v[i])
        {
            c++;
        }
    }
    cout<<c;
}

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

int main(){
    int al=0;
    string S;
    string alp = "abcdefghijklmnopqrstuvwxyz";
    cin >> S;
    sort(S.begin(), S.end());
    S = S + "1";
    for(int i=0; i<S.size()-1; i++){
        if(alp[al] != S[i]) break;
        if(S[i] != S[i+1]) al++;
    }
    if(al != alp.size()) cout << alp[al] << endl;
    else cout << "None" << endl;
}


Measured memory_bytes: 512
N = int(input())
L = list(map(int,input().split()))
from itertools import combinations


Cs = list(combinations(L,3))
cnt=0
for C in Cs:
    # print('C*',C)
    if len(set(C)) == 3:
        a,b,c = C[0],C[1],C[2]
        if (a+b) > c and (b+c)>a and (c+a)>b:
            cnt+=1

print(cnt)


Measured memory_bytes: 90560
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        ArrayList<Integer> array = new ArrayList<Integer>(3);
        array.add(a);
        array.add(b);
        array.add(c);
        
        Collections.sort(array, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        });
        StringBuffer buf = new StringBuffer();
        for (Integer item : array) {
            buf.append(item).append(" ");
        }
        System.out.println(buf.toString().trim());
    }
}

Measured memory_bytes: 17176
// Do you knOW what it feels like?

		// To be TorTured by your own MinD?
	
	// I don't wanna feel the PAIN.

// I BeG you to KILL me, pleASE...

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

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Os")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=1e5+10, lg=17, mod=1e9+7, inf=1e18;

ll a,b,c,d,n;

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>a>>d>>n>>b>>c>>n>>n;
	n=a%2+b%2+c%2;
	if(a*b*c&&n>=2) ++n%=2;
	cout<<a+b+c+d-n;
	
	return 0;
}


















Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define M 1000000007
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define rep(i,s,e) for(int i=s;i<e;i++)
#define drep(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
int a[N];
int main(){
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    long long area=1,o=0;
    for(int i=n-1;i>0;i--){
        if(a[i]==a[i-1]){
            area *=a[i];
            o++;
            i--;
        }
        if(o==2)
            break;
    }
    if(o==2)
        cout<<area<<endl;
    else
        cout<<0<<endl;

    return 0;
}

Measured memory_bytes: 640
n = int(input())
d = sorted(map(int, input().split()))
m = int(input())
t = sorted(map(int, input().split()))
if n < m:
    print("NO")
    exit()
p = 0
ans = True
for i in range(m):
    while p < n and d[p] < t[i]:
        p += 1
    if p >= n or d[p] > t[i]:
        ans = False
    p += 1
print(["NO", "YES"][ans])


Measured memory_bytes: 35556
#include "bits/stdc++.h"

typedef long long ll;

using namespace std;
int main() {
	int A, B, C, res;
	cin >> A >> B >> C;
	if (B / A < C) {
		res = B / A;
	}
	else {
		res = C;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int a,b;char c;
    cin>>a>>c>>b;
    if(c=='+') printf("%d\n",a+b);
    else if(c=='-') printf("%d\n",a-b);
    else if(c=='*') printf("%d\n",a*b);
    else printf("%d\n",a/b);
}

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

struct UnionFind {
    vector<int> par;
    UnionFind(int n): par(n, -1) {}
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (par[x] > par[y]) {
            swap(x, y);
        }

        // yをxに結合する
        par[x] += par[y];
        par[y] = x;
    }
};

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

    vector<ll> x(N), y(N);

    for (int i =0; i < N; i++) {
        cin >> x[i] >> y[i];
    }

    using pint = pair<int, int>;
    using Edge = pair<ll, pint>;
    vector<Edge> edges;

    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] < x[j]; });
    for (int i = 0; i + 1 < ids.size(); i++) {
        int u = ids[i], v = ids[i+1];
        edges.push_back(Edge(x[v]-x[u], pint(u, v)));
    }

    sort(ids.begin(), ids.end(), [&](int i, int j) { return y[i] < y[j]; });
    for (int i = 0; i + 1 < ids.size(); i++) {
        int u = ids[i], v = ids[i+1];
        edges.push_back(Edge(y[v]-y[u], pint(u, v)));
    }

    sort(edges.begin(), edges.end());
    UnionFind uf(N);
    ll res = 0;
    for (auto e: edges) {
        int u = e.second.first, v = e.second.second;
        ll cost = e.first;
        if (uf.issame(u, v)) continue;
        uf.merge(u, v);
        res += cost;
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 9416
using System;

class Program {
    static void Main (string[] args) {
        int n = int.Parse (Console.ReadLine ());
        int tmp = n % 10;
        if (tmp == 3) {
            Console.WriteLine ("bon");
        } else if (tmp == 0 || tmp == 1 || tmp == 6 || tmp == 8) {
            Console.WriteLine ("pon");
        } else {
            Console.WriteLine ("hon");
        }

    }
}

Measured memory_bytes: 27240
#!python3

def resolve():
    N = int(input().rstrip())
    a = list(map(int, input().rstrip().split(" ")))

    k = 0
    m = 1
    for x in a:
        if x == m:
            m += 1
            continue
        k += 1
    if len(a) == k:
        k = -1
    print(k)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 24744
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<double,double> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const LL INF=1<<30;

string s,g;
int dfs(int k){
    if(s==g) return 0;
    int t=(g[k]-s[k]+10)%10;
    if(t==0) return dfs(k+1);
    string ss=s;
    int ret=INF;
    for (int i = k; i < s.length(); i++) {
        s[i]='0'+(s[i]-'0'+t)%10;
        ret=min(ret,dfs(k+1)+1);
    }
    s=ss;
    return ret;
}
    

int main(){
    int n;
    while(cin >> n,n){
        cin >> s >> g;
        cout << dfs(0) << endl;
    }
    return 0;
}



Measured memory_bytes: 3160
n = int(input())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for j in range(n):
    bind = j
    top = n
    bot = -1
    while top-bot > 1:
        mid = (top+bot)//2
        if b[bind] > a[mid]:bot = mid
        else:top = mid
    
    aind = bot
    l = -1
    r = n
   
    while r-l> 1:
   
        cen = (l+r)//2
        if b[bind] < c[cen]:r = cen
        else:l = cen
    cind = r
    ans +=(aind+1)*(n-cind)
    
print(ans)
    


Measured memory_bytes: 105444
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE
void solve(void)
{
  string str;
  int N,K;
  cin>>N>>K;
  cin>>str;
  str[K-1] -= 'A' - 'a';
  cout<<str<<endl;
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


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

int p(int i)
{
    int sum=0;
    for(int q=i-1;q>0;q--)
        sum+=q;
    return sum;
}

int main(void)
{
    int n,m,sum=0;
    scanf("%d%d",&n,&m);
    if(n>=2)
        sum+=p(n);
    if(m>=2)
        sum+=p(m);
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    int ans = 0;
    REP(i,n){
        int x = in();
        while (x % 2 == 0){
            ans++;
            x /= 2;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<int>
const int MOD = 1e9 + 7;
ll mod(ll x) {
	return (x % MOD + MOD) % MOD;
}
ll mul(ll a, ll b) {
	return mod(mod(a) * mod(b));
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
#endif
	fio;
	ll n, k;
	cin >> n >> k;
	vector<ll> pos, neg;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x > 0)
			pos.push_back(x);
		else
			neg.push_back(x);
	}
	if (pos.size()) {
		ll prod = 1;
		vector<ll> lst;

		sort(neg.begin(), neg.end());
		if (k % 2) {
			sort(pos.begin(), pos.end());
			prod = pos.back();
			pos.pop_back();
			k--;
		}
		sort(pos.rbegin(), pos.rend());
		for (int i = 0; i + 1 < pos.size(); i += 2)
			lst.push_back(pos[i] * pos[i + 1]);
		for (int i = 0; i + 1 < neg.size(); i += 2)
			lst.push_back(neg[i] * neg[i + 1]);
		if (pos.size() % 2 != 0 and neg.size() % 2 != 0)
			lst.push_back(pos.back()*neg.back());
		sort(lst.rbegin(), lst.rend());
		for (int i = 0; i < k / 2; i++)
			prod = mul(prod, lst[i]);
		cout << prod << endl;
	}
	else {
		ll prod = 1;
		sort(neg.begin(), neg.end());
		if (k % 2 != 0)
			reverse(neg.begin(), neg.end());
		for (int i = 0; i < k; i++)
			prod = mul(prod, neg[i]);
		cout << prod << endl;
	}
	return 0;
}

Measured memory_bytes: 6564
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, m = gi()
l = sorted(gi())[::-1]
if 4 * m * l[m - 1] < sum(l):
	print("No")
else:
	print("Yes")

Measured memory_bytes: 3060
data=[]
for i in input():
  data.append(i)
  
N=0
maxa=0

for j in range(len(data)):
  if data[j]=="A" or data[j]=="C" or data[j]=="G" or data[j]=="T":
    N=N+1
    if N>maxa:
      maxa=N
  else:
    N=0

print(maxa)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
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...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n, W;
	cin >> n >> W;
	int w[n + 1], v[n + 1];
	for(int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	int dp[n + 1][W + 1];
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= W; j++) {
			if(dp[i - 1][j] != -1) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			}
			if(j + w[i] <= W && dp[i - 1][j] != -1) {
				dp[i][j + w[i]] = max(dp[i][j + w[i]], dp[i - 1][j] + v[i]);
			}
		}
	}
	int ans = 0;
	for(int i = 0; i <= W; i++) {
		ans = max(ans, dp[n][i]);
	}
	cout << ans;

	return 0;
}

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

int main() {
  int N, L;
  cin >> N >> L;
  
  vector<string> S(N);
  rep(i, N) cin >> S[i];
  
  sort(S.begin(), S.end());
  
  string ans = "";
  rep(i, N) {
    ans += S[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int M=1e9+7;
const int N=1e5+5;
using namespace std;
long long f[N],fi[N];
int powr(int a,int b)
{
	long long y=a,x=1;
	while(b>0)
	{
		if(b&1)
		x=(x*y)%M;
		y=(y*y)%M;
		b=b/2;
	}
	return x%M;
}
int mod_inv(int n)
{
	return powr(n,M-2);
}
int c(int n,int r)
{
	if(r>n) return 0;
	return ((f[n]*fi[r])%M*fi[n-r])%M;
}
int main() {
	map<int,int>m;
	int n,tp;
	cin>>n;
	n++;
	int a[n+3];
	long long ans[n+3];
	f[0]=fi[0]=1;
	for(int i=1;i<=n;i++)
	{
	  cin>>a[i];
	  f[i]=(f[i-1]*i)%M;
	  fi[i]=(mod_inv(i)*fi[i-1])%M;
	}
	for(int i=1;i<=n;i++)
	{
		if(m[a[i]]==0)
		m[a[i]]=i;
		else
		{
			tp=i-m[a[i]]+1;
			break;
		}
	}
	for(int i=1;i<=n;i++)
	{
		int rs=c(n,i);
		ans[i]=rs-c(n-tp,i-1);
		if(ans[i]<0) ans[i]=(ans[i]+M)%M;
		cout<<ans[i]<<endl;
	}
	return 0;
}

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

int dat[200010];
int count[200010];

void init(int N){
    for(int i=0; i<N; i++){
        dat[i] = i;
    }
}


int find(int v)
{
    if(dat[v] == v)
        return v;
    else
    {   
        //路径压缩(使搜索祖宗的过程中，路径中搜索的结点的父亲的变为祖宗)
        dat[v] = find(dat[v]);
        return dat[v];
    }   
}

void unio(int v,int u)
{
    int t1 = find(v);
    int t2 = find(u);
    dat[t2] = t1; 
    return;
}

int main(){
    int N, M;
    scanf("%d %d", &N, &M);
    init(N);
    for(int i=0; i<M; ++i){
        int a, b;
        scanf("%d %d", &a, &b);
        unio(a-1, b-1);
    }
    memset(count, 0, N*sizeof(int));
    for(int i=0; i<N; ++i){
        int r = find(i);
        count[r]++;
    }

    int max = 0;
    for(int i=0; i<N; ++i){
        if(max < count[i])
            max = count[i];
    }
    printf("%d\n", max);
    return 0;
}


Measured memory_bytes: 5504
#include<iostream>
using namespace std;
long long n, m;
long long a[100000];
bool search(long long v){
    long long n2=0,m2=0,b=0;
    while (n2<n&&m2<m){
        if (b+a[n2]<=v){
            b+=a[n2];
            n2++;
        }
        else{
            b=0;
            m2++;
        }
    }
    if (n2==n&&m2<m){
		return true;
	}
    return false;
}

int main(){
 
    cin>>n>>m;
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    int l,r;
    l=0;r=100000*10000;
    while(r-l>1){
        long long mi=(l+r)/2;
        if(search(mi))r=mi;
        else l = mi;
    }
        cout<<r<<endl;
        return 0;
}





Measured memory_bytes: 3896
#include<list>
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  int n,k; cin >>n >>k;
  li m;
  list<int> ls;
  rep(i,k){
    int a; cin >>a;
    m+=a;
    ls.push_back(a);
  }
  li s=m;
  rep(i,n-k){
    int a=ls.front(); ls.pop_front();
    s-=a;
    cin >>a;
    s+=a;
    ls.push_back(a);
    if(s>m)m=s;
  }

  printf("%.5lf",(m+k)/2.0);
}

/// confirm df==0 ///


Measured memory_bytes: 6528
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
typedef long long ll;
using namespace std;
const int maxn=201100;
const int mod=1000000000+7;
int h,w,a,b;
ll inv[maxn],F[maxn],Finv[maxn];
 
void init(){
    inv[1]=1;
    for(int i=2;i<maxn;i++){
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    }
    F[0]=1;
    Finv[0]=1;
    for(int i=1;i<maxn;i++){
        F[i]=F[i-1]*i%mod;
        Finv[i]=Finv[i-1]*inv[i]%mod;
    }
}
 
ll C(ll n,ll m){
    if(n<0||m<0||m>n) return 0;
    return F[n]*Finv[m]%mod*Finv[n-m]%mod;
}
 
 
int main(){
    init();
    scanf("%d%d%d%d",&h,&w,&a,&b);//2 3 1 1
    ll ans=0;
    for(int i=1;i<=h-a;i++){
        //cout<<b+i-2<<"  "<<i-1<<endl;
        //cout<<h+w-b-i-2<<" "<<w-b-1<<endl;
        ans=(ans+C(b+i-2,i-1)*C(h+w-b-i-1,w-b-1)%mod)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4992
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author hakamada
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC114_1 solver = new ABC114_1();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC114_1 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            if (N == 7) {
                out.println("YES");

            } else if (N == 5) {
                out.println("YES");

            } else if (N == 3) {
                out.println("YES");

            } else {
                out.println("NO");
            }

        }

    }
}



Measured memory_bytes: 21204
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 505
int a[N][N],K,n;
int main()
{
	scanf("%d",&K);
	if(K<=500)
	{
		printf("%d\n",K);
		for(int i=1;i<=K;i++,puts(""))
			for(int j=1;j<=K;j++)
				printf("%d ",i);
		return 0;
	}else if(!(K&3))
	{
		n=K>>1;
		printf("%d\n",n);
		for(int i=1;i<=n;i++,puts(""))
			for(int j=1;j<=n;j++)
				printf("%d ",(j&1)?(i):(i+n));
		return 0;
	}else
	{
		n=((K+3)>>2)<<1;
		printf("%d\n",n);
		for(int i=0;i<n;i++,puts(""))
			for(int j=0;j<n;j++)
			{
				int x=(i+j)%n+((i&1)?0:n);
				printf("%d ",(x>=K?x-n:x)+1);
			}
	}
}


Measured memory_bytes: 1152
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = sum(b)
for i in range(1,n):
    if a[i]-1==a[i-1]:
        ans+=c[a[i-1]-1]
print(ans)

Measured memory_bytes: 38256
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

use std::time::Instant;
fn main() {
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums = HashMap::with_capacity(n + 1);
    for &a in &aa {
        *nums.entry(a).or_insert(0) += 1;
    }
    // let mut nums: HashMap<_, i32> = aa.iter()
    //     .fold(HashMap::with_capacity(n + 1), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }

    let mut dests = bb.iter().enumerate()
        .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: BTreeSet<_> = (0..n + 1).collect();
    let mut r2: HashSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(aa, bb)", (&aa, &bb));
    let mut cnt = 1;
    while !rems.is_empty() {
        if !r2.is_empty() {
            cnt += 1;
        }
        while let Some(s_idx) = q.pop_front() {
            r2.remove(&s_idx);
            if !rems.remove(&s_idx) { continue; }
            let s_num = aa[s_idx];
            if let Some(destv) = dests.remove(&s_num) {
                for dest in destv {
                    q.push_back(dest);
                }
            }
        }
        if let Some(&rem) = rems.iter().next() {
            q.push_back(rem);
            ans += 1;
        }
        if let Some(&r) = r2.iter().next() {
            // q.push_back(r);
            cnt += r;
        }
    }
    if cnt > 1e18 as usize{
        println!("{}", "hoge");
    }
    println!("{}", ans);
    std::process::exit(0);
}


Measured memory_bytes: 27576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, string>> ps(m);
    rep(i, m) cin >> ps[i].first >> ps[i].second, ps[i].first--;
    vector<ll> wacnt(n, 0);
    vector<bool> isac(n, false);
    rep(i, m) {
        ll p = ps[i].first;
        if (isac[p]) continue;
        if (ps[i].second == "AC") {
            isac[p] = true;
        }
        else {
            wacnt[p]++;
        }
    }
    ll waans = 0, acans = 0;
    rep(i, n) if (isac[i]) waans += wacnt[i];
    rep(i, n) if (isac[i]) acans++;
    cout << acans << " " << waans << endl;
    return 0;
}


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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
using namespace std;
using ll=long long;
using ld=long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class ADoubleHelix {
public:
	void solve(std::istream& in, std::ostream& out) {
	    char b;
	    in >> b;
	    char res;
	    if(b == 'T') res = 'A';
	    if(b == 'A') res = 'T';
	    if(b == 'G') res = 'C';
	    if(b == 'C') res = 'G';
	    out << res << endl;
	}
};


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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	int R;
	cin >> R;
	if (R < 1200) {
		cout << "ABC" << endl;
	}
	else if (R < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <iomanip>
using namespace std;

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

void print_vector(vector<ll> vt){
    for(auto v: vt){
        cout << v;
    }
    cout << endl;
}

ll N;
vector<ll> a, b;

int main()
{
    cin >> N;
    for(int i=0; i<N; i++){
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    for(int i=0; i<N; i++){
        ll tmp;
        cin >> tmp;
        b.push_back(tmp);
    }
    ll ans=0, k=0;
    while(k<=30){//
        vector<ll> tmpa(N), tmpb(N);
        ll base=1<<k;
        ll mod=base*2;
        for(int i=0; i<N; i++){
            tmpa[i]=a[i]%mod;
        }
        for(int i=0; i<N; i++){
            tmpb[i]=b[i]%mod;
        }
        sort(tmpb.begin(), tmpb.end());
        ll cnt=0;//奇数個あったらXORは1
        for(int i=0; i<N; i++){
            auto s1=lower_bound(tmpb.begin(), tmpb.end(), base-tmpa[i]);
            auto b1=lower_bound(tmpb.begin(), tmpb.end(), base*2-tmpa[i]);
            cnt+=b1-s1;
            auto s2=lower_bound(tmpb.begin(), tmpb.end(), base*3-tmpa[i]);
            auto b2=lower_bound(tmpb.begin(), tmpb.end(), base*4-tmpa[i]);
            cnt+=b2-s2;
        }
        if(cnt%2==1){
            ans+=base;
        }
        k++;
    }

    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 6672
from math import ceil


def solve(h, aa, bb):
    max_a = max(aa)
    i = 0
    for b in sorted(bb, reverse=True):
        if b <= max_a:
            break
        i += 1
        h -= b
        if h <= 0:
            return i
    return i + ceil(h / max_a)


n, h = map(int, input().split())
aa, bb = zip(*(map(int, input().split()) for _ in range(n)))

print(solve(h, aa, bb))


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

using namespace std;
int main()
{
  char ch;
  
  cin>>ch;
  
  if(ch=='A')
    cout<<"T"<<endl;
  else if(ch=='T')
    cout<<"A"<<endl;
  else if(ch=='G')
    cout<<"C"<<endl;
  else if(ch=='C')
    cout<<"G"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define elif else if
typedef long long ll;
typedef unsigned long long ull;
#define DEBUG(x) cout << (x) << endl

ll n, p;
string s;
ll tmp[10005] = {0};

int main()
{
    scanf("%lld %lld", &n, &p);
    cin >> s;
    tmp[0] = 1;
    ll ans = 0;
    ll now = 0;
    ll times = 1;
    if (p == 2 || p == 5)
    {
        for (int i = 0; i < n; i++)
        {
            if ((s[i] - '0') % p == 0)
            {
                ans += i + 1;
            }
        }
    }
    else
    {
        for (int i = n - 1; i >= 0; i--)
        {
            now += (s[i] - '0') * times;
            times *= 10;
            now %= p;
            times %= p;
            ans += tmp[now];
            tmp[now] += 1;
        }
    }

    printf("%lld\n", ans);

    return 0;
}


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

int main(){
  string s;
  cin>>s;
  int n=0;
  int m=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='S')n++;
    if(s[i]=='T'&&n!=0){
      n--;
      m++;
    }
    //cout<<n<<" "<<m<<endl;
  }
  cout<<s.size()-(m*2)<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
  
using namespace std;

#define pi 3.141592653589793

int main()
{
	int n;
	cin >> n;
	int f[45];
	f[0] = 1;
	f[1] = 1;
	for(int i = 2; i <= n; i++){
		f[i] = f[i - 2] + f[i - 1];
	}
	cout << f[n] << endl;
}

Measured memory_bytes: 1160