akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

int main() {
  std::cout << std::setprecision(9);
  int x, y;
  cin >> x >> y;

  if (y >= 2*x && y <= 4*x && y % 2 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main() {
    int n,i,s,h,c,d,num;
    char suit;
    cin>>n;
    s=h=c=d=0;
    for (i=0;i<n;i++) {
        cin >> suit >> num;
        if (suit == 'S') s |= 1<<num;
        else if (suit == 'H') h |= 1<<num;
        else if (suit == 'C') c |= 1<<num;
        else if (suit == 'D') d |= 1<<num;
    }
    for (int i=1;i<=13;i++) {
        if ((s & 1<<i) == 0) cout << "S " << i << endl;
    }
    for (int i=1;i<=13;i++) {
        if ((h & 1<<i) == 0) cout << "H " << i << endl;
    }
    for (int i=1;i<=13;i++) {
        if ((c & 1<<i) == 0) cout << "C " << i << endl;
    }
    for (int i=1;i<=13;i++) {
        if ((d & 1<<i) == 0) cout << "D " << i << endl;
    }
    return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define ll long long
#define endl "\n"
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define hell 1000000007
#define ff first
#define ss second
#define pii pair<ll,ll>
#define upd upper_bound
#define lbd lower_bound
#define vi vector<ll>
#define vii vector<pii>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)

using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define N 200005

ll i=0,j=0;

ll powr(ll a,ll b)
{
    ll i=0;
    ll ans=1;
    for(i=1;i<=b;i++)
    {
        ans*=a;
    }
    return ans;
}

ll n,m;
ll dp[N];
vi adj[N];

ll dfs(ll v)
{
    if(dp[v]>=0)
    {
        return dp[v];
    }
    dp[v]=0;
    if(adj[v].size()==0)
        return dp[v];
    for(auto it : adj[v])
    {
        dp[v]=max(dp[v],dfs(it));
    }
    dp[v]+=1;
    return dp[v];
}

int main()
{
    IOS;
    ll h,w;
    cin>>h>>w;
    char ch[h+1][w+1];
    for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            cin>>ch[i][j];
        }
    }
   /* for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            cout<<ch[i][j];
        }
        cout<<endl;
    } */
    ll dp[h+1][w+1];
    memset(dp,0,sizeof(dp));
    dp[1][1]=1;
    for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            if(i==1 and j==1)
                continue;
            if(ch[i][j]=='#')
                dp[i][j]=0;
            else
            {
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%hell;
            }
        }
    }
    /*for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    cout<<dp[h][w]<<endl;
}



Measured memory_bytes: 15232
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    long N;
    cin >> N;
    long copy_N = N;
    long S = 0;
    while (copy_N > 0) {
        S += copy_N%10;
        copy_N /= 10;
    }
    if (N%S == 0){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, tot, mod, ans;

struct data {
	int l, r;

	bool operator < (const data &t) const {
		int vl = l ? l : r, vr = t.l ? t.l : t.r;
		if (vl != vr) return vl < vr;
		vl = l ? r : l, vr = t.l ? t.r : t.l;
		return vl < vr;
	}
}a[501];
int f[600][600];

inline void addto(int &x, int y) {
	x += y;
	if (x < 0) x += mod;
	if (x >= mod) x -= mod;
}

int main() {
	scanf("%d%d", &n, &mod);
	n *= 2;
	for (int i = 0; i < n; ++i) {
		int l = n, r = 0;
		for (int j = 0; j < n; ++j)
			if (i * i + j * j >= n * n / 4 && i * i + j * j <= n * n) {
				l = min(l, j); r = max(r, j);
			}
		a[i] = (data){l, r + 1};
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i)
		if (!a[i].l) ++tot;
	for (int i = 0; i <= n; ++i) {
		memset(f, 0, sizeof f);
		f[0][0] = 1;
		int cnt = 0;
		for (int j = 0; j < n; ++j) {
			for (int k = 0; k <= j; ++k) {
				if (a[j].l) {
					addto(f[j + 1][k + 1], 1ll * f[j][k] * (a[j].l - (cnt + k)) % mod);
					addto(f[j + 1][k], 1ll * f[j][k] * (a[j].r - (i + j - k + tot - cnt)) % mod);
				} else {
					addto(f[j + 1][k], 1ll * f[j][k] * (a[j].r - (cnt + k)) % mod);
				}
			}
			cnt += !a[j].l;
		}
		assert(cnt == tot);
		if (i & 1) addto(ans, -f[n][i]);
		else addto(ans, f[n][i]);
	}
	printf("%d", ans);
}


Measured memory_bytes: 1664
#include <cstdio>
#include <algorithm>
#include <cstring>

#define R register
bool vis[100][100], pk[100][100];
inline bool dfs(R int x, R int y)
{
	if (x <= 1 && y <= 1) return 0;
	if (x > y) std::swap(x, y);
	if (vis[x][y]) return pk[x][y];
	vis[x][y] = 1;
	for (R int i = 1; 2 * i <= x; ++i)
		if (!dfs(x - 2 * i, y + i)) return pk[x][y] = 1;
	for (R int i = 1; 2 * i <= y; ++i)
		if (!dfs(x + i, y - 2 * i)) return pk[x][y] = 1;
	return 0;
}
int main()
{
/*	for (R int i = 1; i <= 10; ++i)
		for (R int j = 0; j <= i; ++j)
		{
			printf("%d %d %d\n", i, j, dfs(i, j));
		}*/
	R int x, y; scanf("%d%d", &x, &y);
	if (std::abs(x - y) < 2) puts("Brown");
	else puts("Alice");
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String s = sc.next();
        char[] S = s.toCharArray();
        int counter = 0;
        char temp = S[0];
        for (int i=1; i<N; i++) {
            if (S[i]==temp) {
                S[i] = ' ';
            } else {
                temp = S[i];
            }
        }
        String out = "";
        for (int i=0; i<N; i++) {
            if (S[i]!=' ') {
                out += S[i];
            }
        }
        System.out.println(out.length());
    }
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N;
    cin>>N;
    string s;
    cin>>s;
    int r = 0;
    int b = 0;
    REP(i,N) {
        if (s[i] == 'R') r++;
        else b++;
    }
    if (r>b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

#define MOD 1000000007
#define INT_MAX

int main()
{
	int k, s;
	cin >> k >> s;

	int res = 0;
	
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			int z = s - x - y;
			if (0 <= z && z <= k) {
				res++;
			}
		}
	}

	cout << res << endl;

	return (0);
}

