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

int main() {
  int H,W,count=0;
  cin >> H >> W;
  vector<vector<int>> V(H+2,vector<int>(W+2,-2));
  for(int i=1;i<=H;i++){
    string s;
    cin >> s;
    for(int j=1;j<=W;j++){
      if(s[j-1]=='.'){
        V[i][j] = -1;
        count++;
      }
    }
  }
  
  queue<pair<int,int>> Q;
  Q.push(make_pair(1,1));
  V[1][1] = 1;
  while(!Q.empty()){
    pair<int,int> u = Q.front();
    Q.pop();
    int x = u.first, y = u.second;
    if(V[x+1][y]==-1){
      V[x+1][y] = V[x][y]+1;
      Q.push(make_pair(x+1,y));
    }
    if(V[x][y+1]==-1){
      V[x][y+1] = V[x][y]+1;
      Q.push(make_pair(x,y+1));
    }
    if(V[x-1][y]==-1){
      V[x-1][y] = V[x][y]+1;
      Q.push(make_pair(x-1,y));
    }
    if(V[x][y-1]==-1){
      V[x][y-1] = V[x][y]+1;
      Q.push(make_pair(x,y-1));
    }
  }
  
  if(V[H][W]!=-1) cout << count-V[H][W] << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, raw_input().split())
S = raw_input()
S_list = list(S)

c1 = 0
c2 = 0
for i in range(len(S_list)):
    if c1 < A+B and S_list[i] == 'a':
        c1 += 1
        print 'Yes'
    elif c1 < A+B and c2 < B and S_list[i] == 'b':
        c1 += 1
        c2 += 1
        print 'Yes'
    else:
        print 'No'
    

Measured memory_bytes: 31848
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
import numpy as np
def bisearch(t):
  dp=np.full(k,False)
  dp[0]=True
  for i in range(n):
    if i==t:continue
    dp[a[i]:] = np.logical_or(dp[a[i]:], dp[:-a[i]]) 
  return any(dp[max(0,k-a[t]):])
l,r=-1,n
while r-l>1:
  x=(l+r)//2
  if bisearch(x):
    r=x
  else:
    l=x
print(r)

Measured memory_bytes: 14492
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  int n;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];
  FORR(i, n - 1, 1) cout << a[i] << " ";
  cout << a[0] << endl;
}



