akhauriyash/Code-Regression huggingface dataset:
program ABC151C
    implicit none
    integer(8)::N,M,p,i
    integer(8)::ac=0
    integer(8)::pen=0
    character(2)::S
    integer(8),allocatable,dimension(:)::flgs,w_count

    read(5,*)N,M
    allocate(flgs(N))
    allocate(w_count(N))
    flgs=0
    w_count=0

    if(M/=0)then
        do i=1,M
            read(5,*)p,S

            if(S=="WA")then
                if(flgs(p)==0)then
                    w_count(p)=w_count(p)+1
                end if
            else if(S=="AC")then
                if(flgs(p)==0)then
                    ac=ac+1
                    flgs(p)=1
                end if
            end if
        end do

        do i=1,N
            if(flgs(i)==1)then
                pen=pen+w_count(i)
            end if
        end do
    end if

    print'(i0,1x,i0)',ac,pen
end program ABC151C

Measured memory_bytes: 1792
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))


def binSearch(A, key):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False

ans = []
for i in t:
    v = binSearch(s, i)
    if v != False:
        ans.append(v)

print(len(set(ans)))


Measured memory_bytes: 16716
def main():
    import sys
    from math import sqrt
    input = sys.stdin.readline

    mod = 1000000007
    N, K = map(int, input().split())
    n = int(sqrt(N))
    dp = [[0] * (2*n+1) for _ in range(K+1)]
    dp[0][1] = 1

    num = [0] * (n+1)
    for i in range(1, n):
        num[i] = N // i - N // (i+1)
    num[n] = N // n - n

    for i in range(K):
        cs = dp[i][:n+1]
        cs2 = dp[i][n+1:]
        for j in range(1, n+1):
            cs[j] = (cs[j] + cs[j-1])%mod
        for j in range(1, n):
            cs2[j] = (cs2[j] + cs2[j-1])%mod
        for j in range(1, n+1):
            dp[i+1][-j] = (cs[j] * num[j])%mod
            dp[i+1][j] = (cs2[-j] + cs[n])%mod
    ans = 0
    for a in dp[-1]:
        ans = (ans + a)%mod
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 117872
#include <iostream>
#include <cmath>
#define	NUM		1000000
using namespace std;

bool sosuu[NUM+1] = {false};
int t = 0;
int out[30];

void Prime(int a)
{
	int count = 0;
	int x;
	x = floor(sqrt(a));
	for(int i = 2; i < x+1; i++){
		if(sosuu[i] == true){
			continue;
		}
		for(int j = 2*i; j < a+1; j = j+i){
			sosuu[j] = true;
		}
	}
	for(int i = 2; i < a+1; i++){
		if(sosuu[i] == false){
			count++;
		}
	}
	out[t] = count;
}

int main()
{
	int n;
	while(cin >> n){
		Prime(n);
		t++;
	}
	for(int i = 0; i < t; i++){
		cout << out[i] << endl;
	}
}

Measured memory_bytes: 2136
#include<stdio.h>
#define max 100
#define inf 10000000
int main(){

  int n, u, k,v, c, i, j, min;
  int d[max],node[max][max],jud[max];

  scanf("%d",&n);
  for(i = 0; i < n;i++){
    for(j = 0;j <n;j++){
      node[i][j] = -1;
    }
  }

  for(i = 0;i < n ;i++){
    scanf("%d %d",&u,&k);
    for(j = 0;j < k;j++){
      scanf("%d %d",&v,&c);
      node[i][v] = c;
    }
  }

  for(i = 0;i <n;i++){
    d[i] = inf;
    jud[i] = 1;
  }

  d[0] = 0;

  while(1){
    min = inf;
    for(i = 0;i <n;i++){
      if(min > d[i] &&jud[i] == 1){
	u = i;
	min = d[i];
      }
    }
    if(min == inf)break;
    jud[u] = 0;
    for(j = 0;j < n;j++){
      if(node[u][j] == -1)continue;
	if(d[j] > d[u] + node[u][j]){
	  d[j] = d[u] + node[u][j];
	}
    }
  }

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

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#include "string"
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)
const int N = 2e6 + 5;
int a,b,n;

int fl(int x){
	int tt = (a*x)/b - a*(x/b);
	//cout<<x<<" "<<tt<<endl;
	return tt;
}

int32_t main() { 
    boost;
    cin>>a>>b>>n;
    int x = (n/b)*b;
    int ans = fl(n);
    if(x>2)
    	 ans = fl(x-1);
    
    for(int i=1;i<=sqrt(n);i++)
    	ans = max(ans,fl(i));
    cout<<ans<<endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<long long> vec(N);
  long long a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    vec.at(i) = a;
  }
  
  int Ans = 0;
  bool B = 1;
  for (int i = 0; i < N-2; i++) {
    for (int j = i+1; j < N-1; j++) {
      for (int k = j+1; k < N; k++) {
        if (vec.at(j) == vec.at(k) || vec.at(k) == vec.at(i) || vec.at(i) == vec.at(j))
          continue;
        else {
          int L = abs(vec.at(j)-vec.at(k));
          int M = vec.at(j)+vec.at(k);
          if (L < vec.at(i) && vec.at(i) < M)
            Ans++;
        }
      }
    }
  }
  cout << Ans << endl;
}