Measured memory_bytes: 256
//
//	Created by shamim_nik
//

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,
		tree_order_statistics_node_update> indexed_set;

#define br printf("\n")

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

//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	char ch;
	cin >> ch;
	if (ch >= 'A' && ch <= 'Z') {
		cout << "A\n";
	} else if (ch >= 'a' && ch <= 'z') {
		cout << "a\n";
	}
	return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int root[100100],x[100100],to=0,db[100100][20],dp[100100];
bool done[100100];
vector<int> ar,g[100100];
queue<int> que;

int lca(int a, int b){
	int d = 0,i;
	d = dp[a] - dp[b];
	if(d < 0){
		swap(a,b);
		d = (-d);
	}
	for(i=0; i<20; ++i){
		if(d&(1<<i)){
			a = db[a][i];
		}
	}
	if(a==b){
		return a;
	}
	for(i=19; i>=0; --i){
		if(db[a][i] == db[b][i]){
			continue;
		}
		a = db[a][i];
		b = db[b][i];
	}
	return db[a][0];
}

struct node{
	int id,lch,rch,v;
};

node segtree[4114114];

int init(int v, int l, int r){
	int id;
	id = to;
	++to;
	segtree[id].id = id;
	if(r-l>1){
		segtree[id].lch = init(v,l,(l+r)/2);
		segtree[id].rch = init(v,(l+r)/2,r);
		segtree[id].v = segtree[segtree[id].lch].v + segtree[segtree[id].rch].v;
	}else{
		segtree[id].v = ((l<=v && v<r)?1:0);
	}
	return id;
}

int update(int from, int v, int l, int r){
	int id;
	if(!(l<=v && v<r)){
		return segtree[from].id;
	}
	id = to; ++to;
	segtree[id].id = id;
	if(r-l>1){
		segtree[id].lch = update(segtree[from].lch,v,l,(l+r)/2);
		segtree[id].rch = update(segtree[from].rch,v,(l+r)/2,r);
		segtree[id].v = segtree[segtree[id].lch].v + segtree[segtree[id].rch].v;
	}else{
		segtree[id].v = segtree[from].v+1;
	}
	return id;
}

int query(int a, int b, int i, int l, int r){
	int vl,vr;
	if(b<=l || r<=a){
		return 0;
	}
	if(a<=l && r<=b){
		return segtree[i].v;
	}
	vl = query(a,b,segtree[i].lch,l,(l+r)/2);
	vr = query(a,b,segtree[i].rch,(l+r)/2,r);
	return vl+vr;
}

