akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  int n,a;
  cin>>n>>a;
  string ans="No";
  if(n%500<=a)ans="Yes";
  cout(ans);
  return 0;
}

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

typedef long long ll;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

ll a[200005];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        if (i > 0)
            a[i] += a[i - 1];
    }
    ll ans = LL_INF;
    for (int i = 0; i < n - 1; i++) {
        if (abs(a[n - 1] - 2 * a[i]) < ans)
            ans = abs(a[n - 1] - 2 * a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
from math import factorial
N=int(input())
K=int(input())
S=list(map(int,str(N)))

def C(n,r):
  if n>=r:
    return factorial(n)//factorial(r)//factorial(n-r)
  else:
    return 0

def D(i,j):
  return C(i,j)*(9**j)

ans=0
l=len(S)
for i in range(l):
  if S[i]!=0:
    ans+=(S[i]-1)*D(l-1,K-1)+D(l-1,K)
    l-=1
    K-=1
  else:
    l-=1
  if K==0:
    ans+=1
    break
    
print(ans)

Measured memory_bytes: 3064
import sys
from fractions import gcd

N=input()
A=map(int, sys.stdin.readline().split())

L=[]
R=[]

for i,a in enumerate(A):
    if i==0:
        L.append(a)
    else:
        L.append( gcd(L[-1],a) )

for i,a in enumerate(A[::-1]):
    if i==0:
        R.append(a)
    else:
        R.append( gcd(R[-1],a) )
R=R[::-1]

ans=float("-inf")
for i in range(N):
    if i==0:
        ans=max(ans,R[i+1])
    elif i==N-1:
        ans=max(ans,L[i-1])
    else:
        ans=max( ans,gcd(L[i-1],R[i+1]) )

print ans


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

int main(){
    int N, D;
    cin >> N >> D;
    vector<int> X(N);
    vector<int> Y(N);
    int i;

    for(i=0; i<N; i++){
        cin >> X.at(i) >> Y.at(i);
    }

    int ans = 0;
    for(i=0;i<N;i++){
        if(pow(D, 2) >= (pow(X.at(i), 2)+pow(Y.at(i), 2))){
            ans += 1;
        }
    }

    cout << ans << endl;
}

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

int n;
std::vector<std::pair<long long, int>> a;
bool possible(const int);
bool adjust(std::vector<std::pair<long long, int>>&, const int);

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		long long tmp;
		scanf("%lld", &tmp);
		if (!i || a.back().first != tmp)
			a.push_back({tmp, 1});
		else
			a.back().second++;
	}

	int left{0}, right{n};
	while (left + 1 < right)
	{
		int mid{(left + right) / 2};
		if (possible(mid)) right = mid;
		else left = mid;
	}
	printf("%d\n", right);

	return 0;
}

bool possible(const int type)
{
	long long pre_length{};
	std::vector<std::pair<long long, int>> s;
	for (auto& e: a)
	{
		if (pre_length < e.first)
			s.push_back({e.first - pre_length, e.second - 1});
		else
		{
			if (!adjust(s, type)) return false;
			while (pre_length - s.back().first >= e.first)
			{
				pre_length -= s.back().first;
				s.pop_back();
			}
			if (pre_length == e.first)
				s.back().second += e.second;
			else
			{
				for (long long i{}; i < pre_length - e.first && s.back().second; i++)
					s.back().second /= type;
				s.back().first -= pre_length - e.first;
				s.back().second += e.second;
			}
		}
		pre_length = e.first;
	}
	return adjust(s, type);
}

bool adjust(std::vector<std::pair<long long, int>>& s, const int type)
{
	for (auto i{s.end() - 1}; i != s.begin(); i--)
	{
		long long tmp{1};
		for (int j{}; tmp <= i->second && j < i->first; j++)
			tmp *= type;
		if (i->second < tmp) continue;
		(i - 1)->second += i->second / tmp;
		i->second %= tmp;
	}
	long long tmp{1};
	for (int i{}; tmp <= s.front().second && i < s.front().first; i++)
		tmp *= type;
	if (s.front().second < tmp) return true;
	return false;
}

Measured memory_bytes: 12012
r,g,b,n = [int(i) for i in input().split()]
ans = 0
 
for i in range(0,n+1,r):
    for j in range(0,n+1,g):
        total = i + j
        if n - total < 0:
            break
        elif (n - total) % b == 0:
            ans += 1
 
print(ans)

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

