akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i,n){
    cin >> vec[i];
  }
  int ans = 0;
  rep(i,n){
    if(vec[i] != i+1){
      if(vec[vec[i]-1] != i+1){
        cout << "NO";
        return 0;
      }
      ans++;
    }
  }
  
  if(ans >= 3){
    cout << "NO";
  }
  else{
  cout << "YES";
  }
  return 0;
}

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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
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; }

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

// 繰り返し二乗法
ll power(ll a, ll b){
    if(a==1)return a;
    // if(a==0)re
    ll res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int MAX=2100000;

ll fact[MAX], fact_inv[MAX];

void init_fact(ll n){
    fact[0]=1;
    // 階乗の計算
    for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
    fact_inv[n]=power(fact[n], MOD-2);
    // 逆元の計算
    for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll perm(ll n, ll r){
    return (fact[n]*fact_inv[n-r])%MOD;
}

int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;

    for(ll i = 0; i*4<=n; i++){
        if((n-i*4)%7==0){
            puts("Yes");
            return 0;
        }
    }

    puts("No");


    return 0;

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 
 
void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
 
double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}
 
ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}
 
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
 
vec modncrlistp,modncrlistm;
 
ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}
 
ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}
 
ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}
 
ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  startupcpp();
  ll i,N,K,ans=0;
  string s,t;cin>>s>>t;
  vsort(s);vrsort(t);
  if(s<t){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int N, W;
int dp[1002][10002];
typedef struct item {
    int v;
    int w;
} Item;

vector<Item> its;

void solve() {
    for (int j = 0; j < N; ++j) {
        dp[j][0]  = 0;
    }
    for (int k = 0; k <= W; ++k) {
        if(k>=its[0].w) dp[0][k] = its[0].v;
        else dp[0][k] = 0;
    }
    for (int i = 1; i < N; ++i) {
        for (int j = 0; j <= W; ++j) {
            if(j-its[i].w>=0){
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-its[i].w] + its[i].v);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
}
int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) {
        int v,w;
        cin >> v >> w;
        Item it = {v, w};
        its.push_back(it);
    }
    solve();
    cout << dp[N-1][W] << endl;

    return 0;
}


Measured memory_bytes: 7052
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui n; cin >> n;
  if(n == !!n){ cout << "Hello World" << CRLF; return; }

  ui a,b; cin >> a >> b;
  cout << a + b << CRLF;

  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#define endl "\n"

using namespace std;

int main(){
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  int sum[N];
  sum[0] = 0;
  for(int i = 0; i < N - 1; i++){
    sum[i + 1] = sum[i] + (S.substr(i, 2) == "AC");
  }
  for(int i = 0; i < Q; i++){
    int l, r;
    cin >> l >> r;
    cout << sum[r - 1] - sum[l - 1] << endl;
  }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int>d;
    d.push_back(1);
    for (int i = 1; i < 2*n; i++)
    {
        if(s[i-1]!=s[i]) d.push_back(d[i-1]);
        else d.push_back(abs(d[i-1]-1)); 
    }
    int MOD=1e9+7;
    int cnt_L=0,cnt_R=0;
    for (int i = 0; i < 2*n; i++)
    {
         if(d[i]==1) cnt_L++;
        else cnt_R++;
    }
    if(cnt_R!=cnt_L) {
        cout<<0<<endl;
        return 0;
    }
    if(s[0]=='W' || s.back()=='W') {
        cout<<0<<endl;
        return 0;
    }
    cnt_R=0,cnt_L=0;
    ll ans=1;
    for (int i = 0; i < 2*n; i++)
    {
        if(d[i]==0){
            ans*=cnt_L-cnt_R;
            ans%=MOD;
            cnt_R++;
        }
        if(d[i]==1) cnt_L++;
    }
    ll k=1;
    for (int i = 1; i <= n; i++)
    {
        k*=i;
        k%=MOD;
    }
    cout<<(ans*k)%MOD<<endl;

    return 0;
}

Measured memory_bytes: 2680
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

r, g, b = MAP()

if int(str(g)+str(b))%4 == 0:
	print("YES")
else:
	print("NO")


