akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <sstream>
using namespace std;

const int MAXN = 21;
const int INF = 1<<28;
int N;
int G[MAXN][MAXN];

int main() {
  cin >> N;
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) {
      G[i][j] = i == j ? 0 : INF;
    }
  }
  int m;
  cin >> m;
  ++m;
  int a, b, c, d;
  while(m--) {
    string s;
    cin >> s;
    replace(s.begin(), s.end(), ',', ' ');
    stringstream ss(s);
    ss >> a >> b >> c >> d;
    --a;
    --b;
    if(!m) break;
    G[a][b] = c;
    G[b][a] = d;
  }

  for(int k = 0; k < N; ++k) {
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < N; ++j) {
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }

  cout << c-d-G[a][b]-G[b][a] << endl;
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

template <typename T>
struct BIT{
	vector<T> v;
	int n;
	
	const T init_value = 0;
	
	BIT(int sz){
		n=sz+1;
		v.resize(n,init_value);
	}
	
	BIT(vector<T> &x){
		n=x.size()+1;
		v.resize(n,init_value);
		
		for(int i=0;i<x.size();i++){
			add(i,x[i]);
		}
		
	}

	void add(int x,T val){
		x++;
		while(x < n){
			v[x] = func(v[x],val);
			x += x & (-x);
		}
	}
	
	//区間[0,r)におけるクエリ処理
	T query(int r){
		T ret = init_value;
		
		while(r>0){
			ret = func(v[r],ret);
			r -= r & (-r);
		}
		
		return ret;
	}
	
	T query(int l,int r){
		return query(r) - query(l);
	}
	
	T func(T a,T b){
		return a+b;
	}
	
};

long long get(vector<int> p){
	BIT<long long> B(p.size());
	vector<int> pos(p.size());
	for(int i=0;i<p.size();i++){
		pos[p[i]]=i;
	}
	
	long long ret = 0;
	for(int i=0;i<p.size();i++){
		ret += B.query(pos[i],p.size());
		B.add(pos[i],1LL);
	}
	return ret;
}

int main(){
	
	vector<int> cnt(26);
	string S;
	cin>>S;
	
	for(int i=0;i<S.size();i++){
		cnt[S[i]-'a']++;
	}
	
	int x = 0;
	for(int i=0;i<26;i++)x += cnt[i]%2;
	if(x>=2){
		cout<<-1<<endl;
		return 0;
	}
	
	vector<int> now(26,0);
	vector<int> p;
	{
		vector<int> L,R,M;
		
		for(int i=0;i<S.size();i++){
			int t = S[i]-'a';
			now[t]++;
			if(cnt[t]%2==1&&now[t]*2-1==cnt[t]){
				M.push_back(i);
			}
			else if(now[t]*2<=cnt[t]){
				L.push_back(i);
			}
			else{
				R.push_back(i);
			}
		}
		for(int i=0;i<L.size();i++)p.push_back(L[i]);
		for(int i=0;i<M.size();i++)p.push_back(M[i]);
		for(int i=0;i<R.size();i++)p.push_back(R[i]);
	}

	long long ans = get(p);

	string T = "";
	for(int i=0;i<p.size();i++)T += S[p[i]];
	vector<vector<int>> ind(26,vector<int>());
	for(int i=0;i<T.size();i++){
		ind[T[i]-'a'].push_back(i);
	}
	
	for(int i=0;i<26;i++)reverse(ind[i].begin(),ind[i].end());

	for(int i=0;i<T.size();i++){
		int x = i;
		if(i>=T.size()/2)x = T.size()-1-i;

		p[i] = ind[T[x]-'a'].back();
		ind[T[x]-'a'].pop_back();
	}
	
	ans += get(p);
	
	cout<<ans<<endl;
	
		
	
	
	
	return 0;
}

Measured memory_bytes: 9392
A, B = map(int, input().split())


A_yaku = []

now = 0

a = 2

while A >= a*a:
  if A%a == 0:
    if a != now:
      A_yaku.append(a)
      now = a
    A /= a
  else:
    a +=1

if A != now and A != 1:
  A_yaku.append(A)

B_yaku = []

now = 0

a = 2

while B >= a*a:
  if B%a == 0:
    if a != now:
      B_yaku.append(a)
      now = a
    B /= a
  else:
    a +=1

if B != now and B != 1:
  B_yaku.append(B)

count = 0

if(len(A_yaku) >= len(B_yaku)):
  for i in range(0,len(B_yaku)):
    if(B_yaku[i] in A_yaku):
      count += 1
else:
  for i in range(0,len(A_yaku)):
    if(A_yaku[i] in B_yaku):
      count += 1

count += 1

print(count)




Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <set>