Measured memory_bytes: 3596
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int a, b;
  //  cout << ans << endl;
    cin >> a >> b;
    if (a+b>=10) cout << "error" << endl;
    else cout << a+b << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
          if(n/i==i)
            c++;
          else
            c+=2;
        }

    }

    
    return  c;
}
int func(int n)
{
    return (n*(n+1))/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   
   int a,b;
   cin>>a>>b;
   int n=b-a;
   int ans=func(n-1)-a + func(n)-b;
   cout<<ans/2;




 return 0;
}








Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
typedef long long ll;
using namespace std;
const int INF = 1e9;

int main() {
    int n, W;
    cin >> n >> W;
    vector<int> v(n), w(n);
    rep(i, n) cin >> v[i] >> w[i];

    vector<vector<ll>> dp(n + 1, vector<ll>(W + 1));

    rep(i, n) {
        rep(j, W + 1) {
            if (j >= w[i])
                dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
            else
                dp[i + 1][j] = dp[i][j];
        }
    }

    cout << dp[n][W] << endl;

    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



int main(){
    int n;
    cin >> n;
    V<int> a(n);
    rep(i,n) cin >> a[i];
    V<ll> sums(n+1);
    sums[1] = a[0];
    for(int i = 2; i <= n; i++) {
        sums[i] = a[i-1] + sums[i-1];
    }
    ll ans = infll;
    for(int i = 2; i <= n-2; i++) {

        auto func = [&](int L, int R) {
            int l = L; int r = R;
            while(abs(r-l) > 1) {
                int mid = (r+l)/2;
                ll p = sums[mid]-sums[L];
                ll q = sums[R]-sums[mid];
                if(p < q) l = mid;
                else r = mid;
            }
            Pl res;
            if(abs((sums[l]-sums[L])-(sums[R]-sums[l])) > abs((sums[r]-sums[L])-(sums[R]-sums[r])))
                res = make_pair(sums[r]-sums[L], sums[R]-sums[r]);
            else
                res = make_pair(sums[l]-sums[L], sums[R]-sums[l]);
            return res;
        };

        Pl a = func(0,i);
        Pl b = func(i,n);
        ll tmp = max({a.fi, a.se, b.fi, b.se}) - min({a.fi, a.se, b.fi, b.se});
        chmin(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5640
#!/usr/bin/env python
# coding: utf-8

# In[7]:


S = input()


# In[8]:


s_set = set(S)
if "S" in s_set and "N" in s_set:
    if "E" in s_set and "W" in s_set:
        print("Yes")
    elif "E" in s_set or "W" in s_set:
        print("No")
    else:
        print("Yes")
elif "S" in s_set or "N" in s_set:
    print("No")
else:
    if "E" in s_set and "W" in s_set:
        print("Yes")
    elif "E" in s_set or "W" in s_set:
        print("No")
    else:
        print("Yes")


# In[ ]:






Measured memory_bytes: 9064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdio>


using namespace std;

int N, M;

int main() {

    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &p[i]);
    }
    sort(p.begin(), p.end());
    
    cin >> M;
    vector<int> q(M);
    for (int i = 0; i < M; i++) {
        scanf("%d", &q[i]);
    }
    sort(q.begin(), q.end());

    int cur = 0;
    for (int i = 0; i < N; i++) {
        if (q[cur] == p[i]) cur++;
        if (cur >= M) break;
    }

    if (cur == M) cout << "YES\n";
    else cout << "NO\n";
}


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

using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  string dist = "keyence";

  if (s.size() == 7) {
    if (s == dist) puts("YES");
    else puts("NO");
    return 0;
  }
  
  int n_remove = s.size() - dist.size();

  for (int i = 0; i <= s.size() - n_remove; ++i) {
    int last = i + n_remove - 1;
    string tmp = "";
    for (int j = 0; j < s.size(); ++j) {
      if (j < i || j > last) tmp += s[j];
    }
    if (tmp == dist) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}




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

int main(){
  string s;
  cin >> s;
  if(s[0] == s[1] && s[1] == s[2])
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  
  return 0;
}

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

a = [x for x in a if x % 2 == 0]
a = [x for x in a if x % 3 != 0 and x % 5 != 0]

if len(a) == 0:
    print('APPROVED')
else:
    print('DENIED')



Measured memory_bytes: 62000
def main():
    N, M = map(int, input().split())
    y = []
    for i in range(M):
        y.append(list(map(int, input().split())))
    youbou = sorted(y, key = lambda x:x[1])
    
    cnt = 0
    k = 0
    for i in range(M):
        if(youbou[i][0] >= k):
            cnt += 1
            k = youbou[i][1]
    print(cnt)
main()

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

int main(){
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    long long M=-1000000000000000000;
    M=max(M,a*c);
    M=max(M,a*d);
    M=max(M,b*c);
    M=max(M,b*d);
    cout << M << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 3680
#include <stdio.h>
 
int main(){
 
  int i,j,a[26];
  int n,h = 32;
 
 
  while(1) {
    h = 32;
  scanf("%d",&n);
  if(n == 0) break;
 
 
  for(i=0;i<n;i++) scanf("%d",&a[i]);
 
  i = 0;
  while(1) {
 
    h = h -(h-1)%5;
    printf("%d\n",h);
 
 
    h -= a[i%n];
    if(h>0) printf("%d\n",h);
    else {
      printf("0\n");
      break;
    }
 
    i++;
 
  }
   
  }
 
  return 0;
 
}

Measured memory_bytes: 1040
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;
const string sp = " ";
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans= fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

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

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

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int> factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

string s;
int n;
int cnt[3];
signed main() {
  cin>>s;
  n=s.size();
  rep(i,n) {
    cnt[s[i]-'a']++;
  }
  if(min({cnt[0],cnt[1],cnt[2]})>=max({cnt[0],cnt[1],cnt[2]})-1) puts("YES");
  else puts("NO");
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int n,m;
    while(cin>>n>>m,n){
        int a[n+1]={},x,y,ans=0;
        r(i,n){
            cin>>x>>y;
            a[x]=max(a[x],y);
        }
        r(i,n+1)ans+=a[i];
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3068
import kotlin.math.floor

fun main() {
    abc165b()
}

fun abc165b() {
    val x = readLine()!!.toLong()
    var n = 0
    var current = 100L
    while (current < x) {
        val r = floor(current * 0.01).toLong()
        current += r
        n++
    }
    println(n)
}

Measured memory_bytes: 34448
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define P pair<int,int>
#define inf 1000000007
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
ll llmin(ll a,ll b){
  if(a>b) return b;
  else return a;
}

//cout << setprecision(123);
int main(){
  int N,M,a,b=inf,ans;
  cin>>N>>M;
  vector<pair<int,int>>v(M);
  REP(i,M) cin>>v[i].first>>v[i].second;
  sort(v.begin(),v.end());
  a=v[M-1].first;
  
  REP(i,M){
    b=min(b,v[i].second);
    if(a>b){
      ans=0;
      break;
    }
  }
  if(a<=b){
    ans=b-a+1;
  }
  
  cout << ans <<endl;
}

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    for (int i = 1; i < N; i++) A[i] += A[i - 1];

    ll res = INT64_MAX;
    int left = 0, mid = 1, right = 2;
    while (mid < N - 2) {
        while (left < mid - 1) {
            ll prev = abs(A[mid] - 2 * A[left]);
            ll next = abs(A[mid] - 2 * A[left + 1]);
            if (prev > next) left++;
            else break;
        }

        while (right < N - 2) {
            ll prev = abs((A[N - 1] - A[mid]) - 2 * (A[right] - A[mid]));
            ll next = abs((A[N - 1] - A[mid]) - 2 * (A[right + 1] - A[mid]));
            if (prev > next) right++;
            else break;
        }

        ll P = A[left];
        ll Q = A[mid] - A[left];
        ll R = A[right] - A[mid];
        ll S = A[N - 1] - A[right];

        res = min(res, max({P, Q, R, S}) - min({P, Q, R, S}));
        mid++;
    }

    cout << res << endl;
    return 0;
}

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

const int MAX_N = 100010;
vector<int> G[MAX_N];

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

    vector<int> in(N, 0);

    for(int i = 0; i < M; i++)
    {
        int x;
        int y;
        cin >> x >> y;
        x--;
        y--;
        G[x].push_back(y);
        in[y]++;
    }

    queue<int> st;
    for(int i = 0; i < N; i++) if(in[i] == 0) st.push(i);

    vector<int> dp(N, 0);

    while(st.size())
    {
        int v = st.front();
        st.pop();
        for(const auto& to:G[v])
        {   
            in[to]--;
            if (in[to] == 0)
            {
                st.push(to);
                dp[to] = max(dp[to], dp[v] + 1);
            }
        }
    }

    cout << *max_element(dp.begin(), dp.end()) << endl;
}

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

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

typedef long long ll;
typedef long long int64;

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

  ll ret = n;

  for(int i=1; i<s.size(); i++){
    if(s[i-1] == s[i]) ret--;
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#define l int64_t
#define c continue;
#define o(a) cout<<a<<endl;
#define r(i,x,y) for(l i=x;i<y;i++){
using namespace std;
int main(){l m=1e9+7,x,y,z,w,o,p,v[93],t[91][91][2],b;v[0]=1,v[1]=1;r(i,2,93)v[i]=v[i-1]+v[i-2];}r(i,2,91)r(j,1,i)b=v[i+1];if(j<2){t[i][0][0]=v[i],t[i][0][1]=b,t[i][j][0]=b,t[i][j][1]=2*b-v[i];c;}t[i][j][0]=t[i-1][j-1][1],t[i][j][1]=t[i-1][j-1][1]+t[i-1][j-1][0];}}cin>>b;while(b--){cin>>x>>y;if(x>y)swap(x,y);if(y<2){o("1 1")c}r(i,0,93)if(v[i]>x||v[i+1]>y){z=i-1,o(z)break;}}if(z<2){o(x*y%m)c}w=0;r(j,0,z)o=t[z][j][0],p=t[z][j][1];if(o>x||p>y)c w+=(y-p)/o+1;if(x>=p)w+=(x-p)/o+1;}o(w%m)}}

