akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// gcd, lcm
ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

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


int main() {
    ll n, m, q;
    cin >> n >> m >> q;
    vector<vector<ll>> vec;
    vec = vector<vector<ll>>(n, vector<ll>(n, 0));
    REP(i, m) {
        ll l, r;
        cin >> l >> r;
        l--;
        r--;
        vec[l][r]++;
    }
    FOR(i, 1, n) {
        REP(j, n - i) {
            vec[j][j + i] = vec[j][j + i] + vec[j][i + j - 1] + vec[j + 1][i + j] - vec[j + 1][i + j - 1];
        }
    }
    vector<ll> ans;
    REP(i, q) {
        ll c, d;
        cin >> c >> d;
        c--;
        d--;
        ans.push_back(vec[c][d]);
    }
    for (ll a : ans) {
        cout << a;
        RN
    }
    return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;

int D, G;
vector<int> p,c;


int ans = 10000000;



void dfs(int i, int n, int sc){
    
    if (i==0) {
        if(sc <= 0) ans = min(ans, n);
    }else{
        
        if (sc > 0) {
            
            dfs(i-1, n, sc);
            
            int ss = sc;
            
            if (ss/(100*i) < p[i-1]) {
                if (ss%(100*i) == 0) {
                    dfs(i-1, n += (ss/(100*i)), sc -= (p[i-1]*100*i));
                }else{
                    dfs(i-1, n += (ss/(100*i) + 1), sc -= (p[i-1]*100*i));
                }
                
            }else{
                dfs(i-1, n += p[i-1], sc -= (p[i-1]*(100*i)+c[i-1]));
                
            }
            
        }else{
            dfs(i-1, n, sc);
        }
        
        
        
    }
    
    
    
    
    
    
    
}



int main()
{
    cin >> D >> G;
    p.assign(D, 0);
    c.assign(D, 0);
    rep(i, D) cin >> p[i] >> c[i];
    
    
    
    dfs(D, 0, G);
    
    cout << ans << endl;
    
    
    return 0;
}



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int a,b,t;
	cin>>a>>b>>t;
	cout<<b*(t/a)<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x1 = sc.nextInt();
    int y1 = sc.nextInt();
    int x2 = sc.nextInt();
    int y2 = sc.nextInt();
    int x3 = x2+y1-y2;
    int y3 = y2+x2-x1;
    int x4 = x1+y1-y2;
    int y4 = y1+x2-x1;
    System.out.printf("%d %d %d %d\n", x3, y3, x4, y4);
  }
}

Measured memory_bytes: 35852
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
typedef long long ll;
static const ll MAX = 110000;
static const ll NIL = -1;

ll n;
vector<ll> G[MAX];
ll color[MAX];

void dfs(ll r, ll c) {
  stack<ll> S;
  S.push(r);
  color[r] = c;
  while (!S.empty()) {
    ll u = S.top(); S.pop();
    for (ll i = 0; i < G[u].size(); i++) {
      ll v = G[u][i];
      if (color[v] == NIL) {
        color[v] = c;
        S.push(v);
      }
    }
  }
}

void assignColor() {
  ll id = 1;
  for (ll i = 0; i < n; i++) color[i] = NIL;
  for (ll u = 0; u < n; u++) {
    if (color[u] == NIL) dfs(u, id++);
  }
}

int main() {
  ll s, t, m, q;
  cin >> n >> m;
  for (ll i = 0; i < m; i++) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin >> q;

  for (ll i = 0; i < q; i++) {
    cin >> s >> t;
    if (color[s] == color[t]) {
      cout << "yes" << endl;
    }
    else {
      cout << "no" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 9996
#include <bits/stdc++.h>
#define FOR(i, n) for (int i = 0; i < n; i++) 

using namespace std;

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

int main() {
  int n; scanf("%d", &n);
  int a[n];
  int x[n][n], y[n][n];
  FOR(i, n) {
    scanf("%d", a + i);
    FOR(j, a[i]) {
      scanf("%d%d", &x[i][j], &y[i][j]);
      x[i][j]--;
    }
  }
  int maxi = 0;
  FOR(mask, (1<<n)) {
    int sum = 0;
    bool bl = true;
    FOR(i, n) {
      bool isTrue = (mask & (1<<i)) > 0;
      if (!isTrue) continue;
      sum++;

      FOR(j, a[i]) {
        bool k = y[i][j];
        if (!isTrue) k = !k;
        bool stoKaze = (mask & (1<<(x[i][j]))) > 0;
        if (k != stoKaze) bl = false;
      }
    }
    if (!bl) continue;
    maxi = max(maxi, sum);
  }
  printf("%d\n", maxi);
  return 0;
}


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

int main () {
  vector<vector<char>> data(2,vector<char>(3));
  for (int i = 0; i < 2; i++) {
    for (int j =0; j < 3; j++) {
      cin >> data.at(i).at(j);
    }
  }
  if (data.at(0).at(0)==data.at(1).at(2)&&
      data.at(0).at(1)==data.at(1).at(1)&&
      data.at(0).at(2)==data.at(1).at(0)) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
from collections import deque
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())),reverse=True)
q=sorted(list(map(int,input().split())),reverse=True)
r=deque(sorted(list(map(int,input().split())),reverse=True))
p=deque(p[:x])
q=deque(q[:y])
ans=sum(p)+sum(q)

while p[-1]<r[0] or q[-1]<r[0]:
  if p[-1]<q[-1]:
    ans+=r[0]-p[-1]
    r.popleft()
    p.pop()
  else:
    ans+=r[0]-q[-1]
    r.popleft()
    q.pop()
  if p==deque([]) or q==deque([]) or r==deque([]):
    break
if r==deque([]):
  pass
elif p==deque([]):
  while q[-1]<r[0]:
    ans+=r[0]-q[-1]
    r.popleft()
    q.pop()
    if q==deque([]) or r==deque([]):
      break
elif q==deque([]):
  while p[-1]<r[0]:
    ans+=r[0]-p[-1]
    r.popleft()
    p.pop()
    if p==deque([]) or r==deque([]):
      break
  
print(ans)

Measured memory_bytes: 105892
main = do
	cs <- getLine
	let w:h:x:y:r:_ = toIntList cs
	putStrLn $ if inRange w x r && inRange h y r then "Yes" else "No"

toIntList :: String -> [Integer]
toIntList = map read . words

inRange :: Integer -> Integer -> Integer -> Bool
inRange range origin offset = 0 <= (origin - offset) && (origin + offset) <= range


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 30;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};



