akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> g[101010];
int n;
inline vector<int> dijkstra(int x) {
  vector<int> dist(n, 1 << 30);
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
  dist[x] = 0;
  que.push(make_pair(0, x));
  while ((int) que.size()) {
    pair<int, int> p = que.top();
    que.pop();
    int cur = p.second;
    int dist_to_cur = p.first;
    if (dist[cur] < dist_to_cur) continue;
    for (auto &nbr : g[cur]) {
      int to = nbr.first;
      int path = nbr.second;
      if (dist[to] > dist[cur] + path) {
        dist[to] = dist[cur] + path;
        que.push(make_pair(dist[to], to));
      }
    }
  }
  return dist;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> n;
  for (int i = 0; i + 1 < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].emplace_back(v, w % 2);
    g[v].emplace_back(u, w % 2);
  }
  vector<int> dist = dijkstra(0);
  for (int i = 0; i < n; i++) {
    cout << dist[i] % 2 << '\n';
  }
  cout << endl;
  return 0;
}

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

#define ll long long
using namespace std;
const int N = 200 + 9;
ll mod = 1e9L + 9;

void test() {
    int n, w;
    cin >> n >> w;
    vector<ll> weights(n), values(n);
    for (int i = 0; i < n; i++)cin >> weights[i] >> values[i];
    /*
     * dp[i] => max value with weight i
     */
    vector<ll> dp(w + 1);
    for (int item = 0; item < n; item++) {
        //item
        /* weight_item = 3
         * dp[5] = max(dp[5],dp[2]+val_item)
         * dp[8] = max(dp[8],dp[5]+val_item)
         */
        int cur_w = weights[item], cur_v = values[item];
        for (int weight = w; weight >=cur_w; weight--) {
            dp[weight] = max(dp[weight], dp[weight - cur_w] + cur_v);
        }
        for (int i = 1; i <= w; i++)dp[i] = max(dp[i], dp[i - 1]);
    }
    cout << dp[w] << endl;


}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //    freopen("input.in", "r", stdin);
    int t = 1;
//    cin >> t;
//    scanf("%d", &t);
    for (int cas = 1; cas <= t; cas++) {
//        printf("Case %d: ", cas);
        test();
    }
}

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

using namespace std;

int main(void) {
	int i, j, tmp;
	int N, M;
	vector<int> T, P, X, ans;
	// get input ----------------------------------------
	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> tmp;
		T.push_back(tmp);
	}
	cin >> M;
	for (i = 0; i < M; i++) {
		cin >> tmp;
		P.push_back(tmp-1);
		cin >> tmp;
		X.push_back(tmp);
	}
	// calc ---------------------------------------------
	for (i = 0; i < M; i++) {
		tmp = 0;
		for (j = 0; j < N; j++) {
			if (j == P[i]) {
				tmp += X[i];
			}
			else {
				tmp += T[j];
			}
		}
		ans.push_back(tmp);
	}
	// disp answer --------------------------------------
	for (i = 0; i < M; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}





Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, W = map(int, input().split())
    items = [tuple(map(int, input().split())) for _ in range(N)]

    dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

    for max_w in range(W+1):
        for i, (w, v) in enumerate(items):
            if max_w - w >= 0:
                dp[i+1][max_w] = max(dp[i][max_w], dp[i][max_w-w] + v)
            else:
                dp[i+1][max_w] = dp[i][max_w]
    print(dp[N][W])

if __name__ == '__main__':
    main()


Measured memory_bytes: 171784
#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,k,l=0,i;
    string s;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        s=to_string(i);
        k=s.size();
        if(k%2!=0)
            l++;
    }
    cout<<l<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}




vector<ll> calc(vector<ll> &v){
  vector<ll> res;
  for(auto itr : v) {
    for(ll i=-1; i<=1; i++) {
      ll add = itr%10 + i;
      if(add >= 0 && add <= 9) res.push_back(itr * 10 + add);
    }
  }
  return res;
}




int main() {
  int K;
  cin >> K;
  vector<ll> all;
  vector<ll> re;
  rep(i,9) {
    re.push_back(i+1);
    all.push_back(i+1);
  }

  for(int d = 1; d < 10; d++) {
    re = calc(re);
    for(auto itr : re) all.push_back(itr);
  }

  cout << all[K-1] << endl;

  
  return 0;
}





Measured memory_bytes: 4076
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
# MARCH = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
t = input()
me = []
ans = 0
for i in range(len(t)):
    if i < k:
        if t[i] == "r":
            me.append("p")
            ans += p
        elif t[i] == "s":
            me.append("r")
            ans += r
        else:
            me.append("s")
            ans += s
    else:
        if t[i] == "r" and me[i-k] != "p":
            me.append("p")
            ans += p
        elif t[i] == "s" and me[i-k] != "r":
            me.append("r")
            ans += r
        elif t[i] == "p" and me[i-k] != "s":
            me.append("s")
            ans += s
        else:
            me.append("?")
print(ans)



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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