Measured memory_bytes: 4424
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

int main(){
    int w, h, x, y; cin>>w>>h>>x>>y;

    double S = 1. * w * h / 2;
    cout << fixed << setprecision(10) << S << " ";
    if(x == w / 2 && y == h / 2 && w % 2 == 0 && h % 2 == 0){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


from heapq import heappush, heappop

def dijkstra(graph: list, start, INF=float('inf')) -> list:
    n = len(graph)
    dist = [INF ] *n
    visited = [False ] *n

    dist[start] = 0
    que = [(0, start)]

    while que:
        cost, cur = heappop(que)

        if visited[cur]:
            continue

        visited[cur] = True

        for nextnode, edgecost in graph[cur]:
            nextcost = cost + edgecost
            if nextcost < dist[nextnode]:
                dist[nextnode] = nextcost
                heappush(que, (nextcost, nextnode))

    return dist


n, m = li()

graph = [[] for _ in range(3*n)]
for _ in range(m):
    u, v = li_()
    for i in range(3):
        graph[i*n + u].append([(i+1)%3 * n + v, 1])

s, t = li_()
INF = 1<<62
dist = dijkstra(graph, s, INF)

print(-1 if dist[t] == INF else dist[t] // 3)


Measured memory_bytes: 90712
#include <iostream>

int main() {

	int A, B, C, K;
	std::cin >> A >> B >> C >> K;

	int sum = 0;
	int i = 1;

	while (i <= K) {
		if (i <= A) {
			sum += 1;
		}
		else if (i <= A + B) {
		}
		else if (i <= A + B + C) {
			sum -= 1;
		}
		i++;
	}
	std::cout << sum << std::endl;
};

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int x, n,count=1;
	cin >> n >> x;
	vector<int>l(n);
	vector<int>d(n+1);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	d[0] = 0;
	for (int i = 1; i < n; i++) {
		d[i] = d[i - 1] + l[i - 1];
		count++;
		d[i + 1] = d[i] + l[i];
		if (d[i + 1] > x&&d[i] <= x) {
			cout << count << endl;
			//cout << d[i] << endl;
			//cout << d[i+1] << endl;
			exit(0);
		}
		if (i==n-1&&d[i + 1] <= x) {
			cout << count + 1 << endl;
		}
	}

}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
  long a,v,b,w,t;
  scanf("%ld" "%ld", &a, &v);
  scanf("%ld" "%ld", &b ,&w);
  scanf("%ld", &t);
  int dif = abs(a-b);
  if(dif-v*t+w*t<=0){
    printf("YES");
  }else{
    printf("NO");
  }
  return 0;
}

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


int main(){
    int n,m;
    cin >> n >> m;
    vector<int> p(m),y(m);
    vector<int> s[n];
    rep(i,m){
        cin >> p[i] >> y[i];
        p[i]--;
        s[p[i]].push_back(y[i]);
    }
    rep(i,n) sort(s[i].begin(),s[i].end());
    rep(i,m){
        auto it = lower_bound(s[p[i]].begin(),s[p[i]].end(),y[i]);
        int now = distance(s[p[i]].begin(),it);
        printf("%012lld\n",ll(p[i]+1)*1000000+ll(now+1));
    }
    return 0;
}

Measured memory_bytes: 9328
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC118C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt;

            var A = NextLongs;

            long ans = Gcd(A[0], A[1]);
            for (int i = 2; i < N; i++)
            {
                ans = Gcd(ans, A[i]);
            }

            Console.WriteLine(ans);
        }

        /// <summary>
        /// 最大公約数
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 22880
def main():
    N = input()
    A_raw = input().split(' ')
    A_n = []
    for i in A_raw:
        A_n.append(int(i))
    
    A_n.sort()
    
    for i in range(len(A_n)):
        if i == len(A_n)-1:
            print('YES')
        elif A_n[i] == A_n[i+1]:
            print('NO')
            return 0
    return 0