Measured memory_bytes: 5204
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r, D;
		r = sc.nextInt();
		D = sc.nextInt();
		int x[] = new int[11];
		x[0]=sc.nextInt();
		sc.close();

		for (int i = 0; i < 10; i++) {
			x[i+1]= r * x[i] - D;
			System.out.println(x[i+1]);
		}
	}
}


Measured memory_bytes: 21840
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define all(x)              (x).begin(), (x).end()
#define inf                 1e18

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>;

void solve() {
	ll a, b;
	cin >> a >> b;
	cout << a * b;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	ifstream cin("input.txt");
//	ofstream cout("output.txt");
	int q = 1; // cin >> q;
	while (q--) {
		solve();
	}
}

Measured memory_bytes: 3660
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;

int main(){
    ll n, k, q;
    cin >> n >> k >> q;
    llv r(n);
    // r.assign(0, r.size());
    rep(i,q){
        ll p;
        cin >> p;
        r[p-1]++;
    }
    rep(i,n){
        if((k - q) + r[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
vector<int> A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,1<<N) cin>>x, A.push_back(x);
	while(A.size()>1) {
		B.clear();
		for(i=0;i<A.size();i+=2) {
			x=A[i];
			y=A[i+1];
			if(x!=y) B.push_back(abs(x-y));
			else B.push_back(abs(y));
		}
		
		swap(A,B);
	}
	
	cout<<A[0]<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 2292
#include <iostream>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll fact[100001];
int main(){
  fact[0]=1LL;
  for(ll i=1;i<=100000;++i)
    fact[i]=(fact[i-1]*i)%mod;
  int n,m;
  cin >> n >> m;
  if(m>n) swap(n,m);
  if(n==m){
    cout << (2*fact[n]*fact[n])%mod << endl;
  }
  else if(n==m+1)
    cout << (fact[n]*fact[m])%mod << endl;
  else
    cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ld long double 
signed main() {
  cout << setprecision(20) << fixed ;
  int n ;
  cin >>n ;
  vector<ld>a(n) ;
  for(int i=0;i<n;i++) 
    cin >> a[i];
  vector<vector<ld>>dp(n+1,vector<ld>(n+1)) ;
  //dp[i][h]-> probability of having j heads after processing i coins
  dp[0][0]=1.00 ;
  for(int i=1;i<=n;i++)
    for(int j=0;j<=i;j++)
      dp[i][j]=(j>0?dp[i-1][j-1]*a[i-1]:0)+dp[i-1][j]*(1.00-a[i-1]) ;
  ld ans =0 ;
  for(int i=(n+1)/2;i<=n;i++)
    ans+=dp[n][i] ;
  cout << ans ;
}

Measured memory_bytes: 144268
n, l = map(int, input().split())

taste = [0] * n
for i in range(n):
    taste[i] = l + i

if taste[0] > 0:
    ans = sum(taste) - taste[0]
elif taste[-1] < 0:
    ans = sum(taste) - taste[-1]
else:
    ans = sum(taste)

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int i,j,x;
	int t[3];
	
	scanf("%d %d %d",&t[0],&t[1],&t[2]);
	
	for(i=0;i<3;i++){
		for(j=0;j<2-i;j++){
			if(t[j]>t[j+1]){
				x=t[j+1];
				t[j+1]=t[j];
				t[j]=x;
			}
		}
	}
	printf("%d %d %d\n",t[0],t[1],t[2]);
	
	return(0);
}

Measured memory_bytes: 596
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long

const ll INF = 7+(1e+9);
typedef int Weight;
struct Edge {  //src:辺の始点,dst:辺の終点,weight:辺の重さ
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : //辺は重さが重いものを"小さい"と定義する
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

//引数 Graph:隣接リスト,r:最小全域木の始点
//戻値 total:最小全域木の重み,T:最小全域木の辺集合
void shortestPath(const Graph &g,vector<vector<Weight> > &dist,vector<vector<int> > &inter) {
  int n = g.size();
  dist.assign(n,vector<Weight>(n,INF));
  for(int i=0;i<n;i++){
    dist[i][i]=0;
  }
  for(int i=0;i<n;i++){
    for(auto f=g[i].begin();f!=g[i].end();f++){
      dist[i][f->dst]=f->weight;
    }
  }
  inter.assign(n, vector<int>(n,-1));
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if (dist[i][j] > dist[i][k] + dist[k][j]) {
          dist[i][j] = dist[i][k] + dist[k][j];
          inter[i][j] = k;
        }
      }
    }
  }
}
void buildPath(const vector<vector<int> > &inter,int s,int t,vector<int> &path) {
  int u = inter[s][t];
  if (u < 0) path.push_back(s);
  else buildPath(inter, s, u, path), buildPath(inter, u, s, path);
}
vector<int> buildPath(const vector<vector<int> > &inter,int s,int t) {
  vector<int> path;
  buildPath(inter, s, t, path);
  path.push_back(t);
  return path;
}


int main(){
  ll n;
  cin>>n;
  Graph g(n);
  ll u,k,v,w;
  for(ll i=0;i<n;i++){
    cin>>u>>k;
    for(ll j=0;j<k;j++){
      cin>>v>>w;
      g[u].push_back(Edge(u,v,w));
    }
  }
  vector<vector<Weight> >dist;
  vector<vector<int> > inter;
  shortestPath(g,dist,inter);
  for(ll i=0;i<n;i++){
    cout<<i<<" "<<dist[0][i]<<endl;
  }
}



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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            string[] str = Console.ReadLine().Split(' ');

            int count = 0;
            int[] a = new int[str.Length];
            for(int i = 0; i < str.Length; i++)
            {
                a[i] = int.Parse(str[i]);
                if (a[i] == count + 1) {count++;}
            }

            if(count == 0)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(a.Length - count);
            }
           


            //ここまで
        }
    }
}


