akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

int main(){
    int n,m ;
    cin >> n >> m ;
    vector<vector<string> > s(n,vector<string>()) ;
    int p ;
    string judge ;
    for (size_t i = 0; i < m; i++)
    {
        cin >> p >> judge ;
        s.at(p-1).push_back(judge) ;
    }
    int ans = 0;
    int pena = 0 ;
    int nowp = 0 ;
    for (size_t i = 0; i < n; i++)
    {
        nowp = 0 ;
        for (size_t j = 0; j < s.at(i).size(); j++)
        {
            if (s.at(i).at(j) == "AC")
            {
                ans ++ ;
                pena += nowp ;
                break ;
            }else
            {
                nowp ++ ;
            }
            
            
        }
        
    }
    cout << ans << " " << pena << endl ;
}

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

using namespace std;

#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define LL long long
#define ULL unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




LL fact[500005];
const LL mod=1e9+7;

LL BigMod(LL val,LL pow)
{
    LL res = 1;
    val = val % mod;
    while(pow > 0)
    {
        if(pow & 1)res = (res*val) % mod;
        pow = pow >> 1;
        val = (val*val) % mod;
    }
    return res;
}

LL nCr(LL n,LL r)
{
    return fact[n]*BigMod(fact[r]*fact[n-r],mod-2)%mod;
}

LL ModInverse(LL n,LL r)
{
    return fact[n]*BigMod(fact[n-r],mod-2)%mod;
}

