akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    bool ans = true;
    rep(i,N) {
        if(A[i] % 2 == 0) {
            if(A[i] % 3 != 0 && A[i] % 5 != 0) ans = false;
        }
    }
    if(ans) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const ll mod = 1e9 + 7;

void dfs(vector<vector<bool>>& v, int i, int j, int& steps, int& n, int& m, vector<vector<bool>>& vis, queue<pair<pii, int>>& qp)
{
    if (i < 1 || j < 1 || i > n || j > m || !v[i][j] || vis[i][j]) return;
    vis[i][j] = 1;
    qp.emplace(mp(i, j), steps);
    dfs(v, i + 1, j, steps, n, m, vis, qp);
    dfs(v, i, j + 1, steps, n, m, vis, qp);
    dfs(v, i - 1, j, steps, n, m, vis, qp);
    dfs(v, i, j - 1, steps, n, m, vis, qp);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, m; cin >> n >> m;
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    vector<vector<bool>> v(n + 1, vector<bool>(m + 1)), vis(n + 1, vector<bool>(m + 1));
    FOR(i, 1, n + 1)
    {
        FOR(j, 1, m + 1)
        {
            char a; cin >> a;
            if (a == '.') v[i][j] = 1;
        }
    }
    queue<pair<pii, int>> qp;
    int steps = 0;
    dfs(v, x1, y1, steps, n, m, vis, qp);
    if (vis[x2][y2])
    {
        cout << 0;
        return 0;
    }
    while (!qp.empty())
    {
        int x = qp.front().first.first, y = qp.front().first.second;
        steps = qp.front().second;
        vis[x][y] = 1;
        if (x == x2 && y == y2)
        {
            cout << steps;
            return 0;
        }
        qp.pop();
        FOR(i, -2, 3)
        {
            FOR(j, -2, 3)
            {
                int cur_x = x + i, cur_y = y + j;
                if (cur_x < 1 || cur_y < 1 || cur_x > n || cur_y > m || vis[cur_x][cur_y] || !v[cur_x][cur_y]) continue;
                qp.emplace(mp(cur_x, cur_y), ++steps);
                dfs(v, cur_x, cur_y, steps, n, m, vis, qp);
                if (vis[x2][y2])
                {
                    cout << steps;
                    return 0;
                }
                steps--;
            }
        }
    }
    cout << -1;
    return 0;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;

  int size = s.length();

  if (size <= k) {
    cout << s;
  }
  if (size > k) {
    for (int i = 0; i < k; i++) {
      cout << s[i];
    }
    cout << "...";
  }

  return 0;
}

Measured memory_bytes: 3624
n, m = map(int, input().split())
li_h = list(map(int, input().split()))
li_route = list()
remove_idx_set = set()

for _ in range(m):
    a, b = map(int, input().split())

    h_a = li_h[a - 1]
    h_b = li_h[b - 1]

    if h_a <= h_b:
        remove_idx_set.add(a - 1)
    if h_a >= h_b:
        remove_idx_set.add(b - 1)
for s in remove_idx_set:
    li_h[s] = 0
print(len([v for v in li_h if v != 0]))


