akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

int deg[100001];
int main() {
	int n,m;
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		deg[x]++,deg[y]++;
	}
	fup(i,1,n,1)if(deg[i]&1)return !printf("NO");
	printf("YES");
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#define MAX 247000
using namespace std;
bool arr[MAX];
void Era(){
	for(int i = 0; i <= MAX; i++){
		arr[i] = true;
	}
	for(int i = 2; i <= sqrt(MAX); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) <= MAX; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}
}
int Eratosthenes(int N){
	int cnt=0;
	for(int i = N+1; i <= N*2; i++){
		if(arr[i]){
			//cout << i << endl;
			cnt++;
		}
	}
	return cnt;
}
int main(){
	Era();
	while(1){
		int n;
		cin >> n;
		if(n==0)	break;
		else	cout << Eratosthenes(n) << endl;
	}
	return 0;
}


Measured memory_bytes: 3340
#include <vector>
#include <stdio.h>
#include <iostream>
#include <algorithm>

#include <vector>
#include <queue>

using namespace std;




class TopologicalSort {
public:
  int n;
  vector< vector<int> > G;
  vector<bool> used;
  vector<int> indeg;
  vector<int> out;

  TopologicalSort(int _n): n(_n), G(n), used(n), indeg(n), out(0) {}

  void bfs(int start) {
    queue<int> q;
    q.push(start);
    while (!q.empty()) {
      int cur = q.front(); q.pop();
      out.push_back(cur);
      for (int v: G[cur]) {
	indeg[v]--;
	if (indeg[v] == 0 && !used[v]) {
	  used[v] = true;
	  q.push(v);
	}
      }
    }
  }
  
  void add_edge(int from, int to) {
    G[from].push_back(to);
  }
  
  vector<int> build() {
    fill(indeg.begin(), indeg.end(), 0);
    fill(used.begin(), used.end(), 0);
    for (int i = 0; i < n; ++i)
      for (int v: G[i]) indeg[v]++;

    for (int i = 0; i < n; ++i) {
      if (indeg[i] == 0 && !used[i]) bfs(i);
    }
    return out;
  }
};

int main () {
  int n;
  scanf("%d", &n);
  vector< vector<int> > a(n, vector<int>(n - 1));

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n - 1; ++j) {
      scanf("%d", &a[i][j]);
      a[i][j]--;
    }
  }

  vector< vector<int> > ids(n, vector<int>(n));
  int n_v = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n - 1; ++j) {
      if (i < a[i][j]) {
	ids[i][a[i][j]] = n_v++;
      }
    }
  }

  TopologicalSort tp = TopologicalSort(n_v);
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j < n - 1; ++j) {
      int last_id = ids[min(i, a[i][j - 1])][max(i, a[i][j - 1])];
      int next_id = ids[min(i, a[i][j])][max(i, a[i][j])];
      tp.add_edge(last_id, next_id);
    }
  }

  vector<int> result = tp.build();
  if (result.size() != n_v) {
    printf("-1\n");
    return 0;
  }

  reverse(result.begin(), result.end());
  vector<int> dp(n_v, 0);
  int ans = 0;
  for (int id: result) {
    for (int v: tp.G[id]) {
      dp[id] = max(dp[id], dp[v] + 1);
    }
    ans = max(dp[id], ans);
  }
  printf("%d\n", ans + 1);
  return 0;
}