struct Edge {
	int to, length;
};
int main() {
	int n; std::cin >> n;
	std::vector<std::vector<Edge>> nodes(n);
	for (auto i = 1; i < n; ++i) {
		int a, b, c; std::cin >> a >> b >> c; --a; --b;
		nodes[a].push_back(Edge{ b, c });
		nodes[b].push_back(Edge{ a, c });
	}
	int q, k; std::cin >> q >> k; --k;
	std::vector<long long int> min_distance(n, -1);
	std::stack<int> stack;
	min_distance[k] = 0; stack.push(k);
	while (!stack.empty()) {
		const auto top = stack.top(); stack.pop();
		for (const auto edge : nodes[top]) if (min_distance[edge.to] == -1) {
			min_distance[edge.to] = min_distance[top] + edge.length;
			stack.push(edge.to);
		}
	}
	for (auto i = 0; i < q; ++i) {
		int x, y; std::cin >> x >> y; --x; --y;
		std::cout << min_distance[x] + min_distance[y] << std::endl;
	}
}


Measured memory_bytes: 8820
# -*- coding: utf-8 -*-
a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

m_list = []

for i in range(m):
    m_list.append(list(map(int, input().split())))


a_min = 1000000000
for item in a_list:
    if item < a_min:
        a_min = item

b_min = 1000000000
for item in b_list:
    if item < b_min:
        b_min = item

val_min = a_min + b_min

for item in m_list:
    tmp = a_list[item[0]-1] + b_list[item[1]-1] - item[2]
    if tmp < val_min:
        val_min = tmp

print(val_min)


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

#define IL __inline__ __attribute__((always_inline))

#define For(i, a, b) for (int i = a, i##end = b; i <= i##end; ++ i)
#define FOR(i, a, b) for (int i = a, i##end = b; i < i##end; ++ i)
#define Rep(i, a, b) for (int i = a, i##end = b; i >= i##end; -- i)
#define REP(i, a, b) for (int i = (a) - 1, i##end = b; i >= i##end; -- i)

typedef long long LL;

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

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

template <class T>
IL T mymax(const T &a, const T &b) {
  return a > b ? a : b;
}

template <class T>
IL T mymin(const T &a, const T &b) {
  return a < b ? a : b;
}

template <class T>
IL T myabs(const T &a) {
  return a > 0 ? a : -a;
}

const int INF = 0X3F3F3F3F;
const double EPS = 1E-10, PI = acos(-1.0);

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
/*------------------------------header------------------------------*/

const int MAXN = 100000 + 5;

int answer, k;

struct Tree {
  int hed[MAXN], nxt[MAXN], to[MAXN], fa[MAXN], cnt;
  
  void addEdge(int u, int v) {
    ++ cnt;
    to[cnt] = v;
    nxt[cnt] = hed[u];
    hed[u] = cnt;
  }
  
  int DFS(int u) {
    int max = 0;
    for (int e = hed[u]; e; e = nxt[e]) {
      int v = to[e];
      chkmax(max, DFS(v));
    }
    ++ max;
    if (max >= k && u != 1 && fa[u] != 1) {
      ++ answer;
      return 0;
    }
    return max;
  }
} T;