Measured memory_bytes: 3112
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		L: for (;;) {
			int n = sc.nextInt();
			if (n == 0)
				return;
			String[][] sed = new String[n][2];
			for (int i = 0; i < n; i++) {
				sed[i][0] = sc.next();
				sed[i][1] = sc.next();
			}
			String from = sc.next();
			String to = sc.next();
			LinkedList<String> que = new LinkedList<String>();
			HashSet<String> set = new HashSet<String>();
			que.add(from);
			set.add(from);
			int cnt = 0;
			while (!que.isEmpty()) {
				int size = que.size();
				for (int i = 0; i < size; i++) {
					String s = que.poll();
					if (s.equals(to)) {
						System.out.println(cnt);
						continue L;
					}
					for (int j = 0; j < n; j++) {
						String m = s.replaceAll(sed[j][0], sed[j][1]);
						if (m.length() <= to.length() && !set.contains(m)) {
							que.add(m);
							set.add(m);
						}
					}
				}
				cnt++;
			}
			System.out.println(-1);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 61232
#include <algorithm>
#include <bitset>
#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 <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

int N, A, B, X[100005];

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

    cin >> N >> A >> B;
    REP(i, N)
        cin >> X[i];

    int ans = 0;
    REP(i, N - 1)
    {
        ans += min(A * (X[i + 1] - X[i]), B);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
int k,n;
  cin>>k>>n;
  int r[n];
  for(int i=0;i<n;i++)
  {cin>>r[i];
  }
  int max=r[0];
  for(int i=0;i<n-1;i++)
  {
    if((r[i+1]-r[i])>max)max=r[i+1]-r[i];
  }
  int t=k+r[0]-r[n-1];
  if (t>max)max=t;
  cout<<(k-max);
  return 0;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	
	k := len(s)
	cnt := 0
	for i := 0; i < k; i++ {
		if s[i] == 'o' {
			cnt++
		}
	}
	if 15 - k >= 8 - cnt {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 512
H,W,A,B = map(int, input().split())
s1 =''
s2 =''
str1 = '0'
str2 = '1'
for i in range(0,A):
  s1 += str1
  s2 += str2

for j in range(A,W):
  s1 += str2
  s2 += str1

for p in range(0,B):
  print(s1)

for p in range(B,H):
  print(s2)

Measured memory_bytes: 3956
#include<iostream>
#include<map>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<vector>
#include<cstring>
#include<sstream>
#include<algorithm>
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;

#define MOD 1000000007

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

    int n;
    cin >> n;

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

        verdict[s] ++;
    }

    string res[] = {"AC", "WA", "TLE", "RE"};
    for (auto r : res) {
        cout << r << " x " << verdict[r] << endl;
    }

    return 0;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    if(a == b) cout << 'H' << endl;
    else cout << 'D' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>

int main(){

  int n;
  cin>>n;
  vi data(n);
  rep(i,n){
    int tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  sort(data.begin(),data.end());
  
  int mindata=data.at(0);
  int maxdata=data.at(n-1);
  
  int answer=-1;
  
  for (int i=mindata;i<=maxdata;i++){
    int dis=0;
    rep(j,n){
      dis+=pow(i-data.at(j),2);
    }
    
    if (answer==-1){
      answer=dis;
    }
    else {
      answer=min(answer,dis);
    }
  }

  
  
  cout<<answer<<endl;
  
  
  
}



Measured memory_bytes: 256
//AtCoder Beginner Contest 087
//B - Coins

#include <iostream>

using namespace std;

int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;

    int count = 0;

    for(int i=0;i<=a;i++){
        int sum1 = 500*i;
        if(sum1 <= x){
            for(int j=0;j<=b;j++){
                int sum2 = sum1 + 100*j;
                if(sum2 <= x){
                    int c_num = (x - sum2)/50;
                    if(c_num <= c) count++;
                }else{
                    break;
                }
            }
        }else{
            break;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    import bisect
    n,m = map(int,input().split())
    d = [[] for i in range(n)]
    ans = [0 for i in range(m)]
    for i in range(m):
        p,y = map(int,input().split())
        d[p-1].append((y,i))
    for i,d_ in enumerate(d):
        d_.sort()
        for c, d__ in enumerate(d_):
            ans[d__[1]] = str(i+1).zfill(6) + str(c+1).zfill(6)
    for i in range(m):
        print(ans[i])

if __name__ == "__main__":
    main()


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

using namespace std ;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll ;
typedef vector<int> vint;
typedef vector<double> vdbl ;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int,int>> vpii ;
typedef vector<pair<ll,ll>> vpll ;
typedef priority_queue<int, vector<int>, greater<int>> spqint ; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll ; //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint ; //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll ; //大きい順に取り出し


#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define IREP(i,v) for(auto i=v.begin(); i !=v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(),(v).end()
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}
//-----------------------------------------




















//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int  n ;
  cin >> n ;
  set<string> S ;
  REP(i,n){
    string s ;
    cin >> s ;
    S.insert(s) ;
  }
  cout << SZ(S) <<endl ;
  
  
  
  return 0 ;
}




Measured memory_bytes: 19292
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ll a[n+1];
	rep(i,1,n+1) cin >> a[i];

	ll cnt=0;
	rep(i,1,n+1){
		if(a[i]!=i) cnt++;
	}
	//trace1(cnt);
	if(cnt==0 || cnt==2) cout << "YES";
	else cout << "NO";
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
import sys
# input = sys.stdin.readline
inf = 10 ** 18

M, K = map(int, input().split())

tmp = 0
notK = []
for i in range(1 << M):
    if i == K: continue
    tmp ^= i
    notK.append(i)
if K == 0:
    ans = []
    for i in range((1 << M)):
        ans.append(i)
    for i in range((1 << M)):
        ans.append((1 << M) - 1 - i)
    #
    for i, ansi in enumerate(ans):
        if i > 0: print(' ', end='')
        print(ansi, end='')
    print()
elif tmp != K:
    print(-1)
else:
    ans = []
    ans.append(notK[0])
    ans.append(K)
    ans.append(notK[0])
    for i in range(1, (1 << M) - 1):
        ans.append(notK[i])
    ans.append(K)
    for i in range(1, (1 << M) - 1):
        ans.append(notK[(1 << M) - 1 - i])
    #
    for i, ansi in enumerate(ans):
        if i > 0: print(' ', end='')
        print(ansi, end='')
    print()

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

int main()
{
	array<int, 6> d;
	map<int, int> m;
	array<string, 6> tbl = {"X2413X","3X05X2","15XX04","40XX51","2X50X3","X3142X"};

	int q = 0, t, f;
	for (int &x : d) {
		cin >> x;
		m[x] = q++;
	}
	cin >> q;
	while (q-- && cin >> t >> f)
		cout << d[tbl[m[t]][m[f]] - '0'] << endl;

	return 0;
}


Measured memory_bytes: 3112
import bisect
x,n=map(int,input().split())
l=list(map(int,input().split()))
k=[0]*(102)
for i in l:
    k[i]=1
s=10000
for i in range(102):
    if k[i]==1:
        continue
    if abs(x-i)<s:
        s=abs(x-i)
        ans=i
print(ans)
    


Measured memory_bytes: 9192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		char[] c = sc.next().toCharArray();
		char b = c[0];
		int ans = 1;
		for(int i = 1; i < n; i++) {
			if(b != c[i]) {
				ans++;
			}
			b = c[i];
		}
		System.out.println(ans);
	}


	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

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

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        int n,k;
        cin>>n>>k;
        int state[k+1];
        state[0] = 2;
        int a[n];
        rep(i,0,n) cin>>a[i];
        rep(i,1,k+1){
            rep(j,0,n){
                if(a[j]>i) break;
                if(state[i-a[j]]==2){
                    state[i] = 1;
                    goto ou;
                }
            }
            state[i] = 2;
            ou:;
        }
        if(state[k]==1) cout<<"First";
        else cout<<"Second";
    }   
}     

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