Measured memory_bytes: 43512
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func pow(a, b int) int {
	ans := 1
	for i := b; i > 0; i-- {
		ans *= a
	}
	return ans
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	m := make(map[int]bool)
	c := 0
	for i := 0; i < n; i++ {
		a := nextInt()
		if m[a] {
			m[a] = false
			c--
		} else {
			m[a] = true
			c++
		}
	}

	fmt.Println(c)
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;
int dx[] = {0, -1, 0, 1}, dy[] = {-1, 0, 1, 0};
vector<pair<int, int>> edge(4);
bool f = 0;
ll n, m, i, j, k;
string s[60];
bool ok[60][60];
void dfs(int p, pair<int, int> cur, int direct) {
    if(cur == edge[p]) {
        f = 1;
        return;
    }
    for(int i = 0; i < 4; i++) {
        int nxtx = dx[(i + direct) % 4] + cur.first, nxty = dy[(i + direct) % 4] + cur.second;
        if(nxtx >= 0 && nxtx < n && nxty >= 0 && nxty < m) {
            if(p==3 && nxtx==0 && nxty==0)f=1;
            if(s[nxtx][nxty] == '.') {
                s[nxtx][nxty] = '#';
                dfs(p, {nxtx, nxty}, (i + direct + 2) % 4);
                if(f) return;
            }
        }
    }
    return;
};

int main() {
    while(1) {
        for(i = 0; i < 60; i++) {
            for(j = 0; j < 60; j++) {
                ok[i][j] = 0;
            }
        }
        cin >> n >> m;
        if(n == 0) break;
        for(i = 0; i < n; i++) {
            cin >> s[i];
        }
        f=0;
        s[0][0]='#';
        edge[0] = {0, m - 1};
        edge[1] = {n - 1, m - 1};
        edge[2] = {n - 1, 0};
        edge[3] = {0, 0};
        dfs(0, edge[3], 1);
        if(f == 0) {
            cout << "NO" << endl;
            continue;
        }
        /*cout << "a" << endl;
        for(i = 0; i < n; i++) {
            for(j = 0; j < m; j++) {
                cout << s[i][j];
            }
            cout << endl;
        }*/
        f = 0;
        dfs(1, edge[0], 4);
        if(f == 0) {
            cout << "NO" << endl;
            continue;
        }

        f = 0;
        dfs(2, edge[1], 0);
        if(f == 0) {
            cout << "NO" << endl;
            continue;
        }

        f = 0;
        dfs(3, edge[2], 1);
        if(f == 0) {
            cout << "NO" << endl;
            continue;
        }
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 3340
#include<bits/stdc++.h>
#define N 100005
#define LL long long
#define INF (1LL<<60)
using namespace std;
int n,m; LL a[N],b[N],sum,ans=-INF;
int main()
{
	int i,x; char op;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		if(i==1) op='+'; else scanf("%c",&op);
		scanf("%d ",&x),sum+=x;
		if(op=='-') a[++m]=x; else b[m]+=x;
	  }
	if(!m) ans=sum;
	for(i=1;i<=m;i++){
		ans=max(ans,sum-2*(a[i]+b[i]));
		sum-=2*a[i];
	  }
	cout<<max(ans,sum);
	return 0;
}

Measured memory_bytes: 1152
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll N=305;
ll read(){
	ll s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
ll n,a[N],sum,tot,ans;
int main(){
	n=read();
	for(ll i=1;i<=n;i++)a[i]=read();
	for(ll i=3;i<=n;i++)sum^=a[i];
	tot=a[1]+a[2];tot-=sum;
	if(tot<0){puts("-1");return 0;}
	for(ll i=42;i>=0;i--){
		if(2*(1ll<<i)<=tot){
			if((sum>>i&1)){puts("-1");return 0;}
			ans+=(1ll<<i);
			tot-=2*(1ll<<i);
		}
	}
	if(tot){puts("-1");return 0;}
	if(ans>a[1]){puts("-1");return 0;}
	for(ll i=42;i>=0;i--){
		if((sum>>i&1)&&(ans+(1ll<<i))<=a[1])ans+=(1ll<<i);
	}
	if(ans==0){puts("-1");return 0;}
	cout<<a[1]-ans;
	return 0;
}

Measured memory_bytes: 3392
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 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;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
	double r, g;
	cin >> r >> g;
	double ans = (2 * g) - r;
	cout << ans << endl;
    return;
}

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



Measured memory_bytes: 256
let id x = x

let n = Scanf.scanf "%d\n" id

let a =
  Array.init n (fun _ -> Scanf.scanf "%d " id)
  |> Array.to_list |> List.fast_sort compare

let m = 1000000007

let rec check = function
  | [] -> true
  | a :: b :: tl when a = b -> check tl
  | _ -> false

let calc n =
  let rec aux i tmp = if i <= 0 then tmp else aux (pred i) (tmp * 2 mod m) in
  aux n 1

let () =
  ( match check (if n mod 2 == 1 then List.tl a else a) with
  | true -> calc (n / 2)
  | false -> 0 )
  |> Printf.printf "%d\n"


Measured memory_bytes: 8448
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int D_MAX_V=20002;
const int D_v_size=20002;
struct D_wolf{
	int t,c,r;
	D_wolf(){t=c=r=0;}
	D_wolf(int t1,int c1,int r1){
		t=t1;c=c1;r=r1;
	}
};
vector<D_wolf>D_G[D_MAX_V];
int D_level[D_MAX_V];
int D_iter[D_MAX_V];

void add_edge(int from,int to,int cap){
	D_G[from].push_back(D_wolf(to,cap,D_G[to].size()));
	D_G[to].push_back(D_wolf(from,0,D_G[from].size()-1));
}
void D_bfs(int s){
	for(int i=0;i<D_v_size;i++)D_level[i]=-1;
	queue<int> Q;
	D_level[s]=0;
	Q.push(s);
	while(Q.size()){
		int v=Q.front();
		Q.pop();
		for(int i=0;i<D_G[v].size();i++){
			if(D_G[v][i].c>0&&D_level[D_G[v][i].t]<0){
				D_level[D_G[v][i].t]=D_level[v]+1;
				Q.push(D_G[v][i].t);
			}
		}
	}
}
int D_dfs(int v,int t,int f){
	if(v==t)return f;
	for(;D_iter[v]<D_G[v].size();D_iter[v]++){
		int i=D_iter[v];
		if(D_G[v][i].c>0&&D_level[v]<D_level[D_G[v][i].t]){
			int d=D_dfs(D_G[v][i].t,t,min(f,D_G[v][i].c));
			if(d>0){
				D_G[v][i].c-=d;
				D_G[D_G[v][i].t][D_G[v][i].r].c+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	for(;;){
		D_bfs(s);
		if(D_level[t]<0)return flow;
		for(int i=0;i<D_v_size;i++)D_iter[i]=0;
		int f;
		while((f=D_dfs(s,t,99999999))>0){flow+=f;}
	}
	return 0;
}
char str[200][200];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",str[i]);
	int T=9999;
	int B=-1000;
	int L=9999;
	int R=-9999;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		if(str[i][j]=='X'){
			T=min(T,i);
			B=max(B,i);
			L=min(L,j);
			R=max(R,j);
		}
	}
	if(T==0||B==a-1||L==0||R==b-1){
		printf("-1\n");return 0;
	}
	int s=2*a*b;
	int t=2*a*b+1;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		if(str[i][j]=='X')add_edge(s,(i*b+j)*2+1,99999999);
		else add_edge((i*b+j)*2,(i*b+j)*2+1,1);
		if(i)add_edge((i*b+j)*2+1,(i*b+j-b)*2,99999999);
		else add_edge((i*b+j)*2+1,t,99999999);
		if(i<a-1)add_edge((i*b+j)*2+1,(i*b+j+b)*2,99999999);
		else add_edge((i*b+j)*2+1,t,99999999);
		if(j)add_edge((i*b+j)*2+1,(i*b+j-1)*2,99999999);
		else add_edge((i*b+j)*2+1,t,99999999);
		if(j<b-1)add_edge((i*b+j)*2+1,(i*b+j+1)*2,99999999);
		else add_edge((i*b+j)*2+1,t,99999999);
		
	}
	printf("%d\n",max_flow(s,t));
}

Measured memory_bytes: 2816
import re
s = input()

match = re.findall(r'R+L+', s)
for m in match:
    numR = m.count('R')
    numL = len(m) - numR
    for i in range(numR-1):
        print('0', end=" ")
    if len(m) % 2 == 0:
        print(len(m)//2, end = " ")
        print(len(m)//2, end = " ")
    else:
        small = len(m) // 2
        large = len(m) - small
        if numR % 2 == 0:
            print(small, end = " ")
            print(large, end = " ")
        else:
            print(large, end = " ")
            print(small, end = " ")            

    for i in range(numL-1):
        print('0', end=" ")

Measured memory_bytes: 7408
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a>=13){
    cout<<b<<'\n';
  }else if(5>=a){
    cout<<0<<'\n';
  }else{
    cout<<b/2<<'\n';
  }
  return 0;
}


Measured memory_bytes: 384
use proconio::input;

fn main() {
    input!{
        n: usize,
    }
    let mut ans = 0;
    for i in 1..n {
        for j in 1..n/i+1 {
            if i * j < n {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2132
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define fi first
#define se second
#define int long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 1e5+5, MOD = 998244353;
int t,n,m,k,x,y;
 
int dp[LIM][3];
//0 -- end in swim
//1 -- end in bugs
//2 -- end in hw

int32_t main()
{
	IOS;
    cin>>n;
    int a,b,c;
    cin>>a>>b>>c;
    dp[1][0]=a;
    dp[1][1]=b;
    dp[1][2]=c;
    forsn(i,2,n+1){
        cin>>a>>b>>c;
        dp[i][0]=a+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<ln;
}


Measured memory_bytes: 2560
function main(input){
  input=input.split(' ');
  const r=input[0];
  const D=input[1];
  var x=input[2];
  
  for(var i=0; i<10; i++){
    x=r*x-D;
    console.log(x);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21320
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

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

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

int N,M,L;
struct Edge {
    int to,d,e;
};
struct Node {
    int v,cost,money;

    bool operator<(const Node& rhs) const {
        return cost>rhs.cost;
    }
};
vector<Edge> G[102];

void solve() {
    int dp[102][102];
    rep(i,102) rep(j,102) dp[i][j]=INF;
    rep(i,102) G[i].clear();

    dp[0][L]=0;
    rep(i,M) {
        int a,b,d,e;
        cin>>a>>b>>d>>e;
        a--;
        b--;
        G[a].push_back({b,d,e});
        G[b].push_back({a,d,e});
    }

    priority_queue<Node,vector<Node>> que;
    que.push({0,0,L});
    while(que.size()) {
        Node node=que.top();
        que.pop();
        int v=node.v;
        int money=node.money;

        //printf("[debug] %d %d %d : %d\n",v,node.cost,money,dp[v][money]);
        rep(i,G[v].size()) {
            Edge e=G[v][i];

            if(chmin(dp[e.to][money],dp[v][money]+e.e)) {
                que.push({e.to,dp[e.to][money],money});
            }
            if(money-e.d>=0 && chmin(dp[e.to][money-e.d],dp[v][money])) {
                que.push({e.to,dp[e.to][money-e.d],money-e.d});
            }

        }
    }

    int ans=INF;
    rep(i,L+1) chmin(ans,dp[N-1][i]);

    cout<<ans<<endl;

}

int main() {
    while(cin>>N>>M>>L) {
        if(!N) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1756
#include "bits/stdc++.h"
#define int long long
#define fi first
#define se second
using namespace std;
const long long INF=1e18;
const long long MD=1e9+7;
int n,a[1003],sum,k;
int ournum;
bool hasbit(int bit, int num){
    if (((1ll<<bit) & num) ==0) return 0;
    return 1;
}
bool cmp(int a, int b){
    for (int i=40; i>=0; i--){
        if (!hasbit(i,ournum))continue;
        if (hasbit(i,a) && !hasbit(i,b))
            return a<b;
        if (!hasbit(i,a) && hasbit(i,b))
            return b<a;
    }
    return a<b;
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    for (int i=1; i<=n; i++){
        cin>>a[i];
    }
    vector<int> v;
    for (int i=1; i<=n; i++){
        sum=0;
        for (int j=i; j<=n; j++){
            sum+=a[j];
            v.push_back(sum);
        }
    }
    /*for (int i=0; i<v.size(); i++){
        cout<<v[i]<<" ";
    }
    cout<<endl;
     */
    int ans=0;
    for (int i=40; i>=0; i--) {
        vector<int> ne;
        for (int j = 0; j < v.size(); j++) {
            if (hasbit(i,v[j]))ne.push_back(v[j]);
        }
        if (ne.size()<k) {
            continue;
        }
        if (ne.size()==k){
            int num=ne[0];
            for (auto j:ne){
                num&=j;
            }
            cout<<num<<endl;
            return 0;
        }
        v=ne;
    }
    int num=v[0];
    for (int i=0; i<k; i++){
        num&=v[i];
    }
    cout<<num<<endl;

}

Measured memory_bytes: 6128
# 2019-11-17 10:52:21(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    a, s = sys.stdin.read().split()
    a = int(a)
    print(s if a >= 3200 else 'red')


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll N;
	std::cin >> N;

	map<ll, ll> dic;
	dic[0] = 1;
	rep(i, 0, N) {
		ll a;
		std::cin >> a;
		dic[a]++;
	}

	if (dic[0] > 1 || dic[12] > 1) {
		std::cout << 0 << endl;
		return 0;
	}
	rep(i, 1, 12) {
		if (dic[i] > 2) {
			std::cout << 0 << endl;
			return 0;
		}
	}

	ll ans = 0;
	rep(i, 0, (1LL << 12)) {
		ll tmp = 9999;
		repeq(j, 0, 12) {
			if (dic[j]>0) {
				if (dic[j] > 1) {
					tmp = min(tmp, min(j + j, 24 - j - j));
				}
				vll a = { j,24 - j };
				repeq(k, j + 1, 12) {
					if (dic[k]>0) {
						vll b = { k,24 - k };
						if (dic[k] > 1) {
							tmp = min(tmp, min(k + k, 24 - k - k));
							if (dic[j] > 1) {
								rep(jj, 0, 2) {
									rep(kk, 0, 2) {
										tmp = min(tmp, min(abs(a[jj] - b[kk]), 24 - abs(a[jj] - b[kk])));
									}
								}
							}
							else{
								rep(kk, 0, 2) {
									tmp = min(tmp, min(abs(a[(bool)(i & (1LL << j))] - b[kk]), 24 - abs(a[(bool)(i & (1LL << j))] - b[kk])));
								}
							}
						}
						if (dic[j] > 1) {
							rep(jj, 0, 2) {
								tmp = min(tmp, min(abs(a[jj] - b[(bool)(i & (1LL << k))]), 24 - abs(a[jj] - b[(bool)(i & (1LL << k))])));
							}
						}
						else {
							tmp = min(tmp, min(abs(a[(bool)(i & (1LL << j))] - b[(bool)(i & (1LL << k))]), 24 - abs(a[(bool)(i & (1LL << j))] - b[(bool)(i & (1LL << k))])));
						}
					}
				}
			}
		}
		ans = max(ans, tmp);
	}


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


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
    Main(){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(a*b + " " + 2*(a+b));
    }

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



Measured memory_bytes: 26012
while True:
    n = int(input())
    if n == 0:
        break
    tensu = []
    for i in range(1,n+1):
        s = int(input())
        tensu.append(s)
    m = min(tensu)
    M = max(tensu)
    tensu.remove(m)
    tensu.remove(M)
    t = len(tensu)
    sum = 0
    for j in range(0,t):
        sum += tensu[j]
    r = sum // t
    print(r)
            



Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int N,L;
    cin >> N >> L;
    string S[N];
    REP(i,N){
        cin >> S[i];
    }
    sort(S,S+N);
    REP(i,N) cout << S[i];
    cout << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
a = [tuple(map(int, input().split())) for _ in range(N)]

table = [0] * (1 << N)
for k in range(1 << N):
  for i in range(N):
    for j in range(N):
      if (1 << i) & k and ((1 << j) & k):
        table[k] += a[i][j]
  table[k] //= 2

dp = [0] * (1 << N)
for i in range(1 << N):
  j = i
  dp[i] = table[i]
  while j > 0:
    dp[i] = max(dp[i], dp[j] + table[i - j])
    j = (j - 1) & i
print(dp[-1])

Measured memory_bytes: 44892
import math
A, B, H, M = map(int, input().split())
rad_h = 2*math.pi * (H/12 + M/60/12)
rad_m = 2*math.pi * M/60
rad = abs(rad_h - rad_m)

l = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(rad))
print(l)

Measured memory_bytes: 9444
#include<stdio.h>

int main(void){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a>0){
		printf("Positive\n");
	}else if(a<=0 && b>=0){
		printf("Zero\n");
	}else{
		if((a-b)%2==0){
			printf("Negative\n");
		}else{
			printf("Positive\n");
		}
	}
	return 0;
}

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

using namespace std;

int d,t,s; 

int main()
{
	scanf("%d%d%d",&d,&t,&s);
	if(d<=t*s)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    REP(i, n - 2) {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double x[500];
double y[500];
int v[500];
double eps=1e-9;
double PI=acos(-1.0);
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%lf%lf",x+i,y+i);
		double X=0;
		double Y=0;
		for(int i=0;i<a;i++)v[i]=0;
		double ret=0;
		double now=PI/2;
		for(int i=0;i<a;i++){
			double r=999999;
			double th=-999999;
			int at=0;
			for(int j=0;j<a;j++){
				if(v[j])continue;
				double tmp=atan2(y[j]-Y,x[j]-X);
				while(tmp>now+eps){
					tmp-=PI*2;
				}
				if(th+eps<tmp||(th<tmp+eps&&r>sqrt((x[j]-X)*(x[j]-X)+(y[j]-Y)*(y[j]-Y)))){
					th=tmp;
					at=j;
					r=sqrt((x[at]-X)*(x[at]-X)+(y[at]-Y)*(y[at]-Y));
				}
			}
			now=th;
			v[at]=1;
			ret+=r;
			X=x[at];Y=y[at];
		//	printf("%f %f\n",X,Y);
		}
		printf("%.1f\n",ret);
	}
}

Measured memory_bytes: 1180
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <string>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 998244353;

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

int main()
{
  int N,T;
  int min = 1001,tm,cost;
  cin >> N >> T;
  for(int i=0;i<N;i++){
    cin >> cost >> tm;
    if(min > cost && tm <= T) min = cost;
  }
  if(min == 1001) cout << "TLE";
  else cout << min;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v),v.end()));
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = 1 << (s.size()-1);
	ll ans = 0;
	REP(i, n) {
		ll sum = 0, tmp = s[0]-'0';
		REP(j, s.size()) {
			if (i&(1 << j)||j==s.size()-1) {
				sum += tmp;
				if(j!=s.size()-1)tmp = s[j+1]-'0';
			}
			else {
				tmp = tmp * 10 + (s[j + 1]-'0');
			}
		}
		ans += sum;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n;
  scanf("%d", &n);
  int i,j,p[n],c=0,max,min;
  for(i=0;i<n;i++){
    scanf("%d", &p[i]);
  }
  for(i=1;i<n-1;i++){
    max=p[i];
    min=p[i];
    for(j=i-1;j<=i+1;j++){
      if(p[j]>max) max=p[j];
      if(p[j]<min) min=p[j];
    }
    if(max!=p[i] && min!=p[i]) c++;
  }
  printf("%d", c);
  return 0;
}

Measured memory_bytes: 128
use proconio::input;

fn main() {
    input!{
      n: usize,
      k: usize,
    }
    let mut l = Vec::<u32>::new();
    for _i in 0..n {
        input! {
          p: u32,
        }
        l.push(p)
    }
    l.sort();
    let sum:u32 = l.iter().enumerate()
        .filter(|i| i.0 < k)
        .map(|i| i.1)
        .sum();

    println!("{}", sum)
}


Measured memory_bytes: 2192
n = int(input())
h = list(map(int, input().split()))
 
count = 0
newCount = 0
 
for i in range(n - 1):
    if h[i] >= h[i + 1]:
        count += 1
        newCount = max(count, newCount)
    else:
        count = 0
 
print(newCount)

Measured memory_bytes: 14252
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] str=br.readLine().split(" ");
        int N=Integer.parseInt(str[0]);
        int M=Integer.parseInt(str[1]);
        int[] arr=new int[N];
        double sum=0;
        StringTokenizer st=new StringTokenizer(br.readLine()," ");
        for(int i=0;i<N;i++) sum+=(arr[i]=Integer.parseInt(st.nextToken()));
        Arrays.sort(arr);
        boolean flag=true;
        for(int i=1;i<=M;i++){
            if(4*M*arr[N-i]<sum){
                flag=false;
                break;
            }
        }
        if(flag) System.out.println("Yes");
        else  System.out.println("No");
    }
}

Measured memory_bytes: 21332
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n,a[50];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
    n=read();
    rep(i,1,n) a[i]=read();
    int cnt=0;
    rep(i,2,n-1)
    {
        if (((a[i]<=a[i+1]) && (a[i]>=a[i-1])) || ((a[i]>=a[i+1]) && (a[i]<=a[i-1])))
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    
    if (N % 2 == 0) {
      System.out.printf("%.6f\n", 0.5);
    } else {
      System.out.printf("%.6f\n", (N + 1) / (2.0 * N));
    }
  }
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int mx = max(A, max(B, C));
  int pos = mx * 3 - (A + B + C);
  if(pos & 1) pos += 3;
  printf("%d\n", pos / 2);
  return 0;
}

Measured memory_bytes: 256
a, b, c, d, e, f = map(int, input().split(" "))

max = 0
water = 0
sugar = 0
flag = True

i = 1
while(f >= 100 * a * i):
    j = 0
    while(f >= 100 * (a * i + b * j)):
        k = 0
        while(f >= 100 * (a * i + b * j) + c * k):
            l = 0
            while(f >= 100 * (a * i + b * j) + c * k + d * l):
                n = 100 * (c * k + d * l) / (100 * (a * i + b * j) + c * k + d * l)
                if(n > 100 * e / (100 + e)):
                    break
                if(max < n):
                    max = n
                    water = 100 * (a * i + b * j)
                    sugar = c * k + d * l
                l += 1
            k += 1
        j += 1
    i += 1

i = 0
j = 1
while(f >= 100 * (a * i + b * j)):
    k = 0
    while(f >= 100 * (a * i + b * j) + c * k):
        l = 0
        while(f >= 100 * (a * i + b * j) + c * k + d * l):
            n = 100 * (c * k + d * l) / (100 * (a * i + b * j) + c * k + d * l)
            if(n > 100 * e / (100 + e)):
                break
            if(max < n):
                max = n
                water = 100 * (a * i + b * j)
                sugar = c * k + d * l
            l += 1
        k += 1
    j += 1

if(water == 0):
    water = 100 * a
print("%d %d" %(water + sugar, sugar))

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

int main(){
    int N,K,X,Y;
    cin>>N>>K>>X>>Y;
    int A;
    A = K*X;
    int B;
    B = (N-K)*Y;
    if(N<=K){
        A=N*X;
        B=0;
    }
    cout<<A+B<<endl;
}


Measured memory_bytes: 3592
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const ll MOD = 998244353;
const int MAX_N = 200000;
int n;
pii xd[MAX_N];
vi g[MAX_N];
bool vis[MAX_N];

ll rec(int u) {
    vis[u] = true;

    ll res = 1;
    for (int v : g[u]) {
        res = res * rec(v) % MOD;
    }

    return (res + 1) % MOD;
}

int main() {
    fastio();

    cin >> n;
    forn(i, n) {
        cin >> xd[i].fst >> xd[i].snd;
    }

    sort(xd, xd + n);
    multiset<pii> s;

    for (int i = n - 1; i >= 0; i--) {
        int x, d;
        tie(x, d) = xd[i];
        while (!s.empty() && s.begin()->fst <= x + d - 1) {
            g[i].push_back(s.begin()->snd);
            s.erase(s.begin());
        }
        s.emplace(x, i);
    }

    ll ans = 1;
    forn(i, n) {
        if (!vis[i]) {
            ans = ans * rec(i) % MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 22272
#include <bits/stdc++.h>
using namespace std;
int h[100100];
bool bar[100100];
int main()
{
	int n,m,l,k;
	scanf("%d%d",&n,&m);
	
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&h[i]);
		bar[i]=true;
	}
	int a,b;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		if(h[a]==h[b])
		{
			bar[a]=bar[b]=false;
			continue;
		}
		else if(h[a]>h[b])
		{
			bar[b]=false;
		}
		else bar[a]=false;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(bar[i])	ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4244
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()

using namespace std;

void execute()
{
	int N;
	lint H;
	lint ans;
	lint swing_max = -INF64;
	cin >> N >> H;
	vector<lint> damage(N * 2);
	for (int i = 0; i < N * 2; i++)
	{
		cin >> damage[i];
		if (i % 2 == 0)
			swing_max = max(damage[i], swing_max);
	}
	sort(all(damage), greater<int>());
	for (ans = 0; 0 < H; ans++)
	{
		if (damage[ans] <= swing_max)
		{
			ans += (H + swing_max - 1) / swing_max;
			cout << ans << endl;
			return;
		}
		H -= damage[ans];
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 1792
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, floor
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

l = []
S = list(input())

for s in S:
    if s != "B":
        l.append(s)
    if s == "B" and len(l) != 0:
        l.pop()
    if s == "B" and len(l) == 0:
        continue
print("".join(l))

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

int main() {
	int n, d, x, a[100], sum;
	cin >> n >> d >> x;
	sum = x;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j*a[i]+1 <= d; j++)
			sum++;
	}
	cout << sum << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 5005
using namespace std;
vector<int> G[N];
int n,f[N],a[N],b[N][2];
void GG(){ printf("IMPOSSIBLE"); exit(0);}
void dfs(int t)
{
	int i,j,x,S=0,C=0;
	if(!G[t].size()){ b[t][1]=a[t]; return ;}
	for(i=0;i<G[t].size();i++)
		dfs(G[t][i]),S+=b[G[t][i]][0],C+=b[G[t][i]][1];
	if(S>a[t]) GG();
	for(j=0;j<=a[t]-S;j++) f[j]=0;
	f[0]=1;
	for(i=0;i<G[t].size();i++){
		x=b[G[t][i]][1]-b[G[t][i]][0];
		for(j=a[t]-S;j>=x;j--) f[j]|=f[j-x];
	  }
	for(j=a[t]-S;j>=0;j--) if(f[j]) break;
	b[t][0]=a[t],b[t][1]=C-j;
	if(b[t][0]>b[t][1]) swap(b[t][0],b[t][1]);
}
int main()
{
	int i;
	scanf("%d",&n);
	for(i=2;i<=n;i++)
		scanf("%d",&f[i]),G[f[i]].push_back(i);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	dfs(1);
	printf("POSSIBLE");
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    long long int min = 10000000;
    long long int max = -10000000;
    long long int x, sum = 0;
    for (int i = 0; i < n; i++){
        cin >> x;
        if (min > x){
            min = x;
        }
        if (max < x){
            max = x;
        }
        sum = sum + x;
    }
    cout << min << ' ';
    cout << max << ' ';
    cout << sum << endl;
}
//ITP1_4_D*


Measured memory_bytes: 3100
using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var n2 = (n - 1) / 2;
            var w1 = new List<int>();
            for (int i = 1; i < n; i++) w1.Add(i * i  % n);
            var w2 = w1.Distinct().ToArray();
            var ret = new int[n2];
            for (int i = 0; i < w2.Length; i++)
                for (int j = 0; j < w2.Length; j++)
                    if (i != j)
                    {
                        var z = w2[i] - w2[j];
                        if (z < 0) z += n;
                        if (z > n2) z = n - z;
                        ret[z-1]++; 
                    }
            foreach (var x in ret)
                Console.WriteLine(x);
        }
    }
}

Measured memory_bytes: 10512
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=3e5+7,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//ÄæÔª
//int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}

ll dp[N],wi[N],vi[N];
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int n;
    ll w;
    scanf("%d%lld",&n,&w);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&wi[i],&vi[i]);
    }
    memset(dp,0x3f,sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=n;i++){
        for(int j=100000;j>=vi[i];j--){
            dp[j]=min(dp[j],dp[j-vi[i]]+wi[i]);
        }
    }
    for(int i=100000;i>=0;i--){
        if(dp[i]<=w){
            printf("%d\n",i);
            break;
        }
    }

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}




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

