akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9 + 5;
constexpr long long INFLL = 1LL << 62;
constexpr double eps = (1e-9);


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

  string s;
  cin >> s;
  string r = s;
  reverse(ALL(r));

  vector<char> x;
  rep(i, s.size()) {
    if (s[i] != 'x') x.push_back(s[i]);
  }

  vector<char> y = x;
  reverse(ALL(y));
  rep(i, x.size()) {
    if (x[i] != y[i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  int ans = 0;
  int idx1 = 0;
  int idx2 = 0;
  for (int t = 0; t < (x.size() + 1) / 2; t++) {
    int num1 = 0, num2 = 0;
    while (s[idx1] == 'x') {
      idx1++;
      num1++;
    }
    while (r[idx2] == 'x') {
      idx2++;
      num2++;
    }
    ans += abs(num1 - num2);
    idx1++;
    idx2++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3824
N,M,Q = map(int, input().split())

A=[]
B=[]
C=[]
D=[]
for i in range(Q):
  a,b,c,d = map(int, input().split())
  A.append(a)
  B.append(b)
  C.append(c)
  D.append(d)  

def score(box):
  ret = 0
  for i in range(Q):
    if box[B[i]-1] - box[A[i]-1] == C[i]:
      ret += D[i]
  return(ret)

box = [1]*N
n = N - 1
flag = True
ans = 0
while flag:
#  print(box, score(box))
  ans = max(ans,score(box))
  for nn in range(1,N+1):
    n = N-nn
    if box[n] < M:
      box[n] += 1
      box[n:N] = [box[n]]*(N-n)
      break
    elif box[0]==M:
      flag = False

print(ans)


Measured memory_bytes: 9256
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define inf 1e18
#define mm 998244353
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

void solve(){
    int n; cin>>n;
    map<string, int> mp;
    f(i,n){
    	string s; cin>>s;
    	mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 3664
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

double EPS = 1e-10;

int N, K;
int x[100], y[100], c[100];

int cntC(double x1, double y1, double T){
	int ret = 0;
	for(int i = 0; i < N; i++){
		double dx = x[i] - x1;
		double dy = y[i] - y1;
		// cout << dx * dx + dy * dy << " " << T * T / c[i] / c[i] << endl;
		if(dx * dx + dy * dy <= T * T / (c[i] * c[i]) * (1 + EPS)){
			ret += 1;
		}
	}
	// cout << ret << endl;
	return ret;
}

bool check(double T){
	// cout << "hoge" << endl;
	for(int i = 0; i < N; i++){
		for(int j = i + 1; j < N; j++){
			int dx = x[j] - x[i];
			int dy = y[j] - y[i];
			int d2 = dx * dx + dy * dy;
			double c1 = (double)c[i];
			double c2 = (double)c[j];
			double r12 = T * T / c1 / c1;
			double r22 = T * T / c2 / c2;
			double a = (d2 + r12 - r22) / 2;
			// cout << a << endl;
			// cout << dx << " " << dy << endl;
			if(d2 * r12 - a * a < 0){
				continue;
			}
			double sq = sqrt(d2 * r12 - a * a);
			// cout << (a * dx + dy * sq) / d2 + x[i] << " " << (a * dy - dx * sq) / d2 - y[i] << " " << cntC((a * dx + dy * sq) / d2 + x[i], (a * dy - dx * sq) / d2 - y[i], T) << endl;
			if(cntC((a * dx + dy * sq) / d2 + x[i], (a * dy - dx * sq) / d2 + y[i], T) >= K){
				return true;
			}
			// cout << (a * dx - dy * sq) / d2 - x[i] << " " << (a * dy + dx * sq) / d2 + y[i] << " " << cntC((a * dx - dy * sq) / d2 - x[i], (a * dy + dx * sq) / d2 + y[i], T) << endl;
			if(cntC((a * dx - dy * sq) / d2 - x[i], (a * dy + dx * sq) / d2 + y[i], T) >= K){
				return true;
			}
		}
		if(cntC(x[i], y[i], T) >= K){
			return true;
		}
	}
	return false;
}

int main(){
	cin >> N >> K;
	for(int i = 0; i < N; i++){
		cin >> x[i] >> y[i] >> c[i];
	}
	double L = 0, R = INF;
	while(R - L >= EPS){
		bool ret = check((L + R) / 2);
		if(ret){
			R = (L + R) / 2;
		}else{
			L = (L + R) / 2;
		}
	}
	printf("%.10f\n", R);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

char str[] = "keyence";

int main(){
    string S;
    cin >> S;
    int N = S.length();
    bool ans = true;

    if(S[0] == 'k' && S[N-1] == 'e'){
        int f = 0;
        int b = 6;
        while(1){
            if(str[f] != S[f]) break;
            f++;
        }
        while(1){
            if(str[b] != S[N-1+(b-6)]) break;
            b--;
        }
        if(f > b) ans = true;
        else ans = false;
    }
    else if(S[0] == 'k'){
        for(int i = 0; i < 7; i++){
            if(str[i] != S[i]) ans = false;
        }
    }
    else if(S[N-1] == 'e'){
        for(int i = 0; i < 7; i++){
            if(str[i] != S[N-7+i]) ans = false;
        }
    }
    else{
        ans = false;
    }

    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
n,q=map(int,input().split())
s=input().replace("AC","XY")
ref=[i for i,j in enumerate(s) if j=="X"]
for _ in range(q):
	a,b=map(int,input().split())
	a-=1;b-=1
	print(bisect_left(ref,b)-bisect_left(ref,a))

Measured memory_bytes: 5912
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,a[N];
long long ans;
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)
	{
		if(a[i])
		{
			ans+=a[i]/2;
			a[i]%=2;
			if(a[i])
			{
				if(a[i+1])
				{
					a[i+1]--;
					a[i]--;
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(void){
	int x,y,a[100000],b=0,c=0,d=0,e=0;
	for(;;){
		scanf("%d %d",&x,&y);
		if(x+y!=0){
			a[b]=x;
			a[b+1]=y;
			b++;
			b++;
		}else{
			break;
		}
	}
	for(;;){
		if(a[d]+a[d+1]!=0){
			if(a[d]>a[d+1]){
				c=a[d];
				a[d]=a[d+1];
				a[d+1]=c;
			}
			printf("%d %d\n",a[d],a[d+1]);
			d++;
			d++;
		}else{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1740
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

class Main {
    int N;
    vector<ll> D;
    void input() {
        cin >> N;
        D.resize(N);
        REP(i, N) { cin >> D[i]; }
    }
    void output() {
        vector<vector<int>> d2i(N);
        REP(i, N) { d2i[D[i]].emplace_back(i); }
        if (d2i[0] != vector<int>(1)) {
            cout << 0 << endl;
            return;
        }
        int cnt = 1;
        mint res = 1;
        REP(i, N - 1) {
            if (d2i.empty()) {
                if (cnt < N) res = 0;
                break;
            }
            res *= mint(d2i[i].size()).pow(d2i[i + 1].size());
        }
        cout << res << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 9388
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    //long long int n, i,j,k,sum=0;
    string s;
    getline(cin,s);
    if(s=="Sunny")
        cout<<"Cloudy"<<endl;
    else if(s=="Cloudy")
        cout<<"Rainy"<<endl;
    else if(s=="Rainy")
        cout<<"Sunny"<<endl;
    return 0;
}

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

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

    for (int i = 1; i < 100000; i++) {
        if (floor(i * 0.08) == a && floor(i * 0.1) == b) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
k = 1
while 26**k <= N:
    N -= 26**k
    k += 1

def itoc(i):
    return chr(ord('a') + i)

N -= 1
ans = ''
for _ in range(k):
    N,i = divmod(N,26)
    ans += itoc(i)

if all(c=='z' for c in ans):
    print(ans[:-1])
else:
    print(ans[::-1])

Measured memory_bytes: 9212
#include<stdio.h>

#define INF 2001
#define N 100

int Arr[N][N];

int prim(int n){
  int i,ver,min_cos,cost[N],c[N],sum_weight;

  for(i=0;i<n;i++){
    cost[i] = INF;
    c[i] = 0;
  }

  cost[0] = 0;
  c[0] = 1;
  sum_weight = 0;

  while(1){
    ver = -1;
    min_cos = INF;
    for(i=0;i<n;i++){
      if(c[i] == 1 && cost[i] < min_cos){
	min_cos = cost[i];
	ver =i;
      }
    }

    if(ver == -1){
      break;
    }

    c[ver] = 2;
    sum_weight += cost[ver];

      for (i = 0;i<n;i++) {
      if (c[i] != 2 && Arr[ver][i] < INF) {
        c[i] = 1;
        if (cost[i] > Arr[ver][i]) cost[i] = Arr[ver][i];
      }
    }
  }

  return sum_weight;
}

int main(){
  int i,j,n,w;

  scanf("%d",&n);

  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      scanf("%d",&w);
      if (w == -1) {
	Arr[i][j] = INF;
      }
      
      else Arr[i][j] = w;
    }
  }

  printf("%d\n",prim(n));

  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define debug(x) cout << x << endl;
#define int long long
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
/* 	1) order_of_key (k) : Number of items strictly smaller than k .
	2) find_by_order(k) : K-th element in a set (counting from zero).
*/
using namespace __gnu_pbds;
using namespace std;
using LD = long double;

const int N = 1e6+1;
const int mod = 1e9+7;
const int INF = 1e18;
int row[8] = {1,1,0,-1,-1,-1,0,1};
int col[8] = {0,-1,-1,-1,0,1,1,1};

void solve() {
	int k;
	cin >> k;
	int num = 7,cnt = 0;
	bool flg = true;
	while(cnt < N) {
		cnt++;
		if(num%k == 0) {
			flg = false;
			break;
		}
		num = num*10 + 7;
		num %= k;
	}
	if(flg)
		cout << "-1";
	else
		cout << cnt << endl;
}
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t = 1,i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n; cin >> n;
  LL ans = 0;
  for (RI i = 1; i <= n; ++i)
    if (i % 3 != 0 && i % 5 != 0)
      ans += i;
  cout << ans;

  return 0;
}

// created by Daniel yuan


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main() {
  string s; cin>>s;
  bool can=false;
  rep(i,s.size()-1){
  	if(s[i]=='A' && s[i+1]=='C'){
      can=true;
      break;
    }
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
      
}



Measured memory_bytes: 256
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

def main():
    n,m = mi()

    t = [[] for i in range(n+1)]

    for i in range(m):
        p,s = input().split()
        p = int(p)
        t[p].append(s)

    if m == 0:
        print("0 0")
        exit()


    accnt = 0
    wacnt = 0

    for i in range(1,n+1):
        if not t[i]:
            continue
        wtmp = 0
        flag = False
        for k in t[i]:
            if k == "AC":
                accnt+=1
                flag = True
                break
            else:
                wtmp+=1
        if flag:
            wacnt+=wtmp

    print(accnt,wacnt)






main()


Measured memory_bytes: 20272
#include <bits/stdc++.h>
using namespace std;
long long S(long long v)
{
    return v * (v + 1) / 2;
}
long long n;
int main()
{
    return scanf("%lld", &n), printf("%lld\n", S(n) - 3 * S(n / 3) - 5 * S(n / 5) + 15 * S(n / 15)), 0;
}

Measured memory_bytes: 3832
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        FastReader in = new FastReader();
        test a=new test();
        a.solve(in,out);
        out.close();
    }
}
class test{
    public void solve(FastReader in, PrintWriter out){
       int n=in.nextInt();
       int m=in.nextInt();
       int a[]=new int [n];
       for(int i=0;i<n;i++){
           a[i]=in.nextInt();
       }
       int v []=new int [n];
       Arrays.fill(v,1);
       for(int i=0;i<m;i++){
           int c=in.nextInt();
           int d=in.nextInt();
           c--;
           d--;
           if(a[c]>=a[d]){
               v[d]=0;
           }
           if(a[d]>=a[c]){
               v[c]=0;
           }
       }
       int s=0;
       for(int i=0;i<n;i++){
           s+=v[i];
       }
       out.println(s);
    }
    public long bits(long number){
        return (long)(Math.log(number)/Math.log(2) + 1);
    }
    public String create(long m){
        String s="";
        for(long i=0;i<m;i++){
            s+="1";
        }
        return s;
    }
}

class FastReader{
    BufferedReader br;
    StringTokenizer st;

    public FastReader(){
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next(){
        while(st==null || !st.hasMoreElements()){
            try{
                st=new StringTokenizer(br.readLine());
            }
            catch(IOException e){
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

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

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

    double nextDouble(){
        return Double.parseDouble(next());
    }
    String nextLine(){
        String str="";
        try{
            str=br.readLine();
        }
        catch(IOException e){
            e.printStackTrace();
        }
        return str;
    }
}



Measured memory_bytes: 54180
#include <bits/stdc++.h>
#include <cmath>
#include <math.h>
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  // 長針は1分に360÷60=6度進む
  // 短針は1分に360÷12÷60=0.5度進む
  
  double degree = abs(6 * M  - 0.5 * (H * 60 + M));
  
  if (degree > 180) {
    degree = 360 - degree;
  }
  
  // 角度はラジアンに変換する
  
  double C2 = A * A + B * B - 2 * A * B * cos(degree * M_PI / 180);
  
  cout << fixed << setprecision(20) << sqrt(C2);
  
}

Measured memory_bytes: 4160
import std.stdio;
import std.array;
import std.conv;

void main(){
	string[] d=split(readln());
	if(to!int(d[0])<=to!int(d[2])&&to!int(d[2])<=to!int(d[1])){
		writeln("Yes");
	}else{
		writeln("No");
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N;
ll a[20][20];

ll score[(1<<16)];
ll dp[(1<<16)];
const ll INF=1e18;

ll solve(int state){
    if(dp[state]!=-INF) return dp[state];

    ll res=score[state];
    
    for(int i=state-1;i>0;i--){
        i&=state;
        if(i==0) break;
        ll tmp=solve(i);
        tmp+=solve(state^i);
        res=max(res,tmp);
    }

    return dp[state]=res;
}

int main(){
  cin>>N;
  for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
          cin>>a[i][j];
      }
  }

  for(int i=0;i<(1<<N);i++){
      vector<int> v;
      for(int j=0;j<N;j++){
          if((1<<j)&i) v.push_back(j);
      }

      ll res=0;
      for(int j=0;j<v.size();j++){
          for(int k=j+1;k<v.size();k++){
              res+=a[v[j]][v[k]];
          }
      }
      score[i]=max(res,0ll);
      dp[i]=-INF;
  }

  dp[0]=0;
  cout<<solve((1<<N)-1)<<endl;

  return 0;
}


Measured memory_bytes: 1280
s = input().strip()
N = len(s)
if N%2==0 and s[0]==s[-1]:
    print("First")
elif N%2==0 and s[0]!=s[-1]:
    print("Second")
elif N%2==1 and s[0]==s[-1]:
    print("Second")
else:
    print("First")

Measured memory_bytes: 39152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();
        int k = sc.NextInt();

        int max = Math.Max(a, Math.Max(b, c));
        int answer = a + b + c;
        for (int i = 0; i < k; i++)
        {
            answer += max;
            max *= 2;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

int main()
{
    string o, e; cin >> o >> e;

    string ans;    

    for (int i = 0; i < o.size(); i++) {
        ans += o[i];        
        if (i < e.size()) ans += e[i];        
    }
    
    cout << ans << endl;

    return 0;
}

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

int main() {
string s,t;
cin>>s>>t;
int ans=0;
for(int i=0;i<s.size();i++){
	if(s[i]!=t[i])
	ans++;
}cout<<ans;
return 0;
}

Measured memory_bytes: 3852
#include <iostream>
#include <string>
#include <map>
#include <cctype>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
	ios::sync_with_stdio(false);

	string input;
	map<string, bool>::iterator it;

	while( getline(cin, input) ){
		string str;
		str.reserve(1024);
		
		for(int i = 0; i < input.size(); ++i){
			if( isalpha(input[i]) ){
				str += (char)toupper(input[i]);
			}
		}
		int sz = str.size();
		
		map<string, bool> pals;
		
		//odd length
		for(int center = 1; center < sz - 1; ++center){
			int maxlen = min(center, sz - center - 1);

			int len;
			for(len = 1; len <= maxlen; ++len){
				if(str[center - len] != str[center + len]){
					break;
				}
			}
			--len;

			if( len != 0 ){
				pals.insert( make_pair(string(str, center - len, 2 * len + 1), true) );

				for(int i = 1; i < len; ++i){
					pals[string(str, center - i, 2 * i + 1)] = false;
				}
			}
		}
		
		//even length
		for(int center = 1; center < sz - 2; ++center){
			if( str[center] != str[center + 1] ){
				continue;
			}
			int maxlen = min(center, sz - center - 2);
			
			int len;
			for(len = 1; len <= maxlen; ++len){
				if(str[center - len] != str[center + len + 1]){
					break;
				}
			}
			--len;
			
			if( len != 0 ){
				pals.insert( make_pair(string(str, center - len, 2 * len + 2), true) );
				
				for(int i = 0; i < len; ++i){
					pals[string(str, center - i, i * 2 + 2)] = false;
				}
			}
		}

		bool space = false;
		for(it = pals.begin(); it != pals.end(); ++it){
			if( it->second ){
				if( space ){
					cout << ' ';
				}
				space = true;
				
				cout << it->first;
			}
		}
		cout << '\n';
	}
}

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

#ifndef _WIN32
    #define getchar getchar_unlocked
#endif

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

typedef long long int LLI;
typedef unsigned long long int LLU;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<int> vi;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',') cerr<<*sdbg++;
  cerr<<"="<<h<<",";
  _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int32_t main()
{
	int N; scanf("%d", &N);
	LLU lcm = 1;
	for(int i = 0; i < N; ++i){
		LLU x; scanf("%llu", &x);
		lcm = (x/LLI(__gcd(lcm, x)))*lcm;
	}
	printf("%llu", lcm);
}

/*
5
2
5
10
1000000000000000000
1000000000000000000
*/


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

int gcd(int a,int b)
{
    if (a%b==0)
    {
        return(b);
    }
    else
    {
        return(gcd(b,a%b));
    }
}

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

    vector<int> xs(N);
    for(int i = 0; i < N; ++i){
        cin >> xs[i];
    }
    xs.push_back(X);

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

    vector<int> diffs(N);
    for(int i = 0; i < N; ++i){
        diffs[i] = xs[i + 1] - xs[i];
    }

    int ans = INT_MAX;
    if(N == 1) {
        ans = diffs[0];
    }
    else{
        for(int i = 0; i < N - 1; ++i){
            int tmp = gcd( diffs[i + 1], diffs[i]);
            ans = min(ans, tmp);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

typedef long long ll;

ll h, w, k;
char c[10][10];
bool b[10][10];
ll res;

int main() {
	cin >> h >> w >> k;
	memset(b, true, sizeof b);
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			cin >> c[i][j];
		}
	}

	ll n = 1 << h, m = 1 << w;

	for (ll ii = 0; ii < n; ii++) {
		for (ll jj = 0; jj < m; jj++) {
			ll cnt = 0;
			for (ll i = 0; i < h; i++) {
				if (ii & (1 << i)) continue;
				for (ll j = 0; j < w; j++) {
					if (jj & (1 << j)) continue;
					if (c[i][j] == '#') {
						cnt++;
					}
				}
			}
			if (cnt == k) res++;
		}
	}

	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(){
    string s,max("");
    map<string,int> word;
    map<int,string> tmp;
    while(cin >> s){
        if(s.size() > max.size())max=s;
        word[s]++;
    }
    map<string,int>::iterator it;
    for(it=word.begin();it!=word.end();it++){
        tmp[(*it).second] = (*it).first;
    }
    cout << (*tmp.rbegin()).second << " "<< max << endl;
    return 0;
}

Measured memory_bytes: 3104
n,k=map(int,input().split())
use=[(i,j) for i in range(2,n) for j in range(i+1,n+1)]
if k>(n-2)*(n-1)//2:
  print(-1)
  exit()
ans=[]
for i in range(2,n+1):
  ans+=[(1,i)]
for _ in range((n-2)*(n-1)//2-k):
  ans+=[use.pop()]
print(len(ans))
for i in ans:
  print(*i)

Measured memory_bytes: 74268
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int A, B;
    cin >> A >> B;
    if (A >= 10 || B >= 10) cout << -1 << endl;
    else cout << A * B << endl;
    return 0;
}


Measured memory_bytes: 256
/*
* @Author: dnhirapara
* @Problem: abc177_d
* @Time: 11-September-2020 : ( 16:17:57 )
*/
#include <bits/stdc++.h>

using namespace std;

/************defination************/

#define endl "\n"
#define logger(x) cout << __LINE__ << ": " << #x << " -> " << (x) << endl;
#define ll long long int
#define ull unsigned long long int

vector<ll> g[200005];
vector<bool> vis(200005, 0);

ll max_len = 0;

void dfs(ll node, ll lvl)
{
    vis[node] = true;
    for (auto i : g[node])
    {
        // logger(i);
        if (!vis[i])
        {
            dfs(i, lvl + 1);
            max_len++;
        }
    }
    // max_len = max(lvl, max_len);
}

//@time comp :
//@space comp :
int main()
{
    // ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    // cin.ignore(); must be there when using getline(cin, s)
    ll tc = 1;
    //cin >> tc;
    while (tc--)
    {
        ll n, m;
        cin >> n >> m;
        // logger(n);
        ll u, v;
        for (int i = 0; i <= n; i++)
        {
            vis[i] = false;
        }
        for (ll i = 0; i < m; i++)
        {
            cin >> u >> v;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        ll maxi = LLONG_MIN;
        for (ll i = 1; i <= n; i++)
        {
            if (!vis[i])
            {
                max_len = 0;
                dfs(i, 0);
                // logger(max_len);
                maxi = max(max_len, maxi);
            }
        }
        cout << maxi + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 23924
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;
int a[10005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  REP(i, m) cin >> a[i];

  ll ans = 0;
  ll sum = 0;
  REP(i, m) sum += a[i];

  if(n >= sum) cout << n - sum << endl;
  else cout << -1 << endl;
}


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

int arr[100005];

int32_t main(){
    int n;
    scanf("%lld",&n);
    for (int x = 0; x<n; x++){
        scanf("%lld",&arr[x]);
    }
    int mn = 2;
    int mx = 2;
    for (int x = n-1; x>=0; x--){
        mn = ((mn-1)/arr[x]+1)*arr[x];
        mx = (mx/arr[x])*arr[x]+arr[x]-1;
        if (mx<mn){
            printf("-1");
            return 0;
        }
    }
    printf("%lld %lld",mn,mx);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<string> S(n);
  for(int i=0;i<n;i++){
    cin >> S[i];
  }
  int ac=0,wa=0,tle=0,re=0;
  for(int i=0;i<n;i++){
    if(S[i]=="AC") ac++;
    if(S[i]=="WA") wa++;
    if(S[i]=="TLE") tle++;
    if(S[i]=="RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  return 0;
}


Measured memory_bytes: 6420
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p = sc.nextInt();
        int[] a = new int[n];
        int odd = 0, even = 0;
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
            if(a[i] % 2 == 0){
                even++;
            }else{
                odd++;
            }
        }
        sc.close();

        long ans = 0L;

        if(p == 0){
            ans++;
            if(even==0 && odd < 2){
            }else{
                for(int i=2; i<=odd; i+=2){
                    ans += npm(odd, i);
                }
                //ans *= Math.pow(2, even);
                for(int i=0; i<even; i++) ans *= 2L;
            }
        }else{
            if(odd == 0){
            }else{
                for(int i=1; i<=odd; i+=2){
                    ans += npm(odd, i);
                }
                //ans *= Math.pow(2L, even);
                for(int i=0; i<even; i++) ans *= 2L;
            }
        }
        System.out.print(ans);

    }

    public static long npm(int n, int m){
        long ans = 1;
        long d = 1;
        for(int i=n; i>n-m; i--){
            ans *= i;
            while(d <= m && ans % d == 0){
                ans /= d;
                d++;
            }
        }
        return ans;
    }
}

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

using namespace std;

int main()
{
    int q;
    list <int> L;
    list <int>::iterator it=L.begin();
    cin>>q;
    while(q--)
    {
        int a,b;
        cin>>a;
        if(a<2)
            cin>>b;
        if(a==0)
            it=L.insert(it,b);
        else if(a==1)
        {
            for(int i=0;i<abs(b);i++)
            {
                if(b<0)
                    it--;
                else
                    it++;
            }
        }
        else
            it=L.erase(it);
    }
    it=L.begin();
    for(;it!=L.end();it++)
    {
        cout<<*it<<endl;
    }
    return 0;
}



Measured memory_bytes: 18664
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long mod2 = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int N;
  string s, t;
  cin >> N >> s >> t;

  int ans = 2 * N;
  for (int i = 1; i <= N; i++)
  {
    if (s.substr(N - i, i) == t.substr(0, i))
    {
      ans = 2 * N - i;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repf(i,a,n) for(int i = (int)(a); i < (int)(n); i++)

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    bool ansb = true;
    int ansi = 0;
    int p = 0;
    int a,n,k;
    vector<int> v;
    cin >> n ;
    rep(i,n){
        cin >> a;
        v.push_back(a);
    }
    rep(i,n-2){
        if((v[i]-v[i +1]) * (v[i+2]-v[i+1]) <  0){
            ansi ++ ;
        }
    }
    cout << ansi << endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
     int x,y,tmp;
    Scanner scan = new Scanner(System.in);
    
        while(true){
            x = scan.nextInt();
            y = scan.nextInt();
            if(x == 0 && y == 0) break;
            if(x > y){
                tmp = x;
                x = y;
                y = tmp;
            }
            System.out.println(x +" "+ y);
            }
        }
    }


Measured memory_bytes: 36540
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K, x) binary_search(K.begin(), K.end(), x)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout << x << endl
#define put(x) out(x)
#define in(x) cin >> x
#define maxx(a, b, c) max(a, max(b, c))
#define minn(a, b, c) min(a, min(b, c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main()
{
    int N;
    in(N);
    if(N<=111)out(111);
    else if(N<=222)out(222);
    else if(N<=333)out(333);
    else if(N<=444) out(444);
    else if(N<=555)out(555);
    else if(N<=666)out(666);
    else if(N<=777)out(777);
    else if(N<=888)out(888);
    else if(N<=999)out(999);

}


Measured memory_bytes: 256
//mOzis_
/////*31022618*/////
//****//MONU KUMAR\****//
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define p1(x) cout <<x <<"\n"
#define p2(x,y) cout <<x <<" " <<y <<"\n"
#define p3(x,y,z) cout <<x <<" " <<y <<" " <<z <<"\n"
#define nL cout<<"\n"
#define lp(i,l,r) for (long long int i = l; i < r; i++)
#define mem(a,x) memset(a,x,sizeof(a))              //set elements of array to some value
#define pi 3.1415926535897932384626
#define mod 1000000007
#define pb(x) push_back(x)
#define ff first
#define ss second
#define siz 256                        //characters are stored using 8 bit and there can be
bool anagram(char *s1, char *s2)     //256 possible characters only in lowercase alphabet
{
	ll count[siz];
    mem(count,0) ;
    ll i;
    for (i = 0; s1[i] && s2[i];  i++)
    {
        count[s1[i]]++;
        count[s2[i]]--;
    }
    if (s1[i] || s2[i])
    {
      return false;
    }
    lp(i,0,siz)
    {
    	 if (count[i])
    	 {
    	 	 return false;
    	 }
    }
     return true;

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

	ll t=0;
	//cin>>t;
	clock_t launch=clock();
	ll n,flag=0;
	cin>>n;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		if (a[i]!=i+1)
		{
			t++;
			if (t>=3)
			{
				flag=1;
				break;
			}
		}
	}
	if (flag)
	{
		cout<<"NO"<<"\n";
	}
	else
	{
		cout<<"YES"<<"\n";
	}

	clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
	return 0;
}
//////////*********************end of program*********************//////////



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 1050000000;
constexpr auto MOD = 1000000007;

int main() {
	int k, t;
	cin >> k >> t;
	vi a(t);
	rep(i, t)cin >> a[i];
	sort(all(a));
	int ans = 0;
	if (t == 1)ans = k - 1;
	else {
		int other = 0;
		rep(i, t - 1)other += a[i];
		ans = a[t - 1] - other - 1;
		if (ans < 0)ans = 0;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())

int main()
{
    string s,t; cin >> s >> t;
    Sort(s); Sort2(t);

    if (s<t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

void solve() {
  int n, k;
  cin >> n >> k;
  double ret = 0;
  for(int i = 1; i <= n; i++) {
    double curr = 1.0 / n;
    int now = i;
    while(now < k) {
      now *= 2;
      curr /= 2;
    }
    ret += curr;
  }
  cout << fixed << setprecision(10) << ret << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 256
import java.util.*;
class Main {
  static Scanner sc = new Scanner(System.in);
  
  public static void main(String[] args) {
    A();
    
    
  }
  
  private static void A(){
    
    int n = sc.nextInt();
    int val = sc.nextInt();
    System.out.print((n*500 >= val)?"Yes":"No");
  }
}



Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,fa[N],f[N],h[N];
ll ans;
struct node{int i,x,y;}a[N];
void operator+=(node &x,node y){x.x+=y.x;x.y+=y.y;}
bool operator<(node x,node y){ll t=(ll)x.x*y.y-(ll)x.y*y.x;return (t) ? (t<0) : (x.i<y.i);}
bool operator>(node x,node y){return y<x;}
bool operator==(node x,node y){return (x.x==y.x)&&(x.y==y.y)&&(x.i==y.i);}
int find(int x){return (x==f[x]) ? x : f[x]=find(f[x]);}
void merge(int x,int y){
	x=find(x);y=find(y);
	ans+=(ll)a[x].x*a[y].y;
	f[y]=x;a[x]+=a[y];
}
priority_queue< node,vector<node>,greater<node> > g;
int main(){
	n=read();
	for (int i=2;i<=n;i++) fa[i]=read();
	for (int i=1;i<=n;i++){
		f[i]=i;
		if (read()) a[i]=(node){i,1,0};
		else a[i]=(node){i,0,1};
	}
	for (int i=2;i<=n;i++) g.push(a[i]);
	for (int i=2;i<=n;i++){
		while (h[g.top().i]) g.pop();
		int x=g.top().i,y=find(fa[x]);
		g.pop();h[x]=1;
		merge(y,x);
		if (y!=1) g.push(a[y]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 9588
#include<bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main(){
  long long int a,b,x;
  cin>>a>>b>>x;
 
  long long int A;
  if(a!=0){
   A=(a-1)/x;
  }
  else{
     A=-1;
  }
 
  long long int B=b/x;
 
  long long int ans=B-A;
  cout<<ans<<endl;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

ll binpow(ll x,ll n)
{
	if(n == 0) return 1;
	else if(n & 1)
	{
		return x * binpow(x,n - 1);
	}
	else
	{
		ll y = binpow(x,n / 2);
		return y * y;
	}
	
}
void Compute(ll n)
{
	KAKA
	ll jackpot;
	if(n <= 26)
	{
		char ch = 'a';
		ch += (n - 1);
		cout<<ch<<"\n";
	}
	else{
	vector<ll> prefix(20);
	prefix[0] = 1,prefix[1] = 26;
	pragi(2,20)
	{
		prefix[i] = prefix[i - 1] + binpow(26,i);
	}
	pragi(0,20)
	{
     ll now = prefix[i];
	 ll nxt = prefix[i + 1];
	 if((now <= n) and (nxt > n))
	 {
		 jackpot = i;
		 break;
	 }
	}
	n -= prefix[jackpot];
	if(n == 0)
	{
		string s = "";
		pragi(0,jackpot)
		s += 'z';
		cout<<s<<"\n";
	}
	else
	{
		string t = "";
		pragi(0,jackpot + 1)
		t += 'a';
		vector<ll> bin;
		ll cop = n - 1;
		while(cop > 0)
		{
			ll d = cop%26;
			bin.eb(d);
			cop /= 26;
		}
		//reverse all(bin);
		pragi(0,bin.size())
		{
			t[jackpot - i] += bin[i];
		}
		cout<<t<<"\n";}
	}
	
}
int main()
{
	KAKA
	ll n;
	cin>>n;
	Compute(n);
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    while( true ) {
        cin >> n;
        if( n == -1 ) break;

        int sum = 1150;
        if( n > 10 ) {
            if( n <= 20 ) sum += ( n - 10 ) * 125;
            else sum += 125 * 10;

        }
        if( n > 20 ) {
            if( n <= 30 ) sum += ( n - 20 ) * 140;
            else sum += 140 * 10;

        }
        if( n > 30 )
            sum += ( n - 30 ) * 160;
        cout << 4280 - sum << endl;

    }

    return 0;
}





Measured memory_bytes: 3176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll T[1000], A[1000];
int main() {
	int N;
	cin >> N;
	ll x = 1, y = 1;
	for (int i = 0; i < N; i++) {
		cin >> T[i] >> A[i];
		ll k = max((x + T[i] - 1) / T[i], (y + A[i] - 1) / A[i]);
		x = k * T[i];
		y = k * A[i];
	}
	cout << x + y << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=100000+10;
int n,a[N];
int dis(int x,int y){
    if(y+y>x) y=x-y;
    return y;
}
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    int mx=*max_element(a+1,a+1+n);
    int mn=-1,v=-1;
    for(int i=1;i<=n;i++){
        if(a[i]==mx) continue;
        if(dis(mx,a[i])>mn){
            v=a[i]; mn=dis(mx,a[i]);
        }
    }
    printf("%d %d\n", mx,v);
}

Measured memory_bytes: 640
program atcoder
  implicit none
  integer a, b
  read *, a, b    ! 変数mに、標準入力から数字を読み込み代入する
  if (a.lt.9 .and. b.lt.9) then
  write(*,*) 'Yay!'
  else
  write(*,*) ':('
  end if    !  ","のあとに解答となる変数を書く
end program atcoder

Measured memory_bytes: 256
import itertools

n = list(range(1, int(input()) + 1))
s1 = tuple(map(int, input().split()))
s2 = tuple(map(int, input().split()))
perm = list(itertools.permutations(n))
a = perm.index(s1)
b = perm.index(s2)

print(abs(a - b))

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

int N;
map<int, int> mp;

int main() {
    cin >> N;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        mp[tmp]++;
    }

    int ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        if (itr->first != itr->second) {
            if (itr->first < itr->second) {
                ans += itr->second - itr->first;
            } else {
                ans += itr->second; 
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4736
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (LL i = 0; i < N; ++i)
typedef long long int LL;

int main() {
  LL N;
  in >> N;
  std::vector<LL> a(N + 1);
  rep(i, N) in >> a[i + 1];

  std::vector<LL> ans(N + 1);
  for (LL i = N; i >= 1; --i) {
    if (i * 2 > N)
      ans[i] = a[i];
    else {
      LL sum = 0;
      for (LL j = i * 2; j <= N; j += i) sum += ans[j];
      sum %= 2;
      if (sum != a[i]) ans[i] = 1;
    }
  }

  std::vector<LL> b;
  for (LL i = 1; i <= N; ++i) {
    if (ans[i] == 1) b.push_back(i);
  }
  out << b.size() << std::endl;
  rep(i, b.size()) out << b[i] << std::endl;
}


Measured memory_bytes: 4980