akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int             long long
#define no_of_test(x)   int x; cin>>x; while(x--)
const int mod = 1e9 + 7;
void very_fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}
vector<int>v1, v2;
int get(vector<int>v)
{	int cnt = 0;
	vector<int>k = v;
	sort(k.begin(), k.end());
	while (true)
	{	cnt++;
		if (k == v)
			return cnt;
		next_permutation(k.begin(), k.end());

	}
}

int32_t main()
{
	very_fast();
//	no_of_test(x)
	{
		int n;
		cin >> n;

		for (int i = 0; i < n; i++)
		{
			int x;
			cin >> x;
			v1.push_back(x);
		}
		for (int j = 0; j < n; j++)
		{
			int y;
			cin >> y;
			v2.push_back(y);
		}
		int a1 = get(v1);
		int a2 = get(v2);
		cout << abs(a1 - a2) << "\n";

	}
	return 0;

}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    char s[3][4];
    for(int i=0; i<3; i++){
        cin >> s[i];
    }
    cout << s[0][0] << s[1][1] << s[2][2];
    
    return 0;
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    matrix = [
        list(map(int, input().split()))
        for _ in range(n)
    ]
    vector = [
        int(input())
        for _ in range(m)
    ]

    for v in matrix:
        res = sum(x * y for x, y in zip(v, vector))
        print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 6004
n = int(input())
a = []
b = []
for j in range(n):
    l = list(map(int, input().split()))
    a.append(l[0])
    b.append(l[1])
c = 0
for i in range(n-1, -1, -1):
    if (a[i]+c) % b[i] != 0:
        c += (b[i] - (a[i]+c) % b[i])
print(c)

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

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

  if(a<b)
    {
      cout <<"a < b" <<endl;
    }
  else if (a>b)
    {
      cout <<"a > b" <<endl;
    }
  else
    {
      cout <<"a == b" <<endl;
    }

return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll a,b;
    cin>>a>>b;
    for(int i=0;i<max(a,b);i++)
    {
        cout<<min(a,b);
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
#define int long long

signed main(){

   int x, y;
   cin>> x>> y;

   int inf=1e16;

   if(x<y){
      if(0<x||y<0){
         cout<< y-x<< endl;
      }else{
         int a=y-x;
         if(y<-x){
            a=min(a, -x-y+1);
         }else{
            a=min(a, y-(-x)+1);
         }
         cout<< a<< endl;
      }
   }else{
      if(0>x||y>0){
         cout<< x-y+2<< endl;
      }else{
         if(-x>y){
            cout<< -y-x+1<< endl;
         }else{
            cout<< x-(-y)+1<< endl;
         }
      }
   }

   return 0;
}


Measured memory_bytes: 256
def gcd(t):
    b,a=sorted(t)
    while True:
        m=a%b
        if m==0:
            return b
        a=b;b=m
a,b,k=(int(x) for x in input().split())
g=gcd((a,b))
cd=[]
for i in range(g+1)[::-1]:
    if i==0:
        break
    if g%i==0:
        cd.append(i)
print(cd[k-1])

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String arg[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		
		List<String> lst = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			String s = sc.next();
			lst.add(s);
		}
		
		Collections.sort(lst);

		StringBuffer sb = new StringBuffer();
		for(int i = 0; i < n; i++) {
			sb.append(lst.get(i));
		}
		
		System.out.println(sb);
	}
}

Measured memory_bytes: 21972
unittest
{
	assert( [ "575" ].parse.expand.solve == "Yes" );
	assert( [ "123" ].parse.expand.solve == "No" );
	assert( [ "812" ].parse.expand.solve == "No" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip;
	return tuple( n );
}

auto solve( string n )
{
	return ( n[ 0 ] == n[ 2 ] ) ? "Yes" : "No";
}


Measured memory_bytes: 256
#pragma warning disable
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
using System.Collections;
using static System.Math;
using static System.Console;
class E { static void Main() => new J(); }
class J
{
	const int Mod = 1000000007;
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	public J()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	HashSet<int>[] es;
	void Solve()
	{
		var N = F();
		es = new HashSet<int>[N];
		for (var i = 0; i < N; i++)  es[i] = new HashSet<int>();
		for (var i = 0; i < N - 1; i++) Add(G());
		par = new int[N];
		size = new int[N];
		dep = new int[N];
		DFS(0, -1, 0);
		var w = N - 1;
		var d = dep[w] / 2 + 1;
		while (dep[w] != d) w = par[w];
		WriteLine(N - size[w] > size[w] ? "Fennec" : "Snuke");
	}
	int[] par, size, dep;
	int DFS(int u, int p, int d)
	{
		par[u] = p;
		dep[u] = d;
		es[u].Remove(p);
		foreach (var v in es[u]) size[u] += DFS(v, u, d + 1);
		return ++size[u];
	}
	void Add(int[] a) => Add(a[0] - 1, a[1] - 1);
	void Add(int a, int b)
	{
		es[a].Add(b);
		es[b].Add(a);
	}
	long GCD(long a, long b)
	{
		var n = (ulong)Abs(a); var m = (ulong)Abs(b);
		if (n == 0) return (long)m; if (m == 0) return (long)n;
		int zm = 0, zn = 0;
		while ((n & 1) == 0) { n >>= 1; zn++; }
		while ((m & 1) == 0) { m >>= 1; zm++; }
		while (m != n)
		{
			if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; }
			else { n -= m; while ((n & 1) == 0) n >>= 1; }
		}
		return (long)n << Min(zm, zn);
	}
}