int main()
{
    ll A,B,C,X,Y;

    cin >> A >> B >> C >> X >> Y;
    ll minResult;
    if(A+B > C+C)
    {
        ll minval = min(X,Y);
        ll maxval = max(X,Y);
        if(X < Y)
        {
            minResult = (C+C) * minval + B * (Y - X);
        }else{
            minResult = (C+C) * minval + A * (X - Y);
        }
        for(ll i = min(X,Y); i <= max(X,Y); ++i)
        {
            if(X < Y)
            {
                minResult = min(minResult,(C+C) * i  + B * (Y - i));
            }else
            {
                minResult = min(minResult,(C+C)*i + A * (X - i));
            }
            
        }
        cout << minResult << endl;
    }else{
        cout <<  A * X + B * Y << endl;
    }


	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define REP(i,a,b) for(ll i = a; i < b; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define bins(v, x) binary_search(v.begin(), v.end(), x)
#define pi 2*acos(0.0)
const int INF = 1e7;
const int mod = 1e9 + 7;

ll modExp(ll base, ll exp, ll mod) {
   ll res = 1;
   while (exp > 0) {
    	if (exp % 2 == 1) {
        	res= (res * base) % mod;
		}
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}

ll nCr(ll n,ll k){
   ll C[n + 1][k + 1];

   REP(i,0,n+1){
      REP(j,0,min(i,k)+1) {
         if(j==0 || j==i) {
            C[i][j] = 1;
         } else {
            C[i][j] = C[i-1][j-1] + C[i-1][j];
         }
      }
   }
   return C[n][k];
}

int main(){
   faster;
   //freopen("input.txt","r",stdin);
	 //freopen("output.txt","w",stdout);

   ll a, b, c, k;
   cin >> a >> b >> c >> k;

   if(k <= a) p1(k);
   else if(k > a && k <= a + b) p1(a);
   else if(k > a + b && k <= a + b + c) p1(a + (k-a-b) * (-1));
}


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

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

    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i, n) {
        cin >> v[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(v[i] >= k)
            ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3708
#include <iostream>
#include <vector>
#include <cassert>

inline unsigned long long rot90(unsigned long long x) {
  return (x << 16) | (x >> 48);
}

inline bool same180(unsigned long long x) {
  return (x >> 32) == ((x << 32) >> 32);
}

inline bool same90(unsigned long long x) {
  return (x >> 48) == ((x << 48) >> 48);
}

inline void multi(unsigned long long side, long& cnt) {
  if (same180(side)) {
    cnt *= 2;
    if (same90(side)) {
      cnt *= 2;
    }
  }
}

inline unsigned long long get_min(unsigned long long a,
                                  unsigned long long b,
                                  unsigned long long c,
                                  unsigned long long d) {
  assert(a < (1 << 16));
  assert(b < (1 << 16));
  assert(c < (1 << 16));
  assert(d < (1 << 16));
  return std::min(
      {
          (a << 48) | (b << 32) | (c << 16) | d,
          (b << 48) | (c << 32) | (d << 16) | a,
          (c << 48) | (d << 32) | (a << 16) | b,
          (d << 48) | (a << 32) | (b << 16) | c
      }
  );
}

inline unsigned long long get0(unsigned long long x) { return x >> 48; }
inline unsigned long long get1(unsigned long long x) { return (x << 16) >> 48; }
inline unsigned long long get2(unsigned long long x) { return (x << 32) >> 48; }
inline unsigned long long get3(unsigned long long x) { return (x << 48) >> 48; }

int main() {
  unsigned N;
  std::cin >> N;
  std::vector<unsigned long long> tile(N);
  for (unsigned i = 0; i < N; ++i) {
    unsigned long long a, b, c, d;
    std::cin >> a >> b >> c >> d;
    tile[i] = get_min(a, b, c, d);
  }
  std::sort(tile.begin(), tile.end());
  unsigned long long ans = 0ull;
  for (auto p0 = tile.begin(); p0 < tile.end(); ++p0) {
    for (auto p1 = p0 + 1; p1 < tile.end(); ++p1) {
      //0
      unsigned long long x = *p0;
      unsigned long long y = *p1;
      unsigned long long a, b, c, d;
      auto yy = y;
      for (unsigned k = 0; k < 4; ++k) {
        a = get_min(get1(x), get0(x), get1(y), get0(y));
        b = get_min(get2(x), get1(x), get0(y), get3(y));
        c = get_min(get3(x), get2(x), get3(y), get2(y));
        d = get_min(get0(x), get3(x), get2(y), get1(y));
        auto s = std::upper_bound(p0 + 1, tile.end(), a) - std::lower_bound(p0 + 1, tile.end(), a);
        auto t = std::upper_bound(p0 + 1, tile.end(), b) - std::lower_bound(p0 + 1, tile.end(), b);
        auto q = std::upper_bound(p0 + 1, tile.end(), c) - std::lower_bound(p0 + 1, tile.end(), c);
        auto r = std::upper_bound(p0 + 1, tile.end(), d) - std::lower_bound(p0 + 1, tile.end(), d);
        if (yy == a) { --s; };
        if (yy == b) { --t; };
        if (a == b) { --t; };
        if (yy == c) { --q; };
        if (a == c) { --q; };
        if (b == c) { --q; };
        if (yy == d) { --r; };
        if (a == d) { --r; };
        if (b == d) { --r; };
        if (c == d) { --r; };
        multi(a, s);
        multi(b, t);
        multi(c, q);
        multi(d, r);
        ans += s * t * q * r;
        y = rot90(y);
      }
    }
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i <= (b); ++i)
#define drep(i,a,b) for (int i = (a); i >= (b); --i)
#define grep(i,u) for (int i = head[u],v = e[i].v; i; v = e[i = e[i].nxt].v)
#define il inline
#define LL long long
#define ULL unsigned LL
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
il LL read() {
	LL res = 0,f = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') f = -f; ch = getchar();}
	while (isdigit(ch)) {res = res*10+ch-'0'; ch = getchar();} return res*f;
}
namespace qiqi {
	const int N = 1e4+5; int n,m,k; char s[N]; 
	void main() {
		n = read(); m = n<<1; k = read(); int x = 0,y; while ((1<<x) < n) ++x; k = min(k,x); scanf("%s",s+1); rep(i,1,n) s[m-i+1] = s[i];
		x = 1; while (x <= n) {int i = y = x,j = x+1; while (j <= m && s[i] <= s[j]) i = s[i] < s[j++] ? x : i+1; while (x <= i) x += j-i;}
		rep(i,1,n) s[i] = s[i+y-1]; s[n+1] = x = 0; rep(i,1,n) {++x; if (s[i] != s[i+1]) break;} y = min(x<<(k-1),n); drep(i,n,y+1) s[i] = s[i-y+x]; rep(i,1,y) s[i] = s[1]; puts(s+1);
	}
}
int main() {
	qiqi::main(); return 0;
}

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

typedef long long ll;

template<typename T>
inline T Read(){
    T s = 0, f = 1; char ch = getchar();
    while(!isdigit(ch)) {if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) {s = (s << 3) + (s << 1) + ch - '0'; ch = getchar();}
    return s * f;
}

#define read() Read<int>()
#define readl() Read<long long>()

void solve() {
	int n = read();
	printf("%d\n", n ^ 1);
}

int main()
{
	int T = 1;
	//T = read();
	for(int i = 1; i <= T; ++i) {
		solve();
	}

	return 0;
}


Measured memory_bytes: 3748
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//正しい
		String s = sc.nextLine();
		//間違い
		String t = sc.nextLine();

		//カウント
		int count = 0;

		//文字の長さを繰り返す
		for(int i= 0;i < s.length();i++) {
			//s,tの判定処理
			if(s.substring(i,i+1).equals(t.substring(i,i+1))){



			}
			//s,tの入力が違う場合
			else {
				count++;
			}
		}
		System.out.println(count);
		sc.close();


	}

}


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

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

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

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

int main()
{
    ll R, D, X;
    cin >> R >> D >> X;
    REP(i, 10)
    {
        X = R * X - D;
        cout << X << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 101
#define WHITE 0
#define GRAY 1

static const int INFTY = (1<<21);

main(){
  int n,M[N][N];
  int i,j,e,sum;
  int u,minv;
  int d[N],p[N],color[N];
  
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j]=(e==-1)?INFTY:e;
    }
  }
  
  for(i=0;i<n;i++){
    d[i]=INFTY;
    if(i==0){
      d[i]=WHITE;
    }
    p[i]=-1;
    color[i]=WHITE;
  }
    
  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]==0){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1){
      break;
    }   else {
      color[u]=GRAY;
      for(j=0;j<n;j++){
	if(d[j]>M[u][j] && color[j]==0){
	  p[j]=u;
	  d[j]=M[u][j];
	}
      }
    }
  }
  sum=0;
  for(i=0;i<n;i++){
      if(p[i]!=-1) sum += M[i][p[i]];
    }