int main() {
  int n;
  scanf("%d%d", &n, &k);
  int x;
  scanf("%d", &x);
  if (x != 1) {
    ++ answer;
  }
  For(i, 2, n) {
    scanf("%d", &T.fa[i]);
    T.addEdge(T.fa[i], i);
  }
  T.DFS(1);
  printf("%d\n", answer);
  return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

const ll com_max = 2000000;
ll fac[com_max], inv[com_max], finv[com_max];

void com_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for (ll i = 2; i < com_max; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll com(ll n, ll k) {
    if (n < k) {
        return 0;
    }
    if (n < 0 || k < 0) {
        return 0;
    }

    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll rep_square(ll a, ll b) {
    // return a^b
    ll ans = 1;
    ll base = a;
    while (b != 0) {
        if (b & 1) {
            ans *= base;
            ans %= mod;
        }
        base *= base;
        base %= mod;
        b >>= 1;
    }
    return ans;
}

int main() {
    com_init();
    ll k;
    string s;
    cin >> k >> s;
    ll n = s.length();
    ll ans = 0;

    rep(i, k + 1) {
        ll temp = com(n + k - i - 1, n - 1);

        temp *= rep_square(26, i);
        temp %= mod;

        temp *= rep_square(25, k - i);
        temp %= mod;

        ans += temp;
        ans %= mod;
    }

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



Measured memory_bytes: 52192
MAX = 20000
END = '?'
counter = 0
while counter < MAX:
  a, op, b = input().split() 
  if op == END:
    break
  a=int(a)
  b=int(b)
  if op=='+':
    print(a+b)
  elif op=='-':
    print(a-b)
  elif op=='*':
    print(a*b)
  else:
    print(int(a/b))


Measured memory_bytes: 5596
package main

import (
	"os"
	"fmt"
	"bufio"
	"strings"
)

func main() {
	var sc = bufio.NewScanner(os.Stdin)	
	if (sc.Scan()) {
		if (isABC(sc.Text())) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func isABC(text string) bool {
	if (strings.Contains(text, "a") && 
	    strings.Contains(text, "b") && 
		strings.Contains(text, "c")) {
		return true	
	} else {
		return false
	}
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    ll N,sum=0,left=0;
    cin>>N;
    vector<ll> A(N);
    REP(i,N){
        cin>>A[i];
        sum+=A[i];
    }
    int i=0;
    while(abs(2*left-sum)>abs(2*(left+A[i])-sum)){
        left+=A[i];
        i++;
    }
    cout<<abs(sum-2*left)<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define maxN 100000
using namespace std;
unsigned long long N,M,S=0;
typedef pair<int, int > t;
int A[maxN];
t arr[maxN];

void input()
{
    cin>>N>>M;
    for(int i=0;i<N;i++)
    {
        cin>>A[i];
    }
    for(int i=0;i<M;i++)
    {
        cin>>arr[i].second>>arr[i].first;
    }
}

void solve()
{
    int cnt=0, k=M-1 , l=N-1 ;
    sort(A,A+N);
    sort(arr,arr+M);
    while(cnt<N)
    {
        if(arr[k].first>=A[l] && k>=0 || l<0)
        {
            S=S+arr[k].first;
            arr[k].second--;
            if(arr[k].second==0)
                k--;
        }
        else if( k<0 || arr[k].first<A[l] && l>=0)
        {
            S+=A[l];
            l--;
        }
        cnt++;
    }
}
int main() 
{
    input();
    solve();
    cout<<S;
    return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int dp[410][410][410];
int n, suma, sumb;
inline int power(int a, int b) {
    long long res = a, ans = 1;
    for (; b; b >>= 1, res = res * res % mod) if (b & 1) ans = ans * res % mod;
    return ans;
}
int fac[410], facinv[410];
int main() {
    scanf("%d", &n);
    fac[0] = 1;
    for (int i = 1; i <= 400; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
    facinv[400] = power(fac[400], mod - 2);
    for (int i = 400; i --> 0; ) facinv[i] = 1ll * (i + 1) * facinv[i + 1] % mod;
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        for (int j = 0; j <= suma; j++)
            for (int k = 0; k <= sumb; k++) dp[i][j][k] = dp[i - 1][j][k];
        for (int j = 0, now = 1; j < b; j++, now = 1ll * now * a % mod) {
            for (int k = 0; k <= suma; k++)
                for (int l = 0; l <= sumb; l++) {
                    dp[i][k + a][l + j] = (
                        dp[i][k + a][l + j] 
                        + 1ll * (mod - dp[i - 1][k][l]) * facinv[j] % mod * now
                    ) % mod;
                }
        }
        suma += a, sumb += b - 1;
    }
    int ans = 0;
    for (int i = 1; i <= suma; i++)
        for (int j = 0; j <= sumb; j++) {
            // cerr << dp[n][i][j] << endl;
            ans = (ans + 1ll * dp[n][i][j] * fac[j] % mod * power(power(i, j + 1), mod - 2)) % mod;
        }
    ans = 1ll * ans * (mod - suma) % mod;
    return cout << ans << endl, 0;
}

Measured memory_bytes: 262400
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int K;
	scanf("%d", &K);
	
	int i, j, d = 0, X[100] = {1};
	for (i = 1; i < K; i++) {
		for (j = 0; j < d; j++) if (X[j] != 9 && X[j] <= X[j+1]) break;
		if (j < d || X[j] != 9) {
			for (X[j--]++; j >= 0; j--) X[j] = (X[j+1] > 0)? X[j+1] - 1: 0;
		} else {
			X[++d] = 1;
			for (j = 0; j < d; j++) X[j] = 0;
		}
	}
	
	for (i = d; i >= 0; i--) printf("%d", X[i]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 4223352036854775007
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=10005;
const int NN=2005;
const ll md=998244353;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll x;
    cin >> x;
    ll t=100;
    int i=0;
    while (t<x){
        i++;
        t+=(t)/100;
    }

    cout << i << E;
    r0;
}
/*









*/


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

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

	ll n; int x, m;
	cin >> n >> x >> m;
	if (n == 1) {
		cout << x << endl;
		return 0;
	}

	vector<bool> v(m, false);
	v[x] = true;
	ll ans = x;
	deque<ll> dq;
	dq.push_back(x);
	for (int i = 1; i < n; i++) {
		ll a = dq.back() * dq.back() % m;
		if (v[a]) {
			n -= dq.size();
			while (dq.front() != a) dq.pop_front();
			break;
		} else {
			ans += a;
			dq.push_back(a);
			v[a] = true;
		}
		if (i == n - 1) {
			cout << ans << endl;
			return 0;
		}
	}

	ll sz = dq.size();
	vector<ll> sum(sz + 1, 0);
	for (int i = 0; i < sz; i++) sum[i + 1] = sum[i] + dq[i];
	cout << ans + sum[sz] * (n / sz) + sum[n % sz] << endl;

	return 0;
}

Measured memory_bytes: 4024
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

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


Measured memory_bytes: 256
n = int(input())
lis = [int(input()) for i in range(n)]
if lis[0] != 0:print(-1);exit()
ans = 0
for i in range(n-1,0,-1):
    if lis[i] - lis[i-1] > 1:print(-1);exit()
    elif lis[i] - lis[i-1] == 1:ans += 1
    else:ans += lis[i]
print(ans)

Measured memory_bytes: 58968
#include <cstdio>
#include <random>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <chrono>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long


using namespace std;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const long long INF = 1e18;
const int M = 1e9 + 7;





signed main()
{
	string s;
	cin >> s;
	if(s == "Sunny") cout << "Cloudy" << endl;
	if(s == "Rainy") cout << "Sunny" << endl;
	if(s == "Cloudy") cout << "Rainy" << endl;





    
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict
d = defaultdict(int)

N, M = map(int, input().split())
li = [list(map(int, input().split())) for n in range(M)]

for i in li:
  if i[1] == N:
    d[i[0]] += 1

for i in li:
  if i[0] == 1 and d[i[1]] != 0:
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")

Measured memory_bytes: 67472
import sys
for s in sys.stdin:
  x1,y1,x2,y2,xq,yq =map(float,s[:-1].split(","))
  if x2==x1:
    y=yq
    x=x1
  else:
    m=1.0*(y2-y1)/(x2-x1)
    a=m*m+1
    x0=m*x1-y1
    y0=xq+m*yq
    x=(m*x0+y0)/a
    y=(-x0+m*y0)/a
  print "%0.5f %0.5f"%(2*x-xq,2*y-yq)

Measured memory_bytes: 4248
n = int(input())
lst = list(input())

ans = []
for i in range(1000):
    s = str(i).zfill(3)
    pos = 0
    is_exist = True
    for j in range(3):
        if s[j] in lst[pos:]:
            pos += lst[pos:].index(s[j]) + 1
        else:
            is_exist = False
            break
    if is_exist:
        ans.append(s)
print(len(ans))


Measured memory_bytes: 9372
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N;
    ll A,B;
    cin >>N >>A>>B;
    vector<ll> P(N);
    rep(i,N)cin >> P[i];
    ll a = 0,b = 0,c = 0;
    rep(i,N){
        if(P[i] <= A)a++;
        else if(P[i] > B)c++;
        else b++;
    }
    cout << min(a,min(b,c)) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S / 3600;
        int m = S % 3600 / 60;
        int s = S % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26132
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>

using namespace  std;

int A;
int B;
int C;
int difAB;
int rm_c;


int main(){
    cin>>A;
    cin>>B;
    cin>>C;

    difAB=A-B;
    rm_c=C-difAB;

    if (rm_c>0){
    cout<<rm_c;}
    else {
        cout<<0;
    }



return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/
long long GCD(long long a, long long b){
    return (b ? GCD(b, a%b) : a);
}
long long LCM(long long a, long long b) {
    return a*b/GCD(a,b);
}

/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n,xx; cin >> n >> xx;
    vi x(n); rep(i,n) cin >> x[i];
    vi d(n); rep(i,n) d[i] = abs(x[i]-xx);

    int ans = GCD(d[0], d[1]);
    for(auto dd : d) ans = GCD(ans,dd);

    cout << ans << '\n';
    // printf("ExcutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int sum=0;
    for(int i=0;i<m;i++)
    {
        int x;
        cin>>x;
        sum+=x;
    }
    if(sum>n)
    {
        cout<<"-1";
    }
    else
    {
        cout<<n-sum;
    }
    return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100005];

int main()
{
    int N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }
    sort(A, A + N);
    ll a = A[N - 1];
    ll b = A[0];
    REP(i, N - 1)
    {
        if (a % 2 == 0)
        {
            if (abs(a / 2 - b) > abs(a / 2 - A[i]))
                b = A[i];
        }
        else
        {
            if (std::min(abs(a / 2 - b), abs(a / 2 - b + 1)) > std::min(abs(a / 2 - A[i]), abs(a / 2 - A[i] + 1)))
                b = A[i];
        }
    }

    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 1024
use proconio::input;

fn main() {
    input! {
        s:String,
    }

    let mut dp = vec![false; s.len() + 1];
    dp[0] = true;

    for i in 0..dp.len() {
        if !dp[i] {
            continue;
        }
        for p in &["dreamer", "dream", "eraser", "erase"] {
            if s[i..].starts_with(p) {
                dp[i + p.len()] = true
            }
        }
    }

    println!("{}", if dp[dp.len() - 1] { "YES" } else { "NO" })
}


Measured memory_bytes: 2412
n = int(input())
r = 0
ma = 0
for i in range(n):
    d1 , d2 = map(int, input().split())
    if d1==d2:
        r+=1
        ma = max(r,ma)
    else:
        r=0
if ma>=3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9164
#include<cstdio>
#include<cmath>
#include<algorithm>
#define INF 1000000001
using namespace std;
int n;
int dy[100005][3];
int main() {
	scanf("%d", &n);
	int i,j,k;
	for (i = 1; i <= n; i++) {
		int activity;
		for (j = 0; j < 3; j++) {
			scanf("%d", &activity);
			dy[i][j] = max(dy[i-1][(j+1)%3],dy[i-1][(j+2)%3])+activity;
		}
	}
	int a = max(dy[n][0], dy[n][1]);
	printf("%d", max(a,dy[n][2]));
	return 0;
}
/*
#include<cstdio>
int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt","w",stdout);
	return 0;
}
*/

Measured memory_bytes: 1280
import sys
from collections import namedtuple


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != "\r":
            break
    return result


def next_int() -> int:
    return int(next_str())


query = namedtuple('qry', ('l', 'r'))
Q = next_int()
queries = [query(next_int(), next_int()) for i in range(Q)]
right = -sys.maxsize
left = sys.maxsize


def is_prime(n: int) -> bool:
    if n < 2:
        return False
    i = 2
    while i ** 2 <= n:
        if n % i == 0:
            return False
        i += 1
    return True


def main() -> None:
    global left, right
    for q in queries:
        left = min(left, q.l)
        right = max(right, q.r)

    dp = [0] * ((right - left) // 2 + 1)

    for i in range(left, right + 1, 2):
        j = (i - left) // 2
        if j != 0:
            dp[j] = dp[j - 1]
        if is_prime(i) and is_prime((i + 1) // 2):
            dp[j] += 1

    for q in queries:
        ans = 0
        ans += dp[(q.r - left) // 2]
        if q.l != left:
            ans -= dp[(q.l - left) // 2 - 1]

        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 19084
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
char* replace(char* s,const char* before,const char* after)
{
  assert(s!=(char*)NULL);assert(before!=(char*)NULL);assert(after!=(char*)NULL);
  const size_t szb=strlen(before),sza=strlen(after);
  char* pt=s;
  if(szb==0)return s;
  for(;;)
  {
    pt=strstr(pt,before);if(pt==(char*)NULL)break;const char* remain=pt+szb;
    memmove(pt+sza,remain,strlen(remain)+1);
    memcpy(pt,after,sza);
    pt+=sza;
  }
  return s;
}
int main(void)
{
  int N,x,y,sw,pw3=1,A[531441],B[531441],S[200000];char T[200001];
  x=scanf("%d %s",&N,T);
  replace(T,"SS","");if(T[0]=='\n')return 0;
  rep(i,N)
  {
    rep(j,pw3)rep(k,3)B[j+k*pw3]=k;sw=0;
    rep(j,strlen(T))
    {
      if(T[j]=='R')
      {
        y=S[j];
        rep(k,3){x=y+k*pw3;if(B[x]+sw==2)S[j]=x;B[x]+=sw+1;B[x]%=3;}
      }
      if(T[j]=='S')sw^=1;
    }
    rep(j,pw3){y=A[j];rep(k,3){x=j+k*pw3;A[x]=y+(sw?3-B[x]:B[x])%3*pw3;}}
    pw3*=3;
  }
  rep(i,pw3)printf("%d%c",A[i],i+1==pw3?'\n':' ');
}

Measured memory_bytes: 9048
// scanf 等でエラーを出さないように追加
#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <algorithm>
#include <numeric>
#include <set>
#include <functional>
#include <utility>


using namespace std;


typedef long long ll;


const int MAX_N = 100000;
char s[MAX_N+1];

int match(const char my_hand, const char enemy_hand) {
	if (my_hand == enemy_hand) {
		return 0;
	}
	else if (my_hand == 'p') {
		return 1;
	}
	else {
		return -1;
	}
}

int main() {

	scanf("%s", s);
	const int N = strlen(s);
	
	int answer = 0;

	// たぶん違うけど
	// グーとパーを交互に出してみる
	for (int i = 0; i < N; i++) {
		
		char my_hand;
		if (i % 2 == 0) {
			my_hand = 'g';
		}
		else {
			my_hand = 'p';
		}

		answer += match(my_hand, s[i]);
	}


	cout << answer << endl;

	return 0;
}

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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
long double pi = 3.141592653589793;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    long double a,b; cin >> a >> b;
    long double h,m; cin >> h >> m;
    long double w1 = (long double)30.0 * h + (long double)0.5*m;
    long double w2 = (long double)6.0 * m;
    long double w = abs(w1-w2);
    if(w>180) w = (long double)360.0 - w;
    cout << sqrt(a*a + b*b - (long double)2.0 * a * b * cos( pi*w/(long double)180.0)) << endl;

}

Measured memory_bytes: 4152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] ai;
		ai = new int[n];

		for (int i = 0; i < n; i++) {
			ai[i] = scan.nextInt();
		}

		//??????1???????????????????¬???????(" " + ai[j])
		System.out.print(ai[n - 1]);
		for (int j = n - 2; j >= 0; j--) {
			System.out.print(" " + ai[j]);
		}
		//????????????
		System.out.println();
	}

}

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

typedef long long int lli;
typedef long long ll;
typedef long double ld;



int main(){
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n+1]={0};
        for(int i=1;i<=100;i++){
            for(int j=1;j<=100;j++){
                for(int k=1;k<=100;k++){
                    ll x=i*i+j*j+k*k+i*j+i*k+j*k;
                    if(x<=n)
                        a[x]++;
                }
            }
        }
        for(int i=1;i<=n;i++){
            cout<<a[i]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

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

  int n; cin >> n;
  int ans = 1;
  while(ans*2 <= n) {
    ans*=2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include<cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <ctime>
#include <cstring>
#include <cmath>
#include <stack>
#include <set>
#include <unordered_map>
#define INF 0x3f3f3f3f
#define ll long long
#define rep(i, n) for(ll i=0;i<n;i++)
#define per(i, n) for(int i=n;i>=0;i--)
#define rep2(i, n) for(ll i=1;i<=n;i++)
#define pb(x) push_back(x)
#define clint(x, n) memset(x,n,sizeof(x))
#define mp make_pair
#define fi first
#define se second
#define IO std::ios::sync_with_stdio(false)
#define ull unsigned long long
#define ud long double
#define pii pair<int,int>
using namespace std;
const int maxn = 1e6+5;
const ll inf = 100000000000;
const int mod =998244353;
const int MAX = 123123;
const int N =1005;
string str;
inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
ll max(ll a,ll b){
    if(a>b) return a;
    return b;
}
ll min(ll a,ll b){
    if(a<b) return a;
    return b;
}
int main() {
    int m,n;
    cin>>m>>n;
    if(m==1){
        if(n==1) cout<<"Draw"<<endl;
        else cout<<"Alice";
    }
    else if(n==1){
        cout<<"Bob"<<endl;
    }
    else{
        if(m>n) cout<<"Alice"<<endl;
        else if(m==n) cout<<"Draw"<<endl;
        else cout<<"Bob"<<endl;
    }
    return 0;
}

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

int main() {
	ll n;
	cin >> n;
	ll ans = 1001001001;
	auto keta = [&](ll a) {
		ll cnt = 0;
		while (a) a /= 10, cnt++;
		return cnt;
	};
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			ans = min(ans, max(keta(i),keta(n / i)));
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define scan(a,n) for(long long int index=0;index<n;index++) cin>>a[index];
#define print(a,n) for(long long int index=0;index<n;index++) cout<<a[index]<<" ";cout<<endl;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define vli vector<long long int>
#define vlli vector<pair<long long int,long long int>>
#define vsi vector<string>
#define vci vector<char>
#define all(n) n.begin(),n.end()
#define forr(i,a,b) for(i=a;i<b;i++)
#define forrr(i,a,b) for(i=b-1;i>=a;i--)


 
int main() {
   #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fast;
    ll t;
    t=1;
    while(t--){
       ll a, b, c, d;
    cin>>a>>b>>c>>d;
    vli v;
    v.pb(a*c);
    v.pb(a*d);
    v.pb(b*c);
    v.pb(b*d);
    cout<<*max_element(all(v));

            




    }
    
return 0;    
 }  

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

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    vector<string> c;
    rep(i,n) cin >> s[i];
    sort(s.begin(), s.end()); 
    for(int i = 0; i < n; ++i){
        if(i == 0) c.push_back(s[i]);
        else{
            if(s[i] == s[i-1]) continue;
            else c.push_back(s[i]);
        }
    } 
    sort(c.begin(), c.end());
    int m = c.size();
    // rep(i,m) cout << c[i] << " ";
    // cout << endl;
    vector<int> ans(m);
    int j = 0;
    for(int i = 1; i < n; ++i){
        if(s[i] != s[i-1]) ++j;
        else ans[j]++;
    }
    int cnt = 0;
    rep(i,m){
        cnt = max(cnt, ans[i]);
    }
    cout << endl;
    rep(i,m){
        if(ans[i] == cnt) cout << c[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 17816
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, m, ans = 0;
pair<int, int> a[N];
vector<int> g[N];

int32_t main()
{
	IOS;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i].first >> a[i].second;
		g[a[i].first].push_back(a[i].second);
	}
	multiset<int> s;
	for(int i = 1; i <= m; i++)
	{
		for(auto &it:g[i])
			s.insert(it);
		if(s.size())
		{
			ans += *s.rbegin();
			s.erase(--s.end());
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 9856
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        long mod = (long)Math.pow(10,9)+7;
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long ans = rep2(2,n,mod)-1;
        long alla = 1;
        long allb = 1;
        long diva = 1;
        long divb = 1;
        for(int i = 0; i < a; i++){
            alla *= (n-i);
            alla %= mod;
            diva *= (a-i);
            diva %= mod;
        }
        for(int i = 0; i < b; i++){
            allb *= (n-i);
            allb %= mod;
            divb *= (b-i);
            divb %= mod;
        }
        alla *= rep2(diva,(long)Math.pow(10,9)+5,mod)%mod;
        alla %= mod;
        allb *= rep2(divb,(long)Math.pow(10,9)+5,mod)%mod;
        allb %= mod;
        ans -= (alla+allb);
        while(ans < 0){
            ans += mod;
        }
        System.out.println(ans%mod);
    }
    
    private static long rep2(long b, long n, long mod){
        if(n == 0) return 1;
        if(n == 1) return b;
        long bn = rep2(b,n/2,mod)%mod;
        if(n % 2 == 0){
            return (long)(bn%mod*bn%mod)%mod;
        }else{
            return (long)(bn%mod*bn%mod)%mod*b%mod;
        }
    }
}


Measured memory_bytes: 21844
use proconio::input;

fn main() {
    input! {
        n :usize,
        av: [i64; n],
    };
    let inf = 1_000_000_000_000_000_i64;
    let m = if n % 2 == 0 { 1 } else { 2 };
    // dp[i][j] = x
    // i (0<=i<=n) までで j (0<=j<=m) 個を飛ばしたときの最大値が x
    let mut dp = vec![vec![-inf; m + 1]; n + 1];
    dp[0][0] = 0;
    for (i, &a) in av.iter().enumerate() {
        for j in 0..=m {
            // 飛ばす場合
            if j + 1 <= m {
                dp[i + 1][j + 1] = std::cmp::max(dp[i + 1][j + 1], dp[i][j]);
            }
            // 飛ばさない場合
            dp[i + 1][j] = std::cmp::max(
                dp[i + 1][j],
                dp[i][j] + if (i + j) % 2 == 0 { a } else { 0 },
            );
        }
    }
    let ans = dp[n][m];
    println!("{}", ans);
}


Measured memory_bytes: 16708
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void){


	int a[100000];
	int b[100000];
	int c, d;
	int k;
	int n, m;
	int s, t;
	int x, y, z;
	long long ans;

	scanf("%d %d", &n,&m);
	if (n == m){
		ans = 2;
		for (int i = 1; i <= n; i++){
			ans = ans*i;
			ans = ans % 1000000007;
		}
		for (int i = 1; i <= m; i++){
			ans = ans*i;
			ans = ans % 1000000007;
		}
	}
	else if (n == m + 1 || m == n + 1){
		ans = 1;
		for (int i = 1; i <= n; i++){
			ans = ans*i;
			ans = ans % 1000000007;
		}
		for (int i = 1; i <= m; i++){
			ans = ans*i;
			ans = ans % 1000000007;
		}
	}
	else{
		ans = 0;
	}


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

	return 0;
}


Measured memory_bytes: 128
import math
S = input().split()
A = int(S[0])
B = S[1]
B = B.rsplit(".")
B0 = B[0]
B1 = B[1]
B = int(B0)*100+int(B1)
ans = "000"+str(A*B)
n = len(ans)



print(int(ans[:n-2]))



Measured memory_bytes: 62000
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
long long l,n,ans;
char s[100005];
struct node{node *ch[2];node(){ch[0] = ch[1] = NULL;}};
node *rt = new node();
void dfs(node *nd, long long d){
	if(nd != NULL){
		dfs(nd->ch[0], d-1);
		dfs(nd->ch[1], d-1);
	}else ans ^= d&-d;
}
int main(){
	scanf("%lld%lld\n", &n, &l);
	rep(i,n){
		scanf("%s\n", s);
		node *nd = rt;
		rep(j,strlen(s)){
			if(!nd->ch[s[j]-'0']) nd->ch[s[j]-'0'] = new node();
			nd = nd->ch[s[j]-'0'];
		}
	}
	dfs(rt,l+1);
	puts(ans ? "Alice" : "Bob");
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[200010];map <ll ,ll>b;
int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	for(ll i=1;i<n;i++){
		a[i]=a[i-1]+a[i];
	}
	for(ll i=0;i<n;i++){
		ll now=a[i];
		b[now]++;
	}
	ll ans=0;
    for(auto itr = b.begin(); itr != b.end(); ++itr) {
        ll key= itr->first;
        ll value=itr->second;
        if(key!=0){
        	value--;
        }
        ans+=value*(value+1)/2;
    }	
    cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 14336
import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
void main() {
	string s, maxls, maxas;
	int[string] nums;
	while( (s=readln()).length != 0 ){
		string[] input = split(s);
		foreach(int i, string ts; input){
			nums[ts]++;
			if(maxls.length<ts.length) maxls=ts;
		}
	}
	int mn=-1;
	foreach(string key, int n; nums){
		if(mn<n){
			mn=n;
			maxas=key;
		}
	}
	writeln(maxas, " ", maxls);
}

Measured memory_bytes: 2544
use std::cmp;

const INF: usize = 1e18 as usize;

fn dfs(v: usize, parent: usize, x: &Vec<usize>, graph: &Vec<Vec<usize>>) -> usize {
    let mut dp = vec![INF; x[v] + 1];
    dp[0] = 0;

    for &child in graph[v].iter() {
        if child == parent {
            continue;
        }
        let white = dfs(child, v, x, graph);
        let black = x[child];
        let mut next = vec![INF; x[v] + 1];
        for i in 0..(x[v] + 1) {
            if dp[i] != INF {
                if i + white <= x[v] {
                    next[i + white] = cmp::min(next[i + white], dp[i] + black);
                }
                if i + black <= x[v] {
                    next[i + black] = cmp::min(next[i + black], dp[i] + white);
                }
            }
        }
        dp = next;
    }
    
    *dp.iter().min().unwrap()
}

fn main() {
    let mut sc = Scanner::new();
    let n = sc.read();
    let mut graph = vec![vec![]; n];
    for i in 0..(n - 1) {
        let p = sc.read::<usize>() - 1;
        graph[p].push(i + 1);
        graph[i + 1].push(p);
    }
    let x = sc.read_vec(n);

    if dfs(0, INF, &x, &graph) != INF {
        println!("POSSIBLE");
    } else {
        println!("IMPOSSIBLE");
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 18684
#include <stdio.h>

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);

    if(a == 0 || b == 0 || (a < 0 && b > 0))
    {
        printf("Zero");
    }
    else
    {
        if(a > 0 && b > 0)
        {
            printf("Positive");
        }
        else
        {
            if((b - a) % 2 == 0)
            {
                printf("Negative");
            }
            else
            {
                printf("Positive");
            }
        }
    }
    

    printf("\n");
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    Map<String, Integer> map = new TreeMap<>();

    int N = sc.nextInt();
    int max = 0;
    for (int i = 0; i < N; i++) {
      String S = sc.next();
      if (map.containsKey(S)) {
        int tmp = map.get(S) + 1;
        map.put(S, tmp);
        max = Math.max(max, tmp);
      } else {
        map.put(S, 1);
        max = Math.max(max, 1);
      }
    }

    for (String key : map.keySet()) {
      if (map.get(key) == max) System.out.println(key);
    }
  }
}

Measured memory_bytes: 75604
n, m = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for y in range(n)]
b = [int(input()) for x in range(m)]
c = []

for i in range(n):
    c.append(sum([a[i][x] * b[x] for x in range(m)]))

for i in c:
    print(i)

Measured memory_bytes: 8128
#include <iostream>
#include <string>

using namespace std;

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ret=0;
    for(int i=1;i<n;i++){
        int mx=0;
        int now=0;
        for(int j=0;j<n-i;j++){
            if(now==i||s[j]!=s[j+i]){
                mx=max(mx,now);
                now=0;
            }else{
                now++;
            }
        }
        mx=max(mx,now);
        ret=max(ret,mx);
    }
    cout<<ret<<endl;
}



Measured memory_bytes: 384
N = int(input())
S = input()
d = '111'
ans = S
d


a = 0

for i in S:
    if a:
        if i=='(':
            a = a + 1
        if i==')':
            a = a - 1
    else:
        if i=='(':
            a = a + 1
        if i==')':
            ans = '(' + ans

ans = ans + ')'*a
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

const int INF = 1 << 30;

int A[88][88], B[88][88];
bool dp[88][88][88 * 88 * 2];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    rep(i, 0, H) rep(j, 0, W) cin >> A[i][j];
    rep(i, 0, H) rep(j, 0, W) cin >> B[i][j];
    int M = 0;
    rep(i, 0, H) rep(j, 0, W) {
        M = max(M, abs(A[i][j] - B[i][j]));
    }
    dp[0][0][abs(A[0][0] - B[0][0])] = true;
    rep(i, 0, H) rep(j, 0, W) rep(k, 0, M * (H + W) + 1) {
        if (i + 1 < H) {
            if (k + abs(A[i + 1][j] - B[i + 1][j]) <= M * (H + W)) {
                dp[i + 1][j][k + abs(A[i + 1][j] - B[i + 1][j])] |= dp[i][j][k];
            }
            if (abs(k - abs(A[i + 1][j] - B[i + 1][j])) <= M * (H + W)) {
                dp[i + 1][j][abs(k - abs(A[i + 1][j] - B[i + 1][j]))] |= dp[i][j][k];
            }
        }
        if (j + 1 < W) {
            if (k + abs(A[i][j + 1] - B[i][j + 1]) <= M * (H + W)) {
                dp[i][j + 1][k + abs(A[i][j + 1] - B[i][j + 1])] |= dp[i][j][k];
            }
            if (abs(k - abs(A[i][j + 1] - B[i][j + 1])) <= M * (H + W)) {
                dp[i][j + 1][abs(k - abs(A[i][j + 1] - B[i][j + 1]))] |= dp[i][j][k];
            }
        }
    }
    int ans = INF;
    rep(i, 0, M * (H + W) + 1) {
        if (dp[H - 1][W - 1][i]) {
            ans = min(ans, i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 106624
#include<stdio.h>
#include<stdlib.h>

int main() {
	int n;
	int *a;
	int loop;
	int ans = 0;

	scanf("%d", &n);
	a = malloc(sizeof(int)*n);
	for (loop = 0; loop < n; loop++) {
		scanf("%d", &a[loop]);
		a[loop]--;
	}
	for (loop = 0; loop < n; loop++)
		if (a[a[loop]] == loop&&loop < a[loop]) ans++;

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

	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	int i, j, imax, jmax = 0, count = 0;
	int *buf = calloc(1, 100001 * sizeof(int));
	
	scanf("%d", &imax);
	
	for (i = 0; i < imax; i++) {
		int tmp;
		scanf("%d", &tmp);
		if (jmax < tmp) {
			jmax = tmp;
		}
		if (tmp == 0) {
			buf[tmp] = buf[tmp] + 1;
			buf[tmp + 1] = buf[tmp + 1] + 1;
		} else {
			buf[tmp - 1] = buf[tmp - 1] + 1;
			buf[tmp] = buf[tmp] + 1;
			buf[tmp + 1] = buf[tmp + 1] + 1;
		}
	}
	
	for (j = 0; j < 100000; j++) {
		if (count <= buf[j]) {
			count = buf[j];
		}
	}
	
	printf("%d", count);
	return 0;
}


Measured memory_bytes: 512