Measured memory_bytes: 49848
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int64 n;
    cin >> n;
    vector<int64> t(n);
    vector<int64> a(n);
    for (int64 i=0; i<n; i++) cin >> t[i] >> a[i];

    int64 tin = 1;
    int64 ain = 1;
    for (int64 i=0; i<n; i++) {
        int64 x = max( (tin+t[i]-1)/t[i], (ain+a[i]-1)/a[i]);
        tin = x*t[i];
        ain = x*a[i];
    }

    cout << tin + ain << endl;
}

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

int main() {
  int s1s2s3,a,b,c;
  cin>>s1s2s3;
  a=(s1s2s3-b*10-c)/100;
  b=(s1s2s3-a*100-c)/10;
  c=s1s2s3-a*100-b*10;
  cout<<a+b+c<<endl;
}

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

using namespace std;

int d[111111], p[111111], l[111111], r[111111];

int main()
{
	for (int i = 2; i < 100003; i++) {
		if (p[i]) continue;
		for (int j = i + i; j < 100003; j += i)
			p[j] = 1;
	}
	int n = 0;
	for (int i = 3; i < 100003; i += 2) {
		if (!p[i] && !p[(i + 1) / 2])
			n++;
		d[i] = n;
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
		scanf("%d%d", l + i, r + i);
	for (int i = 0; i < q; i++) {
		cout << d[r[i]] - (l[i] < 3 ? 0 : d[l[i] - 2]) << '\n';
	}
	cout << flush;
	return 0;
}


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

using namespace std;
using ll = long long ;


int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    cout << (4 * a * b < (c - a - b) * (c - a - b) && c - a - b > 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#ifdef DEBUG
std::ostream& dout = cout;
#else
stringstream dout;
#endif
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    int ans=0;
    bool b=false;
    rep(i,s.size()){
        char c=s[i];
        if(c-'0'==9&&b)continue;
        if(b){
            c++;
            b=false;
        }
        ans+=min(c-'0',10-c+'0');
        if(c-'0'>10-c+'0'||(c=='5'&&s[i+1]-'0'>=5)){
            b=true;
        }
    }
    if(b)ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 1948
#include <cstdio>
#include <cctype>

inline void read(int&x){
	char c11=getchar();x=0;while(!isdigit(c11))c11=getchar();
	while(isdigit(c11))x=x*10+c11-'0',c11=getchar();
}

inline void cmax(int&A,int B){A=A>B?A:B;}

const int N=2050;
struct Edge{int v,nxt;}a[N+N];
int head[N],n,k,ans,_;

int dfs(int x,int las,int dep){
	if(dep==-1)return 0;
	int res(1);
	for(int i=head[x];i;i=a[i].nxt)
		if(a[i].v!=las)
			res+=dfs(a[i].v,x,dep-1);
	return res;
}

int main(){
	read(n),read(k);int x,y;
	for(int i=1;i<n;++i){
		read(x),read(y);
		a[++_].v=y,a[_].nxt=head[x],head[x]=_;
		a[++_].v=x,a[_].nxt=head[y],head[y]=_;
	}
	if(!(k&1))
		for(int i=1;i<=n;++i)
			cmax(ans,dfs(i,i,k>>1));
	else
		for(int x=1;x<=n;++x)
		for(int i=head[x];i;i=a[i].nxt)
			if(a[i].v>x)cmax(ans,dfs(x,a[i].v,k>>1)+dfs(a[i].v,x,k>>1));
	printf("%d\n",n-ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(c<=max(a,b)&&c>=min(a,b)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

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

    map<string, int> m;

    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        auto itr = m.find(s);
        if(itr == m.end()){
            m.insert(make_pair(s, 1));
        }
    }

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

Measured memory_bytes: 19180
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    const U_INF: usize = 1 << 60;
    const I_INF: isize = 1 << 60;
    let n: usize = read!();
    let mut ac = 0;
    let mut tle = 0;
    let mut wa = 0;
    let mut re = 0;
    for _ in 0..n {
        let status: String = read!();
        let status: &str = &status;
        match status {
            "AC" => ac += 1,
            "WA" => wa += 1,
            "TLE" => tle += 1,
            "RE" => re += 1,
            _ => panic!("what the fuck?"),
        }
    }
    
    println!("AC x {}", ac);
    println!("WA x {}", wa);
    println!("TLE x {}", tle);
    println!("RE x {}", re);
}


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

int main(void) {
  long long length, step = 0, sum = 0;
  cin >> length;
  int ppl[length];
  for(int i=0; i<length; i++)cin >> ppl[i];
  for(int i = 1; i<length; i++){
    if(ppl[i-1]+step > ppl[i])step = ppl[i-1]+step-ppl[i];
    else step = 0;
    sum += step;
  }
  cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

int N;
string s[300];

bool check(int k){
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(s[i][j]!=s[(j+N+k)%N][(i+N-k)%N]) return false;
        }
    }
    return true;
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> s[i];
    }
    LL ans=0;
    for(int i=0;i<N;i++){
        if(check(i)) ans+=N;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {

	int a, b, c, d;
	vector<int> tmp;
	bool flag = true;

	cin >> a >> b >> c >> d;

	if (a + d >= c && a - d <= c) {
		flag = true;
	}
	else {

		if ((b + 5 >= a && b - 5 <= a) && (b + 5 >= c && b - 5 <= c))
			flag = true;
		else
			flag = false;

	}



	if (flag == false)
		cout << "No" << endl;
	else if (flag == true)
		cout << "Yes" << endl;



	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

const long long MOD = 1000000000LL + 7;
using VLL = vector <long long>;
using VVLL = vector <VLL>;

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

    long long ans = 0;
    int num = S/3;

    int upper = 2*S;
    VVLL C(upper+1, VLL(upper+1));

    for (int i = 0; i < upper; ++i) {
        C[i][i] = C[i][0] = 1;

        for (int j = 1; j < i; ++j) {
            C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD;
        }
    }

    for (int n = 1; n <= num; ++n) {
        int remain = S - 3*n;
        // H remain n
        // = C(n+remain-1) n-1
        ans += C[n+remain-1][n-1];
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 128184
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 
bool find(string s){
	// int n=s.size();
	// for(int i=0;i<n/2;i++)
	string r=s;
	reverse(all(r));
	return r==s;
}

int solve(){

	string s;cin>>s;
	string s1="",s2="";
	for(int i=0;i<s.size()/2;i++) s1+=s[i],s2+=s[s.size()-i-1];
	if(find(s) && find(s1) && find(s2)) cout<<"Yes";
else cout<<"No";



    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i=0; i<n; i++) {
    cin >> a[i];
  }
  for (int i=0; i<n-k; i++) {
    if (a[i]<a[i+k]) printf("Yes\n");
    else printf("No\n");
  }
}

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

int main(){
int a,b,C;
double S,L,h,pi,d,rad;
pi=acos(-1.0);
cin >>a >>b >>C;
rad=C*pi/180.0;
d=sqrt(a*a+b*b-2*a*b*cos(rad));
S=a*b*sin(rad)/2.0;
L=a+b+d;
h=b*sin(rad);
printf("%lf\n%lf\n%lf\n",S,L,h);
return 0;
}

Measured memory_bytes: 3464
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<tuple>
using namespace std;


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

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

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


int main(){
	string s;
	cin >> s;

	int l = 0, r = s.length() - 1;
	int ans = 0;
	while(true){
		if(l >= r)	break;
		if(s[l] != s[r])	ans++;
		l++;
		r--;
	}

	cout << ans << endl;

}

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

using namespace std;

const int MAX = 1e6+1;
int score[MAX];
int N,Q;
vector<int> leader;
vector<int> sc;

void input(){
  cin >> N >> Q;
  sc.resize(N);
  for(int i = 1; i <= N; i++) {
    cin >> score[i];
    sc[i-1] = score[i];
  }
  sort(sc.begin(),sc.end());
}

void add(int n){
  leader.push_back(n);
}

void remove(int n){
  vector<int>::iterator ite = leader.begin();
  while(ite < leader.end()){
    if(*ite == n) ite = leader.erase(ite);
    else ite++;
  }
}

bool isOK(int r, int n){
  int out = 0;
  int pos = 0; // top position that is not cavered yet

  vector<int> v(leader.size());
  for(int i = 0; i < (int)leader.size(); i++) v[i] = score[leader[i]];
  sort(v.begin(),v.end());
  
  for(int i = 0; i < (int)v.size(); i++){
    int llim = lower_bound(sc.begin(),sc.end(),v[i]-r) - sc.begin();
    int rlim = upper_bound(sc.begin(),sc.end(),v[i]) - sc.begin();
    
    // can cover [llim, rlim)
    if(llim > pos) out += llim-pos;
    pos = rlim;
  }

  out += sc.size()-pos;
  return out <= n;
}

void check(int n){
  const int LIM = 1e9+1;
  int l = 0, r = LIM;

  while(l < r){
    int c = (l+r)/2;
    if(isOK(c,n)) r = c;
    else l = c+1;
  }

  if(r == LIM) cout << "NA" << endl;
  else cout << l << endl;
}

void solve(){

  for(int i = 0; i < Q; i++){
    string q;
    int n;
    cin >> q >> n;
    if(q == "ADD") add(n);
    if(q == "REMOVE") remove(n);
    if(q == "CHECK") check(n);
  }
}

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

Measured memory_bytes: 8860
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=105;
int a[maxn];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
        if(a[i]*4*m>=sum)
            cnt++;
    if(cnt>=m) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  while (cin >> N) {
    vector<vector<int>> G(N);
    for (int i = 1; i < N; i++) {
      int p;
      cin >> p;
      --p;
      G[p].push_back(i);
    }
    vector<int> X(N);
    for (int i = 0; i < N; i++) {
      cin >> X[i];
    }
    function<int(int)> solve = [&](int v) {
      int sum = 0;
      bitset<5010> dp;
      dp.set(0);
      for (int u : G[v]) {
        int x0 = X[u];
        int x1 = solve(u);
        if (x1 < 0) {
          return -1;
        }
        sum += x0 + x1;
        dp = (dp << x0) | (dp << x1);
      }
      for (int x = X[v]; x >= 0; x--) {
        if (dp[x]) {
          return sum - x;
        }
      }
      return -1;
    };
    cout << (solve(0) < 0 ? "IMPOSSIBLE" : "POSSIBLE") << endl;
  }
  return 0;
}


Measured memory_bytes: 1664
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        int[] np = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] a = Console.ReadLine().Split().Select(x => int.Parse(x) % 2).ToArray();
        int evenCount = a.Count(x => x == 0);
        int oddCount = a.Count(x => x == 1);
        long comb = 1;
        long oddComb = 0;
        if (np[1] == 0) oddComb++;
        for (int i = 1; i <= oddCount; i++)
        {
            comb = (comb * (oddCount + 1 - i)) / i;
            if (i % 2 == np[1]) oddComb += comb;
        }
        Console.WriteLine(power(2, evenCount) * oddComb);
    }

    static long power(int n, int m)
    {
        long pow = n;
        long res = 1;
        while (m > 0)
        {
            if ((m & 1) == 1) res = res * pow;
            pow = pow * pow;
            m >>= 1;
        }
        return res;
    }
}

