akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main()
{
    int i = 1;

    while (1)
    {
        int a;
        std::cin >> a;


        if (std::cin.eof()) {
            break;
        }

        if (a != 0) {
            std::cout << "Case " << i << ": " << a << std::endl;

            i += 1;
        }
    }
    return 0;
}

Measured memory_bytes: 1156
from heapq import heappush, heappop

sx, sy, gx, gy = map(int, input().split())
n = int(input())
outs = {tuple(map(int, input().split())) for _ in range(n)}
lx, ly = map(int, input().split())
for x in range(-lx - 1, lx + 2):
  outs.add((x, -ly - 1))
  outs.add((x, ly + 1))
for y in range(-ly - 1, ly + 2):
  outs.add((-lx - 1, y))
  outs.add((lx + 1, y))

dic = {}
dic[(0, sx, sy)] = 0
que = []
heappush(que, (0, 0, sx, sy))
vec1 = ((0, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0))
vec2 = ((0, 1), (1, 1), (1, 0), (0, -1), (-1, 0), (-1, 1))
while que:
  score, time, x, y = heappop(que)
  if (x, y) == (gx, gy):
    print(score)
    break
  vec = vec2 if x % 2 else vec1
  inst = vec[abs(x * y * time) % 6]
  new_time = (time + 1) % 6
  for dx, dy in vec:
    nx, ny = x + dx, y + dy
    if (nx, ny) in outs: continue
    new_score = score if (dx, dy) == inst else score + 1
    if (new_time, nx, ny) not in dic or dic[(new_time, nx, ny)] > new_score:
      dic[(new_time, nx, ny)] = new_score
      heappush(que, (new_score, new_time, nx, ny))

  if (new_time, x, y) not in dic or dic[(new_time, x, y)] > score + 1:
    dic[(new_time, x, y)] = score + 1
    heappush(que, (score + 1, new_time, x, y))
else:
  print(-1)


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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int n, m, c;
int b[500];

int main()
{
	IOS;
	cin >> n >> m >> c;
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	int ans = 0;
	while (n--) {
		int sum = c, e;
		for (int i = 0; i < m; i++) {
			cin >> e;
			sum += e * b[i];
		}
		if (sum > 0) ans++;
	}
	cout << ans << endl;
	return 0;
}



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

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

const long long INF = 1LL << 60;


int main(void){
	int n;cin >> n;
	vector<int> v(n+10,0); 
	for(int i=0;i<n-1;i++){
		int a;cin >> a;
		v[a]++;
	}
	for(int i=1;i<=n;i++){
		cout << v[i] << endl;
	}
	return 0; 
}


Measured memory_bytes: 3976
N, x = io.read("*n", "*n")

a = {}

for v = 1, N do
  a[v] = io.read("*n")
end

table.sort(a)

ans = 0

for v = 1, N do
  x = x - a[v]
  if x < 0 then
    break
  end
  ans = ans + 1
end

if x > 0 then
  ans = ans - 1
end

print(ans)


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

int main() {
    int n, money, health = 0;
    cin >> n;
    money = n;
    while(money >=5 ){
        if(money >= 500) health += 1000, money -= 500;
        else if(money >= 5) health += 5, money -= 5;
    }
    cout << health << endl;
    return 0;
}

Measured memory_bytes: 256
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 1001000
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    cin.sync_with_stdio(false);
    ll n,k;cin>>n>>k;