Measured memory_bytes: 20100
#include <bits/stdc++.h>
using namespace std;
int main() {

    vector<int> S(6);
    for (int i = 0; i < 6; i++) {
    cin >> S[i];
    }


    if(S[4]-S[0] > S[5]){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	long long n,a,b,m,M;
	cin >> n >> a >> b;
	m = a*(n-1)+b;
	M = b*(n-1)+a;
	if((M-m+1)>=0)	cout << M-m+1 << endl;
	else	cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    long long int ans = 0;
    // we need to add all numbers whcih are not mutiple sof 3 or 5.
    for(int i = 1; i <= n; i++){
        if(i%3 ==0 || i%5==0)continue;
        else ans+=i;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3548
#include <iostream>
#include <vector>
#include <climits>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;

int main(void) {
  string abcd; cin >> abcd;

  int op1[8] = {+1, +1, +1, +1, -1, -1, -1, -1};
  int op2[8] = {+1, +1, -1, -1, +1, +1, -1, -1};
  int op3[8] = {+1, -1, +1, -1, +1, -1, +1, -1};
  int a = (int)abcd[0] - '0';
  int b = (int)abcd[1] - '0';
  int c = (int)abcd[2] - '0';
  int d = (int)abcd[3] - '0';

  int ans = -1;
  for (int n = 0; n < 8; n++) {
    int sum = a + op1[n] * b + op2[n] * c + op3[n] * d;
    if (sum == 7) {
      ans = n;
      break;
    }
  }

  cout << a;
  cout << (op1[ans] > 0 ? "+" : "-") << b;
  cout << (op2[ans] > 0 ? "+" : "-") << c;
  cout << (op3[ans] > 0 ? "+" : "-") << d << "=7" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i = 1; i<n+1; i++)
typedef long long ll;

using namespace std;
const int V = 100005;
int INF = 1000000000;

int x,y;
int n;
int a[1000];

int main(){
  cin >> n;
  int cnt = 0;
  rep(i,n) cin >> a[i];
  rep(i,n){
    rep(j,n-1){
      if(a[j] > a[j+1]){
        int tmp = a[j];
        a[j] = a[j+1];
        a[j+1] = tmp;
        cnt++;
      }

    }
  }
  rep(i,n){
    cout << a[i];
    if (i == n-1) break;
    cout << ' ';
  }
  cout << endl;
  cout << cnt << endl;
}



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

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

	int n, m;
	cin >> n >> m;
	if (n > 1 && m > 1)cout << (n - 1) * (m - 1);
	else cout << 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        
        if (a > b){ System.out.println("a > b"); }
        else if (a < b){ System.out.println("a < b"); }
        else if (a == b) { System.out.println("a == b"); }
        else {}
        
    }
}


Measured memory_bytes: 26292
//Zory-2019
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define double long double
    const int INF=0x3f3f3f3f;
    const ll LLINF=0x3f3f3f3f3f3f3f3fll;
    ll qread()
    {
        ll ans=0;char c=getchar();int f=1;
        while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) {num=-num;putchar('-');}
        if(num>9) write(num/10);
        putchar('0'+num%10);
    }
    void writeln(ll num){write(num);puts("");}
    #define FR first
    #define SE second
    #define MP make_pair
    #define pr pair<int,int>
    #define PB push_back
    #define vc vector
    void chmax(int &x,const int y) {x=x>y?x:y;}
    void chmin(int &x,const int y) {x=x<y?x:y;}
    const int MAX_N=2e5+10;
    const ll MOD=1e9+7;
    void add(int &x,int y) {x+=y;if(x>=MOD) x-=MOD;if(x<0) x+=MOD;}

    int a[MAX_N];
    void main()
    {
        int n=qread(),M=qread();for(int i=1;i<=n*2;i++) a[i]=qread();sort(a+1,a+n+n+1);
        int l,r,A,B;
        l=1,r=n,A=0;
        while(l<=r)
        {
            int mid=(l+r)>>1;bool bk=0;
            for(int tl=1,tr=2*mid;tl<=tr;tl++,tr--) if(a[tl]+a[tr]>=M) {bk=1;break;}
            if(!bk) A=mid,l=mid+1;
            else r=mid-1;
        }
        l=0,r=n-1,B=n;
        while(l<=r)
        {
            int mid=(l+r)>>1;bool bk=0;
            for(int tl=mid*2+1,tr=2*n;tl<=tr;tl++,tr--) if(a[tl]+a[tr]<M) {bk=1;break;}
            // printf("l=%d r=%d mid=%d bk=%d\n",l,r,mid,bk);
            if(!bk) B=mid,r=mid-1;
            else l=mid+1;
        }
        if(B>A)
        {
            printf("A=%d B=%d\n",A,B);
        }
        else
        {
            int mx=0;
            for(int tl=1,tr=2*B;tl<=tr;tl++,tr--) chmax(mx,a[tl]+a[tr]);
            for(int tl=2*B+1,tr=2*n;tl<=tr;tl++,tr--) chmax(mx,a[tl]+a[tr]-M);
            write(mx);
        }
    }
};
int main()
{
    srand(time(0));
    mine::main();
}


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

int main(){
  int n;
  cin >> n;
  int a[n],b[n],c[n-1];
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];
  
  int points = 0;
  int prev = -100;
  rep(i,n){
    int index = a[i] - 1;
    points += b[index];
    if(index-prev == 1) points += c[prev];
    prev = index;
  }
  
  cout << points << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ll = long long;

ll gcd (ll x, ll y) {
  if (x % y == 0) return y;
  return gcd(y, x % y);
}

bool is_prime (ll n) {
  if (n == 1) return false;
  if (n == 2) return true;

  ll sqrtn = (ll) sqrt(n);

  for (ll i = 2; i <= sqrtn; i++) {
    if (n % i == 0) return false;
  }

  return true;
}

/**
 * main
 */
int main () {
  ll A; cin >> A;
  ll B; cin >> B;
  ll g = gcd(A, B);
  ll sqrtg = (ll) sqrt(g);

  set<ll> S;

  for (ll p = 1; p <= sqrtg; p++) {
    if (g % p != 0) continue;

    if (is_prime(p) || p == 1) {
      S.insert(p);
    }

    ll q = g / p;
    if (q > sqrtg && is_prime(q)) {
      S.insert(q);
    }
  }

#ifdef DEBUG
  printf("gcd=%lld\n", g);
  for (ll x : S) {
    printf("%lld ", x);
  }
  printf("\n");
#endif

  cout << S.size() << endl;
}


