akhauriyash/Code-Regression huggingface dataset:
#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>;

template <typename T>
std::tuple<T, T, T> extgcd(T a, T b){
    T s1 = 1, t1 = 0, s2 = 0, t2 = 1;
    while(b != 0){
        std::tie(s1, t1, s2, t2) = std::make_tuple(s2, t2, s1 - (a / b) * s2, t1 - (a / b) * t2);
        std::tie(a, b) = std::make_tuple(b, a % b);
    }
    return std::make_tuple(s1, t1, a);
}

template <typename T>
T mod_expt(T a, std::int64_t n, T mod){
    T power {1};
    while(n > 0){
        if(n & 1){power = power * a % mod;}
        a = a * a % mod;
        n >>= 1;
    }
    return power;
}

template <typename T>
T mod_inverse(T a, T mod){
    T b;
    std::tie(b, std::ignore, std::ignore) = extgcd(a, mod);
    if(b < 0){b += mod;}
    return b;
}

template <typename T>
struct Combinatorics{
    T modulo;
    std::vector<T> fact, inv_fact;

    Combinatorics(T max, T modulo) : modulo(modulo), fact(max + 1), inv_fact(max + 1) {
        fact[0] = 1;
        for(T i=1;i<=max;++i){
            fact[i] = i * fact[i - 1] % modulo;
        }

        inv_fact[max] = mod_inverse(fact[max], modulo);
        for(T i=max;i>0;--i){
            inv_fact[i - 1] = i * inv_fact[i] % modulo;
        }
    }

    T nPk(T n, T k){
        if(n < k){return 0;}
        return fact[n] * inv_fact[n - k] % modulo;
    }

    T nCk(T n, T k){
        if(n < k){return 0;}
        return fact[n] * inv_fact[k] % modulo * inv_fact[n - k] % modulo;
    }

    T nHk(T n, T k){
        if(n == 0 && k == 0){return 1;}
        return nCk(n + k - 1, k);
    }
};

constexpr ll MOD = 1'000'000'007;
constexpr ll HALF = 500'000'004;

Combinatorics<ll> comb(200100, MOD);
int B, W;
ll X[200100], Y[200100];

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

    std::cin >> B >> W;

    X[0] = 1;
    Y[0] = 1;

    for(int i=1;i<=B+W;++i){
        X[i] = ((X[i-1] - Y[i-1]) + Y[i-1] * 2) % MOD;
        if(i < B + W){
            Y[i] = (X[i] - comb.nCk(i, B) - comb.nCk(i, W)) % MOD;
        }

        if(X[i] < 0){X[i] += MOD;}
        if(Y[i] < 0){Y[i] += MOD;}
    }

    ll p = 0;

    for(int i=1;i<=B+W;++i){
        if(i <= std::min(B, W)){
            std::cout << HALF << std::endl;
        }else{
            ll q = p;
            q += Y[i-1] * mod_expt<ll>(HALF, i, MOD) % MOD;
            if(q >= MOD){q -= MOD;}

            std::cout << q << std::endl;
        }

        if(i >= W){
            p += comb.nCk(i - 1, W - 1) * mod_expt<ll>(HALF, i, MOD) % MOD;
            if(p >= MOD){p -= MOD;}
        }
    }
}


Measured memory_bytes: 9420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)x.size()
#define int ll

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].F;
		a[i].S = i;
	}	
	sort(all(a));
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 != a[i].S % 2) {
			ans++;
		}
	}
	assert(ans % 2 == 0);
	cout << ans / 2 << '\n';
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast,inline", 3)
#include<bits/stdc++.h>
#define il inline
#define rg register
#define gi read<int>
#define int long long
using namespace std;
const int O = 2e5 + 10, lim = 2010, mod = 1e9 + 7, Lim = 2020;
template<class TT>
il TT read() {
	TT o = 0, fl = 1; char ch = getchar();
	while (!isdigit(ch) && ch != '-') ch = getchar();
	if (ch == '-') fl = -1, ch = getchar();
	while (isdigit(ch)) o = o * 10 + ch - '0', ch = getchar();
	return fl * o;
}
int n, a[O], b[O], dp[Lim << 1][Lim << 1], fac[Lim << 2], inv[Lim << 2], ans;
//il void pls(int & x, int y) {x += y; if (x >= mod) x -= mod;}
il int C(int x, int y) {return 1ll * fac[y] * inv[x] % mod * inv[y - x] % mod;}
signed main() {
	fac[0] = inv[1] = 1; for (int i = 1; i <= lim << 2; ++i) fac[i] = 1ll * fac[i - 1] * i % mod; for (int i = 2; i <= lim << 2; ++i) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod; for (int i = 2; i <= lim << 2; ++i) inv[i] = 1ll * inv[i] * inv[i - 1] % mod;
	n = gi();
	for (int i = 1; i <= n; ++i) {
		a[i] = gi(), b[i] = gi();
		++dp[lim - a[i]][lim - b[i]];
	}
	for (int i = 1; i <= lim + 1 << 1; ++i)
		for (int j = 1; j <= lim + 1 << 1; ++j)
			dp[i][j] = ((dp[i][j] + dp[i][j - 1]) % mod + dp[i - 1][j]) % mod;
	for (int i = 1; i <= n; ++i) {
		(ans += dp[lim + a[i]][lim + b[i]]) %= mod;
		(ans += mod - C(a[i] << 1, a[i] + b[i] << 1)) %= mod;
	}
	printf("%lld", 1ll * ans * inv[2] % mod);
	return 0;
}