Measured memory_bytes: 33116
#include<bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
int main(){
  double r;
  cin>>r;
  cout<<(2*M_PI*r)<<"\n";  
 
  
  return 0;
}

Measured memory_bytes: 3776
import java.util.*;

public class Main {
  static int[] p = new int[10];
  static int count = 0;
  static int[][] edge;
  static int N;
  static int M;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    N = sc.nextInt();
    M = sc.nextInt();
    edge = new int[N][N];
    for(int i = 0; i < M; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      edge[a - 1][b - 1] = 1;
      edge[b - 1][a - 1] = 1;
    }
  dfs(1, (1 << N) - 2);
  System.out.println(count);
  }
  public static void dfs(int pos, int mask) {
    if(pos == N) {
      int c = 0;
      for(int i = 0; i < N - 1; i++) {
        if(edge[p[i]][p[i + 1]] == 0) {
          c++;
          break;
        }
      }
        if(c == 0) count++;
      }
    for(int i = 0; i < N; i++) {
      if((mask & (1 << i)) != 0) {
        p[pos] = i;
        dfs(pos + 1, (mask ^ (1 << i)));
      }
    }
  }
}

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

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

using namespace std;

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;

  bool ok = false;
  rep(i, b) {
    if ((a * i % b) == c) {
      ok = true;
      break;
    }
  }

  std::cout << (ok ? "YES" : "NO") << std::endl;

  return 0;
}


Measured memory_bytes: 3568
#include<iostream>

using namespace std;

int main()
{
	int x;
	int a;
	int b;
	cin >> x;
	cin >> a;
	cin >> b;
	if (a-b >= 0)
		cout <<  "delicious" << endl;
	else if (a - b >= 0 - x)
		cout << "safe" << endl;
	else
		cout << "dangerous" << endl;
	return 0;
}

Measured memory_bytes: 256
N = input()
A,B =input().split()
P = input().split()
ansX = 0
ansY = 0
ansZ = 0
for i in range(int(N)):
    if int(P[i]) <= int(A):
        ansX = ansX+1
    elif int(P[i]) <= int(B):
        ansY = ansY+1
    else:
        ansZ = ansZ+1

ans = ansX
if ans >= ansY:
    ans = ansY
if ans >= ansZ:
    ans = ansZ
print(ans)


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

#define ll long long
#define pb push_back
#define fs first
#define se second
#define M 1000000007


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