Measured memory_bytes: 256
a, b, c, x = int(input()), int(input()), int(input()), int(input())
ans = 0
for i in range(a+1):
    if(500*i > x):
        break
    for j in range(b+1):
        if(x - 500*i - 100*j >= 0 and (x - 500*i - 100*j) / 50 <= c):
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

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

	auto n = N;
	vector<char> list;
	while(n > 0) {
		n -= 1;
		const auto x = n % 26;
		n = n / 26;
		list.push_back('a' + x);
	}

	for(int i = list.size() - 1; i >= 0; i--) {
		cout << (char)list[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  string s[n];
  rep(i,n) R s[i];
  map<string,ll> m;
  ll ans=0;
  rep(i,n) {
    sort(all(s[i]));
    ans+=m[s[i]];
    m[s[i]]++;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 16640
n,k=map(int,input().split())
mo=1000000007
x=max(n-k,k)
dp=[[0 for i in range(k+2)] for j in range(x+1)]
dp[0][0]=1
for i in range(1,x+1):
    for  j in  range(1,k+2):
        dp[i][j]=(dp[i-1][j]+dp[i-1][j-1])%mo
for i in range(1,k+1):
    ans=dp[k][i]*(dp[n-k][i-1]+dp[n-k][i]*2+dp[n-k][i+1])
    print(int(ans%mo))

Measured memory_bytes: 77020
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int H, W, h, w;
		H = sc.nextInt();
		W = sc.nextInt();
		h = sc.nextInt();
		w = sc.nextInt();

		while (h > 0) {
			h--;
			H--;
		}

		while (w > 0) {
			w--;
			W--;
		}

		int ans = H*W;
		if (ans < 0) {
			System.out.println(0);
		} else {
			System.out.println(ans);
		}
	}

}


Measured memory_bytes: 35724
#include <iostream>
using namespace std;
typedef long long ll;
ll a[4001];

int main(){
	int n, num, p, q;
	while(cin >> n, n){
		fill(a, a+4001, 0);
		int f = 1;
		
		for(int i = 0;i < n;i++){
			cin >> num >> p >> q;
			a[num] += p * q;
			if(a[num]>999999)cout << num << endl, f = 0;
		}
		
		if(f)cout << "NA" <<endl;
	}
	return 0;
}

Measured memory_bytes: 3152
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N,T;
  cin >> N >> T;
  int c[N],t[N];
  for(int i = 0; i < N; i++){
    cin >>c[i]>>t[i];
  }
  int minCost = 2000;
  for(int i = 0; i < N; i++){
    if(t[i] <= T){
      if(minCost > c[i])
      minCost = c[i];
    }
  }
  if(minCost == 2000){
    cout << "TLE" << endl;
  }else{
    cout << minCost << endl;
  }
  
}

Measured memory_bytes: 256
D, G = [int(x) for x in input().split(" ")]

p = [0]
c = [0]

for i in range(D):
    pi, ci = [int(x) for x in input().split(" ")]
    p.append(pi)
    c.append(ci)

a = list()
for i in range(2**D):
    m = 0
    s = 0
    solves = 0
    for j in range(D):
        if i & (1<<j):
            s += 100 * (j+1) * p[j+1] + c[j+1]
            solves += p[j+1]
        else:
            if m < j+1:
                m = j+1

    if s < G:
        for j in range(1, p[m]):
            s += 100 * m
            solves += 1
            if s >= G:
                break

    if s >= G:
        a.append(solves)

print(min(a))


Measured memory_bytes: 3188
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<char> Vc;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;
typedef vector<vector<char>> VVc;
typedef vector<vector<vector<ll>>> VVV;
typedef vector<vector<vector<vector<ll>>>> VVVV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define rEach(i, mp) for (auto i = mp.rbegin(); i != mp.rend(); ++i)
#ifdef LOCAL
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define dbgarrmint(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j].x<<" ";}cerr<<endl;}
#else
#define dbg(...)
#define dbgmap(...)
#define dbgarr(...)
#define dbgdp(...)
#define dbgmint(...)
#define dbgarrmint(...)
#endif
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int solve(){
    ll n;
    cin>>n;
    ll ans = n;
    ans += n*n;
    ans += n*n*n;
    cout<<ans<<endl;
    return  0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);
    solve();
}