printf("%d\n",sum);
return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>

using namespace std;

int main()
{
  int nitems, noperations;
  cin >> nitems >> noperations;
  vector<long long> item(nitems);
  for (int i = 0; i < nitems; i++) {
    cin >> item.at(i);
  }
  long long result = 0;
  for (int r = 0; r <= min(nitems, noperations); r++) {
    for (int l = 0; l + r <= min(nitems, noperations); l++) {
      int ret = noperations - l - r;
      map<int, int> m;
      for (int i = 0; i < l; i++) {
        m[item.at(i)]++;
      }
      for (int i = 0; i < r; i++) {
        m[item.at(item.size()-1-i)]++;
      }
      for (int i = 0; !m.empty() && i < ret; i++) {
        auto it = m.begin();
        if (it->first > 0) {
          break;
        }
        it->second--;
        if (it->second == 0) {
          m.erase(it);
        }
      }
      long long sum = 0;
      for (const auto& p : m) {
        sum += p.first * p.second;
      }
      result = max(result, sum);
    }
  }
  cout << result << '\n';
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MAX = 10000;
const int INFTY = (int)1 << 29;
class Edge {
public :
	int st, trm, wght;
	Edge(int st=0, int trm=0, int wght=0) :st(st), trm(trm), wght(wght) {}
	bool operator < (const Edge &e)const {
		return wght < e.wght;
	}
};


class disjointset {
public:
	vector<int> rank, p;
	disjointset(int size) {
		rank.resize(size, 0);
		p.resize(size, 0);
		for (int i = 0; i < size; i++) {
			makeset(i);
		}
	}
	void makeset(int x) {
		p[x] = x;
		rank[x] = 0;
	}
	bool same(int x, int y) {
		return findset(x) == findset(y);
	}
	void unite(int x, int y) {
		link(findset(x), findset(y));
	}
	void link(int x, int y) {
		if (rank[x] < rank[y]) {
			p[x] = y;
		}
		else {
			p[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
	}
	int findset(int x) {
		if (x != p[x]) {
			p[x] = findset(p[x]);
			return p[x];
		}
		else {
			return p[x];
		}
	}
};
int kruskal(int N, vector<Edge> edges) {
	sort(edges.begin(), edges.end());
	int minc = 0;
	disjointset ds = disjointset(N);
	for (int i = 0; i < edges.size(); i++) {
		Edge e = edges[i];
		if (not ds.same(e.st, e.trm)) {
			ds.unite(e.st, e.trm);
			minc += e.wght;
		}
	}
	return minc;
}

int main() {
	int N, M;
	int strt, trmnl, wght;
	vector<Edge> edges;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> strt >> trmnl >> wght;
		edges.push_back(Edge(strt, trmnl, wght));
	}
	cout << kruskal(N, edges) << endl;
}

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

using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))
#define PB push_back

typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<int> > vvint;
typedef vector<vector<long long> > vvll;
typedef long long ll;
const ll MOD = 1000000007LL;
int n;
vvint vv;
ll dp[210][210][210];
vvll v;
vint sz;
void add(ll &a, ll b) {
	(a += b) %= MOD;
}

void dfs(int x, int pre) {
	for(int y : vv[x]) {
		if(y == pre) continue;
		dfs(y, x);
	}
	if(pre != -1 && vv[x].size() == 1) {
		v[x][1] = 1;
		sz[x] = 1;
		return;
	}
	bool vis = true;
	reep(i, 0, vv[x].size()) {
		int y = vv[x][i];
		if(y == pre) continue;
		if(vis) {
			vis = false;
			v[x] = v[y];
			sz[x] = sz[y];
			continue;
		}
		vll tmp(n + 2);
		reep(j, 1, sz[x] + 1) {
			reep(k, 1, sz[y] + 1) {
				reep(l, 1, sz[x] + sz[y] + 1) {
					add(tmp[l], v[x][j]*v[y][k] % MOD * dp[j][k][l] % MOD);
				}
			}
		}
		v[x] = tmp;
		sz[x] += sz[y];
	}
	for(int i = n; i >= 0; i--) {
		v[x][i + 1] = v[x][i];
	}
	sz[x]++;
}

void mainmain() {
	cin >> n;
	n++;
	vv = vvint(n);
	vint root(n);
	rep(i, n - 2) {
		int a, b;
		cin >> a >> b;
		vv[a].PB(b);
		vv[b].PB(a);
		root[b] = 1;
	}
	rep(i, n - 1) {
		if(!root[i]) {
			vv[n - 1].PB(i);
			vv[i].PB(n - 1);
		}
	}
	dp[0][0][0] = 1LL;
	rep(i, n) {
		rep(j, n) {
			rep(k, n) {
				if(i && k)    add(dp[i][j][k], dp[i - 1][j][k - 1]);
				if(j && k)    add(dp[i][j][k], dp[i][j - 1][k - 1]);
				if(i && j && k) add(dp[i][j][k], dp[i - 1][j - 1][k - 1]);
			}
		}
	}
	v = vvll(n, vll(n + 2));
	sz = vint(n);
	dfs(n - 1, -1);
	ll ans = 0;
	rep(i, n + 1) {
		add(ans, v[n - 1][i]);
	}
	cout << ans << endl;
}


int main() {
	mainmain();
}

Measured memory_bytes: 70376
N = int(input())
ok = False

def f(n):
    if n == 0:
        global ok
        ok = True
        return
    elif n < 0:
        return
    
    if ok:
        return
    
    f(n-4)
    f(n-7)

f(N)

if ok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<pair<ll, ll> > v(n);
    for(auto &x : v){
        cin >> x.F >> x.S;
    }
    reverse(ALL(v));
    ll ans = 0;
    for(auto &x : v){
        x.F += ans;
        if(x.F % x.S != 0){
            ll d = x.S - (x.F % x.S);
            ans += d;
        }
    }
    cout << ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 1792
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from sys import stdin


class Node():
    NIL = -1

    def __init__(self):
        self.parent = Node.NIL
        self.left = Node.NIL
        self.right = Node.NIL