int main(){
  int N;
  cin >> N;
  int max=0;
  int count=0;
  vector<int> A(N),B(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    B.at(i)=A.at(i);
    if(A.at(i)>max){
      max=A.at(i);
    }
  }
  sort(B.begin(),B.end());
  for(int i=0;i<N;i++){
    if(A.at(i)==max){
      count++;
    }
  }
  if(count>=2){
    for(int i=0;i<N;i++){
      cout << max << endl;
    }
    return 0;
  }
  if(count==1){
    for(int i=0;i<N;i++){
      if(max!=A.at(i)){
        cout << max << endl;
      }else{
        cout << B.at(N-2) << endl;
      }
    }
  }
}

Measured memory_bytes: 3200
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  if(b-a==c-b){
    cout<<"YES"<<'\n';
  }
  else{
    cout<<"NO"<<'\n';
  }
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
using namespace std;
int main(void){
	long long int A,B,C,K;
	
	cin >> A >> B >> C >> K;
	
	long long int point = 0;
	

	if(K < A){
		    point += 1 * K;
		    
	}else{
		    point += 1 * A;
		K -= A;
		if(K < B){
			
		}else{
		    K -= B;
		    point += -1 * K;
		}
	}
	cout << point << endl;

}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rp(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep(i, x, n) for (int i = (x); i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)

#define TRACE(x...) x
#define PRINT(x...)
#define WATCH(x) TRACE(cout << #x << " = " << x << endl )

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll dp[100010][101];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll N, W;
    cin >> N >> W;
    vll v(N), w(N);
    rp(i,N) cin >> w[i] >> v[i];
    rp(i,N+1) dp[0][i] = 0;
    rep(i,1,W+1) {
    	rep(j,1,N+1) {
    		if(i >= w[j-1]) {
    			dp[i][j] = max(dp[i][j-1], dp[i-w[j-1]][j-1] + v[j-1]);
    		} else {
    			dp[i][j] = dp[i][j-1];
    		}
    	}
    }
    
    cout << dp[W][N] << '\n';
    
    return 0;
}