main()

Measured memory_bytes: 25940
#include <cstdio>
#include <random>
using namespace std;

random_device rd;
mt19937 mt(rd());

template <typename T>
struct tree
{
	struct node
	{
		T v;
		int c, p;
		node *n[2];

		node(T x)
		{
			v = x;
			c = 1;
			p = mt();
			n[0] = n[1] = nullptr;
		}
	};

	typedef node N;
	N *root;
	long counter;

	tree()
	{
		root = nullptr;
		counter = 0;
	}

	inline int count(N *n) {return n ? n->c : 0;}

	N* rotate(N* r, int b) 
	{
		N *s = r->n[1 - b];

		r->c += count(s->n[b]) - count(r->n[1 - b]);
		r->n[1 - b] = s->n[b];

		s->c += r->c - count(s->n[b]);
		s->n[b] = r;
		return s;
	}

	N* insert(int x, N *t, int cnt)
	{
		if (!t) {
			counter += cnt;
			return new N(x);
		}
		int b = !(x < t->v);
		if (b)
			cnt -= 1 + count(t->n[0]);
		t->n[b] = insert(x, t->n[b], cnt);
		t->c++;
		return (t->p > t->n[b]->p) ? rotate(t, 1 - b) : t;
	}

	void insert(T x)
	{
		root = insert(x, root, count(root));
	}
};