bool check(int x,int y)
{
	return x>=0 && y>=0 && x<=2000 && y<=2000;
}
int fun()
{
	static int num = 16;
	return num--;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll ans=0;
	if(k>a)
	{
		k-=a;
		ans=a;
		if(k>=b)
		{
			k-=b;
			if(k>0)
			{
				ans-=k;
			}
		}
	}
	else
		ans=k;
	cout<<ans<<endl;

}



Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

void solve(){
    int n;
    ll x,ans=0,sub=0;
    cin>>n>>x;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    rep(i,n-1){
        if(a[i]+a[i+1]>x){
            sub=(a[i]+a[i+1])-x;
            ans+=sub;
            if(sub<=a[i+1])a[i+1]-=sub;
            else {
                a[i]-=sub-a[i+1];
                a[i+1]=0;
            }
        }
    }
    cout<<ans<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 1024
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,u,v = LI()
Graph = [[] for i in range(N+1)]

for i in range(N-1):
    a,b = LI()
    Graph[a].append(b)
    Graph[b].append(a)

from collections import deque

q1 = deque([u])
distance1 = [-1]*(N+1)  # uから各頂点への最短距離
distance1[u] = 0

# bfs

while q1:
    n = q1.pop()
    for d in Graph[n]:
        if distance1[d] != -1:
            continue
        else:
            distance1[d] = distance1[n]+1
            q1.appendleft(d)

q2 = deque([v])
distance2 = [-1]*(N+1)  # vから各頂点への最短距離
distance2[v] = 0

# bfs

while q2:
    n = q2.pop()
    for d in Graph[n]:
        if distance2[d] != -1:
            continue
        else:
            distance2[d] = distance2[n]+1
            q2.appendleft(d)

q3 = deque([u])
distance3 = [-1]*(N+1)  # uから各頂点への最短距離、ただし青木君に追いつかれない
distance3[u] = 0

# bfs

while q3:
    n = q3.pop()
    for d in Graph[n]:
        if distance3[d] != -1 or distance1[d] >= distance2[d]:
            continue
        else:
            distance3[d] = distance3[n]+1
            q3.appendleft(d)

# 青木君に追いつかれずに行ける頂点まで行き、うろうろする

ans = max(distance2[i]-1 for i in range(1,N+1) if distance3[i] >= 0)

print(ans)

Measured memory_bytes: 90216
def main():
    D, N = (int(i) for i in input().split())
    ans = {0: [i for i in range(1, 100)]}
    ans[0].append(101)
    ans[1] = [100*i for i in range(1, 100)]
    ans[1].append(10100)
    ans[2] = [10000*i for i in range(1, 100)]
    ans[2].append(1010000)
    print(ans[D][N-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include"bits/stdc++.h"
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20)
#define ll long long
#define endl '\n'
//       Author
//        ::
//    (  NOBODY  )
//   No Copyright .....You can copy and paste it without my permission...................................
// !!!!!!!!!!!!!!!
#define pb push_back
#define N 300009
int a[N],b[N];
int dp[100009];
int main()
{
    FAST_IO;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=2;i<=n;i++)
    {
      dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
      if(i>2)dp[i]=min(dp[i],dp[i-2]+abs(a[i-2]-a[i]));
    }
    cout<<dp[n];
    return 0;
}


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

int main() {
	
	int n;
	cin >> n;
	vector<char> s(n);
	rep(i, n) cin >> s[i];
	bool is_four = false;
	rep(i, n){
		if(s[i] == 'Y') is_four = true;
	}
	if(is_four) puts("Four");
	else puts("Three");
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[6];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<=999;i+=111){
		if(a<=i){
			printf("%d\n",i);return 0;
		}
	}
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int N; cin>>N;
    cout<<(1000-N%1000)%1000<<endl;
}

Measured memory_bytes: 3504
# include <iostream>
# include <cstdio>
# include <algorithm>
using namespace std;
const int N = 2e5 + 12;
int n,a[N];
int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)scanf("%d",&a[i]);
	int mx = -1,id = -1,mi = 0x3f3f3f3f,Id = -1;
	for(int i = 1;i <= n;i++)if(a[i] > mx)mx = a[i],id = i;
	for(int i = 1;i <= n;i++)if(i != id)
	{
	 if(mx & 1)
	 {
	 	if(a[i] > mx / 2 && a[i] - mx / 2 - 1 < mi)mi = a[i] - mx / 2 - 1,Id = i;
	 	else if(a[i] <= mx / 2 && mx / 2 - a[i] < mi)mi = mx / 2 - a[i],Id = i;
	 }
	 else if(abs(a[i] - mx / 2) < mi)mi = abs(a[i] - mx / 2),Id = i;
	}
	printf("%d %d\n",a[id],a[Id]);
}