int main()
{
  int n, ma, mb; cin >> n >> ma >> mb;
  vector<int> a(n), b(n), c(n);
  rep(i, n) cin >> a[i] >> b[i] >> c[i];
  int dp[n+1][410][410];
  rep(i, n+1) rep(j, 410) rep(k, 410) dp[i][j][k] = INF;
  dp[0][0][0] = 0;

  rep(i, n) {
    for(int ca = 0; ca <= 400; ++ca) {
      for(int cb = 0; cb <= 400; ++cb) {
        if(ca+a[i] <= 400 && cb+b[i] <= 400) {
          chmin(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
        }
        chmin(dp[i+1][ca][cb], dp[i][ca][cb]);
      }
    }
  }
  int ans = INF;
  for(int ca = 1; ca <= 400; ++ca) {
    for(int cb = 1; cb <= 400; ++cb) {
      if(ca*mb == cb*ma) chmin(ans, dp[n][ca][cb]);
    }
  }
  if(ans != INF) cout << ans << endl;
  else cout << -1 << endl;
}

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

int main() {
	long long N;
	string s;
	cin >> N;
	cin >> s;
	int count = 0;
	int result = 0;
	for (int i = 0; i < N; i++) {
		if (s[i] == 'R') {
			count++;
		}
	}
	result = count;
	for (int i = 0; i < count; i++) {
		if (s[i] == 'R') {
			result--;
		}
	}
	cout << result << "\n";
	return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h> 
using namespace std; 
  
// Function to find the minimum number of 
// characters to be replaced in string S2, such 
// that S1 is a substring of S2 
int minimumChar(string S1, string S2) 
{ 
    // Get the sizes of both strings 
    int n = S1.size(), m = S2.size(); 
  
    int ans = INT_MAX; 
  
    // Traverse the string S2 
    for (int i = 0; i < m - n + 1; i++) { 
        int minRemovedChar = 0; 
  
        // From every index in S2, check the number of 
        // mis-matching characters in substring of 
        // length of S1 
        for (int j = 0; j < n; j++) { 
            if (S1[j] != S2[i + j]) { 
                minRemovedChar++; 
            } 
        } 
  
        // Take minimum of prev and current mis-match 
        ans = min(minRemovedChar, ans); 
    } 
  
    // return answer 
    return ans; 
} 
  
// Driver Code 
int main() 
{ 
    string S1;
    
    string S2;
    
    cin>>S1>>S2;
    
    
  
    cout <<minimumChar(S2, S1); 
  
    return 0; 
} 

Measured memory_bytes: 3628
//ABC 176 D--Wizard in Maze
//题目地址：https://atcoder.jp/contests/abc176/tasks/abc176_d
//题解地址：https://atcoder.jp/contests/abc176/editorial/79

#include <bits/stdc++.h>
using namespace std;
#define INF 1000000005
typedef long long ll;
typedef pair<ll,ll> P;

int main() {
	ll h,w,cx,cy,dx,dy;
	cin >> h >> w >> cx >> cy >> dx >> dy;
	cx--;
	cy--;
	dx--;
	dy--;
	string s[h];
	for (ll i = 0; i < h; i++) cin >> s[i];
	deque<P> que;

	que.push_back(P(cx, cy));
	bool visited[h][w];
	ll d[h][w];
	for (ll i = 0; i < h; i++) {
		fill(visited[i], visited[i] + w, false);
		fill(d[i], d[i] + w, INF);
	}
	d[cx][cy] = 0;
	visited[cx][cy] = true;

	while(!que.empty()) {
		P p = que.front();
		ll X = p.first, Y = p.second;
		if (X == dx and Y == dy) {
			cout << d[X][Y] << endl;
			return 0;
		}
		visited[X][Y] = true;
		que.pop_front();
		for (ll i = -2; i < 3; i++)
			for (ll j = -2; j < 3; j++) {
				ll x = X + i, y = Y + j;
				if (x < h and x >= 0 and y < w and y >= 0 and s[x][y] == '.') {
					if (visited[x][y]) continue;
					if (abs(i) + abs(j) < 2) {
						que.push_front(P(x, y));
						d[x][y] = d[X][Y];
						visited[i][j] = true;
					} else {
						if (d[X][Y] + 1 < d[x][y]) {
							d[x][y] = d[X][Y] + 1;
							que.push_back(P(x, y));
						}
					}
				}
			}
	}

	cout << -1 << endl;
	return 0;
}



Measured memory_bytes: 14328
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;
vector<int64_t> par(100007);
vector<int64_t> sz(100007);

void init(int64_t n){
  rep(i,n) {
    par[i] = i;
    sz[i] = 1;
  }
}

int64_t root(int64_t x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = root(par[x]);
  }
}

bool same(int64_t x,int64_t y){
  return root(x) == root(y);
}

void unite(int64_t x,int64_t y){
  x = root(x);
  y = root(y);
  if(x == y) return;
  sz[y] = sz[x] + sz[y];
  par[x] = y;
}

int64_t calc_size(int64_t x){
  return sz[root(x)];
}

int main(){
  int64_t n,m,k;
  cin >> n >> m >> k;
  vector<int64_t> num(n);
  init(n);
  rep(i,m){
    int64_t a,b;
    cin >> a >> b;
    unite(a-1,b-1);
    num[a-1]--;
    num[b-1]--;
  }
  rep(i,n){
    num[i] += calc_size(i);
  }
  /*rep(i,n){
    cout << calc_size(i) << " " << endl;
  }*/
  rep(i,k){
    int64_t c,d;
    cin >> c >> d;
    if(same(c-1,d-1)){
      num[c-1]--;
      num[d-1]--;
    }
  }
  rep(i,n){
    cout << num[i]-1 << " ";
  }
    
  
    
  
}

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

template <int mod>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const {
    return ModInt(*this) += p;
  }
  ModInt operator-(const ModInt &p) const {
    return ModInt(*this) -= p;
  }
  ModInt operator*(const ModInt &p) const {
    return ModInt(*this) *= p;
  }
  ModInt operator/(const ModInt &p) const {
    return ModInt(*this) /= p;
  }
  bool operator==(const ModInt &p) const {
    return x == p.x;
  }
  bool operator!=(const ModInt &p) const {
    return x != p.x;
  }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ans(1), mul(x);
    while(n) {
      if(n & 1) ans *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ans;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

long long n;
vector<long long> a, dp;

ModInt<MOD> solve();

int main() {
  cin >> n;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

ModInt<MOD> solve() {
  ModInt<MOD> ans = 1;
  dp.assign(n + 3, 0);
  dp[0] = 3;
  for(int i = 0; i < n; ++i) {
    ans *= dp[a[i]];
    --dp[a[i]];
    ++dp[a[i] + 1];
  }
  return ans;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, m;
    cin >> n >> m;

    vector<vector<int>> dp(m+1, vector<int>(1 << n, inf));
    dp[0][0] = 0;

    REP(i, m){
        REP(j, (1 << n)) dp[i+1][j] = dp[i][j];
        int a, b;
        cin >> a >> b;
        int bit = 0;
        REP(j, b){
            int c;
            cin >> c;
            c--;
            bit |= (1 << c);
        }
        REP(j, (1 << n)){
            if(dp[i][j] == inf) continue;
            chmin(dp[i+1][j | bit], dp[i][j] + a);
        }
    }

    cout << (dp[m].back() == inf ? -1 : dp[m].back()) << endl;

    return 0;
}


Measured memory_bytes: 16256
import java.util.ArrayDeque

fun main(args: Array<String>) {
    val mod = 1000000007L
    val (N, K) = readInputLine().split(" ").let { Pair(it[0].toInt(), it[1].toLong()) }

    val next = Array(N + 1) { mutableListOf<Int>() }

    for (i in 1 until N) {
        val (a, b) = readInputLine().split(" ").map { it.toInt() }
        next[a].add(b)
        next[b].add(a)
    }

    val checked = BooleanArray(N + 1)
    val queue = ArrayDeque<Int>(N)
    checked[1] = true

    var ans = K

    for (i in 1..next[1].size) {
        ans *= K - i
        ans %= mod
    }

    for (node in next[1]) {
        queue.add(node)
        checked[node] = true
    }

    while (queue.isNotEmpty()) {
        val s = queue.poll()!!

        var cnt = 1

        for (node in next[s]) {
            if (!checked[node]) {
                ans *= K - cnt - 1
                ans %= mod
                cnt++
                queue.add(node)
                checked[node] = true
            }
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


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



int main() 
{ 
	
	int n;
	cin>>n;
	vector<int> numbers(n);
	vector<int> occ(n+1,0);
	for(int i=0;i<n;i++){
		cin>>numbers[i];
		occ[numbers[i]]++;
	}
	long long s =0;
	for(int i=0;i<n+1;i++){
		s = s +((((long long) occ[i])*(occ[i]-1))/2);
	}
	for(int i = 0;i<n;i++){
		long long a = s - (occ[numbers[i]]-1);
		cout<<a<<endl;
	}

	
    return 0; 
} 


Measured memory_bytes: 4096
#include<cstdio>
#include<vector>
struct Edge{
    int l,r;
    long long c;
    Edge(){}
    Edge(int l,int r,long long c):l(l),r(r),c(c){}
};
std::vector<Edge>g[100005];
Edge check[200005];
int vis[100005];
long long value[100005];

void dfs(int u){
    vis[u] = 1;
    for(Edge e: g[u]){
        if(!vis[e.r]){
            value[e.r] = value[u]+e.c;
            dfs(e.r);
        }
    }
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 0; i < m; i++){
        int l,r; long long c;
        scanf("%d%d%lld",&l,&r,&c);
        g[l].push_back(Edge(l,r,c));
        g[r].push_back(Edge(r,l,-c));
        check[i] = Edge(l,r,c);
    }
    for(int i = 1; i <= n; i++){
        if(!vis[i]){
            value[i] = 0;
            dfs(i);
        }
    }
    int ok = 1;
    for(int i = 0; i < m; i++){
        int u = check[i].l, v = check[i].r;
        long long c = check[i].c;
        if(value[u]+c!=value[v]){
            ok = 0;
        }
    }
    if(ok) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 22900
#include<iostream>
#include<string>

using namespace std;

int main(){
	int n;
	string s, t;
	cin >>n >>s >>t;
	
	int ans = 0;
	for(int cmn = n; cmn >= 0; --cmn){
		string pfx = t.substr(0,cmn);
		string sfx = s.substr(n-cmn);
		if(pfx == sfx && 2*n-cmn >= n){
			ans = 2*n-cmn;
			break;
		}
	}
	cout <<ans <<'\n';
	return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
 int main(){
  int a,b,c,d,e;
  int X;
  cin>>a>>b>>c>>d>>e;
   if(a==0){
     X=1;
   }
   else if(b==0){
     X=2;
   }
   else if(c==0){
     X=3;
   }
   else if(d==0){
     X=4;
   }
   else{
     X=5;
   }
    cout<<X<<endl;
 }

Measured memory_bytes: 3564
fn main() {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s);
  let mut hp = s.trim().parse::<u64>().unwrap();
  let _hp = hp.clone();
  let mut done = false;
  let mut divided = 0;
  let mut result:u64 = 0;
  while !done {
    hp /= 2;
    result += 2u64.pow(divided);
    divided += 1;
    if hp == 0 {
      done = true;
    }
  }

  println!("{}",result);
}


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

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> point(n) ;
    rep(i, n) point[i] = 0;

    vector<int> a(q);
    for(int i=0; i<q; i++){
        cin >> a[i];
        point[a[i]-1]++;
    }
    for(int i=0; i<n; i++){
        if(point[i]>q-k)
            cout << "Yes" << endl;
        else
        {
            cout << "No" << endl;
        }   
    }
    return 0;
}

Measured memory_bytes: 4032
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
  string str;
  std::vector<char*> s,ans;
  char saisyo,saigo;
  int len,i=0;

  cin>>str;

  len=str.size();
  len-=2;
  saisyo=str[0];
  while(str[i]!='\0'){
    i++;
  }
  i--;
  saigo=str[i];

  cout<<saisyo<<len<<saigo<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int fc(vector<string> &s, int si, int sj){
  queue<pair<int, int>> q;
  int h = s.size(), w = s.front().size();
  vector<vector<int>> d(h, vector<int>(w, -1));
  q.push({si, sj});
  int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
  d.at(si).at(sj) = 0;
  int res = 0;
  while(!q.empty()){
    auto now = q.front(); q.pop();
    rep(i, 4){
      int ni = now.first + dy[i], nj = now.second + dx[i];
      if(nj < 0 || w <= nj || ni < 0 || h <= ni) continue;
      if(d.at(ni).at(nj) != -1 || s.at(ni).at(nj) == '#') continue;
      d.at(ni).at(nj) = d.at(now.first).at(now.second) + 1;
      res = max(res, d.at(ni).at(nj));
      q.push({ni, nj});
    }
  }
  return res;
}

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s.at(i);
  
  int ans = 0;
  rep(i, h){
    rep(j, w){
      if(s.at(i).at(j) == '.'){
        ans = max(ans, fc(s, i, j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

int main() {
    int N;
    cin >> N;
    int x = 0, y = 0, z = 0;
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if(a % 4 == 0) {
            x++;
        } else if(a % 2 == 0) {
            y++;
        } else {
            z++;
        }
    }
    x -= z;
    if(x < -1 || x == -1 && y > 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


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

using namespace std;

int main(){
  size_t N;
  cin >> N;

  vector<size_t> num(N);
  for(size_t i = 0; i < N; ++i)cin >> num.at(i);

  vector<pair<size_t,size_t>> pairs{};

  for(size_t i = 0; i < N; ++i){
    pairs.emplace_back(i + 1, num.at(i));
  }

  sort(pairs.rbegin(),pairs.rend(),[](auto p1, auto p2){ return p1.second >= p2.second;});

  for(auto& it: pairs){
    cout << it.first << " ";
  }
  return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string s, t;cin >> s >> t;
    int n = s.size() + t.size();
    inc(i, 0, n){
        if(i%2 == 0){
            cout << s[i/2];
        }else{
            cout << t[i/2];
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
  ll N;
  cin>>N;
  for(int i=0; i<=7; ++i){
  if(N>=pow(2,i)&&N<pow(2,i+1))
  cout<<pow(2,i)<<endl;
  }
  }
  
  
  

  
  

 


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

#define Debug(x) x
typedef int regular_int;
// #define int ll
typedef long long ll;

int res[300000][2];

regular_int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(12) << fixed;

	string s;
	cin >> s;
	int pos = 0;
	res[0][0] = 1;
	res[1][1] = 1;

	while (pos < s.size()){
        if (pos > 0)
            res[pos][0] = res[pos - 1][1] + 1;
        if (pos > 1){
            res[pos][1] = res[pos - 2][0] + 1;
        }
        if (s[pos] != s[pos - 1]){
            res[pos][0] = max(res[pos][0], (pos >= 1?res[pos - 1][0]: 0) + 1);
        }
        if (pos > 0 && (pos < 3 || s[pos] != s[pos - 2] || s[pos - 1] != s[pos - 3])){
            res[pos][1] = max(res[pos][1], (pos >= 2?res[pos - 2][1]: 0) + 1);
        }

        ++pos;
	}
	cout << max(res[s.size() - 1][0], res[s.size() - 1][1]) << endl;
	return 0;
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  int A, B;
  cin >> A >> B;
  if ((A*B%2) == 0) {
    cout << "No";
  } else {
    cout << "Yes";
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<vector>

using namespace std;
struct Node{
  int value;
  Node *left;
  Node *right;
};

struct Node *NIL;

class BinarySearchTree{
  private:
    Node *root;
  public:
    BinarySearchTree(){
      root=NIL;
    }
    void insert(int value){
      Node *node = (Node*)malloc(sizeof(Node));
      node->value = value;
      node->right = NIL;
      node->left = NIL;
      Node* x=root;
      Node* y=NIL;
      while(x!=NIL){
        y = x;
        if(node->value < x->value){
          x = x->left;
        }
        else{
          x = x->right;
        }
      }
      if(y==NIL)root = node;
      else if(node->value < y->value)y->left = node;
      else y->right = node;
    }
    bool find(int value){
      Node *node = root;
      while(node != NIL){
        if(node->value == value)return true;
        else if(value < node-> value)node = node->left;
        else node = node->right;
      }
      return false;
    }
    void print(){
      inorderWalk(root);
      cout << endl;
      preorderWalk(root);
      cout << endl;
    }
    void inorderWalk(Node *node){
      if(node == NIL)return;
      inorderWalk(node->left);
      cout << ' ' << node->value;
      inorderWalk(node->right);
    }
    void preorderWalk(Node *node){
      if(node == NIL)return;
      cout << ' ' << node->value;
      preorderWalk(node->left);
      preorderWalk(node->right);
    }
};


int main(){
  int n;cin >> n;
  string com;
  BinarySearchTree T;
  for(int i=0;i<n;i++){
    cin >> com;
    if(com == "insert"){
      int num;cin >> num;
      T.insert(num);
    }
    else if(com == "print"){
      T.print();
    }
    else if(com == "find"){
      int num;cin >> num;
      cout << (T.find(num)?"yes": "no") << endl;
    }
  }
}



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
vector<int> g[100005];
int val[100005], sub[100005], ans[100005];
bool rev = 0;
void dfs1(int u, int p, int d){
    if(val[u] != -1){
        sub[u] = 1;
        if((d+rev)%2 != val[u]%2){
            printf("No\n");
            exit(0);
        }
    }
    for(int i=0;i<sz(g[u]);i++){
        int v = g[u][i];
        if(v == p) continue;
        dfs1(v, u, d+1);
        sub[u] += sub[v];
    }
}
int L[100005], R[100005];
void dfs2(int u, int p, int d){
    L[u] = -2e6, R[u] = 2e6;
    if(val[u] != -1){
        L[u] = val[u];
        R[u] = val[u];
    }
    for(int i=0;i<sz(g[u]);i++){
        int v = g[u][i];
        if(v == p) continue;
        dfs2(v, u, d+1);
        L[u] = max(L[u], L[v]-1);
        R[u] = min(R[u], R[v]+1);
    }
    if((d+rev)%2 != (L[u]%2+2)%2) L[u]++;
    if((d+rev)%2 != (R[u]%2+2)%2) R[u]--;
    if(L[u] > R[u]){
        printf("No\n");
        exit(0);
    }
    else if(val[u] != -1 && (val[u] < L[u] || val[u] > R[u])){
        printf("No\n");
        exit(0);
    }
}
void dfs3(int u, int p, int d){
    if(val[u] != -1) ans[u] = val[u];
    else{
        if(L[u] <= ans[p]-1 && ans[p]-1 <= R[u]) ans[u] = ans[p]-1;
        else ans[u] = ans[p]+1;
    }

    for(int i=0;i<sz(g[u]);i++){
        int v = g[u][i];
        if(v == p) continue;
        dfs3(v, u, d+1);
    }
}
int main(){
    int n, k;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) val[i] = -1;
    for(int i=1;i<=n-1;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].eb(b);
        g[b].eb(a);
    }
    scanf("%d", &k);
    int r = 0;
    for(int i=1;i<=k;i++){
        int v, p;
        scanf("%d%d", &v, &p);
        val[v] = p;
        r = v;
    }
    if(val[r]%2 == 1) rev = 1;
    dfs1(r, 0, 0);
    dfs2(r, 0, 0);
    dfs3(r, 0, 0);
    printf("Yes\n");
    for(int i=1;i<=n;i++) printf("%d\n", ans[i]);
}

Measured memory_bytes: 20368
from collections import deque
N, Q = map(int, input().split())

#木の作成
tree = [ [] for _ in range(N+1)]
for n in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

#カウンターの作成
counter = [ 0 for _ in range(N+1)]
for q in range(Q):
    p, x = map(int, input().split())
    counter[p] += x
    
mydeaue = deque()
mydeaue.append(1)

checklist = [0 for _ in range(N+1)]
while (mydeaue):
    i = mydeaue.pop()
    checklist[i] = 1
    for j in tree[i]:
        if checklist[j] == 1:
            continue
        counter[j] += counter[i]
        mydeaue.append(j)
    #print(i)
print(' '.join(map(str, counter[1:])))

Measured memory_bytes: 67164
def find(x): #要素がどの集合か判断
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y): #集合に結合
    x = find(x)
    y = find(y)
    if x == y: return False
    if par[x] > par[y]: x,y = y,x
    par[x] += par[y]
    par[y] = x
    return True

import bisect
n, m = map(int, input().split())
par = [-1]*n

for _ in range(m):
    x, y, z = map(int, input().split())
    unite(x-1, y-1)
par.sort()
print(bisect.bisect_left(par, 0))

Measured memory_bytes: 11800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> d(N);
  rep(i, N) cin >> d[i];

  std::sort(d.begin(), d.end());

  cout << d[N / 2] - d[N / 2 - 1] << endl;

  return 0;
}


Measured memory_bytes: 640
from sys import stdin
def ip(): return [int(i) for i in stdin.readline().split()]
def sp(): return [str(i) for i in stdin.readline().split()]


def ti(i,j,k):
    if i == j or i == k or j == k: 
        return False
    if (i+j) > k and (i+k) > j and (j+k) > i:
        return True
    return False

def solve(A):
    if len(A) < 3: return 0
    ans = 0
    for i in range(len(A)):
        for j in range(i+1, len(A)):
            for k in range(j+1, len(A)):
                if ti(A[i], A[j], A[k]):
                    ans += 1
    return ans

n = input()
A = ip()
print(solve(A))

Measured memory_bytes: 9228
def solve():
    K, S = [int(x) for x in input().split()]
    res = 0
    for x in range(K + 1):
        for y in range(K + 1):
            z = S - x - y
            if 0 <= z <= K:
                res += 1
    return res

if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 40940
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main(){
string st;
int n;
while(1){
cin>>n;if(n==0)break;
bool l=false,r=false,p=false;
int c=0;

for(int i=0;i<n;i++)
{
cin>>st;
if(st=="ru")r=true;
if(st=="rd")r=false;
if(st=="lu")l=true;
if(st=="ld")l=false;
if(r&&l&&p==false){c++;p=true;}
if(r==false&&l==false&&p==true){c++;p=false;}
}
cout<<c<<endl;
}
return 0;
}

Measured memory_bytes: 1208
while True:
    a,op,b=input().split()
    a = int(a)
    b = int(b)
    if op=="+":
        print(a+b)
    elif op=="-":
        print(a-b)
    elif op=="*":
        print(a*b)
    elif op=="/":
        print(a//b)
    else:
        break


Measured memory_bytes: 5592
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define xxx         exit(0);
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;

}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) {
    return (ll)(log(x) / log(base));
}
ll a[3005],dp[3005][3005][2]; ll n;
ll E(ll st, ll ed, ll p)
{
	if(st==ed)
	{
		if(p==1) return dp[st][ed][p] = -1*a[st];
		else return dp[st][ed][p] = a[st];
	}
	if(dp[st][ed][p] != -1) return dp[st][ed][p];
	ll ans=0;
	if(p)
		ans=min(-1*a[st]+E(st+1,ed,!p),-1*a[ed]+E(st,ed-1,!p));
	else
		ans=max(a[st]+E(st+1,ed,!p),a[ed]+E(st,ed-1,!p));
	return dp[st][ed][p]=ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,k,l,m,h,w,val;
    	cin>>n;
    	rep(i,0,n) cin>>a[i];
		repi(i,0,n){
			repi(j,0,n) { dp[i][j][0]=-1; dp[i][j][1]=-1;}
		} 
		cout<<E(0,n-1,0);
	}
	return 0;
}


Measured memory_bytes: 144768
local s = io.read()

local function getAAA(str)
	local len = string.len(str)
	local p = string.find(str, "A")
	if not p then
		return 0
	end
	local p2 = string.find(str, "Z[[a-y]*[A-Y]*$")
	if not p2 then
		return 0
	end
	local n = len - p - (len - p2) + 1
	return n
end

local n = getAAA(s)
print(n)

Measured memory_bytes: 888
ARGF.each_line do |line|
  h, w = line.split.map(&:to_i)
  break if (h == 0) && (w == 0)
  i = 0
  loop do
    i += 1
    if i > h
      puts
      break
    elsif i.odd?
      w.times{|n| print n.odd? ? "." : "#"}
      puts
    else
      w.times{|n| print n.odd? ? "#" : "."}
      puts
    end
  end
end

Measured memory_bytes: 6104
A, B, C = map(int, input().split())
K = int(input())

for i in range(K + 1):
  for j in range(0, K + 1 - i):
    b = B * (2 ** i)
    c = C * (2 ** j)
    if A < b < c:
      print("Yes")
      quit()
      
print("No")
    

Measured memory_bytes: 9168
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  int h, a;
  cin >> h >> a;
  int ans = 0;
  if(h % a == 0) {
    ans = h / a;
  } else {
    ans = h / a;
    ++ans;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] numbers = new int[N];
		
		for(int j = 0; j  <numbers.length; j++) {
			numbers[j] = sc.nextInt();
		}
		
		int max = numbers[0];
		int min = numbers[0];
		
		for(int i = 1; i < numbers.length; i++ ) {
			if(numbers[i] > max ) {
				max = numbers[i];
			}
			if(numbers[i] < min ) {
				min = numbers[i];
			}
		}
		System.out.println(max-min);
	}

}


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

int n,m,deg[100010],a[100010];
vector<int> v[100010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n+m-1;i++){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		//g[y].push_back(x);
		deg[y]++;
	}
	int root=-1;
	for(int i=1;i<=n;i++) if(deg[i]==0){
		root=i;
		break;
	}
	queue<int> q;
	q.push(root);
	while(!q.empty())
	{
		int t=q.front();
		q.pop();
		for(int i=0;i<v[t].size();i++){
			int pos=v[t][i];
			deg[pos]--;
			if(deg[pos]==0){
				a[pos]=t;
				q.push(pos);
			}
		}
	}
	for(int i=1;i<=n;i++) cout<<a[i]<<endl;
	return 0;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

struct state{
    int ly, lx, ry, rx;
};
int w, h;
bool contain(int y, int x){
    return (0 <= y && y < h && 0 <= x && x < w);
}
int dy[4] = {1, -1, 0, 0};
int dx[4] = {0, 0, 1, -1};
bool f[51][51][51][51];

signed main(){
    while(1){
        cin >> w >> h;
        if(w + h == 0) break;
        vector<string> s(h), t(h);
        bool ans = false;
        int lsy, lsx, lgy, lgx, rsy, rsx, rgy, rgx;
        rep(i, 0, h){
            cin >> s[i] >> t[i];
            rep(j, 0, w){
                if(s[i][j] == 'L'){ lsy = i; lsx = j;}
                if(s[i][j] == '%'){ lgy = i; lgx = j;}
                if(t[i][j] == 'R'){ rsy = i; rsx = j;}
                if(t[i][j] == '%'){ rgy = i; rgx = j;}
            }
        }
        queue<state> q;
        q.push((state){lsy, lsx, rsy, rsx});
        rep(i, 0, 51) rep(j, 0, 51) rep(k, 0, 51) rep(l, 0, 51) f[i][j][k][l] = false;
        f[lsy][lsx][rsy][rsx] = true;
        while(!q.empty()){
            state p = q.front(); q.pop();
            // cout << p.ly << " " << p.lx << " " << p.ry << " " << p.rx << endl;
            rep(i, 0, 4){
                int nly = p.ly + dy[i];
                int nlx = p.lx + dx[i];
                int nry = p.ry + dy[i];
                int nrx = p.rx - dx[i];
                if(!contain(nly, nlx) || s[nly][nlx] == '#'){ nly = p.ly; nlx = p.lx;}
                if(!contain(nry, nrx) || t[nry][nrx] == '#'){ nry = p.ry; nrx = p.rx;}
                if(f[nly][nlx][nry][nrx]) continue;
                f[nly][nlx][nry][nrx] = true;
                if(s[nly][nlx] == '%' && t[nry][nrx] == '%'){ ans = true; break;}
                else if(s[nly][nlx] == '%' || t[nry][nrx] == '%') continue;
                q.push((state){nly, nlx, nry, nrx});
            }
            if(ans == true) break;
        }
        cout << (ans ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 11340
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int a,b;
int main()
{
    cin>>a>>b;
    int n = b;
    int k;
    if(b==100)k=1000;
    else if(b<10)k=10;
    else k=100;
    n+=a*k;
    int now = sqrt(n+0.5);
    int x = now*now;
    if(x==n)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int i,k,N,M,idx = 0;
    scanf("%d %d",&N,&M);
    int A[N],B[M],cnt[N],win;
    for(i = 0; i < N; i ++ ){
        scanf("%d",&A[i]);
        cnt[i] = 0;
        
        
    }
    win = cnt[0];
    for(k = 0; k < M; k ++ ){
        scanf("%d",&B[k]);
    }
    //printf("\n");
    for(k = 0; k < M; k ++ ){
        for(i = 0; i < N; i ++ ){
            if(B[k] >= A[i]){
                cnt[i] ++;
                //printf("%d\n",cnt[i]);
                break;
            }
        }
    }
    
    for(i = 0; i < N; i ++ ){
        for(k = i + 1; k < N; k ++ ){
            //if(i == k)continue;
            if(cnt[i] == cnt[k]){
                cnt[i] ++;
                //printf("%d %d\n",cnt[i],cnt[k]);
               // break;
            }
        }
    }
    for(i = 0; i < N; i ++ ){
        if(win < cnt[i]){
            win = cnt[i];
            idx = i;
        }
        
    }
    //printf("%d\n",cnt[0]);
    //printf("%d\n",cnt[1]);
    printf("%d\n",idx + 1);
    return 0;
}

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

int main() {
    ll n, a, b;
    while  (cin >> n >> a >> b) {
        if ((a ^ b) % 2 == 0) {
            cout << abs(a - b) / 2 << '\n';
        }
        else {
            ll g1 = min(a, b);
            ll left = abs(a - b) / 2;
            ll g2 = min(n - a + 1, n - b + 1);
            cout << min(g1, g2) + left << '\n';
        }
    }
}


Measured memory_bytes: 256
row, col = [True] * 8, [True] * 8
d_pos, d_neg = [True] * 15, [True] * 15
board = [["."] * 8 for _ in range(8)]


def change_state(r: int, c: int, undo: bool = False) -> None:
    if undo:
        row[r] = col[c] = d_pos[r + c] = d_neg[r - c + 7] = True
        board[r][c] = "."
    else:
        row[r] = col[c] = d_pos[r + c] = d_neg[r - c + 7] = False
        board[r][c] = "Q"


def solve_eight_queens(r: int = 0) -> None:
    while r < 8 and not row[r]:
        r += 1
    if r == 8:
        for board_row in board:
            print(*board_row, sep="")
        return
    for c in range(8):
        if not col[c] or not d_pos[r + c] or not d_neg[r - c + 7]:
            continue
        change_state(r, c)
        solve_eight_queens(r + 1)
        change_state(r, c, undo=True)


def main():
    K, *RC = map(int, open(0).read().split())
    for r, c in zip(*[iter(RC)] * 2):
        row[r] = col[c] = d_pos[r + c] = d_neg[r - c + 7] = False
        board[r][c] = "Q"
    solve_eight_queens()


if __name__ == "__main__":
    main()



Measured memory_bytes: 5616
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

for i in range(3):
    for j in range(3):
        if a[i][j] in b:
             a[i][j] = 0

import numpy as np 

arr = np.array(a)

answer = "No"
if (0 in arr.sum(axis=0)) or (0 in arr.sum(axis=1)):
    answer = "Yes"
elif arr.diagonal().sum() == 0 or np.fliplr(arr).diagonal().sum() == 0: # 行列左右反転　fliplr()
    answer = "Yes"

print(answer)

Measured memory_bytes: 12492
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 10000000000000;

template <typename T>
struct Edge
{
    int to;
    T cost;
};

template <typename T>
struct WeightedGraph
{
    int n;
    vector<vector<Edge<T>>> g;
    
    WeightedGraph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to, T cost){
        g[from].push_back((Edge<T>){to, cost});
    }
};

int main()
{
    int n, m;
    ll l;
    cin >> n >> m >> l;
    WeightedGraph<ll> g(n);
    for(int i = 0; i < m; i++){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        g.add_edge(a, b, c);
        g.add_edge(b, a, c);
    }
    P d[305][305];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++) d[i][j] = P(INF, INF);
    }
    for(int r = 0; r < n; r++){
        bool used[305]{0};
        d[r][r] = P(0, -l);
        while(true){
            int u = -1;
            for(int v = 0; v < n; v++){
                if(!used[v] && (u == -1 || d[r][v] < d[r][u])) u = v;
            }
            if(u == -1) break;
            used[u] = true;
            for(Edge<ll> e : g.g[u]){
                int v = e.to;
                if(used[v]) continue;
                ll rest = -d[r][u].second;
                if(e.cost <= rest) d[r][v] = min(d[r][v], P(d[r][u].first, e.cost - rest));
                else if(e.cost <= l) d[r][v] = min(d[r][v], P(d[r][u].first + 1, e.cost - l));
            }
        }
    }
    int q;
    cin >> q;
    while(q--){
        int s, t;
        cin >> s >> t;
        s--; t--;
        if(d[s][t].first == INF) cout << -1 << endl;
        else cout << d[s][t].first << endl;
    }
}


Measured memory_bytes: 7372