static inline int in()
{
    int c, n = 0;
    while ((c = getchar_unlocked()) >= '0' && c <= '9')
		n = 10 * n + (c - '0');
    return n;
}

int main()
{
	int	n = in();

	tree<int> t;
	while (n--)
		t.insert(in());

	printf("%ld\n", t.counter);
}



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

int main(){
  int n;
  cin >> n;
  if(n==22){
    cout << "Christmas Eve Eve Eve" << endl;
  }
  else if(n==23){
    cout << "Christmas Eve Eve" << endl;
  }
  else if(n==24){
    cout << "Christmas Eve" << endl;
  }
  else if(n==25){
    cout << "Christmas" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}

pii get(string s){
	stack<char> st;
	pii ans = {0, 0};
	for(auto &c : s){
		if(c == '(')
			st.push(c);
		else{
			if(st.empty())
				ans.first++;
			else{
				st.pop();
			}
		}
	}

	ans.second = (int)st.size();

	return ans;
}

bool balanced(string &s){
	int bal = 0;
	for(auto &c : s){
		if(c == '(')
			bal++;
		else
			bal--;
		if(bal < 0)
			return false;
	}
	return bal == 0;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);


	int n;
	cin >> n;

	vector<pii> v1, v2;

	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		pii x = get(s);

		if(x == pii(0, 0))
			continue;

		if(x.second > x.first)
			v1.push_back(x);
		else
			v2.push_back(pii(x.second, x.first));
	}

	sort(v1.begin(), v1.end());
	sort(v2.rbegin(), v2.rend());

	string s = "";

	for(auto &p : v1){
		for(int i = 0; i < p.first; i++)
			s += ")";
		for(int i = 0; i < p.second; i++)
			s += "(";
	}

	for(auto &p : v2){
		for(int i = 0; i < p.second; i++)
			s += ")";
		for(int i = 0; i < p.first; i++)
			s += "(";
	}


	if(balanced(s))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 13872
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())

void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
bool sortdes(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasc(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;} 
int gcd(int x,int y){return __gcd(x,y);}

void test_case(){
    int n;
    cin>>n;
    map<string,int> mp;
    fors(i,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    test(mp.size());
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
		test_case();
    }
}

Measured memory_bytes: 19156
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
	static int max;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = 0;
		HashMap<String,Boolean> use = new HashMap<String,Boolean>();
		char pre = 'a';
		while(true) {
			char say = 'a' -1;
			for(int i = 0; i < 26; i++) {
				say = (char)(say + 1);
				if(!use.containsKey(pre + "" + say + "" + 'a')) break;
			}
			char say2 = 'a';
			boolean f = false;
			if(use.containsKey(pre + "" + say + "" + 'a')) {
				f = true;
				for(int i = 0; i < 26; i++) {
					say2 = (char)(say2 + 1);
					if(!use.containsKey(pre + "" + say + "" + say2+ "" + 'a')) break;
				}
			}
			String aa = pre + "" + say + "" + 'a';
			if(f) {
				aa = pre + "" + say + "" + say2+ "" + 'a';
			}
			
			use.put(aa, true);
			
			System.out.println("?" + pre + "" + say + "" + "a");
			
			String get = sc.next();
			if(get.charAt(0) != 'a' || use.containsKey(get) || get.length() >= 3) {
				System.out.println("!OUT");
				return;
			}
			pre = get.charAt(get.length()-1);
			use.put(get, true);
		}
		
		
		
		
	}
}

Measured memory_bytes: 17368
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b=sc.nextInt();
		int max=a+b;
		if(a-b>=max) max=a-b;
		if(a*b>=max) max=a*b;

		System.out.println(max);


	}
}