def read_nodes(T):
    for line in stdin:
        id, left, right = [int(x) for x in line.split()]
        T[id].left = left
        if left != Node.NIL:
            T[left].parent = id
        T[id].right = right
        if right != Node.NIL:
            T[right].parent = id


def root_of(T):
    return [u.parent for u in T].index(Node.NIL)


def walk_preorder(T):

    def rec(id):
        nonlocal T

        if id == Node.NIL:
            return
        print("", id, end="")
        rec(T[id].left)
        rec(T[id].right)

    print("Preorder")
    rec(root_of(T))
    print()


def walk_inorder(T):

    def rec(id):
        nonlocal T

        if id == Node.NIL:
            return
        rec(T[id].left)
        print("", id, end="")
        rec(T[id].right)

    print("Inorder")
    rec(root_of(T))
    print()


def walk_postorder(T):

    def rec(id):
        nonlocal T

        if id == Node.NIL:
            return
        rec(T[id].left)
        rec(T[id].right)
        print("", id, end="")

    print("Postorder")
    rec(root_of(T))
    print()


def main():
    n = int(stdin.readline())
    T = [Node() for _ in range(n)]

    read_nodes(T)
    walk_preorder(T)
    walk_inorder(T)
    walk_postorder(T)


main()



Measured memory_bytes: 5632
<?php
  $n = trim(fgets(STDIN));
  $a = explode(" ",trim(fgets(STDIN)));
  $count = 0;
  $now = 1;
  for ($i=0; $i<$n; $i++){
    if($a[$i] != $now) {
      $count++;
    } else {
      $now++;
    }
  }
  if ($count != $n) echo $count."\n";
  else echo "-1\n";