char change(char &s) {
  if (s == 'S')
    return 'W';
  else
    return 'S';
}
char calc(char &type, char &claim, char &neighbor) {
  if ((type == 'S' && claim == 'o') || (type == 'W' && claim == 'x'))
    return neighbor;
  else
    return change(neighbor);
}
signed main() {
  int n = read();
  string s = readString();
  auto solv = [&](char &s1, char &s2) {
    string ret;
    ret += s1, ret += s2;
    FOR(i, 2, n) { ret += calc(ret[i - 1], s[i - 1], ret[i - 2]); }
    char pred1 = calc(ret[n - 1], s[n - 1], ret[n - 2]);
    char predn = calc(s1, s[0], s2);
    if (ret[0] == pred1 && ret[n - 1] == predn)
      return ret;
    else
      return string();
  };
  string ans;
  char type[2] = {'S', 'W'};
  REP(i, 2) REP(j, 2) {
    ans = solv(type[i], type[j]);
    if (ans.size()) {
      std::cout << ans << std::endl;
      return 0;
    }
  }
  print(-1);
}


Measured memory_bytes: 2772
#include <bits/stdc++.h>
using namespace std;
int N,W,i,j,a,b;
vector<int64_t>dp((int)1e5+10,2147483647);
void solve()
{
    cin>>N>>W;
    dp[0]=0;
	for(i=0;i<N;i++){
        cin>>a>>b;
        for(j=(int)1e5+10;j>=b;j--)
            dp[j]=min(dp[j],dp[j-b]+a);
    }
    for(i=dp.size()-1;i>=0;i--)
        if(dp[i]<=W){
            cout<<i<<endl;
            break;
        }
}

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


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int h,w;cin >>h>>w;
    vector<string>s(h);
    for (int i = 0; i < h; ++i) {
        cin >>s[i];
    }
    queue<P>que;
    que.push({0,0});
    vector<vector<int>>d(h,vector<int>(w,INF));
    d[0][0]=(s[0][0]=='#')?1:0;
    while(!que.empty()){
        P pos=que.front();que.pop();
        int x=pos.second;
        int y=pos.first;
        int now=d[y][x];
        char key=s[y][x];
        if(x+1<w){
            int cost=(s[y][x+1]!=key)?1:0;
            if(d[y][x+1]>now+cost){
                d[y][x+1]=now+cost;
                que.push({y,x+1});
            }
        }
        if(y+1<h){
            int cost=(s[y+1][x]!=key)?1:0;
            if(d[y+1][x]>now+cost){
                d[y+1][x]=now+cost;
                que.push({y+1,x});
            }
        }
    }
    if(s[h-1][w-1]=='#')d[h-1][w-1]++;
    cout <<d[h-1][w-1]/2<<endl;
}


Measured memory_bytes: 3696
#include <stdio.h>
 
struct pair {
  int x;
  int ar;
};
int top_stack1 = 0, top_stack2 = 0;
int stack1[20000];
struct pair stack2[20000];
  
void push_stack1(int x) {
  stack1[top_stack1] = x;
  top_stack1++;
}
 
void push_stack2(int j, int a) {
  stack2[top_stack2].x = j;
  stack2[top_stack2].ar = a;
  top_stack2++;
}
 
int pop_stack1(void) {
  int r = 0;
 
  top_stack1--;
   
  if(top_stack1 < 0) {
    top_stack1 = 0;
    return 0;
  }
  r = stack1[top_stack1];
  return r;
 
}
 
struct pair pop_stack2(void) {
  struct pair s;
 
  top_stack2--;
   
  if(top_stack2 < 0) {
    top_stack2 = 0;
    return;
  }
  s = stack2[top_stack2];
  return s;
 
}
int main() {
  int i, j;
  int sum = 0, a;
  struct pair c;
  char input[20000];
 

  scanf("%s", input);

  for (i = 0; input[i] != '\0'; i++) {
    if(input[i] == '\\') push_stack1(i);
    else if((input[i] == '/') && (top_stack1 > 0)) {
      j = pop_stack1();
      sum += i - j;
      a = i - j;
      while ((top_stack2 > 0) && stack2[top_stack2 - 1].x > j) {
        a += stack2[top_stack2 - 1].ar ;
        c = pop_stack2();
      }
      push_stack2(j, a);
    }
  }

  printf("%d\n", sum);
  printf("%d", top_stack2);
  for(i = 0; i < top_stack2; i++) {
    if(i < top_stack2) printf(" ");
    printf("%d", stack2[i].ar);
  }
  printf("\n");
 
 
  return 0;
}


Measured memory_bytes: 2144
/*  ex6_2
    potter0723sw  */

#include <stdio.h>
#include <string.h>

int main(void){
    int num, last;
    char string[101];//ヌル文字分含め確保
    scanf("%s", string);
    num = (int)strlen(string) - 2;//省略する文字数は最初と最後以外の数（ヌル文字はカウントされてない）
    last = (int)strlen(string) - 1;//配列は0から始まることに注意
    printf("%c%d%c\n", string[0], num, string[last]);
    return 0;
}