Measured memory_bytes: 23764
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	int N, K, Q;
	N = sc.nextInt();
	K = sc.nextInt();
	Q = sc.nextInt();

	int A[] = new int[Q];
	for (int i = 0; i < Q; i++) {
	    A[i] = sc.nextInt();
	}
	int X[] = new int[N];
	for (int i = 0; i < N; i++)  {
	    X[i] = K - Q;
	}
	for (int i = 0; i < Q; i++) {
	    X[A[i] - 1]++;
	}

	for (int i = 0; i< N; i++) {
	    if (X[i] > 0)
		System.out.println("Yes");
	    else
		System.out.println("No");
	}
    }
}

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


dig = [[0 for _ in range(10)] for i in range(10)]

for i in range(1,N+1):
    n = str(i)
    f = int(n[0])
    l = int(n[-1])
    dig[f][l] += 1


ans = 0

for i in range(10):
    for j in range(10):
        ans += dig[i][j]*dig[j][i]

print(ans)

Measured memory_bytes: 3064
N = int(input())
K = int(input())
Ball = list(map(int,input().split()))
sumA = 0
sumB = 0

def SUMa(i):
    sumA = Ball[i]*2
    return sumA
def SUMb(i):
    sumB = (K-Ball[i]) *2
    return sumB

goukei = 0
for i in range(0,N):
    if SUMa(i) > SUMb(i):
        goukei += SUMb(i)
    else:
        goukei += SUMa(i)

print(goukei)

Measured memory_bytes: 3064
import collections

n = int(input())
an = []
for i in range(n):
    a = input()
    an.append(a)

c = list(collections.Counter(an).values())
Ans = 0
for i in range(len(c)):
    if int(c[i]) % 2 == 1:
        Ans = Ans + 1

print(Ans)