Measured memory_bytes: 3600
class BIT():
    def __init__(self,n):
        self.BIT=[0]*(n+1)
        self.num=n

    def query(self,idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def update(self,idx,x):
        while idx <= self.num:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return

N=int(input())
a=[list(map(int,input().split())) for i in range(3)]
odd=[]
even=[]
for i in range(N):
    x,y,z=a[0][i],a[1][i],a[2][i]
    if x<z:
        if y!=x+1 or z!=y+1:
            print("No")
            exit()
        else:
            if i%2==0:
                if x%6==1:
                    even.append(x//6+1)
                else:
                    print("No")
                    exit()
            else:
                if x%6==4:
                    odd.append(x//6+1)
                else:
                    print("No")
                    exit()
    else:
        if y!=x-1 or z!=y-1:
            print("No")
            exit()
        else:
            if i%2==0:
                if z%6==1:
                    even.append(-(z//6)-1)
                else:
                    print("No")
                    exit()
            else:
                if z%6==4:
                    odd.append(-(z//6)-1)
                else:
                    print("No")
                    exit()

oddsign=0
ODD=[(abs(odd[i]),i) for i in range(len(odd))]
ODD.sort()
for i in range(len(odd)):
    val,id=ODD[i]
    check=(id-i)%2
    if check==1:
        oddsign+=(odd[id]>0)
    else:
        oddsign+=(odd[id]<0)

evensign=0
EVEN=[(abs(even[i]),i) for i in range(len(even))]
EVEN.sort()
for i in range(len(even)):
    val,id=EVEN[i]
    check=(id-i)%2
    if check==1:
        evensign+=(even[id]>0)
    else:
        evensign+=(even[id]<0)

oddbit=BIT(len(odd))
check=0
for i in range(len(odd)):
    v=abs(odd[i])
    check+=i-oddbit.query(v)
    oddbit.update(v,1)

if check%2!=evensign%2:
    print("No")
    exit()

evenbit=BIT(len(even))
check=0
for i in range(len(even)):
    v=abs(even[i])
    check+=i-evenbit.query(v)
    evenbit.update(v,1)

if check%2!=oddsign%2:
    print("No")
    exit()

print("Yes")


Measured memory_bytes: 104332
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

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

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool up_min(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool up_max(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_mdvector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_mdvector(int n, Ts ... ts){
        return vector<decltype(make_mdvector(ts...))>(n, make_mdvector(ts...));
    }

    inline ll bit(int x){
        return 1ll << x;
    }

    template<class T>
    istream& operator>>(istream& is, vector<T>& v){
        for (auto &&x : v) { is >> x; } return is;
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    ll N;
    void run();
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef XELMH
    string test_cases = "test_A.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


void solver::run(){
    vector<string> days{"SUN", "MON","TUE","WED","THU","FRI","SAT"};
    vector<int> ans{7, 6,5,4,3,2,1};
    string in;
    is >> in;
    for (int i = 0; i < days.size(); ++i) {
        if(in[0] == days[i][0] and in[1] == days[i][1]){
            os << ans[i] << endl;
            return;
        }
    } // end i
}


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

int main(){
  int n,m;
  vector< pair<int,int> > a;

  cin >> n;
  while(n--){
    int k,g;
    cin >> k >> g;
    a.push_back(make_pair(k,g));
  }

  cin >> m;
  while(m--){
    int k,g;
    cin >> k >> g;
    a.push_back(make_pair(k,g));
  }

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

  for(size_t i=0;i<a.size();i++){
    printf("%d:%02d",a[i].first,a[i].second);
    if(i+1==a.size())putchar('\n');
    else putchar(' ');
  }
}

Measured memory_bytes: 1200
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll> ps(N);
  for (auto i = 0; i < N; i++) cin >> ps[i];
  sort(ps.begin(), ps.end());
  ll res = 0;
  for (auto i = 0; i < N-1; i++) res += ps[i];
  res += ps[N-1] / 2;

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main() {
    int q; cin >> q;
    priority_queue<ll> left;
    priority_queue<ll, vector<ll>, greater<ll>> right;
    ll lsum = 0;
    ll rsum = 0;
    ll b_sum = 0;
    while(q--) {
        int type;
        cin >> type;
        if(type == 1) {
            ll a, b;
            cin >> a >> b;
            b_sum += b;
            if(left.empty()) {
                left.push(a);
                lsum += a;
            }
            else if(left.size() > right.size()) {
                if(a < left.top()) {
                    // left.top()をrightに移す
                    lsum -= left.top(); rsum += left.top();
                    right.push(left.top()); left.pop();
                    // aをleftに
                    lsum += a; left.push(a);
                }
                else {
                    right.push(a); rsum += a;
                }
            }
            else if(left.size() <= right.size()) {
                if(a <= right.top()) {
                    lsum += a; left.push(a);
                }
                else {
                    // right.top()をleftに移す
                    lsum += right.top(); rsum -= right.top();
                    left.push(right.top()); right.pop();
                    // aをrightに
                    rsum += a; right.push(a);
                }
            }
        }
        if(type == 2) {
            ll res = b_sum;
            ll med = left.top();
            res += rsum - med * (int)right.size();
            res += med * (int)left.size() - lsum;
            printf("%lld %lld\n", med, res);
        }
    }
    return 0;
}


Measured memory_bytes: 4976
#include<cstdio>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
    int a,b;
    char ch;
    while(scanf("%d %c %d",&a,&ch,&b)!=EOF)
    {
        if(ch=='+') printf("%d\n",a+b);
        else printf("%d\n",a-b);
    }
    return 0;
}

Measured memory_bytes: 128
n,k = [int(i) for i in input().split()]

ans=0
one = 0
three = 0
six = 0

th = n%k
roop = (n//k)
if k%2==0:
    semiroop = roop +(1 if th>=k/2 else 0)
else:
    semiroop = 0
rp=roop
one = rp
three = rp*(rp-1)
six = rp*(rp-1)*(rp-2)
#ans += one + 3*(three) + 6*(six)
ans += rp**3
rp = semiroop
one = rp
three = rp*(rp-1)
six = rp*(rp-1)*(rp-2)
#ans += one + 3*(three) + 6*(six)
ans+=rp**3
print(ans)


Measured memory_bytes: 3064
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int[] H = new int[N+1]; 
     for (int i=1;i<N+1;i++){
       H[i]= scan.nextInt();
     }
    
    int count =0;
    int best=0;
    for (int j=	1;j<N;j++){
     if(H[j]>=H[j+1]) {
       count ++;
     }else{
       if(best<count) best=count;
       count =0;
     }
    }
    if(best<count) best=count;
  
    System.out.println(best);
  
  }
 
}

Measured memory_bytes: 49828
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    d = defaultdict(int)
    for _ in range(n):
        si = input()
        d[si[0]] += 1
    dn = {0:"M",1:"A",2:"R",3:"C",4:"H"}
    ans = 0
    for j in itertools.combinations(range(5),3):
        ans += d[dn[j[0]]]*d[dn[j[1]]]*d[dn[j[2]]]
    print(ans)
    return None

if __name__ == '__main__':
    main()


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

typedef struct {
  int id;
  int dest;
  int color;
} Edge;

typedef struct {
  int id;
  vector<Edge> edges;
} Node;

int ncolor;
vector<pair<int, int> > colors;
Node nodes[110000];

bool comb(pair<int, int> lhs, pair<int, int> rhs)
{
  return lhs.first < rhs.first;
}

void dfs(int nid, int color, int prev){
  //printf("node:%d incoming edge color:%d (from %d)\n", node.id, color, prev);
  Node node = nodes[nid];
  if(node.edges.size()==0) return;
  int cnt = 1;
  for(auto e:node.edges){
    if(e.dest != prev ) {
      e.color = ( color + cnt ) % ncolor;
      colors.emplace_back(e.id, e.color);
      dfs(e.dest, e.color, nid);
      cnt++;
    }
  }
  return;
}

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

  rep(i,N) {
    nodes[i].id = i;
  }

  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    nodes[a].edges.push_back((Edge){i, b, 0});
    nodes[b].edges.push_back((Edge){i, a, 0});
  }

  ncolor = 0;
  for(auto n:nodes){
    int m = n.edges.size();
    ncolor = max(m, ncolor);
  }
  cout << ncolor << endl;

  dfs(0, ncolor-1, -1);

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

  for(auto it: colors) {
    cout << it.second + 1<< endl;
  }

}



Measured memory_bytes: 13304
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i= 0; i<n; i++){
			a[i] = sc.nextInt();
		}
		int ans = 0;
		for(int i=0; i<n; i++){
			if(a[a[i]-1]-1 == i){
				ans++;
			}
		}
		System.out.println(ans/2);
	}

}

Measured memory_bytes: 46592
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, a[100005] = {}, b, c = 0;
    cin >> n;
    fr(n) {
        cin >> b;
        if (b <= 100000) a[b]++;
    }
    fr1(100000) if (a[i] >= i) c += i;
    cout << n - c;
}


Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  
  int sa, x, y = 0;
  x = N / 2 - 1;
  y = N / 2;
  
  vector<int> d(N);
  
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);    
  }
  
  sort(d.begin(), d.end());
  
  sa = d.at(y) - d.at(x);
  
  cout << sa << endl;
  //cout << x << endl;
  //cout << y << endl;
  
}

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