Measured memory_bytes: 768
S = str(input())
T = str(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

if T[:-1] == S:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9088
#include <stdio.h>
#include <string.h>
int strjdg(char data[],int len);
int main()
{
    int n=0,len;
    char str[100];
    while(scanf("%s",str)!=EOF){
        len = strlen(str)-1;
        n += strjdg(str,len);
    }
    printf("%d\n",n);
    return 0;
}

int strjdg(char data[],int len){
    int i=0,result=1;
    while(1){
        if(data[i]!=data[len]){
            result = 0;
            break;
        }
        if(i==len||i-1==len){
            break;
        }else{
            i++;
            len--;
        }
    }
    return result;
}

Measured memory_bytes: 540
#!/usr/bin/env python3
import collections

table = collections.defaultdict(dict)
table[1][3] = '''
aa.
..b
..b
'''.strip().splitlines()
table[2][3] = '''
aab
d.b
dcc
'''.strip().splitlines()
table[3][4] = '''
aadc
bbdc
ghff
ghee
'''.strip().splitlines()
table[3][5] = '''
abb.d
a.ccd
eefgg
hif..
hi.jj
'''.strip().splitlines()
table[3][7] = '''
a.cc.dd
abb..e.
..mm.ef
l...n.f
lk..n..
.k..hhg
jj.ii.g
'''.strip().splitlines()

def solve1(n, q):
    dp = [None] * (n + 1)
    dp[0] = 0
    for i in range(n + 1):
        for delta in table[q].keys():
            if i - delta >= 0 and dp[i - delta] is not None:
                dp[i] = delta
    if dp[n] is None:
        return None
    f = [['.' for _ in range(n)] for _ in range(n)]
    k = n
    while k:
        delta = dp[k]
        k -= delta
        for y in range(delta):
            for x in range(delta):
                f[k + y][k + x] = table[q][delta][y][x]
    return [''.join(line) for line in f]

def solve(n):
    return solve1(n, 1) or solve1(n, 2) or solve1(n, 3)

def main():
    n = int(input())
    f = solve(n)
    if f:
        for line in f:
            print(line)
    else:
        print(-1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 14188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;
ll i;



int main(){
    ll N,A;
    cin>>N>>A;
    if(N%500<=A)cout<<"Yes";
    else cout<<"No";
    cout<<endl;
}


Measured memory_bytes: 256
while True:
  n,x=list(map(int,input().split()))
  ans=0
  if n == 0 and x == 0:
    break
  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:
          ans += 1
  print(ans)


Measured memory_bytes: 5596
# -*- coding: utf-8 -*-
import itertools


def find_combination(a):
    for indices in itertools.product(range(2), repeat=3):
        count = a[0]
        for i in range(3):
            if indices[i] == 0:
                count += a[i+1]
            else:
                count -= a[i+1]
            if count == 7:
                return indices
    return None


if __name__ == '__main__':
    a = [int(i) for i in input()]
    indices = find_combination(a)
    result = str(a[0])
    for i in range(3):
        if indices[i] == 0:
            result += '+'
        else:
            result += '-'
        result += str(a[i+1])
    print(result + '=7')


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

using namespace std;

using ll = long long;
using ld = long double;

int main(){
  const double pi = acos(-1);
  long double a,b,h,m;
  cin >> a >> b >> h >> m;
  
  long double x;
  x =a*a + b*b - 2*a*b*cos(2*pi - abs( h*(2*pi/12)+ (long double)m*2*pi/60/12 - (long double)m*pi/30 ));
  x = sqrtl(x);
  
  cout << setprecision(11) << x << endl;
}


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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using namespace std; 

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";} 
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    
    irep(i, n) {
        string t = s.substr(i);
        irep(j, t.size()+1) {
            string u = t.substr(0, j);
            bool ok = true;
            irep(k, u.size()) {
                if(u[k] != 'A' && u[k] != 'C' && u[k] != 'G' && u[k] != 'T') {
                    ok = false;
                } 
            }
            if(ok) { chmax(ans, (int)u.size()); }
        }
    }

    cout << ans << endl;

    return 0;
}

/*atcoder*/


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

ll sum(ll n) {
if(n==0) {
return 0;
}
  
  ll s=n+sum(n-1);
  return s;
}
 
int main() {
  ll N;
  cin>>N;
  cout<<sum(N)<<endl;
}

Measured memory_bytes: 3560
N=int(input())
*A,=map(int, input().split())
A=[0]+A+[0]
sm=sum([abs(A[i+1] - A[i]) for i in range(N+1)])
B=[abs(A[i+1] - A[i-1]) - abs(A[i+1] - A[i]) - abs(A[i] - A[i-1]) for i in range(1,N+1)]
for b in B: print(sm+b)


Measured memory_bytes: 63596
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long a, b, c;
    cin >> a >> b >> c;
    long double d = 2.0 * (sqrtl((long double)(a * b)));
    cout << ((long double)(c - a - b) > d ? "Yes" : "No") << endl;
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()


using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> L(N);
	REP(i, N) cin >> L[i];

	sort(L.rbegin(), L.rend());

	if (L[0] < accumulate(L.begin() + 1, L.end(), 0))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            // おかね
            int N = Convert.ToInt32(Console.ReadLine());

            while (true)
            {
                if (N > 1000)
                    N = N - 1000;
                else if (N <= 1000)
                {
                    Console.WriteLine(1000 - N);
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 27444
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define int long long
signed main() {
	int n, t; cin >> n >> t;
	int k = 0, m = 10000000000, p = 0;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		if (i) {
			if (a - m == p)k++;
			else if (a - m > p) {
				p = a - m;
				k = 1;
			}
		}
		m = min(a, m);
	}
	cout << k << endl;
}

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

int N;
vector<int> goal;
vector<int> L;
vector<int>ans;
//pair(総本数,総長さ)
vector<pair<int,int>> G(4,make_pair(0,0));
void check(int i){
	if(i!=N){
		for(int j=0;j<4;j++){
			G[j].first++;
			G[j].second+=L[i];
			check(i+1);
			G[j].first--;
			G[j].second-=L[i];
		}
	}
	else{
		int T=0;
		for(int i=0;i<3;i++){
			if(G[i].first==0){T=-1; break;}
			else{
				T+=abs(goal[i]-G[i].second)+10*(G[i].first-1);
			}
		}
		if(T>=0)ans.push_back(T);
	}

}

signed main(){
	cin>>N;
	goal.assign(3,0);
	for(int i=0;i<3;i++)cin>>goal[i];
	L.assign(N,0);
	for(int i=0;i<N;i++)cin>>L[i];
	check(0);
	sort(ans.begin(),ans.end());
	cout<<ans[0]<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

  ll a, b;
  cin >> a >> b;
  ll c = a ^ b, d = (a - 1) ^ b, a4 = a % 4, b4 = b % 4;
  if(a % 2){
    if(b4 == a4) cout << a << endl;
    if(b4 == (a4 + 1) % 4) cout << c << endl;
    if(b4 == (a4 + 2) % 4) cout << a - 1 << endl;
    if(b4 == (a4 + 3) % 4) cout << d << endl;
    return 0;
  }
  else{
    if(b4 == a4) cout << b << endl;
    if(b4 == (a4 + 1) % 4) cout << 1 << endl;
    if(b4 == (a4 + 2) % 4) cout << b + 1 << endl;
    if(b4 == (a4 + 3) % 4) cout << 0 << endl;
    return 0;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);
		String s = stdin.next();
		char[] c;
		c = s.toCharArray();
		c[3]='8';
		System.out.println(c);


	}

}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

const std::string MARCH = "MARCH";
int N;
std::string S;
int cnt[30];

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> S;

        cnt[S[0] - 'A'] += 1;
    }

    ll c = 0;
    for(int i=0;i<5;++i){
        for(int j=i+1;j<5;++j){
            for(int k=j+1;k<5;++k){
                c += 1ll * cnt[MARCH[i] - 'A'] * cnt[MARCH[j] - 'A'] * cnt[MARCH[k] - 'A'];
            }
        }
    }

    std::cout << c << std::endl;
}


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