Measured memory_bytes: 79232
/*#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#define ll long long
using namespace std;

int main(){
	int n,h,ans=0;
	cin>>n;
	while(n--){
		int b;
		cin>>b;
		if(b==1){
			cout<<"hard";
			return 0;
		}
	}
	cout<<"easy";
	return 0;
}*/


#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int c1 =0 ;
  for(int i = a;i<=b;i++){
    if(i%c==0) c1++;
  }
  cout<<c1;
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ar array

int test_case()
{
   int price;
   cin >> price;
   
   if (price % 1000 == 0) {
      return 0;
   } else if (price < 1000) {
      return 1000 - price;
   }      
   
   while (price > 1000) {
      price -= 1000;
      if (price < 1000) {
         return 1000 - price;
      }
   }
           
}
   
int main()
{
   cout << test_case();
   
   return 0;
}

Measured memory_bytes: 3584
from collections import defaultdict
def main():
    n, k = map(int, input().split(" "))
    a = list(map(lambda i: int(i)-1, input().split(" ")))
    s = [0]
    d = defaultdict(lambda:0)
    x = a[0]
    for i in range(n):
        s.append(x)
        x = a[x]

    bb=None
    for i in range(n):
        d[s[i]] += 1
        if d[s[i]] ==2:
            bb=s[i]
            break

    cc = s.index(bb)
    s[cc]=-1
    dd = s.index(bb)
    loop_len = dd-cc
    s[cc]=s[dd]
        
    if bb ==None or k < cc:
        print(s[k]+1)
    else:
        y = (k-cc) % loop_len
        print(s[y+cc]+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 37304
program prob58
    implicit none
    integer :: r
    read(*,*) r
    if(r < 1200) then
        write(*,*) "ABC"
    else if(r < 2800) then
        write(*,*) "ARC"
    else
        write(*,*) "AGC"
    end if
    stop
contains
end program prob58

Measured memory_bytes: 2772
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

ll od[MAX];

ll COM(ll a, ll b) {
	if (od[a] - od[a - b] - od[b] == 0) { return 1; }
	else { return 0; }
}

ll ch(ll M, vector<ll>a) {
	ll c = 0;
	repn(i, M) {
		c += a[i] * COM(M - 1, i - 1);
		c %= 2;
	}

	return c;
}


int main() {
	od[0] = 0;

	repn(i, MAX-1) {
		od[i] = od[i - 1];
		for (ll c = i; c % 2 == 0; c /= 2) { od[i]++; }
	}


	ll N;
	cin >> N;

	string S;
	cin >> S;

	vector<ll> a(N + 1);

	repn(i, N) {
		a[i] = S[i - 1] - '0';
	}

	vector<ll> b(N);

	repn(i, N - 1) b[i] = abs(a[i + 1] - a[i]);

	ll M = N - 1;

	ll ans = 0;

	ll t = 1;
	repn(i, M) { if (b[i] == 1) { t = 0; } }

	if (t == 1) {
		vector<ll> c(M + 1);
		repn(i, M) c[i] = b[i] / 2;
		if (ch(M, c) == 1) { ans = 2; }
	}

	if (ans != 2) {
		vector<ll> c(M + 1);
		repn(i, M) c[i] = b[i] % 2;
		if (ch(M, c) == 1) { ans = 1; }
	}

	cout << ans;






















	system("PAUSE");

}





Measured memory_bytes: 40452