akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

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

using namespace std;
using ll = long long int;

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



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

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

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

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

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

//ワーシャルフロイト法のテンプレ.graphに最短経路が格納される.
//負の重みがある場合inf + const = inf に気を付けること.
//graphは隣接行列.
void WF(vector<vector<int>> &graph){
	int n = graph.size();
	for (int k = 0; k < n; k++){
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
			}
		}
	}
}

//素因数分解をする関数.
map<long long int, int> prime_factorization(long long int a)
{
	map<long long int, int>ans;
	for (long long i = 2; i*i <= a; ++i) {
		while (a%i == 0) {
			ans[i]++;
			a /= i;
		}
	}
	if (a != 1)ans[a]++;
	return ans;
}

int main()
{
	ll n, mod = 1e9+7;
	cin >> n;
	ll ans = 1;
	map<ll, int> res;
	rep2(i, 1, n + 1)
	{
		map<ll, int> t = prime_factorization(i);
		for (auto x:t){
			res[x.first] += x.second;
		}
	}
	for (auto x:res){
		ans *= (1 + x.second);
		ans = ans % mod;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using V = vector<int>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }


int main() {
  int n, q; cin >> n >> q;
  V c(n); cin >> c;
  rep(i, n) --c[i];
  int B = sqrt(3*q); // number of buckets

  // input and sort queries
  using Query = array<int, 3>;
  vector<Query> query(q);
  rep(i, q) {
    int l, r; cin >> l >> r;
    --l;
    query[i] = {l, r, i};
  }
  sort(all(query), [&] (const Query &a, const Query &b) {
    if (a[0] / B != b[0] / B) return a[0] < b[0];
    else if (a[0] / B % 2 == 0) return a[1] < b[1];
    else return a[1] > b[1];
  });

  // edit here
  int sum = 0;
  int l = 0, r = 0;
  V cnt(n), ans(q);

  auto add = [&] (int i) {
    if (cnt[c[i]] == 0) ++sum;
    ++cnt[c[i]];
  };
  auto del = [&] (int i) {
    --cnt[c[i]];
    if (cnt[c[i]] == 0) --sum;
  };
  // 

  // O(n \sqrt{q})
  for(const auto [li, ri, i] : query) {
    while (li < l) add(--l);
    while (ri < r) del(--r);
    while (r < ri) add(r++);
    while (l < li) del(l++);
    ans[i] = sum;
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 15484
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n,W;
     cin>>n>>W;
     vector<ll>dp(W+1,0);
    for(int i=0;i<n;i++)
    {
         ll value,weight;
         cin>>weight>>value;
         for(int weight_already=W-weight;weight_already>=0;--weight_already)
           dp[weight_already+weight]=max(dp[weight_already+weight],dp[weight_already]+value);
    }
    ll answer=0;
     for(int i=0;i<=W;i++)
       answer=max(answer,dp[i]);
    cout<<answer;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//    std::sort(a.begin(), a.end(), std::greater<int>() );
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int a, b;
    cin >> a >> b;
    if (a < 0)
    {
        if (b < 0)
        {
            if (abs(a - b) % 2 == 1)
                cout << "Positive" << endl;
            else
                cout << "Negative" << endl;
        }
        else if (b >= 0)
        {
            cout << "Zero" << endl;
        }
    }
    else if (a == 0)
    {
        cout << "Zero" << endl;
    }
    else if (a > 0)
    {
        cout << "Positive" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
    using namespace std;
    int main() 
    {
    	int n, x, S = 0;
        cin>>n;
        x = n;
        while(n != 0){
        	S += n % 10;
        	n /= 10;
        }
        if(x % S == 0){
        	cout<<"Yes";
        }else{
        	cout<<"No";
        }
    }

Measured memory_bytes: 256
N, m = map(int, input().split())
s = []
for _ in range(m):
    i = list(map(int, input().split()))
    s.append(i)
n = [-1]*(N+1)
for i in s:
  if n[i[0]] != -1 and n[i[0]] != i[1]:
    print(-1)
    exit(0)
  try:
    n[i[0]] = i[1]
  except:
    print(-1)
    exit(0)
n = n[1:]
if N == 1:
  l = [i for i in range(0,10)]
else:
  l = [i for i in range(10**(N-1),10**N)]
for i in l:
  cnt = 0
  for j in range(N):
    if n[j] != -1 and n[j] != int(str(i)[j]):
      cnt = 1
  if cnt == 0:
    print(i)
    exit(0)
print(-1)

Measured memory_bytes: 3064
s = input()
if s[0] == "A":
  if s[2:-1].count("C") == 1:
    if s[1].islower() and s[-1].islower():
      s = s.replace("C","c").replace("A","a")
      if s.islower():
        print("AC")
        exit()

print("WA")

Measured memory_bytes: 3060
n = int(input())
s = list(input())
b_c,w_c = s.count('#'),s.count('.')
ans = w_c
b_r,w_r = 0,0
for i in range(n-1):
    if s[i]=='#':b_r+=1
    else:w_r+=1
    if s[i]!=s[i+1]:
        ans = min(ans,b_r+w_c-w_r)
if s[-1]=='#':b_r+=1
else:w_r+=1
ans = min(ans,b_r+w_c-w_r)
print(ans)

Measured memory_bytes: 61424
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int x=0,y=0,len;
    string s,t;
    cin>>len;
    cin>>s;
    for(int i=0; i<s.length(); i++)
    {
        if(s[i]=='R')
            x++;
        else
            y++;
    }
    for(int i=0;i<x;i++)
        t+="R";
    for(int i=0;i<y;i++)
        t+="W";
    int cnt=0;
    for(int i=0;i<s.length();i++){
        if(s[i]!=t[i])
            cnt++;
    }
    cout<<cnt/2<<endl;
    return 0;
}


Measured memory_bytes: 3872
typedef struct{int x1,y1,x2,y2;char l[21];}B;typedef struct{char t[21];int n;B b[100];}P;P*p,a[100];B*b;h[99999],c,H,m,i,j,x,y;char o[9];main(n){for(;scanf("%d%*d%*d",&n)*n;){for(i=n;i--;)for(p=a+i,scanf("%s%d",p->t,&j),p->n=j;j--;scanf("%d%d%d%d%s",&b->x1,&b->y1,&b->x2,&b->y2,b->l))b=p->b+j;for(h[H=c=0]=n-scanf("%d",&m);m--;){scanf("%s",o);if(*o=='c')for(p=a+h[c],scanf("%d%d",&x,&y),i=p->n;i--;)if(b=p->b+i,x>=b->x1&&x<=b->x2&&y>=b->y1&&y<=b->y2)for(j=n;j--;)!strcmp(a[j].t,b->l)?h[H=++c]=j:0;if(*o=='b')c-=c>0;if(*o=='f')c+=c<H;if(*o=='s')puts(a[h[c]].t);}}}

Measured memory_bytes: 0
using System;

public static class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int num, i;
        int cnt = 0;
        string[] str = Console.ReadLine().Split(' ');
        string[] arr = new string[N];
        while (true)
        {
            for (i = 0; i < N; i++)
            {
                num = int.Parse(str[i]);
                if (num % 2 == 0)
                {
                    num = num / 2;
                    arr[i] = num.ToString();
                }
                else
                {
                    goto end;
                }
            }
            cnt += 1;
            str = arr;   
        }
        end:
        Console.WriteLine(cnt);
    }
}

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

bool solve(){
    int e, m;
    cin >> e;
    if(e == 0) return false;
    m = e;
    for(int z=0;z*z*z<=e;z++){
        for(int y=0;z*z*z+y*y<=e;y++){
            int x = e-z*z*z-y*y;
            m = min(m, x+y+z);
        }
    }
    cout << m << endl;
    return true;
}

int main(){
    while(solve());
    return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

using namespace std;

typedef long long ll;

const long long int INF = 1 << 30; //10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

inline void maxch(int& a, int b) { if (a < b) a = b; }

int exp_mod(long long a, long long b, int m) {
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return (int)res;
}

int fact_mod(int n, int m) {
	long long res = 1;
	for (int i = n; i > 0; --i)
		res = (res * i) % m;
	return (int)res;
}

int comb_mod(ll n, int r) {
	long long res = 1;
	for (ll i = 0; i < r; ++i)
		res = (res * (n - i)) % MOD;
	return (res * exp_mod(fact_mod(r, MOD), MOD - 2, MOD)) % MOD;
}

int main() {
	int x,y;
	cin >> x >> y;
	
	if((x+y) % 3 != 0) cout << 0 << endl;
	else {
		ll n = (x+y) / 3;
		if(2*n < x || 2*n < y) cout << 0 << endl;
		else cout << comb_mod(n,2*n - x) << endl;
	}
}

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

int main() {

	int first, secound;
	char op;

	cin >> first;
	cin >> op;
	cin >> secound;

	if (op == '+') {
		cout << first + secound
		<< endl;
	}
	else if(op=='-') {
		cout << first - secound
			<< endl;
	}

}

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

void solve(std::string S) {}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can
// remove this line by using your custom template)
int main() {
  std::string S;
  std::cin >> S;

  int len = S.size();

  int cnt = 0;
  for (int i = 0; i < len / 2; i++) {
    // cout << S[i] << "," << S[len - i - 1] << endl;
    //
    if (S[i] != S[len - i - 1]) {
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include <iomanip> 
#include<vector>
#define fo(i,n) for(int i=1;i<=n;i++)
#define f(i,n) for(int i=2;i<=n;i++)
#define ll long long
/*Elegizip, elegizip otken sol bir shaktar-ai
 Elendeter zamanymnyn otip bara zhatkanny-ai
Umytylmas-Umytylmas Kairan esil shaktar-ai
Zamanymnyn kolyn bulgap otip bara jatkany-ai
 kairan esil , kairan esil shaktar-ai
kolyn bulgap zamanymnyn otip bara jatkany-ai;*/
using namespace std;

int main()
{ios::sync_with_stdio(0);

ll t;
cin>>t;

ll k=t-t%500;
ll r=t%500-(t%500)%5;


cout<<2*k+r;


}

Measured memory_bytes: 256
import math

a, b, x = map(int, input().split())

if a*a*b >= 2 * x:
    ans = math.atan(a*b*b/(2*x))
    print(ans/math.pi*180)
else:
    ans = math.atan(2*b/a - 2*x/(a**3))
    print(ans / math.pi * 180)


Measured memory_bytes: 2940
a,b,c,x,y = map(int,input().split())
ans = 0
if a + b >= 2*c:
    ans += 2 * min(x,y) * c
    if x > y:
        if a < 2*c:
            ans += (x-y)*a
        else:
            ans += (x-y)*(2*c)
    elif x == y:
        pass
    else:
        if b < 2*c:
            ans += (y-x)*b
        else:
            ans += (y-x)*(2*c)
else:
    ans += x*a + y*b
print(ans)

Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;

bool hantei(string t,string s){
  int tsize = t.size(), ssize = s.size();
  for (int i=0; i<ssize; i++){
    if (tsize - ssize < 0)
      return 0;
    if ( t.at(tsize-ssize+i) != s.at(i) ){
      return 0;
    }
  }
  return 1;  
}



int main()
{
  string s;
  cin >> s;
  bool flag = 1;
  int cnt = 0;
  
  while ( s.size() != 0 ){
    if (hantei (s,"dream") == 1)
      s.erase(s.end()-5, s.end());
    else 
      cnt++;
    
    if (hantei (s,"dreamer") == 1)
      s.erase(s.end()-7, s.end());
    else 
      cnt++;
    
    if (hantei (s,"erase") == 1)
      s.erase(s.end()-5, s.end());  
    else 
      cnt++;
    
    if (hantei (s,"eraser") == 1)
      s.erase(s.end()-6, s.end());  
    else 
      cnt++;
    
    if (cnt == 4){
      flag = 0;
      break;
    }
    else
      cnt = 0;
  }
  
  if (flag == 0)
    cout << "NO";
  else 
    cout << "YES";

  return 0;
}

Measured memory_bytes: 512
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def main():
    num_people, num_check = map(int, input().split())
    data_people = [list(map(int, input().split())) for i in range(num_people)]
    data_check = [list(map(int, input().split())) for i in range(num_check)]

    for i in range(num_people):
        ans_ind = 1
        kyori = abs(data_people[i][0] - data_check[0][0]) + abs(data_people[i][1] - data_check[0][1])
        for j in range(1, num_check):
            kari = abs(data_people[i][0] - data_check[j][0]) + abs(data_people[i][1] - data_check[j][1])
            if kari < kyori:
                kyori = kari
                ans_ind = j + 1
        print(ans_ind)

if __name__ == '__main__':
    main()

Measured memory_bytes: 39024
import numpy as np
from scipy.sparse.csgraph import connected_components

n, m = list(map(int, input().split()))
edges = []
graph = np.zeros((n, n), dtype=np.int)
for _ in range(m):
    edges.append(list(map(int, input().split())))
    graph[edges[-1][0]-1][edges[-1][1]-1] += 1
    graph[edges[-1][1]-1][edges[-1][0]-1] += 1

num_of_bridges = 0
for edge in edges:
    g = graph.copy()
    g[edge[0]-1][edge[1]-1] -= 1
    g[edge[1]-1][edge[0]-1] -= 1
    if connected_components(g, return_labels=False) != 1:
        num_of_bridges += 1

print(num_of_bridges)


Measured memory_bytes: 18032
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

class UnionFind {
public:
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int N,M,K;
int rf[100005],blo[100005];
int ff[100005];

int main(){
    cin>>N>>M>>K;
    UnionFind uf(N+1);
    for(int i=0;i<M;++i){
        int a,b;
        cin>>a>>b;
        a--,b--;
        ff[a]++,ff[b]++;
        uf.unite(a,b);
    }
    for(int i=0;i<N;++i){
        rf[uf.root(i)]++;
    }
    for(int i=0;i<K;++i){
        int c,d;
        cin>>c>>d;
        c--,d--;
        if(uf.same(c,d)){
            blo[c]++;
            blo[d]++;
        }
    }
    for(int i=0;i<N;++i){
        cout<<rf[uf.root(i)]-ff[i]-blo[i]-1<<endl;
    }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct Edge {
  int src, dst;
  int dir;
  Edge(int src, int dst, int dir):src(src),dst(dst),dir(dir){}
};

int N;
ll M;
vector<Edge> G[100005];
ll dp[100005];
ll dp2[100005];
ll ans[100005];

ll dfs(int p, int v){
  ll ret = 1;
  rep(i,G[v].size()){
    if(G[v][i].dst == p){
      G[v][i].dir = -1;
      continue;
    }
    G[v][i].dir = 1;
    ret *= dfs(v,G[v][i].dst) + 1;
    ret %= M;
  }
  return dp[v] = ret;
}

int main(){
  cin >> N >> M;
  rep(i,N-1){
    int x, y;
    cin >> x >> y;
    G[x].emplace_back(x,y,0);
    G[y].emplace_back(y,x,0);
  }

  rep(i,100005){
    dp[i] = -1;
    dp2[i] = -1;
    ans[i] = -1;
  }

  ans[1] = dfs(-1,1);
  dp2[1] = 0;
  
  queue<int> que;
  que.push(1);
  while(!que.empty()){
    int p = que.front(); que.pop();

    int pp = -1;
    vector<int> children;
    rep(i,G[p].size()){
      if(G[p][i].dir == -1){
        pp = G[p][i].dst;
      }else{
        children.push_back(G[p][i].dst);
      }
    }

    int n = children.size();
    rep(i,n) que.push(children[i]);

    vector<ll> prod1(n);
    vector<ll> prod2(n);
    if(n>0) prod1[0] = (dp[children[0]] + 1) % M;
    if(n>0) prod2[n-1] = (dp[children[n-1]] + 1) % M;
    REP(i,1,n){
      prod1[i] = (dp[children[i]] + 1) * prod1[i-1];
      prod1[i] %= M;
      prod2[n-1-i] = (dp[children[n-1-i]] + 1) * prod2[n-i];
      prod2[n-1-i] %= M;
    }
    
    rep(i,n){
      ll tmp = (dp2[p] + 1) % M;
      if(i>0){
        tmp *= prod1[i-1];
        tmp %= M;
      }
      if(i+1<n){
        tmp *= prod2[i+1];
        tmp %= M;
      }
      dp2[children[i]] = tmp;
    }
    
    rep(i,n){
      ans[children[i]] = (dp[children[i]] * (dp2[children[i]] + 1)) % M;
    }
  }

  REP(i,1,N+1){
    cout << ans[i] << endl;
  }
  
  return 0;
}


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

int n,m,l[500000],r[500000],ans;
string s;


int  main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>l[i]>>r[i];
    }
    sort(l,l+m);
    reverse(l,l+m);
    sort(r,r+m);
    if(r[0]-l[0]+1<0){cout<<0<<endl;return 0;}
    cout<<r[0]-l[0]+1<<endl;
}


Measured memory_bytes: 1024
import sys
import decimal # 10進法に変換，正確な計算

def input():
    return sys.stdin.readline().strip()

def main():
    n = int(input())
    s = input()
    count = 0
    for i in range(n-2):
        if s[i] == "A" and s[i+1] == "B" and s[i+2] == "C":
            count += 1
            i += 3
    print(count)

    
    
main()

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

typedef long long LL;
vector<LL> primes;
const LL RT = 2200;
const LL LIM = 1e10+10;

void sieve() {
    vector<bool> isp(RT, 1);
    for (LL i=2; i<RT; i++)
        if (isp[i]) {
            primes.push_back(i);
            for (LL j=2*i; j<RT; j+=i)
                isp[j] = 0;
        }
}

pair<LL, LL> process(LL x) {
    LL a = 1, b = 1;
    for (LL p: primes) {
        if (x%p)    continue;
        if (p*p*p > x)  break;
        LL cnt = 0;
        while (x%p==0) x/=p, cnt++;

        if (cnt%3==1) {
            a *= p;
            if (b > LIM/(p*p))  b = LIM;
            else                b *= p*p;
        }
        if (cnt%3==2) {
            a *= p*p;
            if (b > LIM/p)  b = LIM;
            else            b *= p;
        }
    }

    if (x == 1)     return {a, b};

    LL rt = round(sqrt(x));
    if (rt*rt == x) {
        a *= rt*rt;
        if (b > LIM/rt)  b = LIM;
        else            b *= rt;
    }
    else {
        a *= x;
        if (b > (LIM/x)/x)  b = LIM;
        else                b*=x*x;
    }
    return {a, b};
}

const LL N = 1e5+7;
LL a[N], b[N];

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

    sieve();

    LL n;
    cin>>n;

    map<long long, LL> cnt;
    map<long long, long long> opp;

    for (LL i=1; i<=n; i++) {
        LL x;
        cin>>x;

        auto pr = process(x);
        a[i] = pr.first;
        b[i] = pr.second;

        cnt[a[i]]++;
        opp[a[i]] = b[i];
        opp[b[i]] = a[i];
    }
    cnt[LIM] = 0;

    LL ans = 0;
    for (auto pr: opp) {
        LL a = pr.first, b = pr.second;
        if (a == LIM)   continue;
        if (a == b)     ans += min(1LL, cnt[a]+cnt[b]);
        else if (a < b) ans += max(cnt[a], cnt[b]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 25756
n,a,b=map(int,input().split())
m=10**9+7
def f(x,y):
    c=1
    for i in range(1,y+1):c=(c*(x-i+1)*pow(i,m-2,m))%m
    return c
print((pow(2,n,m)-1-f(n,a)-f(n,b))%m)

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

using namespace std;

typedef long long ll;

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

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

	int n;
	cin >> n;

	int x = 0;
	vector<int> a(n);
	rep(i, n){
		cin >> a[i];
		x ^= a[i];
	} 

	rep(i, n){
		cout << (x ^ a[i]) << (i == n - 1 ? "\n" : " ");
	}
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    map<ll,ll> mp;
    REP(i,n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    vector<ll> b = a;
    sort(ALL(b), greater<ll>());
    UNIQUE(b);
    REP(i,n) {
        ll ans = (a[i]==b[0] && mp[a[i]]==1 ? b[1] : b[0]);
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 12160
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

/**
 * I should implement static I op(I, I).
 */
template<class I>
class SegTree {
  int n;
  std::vector<I> dat;
  I e;
public:
  SegTree(int n_, I e) : e(e) {
    n = 1;
    while (n < n_) { n *= 2; } // n is a power of 2
    dat.resize(2 * n);
    for (int i = 0; i < 2 * n - 1; i++) {
      dat[i] = e;
    }
  }
  /* ary[k] <- v */
  void update(int k, I v) {
    k += n - 1;
    dat[k] = v;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = I::op(dat[2 * k + 1], dat[2 * k + 2]);
    }
  }
  /* http://proc-cpuinfo.fixstars.com/2017/07/optimize-segment-tree/ */
  I query(int a, int b) const {
    I left = e;
    I right = e;
    a += n - 1;
    b += n - 1;
    while (a < b) {
      if ((a & 1) == 0) {
	left = I::op(left, dat[a]);
      }
      if ((b & 1) == 0) {
	right = I::op(dat[b - 1], right);
      }
      a = a / 2;
      b = (b - 1) / 2;
    }
    return I::op(left, right);
  }
};

struct max_ll {
  ll v;
  max_ll(): v(0) {}
  max_ll(ll v): v(v) {}
  operator ll() const { return v; }
  static max_ll op(max_ll x, max_ll y) {
    return std::max(x, y);
  }
};

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  scanf("%d", &n);
  std::vector<int> x(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &x[i]);
  auto seg =
    SegTree<max_ll>(n + 1, std::numeric_limits<ll>::min());
  ll ma = 0;
  for (int i = 0; i < n; ++i) {
    ll res = std::max((ll)seg.query(1, x[i]), 0LL);
    ll cur = res + x[i];
    ma = std::max(ma, cur);
    seg.update(x[i], cur);
  }
  ll whole = (ll)n * (ll)(n + 1) / 2;
  printf("%lld\n", whole - ma);
}



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

int main() {
    int k;
    cin >> k;
    int even=0, odd=0;
    for(int i=0; i<k; i++) {
        if(i%2==0) {
            even++;
        } else {
            odd++;
        }
    }
    cout << even * odd << endl;
    return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 205
#define ll long long
#define inf 0x3f3f3f3f
int n, ans, flg;
int dis[N], col[N];
char S[N][N];
queue<int>q;
void Bfs1(int s)
{
	memset(col, -1, sizeof(col));
	col[s] = 0;
	q.push(s);
	while (!q.empty())
	{
		int x = q.front();
		q.pop();
		for (int i = 1; i <= n; i++)
		{
			if (S[x][i] == '0')continue;
			if (col[i] == -1)
			{
				col[i] = col[x] ^ 1;
				q.push(i);
			}
			else
				if (col[i] == col[x])
					flg = 1;
		}
	}
}
void Bfs2(int s)
{
	memset(dis, -1, sizeof(dis));
	dis[s] = 0;
	q.push(s);
	while (!q.empty())
	{
		int x = q.front();
		q.pop();
		ans = max(ans, dis[x]);
		for (int i = 1; i <= n; i++)
		{
			if (S[x][i] == '0')continue;
			if (dis[i] == -1)
			{
				dis[i] = dis[x] + 1;
				q.push(i);
			}
		}
	}
}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%s", S[i] + 1);
	Bfs1(1);
	if (flg)
	{
		puts("-1");
		return 0;
	}
	for (int i = 1; i <= n; i++)
		Bfs2(i);
	printf("%d\n", ans + 1);
}


Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  int n,m;
  cin>>n>>m;
  VI a(m);
  int sum=0;
  rep(i,m) {
    cin>>a[i];
    sum+=a[i];
  }
  if(sum>n){
    cout<<-1<<endl;
  }else{
    cout<<n-sum<<endl;
  }
  

}


Measured memory_bytes: 3664
/*||>>>> Praveen Ojha <<<<>>>> 22 June 2019 <<<<>>>> 05:07:45 <<<<||*/
// #pragma GCC optimize("Ofast") //(Very Fast but Inaccurate)
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //(Small operations in many loops)
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
//Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

int32_t main(){__
	int n,m,x,y,sumi=0;
	cin>>n;
	vi a(n+1);
	for(int i=1;i<=n;i++)
		cin>>a[i],sumi+=a[i];
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>x>>y;
		cout<<sumi-a[x]+y<<"\n";
	}
return 0;
}

Measured memory_bytes: 256
bingo = [list(map(int, input().split())) for i in range(3)]
b = [[False] * 3 for i in range(3)]
N = int(input())
for i in range(N):
  n = int(input())
  for h in range(3):
    for w in range(3):
      if bingo[h][w] == n:
        b[h][w] = True

for i in range(3):
  if all(b[i]):
    print("Yes")
    exit()
for i in range(3):
  if all([b[0][i], b[1][i], b[2][i]]):
    print("Yes")
    exit()
if b[0][0] and b[1][1] and b[2][2]:
  print("Yes")
  exit()
if b[0][2] and b[1][1] and b[2][0]:
  print("Yes")
  exit()
print("No")

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

int main(){
  int x,n,m;
  cin >> x >> n >> m;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int c=0;
  for(int i=0;i<n;i++){
    if(a[i]<m){
      c++;
    }
  }
  cout << min(c,n-c) << endl;
}

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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(exp, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)1e3+1;
int H, W, A, B, arr[MAXN][MAXN];


int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> H >> W >> A >> B;
    for(int i=0; i<2*B; i++)
    {
        for(int j=0; j<2*A; j++)
        {
            if(i<B)
            {
                if(j<A)
                {
                    arr[i][j] = 0;
                }
                else
                {
                    arr[i][j] = 1;
                }
            }
            else
            {
                if(j<A)
                {
                    arr[i][j] = 1;
                }
                else
                {
                    arr[i][j] = 0;
                }
            }
        }
    }

    for(int i=0; i<2*B; i++)
    {
        for(int j=2*A; j<W; j++)
        {
            if(i < B)
            {
                arr[i][j] = 1;
            }
            else
            {
                arr[i][j] = 0;
            }
        }
    }

    for(int i=2*B; i<H; i++)
    {
        for(int j=0; j<2*A; j++)
        {
            if(j < A)
            {
                arr[i][j] = 1;
            }
            else
            {
                arr[i][j] = 0;
            }
        }
    }

    for(int i=2*B; i<H; i++)
    {
        for(int j=2*A; j<W; j++)
        {
            arr[i][j] = 0;
        }
    }

    for(int i=0; i<H; i++)
    {
        for(int j=0; j<W; j++)
        {
            cout << arr[i][j];
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 5120
N = int(input())
A = [0]
A.extend(list(map(int,input().split())))
A.append(0)

S = 0
for i in range(N+1):
    S += abs(A[i+1]-A[i])
for i in range(1,N+1):
    print(S-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))


Measured memory_bytes: 14048
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<long long> firstpath;
    vector<long long> roop;
    long long N;
    long long K;;
    cin >> N >> K;
    long long A[N],visited[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
        A[i]--;
        visited[i]=0;
    }
    long long now,roopstart;
    now=A[0];
    visited[0]=1;
    while(1){
        if(visited[now]>0){
            roopstart=now;
            break;
        }else{
            visited[now]=1;
            now=A[now];
        }
    }
    now=0;
    while(1){
        if(now==roopstart){
            break;
        }else{
            firstpath.push_back(now);
            now=A[now];
        }
    }
    now=roopstart;
    roop.push_back(roopstart);
    while(1){
        now=A[now];
        if(now==roopstart) break;
        else{
            roop.push_back(now);
        }
    }
    long long ans;
    if(K<firstpath.size()){
        ans = firstpath.at(K);
    }else{
        K-=firstpath.size();
        K%=roop.size();
        ans=roop.at(K);
    }
    cout << ans+1;
    return 0;
}


Measured memory_bytes: 8440
#include <iostream>
using namespace std;
int N,A[100002],B[100001];
int main() {
	cin>>N;
	for(int i=1;i<=N+1;i++)cin>>A[i];
	for(int i=1;i<=N;i++)cin>>B[i];
	long c=0;
	for(int i=1;i<=N;i++){
		if(B[i]<=A[i]){c+=B[i];A[i]-=B[i];B[i]=0;}
		else{c+=A[i];B[i]-=A[i];A[i]=0;
		   if(B[i]<=A[i+1]){c+=B[i];A[i+1]-=B[i];B[i]=0;}
		   else{c+=A[i+1];B[i]-=A[i+1];A[i+1]=0;}
		}
	}
	cout<<c;
	return 0;
}


Measured memory_bytes: 1024
def is_target_string(S):
    if S[0] != 'A':
        return False
    C_cnt = 0
    C_index = -1
    for i in range(2, len(S)-1):
        if S[i] == 'C':
            C_cnt += 1
            C_index = i
    if C_cnt != 1:
        return False

    for i in range(len(S)):
        if i != 0 and i != C_index:
            if S[i].isupper():
                return False

    return True

S = input()

print('AC' if is_target_string(S) else 'WA')



Measured memory_bytes: 3060
/* This code is written by yuiky*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>

#define mod 1000000007
#define ab 123456789
#define ba 987654321
#define ll long long 
#define rep(i, n) for(int i = 0; i < n; i++)
#define str(i, s) for(int i = 0; i < s.length(); i++)

using namespace std;

int main(){
    string s;
    cin >> s;
    string c = "coffee";
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using namespace std;

int main() {
    int x[3001], y[3001];
    int i = 0;
    while(true) {
        cin >> x[i] >> y[i];
        if(x[i] == 0 && y[i] == 0) break;
        i++;
    }

    for(int j = 0; j < i; j++) {
        if(x[j] > y[j]) {
            int tmp = x[j];
            x[j] = y[j];
            y[j] = tmp;
        }
        
        cout << x[j] << " " << y[j] << endl;
    }

    return 0;
}


Measured memory_bytes: 3020
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

struct camel
{
    ll K, diff, L, R;
};

bool operator< (const camel &camel1, const camel &camel2){
    return camel1.K<camel2.K;
}
bool operator> (const camel &camel1, const camel &camel2){
    return camel1.K>camel2.K;
}


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

    for(int h=0; h<T; h++){
        int N;
        cin >> N;
        priority_queue<camel, vector<camel>, less<camel>> pqueL;
        priority_queue<camel, vector<camel>, greater<camel>> pqueR;
        for(int i=0; i<N; i++){
            ll K, L, R;
            cin >> K >> L >> R;
            K--;
            if(L>R){
                pqueL.push({K,L-R,L,R});
            }else{
                pqueR.push({K,R-L,L,R});
            }
        }

        ll ans=0;
        priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, less<pair<ll,ll>>> que;
        for(int i=(int)pqueL.size()-1; i>=0; i--){
            while((int)pqueL.size()>0 && pqueL.top().K>=i){
                que.push(make_pair(pqueL.top().diff,pqueL.top().L));
                pqueL.pop();
            }

            if((int)que.size()>0){
                //cout << que.top().second << endl;
                ans+=que.top().second;
                que.pop();
            }
        }
        while((int)que.size()>0){
            //cout << que.top().second << endl;
            ans+=que.top().second-que.top().first;
            que.pop();
        }

        for(int i=(int)pqueL.size(); i<N; i++){
            while((int)pqueR.size()>0 && pqueR.top().K<i){
                que.push(make_pair(pqueR.top().diff,pqueR.top().R));
                pqueR.pop();
            }

            if((int)que.size()>0){
                //cout << que.top().second << endl;
                ans+=que.top().second;
                que.pop();
            }
        }
        while((int)que.size()>0){
            //cout << que.top().second << endl;
            ans+=que.top().second-que.top().first;
            que.pop();
        }
        while((int)pqueR.size()>0){
            ans+=pqueR.top().L;
            pqueR.pop();
        }

        cout << ans << '\n';
    }
}

Measured memory_bytes: 12904
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

int n, mem, a[3];
int main() {
	cin >> n;
	a[0] = a[1] = a[2] = 0;
	lp(n) {
		cin >> mem;
		if (mem % 4 == 0)a[2]++;
		else if(mem % 2 == 0)a[1]++;
		else a[0]++;
	}
	if (a[1] == 0) {
		if (a[0] <= a[2] + 1)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else {
		if (a[0] <= a[2])cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define maxn 100050
int a[105],dp[maxn];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	dp[0]=0;
	for (int i=1;i<=k;i++){
		int f=0;
		for (int j=1;j<=n;j++)
		if (i-a[j]>=0&&(!dp[i-a[j]])) {
			f=1;
			break;
		}
		dp[i]|=f;
	}
	if (dp[k]) printf("First\n");else 
		printf("Second\n");
	return 0;
}
/*
dp[j]表示状态为j的sg函数

dp[j]=mex(dp[j-a[i]])
*/


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5000100;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

bool graph[101][101];
bool visit[101010];
vector<ll> to[101010];
vector<ll>ball(101010, 1);
vector<bool>flag(101010);

//long longしか使わない
//素数は1より大きい
int main() {
	ll n;
	cin >> n;
	ll ans = 0;
	rep(i, n) {
		ll x;
		cin >> x;
		ans = ans ^ x;
	}
	if (ans == 0) {
		puts("Yes");
	}
	else {
		puts("No");
	}
	return 0;
}


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

int main() {
	int a,b,sum=0,ave=0,i=0;
    while(scanf("%d,%d",&a,&b)!=EOF){
        sum+=(a*b);
        ave+=b;
        i++;
    }
    double c=ave;
    
    printf("%d\n%d\n",sum,(int)(c/i+0.5));
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    string s; cin>>s;
    int cnt=0, ans=0;
    rep(i,n){
        if (s[i]=='D'){
            cnt--;
        }else{
            cnt++;
        }
        chmax(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
dist=[]
for i in range(N-1):
    for j in range(i+1,N):
        dist.append(math.sqrt((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2))
print(2*sum(dist)/N)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
int max(int x,int y) {
  if (x > y) {
    return x;
  } else {
    return y;
  }
}
int min(int x,int y) {
  if (x > y) {
    return y;
  } else {
    return x;
  }
}
int main(void) {
  int A,B;
  scanf("%d %d", &A, &B);
  int ans;
  ans = max(A,B) + max(max(A,B)-1,min(A,B));
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 105;
const int MAXV = 100005;

ll N, W, w[MAXN], v[MAXN], dp[MAXN][MAXV], inf = 1e18, ans = 0;       // Minimum weight of objects to get value val from objects of indices ind to N

ll rec(ll ind, ll val)
{
	if(val == 0) return 0;
	if(ind > N) return inf;
	if(ind == N || val < 0) return inf;
	if(dp[ind][val] != 1e17) return dp[ind][val];
	return dp[ind][val] = min(w[ind] + rec(ind + 1, val - v[ind]), rec(ind + 1, val));
}

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

 	cin >> N >> W;
 	for(int i=0;i<N;i++) cin >> w[i] >> v[i];
 	for(int i=0;i<MAXN;i++)
 		for(int j=0;j<MAXV;j++)
 			dp[i][j] = 1e17;
 	for(int i=0;i<MAXN;i++)
 		for(int j=0;j<MAXV;j++)
 			if(rec(i, j) <= W)
 				ans = max(ans, (ll)j);
 	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 82304
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

bool solve(vector<int> D){
  int N = D.size();
  int max_d = 0;
  for(int i = 0; i < N; ++i){
    if(max_d < i*10){
      return false;
    }
    max_d = max(max_d,i*10+D[i]);
  }
  return true;
}

int main(){
  int N;
  cin >> N;
  vector<int> D(N);
  for(int i = 0; i < N; ++i) cin >> D[i];
  bool f = solve(D);
  reverse(D.begin(), D.end());
  f &= solve(D);
  if(f) cout << "yes" << endl;
  else cout << "no" << endl;
}



Measured memory_bytes: 5216
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

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

    long long count = 0;
    int buf = 0;
    bool findB = false;
    for(int i = 0; i < s.size(); i++){
        if(!findB){
            if(s[i] == 'B'){
                findB = true;
            }else{
                buf++;
            }
            continue;
        }
        if(s[i] == 'W'){
            count += (i-buf);
            buf++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 952
#include <bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
const long long MAXN=4010;
long long n,x[200010],y[200010];
long long dp[MAXN+100][MAXN+100];
long long fac[2*MAXN+100],inv[2*MAXN+100];
long long C(long long x,long long y){return fac[x]*inv[y]%mod*inv[x-y]%mod;}
long long fpm(long long x,long long y){
	long long res=1;
	while(y){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
long long ans=0;
int main(){
	scanf("%lld",&n);
	for(register long long i=1;i<=n;i++) scanf("%lld%lld",&x[i],&y[i]);
	fac[0]=1;for(register long long i=1;i<=8000;i++)fac[i]=fac[i-1]*i%mod;
	inv[1]=1;for(register long long i=2;i<=8000;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	inv[0]=1;for(register long long i=1;i<=8000;i++)inv[i]=inv[i-1]*inv[i]%mod;
	memset(dp,0,sizeof(dp));
	for(register long long i=1;i<=n;i++) dp[2005-x[i]][2005-y[i]]++;
	for(register long long i=-2005+1;i<=2005;i++){
		for(register long long j=-2005+1;j<=2005;j++){
			dp[2005+i][2005+j]=(dp[2005+i][2005+j]+dp[2005+i][2005+j-1]+dp[2005+i-1][2005+j])%mod;
		}
	}
	for(register long long i=1;i<=n;i++) ans=(ans+dp[2005+x[i]][2005+y[i]])%mod;
	for(register long long i=1;i<=n;i++) ans=((ans-C(2ll*x[i]+2ll*y[i],2ll*x[i]))%mod+mod)%mod;
	ans=ans*fpm(2,mod-2)%mod;
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 135424
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int r = (n % 1000);
    int ans = 0;
    if(r > 0) ans = 1000 - r;
    System.out.println(ans);
  }
}

Measured memory_bytes: 35844