if a <= b:
  while min > abs(a-b):
    min = abs(a-b)
    a   =abs(a-b)
else :
  a = a%b
  while min > abs(a-b):
    min = abs(a-b)
    a   = abs(a-b)
  
print(min)    

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

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

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/

int C[1<<20], N, ai, bi;
vector<int> g[1<<20];

ll dp[1<<20];
ll ans[1<<20];

ll possible(ll x) {
  return x*(x+1)/2;
}


int dfs(int s, int p) {
  int num_nodes = 1, sub_nodes;

  for(auto node:g[s]) {
    if(node != p) {
      int temp = dp[C[s]];
      dp[C[s]] = 0;
      sub_nodes = dfs(node, s);
      num_nodes += sub_nodes;
      ans[C[s]] += possible(sub_nodes - dp[C[s]]);
      dp[C[s]] = temp;
    }
  }
  dp[C[s]] += num_nodes;

  return num_nodes;
}



int main() {

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

  cin >> N;
  rep(i, N) {
    cin >> C[i];
    C[i]--;
  }
  rep(i, N-1) {
    cin>>ai>>bi;
    ai--;bi--;
    g[ai].pb(bi);g[bi].pb(ai);
  }

  dfs(0, -1);
  rep(i, N) {
    cout << possible(N) - ans[i] - possible(N-dp[i]) << endl;
  }
  // rep(i, N) {
  //   debug(dp[i]);
  // }
  // rep(i, N) {
  //   debug(ans[i]);
  // }

  return 0;
}