//    ll ans=ceil((n*1.0+k*1.0)*1.0/(k*1.0));
//    cout<<"ans= "<<ans<<endl;
    ll a1=n%k;
    ll b1=abs(k-a1);
    cout<<min(a1,b1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
long long n,k;
long long cnt,tmp;
double res = 0;
long long c[100005];
long long len = 0;

int main()
{
    cin>>n>>k;
    if(n>=k){
        res += (double)(n-k+1)/(double)(n);
    }
    for(long long i = 1;i<=min(n,k-1);i++){
        tmp = i;
        cnt = 0;
        while(tmp < k){
            tmp*=2;
            cnt+=1;
        }
        c[len++] = cnt;
        double x = 1.0/n;
        x /= (1<<cnt);
        res += x;
    }
    

    printf("%.12lf\n",res);
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int pow(int a,int b);
int main(void){
    int n,k;
    scanf("%d%d",&n,&k);
    int ans = pow(k-1,n-1);
    ans *= k;
    printf("%d\n",ans);
    return 0;
}

int pow(int a,int b){
    int c=1,i=0;
    while(i<b)
    {
        c*=a;
        i++;
    }
    return c;
}

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

using namespace std;

int main()
{
    vector<int> vec(3);
    for (int i = 0; i < 3; i++)
    {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());

    for (int i = 0; i < 3; i++)
    {
        cout << vec.at(i);
        if (i == 2)
        {
            break;
        }
        cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
 
ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}
 
int main(){
    ll n;cin>>n;
  if(n%2==0){
	cout<<(n/2)-1<<endl;
  }else{
	cout<<(n-1)/2<<endl;
  }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
int main(){
    using namespace std;
    int m,f,r,i;
    char a;
    vector<char> v;
    while(1){
        cin >> m >> f >> r;
        if(m==-1&&f==-1&&r==-1){
            break;
        }else if(m==-1||f==-1){
            a = 'F';
        }else if(m+f>=80){
            a ='A';
        }else if(m+f>=65&&m+f<80){
            a = 'B';
        }else if(m+f>=50&&m+f<65){
            a = 'C';
        }else if(m+f>=30&&m+f<50){
            if(r>=50){
                a = 'C';
            }else{
                a = 'D';
            }
        }else{
            a = 'F';
        }
        v.push_back(a);
    }
    for(i=0;i<v.size();i++){
        cout << v[i] << endl;
    }
    return 0;
}

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

#define int long long int

using namespace std;

const int mod = 998244353;

int pow_mod(int a, int p)
{
    int cur = a, ans = 1;

    while (p > 0)
    {
        if (p & 1)
            ans = (ans * cur) % mod;
        p /= 2;
        cur = (cur * cur) % mod;
    }

    return ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    vector<int> d(n);
    vector<int> cnt(n, 0);
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
        cnt[d[i]]++;
    }

    if (d[0] != 0 || cnt[0] != 1)
    {
        cout << "0\n";
        return 0;
    }

    int res = 1;
    for (int i = 1; i < n; i++)
        res = (res * pow_mod(cnt[i - 1], cnt[i])) % mod;

    cout << res << "\n";

    return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

void prime_map(map<ll, ll> &m, ll num) {
    for (ll i = 2; i * i <= num; i++) {
        while (num % i == 0) {
            m[i]++;
            num /= i;
        }
    }
    if (num != 1) {
        m[num] = 1;
    }
    return;
}

int main() {
    ll n;
    cin >> n;
    map<ll, ll> m;
    prime_map(m, n);
    ll ans = 0;
    for (auto iter = m.begin(); iter != m.end(); iter++) {
        ll left = 0, right = iter->second;
        if (right == 1) {
            ans += 1;
            continue;
        }
        while (right - left > 1) {
            ll mid = (right + left) / 2;
            if (mid * (mid + 1) / 2 <= iter->second) {
                left = mid;
            } else {
                right = mid;
            }
        }
        ans += left;
    }
    cout << ans << endl;
    return 0;
}



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

int main(){

    int N;
    cin >>N;
    vector<pair<string,pair<int,int>>>S(N);

    for(int i=0;i<N;i++){
      cin>>S.at(i).first>>S.at(i).second.first;
      S.at(i).second.first*=-1;
      S.at(i).second.second=i;
    }
    sort(S.begin(), S.end());

    for(int i=0;i<N;i++){
          cout<<S.at(i).second.second+1<<endl;
      }
  }


Measured memory_bytes: 256
from collections import Counter

X, A = map(int, input().split())
x = [i - A for i in map(int, input().split())]
x.sort()
dp = Counter()

for i in x:
    for j, k in list(dp.items()):
        dp[j + i] = dp[j + i] + k
    dp[i] += 1

print(dp[0])

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


struct UnionFind {
  vll d;
  UnionFind(ll n=0): d(n,-1) {}
  ll find(ll x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(ll x, ll y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(ll x, ll y) { return find(x) == find(y);}
  ll size(ll x) { return -d[find(x)];}
};



int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n,m;
  cin>>n>>m;


  vector<vll> g(m);
  REP(i,n){
    ll k;
    cin>>k;

    REP(j,k){
      ll l;
      cin>>l;
      l--;
      g[l].push_back(i);
    }
  }

  UnionFind uf(n);
  REP(i,m){
    REP(j,g[i].size())
      uf.unite(g[i][0],g[i][j]);
  }


  bool flag=true;
  ll x=uf.find(0);
  if(uf.find(0)<0)
    x=0;

  REP1(i,n){
    if(x!=uf.find(i))
      flag=false;
  }

  if(flag)
    YES;
  else
    NO;
}



Measured memory_bytes: 4736
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
// using namespace __gnu_pbds;
using namespace std;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair <long long,long long> ii;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ld a,b;
    cin >> a >> b;
    a--;b--;
    cout << ceil(b/a) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <map>
#include <vector>
//#include <unordered_map>
//#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long LL;
using namespace std;
const int maxn=200005;
const int inf=0x3f3f3f3f;
int pos[maxn];
int seq[maxn];
int n;
int tot;
int Max[maxn << 2],Max2[maxn<<2];
void push_up(int rt)
{
    Max[rt] = min(Max[rt << 1], Max[rt << 1 | 1]);
}
void push_up2(int rt)
{
    Max2[rt] = min(Max2[rt << 1], Max2[rt << 1 | 1]);
}
void build(int l=1, int r=n, int rt=1)
{
    if(l == r)
    {
        if(l&1) Max[rt]=seq[l];
        else Max[rt]=inf;
        return;
    }
    int mid = (l + r) >> 1;
    build(lson);
    build(rson);
    push_up(rt);
}
int query(int L, int R, int l=1, int r=n, int rt=1)
{
    if(L <= l && R >= r) return Max[rt];
    int cnt = inf;
    int mid = (l + r) >> 1;
    if(L <= mid) cnt = min(cnt, query(L, R, lson));
    if(R > mid) cnt = min(cnt, query(L, R, rson));
    return cnt;
}

void build2(int l=1, int r=n, int rt=1)
{
    if(l == r)
    {
        if((l&1)==0) Max2[rt]=seq[l];
        else Max2[rt]=inf;
        return;
    }
    int mid = (l + r) >> 1;
    build2(lson);
    build2(rson);
    push_up2(rt);
}
int query2(int L, int R, int l=1, int r=n, int rt=1)
{
    if(L <= l && R >= r) return Max2[rt];
    int cnt = inf;
    int mid = (l + r) >> 1;
    if(L <= mid) cnt = min(cnt, query2(L, R, lson));
    if(R > mid) cnt = min(cnt, query2(L, R, rson));
    return cnt;
}
struct node
{
    int x,y,z;
    node() {}
    node(int a,int b,int c):z(a),x(b),y(c) {}
    friend bool operator < (node a,node b)
    {
        return a.z > b.z;
    }
};
void solve()
{
    priority_queue<node >que;
    que.push(node(query(1,n),1,n));
    node t;
    int l,r;
    while(!que.empty())
    {
        t=que.top();
        l=t.x;
        r=t.y;
        que.pop();
        if(l&1)
        {
            int a=query(l,r);
            a=pos[a];
            int b=query2(a+1,r);
            b=pos[b];
            printf("%d %d ",seq[a],seq[b]);
            //cout<<"ha"<<a<<' '<<b<<endl;
            if(a>l)
                que.push(node(query(l,a-1),l,a-1));
            if(a<b-1)
                que.push(node(query2(a+1,b-1),a+1,b-1));
            if(b<r)
                que.push(node(query(b+1,r),b+1,r));
        }
        else
        {
            int a=query2(l,r);
            a=pos[a];
            int b=query(a+1,r);
            b=pos[b];
            printf("%d %d ",seq[a],seq[b]);
            //cout<<"ha"<<a<<' '<<b<<endl;
            if(a>l)
                que.push(node(query2(l,a-1),l,a-1));
            if(a<b-1)
                que.push(node(query(a+1,b-1),a+1,b-1));
            if(b<r)
                que.push(node(query2(b+1,r),b+1,r));
        }
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; ++i)
    {
        scanf("%d",seq+i);
        pos[seq[i]]=i;
    }
    build();
    build2();
    solve();
    return 0;
}


Measured memory_bytes: 9848
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, q, c, x, y;
  scanf("%lld%lld", &n, &q);
  ll seg[n * 4], f = 1;
  while(f < n) f *= 2;
  for(i = 0; i < f * 2; ++i) seg[i] = 0;
  for(i = 0; i < q; ++i) {
    scanf("%lld%lld%lld", &c, &x, &y);
    x--;
    if(c) {
      y--;
      ll ans = 0;
      ll r = x + f;
      while(1) {
        ll las, ra = 1;
        while(!(r % 2)) r /= 2;
        while(ra <= r) ra *= 2;
        ra /= 2;
        las = f / ra * (r + 1 - ra) - 1;
        //printf("f%lld r%lld ra%lld\n", f, r, ra);
        while(las > y) {
          r *= 2;
          ra *= 2;
          las = f / ra * (r + 1 - ra) - 1;
          //printf("f%lld r%lld ra%lld\n", f, r, ra);
        }
        ans += seg[r];
        if(las == y) break;
        r++;
        //printf("f%lld r%lld ra%lld\n", f, r, ra);
      }
      printf("%lld\n", ans);
    } else {
      int now = (x + f) / 2;
      seg[x + f] += y;
      while(now) {
         seg[now] = seg[now * 2] + seg[now * 2 + 1];
         now /= 2;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 4732
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

typedef double R;
typedef complex<R> P;
const R PI = 3.1415926535897932384626;

istream& operator>>(istream &is, P &p) {
	R x, y;
	is >> x >> y;
	p = P(x, y);
	return is;
}

int n;
double r, theta;

double dp[401][10005];

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> r >> theta; theta = theta/180.*PI;
	vector<P> p(n);
	REP(i, n) cin >> p[i];
	vector<vector<pair<int, double>>> g(n*n);
	REP(i, n)REP(j, n)REP(k, n){
		if(i==k || i==j || j==k) continue;
		if(abs(arg((p[j]-p[i]) / (p[k]-p[j]))) < theta){
			g[j*n+i].emplace_back(k*n+j, abs(p[k]-p[j]));
		}
	}
	REPS(j, n)if(abs(p[0]-p[j]) < r) dp[j*n][1] = abs(p[0]-p[j]);
	int ans = 0;
	while(++ans){
		int f = 0;
		REP(i, n*n)if(dp[i][ans] != 0){
			f = 1;
			auto &t = dp[i][ans];
			FOR(it, g[i]) if(t + it->second < r){
				if(dp[it->first][ans+1] > t + it->second || dp[it->first][ans+1] == 0)
				dp[it->first][ans+1] = t + it->second;
			}
		}
		if(!f) break;
	}
	cout << ans - 1 << endl;
	return 0;
}

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

const int MAX = 1000000;
bool ok[MAX + 10];
signed main(void)
{
	long long n, p, i, x;
	long long ans, cnt;

	cin >> n >> p;
	rep(i, 100000) ok[i] = true;
	ok[0] = ok[1] = false;
	for(int i = 2; i < sqrt(p); i++)
	{
		if (ok[i])
		{
			for(int j = 0; i * (j + 2) <= sqrt(p); j++)
			{
				ok[i * (j + 2)] = false;
			}
		}
	}
	x = p;
	i = 0;
	ans = 1;
	while(sqrt(p) >= i)
	{
		i++;
		if (ok[i])
		{
			cnt = 0;
			while (x % i == 0)
			{
				x /= i;
				cnt++;
			}
			if (cnt >= n)
			{
				ans *= pow(i, (cnt / n));
			}
		}
	}
	if (n == 1)
		ans = p;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG
/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#else
#define print(...)
#endif

void solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<vector<ll>> dp(N + 1, vector<ll>(2, -INF));
    dp[0][0] = 0;
    rep(i, N) {
        ll a = A[i];
        if (i < N - 1) {
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + a);
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] - a);
            dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + a);
            dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] - a);
        } else {
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + a);
            dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] - a);
        }
    }
    ll ans = -INF;
    ans = max(ans, dp[N][0]);
    print(dp);
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 9500
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
sys.setrecursionlimit(100000)
# MOD = 10**9 + 7