Measured memory_bytes: 130944
N,Q=map(int,input().split())
S=input()
listS=list(S)
ans=0
listAC=[ans]
for k in range(1,N):
  if listS[k-1]=="A" and listS[k]=="C":
    ans+=1
  listAC+=[ans]  
for i in range(Q):
  l,r=map(int,input().split())
  ans=listAC[r-1]-listAC[l-1] 
  print(ans)    

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

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

int main() {
    int n; cin >> n;
    vector<long long> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    long long ans = v[0];
    for (int i = 0; i < n; i++) {
        ans = gcd(ans, v[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int A;
char s[15];
int main()
{
	scanf("%d%s",&A,s+1);
	if(A>=3200)printf("%s",s+1);
	else printf("red\n");
}

Measured memory_bytes: 256
N = int(input()) 
S = [input() for _ in range(N)]
new_S = set(S)
M = int(input()) 
T = [input() for _ in range(M)]
use = 0
for i in new_S:
    use1 = S.count(i) - T.count(i) 
    use = max(use,use1)

print(use)

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

int s1[2001][2001], s2[2001][2001], s3[2001][2001];
int main() {
	int n, m, q; scanf("%d%d%d", &n, &m, &q);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			scanf("%1d", &s1[i][j]);
			s2[i][j] = (s1[i][j] && s1[i - 1][j]);
			s3[i][j] = (s1[i][j] && s1[i][j - 1]);
		}
	}
	for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)
		s1[i][j] += s1[i - 1][j], s2[i][j] += s2[i - 1][j], s3[i][j] += s3[i - 1][j];
	for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)
		s1[i][j] += s1[i][j - 1], s2[i][j] += s2[i][j - 1], s3[i][j] += s3[i][j - 1];
	rep(i, q) {
		int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); x1--; y1--;
		printf("%d\n", s1[x2][y2] - s1[x2][y1] - s1[x1][y2] + s1[x1][y1] - (s2[x2][y2] - s2[x2][y1] - s2[x1 + 1][y2] + s2[x1 + 1][y1] + s3[x2][y2] - s3[x2][y1 + 1] - s3[x1][y2] + s3[x1][y1 + 1]));
	}
}

Measured memory_bytes: 48768
A, B, C = list(map(int, input().split()))
[A, B, C].sort() #smaller~bigger
if A==B and B==C:
    if A%2==0:
        print(-1)
    else:
        print(0)
elif (A%2==1) or (B%2==1) or (C%2==1):
    print(0)
else:
    cnt = 0
    while ((A%2==0) and (B%2==0) and (C%2==0)):
        [A, B, C] = [(A+B)/2, (A+C)/2, (B+C)/2]
        cnt += 1
    print(cnt)


Measured memory_bytes: 62080
a, b = map(int, input().split())
c = []
for i in range(a):
    d, e = map(int, input().split())
    c.append([d, e])
c.sort()
for i in range(a):
    if c[i][1] <= b:
        print(c[i][0])
        exit()
print("TLE")


Measured memory_bytes: 2940
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int road[200005], train[200005];

void init(char moji) {
  if (moji=='r'){
    for (int i=0; i<200005; i++){
      road[i] = -1;
    }
  } else {
    for (int i=0; i<200005; i++){
      train[i]= -1;
    }
  }
  return;
}

int getroot(int n, char moji){
  if (moji=='r'){
    if (road[n]<0){
      return n;
    } else {
      int root = getroot(road[n], moji);
      //road[n] = root;
      return root;
    }
  } else {
    if (train[n]<0){
      return n;
    } else {
      int root = getroot(train[n], moji);
      //train[n] = root;
      return root;
    }
  }
}

bool samegroup(int n, int m, char moji){
  int nroot = getroot(n, moji);
  int mroot = getroot(m, moji);
  if (nroot==mroot){
    return true;
  } else {
    return false;
  }
}

bool unite (int n, int m, char moji){
  if (samegroup(n, m, moji)){
    return false;
  } else {
    int nroot = getroot(n, moji);
    int mroot = getroot(m, moji);
    if (moji=='r'){
      if (abs(road[nroot])==abs(road[mroot])){
        road[mroot] = nroot;
        road[nroot]--;
      } else if (abs(road[nroot])>abs(road[mroot])){
        road[mroot]=nroot;
      } else {
        road[nroot] = mroot;
      }
    } else {
      if (abs(train[nroot])==abs(train[mroot])){
        train[mroot] = nroot;
        train[nroot]--;
      } else if (abs(train[nroot])>abs(train[mroot])){
        train[mroot]=nroot;
      } else {
        train[nroot] = mroot;
      }
    }
    return true;
  }
}