Measured memory_bytes: 53768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef unsigned long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
    int n,m;
    string s,t;
    cin >> n >> m;
     s="";t="";
    rep(i,n) s+=to_string(m);
    rep(i,m) t+=to_string(n);
    if (s <= t) cout << s << endl;
    else cout << t << endl;
    
    return 0;
}


Measured memory_bytes: 256
# B問題
A = input()
B = input()
C = input()
flag = False
tmp = A[0]
A  = A[1:]
while True:
    if tmp == 'a':
        if len(A) == 0:
            flag = 'A'
            break
        tmp = A[0]
        A = A[1:]
        continue
    elif tmp == 'b':
        if len(B) == 0:
            flag = 'B'
            break
        tmp = B[0]
        B = B[1:]
        continue
    elif tmp == 'c':
        if len(C) == 0:
            flag = 'C'
            break
        tmp = C[0]
        C = C[1:]
        continue        
print(flag)        

Measured memory_bytes: 3064
/*
* @Author: 王文宇
* @Date:   2017-11-18 16:12:33
* @Last Modified by:   王文宇
* @Last Modified time: 2017-11-18 16:14:18
*/
#include <iostream>
using namespace std;
int main()
{
	char a,b;
	cin>>a>>b;
	int a1 = a - '0';
	int b1 = b - '0';
	if(a1<b1)cout<<"<"<<endl;
	if(a1>b1)cout<<">"<<endl;
	if(a1==b1)cout<<"="<<endl;
	return 0; 
}

Measured memory_bytes: 256
import sys
from collections import deque


def IN_I(): return int(sys.stdin.readline().rstrip())
def IN_LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def IN_S(): return sys.stdin.readline().rstrip()
def IN_LS(): return list(sys.stdin.readline().rstrip().split())


N = IN_I()
S = IN_S()
d = deque(S)

l = 0
for i in range(N):
    if S[i] == '(':
        l += 1
    else:
        if l == 0:
            d.appendleft('(')
        else:
            l -= 1

r = 0
for i in range(N - 1, -1, -1):
    if S[i] == ')':
        r += 1
    else:
        if r == 0:
            d.append(')')
        else:
            r -= 1
print(''.join(d))


Measured memory_bytes: 9460
#include<bits/stdc++.h>
#define    ll          unsigned long long int
#define    sz          200010
#define    md          1000000007
#define    py          printf("Yes\n")
#define    pn          printf("No\n")
#define    sc1(a)      scanf("%lld",&a)
#define    sc2(a,b)    scanf("%lld %lld",&a,&b)
#define    pv(a)      printf("%lld\n",a)