int main()
{
	int n;
	cin >> n;
	int d = floor(log10(n) + 1);
	int m = 1;
	for (int k = 0; k < d - 1; k++)  m *= 10;

	int s = 0;
	int i = 1;
	int t = 9;
	while (i < d) {
		s += t;
		t *= 100;
		i += 2;
	}
	if (d % 2 == 0) {
		cout << s << endl;
	}
	else {
		cout << s + (n - m) + 1 << endl;
	}

}

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

typedef long long int llint;

int main()
{
  int n, k;
  cin>> n >> k;

  llint c0 = n / k;
  llint c2 = 0;
  for(int i = 1; i <= n; i++) if(i % k == k / 2) c2++;

  if(k % 2)
    cout<< c0 * c0 * c0 <<endl;
  else
    cout<< c0 * c0 * c0 + c2 * c2 * c2 <<endl;
    
  return 0;
}


Measured memory_bytes: 256
def mypower x
    result = 1
    pminus2 = 1_000_000_005
    for i in 0..30
        result = (result * x) % 1_000_000_007 if pminus2[i] == 1
        x = (x * x) % 1_000_000_007
    end
    return result
end

def counting x, y
    arr = [1]
    count = 1
    y.times{|i|
        count *= (x + i + 1) % 1_000_000_007
        count *= mypower(i + 1) % 1_000_000_007
        count %= 1_000_000_007
        arr << count
    }
    return arr