int main(){
  int N, K, L;
  scanf("%d", &N);
  scanf("%d", &K);
  scanf("%d", &L);
  std::vector<int > p(K), q(K), r(L), s(L);
  for (int i=0; i<K; i++){
    scanf("%d", &p[i]);
    scanf("%d", &q[i]);
  }
  for (int i=0; i<L; i++){
    scanf("%d", &r[i]);
    scanf("%d", &s[i]);
  }
  init('r');
  init('t');
  for (int i=0; i<K; i++){
    if (!samegroup(p[i],q[i],'r')){
      unite(p[i],q[i],'r');
    }
  }
  for (int i=0; i<L; i++){
    if (!samegroup(r[i],s[i],'t')){
      unite(r[i],s[i],'t');
    }
  }
  //std::set<std::pair<int, int > > set;
  std::map<std::pair<int, int>, int> mp;
  for (int i=1; i<=N; i++){
    //set.insert(std::make_pair(getroot(i,'r'), getroot(i, 't')));
    mp[std::make_pair(getroot(i,'r'), getroot(i, 't'))]++;
  }
  for (int i=1; i<=N; i++){
    printf("%d%c",mp[std::make_pair(getroot(i,'r'), getroot(i, 't'))],(i==N)?'\n':' ');
  }  
  return 0;
}