def solve(f):
    n, m = f.read_int_list()
    g = collections.defaultdict(list)
    g2 = {}
    for _ in xrange(m):
        u, v, s = f.read_int_list()
        g[u].append((v, s))
        g[v].append((u, s))
        if u < v:
            g2[(u,v)] = s
        else:
            g2[(v,u)] = s

    vis = [None] * (n+1)
    vis[1] = (1, 0)
    res = set()

    def dfs(v):
        for vi, si in g[v]:
            if vis[vi] is not None:
                if v > vi:
                    res.add((vi,v))
                else:
                    res.add((v,vi))
            else:
                vis[vi] = (vis[v][0]*-1, si-vis[v][1])
                dfs(vi)

    dfs(1)

    a = None
    for u, v in res:
        aa = vis[u][0]+vis[v][0]
        if aa == 0:
            if g2[(u,v)] != vis[u][1] + vis[v][1]: return 0
        else:
            bb = g2[(u,v)]-vis[u][1]-vis[v][1]
            a2 = bb / aa
            if aa*a2 != bb: return 0
            if a is not None and a != a2: return 0
            a = a2

    a1min = a2min = float('inf')
    a1max = a2max = -float('inf')
    for i in xrange(1,n+1):
        if vis[i][0] == 1:
            a1min = min(vis[i][1], a1min)
            a1max = max(vis[i][1], a1max)
        else:
            a2min = min(vis[i][1], a2min)
            a2max = max(vis[i][1], a2max)

    # print a1min, a1max, a2min, a2max
    amax = a2min-1
    amin = max(1, -a1min+1)
    # print amax, amin
    if amax < amin:
        return 0
    else:
        if a is not None:
            return min(1, amax-amin+1)
        else:
            return amax-amin+1


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 882112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i< (n); i++)
int main(){
int N=0;
vector<int> vec(300);
cin >> N;
rep(i,N) cin >> vec[i];
int counter=0, odd=0;
while(true){
    rep(i,N){
        if(vec[i]%2==1) odd++;
    }
    if (odd>0) break;
    rep(i,N) vec[i]=vec[i]/2;
    counter++;
}
cout << counter << endl;

}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

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

  ll n, m;
  cin >> n >> m;

  ll ans = 0;
  ans = min(n, m/2);
  m -= 2*ans;
  ans += m/4;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