Measured memory_bytes: 128
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h1 = gi();
    int s1 = gi();
    int h2 = gi();
    int s2 = gi();
    int t = 0;
    while (h1*h2 > 0) {
        if (t == 0)
            h2 -= s1;
        else
            h1 -= s2;
        t = 1-t;
    }
    printf(h2 <= 0 ? "Yes\n" : "No\n");

    return 0;
}


Measured memory_bytes: 3852
/* You can't hack me! */
#pragma warning(disable : 4996)
#include"bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vch;
typedef set<ll> sll;
#define fo(i,n) for(ll i=0; i<(n); i++)
#define FO(i,a,b) for(auto i=a; i!=(b); i+=(b)>(a)?1:-1)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(c) c.begin(), c.end()
#define sc scanf
#define pr printf
#define il(x) sc("%lld", &(x))
#define id(x) sc("%Lf", &(x))
#define os(x) pr("%lld ", x)
#define on(x) pr("%lld\n", x)
#define nl pr("\n")

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll t=1;
    //il(t);
    while(t--)
    {
        ll a, b, c, d;
        il(a);
        il(b);
        il(c);
        il(d);
        while(a && c)
        {
            c-=b;
            if(c<=0)
            {
                pr("Yes");
                break;
            }
            a-=d;
            if(a<=0)
            {
                pr("No");
                break;
            }
        }
    }
    cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "s\n";
    return 0;
}