using namespace std;


ll num[sz];
ll ax[sz];
ll bx[sz];


int main()
{

    ll n,i,j,k,p,d,x=0;

    cin>>n;

    for(i=1;i<=n;i++)
    {
        cin>>num[i];
    }

    for(i=1;i<=n;i++)cin>>ax[i];

    for(i=1;i<n;i++)cin>>bx[i];

    for(i=1;i<=n;i++)
    {
        x+=ax[num[i]];
        if((num[i]-1)==(num[i-1]))x+=bx[num[i-1]];
    }

    cout<<x<<endl;

    return 0;
}


Measured memory_bytes: 2304
X = int(input())

MAGIC_NUMBER = 2

prime = [True] * (X * MAGIC_NUMBER + 1)
prime[0] = False
prime[1] = False

for p in range(2, X + 1):
    if not prime[p]: continue
    p_tmp = p
    while True:
        p_tmp += p
        if p_tmp >= len(prime): break
        prime[p_tmp] = False

# print("#", prime)
for ans in range(X, X * MAGIC_NUMBER + 1):
    if prime[ans]: break

print(ans)

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

using namespace std;

using int64 = long long;
const int mod = (int) (1e9 + 7);

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  int N;
  cin >> N;
  auto mat = make_v< int >(N, N);

  auto rec = MFP([&](auto rec, vector< int > p, int level) -> void {
    vector< int > latte, malta;
    while(p.size() >= 1) {
      latte.emplace_back(p.back());
      p.pop_back();
      if(p.size() >= 1) {
        malta.emplace_back(p.back());
        p.pop_back();
      }
    }
    if(latte.size() > 1) rec(latte, level + 1);
    if(malta.size() > 1) rec(malta, level + 1);
    for(int i : latte) for(int j : malta) mat[i][j] = mat[j][i] = level;
  });
  vector< int > p(N);
  iota(begin(p), end(p), 0);
  rec(p, 1);
  for(int i = 0; i + 1 < N; i++) {
    for(int j = i + 1; j < N; j++) {
      cout << mat[i][j] << " ";
    }
    cout << endl;
  }

}




Measured memory_bytes: 1536
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define ll long long
using namespace std;
int lcm(ll m,ll n)
{
	ll r,s,t;
	ll k=m;
	ll p=n;
	if(m<n)
	{
		t=m;m=n;n=t;
	}
	while(r=m%n,r!=0)
	{
		m=n;n=r;
	}
	return (k/n)*(p/n)*n;
}
int main()
{
	ll n;
	scanf("%lld",&n);
	ll k=lcm(2,n);
	printf("%lld\n",k);
	return 0;
}

Measured memory_bytes: 256
x,y=map(int,input().split())
def money(a):
    if a==1:
        return 300000
    elif a==2:
        return 200000
    elif a==3:
        return 100000
    else:
        return 0

ans=money(x)+money(y)
if ans==600000:
    print(1000000)
else:
    print(ans)


Measured memory_bytes: 2940
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

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


	int N = getint(), K = getint();

	ll s[100001], sa[100001];
	s[0] = 0;
	sa[0] = 0;
	rep1(i, N) {
		int a = getint();
		s[i] = s[i - 1] + a;
		sa[i] = sa[i - 1] + max(a, 0);
	}

	ll kotae = 0;
	for (int i = 1; i <= N - K + 1; i++) {
		ll kari = max(s[i + K - 1] - s[i - 1], 0ll) + sa[i - 1] + sa[N] - sa[i + K - 1];
		kotae = max(kotae, kari);
	}
	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

string a;
int ans;

int main(){
	cin>>a;
	int n=a.length();
	for(int i=0;i<n;i++){
		for(int j=1;j<(n/2);j++){
			int l1=i,l2=i+j;
			int r1=i+j,r2=n;
			if(l2+j>n)break;
			bool f=true;
			while(l1<r1&&l2<r2)
				if(a[l1]!=a[l2]){f=false;break;}
				else l1++,l2++;
			if(f==true)ans=max(2*j,ans);
		}
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 256