Measured memory_bytes: 18932
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    
		String x = "";
		try {
			while ((x = in.readLine()) != null) {
				int lim = Integer.parseInt(x);
				
				int count = 0;
				for (int a = 0; a < 10; a++) {
					if (a > lim) break;
					
					for (int b = 0; b < 10; b++) {
						int sum2 = a + b;
						if (sum2 > lim) break;
						
						for (int c = 0; c < 10; c++) {
							int sum3 = sum2 + c;
							if (sum3 > lim) break;
							
							if ((lim - sum3) < 10) count++;
						}
					}
				}
				
				System.out.println(count);
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24268
def main():
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        if a[i]-1 > i and a[a[i]-1]-1 == i:
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14008
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
const int inf = 1<<29;
#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

bool wf(vvi & d){
    int n=d.size();
    rep(k,n)rep(i,n)rep(j,n){
        if(i==j) continue;
        if(d[i][j]!=inf) continue;
        if(d[i][k]==inf || d[k][j]==inf) continue;
        d[i][j] = d[i][k]+d[k][j];
    }
    rep(k,n)rep(i,n)rep(j,n){
        if(d[i][j]>=inf || d[i][k]>=inf || d[k][j]>=inf){
            // cout << i << " " << j << " " << k << " " << d[i][j] << endl;
            continue;
        }
        if(d[i][j] != d[i][k]+d[k][j]){
            return false;
        }
    }
    return true;
}

int main(){
    int n;
    while(cin >> n && n){
        int c = 0;
        map<string,int> m;
        vvi d(n*2, vi(n*2,inf));
        rep(i,n){
            char u1[20],u2[20];
            int t;
            scanf(" 1 %s = 10^ %d %s",u1,&t,u2);
            // cout << u1 << " " << u2 << " " << t << endl;
            string u(u1),v(u2);
            if(m.find(u) == m.end()){
                m[u] = c++;
            }
            if(m.find(v) == m.end()){
                m[v] = c++;
            }
            int mu=m[u];
            int mv=m[v];
            d[mu][mv] = t;
            d[mv][mu] = -t;
        }

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

Measured memory_bytes: 1468
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#define int long long
#define REP(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define mp(x,y) make_pair((x),(y))
using namespace std;


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

	string S;
	cin >> S;
	int f[4] = { 0 };
	rep(i, S.size()){
		switch (S[i]){
		case 'N':f[0]++; break;
		case 'S':f[1]++; break;
		case 'W':f[2]++; break;
		case 'E':f[3]++; break;
		}
	}
	if (f[0] * f[1] == 0 && f[0] + f[1] != 0){
		cout << "No" << endl;
		return 0;
	}
	if (f[2] * f[3] == 0 && f[2] + f[3] != 0){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;

}

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

ll mod=1e9+7;

ll mod_pow(ll a,ll b){
	a%=mod;
	if(b==0)return 1;
	if(b==1)return a;
	ll res=mod_pow(a,b/2)%mod;
	res*=res; res%=mod;
	if(b%2)res*=a;
	return res%mod;
}

struct perm{
private:
	int sz;
	vector<ll> p,invp;
public:
	perm(int n){
		sz=n+1;
		p.resize(sz),invp.resize(sz);
		p[0]=1;
		for(int i=1;i<=sz-1;i++){
			p[i]=p[i-1]*i%mod;
		}
		invp[sz-1]=mod_pow(p[sz-1],mod-2);
		for(int i=sz-2;i>=0;i--){
			invp[i]=invp[i+1]*(i+1)%mod;
		}
	}
	ll comb(ll x,ll y){
		if(x<y||y<0)return 0;
		return (p[x]*invp[x-y]%mod)*invp[y]%mod;
	}
};
perm p(1e7);

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll a,b,c,d; cin >> a >> c >> b >> d;
	ll ans=p.comb(a+c,c)-p.comb(a+d+1,a)-p.comb(b+c+1,b+1)+p.comb(b+d+2,b+1);
	ans%=mod;
	if(ans<0)ans+=mod;
	cout << ans << endl;
}

Measured memory_bytes: 156672
#include<bits/stdc++.h>
#define rep2(i,n,m) for (int i = int(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,n,0)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;//
template <typename T>
T sq (T x) {
    return x * x;
}

signed main () {
    int N ;
    cin >> N ;
    int ans = 0;

    rep2 (i ,N + 1,1){
        // cout << " i " <<  i <<endl;
        // cout << " ans " << ans << endl;
        ans = ans + i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,h; cin>>n>>h;
    vector<int> a(n), b(n);
    rep(i,n) cin>>a[i]>>b[i];
    sort(etob(a));
    int m=a[0];
    sort(etob(b));
    int cnt=n;
    rep(i,n){
        if(m>=b[i]){
            cnt=i;
            break;
        }
    }
    int ans=0;
    rep(i,cnt){
        ans++;
        h-=b[i];
        if(h<=0){
            cout<<ans<<endl;
            return 0;
        }
    }
    ans+=(h+m-1)/m;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4028
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define M 100010


int main(){
	IOS;
	tihs;
	ll n;cin>>n;
	ll a[n];
	bool ok=1;
	rep(i,0,n){
		cin>>a[i];
		if(a[i]%2==0){
			if(a[i]%3==0 or a[i]%5==0)continue;
			ok=0;
		}
	}
	if(ok)cout<<"APPROVED";
	else cout<<"DENIED";






	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <math.h>
#include <vector>


using namespace std;
int N;
long long ans=0,A;

int main(){
	cin>>N;
	vector<long long> v;
	for(int i=0;i<3*N;++i){
		cin>>A;
		v.push_back(A);
	}
	sort(v.begin(),v.end());
	int t=0;
	for(int i=v.size()-2;i>t;i-=2){
		ans+=v[i];
		++t;
	}
	cout<<ans<<endl;
	return 0;
}


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

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

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

	UnionFind uf( n );
	for( int i = 0; i < q; i++ ) {
		int com, x, y;
		cin >> com >> x >> y;
		if( com == 0 ) {
			uf.unionSet( x, y );
		}
		else {
			cout << uf.findSet( x, y ) << endl;
		}
	}
}



Measured memory_bytes: 3160
package main

import "fmt"

var H, W int

type point struct {
	x, y int
}

func (p *point) add(q point) {
	p.x += q.x
	p.y += q.y
	if p.x < 0 {
		p.x += H
	}
	if p.y < 0 {
		p.y += W
	}
	p.x %= H
	p.y %= W
}

func isPalindrome(str string) bool {
	for i, j := 0, len(str)-1; i < j; i, j = i+1, j-1 {
		if str[i] != str[j] {
			return false
		}
	}
	return true
}

func magicSpel(arr []string) string {
	var ans string
	m := map[string]int{}
	for i := range arr {
		for j := range arr[i] {
			for _, d := range []point{{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}} {
				cur := point{x: i, y: j}
				str := string(arr[cur.x][cur.y])
				cur.add(d)
				for i != cur.x || j != cur.y {
					str += string(arr[cur.x][cur.y])
					cur.add(d)
					if isPalindrome(str) {
						m[str] += 2
					} else {
						m[str]++
					}
				}
			}
		}
	}
	for s, v := range m {
		if 1 < v {
			if len(ans) < len(s) {
				ans = s
			} else if len(ans) == len(s) && s < ans {
				ans = s
			}
		}
	}

	if len(ans) == 0 {
		return "0"
	}

	return ans
}

func main() {
	for {
		fmt.Scan(&H, &W)
		if H == 0 && W == 0 {
			break
		}

		var arr []string

		for i := 0; i < H; i++ {
			var s string
			fmt.Scan(&s)
			arr = append(arr, s)
		}

		fmt.Println(magicSpel(arr))
	}
}

// 2 3
// ABC
// DEF




Measured memory_bytes: 43036
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int maxn=2e3+5;
char S[maxn];
int s[maxn][maxn],a[maxn][maxn];
int i,j,H,W,ans,h[maxn][maxn],t,q[maxn][2],cnt,len;
int main(){
	scanf("%d%d",&H,&W);
	fo(i,1,H) {
		scanf("%s",S+1);
		fo(j,1,W) s[i][j]=S[j]=='#';
	}
	ans=max(H,W);
	if (H==1||W==1) return printf("%d\n",ans),0;
	H--,W--;
	fo(i,1,H){
		cnt=0;
		fo(j,1,W){
			t=s[i][j]^s[i][j+1]^s[i+1][j]^s[i+1][j+1]^1;
			len=h[i][j]=(t)?h[i-1][j]+1:0;
			for(;cnt&&q[cnt][0]>len;cnt--) ans=max(ans,(q[cnt][0]+1)*(j-q[cnt-1][1]));
			q[++cnt][0]=len,q[cnt][1]=j;
		}
		for(;cnt;cnt--) ans=max(ans,(q[cnt][0]+1)*(W-q[cnt-1][1]+1));
	}
	printf("%d\n",ans);
}

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

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

int main(){
  //入力受け取り
  int H, W; 
  cin >> H >> W;
  vector<string> field(H);
  rep(i,H) cin >> field.at(i);
  
  //BFSの準備
  vector<vector<int>> dist(H, vector<int> (W, -1));
  queue<pint> que;
  rep(i,H)rep(j,W){
    if(field.at(i).at(j) == '#'){
      que.push(make_pair(i,j));
      dist.at(i).at(j) = 0;
    }//if
  }//rep
  
 //BFS
  while(!que.empty()){
        pint p = que.front();
        que.pop();
        int x = p.first;
        int y = p.second;
        rep(dir,4){
          int nx = x + dx[dir];
          int ny = y + dy[dir];
          if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
          if(field.at(nx).at(ny) == '#') continue;
          if(dist.at(nx).at(ny) == -1){
            dist.at(nx).at(ny) = dist.at(x).at(y) + 1;
            que.push(make_pair(nx,ny));
          }else if(dist.at(nx).at(ny) > dist.at(x).at(y) + 1){
            dist.at(nx).at(ny) = dist.at(x).at(y) + 1;
            que.push(make_pair(nx,ny));
          }
        }//rep
      }//while 
  
  //最も遠いdistを出力
  int ans = 0;
  rep(i,H)rep(j,W){
    ans = max(ans,dist.at(i).at(j));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13456
/**
 * File              : B.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 10.01.2020
 * Last Modified Date: 10.01.2020
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

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

bool is_valid(string& s, int pos) {
    int n = s.size();
    if (n - pos < 3)
        return false;
    return s[pos] == 'A' && s[pos+1] == 'B' && s[pos+2] == 'C';
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (is_valid(s, i))
            ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline
n, m = map(int, input().split())
edges = [[] for i in range(n)]
edges_r = [[] for i in range(n)]
for i in range(n+m-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges_r[b].append(a)

# 根と入次数
s = 0
ks = []
for i,e in enumerate(edges_r):
    if len(e) == 0:
        s = i
    ks.append(len(e))

parents = [-1] * n
INF = 1 << 60
q = deque([s])
while len(q) > 0:
    u = q.popleft()
    for v in edges[u]:
        # 入次数を1減らす
        ks[v] -= 1
        # 0だった時、親が決まる。
        # 親が決まったとき、子を探す
        if ks[v] == 0:
            parents[v] = u
            q.appendleft(v) 

for p in parents:
    print(p+1)

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

using namespace std;

typedef long long int LL;
typedef int ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))

const ll M=2e5+5,LG=19,SM=2000+5,inf=1e9+1;
ll mod=1e9+7;

int main()
{
	ios::sync_with_stdio(0);
    str s;
    cin >> s;
    ll n=SZ(s);
    ll k=n;
    For(i,1,n)
    {
        if (s[i]!=s[i-1])
        {
            smin(k,max(i,n-i));
        }
    }    
    cout << k << '\n';
}

Measured memory_bytes: 512
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
using namespace std;
int main(){
  int n,a,b,k,x,y;
  cin>>k>>x;
  if(k*500>=x)ou("Yes");
  else ou("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m;
vector<int> v[100010];
int d[100010];
int res=0;
int work(int x)
{
	if (d[x]>=0) return d[x];
	if (v[x].empty())
	{
		d[x]=0;
		return 0;
	}
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i];
		d[x]=max(d[x],work(xi)+1);
	}
	return d[x];
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<m;i++)
	{
		int x,y;
		cin >>x>>y;
		v[x-1].push_back(y-1);
	}
	fill(d,d+n,-1);
	for (int i=0;i<n;i++) res=max(res,work(i));
	cout <<res;
	return 0;
} 

Measured memory_bytes: 8192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();

        string answer = n == 1 ? "Hello World" : (sc.NextInt() + sc.NextInt()).ToString();

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

int main(){
  int X;
  

  cin >> X;
  while(1){
    for(int i=1;i<120;++i){
      for(int j=0;j<i;++j){
        if(pow(i,5) - pow(j,5) == X){
          cout << i << " " <<  j << endl;
          return 0;
        }else if(pow(i,5) + pow(j,5) == X){
          cout << i << " " << -j << endl;
          return 0;
        }else if(-pow(i,5) + pow(j,5) == X){
          cout << -i <<" " << -j << endl;
          return 0;
        }else if(-pow(i,5) - pow(j,5) == X){
          cout << -i <<" " << j << endl;
          return 0;
        }
      }
    }
  }

  
}


Measured memory_bytes: 4096
L = [list(map(int,input().split()))]
K = int(input())
import copy

def peice_double(L):
    l = []
    for x in L:
        tmp = copy.copy(x)
        for i in range(3):
            tmp[i] = tmp[i] * 2
            l.append(copy.copy(tmp))
            tmp[i] = tmp[i] // 2
    return l
for i in range(K):
    L = peice_double(L)
ans = 0
for x in L:
    ans = max(ans, sum(x))
print(ans)

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

int main(){
    int N;
    cin >> N;
    int v[N];
    for(int i = 0; i < N; i++){
        cin >> v[i];
    }
    double temp = 0;
    sort(v,v+N);
    temp = v[0];
    for(int i = 1; i < N; i++){
        temp = (temp + v[i])/2;
    }
    cout << temp << endl;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
a = [list(map(int, input().split())) for i in range(q)]

c = [0] * n
for i in range(1,n):
  c[i] = c[i-1] + (s[i-1]+s[i] == 'AC')

for x in a:
  print(c[x[1]-1]-c[x[0]-1])

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;

const int INF = 1001001001;

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

  int n; cin >> n;
  vector<int> h(n); rep(i, n) cin >> h[i];
  int dp[n+1]; rep(i, n+1) dp[i] = INF;
  dp[0] = 0;
  
  rep(i, n) {
    dp[i+1] = dp[i] + abs(h[i]-h[i+1]);
    if(i > 0) dp[i+1] = min(dp[i+1], dp[i-1] + abs(h[i-1] - h[i+1]));
  }
  cout << dp[n-1] << endl;
}
	 


Measured memory_bytes: 1024
import collections

n=int(input())
a=list(map(int,input().split()))
c = collections.Counter(a)

rkey=list(set(a))
list.sort(rkey, reverse=True)
rvalue=[c[i] for i in rkey]

for i in range(len(rvalue)):
  if rvalue[i]>=4:
    print(rkey[i]**2)
    exit()
  elif rvalue[i]>=2:
    width=rkey[i]
    rvalue.pop(i)
    rkey.pop(i)
    break
else:
  print("0")
  exit()
for i in range(len(rvalue)):
  if rvalue[i]>=2:
    height=rkey[i]
    break
else:
  print("0")
  exit()
print(width*height)    


Measured memory_bytes: 20892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader cd = new BufferedReader(new InputStreamReader(System.in));
		String[] vd = cd.readLine().split(" ");
		int a = Integer.parseInt(vd[0]);
		int b = Integer.parseInt(vd[1]);
		
		if(a<=8&&b<=8) System.out.println("Yay!");
		else System.out.println(":(");
	}

}


Measured memory_bytes: 20948
import sys
input = sys.stdin.readline

# from collections import deque

def linput(_t=int):
    return list(map(_t, input().split()))

def gcd(n,m):
    while m: n,m = m, n%m
    return n

def lcm(n,m): return n*m//gcd(n,m)

def main():
    # N = int(input())
    # vA = [int(input()) for _ in [0,]*N]
    h,m,H,M,K = linput()

    res = 60*H + M - 60*h - m - K

    print(res)
    # print(("No","Yes")[res%2])
    # print(*vR, sep="\n")

main()


Measured memory_bytes: 9184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Main {

	public static void main(String[] args) {

		// Listに標準入力の値を取得
		ArrayDeque<String> inputs = new ArrayDeque<>();
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			while (br.ready()) {
				String[] lineArray = br.readLine().split(" ");
				Arrays.<String> stream(lineArray).forEach(s -> inputs.add(s.trim()));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		// 入力取得
		String s = inputs.pop();
		Integer n = Integer.parseInt(inputs.pop());
		
		List<Integer> list = new ArrayList<>();
		for (String str : inputs) {
			int num = Integer.parseInt(str);
			list.add(num);
		}
		Collections.sort(list);

		int result = 0;
		for (int i = 0; i < n; i++) {
			Integer base = list.get(i);
			result += base;
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 34128
def main():
    N = int(input())
    S = input()

    if N % 2 == 1:
        print("No")
        exit()

    flag = True
    for i in range(int(N/2)):
        if S[i] == S[i + int(N/2)]:
            continue
        flag = False

    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060