Measured memory_bytes: 23856
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main(void) {
    int i, j, k, l, N;
    while(cin >> N) {
        int ans = 0;
        for(i = 0; i < 10; i++) {
            for(j = 0; j < 10; j++) {
                for(k = 0; k < 10; k++) {
                    for(l = 0; l < 10; l++) {
                        if(i + j + k + l == N) {
                            ans++;
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 0
n = gets.chomp.to_i
s = gets.chomp

scores = []

(1..n-1).each do |variable|
  a = s[0, variable]
  b = s[variable, n]

  score = 0
  ('a'..'z').map do |char|
    score += a.include?(char) && b.include?(char) ? 1 : 0
  end

  scores << score
end

puts scores.max

Measured memory_bytes: 1788
from math import ceil, floor
N = int(input())
A = list(map(int, input().split()))
average = sum(A) / N
floor_A = floor(average)
ceil_A = ceil(average)
floor_sum = 0
ceil_sum = 0
for a in A:
    floor_sum += (a - floor_A) ** 2
    ceil_sum += (a - ceil_A) ** 2
print(min(ceil_sum, floor_sum))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin >> n;
    double result=0;

    double tmpn;
    string tmps;
    while(n--){
        cin >> tmpn >> tmps;
        if(tmps[0]=='J'){
            result += tmpn;

        }else{
            result += tmpn * 380000.0;
        }
    }
    cout << result << endl;


    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
const int INFI=2147483647;
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


ll power10(ll a, ll p){
  // 10^a mod pを求めたい
  if (a == 0) return 1;
  ll tmp = power10(a/2, p);
  if (a % 2 == 0) return tmp * tmp % p;
  else return tmp * tmp % p * 10 % p;
}

int main() {
  int n,p; cin >>n >>p;
  string s; cin >>s;
  ll res = 0;
  if (p == 2 || p == 5){
    // 右端が割り切れるかどうかのみで決まる
    for (int i=n-1; i>=0; i--){
      int digit = s.at(i) - '0';
      if (digit % p == 0){
        res += i+1;
      }
    }
  }else{
    map<int, int> t;
    // Ui:Sのi-N文字目までを評価した整数とする。Un+1=0とする。
    // Sのi-j文字目までを評価した整数は、p=2,5のときは右端が割り切れるかどうかのみで決まる。
    // pがそれ以外の時は、(Ui-Uj+1)/10^hatenaだが、pと10が互いに素なのでUi-Uj+1が割り切れるかどうかで決まる。
    // というわけでSを右から見ていき、Ui mod p を格納しつつ進んでいく。
    // t[key] = value...key:Ui mod p の値。value:その値であるUiがいくつあったか。
    t[0] = 1;
    ll tmp = 0;
    for (int i=n-1; i>=0; i--){
      int digit = s.at(i) - '0';
      tmp = tmp + power10(n-1-i, p) * digit % p;
      tmp %= p;
      if (t.count(tmp)){
        res += t.at(tmp);
      }
      t[tmp]++;
    }
  }
  cout <<res <<endl;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

// {{{ Union Find  to use UFinit(n) for 0-n UFs

int UFpare[190004];
int UFrank[190004];
void UFinit(int n){
    for (int i = 0; i <= n; i++) {
        UFpare[i] = i;
        UFrank[i] = 0;
    }
}
int UFroot( int x ){
    if( UFpare[x] == x ) return x;
    else{
        return UFpare[x] = UFroot(UFpare[x]);
    }
}
void UFunion( int x , int y ){
    x = UFroot(x);
    y = UFroot(y);
    if( x == y ) return;
    if( UFrank[x] < UFrank[y] ){
        UFpare[x] = y;
    }else{
        UFpare[y] = x;
        if ( UFrank[x] == UFrank[y] ) UFrank[x]++;
    }
}
bool UFsame( int x, int y){
    return UFpare[x] == UFpare[y];
}


/*
 * UFinit(n) := initialize Union Find with n UFs( must operate )
 * UFpare[] = root of node
 * UFrank[] = rank of root
 * UFroot(x) := return root of node
 * UFunion(x,y) := unite two root in a root
 * UFsame(x,y) := return two root is same
 */
// }}}


int main() {

    int n,m;
    int a[500] , b[500];
    Scd2(n,m);
    Rep(i,m){
        Scd2(a[i],b[i]);
    }

    int tmp;
    int ans = 0;
    Rep(ign,m){
        UFinit(n);
        Rep(i,m){
            if( i == ign)
                continue;
            UFunion(a[i],b[i]);
        }
        tmp = UFroot(1);
        Repe(i,n+1,2){
            if( tmp != UFroot(i) ){
                ans++;
                break;
            }
        }
    }

    printf ("%d\n", ans);

    return 0;
}



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

b = []
c = [0 for i in range(n+1)]

for i in reversed(range(1, n+1)):
    cnt = 0
    for j in range(1, n // i + 1):
        cnt += c[j * i]
    if (cnt + a[i-1]) % 2:
        c[i] = 1
        b.append(i)

print(len(b))
print(" ".join(list(map(str, b))))

Measured memory_bytes: 19868
def f(s):
  while 1:
    b=s.find(")")
    if b<0: return g(s)
    a=s[:b].rfind("(")
    s=s.replace(s[a:b+1],f(s[a+1:b]))

def g(s):
  a=""
  f=1
  x=[]
  def F(a,b):
    x.append(a)
    x.append(b)
    return 1,""
  for c in s:
    if c=="=": continue
    elif c in "*/": f,a=F(a,c)
    elif c in "+-":
      if f==1: f,a=0,c
      else: f,a=F(a,c)
    else: f,a=0,a+c
  x.append(a)

  s=x[:]
  x=[]
  f=""
  for e in s:
    if e in "+-": x.append(e)
    elif e in "*/": f=e
    else:
      a=int(e)
      if f=="*": a*=x.pop()
      elif f=="/": a=int(1.0*x.pop()/a)
      x.append(a)
      f=""

  a,f=0,1
  for e in x:
    if e=="+": f=1
    elif e=="-": f=-1
    else: a+=f*e
  return str(a)

n=input()
for _ in [0]*n:
  print f(raw_input())

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

signed main(){
    int n,p;
    cin >> n >> p;
    int t = sqrt(p);
    int ans=1;
    int y;
    //cerr << t;
    if(n!=1){
    for(int i=1;i<t;i++){
        y=0;
        while(p%(i+1)==0){
            p= p/(i+1);
            y++;

        }
       // cerr<< y;
        while(y>=n){
            ans *= (i+1);
            y -=n;
        }
        
    }

    cout << ans;
    }else{
        cout << p;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
x,y = map(int,input().split())
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=2
if x==2 or y==2:
    print("No")
    sys.exit()
elif (x in a) and (y in a):
    print("Yes")
    sys.exit()
elif (x in b) and (y in b):
    print("Yes")
    sys.exit()
else: print("No")
    



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll n,a,b;
    cin>>n>>a>>b;
    if(a==0){
        cout<<0; return 0;
    }
    if(n<=a+b){
        cout<<min(n,a); return 0;
    }
    ll ans=n/(a+b)*a+min(n%(a+b),a);
    cout<<ans;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int X,Y,Z;
    cin >>X>>Y>>Z;
    cout << (X-Z)/(Y+Z) << endl;



}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <climits>
#include <set>


using namespace std;

typedef long long ll;


ll res=LLONG_MAX;
void check(int x,int y)
{
    for(int i=1;i<x;i++)
    {
        ll s1=(ll)i*y;
        ll s2,s3;
        ll tx=x-i,ty=y;
        for(int j=0;j<2;j++)
        {
            if(j)
            {
                swap(tx,ty);
                s2=(ll)(tx/2)*ty;
                s3=(ll)(tx-tx/2)*ty;
                ll mi=min(s1,min(s2,s3));
                ll ma=max(s1,max(s2,s3));
                if(abs(ma-mi)<res) res=abs(ma-mi);
            }
            else
            {
                
                s2=(ll)(tx/2)*ty;
                s3=(ll)(tx-tx/2)*ty;
                ll mi=min(s1,min(s2,s3));
                ll ma=max(s1,max(s2,s3));
                if(abs(ma-mi)<res) res=abs(ma-mi);
            }
        }
    }
}

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
//    if(n%3==0||m%3==0)
//    {
//        cout<<"0"<<endl;
//        return 0;
//    }
    check(n,m);
    check(m,n);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdint>
using namespace std;

const int MOD = 1000000007; // 今回使う余り

class Factorial{
	private:
		int mod;
		int n;
		vector<int> fact, inv;
		void calc();
	public:
		Factorial(int mod, int n);
		int add(int a, int b);
		int sub(int a, int b);
		int mul(int a, int b);
		int div(int a, int b);
		int rem(int a, int b);
		int power(int a, int b);
		int getCombination(int a, int b);
		int getPermutation(int a, int b);
		int getFactorial(int a);
		int getInverse(int a);
};

/**
 * 関数の初期化を行います。この時に空間O(n)と計算時間O(n)が必要なことに注意してください。
 * @param mod 用いる余り ※必ず素数にすること
 * @param n 用意する階乗の範囲
 */
Factorial::Factorial(int mod, int n) {
	Factorial::mod = mod;
	Factorial::n = n;
	fact.resize(n + 1, 1);
	inv.resize(n + 1, 1);
	calc();
}

void Factorial::calc() {
	for (int i = 1;i <= n;++i) {
		fact[i] = mul(fact[i - 1], i);
	}
	inv[n] = power(fact[n], mod - 2);
	for (int i = n - 1;i >= 0;--i) {
		inv[i] = mul(inv[i + 1], i + 1);
	}
}

/**
 * a+bをmod環境下で返します。
 * @param a 足す値
 * @param b 足される値
 * @return (a + b) % mod
 */
int Factorial::add(int a, int b) {
	return ((int64_t)a + b) % mod;
}

/**
 * a-bをmod環境下で返します。
 * @param a 引く値
 * @param b 引かれる値
 * @return (a - b) % mod
 */
int Factorial::sub(int a, int b) {
	return ((int64_t)a - b) % mod;
}

/**
 * a*bをmod環境下で返します。
 * @param a 掛ける値
 * @param b 掛けられる値
 * @return (a * b) % mod
 */
int Factorial::mul(int a, int b) {
	return ((int64_t)a * b) % mod;
}

/**
 * a/bをmod環境下で返します。O(log(mod))な点にご注意ください
 * @param a 割る値
 * @param b 割られる値
 * @return (a / b) % mod
 */
int Factorial::div(int a, int b) {
	return mul(a, power(b, mod - 2));
}

/**
 * a%bを返します。
 * @param a 割る値
 * @param b 割られる値
 * @return a % b
 */
int Factorial::rem(int a, int b) {
	return a % b;
}

/**
 * aのb乗をmod環境下で返します。
 * @param a 底
 * @param b 冪指数
 * @return pow(a, b) % mod
 */
int Factorial::power(int a, int b) {
	if (b == 0) return 1;
	if (b == 1) return a;
	if (b == 2) return mul(a, a);
	if ((b & 1) == 0) return power(power(a, b >> 1), 2);
	return mul(power(power(a, b >> 1), 2), a);
}

/**
 * aCbをmod環境下で返します。
 * @param a 元集合
 * @param b 元
 * @return (aCb) % mod
 */
int Factorial::getCombination(int a, int b) {
	return mul(getPermutation(a, b), getInverse(b));
}

/**
 * aPbをmod環境下で返します。
 * @param a 元集合
 * @param b 元
 * @return (aPb) % mod
 */
int Factorial::getPermutation(int a, int b) {
	return mul(getFactorial(a), getInverse(a - b));
}

/**
 * a!をmod環境下で返します。
 * @param a 計算する値
 * @return a! % mod
 */
int Factorial::getFactorial(int a) {
	return fact[a];
}

/**
 * a!の-1乗をmod環境下で返します。
 * @param a 計算する値
 * @return pow(a!, -1) % mod
 */
int Factorial::getInverse(int a) {
	return inv[a];
}

int main() {
	int H, W, A, B;
	cin >> H >> W >> A >> B;
	
	Factorial f(MOD, H + W);
	int ans = 0;
	for (int i = B;i <= W;i ++) {
		ans = f.add(ans, f.mul(f.getCombination(H - A - 1 + i, i), f.getCombination(A + W - i - 2, W - 1 - i)));
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

こういう移動経路問題は組み合わせ問題なのでライブラリがあると楽よ
後は書いてみれば分かる
*/

Measured memory_bytes: 1792