Measured memory_bytes: 3868
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin >> a;
    if(a[5]=='1'){
        cout << "TBD" << endl;
    }else{
        if(a[6]<'5'){
            cout << "Heisei" << endl;
        }else{
            cout << "TBD" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;
long long modinv(long long a, long long m=MOD) {long long b = m, u = 1, v = 0;while (b) {    long long t = a / b;    a -= t * b; swap(a, b);    u -= t * v; swap(u, v);}u %= m; if (u < 0) u += m;return u;}
//MODの割り算の際にa/＝b;をa *= modinv(b,MOD);とする。
int gcd(int a, int b){if (a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}
 
int main(){
    int N,T;cin >> N >> T;
    int mi = INT32_MAX;
    int ans = 0;
    rep(i,N){
        int c,t;
        cin >> c >> t;
        if(t<=T)mi = min(mi, c);
    }

    if(mi==INT32_MAX)puts("TLE");
    else cout << mi << endl;
    return 0;
}

Measured memory_bytes: 3592
n=int(input())
a_list=list(map(int,input().split()))
num1=a_list.count(1)
import functools
import operator
if 0 in a_list:
    print("0")
elif n > 60+num1:
    print("-1")
else:
    p = functools.reduce(operator.mul, a_list)

    if p <= 10**18:
        print(p)
    else:
        print("-1")

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


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

    if(D[N/2-1] == D[N/2]){
        cout << 0 << endl;
    }else{
        cout << D[N/2] - D[N/2-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3764
#include<cstdio>
#include<algorithm> 
#include<cstring>
#include<map>
#define LL long long
using namespace std;
const int N=2e5+10;
const int M=1<<26;
const int inf=0x3f3f3f3f;
int n,a,sum,f[N],m[M];
char s[N];
int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	memset(m,0x3f,sizeof(m));
	m[0]=0;
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
	{
		a=1<<(s[i]-'a');
		sum=sum^a;
		m[sum]=min(m[sum],i);
		f[i]=m[sum]+1;
		for(int j=0;j<26;j++)
			f[i]=min(f[i],m[sum^(1<<j)]+1);
		m[sum]=min(m[sum],f[i]);
//		printf("%d %d\n",i,f[i]);
	}
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 263424
#include <iostream>
 
using namespace std;
 
int main(){
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int O = 0;
  while (A >= B){
    B *= 2;
    O += 1;
  }
  while (B >= C){
    C *= 2;
    O += 1;
  }
  if (O > K){ cout << "No";}
  else{ cout << "Yes";}
}

Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	int count = 0;

	for (int i = 0; i < 3; i++)
	{
		if (s.at(i) == t.at(i))
		{
			count++;
		}
	}

	cout << count << endl;
}


Measured memory_bytes: 256
#include <complex>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef double number;

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<number> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

typedef vector<P> G;

#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
#define diff(P, i) (next(P, i) - curr(P, i))
number convex_diameter(const G &pt) {
  const int n = pt.size();
  int is = 0, js = 0;
  for (int i = 1; i < n; ++i) {
    if (imag(pt[i]) > imag(pt[is])) is = i;
    if (imag(pt[i]) < imag(pt[js])) js = i;
  }
  number maxd = norm(pt[is]-pt[js]);

  int i, maxi, j, maxj;
  i = maxi = is;
  j = maxj = js;
  do {
    if (cross(diff(pt,i), diff(pt,j)) >= 0) j = (j+1) % n;
    else i = (i+1) % n;
    if (norm(pt[i]-pt[j]) > maxd) {
      maxd = norm(pt[i]-pt[j]);
      maxi = i; maxj = j;
    }
  } while (i != is || j != js);
  return maxd; /* farthest pair is (maxi, maxj). */
}

int main(){
	G poly;
	P p;
	int n;
	double x,y;
	for(scanf("%d",&n);n--;poly.push_back(p))scanf("%lf%lf",&x,&y),p=P(x,y);
	printf("%f\n",sqrt(convex_diameter(poly)));
}

Measured memory_bytes: 1552
#include <bits/stdc++.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#include <set>
#include <fstream>

//#define _debug
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define sz(x) x.size()
#define pb push_back
//#define _online_judge

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = static_cast<const int>(1e4 + 5);
const int MOD = 1000000007;



int main(){
    FASTIO;
#ifdef _online_judge
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif

    int arr[26];memset(arr,0,sizeof arr);
    string s;cin >> s;
    for(int i=0;i<s.size();i++) arr[s[i]-'a']++;
    for(int i=0;i<26;i++){

        if(arr[i]&1){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    if iterator.next().unwrap().chars().any(|c| c == '9') {
        "Yes".to_string()
    } else {
        "No".to_string()
    }
}


Measured memory_bytes: 2144
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int inf=1e9;
int n,a,t;
vector<vector<int>> g;
vector<int> da,dt;
void dfs(int node,int par,int st)
{
	for(auto u:g[node])
	{
		if(u!=par)
		{
			if(st==1)
			{
				da[u]=min(da[u],da[node]+1);
				dfs(u,node,1);
			}
			else
			{
				dt[u]=min(dt[u],dt[node]+1);
				dfs(u,node,0);
			}
		}
	}
}
#define sz(x) (int)(x).size();
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	n=in();t=in();a=in();a--;t--;
	int u,v;
	g=vector<vector<int>>(n);
	da=dt=vector<int>(n,inf);
	for(int i=0;i<n-1;i++)
	{
		u=in();v=in();
		u--;v--;
		g[u].push_back(v);g[v].push_back(u);
	}
	
	da[a]=0;dt[t]=0;
	dfs(a,-1,1);
	dfs(t,-1,0);
	int ans=0;
	
	for(int i=0;i<n;i++)
	{
		if(da[i]>dt[i])ans=max(ans,da[i]);
	}
	cout<<ans-1;
}

Measured memory_bytes: 15524
#include <iostream>
#include <cstring>
#include <string>
#include <map>

typedef long long LL;
const int Mod = 998244353;
const int MN = 105;

std::string S;
std::map<std::string, int> f;

int DP(std::string str) {
	if (f.find(str) != f.end()) return f[str];
	std::string tmp(str.begin(), str.end() - 1), tmp2;
	int Ans = (str.back() - '0' + 1) * DP(tmp);
	for (int len = 1; len <= (int)str.length() / 2; ++len) {
		tmp2.assign(str.end() - len, str.end());
		for (int i = 2; i * len <= (int)str.length(); ++i) {
			for (int j = 0; j < len; ++j)
				if (*(str.end() - i * len + j) == '0')
					tmp2[j] = '0';
			tmp.assign(str.begin(), str.end() - i * len);
			Ans = (Ans + (LL)DP(tmp) * DP(tmp2)) % Mod;
		}
	}
	return f[str] = Ans;
}

int main() {
	std::cin >> S;
	f[""] = f["0"] = 1;
	f["1"] = 2;
	std::cout << DP(S) << std::endl;
	return 0;
}

Measured memory_bytes: 5632
#include "bits/stdc++.h"
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int l = s.size();
  char x;
  for (int i = 0; i < l; i++) {
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    x = s[0];
    s.erase(s.begin());
    s += x;

  }
  cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
int j,n,i,c=0;
scanf("%d",&n);
for(i=n;i>=n;i++)
{
c=0;
for(j=2;j<i;j++)
{
if(i%j==0)
c++;
}
if(c==0)
{
printf("%d",i);
exit(0);
}
}
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {+0,+1,+1,+1,+0,-1,-1,-1};
int ty[] = {-1,-1,+0,+1,+1,+1,+0,-1};

map<string,int> freq;

void dfs(int x,int y,
	 string str,
	 int visited,
	 char stage[4][4],
	 const set<string>& keywords){
  str += stage[y][x];
  visited |= (1<<(4*y+x));
  if(keywords.count(str) > 0){
    freq[str]++;
  }

  if(__builtin_popcount((visited)) >= 8) return;

  for(int i=0;i<8;i++){
    int dx = x + tx[i];
    int dy = y + ty[i];
    if(dx < 0 || dx >= 4 || dy < 0 || dy >= 4) continue;
    int idx = dy * 4 + dx;
    if(visited & (1<<idx)) continue;
    dfs(dx,dy,str,visited,stage,keywords);
  }
}



int main(){
  int N;
  while(~scanf("%d",&N)){
    freq.clear();
    char stage[4][4];

    set<string> keywords;
    vector<string> keywords_v;
    map<string,int> score_table;
    int dp[10001];

    for(int i=0;i<N;i++){
      string word;
      int score;
      cin >> word >> score;
      score_table[word] = score;
      keywords.insert(word);
      keywords_v.push_back(word);
    }
    for(int y=0;y<4;y++){
      string line;
      cin >> line;
      for(int x=0;x<4;x++){
	stage[y][x] = line[x];
      }
    }

    int time_limit;
    scanf("%d",&time_limit);
    memset(dp,-1,sizeof(dp));
    for(int y=0;y<4;y++){
      for(int x=0;x<4;x++){
	dfs(x,y,"",0,stage,keywords);
      }
    }

    dp[0] = 0;
    for(int key_idx=0;key_idx < keywords_v.size();key_idx++){
      const string& key = keywords_v[key_idx];
      int cost = key.length();
      int score = score_table[key];

      int scalar = 1;
      int capacity = freq[key];
      for(;
	  scalar <= capacity;
	  capacity -= scalar,scalar *= 2){

	for(int next_time=time_limit;next_time - cost * scalar>=0;next_time--){
	  int from_time = next_time - cost * scalar;
	  if(dp[from_time] == -1) continue;
	  dp[next_time] = max(dp[from_time] + score * scalar,
			      dp[next_time]);
	}
      }

      if(capacity){
	for(int next_time=time_limit;next_time - cost * capacity>=0;next_time--){
	  int from_time = next_time - cost * capacity;
	  if(dp[from_time] == -1) continue;
	  dp[next_time] = max(dp[from_time] + score * capacity,
			      dp[next_time]);
	}
      }
    }

    int max_score = 0;
    for(int time = time_limit; time >=0; time--){
      max_score = max(dp[time],max_score);
    }
    printf("%d\n",max_score);
  }
}

Measured memory_bytes: 1356
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, T: "List[int]", M: int, P: "List[int]", X: "List[int]"):
    for j in range(M):
        ret = 0
        for i in range(N):
            if i == P[j] - 1:
                ret += X[j]
            else:
                ret += T[i]
        print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]" 
    X = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        P[i] = int(next(tokens))
        X[i] = int(next(tokens))
    solve(N, T, M, P, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   int x,a,b; cin>>x>>a>>b;
   cout<< (x-a)%b <<endl;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    string S;
    cin >> S;

    int numOfTry = S.size() / 2;
    int ans = 0;
    rep(i, numOfTry) {
        if (S.at(i) != S.at(S.size() - (i + 1))) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    string S,T;
    int A,B;
    string U;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if(S==U)A --;
    if(T==U)B--;
    cout << A << " " << B << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>
#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec) {
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

//#define solvsh
//#define multi
#ifdef solvsh

const int MAXN = 2e5 + 20;

int per[MAXN];
ll costs[MAXN];

ll tree[MAXN];
ll inp[MAXN];
int where[MAXN];

void build(int ver, int tl, int tr) {
    if (tl == tr) {
        tree[ver] = inp[tl];
    } else {

        int mid = (tl + tr) >> 1;

        build(2 * ver, tl, mid);
        build(2 * ver + 1, mid + 1, tr);

        tree[ver] = min(tree[2 * ver], tree[2  *ver + 1]);
    }
}

ll adds[4 * MAXN];

void upd(int v, int tl, int tr, int l, int r, ll add){
    if (l > r)
        return;
    if (tl == l && tr == r){
        adds[v] += add;
        return;
    }

    auto mid = (tl + tr) >> 1;

    upd(2 * v, tl, mid, l, min(mid, r), add);
    upd(2 * v + 1, mid + 1, tr, max(mid + 1, l), r, add);

    tree[v] = min(tree[2 * v], tree[2 * v  +1]) + adds[v];
}

ll get_min(){
    return tree[1];
}


void solve() {
    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> per[i];
        where[per[i]] = i;
    }

    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> costs[i];
        sum += costs[i];
    }

    for (int i = 1; i <= n; ++i) {
        inp[i] = inp[i - 1] + costs[where[i]];
    }
    build(1, 1, n);

    ll answr = 1e18;

    for (int i = 0; i < n; ++i) {

        int val = per[i];

        upd(1, 1, n, 1, val - 1, costs[i]);
        upd(1, 1, n, val, n, -costs[i]);

        answr = min(answr, get_min());
    }

    cout << answr;
}

#else

ll mod = 1e9+7;

const int MAXN = 2e5 + 9;


void solve() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int sm = min(a, k);
    k -= min(a, k);

    if (k > 0){
        k -= min(b, k);
    }

    if (k > 0){
        sm -= min(c, k);
        k -= min(c, k);
    }

    cout << sm;

}

#endif

void multisolve() {

    int t;
    cin >> t;

    int i = 1;
    while (t--) {
        cout << "Case #" << (i++) << ": ";
        solve();
        cout << "\n";
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);



#ifdef multi
    multisolve();
#else
    solve();
    //    gen();
#endif

}


Measured memory_bytes: 3644
#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 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(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n){
		int in;
		cin >> in;
		in--;
		a.at(i) = in;
	}
	int ans = 0;
	rep(i, n){
		if(a.at(i) > i){
			int fr = a.at(i);
			if(a.at(fr) == i) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

#define SQ(x)	((x) * (x))

int main(void)
{
	int inte[3];
	int rect, dia;
	
	rect = 0;
	dia = 0;
	
	while (scanf("%d,%d,%d", &inte[0], &inte[1], &inte[2]) != EOF){
			
		if (SQ(inte[2]) == SQ(inte[0]) + SQ(inte[1])){
			rect++;
		}
		else if (inte[0] == inte[1]){
			dia++;
		}
		
	}
		printf("%d\n%d\n", rect, dia);
	return (0);
}

Measured memory_bytes: 596
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

typedef pair<int, int> pii;

struct Edge
{
	int t, c;
	Edge(int t,int c):t(t),c(c){}
};

vector<Edge> edges[10000];
int d[10000];

void dijkstra(int n)
{
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	d[0] = 0;
	pq.push(make_pair(0, 0));

	while (!pq.empty())
	{
		pii tp = pq.top();
		pq.pop();

		if (d[tp.second] < tp.first)
		{
			continue;
		}

		for (int i = 0; i != edges[tp.second].size(); i++)
		{
			if (d[tp.second] + edges[tp.second][i].c < d[edges[tp.second][i].t])
			{
				d[edges[tp.second][i].t] = d[tp.second] + edges[tp.second][i].c;
				pq.push(make_pair(d[edges[tp.second][i].t], edges[tp.second][i].t));
			}
		}
	}
}

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

	for (int i = 0; i < n; i++)
	{
		d[i] = 100000000;
	}

	for (int i = 0; i < n; i++)
	{
		int id, k;
		cin >> id >> k;
		for (int j = 0; j < k; j++)
		{
			int v, c;
			cin >> v >> c;
		
			edges[id].push_back(Edge(v, c));
		}
	}

	dijkstra(n);

	for (int i = 0; i < n; i++)
	{
		printf("%d %d\n", i, d[i]);
	}

	return 0;
}


Measured memory_bytes: 8020
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


template <typename T>
struct segtree{
	//元データx[i]はv[n+i]
	//v[i]の親はv[i/2],子はv[i*2]とv[i*2+1]
	vector<T> v;
	int n;
	
	const T init_value = 0;
	
	segtree(vector<T> &x){
		n=1;
		while(true){
			if(n>=x.size())break;
			n*=2;
		}
		v.resize(2*n,init_value);
		
		for(int i=0;i<x.size();i++){
			v[n+i]=x[i];
		}
		for(int i=n-1;i>=0;i--){
			v[i]=func(v[i*2],v[i*2+1]);
		}
	}

	void update(int x,T val){
		x+=n;
		v[x]=val;
		while(true){
			x=(x)/2;
			v[x]=func(v[x*2],v[x*2+1]);
			if(x<=0)break;
		}
	}
	
	//区間[l,r)におけるクエリ処理
	T query(int l,int r){
		T res = init_value;
		l+=n;r+=n;
		while(true){
			if(l%2==1){
				res=func(v[l],res);
				l++;
			}
			if(r%2==1){
				res=func(v[r-1],res);
				r--;
			}
			if(l>=r)break;
			l/=2;r/=2;
		}
		return res;
	}
	T func(T a,T b){
		return a+b;
	}
	
	void show(){
		int n = 1;
		for(int i=1;i<v.size();i++){
			for(int j=0;j<n;j++){
				if(j!=0)cout<<' ';
				cout<<v[i+j];
			}
			cout<<endl;
			i+=n-1;
			n*=2;
		}
	}
	
};

int main(){
	
	long long N,K;
	cin>>N>>K;
	
	vector<long long> A(N);
	
	map<long long,int> mp;
	
	for(int i=0;i<N;i++){
		cin>>A[i];
		A[i] -= K;
		
		if(i!=0)A[i] += A[i-1];
		
		mp[A[i]] = -1;	
		mp[-A[i]] = -1;
	}
	

	int cnt = 0;
	for(auto &a:mp){
		a.second = cnt;
		cnt++;
	}
	
	vector<long long> v(cnt,0);
	segtree<long long> S(v);
	long long ans = 0;
	for(int i=0;i<N;i++){
		if(A[i]>=0)ans++;
		ans += S.query(0,mp[A[i]]+1);
		S.update(mp[A[i]],S.query(mp[A[i]],mp[A[i]]+1)+1);
	}
	
	cout<<ans<<endl;
	
	return 0;
}


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

#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define T() int tt; cin >> tt; rep1(qq,1,tt)
#define rep(i,start,lim) for(int i=start;i<lim;i++)
#define rep1(i,start,lim) for(int i=start; i<=lim; ++i)
#define repd(i,start,lim) for(int i=start;i>=lim;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define br cout<<"\n"
#define MOD (1000000007LL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eps (1e-6)
#define what_is(x) cerr << #x << " is " << x << "\n";
#define int long long int
#define infll 9e18
#define inf 1e12

#define lnode (2 * node + 1)
#define rnode (2 * node + 2)

using namespace std;

typedef pair<int, int> pii;

const int N = 3 * 1e6 + 2;

int n, k;

int32_t main(){

  FIO
  //cout << fixed << setprecision(10);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  cin >> k;
  int a, b;
  if(k == 1) return cout << "OK\n", 0;
  cin >> a >> b;
  if((a / k) * k >= a && (a / k) * k <= b) cout << "OK\n";
  else if((a / k) * k + k <= b) cout << "OK\n";
  else cout << "NG\n";


	return 0;
}






Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
 
using namespace std;
 
int main (){
  
  long long int a,b,c,d[110],e,f,g;
  
  
  cin >>a;
   cin >>b>>c ;
  for(int i=0;i<a;i++)
  cin >> d[i];
  e =0,f=0,g=0;
 for(int i=0;i<a;i++){
   if(d[i]<=b){
     e++;
   }
   if(d[i]>=b+1 &&d[i]<=c){
     f++;
   }
   if(d[i]>c){
     g++;
   }
 }
cout << min( min(e,f),g) << endl;
 
  return 0;
}
 


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  
  int h,w; cin>>h>>w;
  char a[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>a[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]=='.'){
        int ans=0;
        for(int k=max(i-1,0);k<=min(i+1,h-1);k++){
          for(int l=max(j-1,0);l<=min(j+1,w-1);l++){
            if(a[k][l]=='#') ans++;
          }
        }
        a[i][j]='0'+ans;
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<a[i][j];
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 200000 + 100;

int main()
{
	LL n, a[N];
	cin >> n;
	for(int i = 0 ; i < n; i++)
		cin >> a[i];
	LL sum = 0;
	for(int i = 1; i < n; i++){
		if(a[i] < a[i - 1]){
			sum += (a[i - 1] - a[i]);
			a[i] = a[i - 1];
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 5176
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

struct S{
   int id, ac, time;
   vector<int> wa;
};
bool cmp(S p1, S p2){
   if(p1.ac == p2.ac){
       if(p1.time == p2.time){
           return p1.id > p2.id;
       }
       return p1.time < p2.time;
   }
   return p1.ac > p2.ac;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, t, p, r;
    while(1){
        cin >> m >> t >> p >> r;
        if(m + t + p + r == 0) break;
        vector<S> d(t);
        rep(i, 0, t){
            d[i].id = i; d[i].ac = 0; d[i].time = 0; d[i].wa.resize(p);
        }
        rep(i, 0, r){
            int mi, ti, pi, ji;
            cin >> mi >> ti >> pi >> ji;
            ti--; pi--;
            if(ji == 0){
                d[ti].ac++;
                d[ti].time += mi + 20 * d[ti].wa[pi];
            }else{
                d[ti].wa[pi]++;
            }
        }
        sort(all(d), cmp);
        rep(i, 0, t){
            cout << d[i].id + 1;
            if(i != t - 1){
                if(d[i].ac == d[i + 1].ac && d[i].time == d[i + 1].time) cout << "=";
                else cout << ",";
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3200
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
 
class Main {
     
    private static String context;
    private static int pos;
     
    public Main() {
        this.context = "";
        this.pos = 0;
    }
     
    public static void setContext(String exp) {
        context = exp;
    }
 
    private static double fact() { 
        if( context.charAt(pos) == '(' ) {
            ++pos;
            double p = expression();
            ++pos;
            return p;
        } else {
            int sp = pos;
            while( pos < context.length() && ( ( '0' <= context.charAt(pos) && context.charAt(pos) <= '9' ) || context.charAt(pos) == '.' ) ) {
                ++pos;
            }
            String q = context.substring(sp, pos);
            return Double.parseDouble(q);
        }
    }
     
    private static double term() {
        double p = fact();
        while( pos < context.length() ) {
            char c = context.charAt(pos);
            if( c =='*' ) {
                ++pos;
                p *= fact();
            } else if( c == '/' ) {
                ++pos;
                //p /= (int)fact();
		p = (int)(p / (int)fact());
            } else {
                break;
            }
        }
        return p;
    }
     
    private static double expression() {
        double p = term();
        while( pos < context.length() ) {
            char c = context.charAt(pos);
            if( c == '+' ) {
                ++pos;
                p += term();
            } else if( c == '-' ) {
                ++pos;
                p -= term();
            } else {
                break;
            }
        }
        return p;
    }
     
    public static double eval(String exp) {
        context = removeSpace(exp);
        pos = 0;
        return expression();
    }
     
    private static String removeSpace(String s) {
        String t = "";
        for(int i=0;i<s.length();++i) {
            char c = s.charAt(i);
            if( c == ' ') {
                continue;
            } 
            t += c;
        }
        return t;
    }
     
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for(int i=0;i<n;++i) {
            String s = br.readLine();
            s = s.substring(0,(int)s.length()-1);
            System.out.println((int)eval(s));
        }
    }
}



Measured memory_bytes: 24488
M, K = map(int,input().split())
if [M, K] == [0, 0]:
    print("0 0")
    exit(0)
if [M, K] == [1, 0]:
    print("0 0 1 1")
    exit(0)
if [M, K] == [1, 1]:
    print(-1)
    exit(0)
if 2**M <= K:
    print(-1)
    exit(0)

a = []
for k in range(2**M):
    if k != K:
        a.append(k)
ans = a+[K]+a[::-1]+[K]
print(*ans, sep=" ")

Measured memory_bytes: 69488
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using lli = long long int;

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

template <class S, class T> inline void chmax(S &a, T b){if(a < b) a = b;}
template <class S, class T> inline void chmin(S &a, T b){if(a > b) a = b;}

constexpr int MAX_N = 100;
constexpr int ALPHABET = 'z' - 'a' + 1;
constexpr int INF = 1e9 + 1;
char str[MAX_N+1];
std::vector<int> A[ALPHABET];

int main(void){
    scanf("%s", str); int n = 0;
    while(str[n] != '\0'){
        A[str[n] - 'a'].push_back(n);
        n++;
    }
    int res = INF;
    REP(i, ALPHABET) if(A[i].size() != 0){
        const int s = A[i].size();
        int mx = -1;
        chmax(mx, A[i][0]);
        REP(j, s-1){
            int diff = A[i][j+1] - A[i][j];
            chmax(mx, diff - 1);
        }
        chmax(mx, n - A[i][s-1] - 1);
        chmin(res, mx);
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 504
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll X;
  cin>>X;
  for(ll i=X;;i++){
    bool prime=true;
    for(ll j=2;j*j<=i;j++){
      if(i%j==0){
        prime=false;
        break;
      }
    }
    if(prime){cout<<i;break;}
  }
  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
long long gcd(long long a,long long b){ return b ? gcd(b,a%b) : a; }
long long lcm(long long a,long long b){ return a * b / gcd(a, b); }
 
 
int main(){
	long long N,M;
	cin >> N >> M;
	string S,T;
	cin >> S >> T;
	long long L = lcm(N,M);
	long long G = gcd(N,M);
	long long s = N / G;
	long long t = M / G;
	for(long long i = 0;i < L; i++){
		//cout << i*s << "=" << S[i*s] << " " << i*t << "=" << T[i*t] << endl;
		if(i*s >= N || i*t >= M) break;
		if(S[i*s] != T[i*t]){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << L << endl;
    return 0;
}

Measured memory_bytes: 512
N, M = map(int, input().split())
A = list(map(int, input().split()))

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

def lcm(a, b):
  return a * b // gcd(a, b)  
  
B = [a for a in A]

while 1:
  cnt = 0
  for b in B:
    cnt += b % 2
  if cnt == 0:
    for i in range(N):
      B[i] //= 2
  else:
    if cnt == N:
      break
    else:
      print(0)
      exit()
#print("B:", B)

x = A[0]
for i in range(1, N):
  x = lcm(x, A[i])
  if x // 2 > M:
    print(0)
    exit()
#print("x:", x)

print((M - x // 2) // x + 1)

Measured memory_bytes: 64356
#include<bits/stdc++.h>
using namespace std;
typedef long long L;
int main()
{
  L n,tot=0;
  scanf("%lld",&n);
  L v[n+1],c[n+1];
  for(L i=0;i<n;i++)scanf("%lld",&v[i]);
  for(L i=0;i<n;i++)scanf("%lld",&c[i]);
  for(L i=0;i<n;i++){
  	if(v[i]>c[i])tot+=(v[i]-c[i]);
  }
  printf("%lld\n",tot);
  return 0;
}

Measured memory_bytes: 256
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
let a = arr[0]
let b = arr[1]


var sockets = 1
var o = 0
while 1 == 1 {
  if( sockets >= b ) {
    break
  }
  
  sockets = sockets - 1 + a
  o += 1
  //print( sockets )
}

print( o )

Measured memory_bytes: 4208
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
    }
} fast;
void check_input() {
    assert(cin.eof() == 0);
    int tmp;
    cin >> tmp;
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
// #define int long long

signed main() {
    //input
    int N;cin>>N;
    vector<int> x(N);
    rep(n, N) cin>>x[n];
    int L;cin>>L;
    int Q;cin>>Q;

    //solve
    vector<vector<int>> db(N, vector<int>(18));
    rep(n, N){
        // fill: db[n][0]
        // x[n] + L
        db[n][0] = upos(x, x[n]+L) - 1;
    }

    rep(k, 1, 18){
        rep(n, N){
            // fill: db[n][k];
            db[n][k] = db[db[n][k-1]][k-1];
        }
    }
    dump_2d(db, N, 18);

    rep(q, Q){
        int a,b;
        cin>>a>>b;
        a--;b--;
        if (a>b) swap(a, b);
        // db[a][x]<=bとなる最大
        int ans = 0;
        while (a!=b){
            dump(a, b);
            int k = lpos(db[a], b) - 1;
            if (k==-1){
                ans++;
                break;
            }
            ans += pow(2, k);
            dump(k, ans);
            a = db[a][k];
        }
        cout << ans << endl;
    }

    return 0; 
}


Measured memory_bytes: 13312