X, N = map(int, input().split())
if int(N) == 0:
    print(X)
else:
    Y = list(map(int, input().split()))
    x = int(X)
    for i in range(100):
        if x - i not in Y:
            print(x - i)
            break
        elif x + i not in Y:
            print(x + i)
            break


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

int main() {
  ll n;
  cin >> n;
  vector<ll> a (n);
  for(int i=0; i<n; i++){
    cin >> a.at(i);
  }
  ll ans = 1;
  vector<ll> v (3);
  for(int i=0; i<n; i++){
    ll count = 0;
    ll id = -1;
    if(a.at(i) == v.at(0)){
      count++;
      id = 0;
    }
    if(a.at(i) == v.at(1)){
      count++;
      id = 1;
    }
    if(a.at(i) == v.at(2)){
      count++;
      id = 2;
    }
    if(id == -1){
      ans = 0;
      break;
    }
    ans *= count;
    v.at(id)++;
    ans %= 1000000007;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string n;
    cin >> n;
    int count = 1;
    char store;
    for(int i = 0;i < 4;i++) {
        if(n[i] == store) {
            count++;
            if(count>=3) {
                cout << "Yes" << endl;
                return 0;
            }
        } else {
            count = 1;
            store = n[i];
        }
    }

    if(count>=3) {
        cout << "Yes" << endl;
        return 0;
    }else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<ll> march(5);
    REP(i,n) {
        string s; cin >> s;
        switch (s[0])
        {
        case 'M':
            march[0]++;
            break;
        case 'A':
            march[1]++;
            break;
        case 'R':
            march[2]++;
            break;
        case 'C':
            march[3]++;
            break;
        case 'H':
            march[4]++;
            break;
        
        default:
            break;
        }
    }

    ll ans = 0;
    REP(i,3) FOR(j,i+1,4) FOR(k,j+1,5) ans += march[i] * march[j] * march[k];

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    ll x;
    cin >> x;
    ll cur = 100;
    int res = 0;
    do {
        cur = (ll)(cur * 1.01);
        ++res;
    } while (cur < x);
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3608
# かなり手こずった．
# 原因は最終行の print にインデントがなく
# c が空のケースでエラーが出ていた．

a, b = map(int, input().split())
if b-a >= 2019:
    print(0)
else:
    c = []
    for i in range(a,b):
        for j in range(i+1,b+1):
            c.append(i*j % 2019)
    print(min(c))


Measured memory_bytes: 75332
import Control.Monad
import Data.Bits
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

main = do
  getLine
  as <- getIntList
  let all = foldr1 xor as
  mapM_ (print . xor all) as

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

long long gcd(long long y, long long x){
    return x ? gcd(x,y%x) : y;
}

int main(void){
    int n;
    cin >> n;
    
    vector<int> a(n), d(n), e(n);
    rep(i, n){
        cin >> a.at(i);
        d.at(i) = 0;
        e.at(i) = 0;
    }
    
    int tmp = a.at(0);
    rep(i, n){
        tmp = gcd(tmp, a.at(i));
        d.at(i) = tmp;
    }
    
    tmp = a.at(n-1);
    rep(i, n){
        tmp = gcd(tmp, a.at(n-i-1));
        e.at(i) = tmp;
    }
    
    int gcd_max = 0;
    rep(i, n){
        if(i != 0 && i != n-1){
            tmp = gcd(d.at(i-1), e.at(n-i-2));
        } else {
            if(i == 0){
                tmp = e.at(n-2);
            } else {
                tmp = d.at(n-2);
            }
        }
        gcd_max = max(tmp, gcd_max);
    }
    
    cout << gcd_max << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;

int main(){
	string s1,s2;
	int dp[1001][1001];
	
	cin>>s1;
	cin>>s2;
	
	for(int i=0;i<=s1.length();i++) dp[i][0]=i;
	for(int j=0;j<=s2.length();j++) dp[0][j]=j;
	
	for(int i=1;i<=s1.length();i++){
		for(int j=1;j<=s2.length();j++){
			int t;
			t= (s1[i-1]==s2[j-1] ? 0 : 1);
			dp[i][j]=min(min(dp[i-1][j]+1,dp[i][j-1]+1),dp[i-1][j-1]+t);
		}
	}
	printf("%d\n",dp[s1.length()][s2.length()]);
}


Measured memory_bytes: 7280
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#include <algorithm>

using namespace std;
typedef tuple<int, int, int> tiii;
const int INF = 1000000000;

struct Random {
	int a, b, C, M;
	Random(int A, int B) : a(A), b(B), C(~(1 << 31)), M((1 << 16) - 1) { }
	int operator()(){
		a = 36969 * (a & M) + (a >> 16);
		b = 18000 * (b & M) + (b >> 16);
		return (C & ((a << 16) + b)) % 1000000;
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int m, n, A, B;
		cin >> m >> n >> A >> B;
		if(m == 0 && n == 0 && A == 0 && B == 0){ break; }
		n += m;
		vector<tiii> p(n);
		for(int i = 0; i < m; ++i){
			int x, y, z;
			cin >> x >> y >> z;
			p[i] = tiii(x, y, z);
		}
		Random random(A, B);
		for(int i = m; i < n; ++i){
			const int x = random();
			const int y = random();
			const int z = random();
			p[i] = tiii(x, y, z);
		}
		sort(p.begin(), p.end());
		vector< map<int, int> > vm(n + 1);
		for(auto &v : vm){ v.insert(make_pair(-INF, INF)); }
		int answer = 0;
		for(int i = 0; i < n; ){
			const int x = get<0>(p[i]);
			vector<tiii> t;
			while(i < n && get<0>(p[i]) == x){
				const int y = get<1>(p[i]);
				const int z = get<2>(p[i]);
				int l = 0, r = n;
				while(l < r){
					const int c = l + (r - l) / 2;
					auto it = vm[c].lower_bound(y);
					if((--it)->second >= z){
						r = c;
					}else{
						l = c + 1;
					}
				}
				t.emplace_back(l, y, z);
				answer = max(answer, l + 1);
				++i;
			}
			for(const auto &e : t){
				const int k = get<0>(e);
				const int y = get<1>(e);
				const int z = get<2>(e);
				auto it = vm[k].upper_bound(y);
				--it;
				if(it->second <= z){ continue; }
				if(it->first < y){ ++it; }
				while(it != vm[k].end()){
					if(it->second < z){ break; }
					vm[k].erase(it++);
				}
				vm[k].insert(make_pair(y, z));
			}
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 37204
#include <iostream>
using namespace std;
#define M 1000000007

int rec(long m, long n) {
    if(n == 1) return m % M;
    long long m2 = rec((m % M) * (m % M), n / 2);
    if(n % 2 == 1) {
        m2 = ((m2 % M) * (m % M));
    }
    return m2 % M;
}

int main(){
    int m,n;
    cin >> m >> n;
    cout << rec(m, n) << endl;
    return 0;
}


Measured memory_bytes: 3096
def main():
    import sys
    input = sys.stdin.readline

    a = list(input())[:-1]
    #print(a)
    n = len(a)

    d = dict()
    for i in range(26):
        d[chr(i+97)] = chr(i+97)
    

    for i in range(n-1,-1,-1):
        min_key = 'zz'
        min_len = 10**9
        for e in d:
            if (min_len == len(d[e]) and min_key > e) or (min_len > len(d[e])):
                min_key = e
                min_len = len(d[e])
        d[a[i]] = a[i]+d[min_key]

    res_len = len(d['a'])
    res_key = 'a'
    for e in d:
        if (res_len == len(d[e]) and res_key > e) or (res_len > len(d[e])):
            res_key = e
            res_len = len(d[e])
    print(d[res_key])

if __name__ =='__main__':
    main()

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,m;
    cin>>n>>m;
    ll ans=0;
    ans+=(n*(n-1))/2;
    ans+=(m*(m-1))/2;
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define LEN 100005
typedef struct pp{
    char name[50];
    int time;
} P;

P Q[LEN];
int head,tail,n;

void enqueue(P val){
    Q[tail]=val;
    tail=(tail+1)%LEN;
}

P dequeue(){
    P ret=Q[head];
    head=(head+1)%LEN;
    return ret;
}

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

int main(){
    int el=0,c;
    int q;
    P u;
    scanf("%d %d",&n, &q);
    int i;
    for(i=1;i<=n;i++){
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].time);
    }
    head=1; tail=n+1;

    while(head!=tail){
        u=dequeue();
        c=min(q,u.time);
        u.time-=c;
        el+=c;
        if(u.time>0) enqueue(u);
        else{
            printf("%s %d\n",u.name, el);
        }
    }
    return 0;

}

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

int main()
{

    int N;
    string S;
    cin >> N;
    cin >> S;

    int cnt = 0;
    for (int i = 1; i < N; i++)
    {
        if (S.at(i) == 'E')
        {
            cnt++;
        }
    }

    int min = cnt;
    for (int i = 0; i < N - 1; i++)
    {
        if (S.at(i) == 'W')
        {
            cnt++;
        }

        if (S.at(i + 1) == 'E')
        {
            cnt--;
        }

        if (min > cnt)
        {
            min = cnt;
        }
    }

    cout << min << endl;
    return 0;
}

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

int main() {

  int N;
  cin >> N;

  map<char, long long> S;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    S[s[0]]++;
  }

  long long answer = 0;

  answer += S['M'] * S['A'] * S['R'];
  answer += S['M'] * S['A'] * S['C'];
  answer += S['M'] * S['A'] * S['H'];
  answer += S['M'] * S['R'] * S['C'];
  answer += S['M'] * S['R'] * S['H'];
  answer += S['M'] * S['C'] * S['H'];
  answer += S['A'] * S['R'] * S['C'];
  answer += S['A'] * S['R'] * S['H'];
  answer += S['A'] * S['C'] * S['H'];
  answer += S['R'] * S['C'] * S['H'];

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define llint long long 
#define mod 1000000007

using namespace std;

llint d, n;
string s;
llint dp[10005][105][3];

int main(void)
{
	cin >> s;
	cin >> d;
	n = s.size();
	
	dp[0][0][0] = 1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < d; j++){
			for(int k = 0; k < 3; k++){
				for(int l = 0; l < 10; l++){
					int nk = k;
					if(i == 0 && l == 0) continue;
					if(k == 0 && l > s[i]-'0') nk = 1;
					if(k == 0 && l < s[i]-'0') nk = 2;
					dp[i+1][(j+l)%d][nk] += dp[i][j][k];
					dp[i+1][(j+l)%d][nk] %= mod;
				}
			}
		}
	}
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		for(int k = 0; k < 3; k++){
			if(i == n && k == 1) continue;
			ans += dp[i][0][k], ans %= mod;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 24832
unittest
{
	assert( [ "3 2" ].solve == 9 );
	assert( [ "5 3" ].solve == 1 );
	assert( [ "31415 9265" ].solve == 27 );
	assert( [ "35897 932" ].solve == 114191 );
	
	assert( [ "10 1" ].solve == 1000 );		// 追加ケース
}



import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	
	auto ans = 0L;
	auto a = n / k;
	auto b = n * 2 / k - a;
	if( k % 2 ) ans = a ^^ 3;
	else        ans = a ^^ 3 + b ^^ 3;
	return ans;
}


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

const int INF = 10000000;

int main(void)
{
    int N;
    cin >> N;
    int a[N];

    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    
    int min = INF;
    int sum = 0;
    for(int i=0; i<N; i++){
        if(a[i] < min){
            sum++;
            min = a[i];
        }
    }

    cout << to_string(sum) << endl;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

N,Q = list(map(int,input().split()))

class RUQ:
  def __init__(self, N, default = None):
    self.N0 = 2**(N-1).bit_length()
    self.data = [(-1,N-1)]*(2*self.N0)
    self.INF = (-1, default)
  # 区間[l, r+1)の値をvに書き換える
  # vは(t, value)という値にする (新しい値ほどtは大きくなる)
  def update(self, l, r, v):
    L = l + self.N0; R = r + self.N0
    while L < R:
      if R & 1:
        R -= 1
        self.data[R-1] = v
      if L & 1:
        self.data[L-1] = v
        L += 1
      L >>= 1; R >>= 1
  # a_iの現在の値を取得
  def _query(self, k):
    k += self.N0-1
    s = self.INF
    while k >= 0:
      if self.data[k]:
        s = max(s, self.data[k])
      k = (k - 1) // 2
    return s
  # これを呼び出す
  def query(self, k):
      return self._query(k)[1]
    
TATE = RUQ(N-1,N-2)
YOKO = RUQ(N-1,N-2)

hidari = N
ue = N

ans = (N-2)**2

for t in range(Q):
  c,x = list(map(int,input().split()))
  if c == 1:
    ans -= TATE.query(x-2)
    if x<hidari:
      hidari = x
      YOKO.update(0,TATE.query(x-2),(t,x-2))
  else:
    ans -= YOKO.query(x-2)
    if x<ue:
      ue = x
      TATE.update(0,YOKO.query(x-2),(t,x-2))
print(ans)

Measured memory_bytes: 82912
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval<newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin

  int A, B, C;
  cin >> A >> B >> C;

  if(A<C && C<B) cout << "Yes" << endl;
  else if (B<C && C<A) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
S=input()

if S.count("0") == 0:
	print(N)
	exit(0)


curLen=0
# rangeLens=[]
rangeVals=[]
stackLens=[]
prev = S[0]
for n in range(N):
	if prev != S[n]:
		# rangeLens.append(curLen)
		stackLens.append(curLen)
		rangeVals.append(prev)
		# curLen=1
	# else:
	# 	curLen+=1
	curLen+=1
	prev = S[n]

stackLens.append(curLen)
rangeVals.append(prev)

stackLens.insert(0,0)
rangeVals.insert(0,rangeVals[0])

# stackLens.append(curLen+1)
# rangeVals.append(prev)

# print(stackLens)

curSumLenMax=0
for r in range(1,len(stackLens)):
	rangeLen=0
	if rangeVals[r] == "0":
		high = 2*K+r-1
		if len(stackLens)-1 < high:
			high = len(stackLens)-1
		rangeLen=stackLens[high]-stackLens[r-1]
	else:
		high = 2*K+1+r-1
		if len(stackLens)-1 < high:
			high = len(stackLens)-1
		# print(high,r,stackLens[high],stackLens[r])
		rangeLen=stackLens[high]-stackLens[r-1]
	curSumLenMax = max( curSumLenMax, rangeLen )


print(curSumLenMax)


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

int main()
{
    string S, SS, T, C;
    cin >> SS >> T;
    if(T.length()>SS.length())
    {
        cout << "UNRESTORABLE" << endl;
    }
    else if(T.length()==SS.length())
    {
        for(int i=0; i<T.length(); i=i+1)
        {
            if(SS[i]=='?' || T[i]==SS[i])
            {
                S+=T[i];
            }
            else
            {
                cout << "UNRESTORABLE" << endl;
                return 0;
            }    
        }
        cout << S << endl;
    }
    else
    {
        C="|";
        for(int j=0; j<(SS.length()-T.length()+1); j=j+1)
        {
            int satisfy=1;
            for(int i=0; i<T.length(); i=i+1)
            {
                if(SS[i+j]!=T[i] && SS[i+j]!='?')
                {
                    satisfy=0;
                }
            }
            if (satisfy == 1)
            {
                S="";
                for(int s=0; s<SS.length(); s=s+1)
                {
                    if(SS[s]!='?')
                    {
                        S+=SS[s];
                    }
                    else
                    {
                        S+='a';
                    }
                }
                for(int t=0; t<T.length(); t=t+1)
                {
                    S[j+t]=T[t];
                }
                if(S<C)
                {
                    C="";
                    for(int n=0; n<S.length(); n=n+1)
                    {
                        C+=S[n];
                    }
                }
            }
        }
        if(C=="|")
        {
            cout << "UNRESTORABLE" << endl; 
        }
        else
        {
            cout << C << endl;
        }              
    }
    return 0;
}

Measured memory_bytes: 256
def ans():
    C = []
    C.append([])
    C.append(list(map(int, ('0 ' + input()).split())))
    C.append(list(map(int, ('0 ' + input()).split())))
    C.append(list(map(int, ('0 ' + input()).split())))

    A = [0] * 4
    B = [0] * 4
    A[1] = 0

    for i in range(1,4):
        B[i] = C[1][i] - A[1]

    for i in range(2, 4):
        A[i] = C[i][1] - B[1]

    for i in range(1,4):
        for j in range(1, 4):
            if C[i][j] == (A[i] + B[j]):
                pass
            else:
                return print('No')
    return print('Yes')
ans()

Measured memory_bytes: 3064
import java.lang.Math;
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        double m=0;
        double[] si = new double[1001];
        int i,n;
        double z=0;
        while(true){
            n = s.nextInt();
            if(n==0)break;
            for(i=0;i<n;i++){
                si[i]=s.nextInt();
                m+=si[i];
            }
            m/=(double)n;
            for(i=0;i<n;i++)z+=(si[i]-m)*(si[i]-m);
            z/=(double)n;
            System.out.println(Math.sqrt(z));
            m=0;
            z=0;
 
        }
         
    }
}



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

using namespace std;

int main() {
    int N;
    cin>>N;
    double A[N];
    REP(i,N){
        cin>>A[i];
    }
    REP(i,N){
        A[i]=1/A[i];
    }
    double sum=0;
    REP(i,N){
        sum+=A[i];
    }
    cout<<1/sum<<endl;
}

Measured memory_bytes: 256
n=int(input())
ls=[list(map(int,input().split())) for i in range(n)]
ls.sort()

first_robot=ls.pop(0)
prev_right=first_robot[0]+first_robot[1]

for i,robot in enumerate(ls):
    left=robot[0]-robot[1]
    right=robot[0]+robot[1]
    if left<prev_right:
        n-=1
        if right<prev_right:
            prev_right=right
    else:
        prev_right=right
print(n)

Measured memory_bytes: 63320