using namespace std;

int main(){
  string S;
  int Q;
  cin >> S >> Q;
  
  string a1, a2;
  bool bReverse = false;
  for (int i = 0; i < Q; i++){
    int T;
    cin >> T;
    
    if (T == 1){
      bReverse = !bReverse;
    }
    else if (T == 2){
      int F;
      string C;
      cin >> F >> C;
      string &targetS = ((F == 1 && !bReverse) || (F == 2 && bReverse)) ? a1 : a2;
      targetS += C;
    }
  }
  
  string ret;
  if (bReverse){
    reverse(S.begin(), S.end());
    reverse(a2.begin(), a2.end());
    ret = a2 + S + a1;
  }else{
    reverse(a1.begin(), a1.end());
    ret = a1 + S + a2; 
  }
  
  cout << ret;
  return 0;         
}

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

#define sc(x) scanf("%d",&x);
#define rep(x ,n) for(int x=0; x<n; x++)
#define ll long long
#define finish(x) return cout << x << endl,0;
#define scarr(a,n) for(int x=0; x<n; x++)scanf("%d",&a[x]);

int main()
{
    string s;
    cin >> s;
    sort(s.begin() ,s.end());
    if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
        finish("Yes");
    finish("No");
}


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

int main(){
    int n;
    cin >> n;
    int num[4];
    for(int i = 0; i < 4; i++){
        num[i] = n % 10;
        n /= 10;
    }

    if((num[0] == num[1] && num[1] == num[2]) || (num[1] == num[2] && num[2] == num[3])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int X,A,B;
    cin >> X >> A >> B;
    X-=A;
    X%=B;
    cout << X << endl;
    return 0;
}

Measured memory_bytes: 256
class Node:
    def __init__(self, node_id, left_child, right_child):
        self.node_id = node_id
        self.parent = -1
        self.sibling = -1
        self.degree = 0
        self.depth = 0
        self.height = 0
        self.node_type = ''

        self.left_child = left_child
        self.right_child = right_child
        

def binarytrees():
    def input_node_list():
        n = int(input())

        for i in range(n):
            node_id, left_child, right_child = list(map(int, input().split()))

            node = Node(node_id, left_child, right_child)
            node_list.append(node)

        node_list.sort(key = lambda node: node.node_id)

    def calc_parent_sibling_degree():
        if node.left_child != -1:
            node_list[node.left_child].parent = node.node_id
            node_list[node.left_child].sibling = node.right_child
            node.degree += 1

        if node.right_child != -1:
            node_list[node.right_child].parent = node.node_id
            node_list[node.right_child].sibling = node.left_child
            node.degree += 1

    def calc_depth(node_id):
        if  node_list[node_id].parent == -1:
            return 0
        else:
            return calc_depth(node_list[node_id].parent) + 1

    def calc_height(node_id):
        if not node_list[node_id].degree:
            return 0
        else:
            return max(calc_height(node_list[node_id].left_child),
                calc_height(node_list[node_id].right_child)) + 1

    def calc_node_type():
        if node.depth == 0:
            node.node_type = 'root'
        elif node.height == 0:
            node.node_type = 'leaf'
        else:
            node.node_type = 'internal node'

    def show_node_info():
        print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'
            .format(node.node_id, node.parent, node.sibling,
            node.degree, node.depth, node.height, node.node_type))

    node_list = []
    input_node_list()

    for node in node_list:
        calc_parent_sibling_degree()

    for node in node_list:
        node.depth = calc_depth(node.node_id)
        node.height = calc_height(node.node_id)

        calc_node_type()

        show_node_info()