int main()
{
    FAST();
    LL i,m,n,ans;
    fact[0]=1;
    for(i=1;i<=500000;i++)fact[i]=(fact[i-1]*i)%mod;
    cin >> n >> m;
    ans=fact[m]*BigMod(fact[m-n],mod-2)%mod;
    ans*=ans;
    ans%=mod;
    for(i=1;i<=n;i++)
    {
        if(i & 1)ans-=(((nCr(n,i)*ModInverse(m,i))%mod)*(ModInverse(m-i,n-i)*ModInverse(m-i,n-i)%mod))%mod;
        else ans+=(((nCr(n,i)*ModInverse(m,i))%mod)*(ModInverse(m-i,n-i)*ModInverse(m-i,n-i)%mod))%mod;
        ans=(ans+mod)%mod;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 7516
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	ll a,b,x;
	cin >> a >> b >> x;
	cout << b / x - a / x + (a % x == 0) << endl;
	return 0;
}

Measured memory_bytes: 3628
/******************************************
/@Author: LeafBelief
/@Date: 2020-04-04
/@Remark:    
/@FileName: solevthie
******************************************/
#include <bits/stdc++.h>
#define CSE(x,y) memset(x,y,sizeof(x))
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

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

const int maxn = 111;
char str[maxn];
int len;

void get_next()
{
    for(int i = 0; i < len; i++)
    {
        if(str[i] <= str[i + 1] && str[i] != '9')
        {
            str[i]++;
            for(int j = i - 1; j >= 0; j--)
                str[j] = max(char(str[j + 1] - 1), '0');
            return;
        }
    }
    if(str[len - 1] == '9')
    {
        for(int i = 0; i < len; i++)
            str[i] = '0';
        str[len++] = '1';
        return;
    }
    else
    {
        str[len - 1]++;
        for(int i = len - 2; i >= 0; i--)
        {
            str[i] = max(char(str[i + 1] - 1), '0');
        }
        return;
    }
    return;
}

int main()
{
    FAST;
    int k;
    cin >> k;
    strcpy(str,"0");
    len = 1;
    while(k--)
    {
        get_next();
    // for(int i = len - 1; i >= 0; i--)
    // {
    //     cout << str[i];
    // }
    // cout << endl;
    }
    for(int i = len - 1; i >= 0; i--)
    {
        cout << str[i];
    }
    cout << endl;
    return 0;
}

// 3234566667


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

int main(){
    long int l;
    long int r;
    cin >> l >> r;
    int min = 2019;
    if(r-l>=2018) min = 0;
    else{
        for(long int i=l;i<r;i++){
            for(long int j=i+1;j<=r;j++){
                long int temp = (i*j)%2019;
                if(min > temp) min = temp;
            }
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#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 rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    ll N, W;
    cin >> N >> W;
    ll w[N], v[N];
    rep(i, N) cin >> w[i] >> v[i];
    ll st = w[0];
    rep(i, N) w[i] -= st;
    ll ans = 0;
    //i個の商品を使うときの価値
    rep2(i, 0, N){
        if(st*i > W) break;
        //dp[i][j]:=i個の商品を使って重さがj以下になるようにしたときの価値の最大値
        ll dp[N+1][3*N+1];
        fill(dp[0], dp[N+1], 0);
        //j個目の商品を使う
        rep(j, N){
            //dp[k][l]からの遷移
            rep3(k, N, 0){
                rep3(l, 3*N, 0){
                    if(k != 0 && dp[k][l] == 0) continue;
                    if(k+1 > N || l+w[j] > 3*N) continue;
                    dp[k+1][l+w[j]] = max(dp[k+1][l+w[j]], dp[k][l]+v[j]);
                }
            }
        }
        ans = max(ans, dp[i][min(3*N, W-st*i)]);
    }
    cout << ans << endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    for (int i=1; i<=5; i++) {
	int x; cin>>x;
	if (x==0) out(i);
    }

    assert(0);
    
    return 0;
}


Measured memory_bytes: 3632
import java.util.*;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long e = sc.nextLong();
		
		List<Long> list = new ArrayList<Long>();
		
		list.add(a);
		list.add(b);
		list.add(c);
		list.add(d);
		list.add(e);
		
		long min = list.stream().min(Comparator.naturalOrder()).orElse(0l);
		double buttom = (double)n / min;
		long buttomMax = (long)Math.ceil(buttom);
		long result = buttomMax + 4;
		System.out.println(result);
	}
}

Measured memory_bytes: 29520
#include<stdio.h>

int main()
{
 int N;
 int i;
 int dig[3];
 scanf("%d",&N);
 
 for(i=N;i<=999;i++)
 {
  dig[2]=i/100;
  dig[1]=(i-dig[2]*100)/10;
  dig[0]=i-dig[2]*100-dig[1]*10;
  if((dig[0]==dig[1])&(dig[1]==dig[2])) break;
 }
 printf("%d\n",i);
 return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  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;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
double PI = 3.141592653589793238;
vector<vector<int>>G(100030);
int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int ans = 1000000000;
	for (int i = 0; i <= max(x, y) ; i++) {
		int sum = a * max((x - i),0) + b * max((y - i),0) + c * 2 * i;
		ans = min(ans, sum);
	}
	cout << ans;
}

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

#define MAX 16777000

int Hash[MAX];
char str[13];

int getChar(char);
int getKey();
int find();
void insert();

int main(){
  int n;
  char com[7];

  scanf("%d" ,&n);
  while(n--){
    scanf("%s %s" ,com ,str);

    if(com[0] == 'i'){
      insert();
    }else{
      if(find()){
	puts("yes");
      }else{
	puts("no");
      }
    }
  }

  return 0;
}

int getChar(char ch){
  if(ch == 'A'){
    return 1;
  }else if(ch == 'C'){
    return 2;
  }else if(ch == 'G'){
    return 3;
  }
  return 4;
}

int getKey(){
  int sum = 0, p = 1, i;

  for(i = 0 ; i < strlen(str) ; i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int find(){
  int key = getKey();

  if(Hash[key]){
    return 1;
  }

  return 0;
}

void insert(){
  Hash[getKey()] = 1;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n,m;cin>>n>>m;
  while(n!=0||m!=0)
  {
    int i;
    vector<int> d(n);
    vector<int> p(n);
    rep(i,n)cin>>d[i]>>p[i];
    vector<pair<int,int>> dp(n);
    rep(i,n)dp[i]=make_pair(p[i],d[i]);
    sort(all(dp));
    reverse(all(dp));
    int now=0;
    while(m>0&&now<n)
    {
      if(m>=dp[now].second)
      {
        m-=dp[now].second;
        dp[now].second=0;
      }
      else if(m>0)
      {
        dp[now].second-=m;
        m=0;
      }
      now++;
    }
    if(m>0)cout<<0<<endl;
    else
    {
      ll ans=0;
      rep(i,n)ans+=dp[i].second*dp[i].first;
      cout<<ans<<endl;
    }
    cin>>n>>m;
  }
}




Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;

int gcd(int, int);

int main(void) {

  int a, b, c;

  cin >> a >> b;

  c = gcd(a, b);

  cout << c << endl;

  return 0;

}

int gcd(int x, int y) {

  int a;

  if(x < y) {

    a = x;
    x = y;
    y = a;

  }

  while(y > 0) {

    a = x % y;
    x = y;
    y = a;

  }

  return x;

}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;


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

    vector<int> A(N);
    vector<int> X(N);
    int sum = 0;
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
        sum += A[i];
    }

    X[0] = sum;
    for (int i = 1; i < N; ++i) {
        if (i % 2 == 1) {
            X[0] -= 2*A[i];
        }
    }
    
    for (int i = 1; i < N; ++i) {
        X[i] = 2*A[i-1] - X[i-1];
    }

    for (int i = 0; i < N; ++i) {
        cout << X[i];
        if (i != N-1) {
            cout << " ";
        }
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

using namespace std;


int main() {
    nl // lofi  
    int a, b, c, d, e;
    cin >> a >> b >> c >> d;
    if(a == 0) {
        cout << 1; return 0;
    }
    if(b == 0) {
        cout << 2; return 0;
    }
    if(c == 0) {
        cout << 3; return 0;
    }
    if(d == 0) {
        cout << 4; return 0;
    }
    if(e == 0) {
        cout << 5; return 0;
    }

} 

Measured memory_bytes: 3644
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)

#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'

using ll = long long;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;


typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

//constexpr long long MOD = (ll) 1e9+7;
constexpr long long MOD = 998244353;

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

struct Edge {
	int to, cap, rev;
	Edge(int _to, int _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
	G[from].push_back(Edge(to, cap, G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}

void dfs(vector<vector<ll>>& g, ll v, ll p, ll x, vector<ll>& con) {
	con[v] += x;
	for (auto next : g[v]) {
		if (next == p) continue;
		dfs(g, next, v, con[v], con);
	}
}

void solve() {
	ll n, q;
	cin >> n >> q;

	vector<vector<ll>> graph(n);
	
	REP(i, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	vector<ll> con(n,0);

	REP(i, q) {
		ll p, x;
		cin >> p >> x;
		p--;
		con[p] += x;
	}

	dfs(graph, 0, -1, 0, con);

	for (auto i : con) cout << i << " ";
	cout << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


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

int main() {
 int N;
 cin >> N;
 vector<int> vec(N-1);
 vector<int> count(N,0);
 for (int i=0; i<N-1; i++) {
 cin >> vec.at(i);
 count.at(vec.at(i)-1) ++;
 } 
 for (int j=0; j<N; j++) {
 cout << count.at(j) << endl;
 }
}

Measured memory_bytes: 4848
#include <iostream>
using namespace std;
int d[6]={1,2,3,5,4,6};

void change_post(int a,int b,int c,int dd,int e,int f){
	d[0]=a; d[1]=b; d[2]=c; d[3]=dd; d[4]=e; d[5]=f;
}

int main(void){
	string s;
	int k,n,sum;
	while(1){
		sum=1;
		change_post(1,2,3,5,4,6);
		cin>>n;
		if(!n) return 0;
		while(n--){
			cin>>s;
			if(s=="North") change_post(d[1],d[5],d[2],d[0],d[4],d[3]);
			else if(s=="East") change_post(d[4],d[1],d[0],d[3],d[5],d[2]);
			else if(s=="West") change_post(d[2],d[1],d[5],d[3],d[0],d[4]);
			else if(s=="South") change_post(d[3],d[0],d[2],d[5],d[4],d[1]);
			else if(s=="Right") change_post(d[0],d[2],d[3],d[4],d[1],d[5]);
			else change_post(d[0],d[4],d[1],d[2],d[3],d[5]);
			sum+=d[0];
		}
		cout<<sum<<endl;
	}
}

	

Measured memory_bytes: 0
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };

LL N, a[112345], b[112345];
LL d[112345], d_1[112345], d_2[112345], score_s, score_f;
std::vector<edge>G[112345];

void dijkstra(LL s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	std::fill(d, d + N + 1, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL v = p.second;
		if (d[v] < p.first) { continue; }
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main()
{
	in >> N;
	rep(i, N - 1)
	{
		in >> a[i] >> b[i];
		G[a[i]].push_back({ b[i],1 });
		G[b[i]].push_back({ a[i],1 });
	}

	dijkstra(1);
	std::copy(d, d + N + 1, d_1);
	dijkstra(N);
	std::copy(d, d + N + 1, d_2);
	rep(i, N)
	{
		if (d_1[i + 1] <= d_2[i + 1]) { ++score_f; }
		else { ++score_s; }
	}

	if (score_f == score_s) { out << "Snuke" << std::endl; }
	else if (score_f > score_s) { out << "Fennec" << std::endl; }
	else if (score_s > score_f) { out << "Snuke" << std::endl; }
	return 0;
}

Measured memory_bytes: 12944
from collections import deque

def main():
    n, m = map(int, input().split())
    to = [[] for _ in range(n+1)]
    for _ in range(m):
        a, b = map(int, input().split())
        to[a].append(b)
        to[b].append(a)
    q = deque([1])
    ans = [None]*(n+1)
    while q:
        p = q.pop()
        for child in to[p]:
            if ans[child] is None:
                ans[child] = p
                q.appendleft(child)
    print("Yes")
    print("\n".join(list(map(str, ans[2:]))))
    
    

if __name__ == "__main__":
    main()

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n, k;
int x[55], y[55], sx[55], sy[55];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    rep(i, n) {
        cin >> x[i] >> y[i];
        sx[i] = x[i];
        sy[i] = y[i];
    }

    sort(sx, sx + n);
    sort(sy, sy + n);
    int ans = LLONG_MAX;
    rep(i, n) {
        rep2(j, i, n) {
            rep(l, n) {
                rep2(m, l, n) {
                    int cnt = 0;
                    rep(o, n) {
                        if (sx[i] <= x[o] && x[o] <= sx[j] && sy[l] <= y[o] && y[o] <= sy[m]) cnt++;
                    }
                    if (cnt >= k) ans = min(ans, (sx[j] - sx[i]) * (sy[m] - sy[l]));
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

int main(){
	string N;
	cin >> N;
	int A = N.size();
	long long nInt = 0;
	for (int i = 0; i < A; i++) {
		char X = N.at(i);
		nInt += (int) (X - '0');
	}
	if (nInt % 9 == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3728
// 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, -1, -1, 0, 1, 1, 1};
int dj[] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int h, w;cin >> h >> w;
    vector<string> c(h);
    inc(i, 0, h) cin >> c[i];
    inc(i, 0, h) {
        inc(j, 0, w) {
            if(c[i][j] == '#') continue;
            int cnt = 0;
            inc(k, 0, 8){
                int ni = i + di[k];
                int nj = j + dj[k];
                if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if(c[ni][nj] == '#') cnt++;
            }
            c[i][j] = char('0'+cnt);
        }
        cout << c[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
    int r, c;
    cin >> r >> c;
    int** mat = new int*[r];
    int* sum = new int[r];
    int* sumr = new int[c];
    int sumall = 0;

    for(int i=0;i<r;i++)
    {
        mat[i] = new int[c];
    }

    for(int j=0;j<c;j++){sumr[j] = 0;}

    for (int i= 0;i < r;i++)
    {
        for (int j=0;j < c;j++)
        {
            cin >> mat[i][j];
        }
    }
    
    for (int i= 0;i < r;i++)
    {
        sum[i] = 0;
        for (int j=0;j < c;j++)
        {
            cout << mat[i][j] << " ";
            sum[i] += mat[i][j];
            sumr[j] += mat[i][j];
        }
        cout << sum[i] << endl;
        sumall+=sum[i];
    }
    for(int i=0;i<c;i++)
    {
        cout << sumr[i] << " ";
    }
    cout << sumall << endl;

    return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,M;
typedef pair<LL,LL> P;
priority_queue<P>que;
int main(){
	cin>>N>>M;
	REP(i,N){
		LL a;
		cin>>a;
		que.push(P(a,1));
	}
	REP(i,M){
		LL b,c;
		cin>>b>>c;
		que.push(P(c,b));
	}
	LL ans=0;
	LL res=N;
	while(res>0){
		P p=que.top();
		que.pop();
		if(res<=p.second){
			ans+=res*p.first;
			res=0;
		}else{
			ans+=p.first*p.second;
			res-=p.second;
		}
		//cout<<ans<<" "<<res<<" "<<p.first<<" "<<p.second<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
typedef  long long   ll;
typedef  long double ld;
#define ceil(n, m) ((n / m) + ( n % m ? 1 : 0))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);

	int n;
	cin >> n;
	vector<vector<int>>a(n, vector<int>(3)), dp(n, vector<int>(3));
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < 3; ++j)
			cin >> a[i][j];

	for (int i = 0; i < 3; ++i)
		dp[0][i] = a[0][i];

	for (int i = 1; i < n; ++i) 
		for (int j = 0; j < 3; ++j)
			for (int k = 0; k < 3; ++k)
				if (j != k)
					dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);

	cout << max({ dp[n - 1][0], dp[n - 1][1], dp[n - 1][2] });
	


}


Measured memory_bytes: 14244
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);



int main(){
    FIN;

    ll x;
    cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;


int main(){

int a,b,k;cin>>a>>b>>k;
for(int i=min(a,b);i>0;i--){
    if(a%i==0&&b%i==0)k--;
    if(k==0){cout<<i;return 0;}
}



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define LL long long
#define LD long double
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define debug(x) cerr << #x << " is " << x << endl;
using namespace std;
int const MAXN = 2e6 + 9;
int main(){
    ios_base::sync_with_stdio (0),cin.tie(0);
    string s;
    cin >> s;
    int ans = 0, cur = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'R') cur++;
        else ans = max(cur, ans), cur = 0;
    }
    ans = max(cur, ans);
    cout << ans << endl;
}

Measured memory_bytes: 3604
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Ciniii(A,B,C);
    int M =  max(A,max(B,C));
    int m = min(A,min(B,C));
    int mid = A+B+C - M-m;
    if(M==m){
        cout << "No" << nn;
    }else if(M!=mid && mid !=m){
        cout << "No" << nn;
    }else{
        cout << "Yes"<< nn;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

s,w = myinput()
if w>=s:
    print("unsafe")
else:
    print("safe")

Measured memory_bytes: 74392
<?php
//error_reporting(0);
//$S = trim(fgets(STDIN));
list($A,$B,$C) =  explode(" ",trim(fgets(STDIN)));

if ($A > $B) {
  list($A,$B) = array($B,$A);
}
if ($A < $C && $B > $C) {
  printf("Yes\n");
}
else {
  printf("No\n");
}


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

int main(){
    string S;  cin >> S;
    int N = S.length();
    int ans = 0;
    for(int i=0, j=N-1; i<j; i++, j--){
        if(S[i] != S[j]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys,bisect as bs,collections as cl
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()

p = [0] + l() + [n+1]
ans = 0
a = [0 for i in range(n+2)]

for i in range(n+2):
    a[p[i]] = i

l = [set() for i in range(n+2)]
r = [set() for i in range(n+2)]

for i in range(n+2):
    l[i].add(max(0,i-1))
    l[i].add(max(0,i-2))
    r[i].add(min(n+1,i+1))
    r[i].add(min(n+1,i+2))


for i in range(n+1):
    m = a[i]
    x2,x1,y1,y2 = min(l[m]),max(l[m]),min(r[m]),max(r[m])
    hoge= i*(abs((m-x1)*(y2-y1)) + abs((y1-m)*(x1-x2)))
    ans += hoge

    r[x1].clear()
    r[x1].add(y1)
    r[x1].add(y2)

    l[y1].clear()
    l[y1].add(x1)
    l[y1].add(x2)
    
    r[x2].clear()
    r[x2].add(x1)
    r[x2].add(y1)

    l[y2].clear()
    l[y2].add(y1)
    l[y2].add(x1)
    

print(ans)




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

namespace CompetitiveProgCsLib
{
	static class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES" : "NO");

		static void Main(string[] args)
		{
			var N = RI;
			string[] str = new string[N];
			for (int i = 0; i < N; i++)
			{
				str[i] = R;
			}
			int count = 0;
			for (int i = 0; i < str.Length; i++)
			{
				if (check(str, 0, i)) count += str.Length;
			}
			Out(count);
		}

		static bool check(string[] str, int a, int b)
		{
			var n = str.Length;
			for (int i = 0; i < n; i++)
			{
				
				for (int j = i + 1; j < n; j++)
				{
					var A1 = (i + a) % n;
					var B1 = (j + b) % n;
					var A2 = (i + b) % n;
					var B2 = (j + a) % n;
					if (str[A1][B1] != str[B2][A2]) return false;
				}
			}
			return true;
		}

	}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

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

    vint cum(n, 0);
    vbool check(n, false);
    srep(i, n, 1) {
        cum[i] = cum[i-1];
        if (s[i-1] == 'A' && s[i] == 'C') {
            cum[i]++;
            check[i-1] = true;
        }
    }

    int l, r;
    int ans;
    rep(i, q) {
        cin >> l >> r;
        if (l <= 1) ans = cum[r-1];
        else {
            ans = cum[r-1] - cum[l-2];
            if (check[l-2]) ans--;
        }
        cout << ans << endl;
    }   
    return 0;
}

Measured memory_bytes: 1408
import sys


class Node:
    __slots__ = ['key', 'parent', 'left', 'right']

    def __init__(self, key):
        self.key = key
        self.parent = self.left = self.right = None


def insert(root, z):
    if root is None:
        return z

    y = None
    x = root
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right

    z.parent = y

    if z.key < y.key:
        y.left = z
    else:
        y.right = z

    return root


def inorder(node):
    if not node:
        return
    yield from inorder(node.left)
    yield node.key
    yield from inorder(node.right)


def preorder(node):
    if not node:
        return
    yield node.key
    yield from preorder(node.left)
    yield from preorder(node.right)


def print_tree(root):
    print(''.join(' ' + str(key) for key in inorder(root)))
    print(''.join(' ' + str(key) for key in preorder(root)))


root = None

n = int(sys.stdin.readline())
for _ in range(n):
    command, *args = sys.stdin.readline().split()
    if command == 'insert':
        root = insert(root, Node(int(args[0])))
    else:
        print_tree(root)



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

int main() {
    std::vector<int> a, b;
    int n, tmp = 0;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> tmp;
        if ((n + i) % 2 != 0) {
            b.insert(b.begin(), tmp);
        } else {
            b.push_back(tmp);
        }
    }
    for (int i = 0; i < n; i++) {
        std::cout << b[i] << " ";
    }
    std::cout << "\n";
}

Measured memory_bytes: 3060
from collections import*
from heapq import*
n,m,*a=map(int,open(0).read().split())
t=[-1]*n
def r(x):
  while t[x]>=0:x=t[x]
  return x
def u(x,y):
  x,y=r(x),r(y)
  if x!=y:
    if t[x]>t[y]:x,y=y,x
    t[x]+=t[y]
    t[y]=x
d=defaultdict(list)
for x,y in zip(*[iter(a[n:])]*2):u(x,y)
for i,v in enumerate(a[:n]):d[r(i)]+=v,
if len(d)<2:
  print(0)
  exit()
*d,=map(sorted,d.values())
c=sum(heappop(t)for t in d)
l=[]
for t in d:l+=t
i=len(d)-2
print(i>len(l)and'Impossible'or c+sum(sorted(l)[:i]))

Measured memory_bytes: 40276
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

ll dp[1024][100010];

void solve(int ca){
    int N; cin>>N;
    vector<int> v(N+1),w(N+1);
    for (int i = 1; i <= N; ++i) {
        cin>>v[i]>>w[i];
    }

    int Q; cin>>Q;
    vector<int> u(Q),L(Q);
    int maxiL=0;
    for (int i = 0; i < Q; ++i) {
         cin>>u[i]>>L[i];
         chmax(maxiL,L[i]);
    }
    //maxiL=500010;
    //int half = (1<<((int)ceil(log2(N))/2))-1;
    int half = min(1023,N);
    //cout<<half<<endl;
    //vector<vector<ll>> dp(half+1,vector<ll>(maxiL+1,0));

    for (int i = 1; i <= half; ++i) {
        int par=i/2;
        for (int j = 0; j <= maxiL; ++j) {
            dp[i][j]=dp[par][j];
            if(j-w[i]>=0) chmax(dp[i][j],dp[par][j-w[i]]+v[i]);
        }
    }
    /*
    for(auto i:dp){
        for(auto j:i){
            cout<<j<<" ";
        }
        cout<<endl;
    }
     */


    for (int i = 0; i < Q; ++i) {
        if(u[i]<=half){
            printf("%lld\n",dp[u[i]][L[i]]);
        }else{
            vector<int> nodes;
            int n=u[i];
            while(n>half){
                nodes.push_back(n);
                n>>=1;
            }
            const int M=nodes.size();
            ll ans=0;
            for (int j = 0; j < (1 << M); ++j) {
                ll vsum=0, wsum=0;
                for (int k = 0; k < M; ++k) {
                    if((j>>k)&1){
                        vsum+=v[nodes[k]];
                        wsum+=w[nodes[k]];
                    }
                }
                if(wsum>L[i]) continue;
                chmax(ans,dp[n][L[i]-wsum]+vsum);
            }
            cout<<ans<<endl;
        }

    }

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 805292
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int i,j,x;
    x = sc.nextInt();
    for(i = 1;i <= x;i++){
      if(i % 3 == 0){
        System.out.print(" " + i);
      }
      else{
        j = i;
        while(j > 0){
          if(j % 10 == 3){
            System.out.print(" " + i);
            break;
          }
          j /= 10;
        }

      }
    }
    System.out.println();
  }
}

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


int main() {
  
  
  
  int N;
  cin>>N;
  vector<int> P(N);
for (int i = 0; i < N; i++) {
  cin >> P.at(i);
}
  
  int m=P.at(0);
  int sw=1;
  
  for (int i = 1; i < N; i++) {
    
    if(P.at(i)<=m){
      sw++;
    }
    
    m=min(m,P.at(i));
}
  cout<<sw<<endl;
  
  
}




Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var W = Console.ReadLine();
            var dict = new Dictionary<char, int>();
            for (var i = 0; i < W.Length; i++)
            {
                if (!dict.ContainsKey(W[i])) dict[W[i]] = 0;
                dict[W[i]]++;
            }
            var answer = true;
            foreach (var x in dict.Values)
            {
                if (x % 2 == 1) answer = false;
            }

            Console.WriteLine(answer ? "Yes" : "No");
        }
    }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
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

int l[200005], r[200005];
pii p[200005];
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;i++){
        scanf("%d%d", &l[i], &r[i]);
        p[i] = pii(l[i], r[i]);
    }   
    sort(p+1, p+1+n);

    multiset<int> ms1, ms2;
    int L = 0;
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(p[i].fi == 0 && p[i].se == m+1){
            ans++;
            continue;
        }
        else if(p[i].fi == 0){
            if(!ms2.empty() && *ms2.begin() < p[i].se){
                ms1.insert(*ms2.begin());
                ms2.erase(ms2.begin());
                ms2.insert(p[i].se);
            }
            else{
                ms1.insert(p[i].se);
            }
        }
        else if(L < m && L+1 <= p[i].fi){
            L++;
            ms2.insert(p[i].se);
        }
        else{
            if(!ms2.empty() && *ms2.begin() < p[i].se){
                ms1.insert(*ms2.begin());
                ms2.erase(ms2.begin());
                ms2.insert(p[i].se);
            }
            else{
                ms1.insert(p[i].se);
            }
        }
    }
    for(auto its = ms1.begin();its != ms1.end();its++){
        int r = *its;
        if(r == m+1 || L == m) ans++;
        else{
            L++;
            L = max(L, r);
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 12800
#include <stdio.h>

int main(){
	unsigned long long a;
	unsigned long long b_integer, b_decimal;

	scanf("%llu%llu%*c%llu", &a, &b_integer, &b_decimal);

	unsigned long long b_times_100 = b_integer * 100 + b_decimal;

	printf("%llu\n", a * b_times_100 / 100);

}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
const int maxn=200100;
char str[maxn];
int beg[maxn],tto[maxn<<1],nex[maxn<<1],e;
void putin(int s,int t){
	tto[++e]=t;
	nex[e]=beg[s];
	beg[s]=e;
}
int q[maxn],l,r;
bool inq[maxn];
int cntA[maxn],cntB[maxn];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	scanf("%s",str+1);
	int s,t;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&s,&t);
		putin(s,t);
		putin(t,s);
	}
	l=1,r=0;
	for(int i=1;i<=n;i++){
		for(int j=beg[i];j;j=nex[j]){
			if(str[tto[j]]=='A')
				cntA[i]++;
			else
				cntB[i]++;
		}
		if(cntA[i]==0||cntB[i]==0){
			q[++r]=i;
			inq[i]=1;
		}
	}
	int u;
	while(l<=r){
		u=q[l],l++;
		for(int i=beg[u];i;i=nex[i]){
			if(str[u]=='A')
				cntA[tto[i]]--;
			else
				cntB[tto[i]]--;
			if((cntA[tto[i]]==0||cntB[tto[i]]==0)&&!inq[tto[i]]){
				inq[tto[i]]=1;
				q[++r]=tto[i];
			}
		}
	}
	if(r<n)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 6784
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
int NOEL(){
    cout<<"No"<<endl;
    return 0;
}
#define N 300010
ll a[N],n;
ll t=-1,s=-1;
vector<ll> L,R;
void Reset(ll i){
    t=-1,s=i;
    L.clear(); R.clear();
}
bool Judge(){
    lol(i,L.size()-1)if(L[i]>L[i+1])return 0;
    lol(i,R.size()-1)if(R[i]>R[i+1])return 0;
    return 1;
}

int main(){
    cin>>n;
    lol(i,n){scanf("%lld",&a[i]);a[i]--;}
    lol(i,n){
	ll siz=i-s;
	if(siz==1&&i==a[i]){
	    Reset(i);
	    continue;
	}
	if(siz%2==1){
	    if(i==a[i])return NOEL();
	    if(a[i]<i)L.push_back(a[i]);
	    if(a[i]>i)R.push_back(a[i]);
	    t=max(t,a[i]);
	    if(t==i){
		if(!Judge())return NOEL();
		Reset(i);
	    }
	}
	else{
	    if(a[i]!=i)return NOEL();
	}
    }
    if(t!=-1)return NOEL();
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 4920