int main(void){
	int n,q,i,j,a,b,c,t,l,r,m,av,bv,cv,v;
	cin >> n >> q;
	for(i=0; i<n; ++i){
		cin >> x[i];
		ar.push_back(x[i]);
	}
	sort(ar.begin(),ar.end());
	for(i=0; i<n; ++i){
		x[i] = (int)(lower_bound(ar.begin(),ar.end(),x[i])-ar.begin());
	}
	for(i=1; i<n; ++i){
		cin >> a >> b; --a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	que.push(0);
	root[0] = init(x[0],0,n);
	done[0] = true;
	dp[0] = 0;
	while(!que.empty()){
		a = que.front();
		que.pop();
		for(i=(g[a].l_ength()-1); i>=0; --i){
			b = g[a][i];
			if(done[b]){
				continue;
			}
			done[b] = true;
			dp[b] = dp[a]+1;
			db[b][0] = a;
			root[b] = update(root[a],x[b],0,n);
			que.push(b);
		}
	}
	for(j=1; j<20; ++j){
		for(i=0; i<n; ++i){
			db[i][j] = db[db[i][j-1]][j-1];
		}
	}
	for(i=0; i<q; ++i){
		cin >> a >> b >> t; --a; --b;
		c = lca(a,b);
		l = -1; r = n-1;
		while(r-l>1){
			m = (l+r)/2;
			av = query(0,m+1,root[a],0,n);
			bv = query(0,m+1,root[b],0,n);
			cv = query(0,m+1,root[c],0,n);
			v = av+bv-cv*2;
			if(x[c]<=m){
				++v;
			}
			if(v<t){
				l = m;
			}else{
				r = m;
			}
		}
		cout << ar[r] << endl;
	}
	return 0;
}



Measured memory_bytes: 48688
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve [r, _, g, _, b] | x `mod` 4 == 0 = "YES"
                      | otherwise      = "NO"
  where x = read [r, g, b] :: Int

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    string S,T;cin >> S >> T;

    bool ok = true;
    rep(i,S.size()){
        if(T[i] != S[i])ok = false;
    }

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

Measured memory_bytes: 3628
n, x = None, None
while True:
    n, x = list(map(int, input().split(' ')))
    if n == 0 and x == 0:
        break
    res = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    res += 1
    print(res)



Measured memory_bytes: 5596
n=int(input())
l=list(map(int,input().split()))
ans=0
if n<3:
    print(0)
    exit()
for i in range(0,n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]!=l[j] and l[j]!=l[k] and l[i]!=l[k]:
                if l[i]<l[j]+l[k] and l[j]<l[i]+l[k] and l[k]<l[i]+l[j]:
                    ans+=1
                    #print(l[i],l[j],l[k])
print(ans)

Measured memory_bytes: 9220
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
int main(){
  string s;
  int a=0;int b=0;
  int cnt=0;
  cin>>s;
  if(s[0]==s[1]&&s[1]==s[2]&&s[2]==s[3]){
    cout<<"No";
    return 0;
  }
  if(s[0]==s[1]) {
    if(s[2]==s[3]){
      cout<<"Yes";
      return 0;
    }
  }else if(s[0]==s[2]) {
    if(s[1]==s[3]){
      cout<<"Yes";
      return 0;
    }
  }else if(s[0]==s[3]) {
    if(s[2]==s[1]){
      cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> mochi(n);
  for (int i=0;i<n;i++){
    cin >> mochi[i];
  }
  sort(mochi.begin(),mochi.end());
  int before=0,ans=0;
  for(int i=0;i<n;i++){
    if (before!=mochi[i]){
      before=mochi[i];
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

int main() {
    int n, k; cin >> n >> k;
    vector<pair<int, int>> xy(n);
    vector<int> x(n);
    vector<int> y(n);
    for (int i = 0; i < n; i++)
    {
        int xx, yy; cin >> xx >> yy;
        x[i] = xx;
        y[i] = yy;
        xy[i] = make_pair(xx, yy);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    ll ans = 4*1e18;
    for (int left = 0; left < n; left++) {
        for (int right = left+1; right < n; right++) {
            for (int bottom = 0; bottom < n; bottom++) {
                for (int upper = bottom+1; upper < n; upper++){
                    int l = x[left], r = x[right];
                    int b = y[bottom], u = y[upper];
                    int tmp = 0;
                    for (int i = 0; i < n; i++) {
                        if (xy[i].first >= l && xy[i].first <= r && xy[i].second >= b && xy[i].second <= u)
                            tmp++;
                    }
                    if (tmp >= k) {
                        ans = min(ans, (ll)(r-l)*(ll)(u-b));
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz");
char s[101][101];
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>h>>w;
    rep(i,h)rep(j,w)cin>>s[i][j];
    rep(i,w+2)cout<<"#";
    cout<<"\n";
    rep(i,h){
        rep(j,w){
            if(j==0)cout<<"#";
            cout<<s[i][j];
            if(j==w-1)cout<<"#\n";
        }
    }
     rep(i,w+2)cout<<"#";
    cout<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=15e4;
vector<int> G[MAX_N];
int N;
unordered_map<int,double> dp[MAX_N];

double dfs(int v,int p){
	if(dp[v].find(p)!=dp[v].end()){
		return dp[v][p];
	}
	int cnt=0;
	for(auto e:G[v]){
		if(e!=p){
			cnt++;
		}
	}
	double ret;
	if(cnt==0){
		ret=0;
	}else{
		ret=1;
		for(auto e:G[v]){
			if(e!=p){
				ret+=dfs(e,v)/cnt;
			}
		}
	}
	return dp[v][p]=ret;
}
typedef pair<int,int> P;
double ans[MAX_N];
int main(){
	cin>>N;
	REP(i,N-1){
		int u,v;
		cin>>u>>v;
		u--;
		v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	vector<int> per;
	{
		queue<P> que;
		que.push(P(0,-1));
		per.push_back(0);
		while(!que.empty()){
			P p=que.front();
			que.pop();
			int v=p.first,q=p.second;
			for(auto e:G[v]){
				if(e!=q){
					que.push(P(e,v));
					per.push_back(e);
				}
			}
		}
	}
	REP(i,N){
		ans[per[i]]=dfs(per[i],-1);
		double sm=0;
		for(auto e:G[per[i]]){
			sm+=dp[e][per[i]];
		}
		if((int)G[per[i]].size()==1){
			dp[per[i]][G[per[i]][0]]=0;
		}else{
			for(auto e:G[per[i]]){
				dp[per[i]][e]=(sm-dp[e][per[i]])/((int)G[per[i]].size()-1)+1;
			}
		}
	}
	REP(i,N){
		printf("%.16f\n",ans[i]);
	}
}

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

int main(){

  int T, D;
  int t_A, t_B;
  int d_A, d_B;
  double ret = 1e9;

  cin >> T >> D;
  cin >> t_A >> t_B;
  cin >> d_A >> d_B;

  for(int i = 0; d_A * i <= D; i++){
    for(int j = i == 0; d_A * i + d_B * j <= D; j++){

      int v_A = d_A * i;
      int v_B = d_B * j;

      ret = min( ret, fabs( (double)T - (double)((t_A * v_A) + (t_B * v_B)) / (double)(v_A + v_B)));
    }
  }

  cout << fixed << setprecision(10) << ret << endl;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template <typename T1, typename T2>
void chmax(T1 &a, const T2 &b) {
  if(a < b) a = b;
}

template <typename T1, typename T2>
void chmin(T1 &a, const T2 &b) {
  if(a > b) a = b;
}

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int sch(int now, int prev, const vector<vector<int>> &tr) {
  int su = 0, zero = 0;
  for(int i=0;i<SZ(tr[now]);++i) {
    int nxt = tr[now][i];
    if(nxt == prev) continue;
    int tmp = sch(nxt, now, tr);
    su += tmp;
    if(tmp == 0) zero++;
  }
  if(zero > 1) su += zero - 1;
  return su;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vector<vector<int>> tr(n);
  vector<int> d(n);
  for(int i=0;i<n-1;++i) {
    int a, b; cin >> a >> b;
    tr[a].push_back(b);
    tr[b].push_back(a);
    d[a]++;
    d[b]++;
  }

  int arg = -1;
  for(int i=0;i<n;++i) {
    if(d[i] >= 3) arg = i;
  }
  if(arg == -1) {
    cout << 1 << endl;
    return 0;
  }

  cout << sch(arg, -1, tr) << endl;
}


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

int main(){
  int n;
  cin >> n;
  vi h(n);
  rep(i,n) cin >> h[i];
  int mx = 0;
  rep(i,n){
    mx = max(mx, h[i]);
    if(mx - h[i] > 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3708
k = int(input())
 
s = 7
for i in range(1, k+1):			# rangeの上限がk
    if s % k == 0:
        print(i)
        break
    s = (s * 10 + 7) % k		# %kが難しい
else:                           # for文にもelseが使える
    print(-1)

Measured memory_bytes: 63112
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<functional>
#include<map>
using namespace std;

int main()
{
	long long n, i=2,res, fro,tmp;
	cin >> n;
	if (n == 0)cout << 2 << endl;
	else if (n == 1)cout << 1 << endl;
	else {
		res = 1; fro = 2;
		while (i <= n)
		{
			tmp = res;
			res += fro;
			fro = tmp;
			i++;
		}
		cout << res<< endl;
	}
	//system("pause");
	return 0;
}

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

struct pair_hash {
    template <class T1, class T2>
    std::size_t operator () (const std::pair<T1,T2> &p) const {
        auto h1 = std::hash<T1>{}(p.first);
        auto h2 = std::hash<T2>{}(p.second);
        return h1 ^ h2;
    }
};

pair<ll, ll> operator-(const pair<ll, ll> &p1, const pair<ll, ll> &p2) {
  return make_pair(p1.first - p2.first, p1.second - p2.second);
}

pair<ll, ll> operator*(ll a, pair<ll, ll> &p) {
  return make_pair(p.first * a, p.second * a);
}

pair<ll, ll> euclid(ll x, ll y, pair<ll, ll> xc = {1, 0}, pair<ll, ll> yc = {0, 1}) {
  if(y == 0)
    return xc;

  return euclid(y, x % y, yc, xc - (x / y) * yc);
}

ll inverse(ll a) {
  return (euclid(MOD, a).second + MOD) % MOD;
}

unordered_map<pair<ll, ll>, ll, pair_hash> combination_hash;

vector<ll> factorial(210000), inverse_factorial(210000);

ll combination(ll a, ll b) {
  ll ret = (factorial[a] * inverse_factorial[a - b]) % MOD;
  ret = (ret * inverse_factorial[b]) % MOD;
  return ret;
}

int main(){

  ll tmp = 1;
  factorial[0] = 1;

  for(ll i = 1; i < 210000; i++) {
    factorial[i] = (factorial[i - 1] * i) % MOD;
  }

  inverse_factorial[0] = 1;

  for(ll i = 1; i < 210000; i++) {
    inverse_factorial[i] = (inverse_factorial[i - 1] * inverse(i)) % MOD;
  }

  ll H, W, A, B;
  cin >> H >> W >> A >> B;

  ll ret = 0;
  for(ll i = 0; i <= H - A - 1; i++) {
    ret += ((combination(B - 1 + i, i) % MOD) * (combination(H + W - B - 2 - i, W - B - 1) % MOD) % MOD);
    ret %= MOD;
  }
  cout << ret << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using P = pair<ll, ll>;
void prp(P& p) {cout << p.first << " " << p.second << endl;}
int main()
{
    int n; cin >> n;
    vector<P> x(n);
    rep(i, n) {
        ll a, b; cin >> a >> b;
        x[i].first = a + b;
        x[i].second = a - b;
    }
    sort(ALL(x));
    int cnt = 1;
    P p = x[0];
    FOR(i, 1, x.size()){
        if(p.first <= x[i].second){ 
            cnt++;
            p = x[i];
        }
    }
    pr(cnt);
    return 0;}

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

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

   set<int> st;
   int x = s;

   while(st.count(x) == 0){
       st.insert(x);
       if(x % 2 == 0){
           x /= 2;
       }
       else{
           x = x * 3 + 1;
       }
   }

   cout << st.size() + 1 << endl;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())

MOD = 10 ** 9 + 7

def comb(n, r):
    ret = 1
    for i in range(r):
        ret *= n - i
        ret %= MOD
    for i in range(r):
        ret *= pow(i+1, MOD-2, MOD)
        ret %= MOD

    return ret % MOD
    

ans = pow(2, n, MOD) - 1 - comb(n, a) - comb(n, b)
ans %= MOD
print(ans)


Measured memory_bytes: 38896
w = 199

x = int(input())

if x >= 400 and x < 600:
    print(8)
elif x >= 600 and x < 800:
    print(7)
elif x >= 800 and x < 1000:
    print(6)
elif x >= 1000 and x < 1200:
    print(5)
elif x >= 1200 and x < 1400:
    print(4)
elif x >= 1400 and x < 1600:
    print(3)
elif x >= 1600 and x < 1800:
    print(2)
elif x >= 1800 and x < 2000:
    print(1)


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

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define MOD 1000000007

int n,m,ss,gg;
vector<pair<int,pll>> g[252521];

ll dist[252521];

ll calc(ll d, ll a, ll b){
  // max t s.t. ceil((tt+ta+b)/(t+a)) <= d
  // (tt+ta+b) / (t+a) <= d
  // t^2 + (a-d)t + b-da <= 0
  // x = ( (d-a)+sqrt((d-a)^2 - 4b+4da) )/2

  // (d-a)^2 - 4d(1-a)
  // d^2 + a^2 - 4d + 2da
  // (d+a)^2 - 4d
  // (d+a)^2 - (2sqrt(d))^2
  // (d+a+2sqrt(d)) * (d+a-2sqrt(d))

  // -x <= t <= x
  ll da = d-a;
  double D2 = (double)da*da - 4.0*b + 4.0*d*a;
  if(D2 < 0)return -1;
  double D = sqrt(D2);
  double x = (da+D)/2.0;
  if(x<0)return -1;
  return min((ll)x,d-1);
}

bool check(ll x){
  REP(i,n)dist[i] = -(1ll<<60);
  // dist[i] := i に着く最大の時間
  priority_queue<pll> Q;
  dist[gg] = x;
  Q.push(pll(x,gg));
  while(!Q.empty()){
    pll P = Q.top(); Q.pop();
    int p = P.second;
    ll d = P.first;
    if(dist[p] != d)continue;
    for(pair<int,pll> PP : g[p]){
      int to = PP.first;
      ll a = PP.second.first;
      ll b = PP.second.second;
      ll t = calc(d,a,b);
      if(t<0)continue;
      if(t<=dist[to])continue;
      dist[to] = t;
      Q.push(pll(t,to));
    }
  }
  return dist[ss]>=0;
}

int main(){
  scanf("%d%d%d%d",&n,&m,&ss,&gg);
  --ss;--gg;
  REP(_,m){
    int u,v; ll a,b;
    scanf("%d%d%lld%lld",&u,&v,&a,&b);
    --u;--v;
    g[u].push_back(make_pair(v,pll(a,b)));
    g[v].push_back(make_pair(u,pll(a,b)));
  }
  ll low = 0, high = 1ll<<60;
  while(low+1<high){
    ll x = (low+high)/2ll;
    bool ok = check(x);
    if(ok){
      high = x;
    }else{
      low = x;
    }
  }
  if(high == (1ll<<60))high = -1;
  printf("%lld\n",high);
  return 0;
}


Measured memory_bytes: 30768
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

int main(){
    int A, B, T;
    cin >> A >> B >> T;
    Print(B * (T / A));
    return 0;
}

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

ll inf =1e9+7;

#define pi 3.14159265358979323846L
bool isprime(ll a)
{
	
	ll cnt=0;	
	for(ll i=1;i*i<a;i++)
	{
		
	 	if(a%i==0)
	 	{
	 		cnt+=2;
		 }
		
		
	}
	
		if(cnt==2)
		return true;
		else
		return false;
		
}
ll mod(ll a)
{
	if(a<inf)return a;
	else
	return a%inf;
}
void solve()
{

	ll n,m;
	cin>>n>>m;
	vector<set<ll>>path(n+1);
	
	
		for(ll i=0,x,y;i<m;i++)
	{
		cin>>x>>y;
	
	path[x].insert(y);
	path[y].insert(x);
		
	}
	
	queue<ll>q;
	ll b[n+1];
	bool visited[n+1]={false};
	
	q.push(1);
	b[1]=1;
	visited[1]=true;
	while(q.size()>0)
	{
		ll parent=q.front();
		q.pop();
		
		visited[parent]=true;
		
		
		for(auto child:path[parent])
		{
			if(visited[child])continue;
			
			b[child]=parent;
			q.push(child);
			visited[child]=true;
			
		}
		
	}
	
	
	cout<<"Yes\n";
	
	for(ll i=2;i<=n;i++)cout<<b[i]<<"\n";
	

}

int main()
{


ios::sync_with_stdio(0); 
	cin.tie(0);

		solve();
	
return 0;

		
	}
	
	
	


Measured memory_bytes: 28152
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    double t, a;
    cin >> t >> a;
    double h[n];
    rep(i, n) cin >> h[i];
    int ans;
    double mn = 1000000;
    rep(i, n){
        if (mn > abs(t - h[i] * 0.006 - a)){
            mn = abs(t - h[i] * 0.006 - a);
            ans = i + 1;
        }
    }
    cout << ans << endl;
}



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

#define int long long 
#define dou  double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	int x;
	cin >> x;
	if(x>=30)
		cout <<"Yes\n";
	else
		cout <<"No\n";
}

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
}

Measured memory_bytes: 3664
n = int(input())

arr6 = []
for i in range(10):
	arr6.append(6**i)

arr9 = []
for i in range(10):
	arr9.append(9**i)


ans = float("inf")
for i in range(n+1):
	count = 0
	tmp = i
	while tmp > 0:
		t = 0
		while arr6[t] <= tmp:
			t+=1

		tmp -= arr6[t-1]
		count += 1

	tmp = n-i
	while tmp > 0:
		t = 0
		while arr9[t] <= tmp:
			t += 1
		tmp -= arr9[t-1]
		count += 1

	ans = min(ans,count)

print ans

Measured memory_bytes: 5764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

using namespace std;
using ui = unsigned int;
using ll = long long;
using ull = unsigned long long;

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

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// CHAR_MAX  = 127
// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


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

    ll r, g, b;
    r = g = b = 0;
    rep(idx, n) {
        switch (s[idx]) {
            case 'R': r += 1; break;
            case 'G': g += 1; break;
            case 'B': b += 1; break;
        }
    }

    ll num_black = 0;
    for (int stride = 1; stride <= (n - 1) / 2.0; stride++) {
        for (int i = 0; i + stride * 2 < n; i++) {
            int j = i + stride;
            int k = j + stride;
            if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) {
                num_black += 1;
            }
        }
    }

    cout << r * g * b - num_black << '\n';

    return 0;
}


Measured memory_bytes: 3140
n = int(input())
num_list = list(map(int, input().split()))

count = 0

for i in range(n-2):
    num_id = i+1
    temp = [num_list[num_id-1], num_list[num_id], num_list[num_id+1]]
    list_sorted = sorted(temp, reverse=True)
    if list_sorted[1] == num_list[num_id]:
        count += 1


print(count)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
#include<numeric>
using namespace std;
typedef long long ll;
//ll mod = 1e9+7;
ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, n-1) {
        if ( a[i] + a[i+1] > x ) {
            ans += a[i] + a[i+1] - x;
            a[i+1] -= a[i] + a[i+1] - x;
            if ( a[i+1] < 0 ) {
                a[i] += a[i+1];
                a[i+1] = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
fun main(args:Array<String>){
  val (N,K,Q) = readLine()!!.split(" ").map{it.toInt()}
  val A = Array(Q){readLine()!!.toInt()}
  val correct = Array(N){0}
  for(x in A){
    correct[x-1]++
  }
  val limit = Q-K+1
  for(x in correct){
    println(if(x>=limit)"Yes" else "No")
  }
}

Measured memory_bytes: 46320
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B___Common_Raccoon_vs_Monster
{
    class Program
    {
        static void Main(string[] args)
        {
            var oneRow = Console.ReadLine();
            var twoRow = Console.ReadLine();

            string[] oneRowSplit = oneRow.Split(' ');
            string[] damage = twoRow.Split(' ');
            var health = int.Parse(oneRowSplit[0]);
            var number = int.Parse(oneRowSplit[1]);

            for (int i = 0; i < number; i++)
            {
                var dame = damage[i];
                health = health- int.Parse(dame);

            }
            if (health <= 0)
            {
                Console.WriteLine("Yes");
                return;
            }
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 15968
from math import *
import sys

N = int(input())
all_input_list = [[int(j) for j in input().split()] for i in range(N)]
x, y, h = [all_input_list[i] for i in range(N) if all_input_list[i][2] > 0][0]
for cx in range(101):
    for cy in range(101):
        flag = 1
        H = h + abs(cx - x) + abs(cy - y)
        for input_list in all_input_list:
            if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
                flag = 0
                break
        if (flag == 1):
            print("%s %s %s" % (cx, cy, H))
            sys.exit(0)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>

template<class T>
inline T _max(const T&a,const T&b)
{
	if(a<0)
		return b;
	return (a>b?a:b);
}
template<class T>
inline T _min(const T&a,const T&b)
{
	if(a<0)
		return b;
	return (a<b?a:b);
}

int N;
struct _b
{
	int x;int y;
	bool operator < (const _b&t2)const
	{
		if(x==t2.x)
			return y<t2.y;
		return (x<t2.x);
	}
}b[205050];

long long ans;
int rmx,rmn,bmx,bmn;
int totMAX,totMIN,tmxk,tmnk;

inline long long GetThisAns()
{
	if(rmx==-1)
		return LLONG_MAX;
	return (long long)(rmx-rmn)*(long long)(bmx-bmn);
}

inline void _swap(int&a,int&b)
{
	a+=b;
	b=a-b;
	a=a-b;
}

inline int getnum()
{
	char c=getchar();
	while(!(c>='0' && c<='9'))
		c=getchar();
	int a=0;
	while(c>='0' && c<='9')
	{
		a*=10;a+=c-'0';
		c=getchar();
	}
	return a;
}

int main()
{
	scanf("%d",&N);
	totMIN=LONG_MAX;totMAX=LONG_MIN;
	for(register int i=1;i<=N;i++)
	{
		b[i].x=getnum();b[i].y=getnum();
		if(b[i].x>b[i].y)
			_swap(b[i].x,b[i].y);
		totMAX=_max(totMAX,_max(b[i].x,b[i].y));
		totMIN=_min(totMIN,_min(b[i].x,b[i].y));
	}
	
	ans=LLONG_MAX;
	rmx=rmn=bmx=bmn=-1;
	
	// (rmx=totMAX && bmn=totMIN) || (rmn=totMIN && bmx=totMAX)
	long long nans=-1;
	rmx=rmn=bmx=bmn=-1;
	rmx=totMAX;bmn=totMIN;
	for(register int i=1;i<=N;i++)
	{
		bmx=_max(bmx,_min(b[i].x,b[i].y));
		rmn=_min(rmn,_max(b[i].x,b[i].y));
	}
	nans=GetThisAns();
	ans=_min(ans,nans);

	// (bmx=totMAX && bmn=totMIN) || (rmx=totMAX && rmn=totMIN)
	nans=-1;
	rmx=rmn=bmx=bmn=-1;
	bmx=totMAX;bmn=totMIN;
	std::sort(&b[1],&b[N+1]);
	rmx=b[N].x;
	int pmin=b[1].y;
	nans=rmx-rmn;
	for(register int i=1;i<N;i++)
	{
		rmx=_max(rmx,b[i].y);
		rmn=_min(pmin,_min(b[i].y,b[i+1].x));
		pmin=_min(pmin,b[i].y);
		nans=_min(nans,(long long)(rmx-rmn));
	}
	ans=_min(ans,nans*(long long)(bmx-bmn));
	
	
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 1664
from math import factorial
n,m=map(int,input().split())
mod=10**9+7
if abs(n-m)>1:
    print(0)
elif abs(n-m)==1:
    d=factorial(n)%mod
    m=factorial(m)%mod
    print((d*m)%mod)
else:
    d=factorial(n)%mod
    print((2*d**2)%mod)

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    vector<int> p(n), q(n);
    for (auto i = 0; i < n; i++) cin >> p[i];
    for (auto i = 0; i < n; i++) cin >> q[i];

    vector<int> num(n);
    iota(num.begin(), num.end(), 1);
    int a = -1, b = -1, cnt = 0;
    do {
        if(equal(p.begin(), p.end(), num.begin())) a = cnt;
        if(equal(q.begin(), q.end(), num.begin())) b = cnt;
        if(a != -1 and b != -1) break;
        cnt++;
    } while(next_permutation(num.begin(), num.end()));

    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> X(2),Y(2);
  for(int i=0;i<2;i++){
      cin>>X.at(i)>>Y.at(i);
  }
  int movex=X.at(0)-X.at(1),movey=Y.at(0)-Y.at(1);
  cout<<X.at(1)+movey<<endl;
  cout<<Y.at(1)-movex<<endl;
  cout<<X.at(0)+movey<<endl;
  cout<<Y.at(0)-movex<<endl;
}


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

const int MAXN = 500 + 3;
int H[MAXN][MAXN];
bool occ[MAXN][MAXN];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void dfs(int x, int y) {
    int z = H[x][y] + occ[x][y];
    for (int t = 0; t < 4; t++) {
        int x1 = x + dx[t], y1 = y + dy[t];
        if (H[x1][y1] > z) {
            H[x1][y1] = z;
            dfs(x1, y1);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N;
    cin >> N;
    
    for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) {
        H[i][j] = min(min(i, N+1-i), min(j, N+1-j)) - 1;
        occ[i][j] = true;
    }

    int res = 0;
    for (int it = 0; it < N*N; it++) {
        int id;
        cin >> id;
        int x = (id+N-1)/N;
        int y = id % N;
        if (y == 0) y += N;
        res += H[x][y];
        occ[x][y] = false;
        dfs(x, y);
    }
    cout << res << "\n";
    
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	double d;
		
	while (cin >> d) {
		if (d < 0) break;
		
		int ans = -1;
		
		for_(S,0,(1<<12)-1) {
			double a = 0;
			for_(i,0,12) if (S >> i & 1) a += pow(2.0, 7 - i);
			if (fabs(a - d) < 1e-12) ans = S;
		}
		
		if (ans == -1) cout << "NA";
		else for_(i,0,12) cout << (ans >> i & 1) << (i == 7 ? "." : "");
		cout << endl;
	}
}

Measured memory_bytes: 1232
import java.util.*;
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int count = 0;
    for ( int i = 1; i <= N; i += 2) {
        int isYaku = 0;
      for( int j = 1; j <= i; j++ ) {
        if( i % j == 0 ) {
          isYaku++;
        }
      }
      if( isYaku == 8 ) {
        count++;
      }
    }
    System.out.println(count);
  }
}

      


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

using namespace std;

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

  int N; cin>>N;
  vector<int> A(N); for (auto& a : A) cin>>a;
  bool ans = true;
  for (auto a : A) {
    if (a % 2 == 0) {
      if (a % 6 != 0 and a % 10 != 0) {
        ans = false;
        break;
      }
    }
  }
  cout << (ans ? "APPROVED" : "DENIED") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
//#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
const lli INF = 1e18L+5;
/*
lli power(lli x,lli y)
{
    lli res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}
*/
/*
lli C[100001];
lli ncr(lli n, lli k) 
{ 
	if(C[k]!=0)
	return C[k];	
	memset(C, 0, sizeof(C)); 
    C[0] = 1;  // nC0 is 1 
  
    for (lli i = 1; i <= n; i++) 
    { 
        for (lli j = min(i, k); j > 0; j--) 
            C[j] = (C[j]%mod + C[j-1]%mod)%mod; 
    } 
    return C[k]%mod; 
}*/
/*
void dfs(lli node,vector<lli> graph[],lli *arr)
{
	arr[node]=1;
	for(lli i=0;i<graph[node].size();i++)
	{
		lli child=graph[node][i];
		if(arr[child]!=1)
		dfs(child,graph,arr);
	}
	return ;
}*/
int main()
{
//cout.precision(10);
//cout.setf(ios::fixed,ios::floatfield);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
	lli T=1;
    //cin>>T;
	while(T--)
	{
		lli n;
		cin>>n;
		cout<<pow(n,3)<<endl;
	}
}
/*
*/



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

int main(){
    int N;
    cin >> N;
    char s;
    bool flag=false;
    rep(i,N){
        cin >> s;
        if(s=='Y') flag=true;
    }
    if(flag) cout << "Four" << endl;
    else cout << "Three" << endl;
}

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

#define MAXN 100100
int n,a[MAXN],dp[MAXN],k;

int main (){
    cin >> n >> k;
    for (int i=0;i<n;++i){
        cin >> a[i];
    }
    for (int i=1;i<n;++i){
        dp[i]=2*1e9;
        for (int j=i-1;(j>=0 && i-j<=k);--j){
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
    }
    cout << dp[n-1];
    return 0;
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int test_cases = 1;
        Solver s = new Solver();
        for (int i = 1; i <= test_cases; i++) {
            s.solve(i, in, out);
        }
        out.close();
    }
}

class Solver {
    void solve(int test_number, InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        int[] a = new int[n];
        int[] freq = new int[(int) (1e5 + 7)];
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
            freq[a[i]]++;
        }
        int max = 0;
        for (int i = 0; i < freq.length; i++) {
            int i1 = freq[i];
            if (i1 > 0) {
                max = Math.max(i1 + (i - 1 >= 0 ? freq[i - 1] : 0) + (i + 1 < freq.length ? freq[i + 1] : 0), max);
            }
        }
        out.println(max);
    }
}


class InputReader {
    BufferedReader br;
    StringTokenizer st;

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

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

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

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

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

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}

Measured memory_bytes: 35752
K,N = map(int, input().split())
A = list(map(int, input().split()))
 
max_d = A[0] + (K-A[-1])
for n in range(1,N):
  _ = A[n-1]
  __ = A[n]
  max_d = max(__-_, max_d)
 

ans = K-max_d
print(ans)

Measured memory_bytes: 25840
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int h,m,s,S;
    	S = sc.nextInt();
    	
    	
    	h = S/(60*60);
    	S = S - h*60*60;
    	m = S/60;
    	s = S%60;
    	System.out.println(h + ":" + m + ":" + s);
    	
    }
}

Measured memory_bytes: 26088
#include <cstdio>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int arr[200001];
int main()
{

	int a;
	cin >> a;
	int flag=1;
	for(int i=0;i<a;i++)
	{
		scanf("%d", &arr[i]);
	}
	sort(arr, arr+a);
	for(int i=0;i<a-1;i++)
	{
		if(arr[i+1]==arr[i])
			flag=0;
	}
	if(!flag)
		cout << "NO";
	else 
		cout << "YES";


	return 0;
}


Measured memory_bytes: 1024
t,*n=map(int,open(0))
for k in n:print(sum(k**j*[0,765144583,346175634,347662323,5655049,184117322,927321758,444014759,542573865,237315285,417297686,471090892,183023413,660103155,727008098,869418286,539588932,729548371,700407153,404391958,962779130,184117322,927321758,444014759,542573865,237315285,417297686,471090892,183023413,660103155,727008098,869418286][(k&1)*16+j]for j in range(16))%(10**9+7))

Measured memory_bytes: 9116
from sys import stdin
import sys
sys.setrecursionlimit(10000)
input = stdin.readline

n = int(input().rstrip())
s = int(input().rstrip())

def f(b, n):
	if n < b:
		return n
	else:
		return f(b, int(n/b)) + (n % b)
if s == n:
	print(n+1)
else:
	for i in range(2, int(n**(1/2))+1):
		if f(i, n) == s:
			print(i)
			break
	else:
		for p in range(int(n**(1/2)), 0, -1):
			if (n-s) % p == 0:
				b = (n-s)/p + 1
				if b >= 2 and f(b, n) == s:
					print(int(b))
					break
			else:
				continue
		else:
			print(-1)


Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <cctype>
#include<math.h>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	if (m == 1)cout << 0 << endl;
	else cout << (n - m) << endl;
}

Measured memory_bytes: 256