if __name__ == '__main__':
    binarytrees()

Measured memory_bytes: 7832
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
import math


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def gcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    ret = math.factorial(x)
    ret = ret // (math.factorial(x - y) * math.factorial(y))

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


def main():
    n = intin()

    print((n - 2) * 180)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
int n , k , r , s , p , ans;
bool yes[N];
int main() {
    abdelrahman010
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    for(int i = 0;i < n;i++) {
        if(i >= k && t[i] == t[i - k] && yes[i % k]) {
            yes[i % k] = false;
            continue;
        }
        yes[i % k] = true;
        if(t[i] == 'r')
            ans += p;
        else if(t[i] == 'p')
            ans += s;
        else
            ans += r;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 592
k = int(input())
a, b = map(int, input().split())

tmp = 0
num = 0
res = False
while(tmp < b):
    num += 1
    tmp = k*num
    if tmp==a or tmp==b or a <= tmp <= b:
        res = True
        break

if res:
    print('OK')
else:
    print('NG')

Measured memory_bytes: 9180
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const ll MOD = 1e9 + 7;

string s;
int n;

ll cc[100];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> s;
	for (char c: s)
		++cc[c - 'a'];
	ll ans = 1;
	for (int i = 0; i < 26; ++i)
		ans = (ans * (cc[i] + 1)) % MOD;
	ans -= 1;
	if (ans == -1)
		ans += MOD;
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
long long sum,r[40][100010];

int solve(int s, int t){
    int i,k;
    for(int i=0;i<40;i++){
        if(r[i][s]>=t){
            k = i;
            break;
        }
    }
    if(k==0){
        return sum;
    }else{
        sum += pow(2,k-1);
        solve(r[k-1][s],t);
    }
}

int main(){
    int i,j,n,q,s,t;
    vector<long long> a,b;
    long long x,l;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x;
        a.push_back(x);
    }
    cin >> l >> q;
    for(i=0;i<n;i++){
        int y = upper_bound(a.begin(),a.end(),a[i]+l)-a.begin()-1;
        b.push_back(y);
    }
	
    for(i=0;i<40;i++){
        for(j=0;j<n;j++){
            if(i==0){
                r[i][j] = b[j];
            }else{
            r[i][j] = r[i-1][r[i-1][j]];
            }
        }
    }
    
    for(i=0;i<q;i++){
        cin >> s >> t;
        if(s>t){
            int z = s;
            s = t;
            t = z;
        }
        s--; t--;
        sum = 1;
        solve(s,t);
        cout << sum << endl;
    }
}


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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N;
  while(cin>>N){
    int h[500];
    ll ans = 1;
    REP(i, N) cin>>h[i];
    for(int i = 1; i <= 125; i++){
      int cnt = 0;
      for(int j = 0; j < N; j++){
        if(h[j] >= i) cnt++;
      }
      ans += min(4 * i, cnt);
    }
    for(int i = 0; i < N; i++){
      if(h[i] > 125) ans += h[i] - 125;
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    string s;
    cin >>s;
    int l=s.length();
    stack<char> st;

    for (int i = 0; i < l; i++){
        if(st.empty() && s[i]=='T'){
            ans++;
        }else if(s[i]=='T'){ 
            st.pop();
        }else if(s[i] == 'S'){
            st.push(s[i]);
        }

    }

    ans += st.size();

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 640
a, b, c, d = [int(x) for x in input().split()]
dp = [[0 for i in range(d + 1)] for j in range(c + 1)]
for i in range(a+1):
    for j in range(b+1):
        dp[i][j]=1
for i in range(a, c + 1):
    for j in range(b, d + 1):
        if i == a and j == b:
            continue
        if i - 1 >= a:
            dp[i][j] += (dp[i - 1][j] * j)
        if j - 1 >= b:
            dp[i][j] += (dp[i][j - 1] * i)
        if (i - 1) >= a and (j - 1) >= b:
            dp[i][j] -= dp[i-1][j-1]*(i-1)*(j-1)
        dp[i][j] %= 998244353

print(dp[c][d])


Measured memory_bytes: 146900
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct node {
    int id = -1;
    node* parent;
    node* left;
    node* right;
    int _depth = -1;
    int _height = -1;
    
    void setLeft(node* child) {
        this->left = child;
        child->parent = this;
    }
    void setRight(node* child) {
        this->right = child;
        child->parent = this;
    }
    
    bool is_root() const {
        return parent == NULL;
    }
    
    int depth() {
        if(_depth>=0) return _depth;
        if(parent==NULL) return _depth = 0;
        return _depth = parent->depth() + 1;
    }
    
    int height() {
        if(_height>=0) return _height;
        if(left==NULL && right==NULL) return _height = 0;
        if(left==NULL) return _height = right->height() + 1;
        if(right==NULL) return _height = left->height() + 1;
        return _height = max(left->height(), right->height()) + 1;
    }
    
    int parent_id() const {
        if(parent==NULL) return -1;
        return parent->id;
    }
    
    int sibling_id() const {
        if(parent==NULL) return -1;
        if(parent->left==NULL || parent->right==NULL) return -1;
        if(parent->left->id==this->id) return parent->right->id;
        if(parent->right->id==this->id) return parent->left->id;
        return -1;
    }
    
    int degree() const {
        return int(left!=NULL) + int(right!=NULL);
    }
    
    string type() const {
        if(parent==NULL) return "root";
        if(left==NULL && right==NULL) return "leaf";
        return "internal node";
    }
};

ostream& operator<<(ostream& os, node& e) {
    os << "node " << e.id << ": parent = " << e.parent_id() << ", sibling = " << e.sibling_id() << ", degree = " << e.degree() << ", depth = " << e.depth() << ", height = " << e.height() << ", " << e.type();
    return os;
}

void preorder(node* n) {
    cout << " " << n->id;
    if(n->left) preorder(n->left);
    if(n->right) preorder(n->right);
}

void inorder(node* n) {
    if(n->left) inorder(n->left);
    cout << " " << n->id;
    if(n->right) inorder(n->right);
}

void postorder(node* n) {
    if(n->left) postorder(n->left);
    if(n->right) postorder(n->right);
    cout << " " << n->id;
}

int main() {
    int n;
    cin >> n;
    vector<node> tree(n);
    for(int i=0; i<n; i++) {
        int id, l, r;
        cin >> id >> l >> r;
        tree[id].id = id;
        if(l>=0) tree[id].setLeft(&tree[l]);
        if(r>=0) tree[id].setRight(&tree[r]);
    }
    node* root;
    for(auto&& e : tree) if(e.is_root()) root = &e;
    cout << "Preorder" << endl;
    preorder(root);
    cout << endl;
    cout << "Inorder" << endl;
    inorder(root);
    cout << endl;
    cout << "Postorder" << endl;
    postorder(root);
    cout << endl;
    
    
}


Measured memory_bytes: 3104
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String input;
		input = sc.nextLine();
		String [] x = input.split("[ ]+");
		int n = Integer.parseInt(x[0]);
		int a = Integer.parseInt(x[1]);
		int b = Integer.parseInt(x[2]);
		if(n*a <= b) {
			System.out.println(n*a);
		}else {
			System.out.println(b);
		}
		sc.close();
	}
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

ll n , q , s , x , y;
ll a[MAXX];
ll p[MAXX];

int main()
{
    _FastIO;

    cin >> n;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        p[a[i]]++;
        s += a[i];
    }
    cin >> q;
    for(ll i = 0; i < q; i++){
        cin >> x >> y;
        ll k = y - x;
        s += (k * p[x]);
        p[y] += p[x];
        p[x] = 0;
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 5164
#include <stdio.h>

int main (void){
    int a[10000],b[10000],c[10000];
    char op[10000];
    int i,j;
    i=0;
    while(1){
        scanf("%d %c %d",&a[i],&op[i],&b[i]);
        if(op[i]=='+'){
            c[i] = a[i] + b[i];
        }
        else if(op[i]=='-'){
            c[i] = a[i] - b[i];
        }
        else if(op[i]=='*'){
            c[i] = a[i] * b[i];
        }        
        else if(op[i]=='/'){
            c[i] = a[i] / b[i];
        }
        else{
            break;
        }
        i++;
    }

    for(j=0;j<i;j++){
        printf("%d\n",c[j]);
    }

    return 0;
}


Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"
#define dint        long double

const int mod = 1e9+7;

inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }


void solve() {
    int n; cin >> n;
    dint a[n];
    int z = 0;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        z += (a[i] == 0);
    }
    if(z) {
        cout << 0 << endl; return;
    }
    dint ans = 1;
    dint lim = 1e18;
    for(int i=0; i<n; i++) {
        if(lim / ans < a[i]) {
            cout << -1 << endl; return;
        }
        ans *= a[i];
    }
    int op = ans;
    cout << op << endl;

}


signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);


    int T = 1;
    //cin >> T;

    while(T--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 5372
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#define LL long long
using namespace std;
LL N,A,B;
LL a[100005];
int main()
{
    int judge(LL x);
    scanf("%lld%lld%lld",&N,&A,&B);
    LL right=0;
    for(LL i=1; i<=N; i++)
    {
        scanf("%lld",&a[i]);
        right+=a[i]/B+1;
    }

    sort(a+1,a+1+N);
    LL left=1;
    while(left<right)
    {
        LL mid=(left+right)>>1;
        if(judge(mid)==1)
            right=mid;
        else
            left=mid+1;
    }
    printf("%lld\n",left);
    return 0;
}
int  judge(LL x)
{
    LL sum=0;
    LL b=x*B;
    LL c=A-B;
    for(LL i=1; i<=N; i++)
    {
        if(a[i]>b)
        {
            if((a[i]-b)%c)
                sum+=(a[i]-b)/c+1;
            else
                sum+=(a[i]-b)/c;
        }
    }
    if(sum<=x)
        return 1;
    else
        return 0;

}


Measured memory_bytes: 1024
#include<cstdio>
int a[105],b[105];
int main()
{
	int n,i,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",&a[i]);
	for(i=1;i<=n;++i)scanf("%d",&b[i]);
	for(i=2;i<=n;++i)a[i]+=a[i-1];
	for(i=n;--i;)b[i]+=b[i+1];
	for(i=1;i<=n;++i)if(a[i]+b[i]>ans)ans=a[i]+b[i];
	printf("%d",ans);
}

Measured memory_bytes: 128
K = int(input())
numbers = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(numbers[K-1])

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

int main(void)
{
	int  n;
	
	while(cin >> n, n){
		int a = 0;
		long long int ans = 0;
		int time[10000];
		for(int i = 0; i < n; i++){
			cin >> time[i];
		}
		
		sort(time, time + n);
		int temp = n;
		for(int j = 0; j < n-1; j++){
			a = 0;
			for(int ii = 0; ii < temp-1; ii++){
				a += time[ii];
			}
			ans += a;
			temp--;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

A, B, C, D = mapint()

cnt = 0
while 1:
    if cnt%2==0:
        C -= B
    else:
        A -= D
    if C<=0:
        print('Yes')
        break
    if A<=0:
        print('No')
        break
    cnt += 1

Measured memory_bytes: 61688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, z, w, a[2019] = {}, d[2][2019] = {};
    cin >> n >> z >> w;
    for (int i = n; i; i--) cin >> a[i]; a[n + 1] = w;
    for (int i = 1; i <= n; i++) {
        d[0][i] = d[1][i] = abs(a[1] - a[i + 1]);
        for (int j = 1; j < i; j++) {
            d[0][i] = max(d[0][i], d[1][j]);
            d[1][i] = min(d[1][i], d[0][j]);
        }
    }
    cout << d[0][n] << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
const int N=200005;
int n,l;
int a[N];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
int pre[N],nxt[N];
long long lf[N],rf[N];
vector<int>now;
long long solve(int x)
{
	long long res=0,sum=0;
	int len=now.size();
	int ppre=pre[now.front()],nnxt=nxt[now.back()];
	for(int i=0;i<len;i++)
	{
		if(i-l+1>=0) sum+=lf[now[i-l+1]];
		res+=sum*rf[now[i]];
	}
	static long long tlf[N],trf[N];
	for(int i=0;i<len;i++)
		tlf[now[i]]=lf[now[i]],trf[now[i]]=rf[now[i]],lf[now[i]]=rf[now[i]]=0;
	if(len<l)
	{
		nxt[ppre]=n+1,pre[nnxt]=0;
		return res;
	}
	int num=len/l;
	for(int i=l-1;i<len;i++)
	{
		int p=(i+1)/l-1;
		rf[now[p]]+=trf[now[i]];
	}
	for(int i=len-l;i>=0;i--)
	{
		int p=num-(len-i)/l;
		lf[now[p]]+=tlf[now[i]];
	}
	now.resize(num);
	for(int i=1;i<num;i++)
		pre[now[i]]=now[i-1],nxt[now[i-1]]=now[i];
	pre[now.front()]=ppre,nxt[ppre]=now.front();
	pre[nnxt]=now.back(),nxt[now.back()]=nnxt;
	for(int p:now)
		q.push(make_pair(x+1,p));
	sum=0;
	for(int i=0;i<num;i++)
	{
		if(i-l+1>=0) sum+=lf[now[i-l+1]];
		res-=sum*rf[now[i]];
	}
	return res;
}
int main()
{
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		q.push(make_pair(a[i],i));
		pre[i]=i-1,nxt[i]=i+1;
		lf[i]=rf[i]=1;
	}
	vector<int>pos;
	long long ans=0;
	while(!q.empty())
	{
		int x=q.top().first;
		pos.push_back(q.top().second);
		q.pop();
		while(!q.empty()&&q.top().first==x) pos.push_back(q.top().second),q.pop();
		now.push_back(pos.front());
		for(int i=1;i<pos.size();i++)
		{
			if(nxt[pos[i-1]]!=pos[i]) ans+=solve(x),now.clear();
			now.push_back(pos[i]);
		}
		ans+=solve(x);
		now.clear();
		pos.clear();
	}
	printf("%lld",ans+n);
	return 0;
}

Measured memory_bytes: 14636
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define fastcin() ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;

typedef pair<int, int> ii;

const int maxn = 100001; 
unordered_map<int, int> M; 
unordered_map<int, ii> tmp; 

int n, ans; 
ii b[maxn]; 

bool isp[maxn];

vector<int> pr; 

void sieve() {
	memset(isp, 1, sizeof isp); isp[1] = 0; isp[2] = 1; 
	pr.pb(2);
	for(int i = 3; i <= 100000; i += 2) {
		if(isp[i]) {
			pr.pb(i);
			for(int j = i * i; j <= 100000; j += 2 * i) 
				isp[j] = 0;  
		}
	}
}

void get(int x, int id) {
	int ans = 1, comp = 1; 
	for(auto p : pr) {
		if(p * p > x) break; 
		if(x % p == 0) {
			int cnt = 0; 
			while(x % p == 0) {
				x /= p; 
				cnt++; 
			}
			cnt %= 3; 
			if(!cnt) continue; 
			for(int i = 1; i <= cnt; i++) ans *= p; 
			for(int i = 1; i <= 3 - cnt; i++) comp *= p; 
		}
	}
	if(x > 1) {
		ans *= x; 
		comp *= x * x;
	}
	b[id] = {ans, comp}; 
}

// chi Miku vo dich 
signed main()
{
	cin >> n; 
	sieve(); 
	for(int i = 1, x; i <= n; i++) {
		cin >> x; 
		if(!tmp.count(x)) {
			get(x, i); 
			tmp[x] = b[i]; 
		}
		else b[i] = tmp[x]; 
		M[b[i].fi]++; 
	}
	if(M[1] > 0) 
		ans = 1; 
	for(int i = 1; i <= n; i++) {
		int mask = b[i].fi, comple = b[i].se, p = M[mask]; 
		if(!p or mask == 1) continue; 
		ans += max(p, M[comple]); 
		M[mask] = M[comple] = 0;  
	}
	cout << ans; 
}


Measured memory_bytes: 18956
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int t=(h2-h1)*60;
    t+=(m2-m1);
    int ans=max(0ll, t-k);
    cout<<ans;
}

Measured memory_bytes: 3580
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)

int cnt[26];
void solve()
{
    string s;
    cin >> s;
    for(int i = 0; i < (int) s.length(); i++)
    {
        cnt[s[i] - 'a']++;
    }
    for(int i = 0; i < 26; i++)
    {
        if(cnt[i] & 1)
        {
            cout << "No";
            return;
        }
    }
    cout << "Yes";
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    solve();
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
lenc = len(c)
a.sort()
c.sort()
ans = 0
for i in b:
	atmp = bisect.bisect_left(a, i)
	ctmp = lenc - bisect.bisect_right(c, i)
	ans += atmp * ctmp
print(ans)

Measured memory_bytes: 23360
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<ll ,ll> P;
#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {

    ll N;
    cin >> N;
    vector<ll> v(N);
    ll tmp = 0, iter;
    vector<P> ans;
    REP(i, N){
        cin >> v[i];
        if (tmp < abs(v[i])){
            tmp = abs(v[i]);
            iter = i;
        }
    }
    if (v[iter] > 0){
        REP(i, N-1){
            //if (v[i] <= v[i + 1]) continue;
            ans.push_back(P(iter, i + 1));
            ans.push_back(P(iter, i + 1));
            v[i+1] += 2 * v[iter];
            iter = i + 1;
        }
    }else{
        for(ll i = N - 1; i > 0; i--){
            //if (v[i-1] <= v[i]) continue;
            ans.push_back(P(iter, i - 1));
            ans.push_back(P(iter, i - 1));
            v[i-1] += 2 * v[iter];
            iter = i - 1;
        }
        
    }
    cout << ans.size() << endl;
    REP(i, ans.size()) cout << (ans[i].first + 1) << " " << (ans[i].second + 1) << endl;
    return 0;
}



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

void solve() {
    int N;
    string S, T;
    cin >> N >> S >> T;
    string ans;
    for (int i = 0; i < N; ++i) {
        ans += S[i];
        ans += T[i];
    }
    cout << ans << endl;
}

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


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

main()
{
        int ans=0;
        rep(i,4)
        {
                char c; cin>>c;
                if(c=='+')ans++;
                else ans--;
        }
        cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long k,pref[200100],a;
int di;
vector<long long> dis;
template<typename T,int sz>
struct binary_indexed_tree{
	#define lowbit(x)  ((x)&(-x))
	T dat[sz];
	void update(int x,T delta){
		for(;x<sz;x+=lowbit(x)){
			dat[x]+=delta;
		}
	}
	T get(int x){
		T res=0;
		for(;x;x-=lowbit(x)){
			res+=dat[x];
		}
		return res;
	}
};
binary_indexed_tree<int,262144> Bi;
int main(){
	#ifdef FILIN
		#ifndef LOCAL
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	pref[0]=0LL;
	for(int i=1;i<=n;i++){
		cin>>a;
		a-=k;
		pref[i]=pref[i-1]+a;
		dis.push_back(pref[i]);
	}
	dis.push_back(0);
	sort(dis.begin(),dis.end());
	dis.erase(unique(dis.begin(),dis.end()),dis.end());
	long long res=0LL;
	di=lower_bound(dis.begin(),dis.end(),0)-dis.begin()+1;
	Bi.update(di,1);
	for(int i=1;i<=n;i++){
		di=lower_bound(dis.begin(),dis.end(),pref[i])-dis.begin()+1;
		res+=(long long)(Bi.get(di));
		Bi.update(di,1);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 4336