Measured memory_bytes: 13396
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. solve<0 then solve+=mod;
//Dont keep array name as size or any other key word
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007


#define sz 100005


ll inf = 1e18;
ll power(ll x, ll n, ll mod)
{
  ll res = 1;
  x %= mod;
  while (n)
  {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res%mod;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll n;
  cin>>n;
  if(n==1)
    cout<<"0\n";
  else
  {
    ll solve=power(10,n,MOD)%MOD;

    ll p8=power(8,n,MOD)%MOD;

    ll p9=(2%MOD*power(9,n,MOD)%MOD)%MOD;

    solve=solve-(p9-p8);

    if(solve<0)
      solve=solve+MOD;
    cout<<solve%MOD<<'\n';
  }
  return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int n;
	cin >> n;
	set <int>a;
	rep(i, n) {
		int tmp;
		cin >> tmp;
		a.insert(tmp);
	}
	if (a.size() == n)print("YES");
	else print("NO");
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int a;
    cin >> a;
    if(a == 1) cout << "Hello World" << endl;
    else {
        int x, y;
        cin >> x >> y;
        cout << x + y << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
コッホ曲線
*/
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

type point struct {
	x float64
	y float64
}

func (p point) String() string {
	return fmt.Sprintf("%.8f %.8f", p.x, p.y)
}

func (p point) add(o point) point {
	return point{p.x + o.x, p.y + o.y}
}

func divide3(p1, p2 point) (point, point) {
	lenX := (p2.x - p1.x) / 3.0
	lenY := (p2.y - p1.y) / 3.0
	return point{p1.x + lenX, p1.y + lenY}, point{p1.x + (lenX * 2), p1.y + (lenY * 2)}
}

// 座標上の点を回転する
func rotate(p1, p2 point, angle float64) point {
	sinT, cosT := math.Sincos(angle)
	newX := ((cosT * (p2.x - p1.x)) + (-sinT * (p2.y - p1.y))) + p1.x
	newY := ((sinT * (p2.x - p1.x)) + (cosT * (p2.y - p1.y))) + p1.y
	return point{newX, newY}
}

func getSummit(p1, p2 point) point {
	return rotate(p1, p2, math.Pi/3.0)
}

func getKochSummit(p1, p2 point) (point, point, point) {
	s, u := divide3(p1, p2)
	t := getSummit(s, u)
	return s, t, u
}

func getKochCurve(p1, p2 point, count int) []point {
	result := make([]point, 0, int(math.Pow(float64(4), float64(count)))+1)
	getKochCurveRec(p1, p2, count, &result)
	// 最後の頂点を追加
	result = append(result, p2)
	return result
}
func getKochCurveRec(p1, p2 point, count int, result *[]point) {
	if count == 0 {
		// 再帰終了.
		// 先頭の頂点だけ追加
		*result = append(*result, p1)
	} else {
		s, t, u := getKochSummit(p1, p2)
		getKochCurveRec(p1, s, count-1, result)
		getKochCurveRec(s, t, count-1, result)
		getKochCurveRec(t, u, count-1, result)
		getKochCurveRec(u, p2, count-1, result)
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := eGetInt(reader)
	result := getKochCurve(point{0, 0}, point{100, 0}, n)
	for _, p := range result {
		fmt.Println(p)
	}
}
func eGetLine(r *bufio.Reader) string {
	s, err := r.ReadString(byte('\n'))
	if err != nil {
		if err != io.EOF {
			log.Fatal(err.Error())
		}
		return s
	}
	return strings.TrimRight(s, "\r\n")
}
func eGetInt(r *bufio.Reader) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInts(r *bufio.Reader) []int {
	line := eGetLine(r)
	fields := strings.Split(line, " ")
	var ints []int
	for _, f := range fields {
		ints = append(ints, eAtoi(f))
	}
	return ints
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}



Measured memory_bytes: 1464
import java.util.Scanner;

class Main{



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		if(n%k == 0){
			System.out.println(0);
		}else{
			System.out.println(1);

		}
		
		

		
	
	}


}

class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}



Measured memory_bytes: 22612
n, k = map(int, input().split())
H = list(map(int, input().split()))
INF = 10**10
C = [INF]*n
C[0] = 0
for i in range(1, n):
  min_j = max(i-k, 0)
  for j in range(i-1, min_j-1, -1):
    C[i] = min(C[i], C[j]+abs(H[i]-H[j]))
print(C[n-1])

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    for (int i = 0; i < N-1; i++) {
        if (A[i]==A[i+1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 1000000007;

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

	ll h;
	cin >> h;
	ll ans = 0;
	ll i = 1;
	while (h > 0) {
		ans += i;
		i = i << 1;
		h = h >> 1;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
int main(){
    std::vector<int> x,y;
    int num1=1,num2=1;
    while(1){
        std::cin>>num1>>num2;
         if(num1==0&&num2==0)break;
        if(num1<num2)std::cout<<num1<<" "<<num2<<"\n";
        else std::cout<<num2<<" "<<num1<<"\n";
    }
}


Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
   int n,sum=0,k;
   cin>>n;
   k=n;
   while(n>0){
   	sum+=n%10;
   	n/=10;
   }	
   k%sum==0?cout<<"Yes":cout<<"No";

   return 0;
}


Measured memory_bytes: 3636
n,m,x = list(map(int,input().split()));
price = [0]*n;
rikai = [[0]*m for i in range(n)];

for i in range(n) :
    ca = list(map(int,input().split()));
    price[i] = ca[0];
    for j in range(m) :
        rikai[i][j] = ca[j+1];

ans = sum(price);
able = 0;
for i in range(2**n) :
    allrikai = [0]*m;
    nowprice = 0;
    for j in range(n) :
        if (i>>j)&1 :
            nowprice += price[j];
            for k in range(m) :
                allrikai[k] += rikai[j][k];
    check = 1;
    for j in range(m) :
        if allrikai[j] < x :
            check = 0;
            break;
    if check and nowprice <= ans :
        able = 1;
        ans = nowprice;

if able :
    print(ans);
else :
    print(-1);

Measured memory_bytes: 9280
//arc099_d.cpp
//Sun Mar  1 10:11:46 2020
 
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;
 
ll calcsn(ll x){
	ll ans = 0;
	while(x>0){
		ans += x%10;
		x /= 10;
	}
	return ans;
}
 
int main(){
	int k;
	cin >> k;
 
	ll keta = 0;
	ll base = 1;
	ll num = 1;
	while (k){
		ll temp = num*base+base-1;
		ll sn = calcsn(temp);
		if (temp<=base*sn){
			cout << temp << endl;
			num++;
			k--;
		}else {
			keta++;
			base = pow(10,keta);
			num = 1;
			ll temp2 = num*base+base-1;
			while (temp2<=temp){
				num++;
				temp2 = num*base+base-1;
			}
		}
	}
 
}
//arc099_d.cpp
//Sun Mar  1 10:11:46 2020


Measured memory_bytes: 512
/*
g++ -std=c++11 -o2 -Wall ABC042C.cpp -o ./out/ABC042C.out
./out/ABC042C.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

constexpr ll INF = 10000000000000000;

bool d[10];

bool func(int c) {
  if (c == 0) return true;
  int a = c % 10;
  if (d[a]) return false;
  return func(c / 10);
}

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int k;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    int c;
    cin >> c;
    d[c] = true;
  }
  for (int i = n; i <= 99999; ++i) {
    if (func(i)) {
      cout << i << "\n";
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
long long ans[maxn];
int main(){
	std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    long long sum=0;
    for(int i=1;i<=n-1;i++)
    {
        sum+=a[i];
        if(i&1)
            sum-=2*a[i];
    }
    sum=a[n]-sum;
    sum/=2;
    ans[1]=sum;
    for(int i=2;i<=n;i++)
    {
        ans[i]=a[i-1]-ans[i-1];
    }
    cout << 2*ans[1];
    for(int i=2;i<=n;i++)
        cout << " " << 2*ans[i];
    return 0;
}


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

using namespace std;

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

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

int main()
{
  int X, Y, Z;
  int res=0;
  cin >> X>>Y>>Z;

  X-= Z;
  res += X/(Y + Z);

  cout << res << endl;
}


Measured memory_bytes: 256
import fractions

a,b,c,d = map(int,input().split())

def lcm(x,y):
  return (x*y) // fractions.gcd(x,y)

tmp   = b-a+1
tmp_c = (b//c-(a-1)//c)
tmp_d = (b//d-(a-1)//d)
tmp_e = (b//lcm(c,d)-(a-1)//lcm(c,d))

print(tmp - tmp_c - tmp_d + tmp_e)



Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {

	ll n; cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<bool> buyDate(n, false);
	vector<bool> sellDate(n, false);
	ll updown = 0;
	ll cash = 1000;
	ll stock = 0;
	for (ll i = 1; i <= n - 1; i++) {
		ll e = a[i] - a[i - 1];
		if (0 < e) {
			if (updown == 1) {}
			else if (updown == -1 || updown == 0) {
				stock += cash / a[i - 1];
				cash -= a[i - 1] * stock;				
			}
			updown = 1;
		}
		else if (e == 0) {}
		else if (e < 0) {
			if (updown == 1 || updown == 0) {
				cash += a[i - 1] * stock;
				stock = 0;
			}
			else if (updown == -1) {}
			updown = -1;
		}
	}
	if (0 < stock) {
		cash += a[n - 1] * stock;
		stock = 0;
	}
	cout << cash << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());
	if(s < t){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
    var input = input.split('\n').map((n) => {
        return parseInt(n);
    }) ;
    var a = input[0];
    var b = input[1];
    var c = input[2];
    var x = input[3];
    var count = 0;
      for (i = 0; i <= a; i++){
        for (j = 0; j <= b; j++){
            for (k = 0; k <= c; k++){
               var t = 500 * i + 100 * j + 50 * k;
               t === x ? count++ : null; 
               }    
            }
        }

        console.log(count);
    }
    
    
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(){
  ll N,A,B;
  cin>>N>>A>>B;
  ll ans=A*(N/(A+B));
  if(N%(A+B)>=A){
    ans+=A;
  }
  if(N%(A+B)<A){
    ans+=N%(A+B);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <type_traits>
using namespace std;

#define INF 1e18
#define int long long
#define MAX 200010

vector<int> to[MAX];
vector<int> ans;
void dfs(int v, int p = -1) {
    for(int u : to[v]) {
        if(u == p) continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

signed main() {
    int n, q; cin >> n >> q;
    for(int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    ans.resize(n);
    for(int i = 0; i < q; i++) {
        int p, x; cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(0);

    for(int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 24320
n,m,l = map(int, input().split())
data = []
data2 = []
tmp = []
for x in range(0,n):
    tmp = input().split()
    data.append([int(tmp[i]) for i in range(m)])
for x in range(0,m):
    tmp = input().split()
    data2.append([int(tmp[i]) for i in range(l)])
output = []
for x in range(n):
    output.append([sum(data[x][i] * data2[i][j] for i in range(m)) for j in range(l)])
for x in range(0,n):
    for y in range(0,l):
        if y != l-1:
            print(output[x][y],end=' ')
        else:
            print(output[x][y])


Measured memory_bytes: 9012
#include<bits/stdc++.h>
// #define int long long int
using namespace std;
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int a,b,c;
	cin >> a;
	while(a>1000){
		a-=1000;
	}
	cout << 1000-a;


	return 0;
}

Measured memory_bytes: 3672
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt(), m = scn.nextInt();
        System.out.println(n * (n - 1) / 2 + m * (m - 1) / 2);
    }
}


Measured memory_bytes: 22868
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);

    long n = scanner.nextLong();

    final StringBuilder s = new StringBuilder();
    long multiplier = 26;
    int i = 0;

    long rest = n;
    while (rest > multiplier) {
      rest -= multiplier;
      multiplier *= 26;
      i++;
    }

    String result = Long.toString(rest - 1, 26)
        .replace("p", "z")
        .replace("o", "y")
        .replace("n", "x")
        .replace("m", "w")
        .replace("l", "v")
        .replace("k", "u")
        .replace("j", "t")
        .replace("i", "s")
        .replace("h", "r")
        .replace("g", "q")
        .replace("f", "p")
        .replace("e", "o")
        .replace("d", "n")
        .replace("c", "m")
        .replace("b", "l")
        .replace("a", "k")
        .replace("9", "j")
        .replace("8", "i")
        .replace("7", "h")
        .replace("6", "g")
        .replace("5", "f")
        .replace("4", "e")
        .replace("3", "d")
        .replace("2", "c")
        .replace("1", "b")
        .replace("0", "a");

    while (result.length() < i + 1) {
      result = "a" + result;
    }

    System.out.println(result);
  }
}


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

int main(){
	long long int x,y;
	cin >> x >> y;

	long long int a = y/x;
	long long int i=1;
	while (a / 2 > 0) {
	 i++;
	 a /= 2;
	}

	cout << i << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdint.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char *argv[]) {
  using namespace std;
  int N;
  vector<int> L;
  cin >> N;
  N *= 2;
  for (int i = 0; i < N; i++) {
    int v;
    cin >> v;
    L.push_back(v);
  }
  sort(L.begin(), L.end());
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (L[i]) {
      sum += L[i];
      for (int k = i + 1; k < N; k++) {
        if (L[k]) {
          L[k] = 0;
          break;
        }
      }
    }
  }
  cout << sum << endl;

  return 0;
}


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

typedef long long int ll;
int main(){
    int H,W;
    cin >> H >> W;
    char table[60][60];
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            cin >> table[i][j];
        }
    }
    int a = 0;
    int dx[4]{0,-1,0,1};
    int dy[4]{1,0,-1,0};
    bool frag = true;
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            if(table[i][j] == '#'){
                bool judje = false;
                for(int k = 0;k < 4;k++){
                    int ny = i + dy[k],nx = j + dx[k];
                     if(0 <= ny && ny < H && 0 <= nx && nx < W){
                        if(table[ny][nx] == '#'){
                            judje = true;
                        }
                    }
                }
                if(judje){
                    a++;
                }else{
                    frag = false;
                }
            }else{
                continue;
            }
        }
    }
    if(frag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
a,b,c,d,e,f = map(int,input().split())
A = 100*a
B = 100*b

x,y = min(A,B),0
dens = y / x

for i in range(f // A + 1):
    for j in range((f - A * i) // B + 1):
        if i==0 and j==0:
            continue
        water = A*i + B*j
        rest = f - water
        for k in range(rest // c + 1):
            for l in range((rest - c*k) // d + 1):
                sugar = c*k + d*l
                total = sugar + water
                if sugar / total > e / (100+e):
                    break
                else:
                    if sugar / total > dens:
                        dens = sugar / total
                        x,y = total,sugar
print(x,y)


Measured memory_bytes: 3064
N=int(input())
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
  s=input()
  d[s]+=1
M=int(input())
for i in range(M):
  s=input()
  d[s]-=1
a=sorted(list(d.values()))
print(max(a[-1],0))

Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    long n = in.nextLong();
    long k = in.nextLong();
    if (n == k) {
      System.out.println(0);
    } else {
      long x = n % k;
      long y = Math.abs(x - k);
      System.out.println(x < y ? x : y);
    }
  }
}

Measured memory_bytes: 23124
n = int(input())
li = list(map(int,input().split()))
sumli = sum(li)
lia = [0]*10**5
for i in range(n):
    lia[li[i]-1] += 1
q = int(input())
for i in range(q):
    b,c = map(int,input().split())
    sumli += c*(lia[b-1]) - b*(lia[b-1])
    lia[c-1] += lia[b-1]
    lia[b-1] = 0 
    print(sumli)

Measured memory_bytes: 21144
A, B, C, D, E, F = map(int, input().split())
s, w = (0, 0)
water_list = [False] * (6000)
sugar_list = [False] * (6000)
water_list[0] = True
sugar_list[0] = True
for i in range(F):
    water_list[i + A * 100] = water_list[i + A * 100] or water_list[i]
    water_list[i + B * 100] = water_list[i + B * 100] or water_list[i]
    sugar_list[i + C] = sugar_list[i + C] or sugar_list[i]
    sugar_list[i + D] = sugar_list[i + D] or sugar_list[i]

for wi in range(0, F + 1, 100):
    for si in range(F + 1):
        if si * 100 <= wi * E and si + wi <= F and water_list[wi] and sugar_list[si]:
            if (si * (s + w) >= s * (si + wi)) or (s == 0 and si > 0):
                s, w = (si, wi)
print('{} {}'.format(s + w, s))


Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  char c[4];
  for(int i = 0; i < 4; i++) c[i] = s[i];

  sort(c, c + 4);
  if(c[0] == c[1] && c[2] == c[3] && c[1] != c[2]){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))

int
main(int argc, char *argv[])
{
  char s[51];
  scanf("%s", s);
  int n = strlen(s);
  if(n > 9 || n < 5) printf("NO\n");
  else{
    char t[20];
    int k = 0; int l = 0;
    while(k < n){
      if(s[k] == 'K' && s[Max(k - 1, 0)] != 'A'){
	t[l++] = 'A';
	t[l++] = 'K';
      }
      else if(s[k] == 'H' && s[k + 1] != 'A'){
	t[l++] = 'H';
	t[l++] = 'A';
      }
      else if(s[k] == 'B' && s[k + 1] != 'A'){
	t[l++] = 'B';
	t[l++] = 'A';
      }
      else if(s[k] == 'R' && s[k + 1] != 'A'){
	t[l++] = 'R';
	t[l++] = 'A';
      }
      else t[l++] = s[k];
      k++;
    }
    t[l] = 0;
    //printf("%s\n", t);
    char x[] = "AKIHABARA\0\0\0\0\0\0\0\0\0\0";
    int cnt = 0;
    for(int i = 0; i < l; i++){
      if(t[i] == x[i])cnt++;
      else break;
    }
    if(cnt == 9) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}


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

int main(void)
{

  int n;

  cin >> n;

  for (int i = 0; i < to_string(n).length(); i++)
  {
    if (to_string(n)[i] == '1')
    {
      cout << 9;
    }
    else if (to_string(n)[i] == '9')
    {
      cout << 1;
    }
  }
}

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

int main() {
    int N;  cin >> N;
    double T, A;  cin >> T >> A;
    vector<int> H(N);
    double diff = 1e9;
    int pos = 0;
    for (int i = 1; i <= N; i++) {
        cin >> H[i];
        double temp = T - H[i] * 0.006;
        if (diff > fabs(temp - A)) {
            pos = i;
            diff = fabs(temp - A);
        }
    }
    cout << pos << endl;
}

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

using namespace std;

int main () {
    string s = "";
    cin >> s;
    int len = s.size();
    int count0 = 0, count1 = 0;
    for (int i=0; i<len; i++) {
        if (s.at(i) == '0') count0++;
        else count1++;
    }
    cout << min(count0, count1) * 2 << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void divisors() {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int h = 0;
		
		for(int i = a; i <= b; i++) {
			if(c%i == 0) {
				h++;
			}
		}
		System.out.println(h);
	}
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		divisors();
	}

}



Measured memory_bytes: 26332
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.sqrt

fun main(args: Array<String>) {

    // IO Templates
    val br = BufferedReader(InputStreamReader(System.`in`))
    val out = PrintWriter(System.out)

    val n = br.readLine()!!.toInt()

    val nums = IntArray(n + 10) { 2 }
    nums[1] = 1

    var cnt = 2

    while (cnt * cnt <= n) {

        var p = cnt + cnt

        while (p <= n) {
            if (p >= cnt * cnt) {
                nums[p]++
            }
            if (p > cnt * cnt) {
                nums[p]++
            }
            p += cnt
        }

        cnt++
    }

    var ans = 0

    for (i in 1 until n) {
        ans += nums[i]
    }

    out.println(ans)

    out.flush()
}

Measured memory_bytes: 38180
#include<stdio.h>
typedef struct card{
  char c;
  int val;
  int num;
}card;
void quicksort(card*,int,int);
int partition(card*,int,int);
int main(){

  int i,j,n,flag=0;

  scanf("%d",&n);
  card A[n];
  for(i=0;i<n;i++){
    scanf(" %c%d",&A[i].c,&A[i].val);
    A[i].num=i;
  }
  quicksort(A,0,n-1);
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      if(A[i].val==A[j].val && A[i].num>A[j].num){
	flag=1;
	break;
      }
    }
    if(flag==1) break;
  }
  
  if(flag==1) printf("Not stable\n");
  else printf("Stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].c,A[i].val);
  }
  return 0;
}
void quicksort(card *A,int p,int r){

  int q;
  if(p<r){
    q=partition(A,p,r);
    quicksort(A,p,q-1);
    quicksort(A,q+1,r);
  }
}
int partition(card *A,int p,int r){

  int i,j;
  int x;
  card swap;

  i=p-1;
  x=A[r].val;

  for(j=p;j<r;j++){
    if(A[j].val<=x){
      i++;
      swap=A[i];
      A[i]=A[j];
      A[j]=swap;
    }
  }
  swap=A[i+1];
  A[i+1]=A[r];
  A[r]=swap;
  return i+1;
}



Measured memory_bytes: 3028
#include <bits/stdc++.h>
#define ll u_int64_t
#define rep(i, n) for (int i=0; i<n; i++)
 
using namespace std;
 
int main() {
	int n;
	cin >> n;
	n %= 10;
	if (n == 3)
		cout << "bon" << endl;
	else if (n == 0 || n == 1 || n == 6 || n == 8)
		cout << "pon" << endl;
	else
		cout << "hon" << endl;	
}

Measured memory_bytes: 3628