Measured memory_bytes: 12288
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll inf = 1e16;
const ll mod=1000000007;
typedef pair<ll,ll> pi;

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    t=1;
    for(ll i=1;i<=t;i++)
    {
        solve();
        cout<<endl;

    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int A, B;
  cin >> A >> B;
  cout << max({0, A-2*B}) << endl;

  return 0;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
m = (n-1)*(n-2)//2
if k > m:
    print(-1)
    exit()
r = m-k

edge = [[] for i in range(n)]
edge[0] = list(range(1, n))
for i in range(1, n):
    for j in range(i+1, n):
        if r == 0:
            break
        edge[i].append(j)
        r -= 1

m = sum(len(i) for i in edge)
print(m)
for i in range(n):
    for j in edge[i]:
        print(i+1, j+1)

Measured memory_bytes: 43120
N, A, B = map(int, input().split())

if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    lose = N - B + 1
    loseThenMeet = (N - (A + lose)) // 2
    win = A - 1 + 1
    winThenMeet = ((B - win) - 1) // 2
    print(min(lose + loseThenMeet, win + winThenMeet))


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>



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

int N;

int main(){
    cin >> N;
    rep(i,10){
        if (i==0) continue;
        if(N%i==0 && N/i < 10 && N/i > 0 && i>0 && i<10){
            cout << "Yes" << endl;
            return 0;
        }
        
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S;
    
    int price = 700;
    
    if (S[0] == 'o')
        price += 100;
    if (S[1] == 'o')
        price += 100;
    if (S[2] == 'o')
        price += 100;
    cout << price << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
double r,x1,x2,x3,y1,y2,y3,x,y,a,b,c,d;
int n,i;
scanf("%d\n",&n);
for(i=0;i<n;i++){
scanf("%lf %lf %lf %lf %lf %lf\n",&x1,&y1,&x2,&y2,&x3,&y3);
a=x2-x1,b=y2-y1,c=y3-y1,d=x3-x1;
x=(b*d*d+b*c*c-a*a*c-b*b*c)/(2*b*d-2*a*c);
x=x+x1;
y=(a*a*d+b*b*d-a*c*c-a*d*d)/(2*b*d-2*a*c);
y=y+y1;
r=(x1-x)*(x1-x)+(y1-y)*(y1-y);
r=sqrt(r);
printf("%.3lf %.3lf %.3lf\n",x,y,r);
}
return 0;
}


Measured memory_bytes: 2040
#include <iostream>

using namespace std;

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

    int cntE = 0, cntW = 0;
    //1人目から東側で東向いている人数を求める。
    for(int i = 1; i < n; i++){
        if(s[i] == 'E'){
            cntE++;
        }
    }

    int ans = cntE;

    //リーダーをずらしながら向き直る人数を求める
    for(int newR = 1; newR < n; newR++){
        //旧リーダーの向き直りカウント
        if(s[newR - 1] == 'W'){
            cntW++;
        }
        if(s[newR] == 'E'){
            cntE--;
        }
        ans = min(ans, cntE + cntW);
    }

    cout << ans << endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
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) << " "

bool is_prime(int x){
    if(x<=1)return false;
    for(int i=2;i*i<=x;i++){
        if(x%i==0)return false;
    }
    return true;
}

int main(){
    int x;cin>>x;
    while(!is_prime(x))++x;
    co(x);
}

Measured memory_bytes: 256
N,x = map(int,input().split())
a = list(map(int,input().split()))

A = sorted(a)

ans = 0

for i in range(len(A)):
    x = x - A[i]
    if x >= 0:
       ans +=1
    else:
        break
        
if x > 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;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  int max = -1000000001;
  int min = 1000000001;
  REP(i, N) {
    if(max < A[i]) max = A[i];
    if(min > A[i]) min = A[i];
  }
  cout << max - min << endl;
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto H = RD;
	auto W = RD;
	auto s = new string[](H);
	foreach (i; 0..H)
	{
		s[i] = RD!string;
	}

	long[][] open = [[0, 0]];
	auto dist = new long[][](H, W);
	foreach (i; 0..H)
		dist[i][] = long.max;
	dist[0][0] = s[0][0] == '#' ? 1 : 0;

	while (!open.empty)
	{
		auto nd = open.front; open.popFront;
		auto y = nd[0];
		auto x = nd[1];
		if (y != H-1)
		{
			auto d = dist[y][x];
			auto ny = y+1;
			auto nx = x;
			if (s[y][x] == '.' && s[ny][nx] == '#')
				++d;
			if (d < dist[ny][nx])
			{
				dist[ny][nx] = d;
				open ~= [ny, nx];
			}
		}
		if (x != W-1)
		{
			auto d = dist[y][x];
			auto ny = y;
			auto nx = x+1;
			if (s[y][x] == '.' && s[ny][nx] == '#')
				++d;
			if (d < dist[ny][nx])
			{
				dist[ny][nx] = d;
				open ~= [ny, nx];
			}
		}
	}

	writeln(dist[H-1][W-1]);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 3324
import java.util.Scanner;

public class Main {
	static int maxn = 100 + 10;
	public static void main(String[] args) 
	{
		Scanner cin = new Scanner(System.in);
		int n=cin.nextInt();
		int k=cin.nextInt();
		if(n<10)
		{
			k+=(10-n)*100;
		}
		System.out.println(k);
	}
	
}

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

int main()
{
    string o, e; cin >> o >> e;

    int n = o.size() + e.size();

    string ans(n, ' ');

    for(int i = 0; i < n; i += 2) ans[i] = o[i / 2];
    for(int i = 1; i < n; i += 2) ans[i] = e[i / 2];

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

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ans(N);
  
  for (int i = 0; i < M * 2; i++) {
    int t;
    cin >> t;
    ans.at(t - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << ans.at(i) << endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


int main() {
    int n; string s; cin >> n >> s;
    
    int res = 0;
    rep(i, 1000){
        vector<int> num{i/100, i/10%10, i%10};
        int p = 0;
        for(char c: s){
            if(c - '0' == num[p]){
               p++; 
            }
            if(p == 3){
                res++;
                break;
            }
        }
    }
    cout << res << ln;
}

Measured memory_bytes: 384
A = int(input())
B = int(input())
C = int(input())
X = int(input())
list_A = list(range(A+1))
list_B = list(range(B+1))
list_C = list(range(C+1))
cnt = 0
for i in range(len(list_A)):
        for j in range(len(list_B)):
                for k in range(len(list_C)):
                        if X-(list_A[i]*500+list_B[j]*100+list_C[k]*50) == 0:
                                cnt += 1
                        else:
                                continue
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll dp[22][2100000];

int main(void) {
    ll N;
    cin >> N;
    ll a[22][22];
    ll i, j, k;
    
    for(i=0; i<N; i++) {
        for(j=0; j<N; j++) {
            cin >> a[i][j];
        }
    }
    
    dp[0][0]=1;
    for(i=0; i<N; i++) {
        for(j=0; j<1<<N; j++) {
            for(k=0; k<N; k++) {
                if(dp[i][j]==0 || a[i][k]==0 || j>>k&1) continue;
                dp[i+1][j | 1<<k]=(dp[i+1][j | 1<<k]+dp[i][j])%MOD;
            }
        }
    }
    
    pr(dp[N][(1<<N)-1]);
    
    
}




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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

double res = 1.0;
double p, e, t;

void rec(int k, double l, double r, double cur) {
    //printf("%d %.12lf %.12lf %.12lf %.12lf\n", k, res, cur, l, r);
    double h = (l + r) / 2.0;
    if (k == 0) {
        if (not(t - e <= h and h <= t + e)) {
            res -= cur;
        }
        return;
    }
    if (t + e < l or r < t - e) {
        res -= cur;
        return;
    }
    if (h < t) {
        rec(k - 1, h, r, cur * (1.0 - p));
        rec(k - 1, l, h, cur * p);
    } else {
        rec(k - 1, h, r, cur * p);
        rec(k - 1, l, h, cur * (1.0 - p));
    }
}

int main() {
    int k;
    double r, l;
    cin >> k >> r >> l >> p >> e >> t;
    rec(k, r, l, 1.0);
    printf("%.12lf\n", res);
    return 0;
}



Measured memory_bytes: 3296
import numpy as np
import sys
input = sys.stdin.buffer.readline
D = int(input())
C = list(map(int, input().split()))
S = []
for _ in range(D):
    S.append(list(map(int, input().split())))

# print('S', S)

contest = np.argmax(S[0]) + 1
# print('contest', contest)

for i in range(contest, D + contest):
    print((i - 1) % 26 + 1)


Measured memory_bytes: 27592
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int h, w, k;
    cin >> h >> w >> k;

    vector<string> c(h); 
    for (int i = 0; i < h; i++) {
        cin >> c[i];
    }

    int ans = 0;
    for (int bit = 0; bit < (1 << h); bit++) {
        for (int bit2 = 0; bit2 < (1 << w); bit2++) {
            vector<string> tmp = c; 

            for (int i = 0; i < h; i++) {
                if (bit & (1 << i)) {
                    for (int j = 0; j < w; j++) {
                        tmp[i][j] = '_';
                    }
                }
            }

            for (int j = 0; j < w; j++) {
                if (bit2 & (1 << j)) {
                    for (int i = 0; i < h; i++) {
                        tmp[i][j] = '_';
                    }
                }
            }

            int cnt = 0;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (tmp[i][j] == '#') {
                        cnt++;
                    }
                }
            }

            if (cnt == k) {
                ans++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3568
#include<stdio.h>
#include<string.h>

#define MAX 150000

typedef struct Point{
  char data[100];
  int t;
} Point;

Point set[MAX];
int head;
int tail;
int k;

void equal(Point);
int minixm(int,int);
Point notequal();

int main(){
  int el = 0;
  int c;
  int i;
  int l;
  Point u;

  scanf("%d %d",&k,&l);

  for(i = 0;i < k;i++){
    scanf("%s %d",set[i].data,&set[i].t);
  }
  head = 0;
  tail = k;

  while(head != tail){
    u = notequal();
    c = minixm(l,u.t);
    u.t -= c;
    el += c;
    if(u.t > 0){
      equal(u);
    }
    else{
      printf("%s %d\n",u.data,el);
    }
  }
  return 0;
}


void equal(Point x){
  set[tail] = x;
  tail = (tail + 1) % MAX;
}

Point notequal(){
  Point x = set[head];
  head = (head + 1) % MAX;
  return x;
}

int minixm(int a,int b){
  return a < b ? a : b;
}



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

int main(){
    int n,k;
    cin>>n>>k;
    int ans=0;
    for(int i=0;i<n;i++){
        int x; cin>>x;
        if(2*x<=k)ans+=2*x;
        else ans+=2*(k-x);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
N, a, b = gets.chomp.split(' ').map(&:to_i)
S = gets.chomp.split('')
pass_s_count = 0
b_rank = 1

N.times {|rank|
  result = 'No'
  if pass_s_count < a+b
    if S[rank] == 'a'
      result = 'Yes'
      pass_s_count += 1
    elsif S[rank] == 'b'
      if b_rank <= b
        result = 'Yes'
        pass_s_count += 1
      end
      b_rank += 1
    end
  end
  puts result
}

Measured memory_bytes: 22672
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= i + 1
a.sort()
if n == 1:
    ans = 0
elif n %  2 == 0:
    m, l = 0, 0
    for i in a:
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 - 1])
    ans = min(l, m)
else:
    k, m, l = 0, 0, 0
    for i in a:
        k += abs(i - a[n // 2 - 1])
        m += abs(i - a[n // 2])
        l += abs(i - a[n // 2 + 1])
        ans = min(k, m, l)
print(ans)

Measured memory_bytes: 25748
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());

ll modinverse(ll x,ll p=mod)
{
	return power(x,p-2,p);
}

int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		ll a,b;
		cin>>n>>a>>b;
		// n=s.length();
		// ll a[n];
		c=power(2,n)-1;
		if(c<0) c+=mod;


		// for nCa
		k=a;
		ll num=1; // n * (n-1) * ... * (n-k+1)
		rep(i,k)
			num=(num*(n-i))%mod;
		ll den=1; // k!
		rep(i,k)
			den=(den*(i+1))%mod;
		m=(num*modinverse(den,mod))%mod;
		c=(c-m);
		if(c<0) c+=mod;


		// for nCb
		k=b;
		num=1; // n * (n-1) * ... * (n-k+1)
		rep(i,k)
			num=(num*(n-i))%mod;
		den=1; // k!
		rep(i,k)
			den=(den*(i+1))%mod;
		m=(num*modinverse(den,mod))%mod;
		c=(c-m);
		if(c<0) c+=mod;

		cout<<c;

		
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int SIZEN = 200010;
int N,K;
int a[SIZEN] = {0};
bool Check(int x){
    int ret = 0;
    for(int i = 1;i <= N;i++){
        if(a[i] <= x)continue;
        int tmp = a[i] / x;
        if(a[i] % x == 0)tmp--;
        ret += tmp;
    }
    return ret <= K;
}
int main(){
    scanf("%d%d",&N,&K);
    for(int i = 1;i <= N;i++)scanf("%d",&a[i]);
    int l = 1,r = 0,ans = 0,mid;
    for(int i = 1;i <= N;i++)r = max(r,a[i]);
    while(l <= r){
        mid = (l+r)/2;
        if(Check(mid))r = mid-1,ans = mid;
        else l = mid+1;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2508
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
lint max = 0;
vector<vector<int>> suretu;
void solve(vector<int> x, int N, int M) {
    if(x.size() == N) {
        suretu.push_back(x);
        return;
    }
    FOR(i, x[x.size()-1], M+1) {
        vector<int> newinit(x);
        newinit.push_back(i);
        solve(newinit, N, M);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> A(Q);
    vector<int> B(Q);
    vector<int> C(Q);
    vector<int> D(Q);
    REP(i, Q) {
        cin >> A[i] >> B[i] >> C[i] >> D[i];
    }
    FOR(i, 1, M+1) {
        vector<int> init = {i};
        solve(init, N, M);
    }
    lint max = 0;
    REP(i, suretu.size()) {
        lint score = 0;
        REP(j, Q) {
            if(suretu[i][B[j]-1] - suretu[i][A[j]-1] == C[j]) {
                score += D[j];
            }
        }
        if(score > max) max = score;
    }
    cout << max << endl;
}

Measured memory_bytes: 9792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <limits.h>

using namespace std;

int main(int argc, char const* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int pre_color = 0;
    int color_count = 1;
    int count = 0;
    for (int i=0; i<N; ++i) {
        int ai;
        cin >> ai;
        if (ai == pre_color) {
            ++color_count;
        }
        else {
            count += color_count / 2;
            color_count = 1;
            pre_color = ai;
        }
    }
    count += color_count / 2;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<long long, long long>;
struct edge { 
    ll to, cost;
    edge(ll t, ll c): to(t), cost(c){};
};
const ll INF = 1LL << 60;

void dijkstra(vector<vector<edge> > &G, vector<ll> &dist, ll start){
    ll n = G.size();
    set<ll> X;
    priority_queue<pll, vector<pll>, greater<pll> > que;
    dist[start] = 0;
    que.push(pll(0, start));
    while(X.size()<n){
        pll p = que.top(); que.pop();
        ll w = p.second, score = p.first;
        if(X.count(w)) continue; //* w already in X, skip
        else {
            X.insert(w); //* put w into X
            dist[w] = score; //* record shortest distance to w
            for(ll i=0; i< G[w].size(); i++){ //* search the neighbours of w
                //* new node G[w][i].to
                if(!X.count(G[w][i].to)){
                    que.push(pll(G[w][i].cost+ score, G[w][i].to));
                } 
            }
        }
    }
}

void solve(long long n, long long m, long long s, long long t, std::vector<long long> u, std::vector<long long> v, std::vector<long long> a, std::vector<long long> b){
    s--; t--;
    //* build two graphs
    vector<vector<edge> > Gyen(n), Gsnu(n);
    for(ll i=0; i< m; i++){
        Gyen[u[i]-1].push_back(edge(v[i]-1, a[i]));
        Gyen[v[i]-1].push_back(edge(u[i]-1, a[i]));
        Gsnu[u[i]-1].push_back(edge(v[i]-1, b[i]));
        Gsnu[v[i]-1].push_back(edge(u[i]-1, b[i]));
    }
    //* dijkstra on Gyen from s
    vector<ll> dist_s(n, INF);
    dijkstra(Gyen, dist_s, s);

    //* dijkstra on Gsnu from t
    vector<ll> dist_t(n, INF);
    dijkstra(Gsnu, dist_t, t);

    //* for i-th year we pick up exchange node available that minimize the total expense
    //* starting from n-1 th year
    priority_queue<ll, vector<ll>, greater<ll> > expense; //* min heap
    vector<ll> res(n);
    for(ll i=n-1; i>=0; i--){
        expense.push(dist_s[i]+dist_t[i]);
        res[i] = expense.top();
    }
    for(ll i=0; i< n; i++) cout << 1000000000000000- res[i] << endl;


}

int main(){
    long long n;
    scanf("%lld",&n);
    long long m;
    scanf("%lld",&m);
    long long s;
    scanf("%lld",&s);
    long long t;
    scanf("%lld",&t);
    std::vector<long long> u(m);
    std::vector<long long> v(m);
    std::vector<long long> a(m);
    std::vector<long long> b(m);
    for(int i = 0 ; i < m ; i++){
        scanf("%lld",&u[i]);
        scanf("%lld",&v[i]);
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(n, m, s, t, std::move(u), std::move(v), std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 24864
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

ll rui(ll a,ll n){
  ll ans=1;
  while(n>0){
    if(n&1) ans=ans*a%mod;
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

int main(){
  ll N; cin >> N;
  if(N%2==1||N<10){
    cout << 0 << endl;
    return 0;
  }
  ll ans=0;
  ll j=10;
  while(N>=j){
    ans+=N/j;
    j*=5;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <tuple>
 
using namespace std;
 
template<typename E>
using Matrix = std::vector<std::vector<E> >;
 
typedef long long LL;
typedef long double LD;
typedef std::pair<LL ,LL> LP;
 
#define INF		1e9
#define EPS		1e-9
#define gcd 	__gcd
#define make_matrix(rows, col, type, default) 			\
					std::vector< std::vector<type> >( 	\
						rows 						  	\
						std::vector<type>(col, default) \
					);
 
#define repeat(n)	for(LL __x = 0; __x < n; __x++)
#define watch(x)	cout << (#x) << " is " << (x) << "\n";
#define DEG_TO_RAD(x) (x * PI / 180.0)
#define RAD_TO_DEG(x) (x * 180.0 / PI)

auto cost(LL i, LL j) -> LL {
    return abs(i-j);
}

auto main() -> int {
    LL n, t;

    std::vector<LL> memo;
    std::vector<LL> rocks; // rock height

    std::cin >> n;
    for(LL i = 0; i < n; i++) {
        std::cin >> t;
        rocks.push_back(t);

        if(i == 0) { memo.push_back(0); continue; }
        if(i == 1) { memo.push_back(cost(rocks[i], rocks[i-1])); continue; }

        memo.push_back(
            min(memo[i-1] + cost(rocks[i], rocks[i-1]), 
                memo[i-2] + cost(rocks[i], rocks[i-2])
            )
        );
    }
    std::cout << memo[n-1];
}

Measured memory_bytes: 2036
import Data.Char
import Data.List

main = print . sum . map (read :: String -> Int) . concat . sub =<< getLine

sub [s] = [(s:"")]:[]
sub (s:ss) = let sub's = sub ss in (map (\(x:xs) -> (s:x):xs) sub's) ++ (map ([s]:) sub's)


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

const int MOD = 1e9 + 7;
const int MAXN = 200005;

vector<LL> fact, inv;

LL modpow(LL b, LL x){
	LL ans = 1, n = b % MOD;
	while(x){
		if (x & 1){
			ans = (ans * n) % MOD;
		}
		n = (n * n) % MOD; x >>= 1;
	}
	return ans;
}

void pregen(){
	fact.resize(MAXN); inv.resize(MAXN);
	fact[0] = inv[0] = 1LL;
	for (int i = 1; i < MAXN; ++i){
		fact[i] = (fact[i-1] * i) % MOD;
		inv[i] = modpow(fact[i], MOD-2);
	}
}

LL choose(int n, int k){
	if (n < k) return 0;
	return ((fact[n] * inv[k]) % MOD * inv[n-k]) % MOD;
}

LL count(int h, int w){
	//cout << h << ' ' << w << '\n';
	return choose(h + w - 2, w - 1);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    pregen();
	int H, W, A, B; cin >> H >> W >> A >> B;
	LL answer = (count(H-A, B+1) * count(A+1, W-B)) % MOD;
	for (int j = B + 2; j <= W ; ++j){
		LL temp = (count(H-A-1, j) * count(A+1, W-j+1)) % MOD;
		answer = (answer + temp) % MOD;
	}
	cout << answer << '\n';
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define pl pair<ll,ll>
#define TC int t;cin>>t;while(t--)
#define in(n) ll n;cin>>n;
#define inarr(n) ll n;cin>>n;vector<ll>arr;
int main(void){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    inarr(n);
    ll ans=0;
    for(int i=0;i<n;i++){
        in(temp);arr.push_back(temp);
    }
    sort(arr.begin(),arr.end());
    // ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(arr[i]+arr[j]>arr[k] && arr[i]!=arr[j] && arr[i]!=arr[k] && arr[j]!=arr[k]){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3544
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define umap unordered_map
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


using Graph = vector<vector<int>>;

int main() {
  int n,q;
  cin>>n>>q;
  
  Graph G(n);
    
  rep(i,n-1){
  ll a,b;  
  cin>>a>>b;
    G[a-1].pb(b-1);
    G[b-1].pb(a-1);
  }
  
  vector<ll> r(n,0);
  rep(i,q){
  ll x,y;
  cin>>x>>y;
    r[x-1]+=y;
  }
  
  
  vector<int> p(n,-1);
  deque<int> que;
  
  p[0]=r[0];
  que.pb(0);
  
 // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop_front();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (p[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            p[nv] = p[v]+r[nv];
            que.pb(nv);
        }
    }

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    rep(i,n) {
      cout << p[i] << endl;
    }
  
  
}


Measured memory_bytes: 24452
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

int K;
int a[112345];
ll ans;
ll dfs(const vector<vint>& g,int p,int v){
  ll h=1;
  for(int u:g[v])if(u!=p){
    h = max(h,dfs(g,v,u)+1);
  }
  if(h==K&&a[v]!=0){
    a[v]=0;
    ans++;
    h=0;
  }
  return h;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N>>K;
  vector<vint> g(N);
  repeat(i,N){
    cin>>a[i];a[i]--;
    if(i==0){
      ans=a[i]!=0;
      a[i]=0;
      continue;
    }
    g[a[i]].push_back(i);
  }
  //debug(ans);
  //debugArray(a,N);
  dfs(g,-1,0);
  //debugArray(a,N);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S;
const ll MOD = (1e+9) + 7;
const ll INF = 1000;//1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>A>>B;
    cout<<(abs(A - B) <= 1 ? "Brown" : "Alice")<<endl;
}

Measured memory_bytes: 768
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    A, B, C, D = [int(x) for x in input().split()]

    if -(-C // B) <= -(-A // D):
        print("Yes")
    else:
        print("No")



if __name__ == '__main__':
    main()


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

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str = br.readLine();

		int A = Integer.parseInt(str.split(" ")[0]);
		int B = Integer.parseInt(str.split(" ")[1]);
		int t = Integer.parseInt(str.split(" ")[2]);


		int bcount = (t-(t%A))/A;

		System.out.println(bcount*B);

	}

}


Measured memory_bytes: 21204
// ayy
// ' lamo
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld; //CARE
typedef complex<ld> pt;
#define fi first
#define se second
#define pb push_back
const ld eps=1e-8;
const int inf=1e9+99;
const ll linf=1e18+99;
const int P=1e9+7;













int32_t main() {
	string s; cin>>s;
	cout<<(s.substr(0,4)=="YAKI" ? "Yes" : "No")<<endl;
}













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

int main(){
    int n, c;
    cin >> n >> c;
    vector<int> num(100'002, 0);
    vector<vector<bool>> checks(30, vector<bool>(100'002, false));
    int s, t, ch;
    for (int i = 0; i < n; i++){
        cin >> s >> t >> ch;
        if (checks[ch-1][s]) s++;
        else checks[ch-1][s] = true;
        if (checks[ch-1][t]) t--;
        else checks[ch-1][t] = true;
        num[s]++;
        num[t+1]--;
    }
    for (int i = 0; i < 100'001; i++){
        num[i+1] += num[i];
    }
    int ans = 0;
    for (int i = 0; i <= 100'000; i++){
        ans = max(ans, num[i]);
    }
    cout << ans << endl;
}





Measured memory_bytes: 1152
N = int(input())

L = [0] * 100

for i in range(1,N+1):
    if i % 10 == 0:
        continue
    a = (i // (10 ** (len(str(i)) - 1))) * 10 + i % 10
    L[a] += 1
    
ans = 0
for i in range(100):
    if L[i] == 0:
        continue
    if i // 10 == i % 10:
        ans += L[i] ** 2
    else:
        a = i // 10 + (i % 10) * 10
        ans += L[i] * L[a]

print(ans)    

Measured memory_bytes: 3064
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <numeric>
typedef long long int ll;
using namespace std;
int main(){
	ll N,M;
	int count=0;
	cin >> N>>M;
	if(N==1){
		if(M==1){
			cout<<1<<endl;
			return 0;
		}else{
			cout<<M-2<<endl;
			return 0;
		}
	}else if(M==1){
		cout<<N-2<<endl;
		return 0;
	}else{
		cout<<(N-2)*(M-2)<<endl;
		return 0;
	}
}

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

int main() {
  int N;
  cin >> N;
  for(int i=1;i<10;i++) {
    if(N <= i*100 + i * 10 + i) {
      cout << i*100 + i * 10 + i << endl;
      break;
    }
  }
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
 
using namespace std;
 
int main() {
	FAST;

	int a,b;
	cin >> a >> b;

	int n = 999;
	int tower[1000];
	tower[0] = 0;
	rep(i,1,n) tower[i] = tower[i-1] + i;

	int len = b-a;

	int res = tower[len-1] - a;

	cout << res << "\n";

	return 0;
}

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

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

#define INF 2e9
#define ALL(v) v.begin(), v.end()

int main(){
  int n;
  int a[110];
  cin>>n;
  rep(i,n){
    cin>>a[i];
  }
  sort(a,a+n,greater<int>());
  int alice=0;
  int bob=0;
  rep(i,n){
    if(i%2==0){
      alice+=a[i];
    }
    else{
      bob+=a[i];
    }
  }
  cout<<alice-bob<<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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,l;
  cin >> n >> l;
  vector<string> vs(n);
  REP(i,n) cin >> vs[i];
  sort(ALL(vs));
  REP(i,n) cout << vs[i];
  
  return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	k, x := nextInt(), nextInt()
	if 500*k >= x {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

func nextByte() []byte {
	sc.Scan()
	return sc.Bytes()
}

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


Measured memory_bytes: 640
#include <stdio.h>
int c,gx,gy;
char map[20][20];
void check(int x,int y)
{
  int n;
  //    printf("check %d %d \n",x,y);
  map[x][y]='#';
  c++;
 
  if(x+1<gy && map[x+1][y]=='.')
      check(x+1,y);
  if(x>0 && map[x-1][y]=='.')
      check(x-1,y);
  if(y+1<gx && map[x][y+1]=='.')
      check(x,y+1);
  if(y>0 && map[x][y-1]=='.')
      check(x,y-1);
}

int main()
{
  int n,m,x,y;
  for(;scanf("%d%d",&gx,&gy),gx;)
    {
      //      puts("start");
      for(x=0;x<20;x++)
      for(y=0;y<20;y++)
	map[x][y]='#';
      for(n=0;n<gy;n++)
	{
	  //  printf("now %d\n",n);
	  scanf("%s",map[n]);
	  for(m=0;m<gx;m++)
	    if(map[n][m]=='@')
	      {
		x=n,y=m;
	      }


	}
      //      puts("scan end");
      //      for(n=0;n<gy;n++)
      //	puts(map[n]);

      c=0;
      check(x,y);
     printf("%d\n",c);
     // for(n=0;n<gy;n++)
	//	puts(map[n]);

    }
  exit(0);
}

Measured memory_bytes: 0