end

h, w, a, b  = gets.chomp.split.map{|s| s.to_i}

right = b - 1
right2 = w - b - 1
leftbox = counting(right, h - a - 1)
rightbox = counting(right2, h - 1)

count = 0
for i in (0..(h - a - 1))
    count += (leftbox[i] * rightbox[h - i - 1]) % 1_000_000_007
    count %= 1_000_000_007
end
puts count


Measured memory_bytes: 3324
#include <iostream>

using namespace std;

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

    int A[200];
    int cnt, min;
    min = 30;
    for(int i = 0; i<N; i++){
        cin >> A[i];
        cnt = 0;
        while(true){
            if(A[i]%2 == 0){
                A[i] /= 2;
                cnt++;
            }else{
                 break;
            }
        }
        if(cnt<min){
            min = cnt;
        }
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int Q = 100100;
int a[Q], b[Q];

int main(void){
  int n, q;
  cin >> n >> q;
  REP(i, 0, q) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  VI t(n, 0);
  t[0] = 1;
  int pos = 0;
  REP(i, 0, q + 1) {
    if (pos >= 1) {
      t[pos - 1] = 1;
    }
    if (pos < n - 1) {
      t[pos + 1] = 1;
    }
    if (i < q) {
      swap(t[a[i]], t[b[i]]);
      if (pos == a[i]) {
	pos = b[i];
      } else if (pos == b[i]) {
	pos = a[i];
      }
    }
  }
  int cnt = 0;
  REP(i, 0, n) cnt += t[i] >= 1;
  cout << cnt << endl;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    vi cnta(n+1, 0), cntb(n+1, 0);
    vi a(n), b(n);
    rep(i, n){
        cin >> a[i];
        cnta[a[i]]++;
    }
    rep(i, n){
        cin >> b[i];
        cntb[b[i]]++;
    }
    rep(i, n+1){
        // cout << i << ": " << cnta[i] << " " << cntb[i] << endl;
        if(cnta[i] + cntb[i] > n){
            cout << "No" << endl;
            return;
        }
    }
    
    set<P, greater<P>> aa, bb;

    rep(i, n+1){
        if(cnta[i] > 0) aa.insert({cnta[i], i});
        if(cntb[i] > 0) bb.insert({cntb[i], -i});
    }

    // cout << aa.size() << " " << bb.size() << endl;
    
    vvi ans(n+1);
    while(!aa.empty()){
        auto ita = aa.begin();
        int cnta = ita->fi;
        int ida = ita->se;
        auto itb = bb.begin();
        int cntb = itb->fi;
        int idb = itb->se;
        if(ida != -idb){
            ans[ida].pb(idb);
            bb.erase(itb);
            if(cntb >= 2) bb.insert({cntb-1, idb});
            // cout << "case1: " << ida << " " << cnta << ": " << idb << " " << cntb << endl;
        }else{
            itb++;
            cntb = itb->fi;
            idb = itb->se;
            ans[ida].pb(idb);
            bb.erase(itb);
            if(cntb >= 2) bb.insert({cntb-1, idb});
            // cout << "case2: " << ida << " " << cnta << ": " << idb << " " << cntb << endl;
        }
        aa.erase(aa.find({cnta, ida}));
        if(cnta >= 2) aa.insert({cnta-1, ida});
    }
    
    cout << "Yes" << endl;
    rep(i, n){
        int sz = ans[a[i]].size();
        // cout << "debug: " << i << " " << a[i] << endl;
        for(auto x : ans[a[i]]){
            cout << abs(x) << " ";
        }
        i += sz-1;
    }
    
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

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

const int N = 110;
string a[N];

int main()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	int n, l;
	cin >> n >> l;
	for (int i = 1; i <= n; i ++ )
		cin >> a[i];
	sort (a + 1, a + 1 + n);
	for (int i = 1; i <= n; i ++ )
		cout << a[i];
	cout << '\n';
	
	return 0;
}

Measured memory_bytes: 3624
# import itertools
# import pprint

sw,lb  = map(int,input().split())
swbit  = [0]*sw
ans,p  = 0,0

for i in range(lb):
  li  = list(map(int,input().split()))
  num = li.pop(0)

  for j in li:
    swbit[j-1] |= 0b1 << i

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

for i in range(lb):
  p |= plist[i] << i

for i in range(0b1<<sw):
  
  status = 0

  for j in range(sw):
    if (i >> j) & 1 :
      status ^= swbit[j]
  
  if p == status:
    ans += 1

print(ans)


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

int main() {
  string s;
  string sfh;
  int q;
  int qs;
  int rvc=0;
  string c;

  cin >> s >> q;

  for(int i=0;i<q;i++) {
    cin >> qs;
    if(qs==1){
      rvc++;
    }
    else if(qs==2){
      cin >> qs;
      cin >> c;
      if(rvc%2==1) {
        if(qs==1) qs=2;
        else qs=1;
      }
      if(qs==1) {
        sfh += c;
      }
      else if(qs==2) {
        s += c;
      }
      else {exit(EXIT_FAILURE);}
    }
    else {exit(EXIT_FAILURE);}
  }

  reverse(sfh.begin(),sfh.end());

  sfh = sfh + s;

  if(rvc%2==1) reverse(sfh.begin(),sfh.end());

  cout << sfh << endl;

  return 0;
}


Measured memory_bytes: 1148
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

map<string, vector<string>> m;
map<string, int> id;
void parse(string s, int _id){
	int n = s.size();
	string gr;
	vector<string> mem;
	int idx = 0;
	rep(i, s.size()){
		if (s[i] < 'a' || s[i] > 'z'){
			if (!idx) gr = s.substr(0, i);
			else mem.push_back(s.substr(idx, i-idx));
			idx = i + 1;
		}
	}
	m[gr] = mem;
	id[gr] = _id;
}

vector<int> G[110];
int ok[110];
void dfs(int v){
	ok[v] = 1;
	for (auto nxt : G[v]){
		if (ok[nxt]) continue;
		dfs(nxt);
	}
}

int main(){
	int n;
	while (cin >> n, n){
		m.clear();
		id.clear();
		rep(i, n){
			string s;
			cin >> s;
			parse(s, i);
		}

		rep(i, 110) G[i].clear();
		set<string> ss;
		for (auto p : m){
			for (auto str : p.second){
				if (!id.count(str)) continue;
				G[id[p.first]].push_back(id[str]);
			}
		}

		MEMSET(ok, 0);
		dfs(0);
		for (auto p : m){
			if (!ok[id[p.first]]) continue;
			for (auto str : p.second){
				if (m.count(str)) continue;
				ss.insert(str);
			}
		}
		cout << ss.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1376
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

COUNT = 0

for i in range(N):
    if A[len(A)-i-1] >= B[len(B)-i-1]:
        COUNT = COUNT + B[len(B)-i-1]
        B[len(B)-i-1] = 0
        
    else:
        COUNT = COUNT + A[len(A)-i-1]
        X = B[len(B)-i-1] - A[len(A)-i-1]
        B[len(B)-i-1] = X
        
        if A[len(A)-i-2] >= B[len(B)-i-1]:
            COUNT = COUNT + B[len(B)-i-1]
            A[len(A)-i-2] = A[len(A)-i-2] - X
        else:
            COUNT = COUNT + A[len(A)-i-2]
            A[len(A)-i-2] = 0
        

print(COUNT)

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


int main() {
	long long a, b, c, d;cin >> a >> b >> c >> d;
	long long lc = c*d/__gcd(c, d);
	long long k1 = b-a+1-(b/c - (a-1)/c + b/d - (a-1)/d - (b/lc - (a-1)/lc));
	cout << k1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define Rep(i, n, a) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, n, 0)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    vector<P> a;
    rep(i, n)
    {
        int aa;
        cin >> aa;
        a.push_back(P{aa, i});
    }
    sort(all(a));
    set<int> st;
    st.insert(-1);
    st.insert(n);
    ll ans = 0;
    rep(i, n)
    {
        st.insert(a[i].second);
        auto it = st.find(a[i].second);
        it++;
        int r = *it;
        it--;
        it--;
        int l = *it;
        ans += (ll)a[i].first * (ll)(r - a[i].second) * (ll)(a[i].second - l);
    }
    cout << ans << endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for (int i = A; i <= B; ++i) {
    string s1 = to_string(i);
    string s2 = s1;
    reverse(s2.begin(), s2.end());
    if (s1 == s2) {
      ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i,n,N) for(ll i=(n);i<(N);i++)
#define RREP(i,n,N) for(ll i=(N-1);i>=(n);i--)
#define p(s) cout<<(s)<<endl
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;
ll N;
ll x[110], y[110];
ll carty[4], cartx[4];
ll cxs, cxb, cys, cyb;
ll compfield[40010][110];
int main(){
    while(cin>>N && N != 0){
        vector<ll> vx;
        REP(i,0,N + 4){
            cin>>x[i]>>y[i];
            vx.push_back(x[i]);
            if(i >= N){
                cartx[i - N] = x[i];
                carty[i - N] = y[i];
            }
        }
//        ll test[110];
//        memcpy(test, x, sizeof(test));
        //cout<<"========"<<endl;
        /*
        REP(i,0,N){
            cout<<x[i]<<", "<<y[i]<<endl;
        }*/
        //カーテンの座標
        sort(cartx, cartx+4);
        sort(carty, carty+4);
        cxs = cartx[0];
        cxb = cartx[3];
        cys = carty[0];
        cyb = carty[3];
        //
        //cout<<"test1"<<endl;
        //座圧
        sort(vx.begin(), vx.end());
        vx.erase(unique(vx.begin(), vx.end()), vx.end());
        //
        //cout<<"test___1___1"<<endl;
        map<ll, ll> xzip;
        map<ll, ll> xunzip;
        //
        //cout<<"test___1___2"<<endl;
        REP(i,0,vx.size()){
            xzip[vx[i]] = i;
            xunzip[i] = vx[i];
            //p(xunzip[i]);
        }
        //
        //cout<<"test2"<<endl;
        //窓の頂点チェック
        //初期化
        REP(i,0,40010){
            REP(j,0,110){
                compfield[i][j] = 0;
            }
        }
        //
        //cout<<"test3"<<endl;
        REP(i,1,N){
            if(y[i] - y[i-1] < 0){
                REP(j,y[i] + 20000, y[i-1] + 20000) compfield[j][ xzip[x[i]] ]++;  //yが異なるならxは必ず同じ
            }else if(y[i] - y[i-1] > 0){
                REP(j,y[i-1] + 20000, y[i] + 20000) compfield[j][ xzip[x[i]] ]--;
            }
        }
        if(y[0] - y[N-1] < 0){
            REP(j,y[0] + 20000, y[N-1] + 20000) compfield[j][ xzip[x[0]] ]++;  //yが異なるならxは必ず同じ
        }else if(y[0] - y[N-1] > 0){
            REP(j,y[N-1] + 20000, y[0] + 20000) compfield[j][ xzip[x[0]] ]--;
        }

        //
        //cout<<"test4"<<endl;
        //塗る
        REP(i,0,40010){
            REP(j,1,xzip.size()){
                compfield[i][j] += compfield[i][j-1];
            }
        }


        //カーテンチェック
        REP(i,cys+20000,cyb+20000){
            REP(j,xzip[cxs],xzip[cxb]){
                //cout<<i<<", "<<j<<endl;
                compfield[i][j] = 0;    //カーテンで覆われている。
            }
        }

        ll ans = 0;
        REP(i,0,40010){
            REP(j,0,xzip.size()-1){
                if(compfield[i][j] > 0){
                    ans += xunzip[j+1] - xunzip[j];
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

int main() {
  int N, D;
  cin >> N;
  cin >> D;
  vector<vector<long>> v(N, vector<long>(2));
  for(int i = 0; i < N; i++){
  	cin >> v.at(i).at(0);
    cin >> v.at(i).at(1);
  }
  int count = 0;
  for(int i = 0; i < N; i++){
  	if(D >= sqrt(v.at(i).at(0)*v.at(i).at(0) + v.at(i).at(1)*v.at(i).at(1))) count++;
  }
  cout << count << endl;
  return 0;
}




Measured memory_bytes: 14144
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;

    int m = 2 * d + 1;
    int ans = (n + m - 1) / m;
    cout << ans << endl;

    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

const int N=1e5+5;
const int mod=1e9+7;

int32_t main() {
string a,b;
cin>>a>>b;
int n=a.size()+b.size();
int aIdx=0,bIdx=0;
FOR(i,1,n){
    if(i%2==0)cout<<b[bIdx++];
    else cout<<a[aIdx++];
}
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
N, M = map(int, input().split())
X = []
s = 0
for _ in range(N):
    b, l, u = map(int, input().split())
    t = M * u - (u - l) * b
    X.append((t, b, l, u))
    s += b * l

X = sorted(X, key = lambda x: -x[0])
A = [0] + [x[0] for x in X]
for i in range(1, N+1):
    A[i] += A[i-1]

def sum_excl(i, j):
    return A[j] if j <= i else A[j] - X[i][0]

def chk(i):
    t, bb, ll, uu = X[i]
    l, r = -1, N + 1
    while r - l > 1:
        m = (l + r) // 2
        if sum_excl(i, m) + t >= s:
            r = m
        else:
            l = m
    re = (r - (i < r)) * M
    rem = s - sum_excl(i, r)
    l, r = -1, M + 1
    while r - l > 1:
        m = (l + r) // 2
        if (m * uu - (uu - ll) * bb if m > bb else m * ll) >= rem:
            r = m
        else:
            l = m
    re += r
    return re

print(min(chk(i) for i in range(N)))

Measured memory_bytes: 71132