akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[1000];
	int z[1000];
	int a, b, c, d, e, f;
	
	while (scanf("%s", str) != EOF) {
		a = strlen(str);
		for (b = 0; b < a; b++) {
			if (str[b] == 'I') {
				z[b] = 1;
			}
			else if (str[b] == 'V') {
				z[b] = 5;
			}
			else if (str[b] == 'X') {
				z[b] = 10;
			}
			else if (str[b] == 'L') {
				z[b] = 50;
			}
			else if (str[b] == 'C') {
				z[b] = 100;
			}
			else if (str[b] == 'D') {
				z[b] = 500;
			}
			else if (str[b] == 'M') {
				z[b] = 1000;
			}
		}
		c = z[b - 1];
		for (b = a - 1; b > 0; b--) {
			if (z[b] <= z[b-1]) {
				c += z[b-1];
			}
			else {
				c -= z[b-1];
			}
		}
		printf("%d\n", c);
	}
	
	return (0);
}

Measured memory_bytes: 544
/*
    author: Ibrahim-Elsayed (Codeforces Handle)
    date: 8/01/2020
*/
//======================================================================
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1e18
#define N_INF -1e18
#define MD 1000000007
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = 3.141592653589793;
//======================================================================

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

    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < (int)s.length(); i++) {
        if(s[i] != t[i]) {
            ans++;
        }
    }

    cout << ans;
    return 0;
}



Measured memory_bytes: 3772
'use strict'

function main(input) {
    const args = input.split('\n');
    const oneL = args[0].split(' ');

    const N = parseInt(oneL[0], 10);
    const M = parseInt(oneL[1], 10);
    const C = parseInt(oneL[2], 10);
    
    const B = args[1].split(' ').map(b => parseInt(b, 10));

    const A = args.slice(2).map(a => {
        return a.split(' ').map(ai => parseInt(ai, 10))
    }); // [[1, 2, 3], [1, 2, 3], ..]

    let count = 0;

    for (let i = 0; i < N; i++) {
        let sum = C;
        for (let j = 0; j < M; j++) {
            sum += A[i][j] * B[j];
        }
        if (sum > 0) count++;
    }

    console.log(count);
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
using lli=long long int;
using loi=long int;
// Problem https://atcoder.jp/contests/abc073/tasks/abc073_c
loi solver(loi numCount,vector<lli> JoisinoSayNo){
    loi result;
    result=0;
    unordered_map<lli,loi> numDict;
    numDict.clear();
    for(loi j=0;j<numCount;j++){
        numDict[JoisinoSayNo.at(j)]=(numDict[JoisinoSayNo.at(j)]+1)%2;
    }
   for(auto itr=numDict.begin();itr != numDict.end();itr++){
   //     cout << "key = " << itr->first << " Value=" << itr->second << endl;
    result=result+itr->second;
    }

    return result;
}

int main(void){
    loi answer;
    loi N;
    cin >> N ;
    vector<lli> Ai(N,0);
    for(loi j=0;j<N;j++){
        cin >> Ai.at(j);
    }
    answer = 0; // 初期化
    answer = solver(N,Ai);
    cout << answer << endl;
}

Measured memory_bytes: 5924
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define gc getchar()
#define mp make_pair
#define P pair<int,int>
#define ri register int
#define rb register bool
#define rc register char
#define t(i) edge[i].to
#define w(i) edge[i].wei
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
#define e(i,x) for(ri i=head[x];i;i=edge[i].nxt)

const int N=2*1e5+10;
int w[N],d[N],cnt[20],res,n,st,sxr[N];
bool book[N];

il int read()
{
	rc ch=gc;ri x=0;rb y=1;
	while(ch!='-' && (ch<'0' || ch>'9'))ch=gc;
	if(ch=='-')ch=gc,y=0;
	while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
	return y?x:-x;
}

int main()
{
	n=read();rp(i,1,n-1){ri u=read()+1,v=read()+1,va=read();w[u]^=va;w[v]^=va;}rp(i,1,n)cnt[w[i]]++;
	rp(i,1,15)res+=cnt[i]/2,st|=(cnt[i]&1)<<(i-1);
	n=1<<15;
	rp(i,1,n-1)d[i]=d[i>>1]+(i&1);rp(i,1,n-1)d[i]-=1;
	rp(i,1,n-1){rp(j,0,14)if((i>>j)&1)sxr[i]^=(j+1);}
	for(int i=1;i<(1<<15);i++)
	{
		if(sxr[i]!=0)continue;
		for(int k=(i-1)&i;k;k=(k-1)&i)
			if(sxr[k]==0)d[i]=min(d[i],d[k]+d[i^k]);
	}
	printf("%d",res+d[st]);
	return 0;
}


Measured memory_bytes: 896
N = int(input())
works = [[int(i) for i in input().split()] for _ in range(N)]
elapsed = 0

works.sort(key=lambda x: x[1])

for work in works:
    time, deadline = work
    if elapsed + time <= deadline:
        elapsed += time
    else:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 41172
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n,m; cin >> n >> m;
    bool ok = true;
    vector<ll> cnt(n);
    rep(i,m){
        ll a,b; cin >> a >> b;
        a--;b--;
        cnt[a]++;cnt[b]++;
    }
    rep(i,n){
        if(cnt[i]%2)ok = false;
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}

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

using namespace std;

int main()
{
   int n,m;
   cin>>n>>m;
   if(n>m)
    for(int i=0;i<n;i++)
        cout<<m;
   else if(m>n)
    for(int i=0;i<m;i++)
        cout<<n;
   else
    for(int i=0;i<m;i++)
        cout<<n;



    return 0;
}


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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e16;

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

  LL ans = 0;
  int N;
  cin >> N;
  vector<int> count(100001, 0);
  FOR(i, 0, N) {
    int a;
    cin >> a;
    count[a]++;
  }

  LL temp;
  FOR(i, 0, 99999) {
    temp = count[i] + count[i + 1] + count[i + 2];
    ans = max(ans, temp);
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
  int r, d, x;
  cin >> r >> d >> x;
  for (int i = 0; i<10;i++) {
    x = r * x -d;
    cout << x << endl;
  }
  return 0;
}


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

bool isPalindrome(int n)
{
	auto s = to_string(n);
	return s == string(s.rbegin(), s.rend());
}
int main()
{
	int a, b;
	cin >> a >> b;
	int c = 0;
	for (int i = a; i <= b; i++)
		if (isPalindrome(i))
			c++;
	cout << c << endl;
}


Measured memory_bytes: 3664
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, m;
	cin>>n>>m;
	int cnt[100010]={};
	bool ok[100010]={};
	for(int i=0; i<m; i++){
		int p; string s;
		cin>>p>>s;
		p--;
		if(ok[p]) continue;
		if(s=="WA"){
			cnt[p]++;
		}else{
			ok[p]=1;
		}
	}
	int ans=0, ans2=0;
	for(int i=0; i<n; i++){
		if(ok[i]) ans++;
		if(ok[i]) ans2+=cnt[i];
	}
	cout<<ans<<" "<<ans2<<endl;
	return 0;
}

Measured memory_bytes: 768
sx,sy,tx,ty = map(int,input().split())

ux = (tx - sx)
uy = (ty - sy)
route = []

for i in range(ux):
    route.append('R')
for i in range(uy):
    route.append('U')
for i in range(ux):
    route.append('L')
for i in range(uy):
    route.append('D')
    
route.append('D')
for i in range(ux):
    route.append('R')
route.append('R')
route.append('U')
for i in range(uy):
    route.append('U')
route.append('L')
route.append('U')
for i in range(ux):
    route.append('L')
route.append('L')
route.append('D')
for i in range(uy):
    route.append('D')
route.append('R')

ans = ''

for i in route:
    ans += i
print(ans)

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

int sum_digits(int x){

	int sum = 0;

	while (x){

		sum += x%10;
		x /= 10;
	}
	
	return sum;

}

int main(){
	
	ios::sync_with_stdio(false);
	
	int a = 1, b, n, min = 1e5;
	
	cin >> n;
	b = n-1;

	while (a <= n/2){

		if (sum_digits(a) + sum_digits(b) < min)
			min = sum_digits(a) + sum_digits(b);
		b--;
		a++;
	}

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

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(lambda x: int(x) - 1, input().split()))
c = list(map(int, input().split()))
 
ans = max(c)
for i in range(n):
    curr = 0
    score = [0]
    posi = i
    while p[posi] != i:
        posi = p[posi]
        curr += c[posi]
        score.append(curr)
    cycle_score = score[-1] + c[i]
    cycle_len = len(score)
    
    for j in range(cycle_len):
        if j <= k and j != 0:
            cycles = (k - j)//cycle_len
            thing = score[j] + max(0, cycle_score) * cycles
            ans = max(ans, thing)
        #Kがサイクルより大きいときの処理をj=0で行う(score[0]は無効なため)
        elif j == 0 and k >= cycle_len:
            thing = cycle_score * k // cycle_len
            ans = max(ans,thing)

print(ans)

Measured memory_bytes: 84580
#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;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n, k;
	cin >> n >>k;
	vector<int> h(n);
	forn(i, n) cin >> h[i];
	if(k >= n) cout << 0 << endl;
	else {
		sort(all(h));
		ll res = 0;
		for(int i = 0; i < n-k; i++) {
			res += h[i];
		}

		cout << res << endl;
	}

	return 0;
}



Measured memory_bytes: 4056
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include<iomanip>

#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int; // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

/*
 * データ変換 
 */
/* char -> int */
int ctoi(char c) { return (int)(c - '0'); }

/*
 * 数学的な計算
 */
/* 階乗 */
int factorial(int n){ int ret = 1; for(int i = 1; i < n + 1; ++i) { ret = ret * i; } return ret; }

/* 最大公約数 */
template <typename T>T gcd(T x, T y){ return x % y == 0 ? y : gcd(y, x % y); }

/* 最小公倍数 */
template <typename T>T lcm(T a, T b) { return a * b / gcd(a, b); }

/* n個の整数の最小公倍数 */
template <typename T>T lcm_n(vector<T> &numbers) { T l; l = numbers[0]; for(int i = 1; i < numbers.size(); ++i) { l = lcm(l, numbers[i]); } return l; }

/*
 * DP向け
 */
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 (b<a) { a=b; return 1; } return 0; }

/*
 * グラフ
 */
class Graph {
   public:
    vector<vector<int>> G;
    vector<int> Trans;
    vector<int> inDeg;
    int numV;
 
    Graph(int numV) {
        this->numV = numV;
        inDeg.assign(numV, 0);
        Trans.assign(numV, 0);
        G.assign(numV, vector<int>());
    }
 
    int topologicalSort(int v, vector<int> &dp) {
        if (dp[v] != -1) {
            return dp[v];
        }
 
        int res = 0;
 
        for (auto to : G[v]) {
            chmax(res, topologicalSort(to, dp) + 1);
        }
 
        return dp[v] = res;
    }
};


int main(){
  string str;
  string str_rev;
  cin >> str;
  str_rev = str;
  reverse(str_rev.begin(), str_rev.end());

  if(str == str_rev){
    string sub1, sub1_rev;
    sub1 = str.substr(0, (str.length() - 1)/2);
    sub1_rev = sub1;
    reverse(sub1_rev.begin(), sub1_rev.end());
    if(sub1 == sub1_rev){
      string sub2, sub2_rev;
      sub2 = str.substr((str.length() + 3)/2 - 1, (str.length() - 1)/2);
      sub2_rev = sub2;
      reverse(sub2_rev.begin(), sub2_rev.end());
      if(sub2 == sub2_rev){
        cout << "Yes" << endl;
      }
    }else{
      cout << "No" << endl;
    }
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int n = sc.nextInt();
			for (int i = 0; i < n; i++) {
				double xa = sc.nextDouble();
				double ya = sc.nextDouble();
				double ra = sc.nextDouble();
				double xb = sc.nextDouble();
				double yb = sc.nextDouble();
				double rb = sc.nextDouble();
				double rab = Math.sqrt((xb - xa) * (xb - xa) + (yb - ya)
						* (yb - ya));
				if(ra+rb<rab) System.out.println("0");
                else if(ra>rb && ra-rb>rab) System.out.println("2");
                else if(rb>ra && rb-ra>rab) System.out.println("-2"); 
                else System.out.println("1");
			}
		}
	}
}

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

using namespace std;

int main(){
    int A, B;
    scanf("%d %d", &A, &B);
    if(A >= 13){
        printf("%d\n", B);
    }
    else if(A >= 6 && A <= 12){
        printf("%d\n", B / 2);
    }
    else{
        puts("0");
    }
    return 0;
}


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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
        //#include <ttmath.h>
        #define endl '\n'
        #define modulo 1000000007
        #define int long long
        #pragma GCC optimize("-Ofast")
        #define float double
        #define PI 3.141592653589793238462643
        #define sinDegrees(x) sin((x) * PI / 180.0)
        #define tanDegrees(x) tan((x) * PI / 180.0)
        #define atanDegrees(x) atan(x)* 180.0 / PI
        using namespace std;
        int power(int x, unsigned int y)
        {
            if (y == 0)
                return 1;
            else if (y % 2 == 0)
                return (power(x, y / 2) * power(x, y / 2));
            else
                return (x * power(x, y / 2) * power(x, y / 2));
        }
        /*#include "testlib.h"
        int main(int argc, char* argv[])
        {
        iostream::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        registerGen(argc, argv, 1);
        int n,k;
        n=rnd.next(1,50);
        k=rnd.next(1,n);
        cout<<n<<' '<<k;
        }*/
        bool comp(int a,int b)
        {
            return a>b;
        }
        int32_t main()
        {
            //freopen("output.txt","w", stdout);
            //freopen("input4.txt","r", stdin);
            iostream::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            int n,maxer=INT_MAX;
            cin>>n;
            int arr[n];
            for(int i=0;i<n;i++){
            cin>>arr[i];
            }
            int counter=0;
            for(int middle=1;middle<=100;middle++){
            for(int i=0;i<n;i++){
            counter=counter+(arr[i]-middle)*(arr[i]-middle);
            }
            maxer=min(counter,maxer);
            counter=0;
            }
            cout<<maxer;
            return 0;
        }


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

typedef std::pair <int, int> pr;
typedef std::map <int, int> map;
const int N = 108;

int n, O, E;
int o[N], e[N];
map S;
int pn = 0, c[10000054], p[666666];

void sieve(int n) {
	int i, j, v;
	memset(c, -1, sizeof c);
	for (i = 2; i <= n; ++i) {
		if (!~c[i]) p[pn] = i, c[i] = pn++;
		for (j = 0; (v = i * p[j]) <= n && j <= c[i]; ++j) c[v] = j;
	}
}

inline bool is_prime(int x) {return p[c[x]] == x;}

namespace F {
	#define ad(x) ((x - 1 ^ 1) + 1)

	const int N = 2000, M = 100000;

	struct edge {
		int u, v, f;
		edge (int u0 = 0, int v0 = 0, int f0 = 0) : u(u0), v(v0), f(f0) {}
	} e[M];

	int V = 2, E = 0, si = 1, ti = 2, flow;
	int first[N], next[M];
	int dep[N], cur[N], que[N];

	inline void addedge(int u, int v, int f) {
		e[++E] = edge(u, v, f), next[E] = first[u], first[u] = E;
		e[++E] = edge(v, u), next[E] = first[v], first[v] = E;
	}

	bool bfs() {
		int h, t = 1, i, x, y;
		memset(dep, -1, sizeof dep);
		que[0] = si, dep[si] = 0;
		for (h = 0; h < t; h++) {
			if ((x = que[h]) == ti) return true;
			for (i = first[x]; i; i = next[i])
				if (dep[y = e[i].v] == -1 && e[i].f)
					que[t++] = y, dep[y] = dep[x] + 1;
		}
		return false;
	}

	int dfs(int x, int lim) {
		int a, c, f = 0;
		if (x == ti || !lim) return lim;
		for (int &i = cur[x]; i; i = next[i])
			if (dep[e[i].v] == dep[x] + 1 && e[i].f) {
				a = std::min(lim - f, e[i].f);
				c = dfs(e[i].v, a);
				e[i].f -= c; e[ad(i)].f += c;
				if ((f += c) == lim) return f;
			}
		return f;
	}

	int Dinic() {
		for (flow = 0; bfs(); flow += dfs(si, INT_MAX))
			memcpy(cur, first, sizeof cur);
		return flow;
	}
}

int main() {
	int i, j, x;
	scanf("%d", &n), sieve(10000053);
	for (i = 0; i < n; ++i) scanf("%d", &x), ++S[x], ++S[x + 1];
	for (const pr &p : S) if (p.second & 1) (p.first & 1 ? o[O++] : e[E++]) = p.first;
	for (i = 0; i < O; ++i) F::addedge(1, 3 + i, 1);
	for (j = 0; j < E; ++j) F::addedge(3 + O + j, 2, 1);
	for (i = 0; i < O; ++i)
		for (j = 0; j < E; ++j)
			if (is_prime(abs(o[i] - e[j]))) F::addedge(3 + i, 3 + O + j, 1);
	x = F::Dinic(), O -= x, E -= x;
	printf("%d\n", x + O + E + (O & 1));
	return 0;
}

Measured memory_bytes: 43136
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<string>


int main() {
	int n;
	bool a;
	std::vector<int> prime;
	prime.emplace_back(2);
	for (int i = 3; i < 1000000; i += 2) {
		a = false;
		for (int j = 3; j <= std::sqrt(i); j += 2) {
			if (i%j == 0) {
				a=true;
			}
		}
		if (a == false) {
			prime.emplace_back(i);
		}
	}
	while (std::cin >> n) {
		int ans = 0;
		for (int i = 0; i < prime.size(); i++) {
			if (prime[i] <= n) {
				ans++;
			}
		}
		std::cout << ans << std::endl;
	}
}

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

const int mod = 1000000007;

int a[200010];
int last[200010];
long long dp[200010];

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
	}
	
	dp[0] = 1;
	for (int i = 1; i <= n; i++){
		dp[i] = dp[i - 1];
		if (last[a[i]] && last[a[i]] != i - 1) dp[i] = (dp[i] + dp[last[a[i]]]) % mod;
		last[a[i]] = i;
	}
	printf("%lld\n", dp[n]);
	return 0;
}


Measured memory_bytes: 3328
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;




//ここから編集する
ll gcd(ll a,ll b){
    if(a < b) swap(a,b);
    if(a % b == 0) return b;
    return gcd(b, a % b);

}

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


int main() {
    int n;
    cin >> n;
    set<int> s;
    REP(i,0,n){
        int tmp;
        cin >> tmp;
        if(s.find(tmp) == s.end()){
            s.insert(tmp);
        }else{
            s.erase(tmp);
        }
    }

    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<LL> S(N); rep(i, N) cin >> S[i];
		LL ans = 0;
		N--;
		for (UL D = 1; D < N; D++) {
			UL mx = (N + 1) / D;
			if (N % D == 0) mx = (N / D + 1) / 2;
			LL sum = 0;
			for (UL T = 1; T < mx; T++) {
				sum += S[D * T];
				sum += S[N - D * T];
				ans = max(ans, sum);
				//cout << "(D, T) = (" << D << ", " << T << ") : ";
				//cout << sum << endl;
			}
		}
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;



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

		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));

		try{
		String s=reader.readLine();
		String p=reader.readLine();
		String ss=s+s;//s????????????????????¨??§???????????°???1?????¨???????????????

		//??£?????¨???????????£????±??????????

		Pattern pat=Pattern.compile(p);

		check(pat, ss);


		}catch(IOException e){
			System.out.print(e);
		}
	}

	private static void check(Pattern pat, String ss){
		Matcher m=pat.matcher(ss);
		if(m.find()){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 24484
#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


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

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


signed main(){

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

    int x, y, z, n, m, s, t;
    cin >> x >> y >> z >> n >> m >> s >> t;
    --s, --t;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
    }
    vector<int> c(m), d(m);
    for(int i = 0; i < m; ++i){
        cin >> c[i] >> d[i];
        --c[i], --d[i];
    }
    int num = x + y + z + n + m;
    vector<i64> range(num, MOD);
    range[x + y + z + s] = 0;

    vector<vector<pair<i64, i64>>> edges(num);
    for(int i = 0; i < n; ++i){
        int idx = x + y + z + i;
        int a_idx = a[i];
        int b_idx = b[i] + x;
        edges[idx].emplace_back(a_idx, 0);
        edges[idx].emplace_back(b_idx, 0);
        edges[a_idx].emplace_back(idx, 1);
        edges[b_idx].emplace_back(idx, 1);
    }
    for(int i = 0; i < m; ++i){
        int idx = x + y + z + n + i;
        int a_idx = c[i] + x;
        int b_idx = d[i] + x + y;
        edges[idx].emplace_back(a_idx, 0);
        edges[idx].emplace_back(b_idx, 0);
        edges[a_idx].emplace_back(idx, 1);
        edges[b_idx].emplace_back(idx, 1);
    }

    priority_queue<pair<i64,i64>, vector<pair<i64,i64>>, greater<pair<i64,i64>>> que;
    que.emplace(0, x + y + z + s);
    while(!que.empty()){
        i64 dist, top;
        tie(dist, top) = que.top();
        que.pop();
        if(dist != range[top])
            continue;
        for(auto& p : edges[top]){
            i64 nex = p.first;
            i64 n_dist = dist + p.second;
            if(chmin(range[nex], n_dist))
                que.emplace(range[nex], nex);
        }
    }

    i64 ans = range[x + y + z + n + t];
    if(ans == MOD){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}



Measured memory_bytes: 41720
def add(a,b):
    return (a[0]+b[0],a[1]+b[1])
    
dic={0:(-1,0),1:(0,-1),2:(1,0),3:(0,1)}

while 1:
    n=int(input())
    if n==0:
        break
    elif n==1:
        print(1,1)
        continue
    v=[(0,0)]
    for i in range(n-1):
        a,b=map(int,input().split())
        v.append(add(v[a],dic[b]))
    solve=sorted(v)
    print(solve[-1][0]-solve[0][0]+1,end=' ')
    solve=sorted(v,key=lambda x:x[1])
    print(solve[-1][1]-solve[0][1]+1)  
        


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

int main(){
    int n;
    map<string, int> mp;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        mp[s]++;
    }
    cout<< "AC x " <<mp["AC"]<<endl;
    cout<< "WA x " << mp["WA"] << endl;
    cout<< "TLE x " << mp["TLE"] << endl;
    cout<< "RE x " << mp["RE"] << endl;
    
}

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

using namespace std;

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

int main(){
    int n, k;
    cin >> n >> k;
    if((n-1)*(n-2)/2 < k)cout << -1 << endl;
    else{
        int dif = (n-1)*(n-2)/2-k;
        cout << n-1+(n-1)*(n-2)/2-k << endl;
        for(int i = 2; i <= n; i++)cout << 1 << ' ' << i << endl;
        for(int i = 2; i <= n; i++){
            for(int j = i+1; j <= n; j++){
                if(!dif)return 0;
                cout << i << ' ' << j << endl;
                dif--;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
 
  char a[4]={'S','H','C','D'};
  map<char,vector<int> >in;
  int n;
  cin>>n;
  rep(i,n){
    char d;
    int m;
    cin>>d>>m;
    in[d].pb(m-1);
  }
  rep(i,4){
    sort(all(in[a[i]]));
  }
  rep(j,4)for(int i=-1;i<12;){
    i++;
    if(in[a[j]].size()==0||i!=in[a[j]][0])cout<<a[j]<<" "<<i+1<<endl;
    else in[a[j]].erase(in[a[j]].begin());
  }
}

Measured memory_bytes: 1220
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	char s[100000];
	scanf("%s", s);
	int n=strlen(s);
	if(n==2){
		if(s[0]==s[1]){
			printf("%d %d\n", 1, 2);
		}else{
			printf("%d %d\n", -1, -1);
		}
		return 0;
	}else{
	for(int i=0; i<n-1; i++){
		if(s[i]==s[i+1]){
			printf("%d %d\n", i+1, i+2);
			return 0;
		}
	}
	for(int i=0; i<n-2; i++){
		if(s[i]==s[i+2]){
			printf("%d %d\n", i+1, i+3);
			return 0;
		}
	}
	printf("%d %d\n", -1, -1);
	return 0;
	}
}

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

using namespace std;
using ll = long long;

#define eb emplace_back
#define pb push_back
// #define mp make_pair
#define ff first
#define ss second

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);     
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <ext/rope>
// using namespace __gnu_pbds; 
// using namespace __gnu_cxx;
// template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;
// template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
// template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}


template <typename A>
istream& operator>>(istream& input,vector<A>& x) { for(auto& i:x) input>>i; return input; }
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {  for(auto& i:x) output<<i<<' '; return output; }
template<typename T, typename U> 
istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> 
ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;}

const int mod = 1e9 + 7;
const int N = 1e6 + 5;


int ans;
int main () {
    io();
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size(); i++)
        if(s[i] != t[i])
            ans++;

    cout << ans;
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;
 
signed main(){
    int p,q,r;
    cin>>p>>q>>r;
    cout<<min({p+q,q+r,r+p})<<endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    unsigned int n, c, k;
    cin >> n >> c >> k;
 
    vector<int> t(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }
    sort(t.begin(), t.end());
 
    vector<int> passengers(n);
    for (int i = 0; i < n; ++i) {
        passengers[i] = 1;
    }
 
    int ans = 0;
    int curr = 0;
    for (int i = 1; i < n; ++i) {
        if (t[i] > t[curr] + k || passengers[ans] == c) {
            ans++;
            curr = i;
        } else {
            passengers[ans]++;
        }
    }
    cout << ans + 1 << endl;
    return 0;
}

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

int n, k;
map<int, int> mp;
vector<int> v;

int main() {
  int ans = 0;
  cin >> n >> k;
  for(int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++mp[a];
  }
  for(auto it = mp.begin(); it != mp.end(); ++it) {
    v.push_back(it->second);
  }
  sort(v.begin(), v.end());
  if(v.size() > k)
    for(int i = 0; i < v.size() - k; ++i) ans += v[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10748
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int hiniti(int y,int m,int d){
    int result=0;
    for(int s=1;s<=y;s++){
        for(int j=1;j<=10;j++){
            if(y==s&&m==j){
                return result+=d;
            }
            if(s%3==0){
                result+=20;
            }else{
                if(j%2==0){
                    result+=19;
                }else{
                    result+=20;
                }
            }
        }
    }
}
int main(void){
    int n;
    cin>>n;
    int y,m,d;
    for(int s=0;s<n;s++){
        cin>>y>>m>>d;
        int t=hiniti(y, m, d);
        cout<<196471-t<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e9;
const ll lmt=1e5+10;
int main()
{
    //freopen("take.in","r",stdin);
    ll n;
    cin>>n;
    ll a[n+1],b[n+1],c[n+1];
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    ll ans[n+1][3];
    ans[1][1]=a[1];
    ans[1][2]=b[1];
    ans[1][3]=c[1];
    for(ll i=2;i<=n;i++)
    {
        ans[i][1]=max(a[i]+ans[i-1][2],a[i]+ans[i-1][3]);
        ans[i][2]=max(b[i]+ans[i-1][1],b[i]+ans[i-1][3]);
        ans[i][3]=max(c[i]+ans[i-1][1],c[i]+ans[i-1][2]);
    }
    cout<<max(ans[n][1],max(ans[n][2],ans[n][3]))<<endl;
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

ll N, M;
ll X;
vll C;
vvll A;

ll search(ll state){
  ll cost = 0;
  vll P(M, 0);
  REP(i,N){
    if((state&(1<<i))==0) continue;
    REP(j,M){
      P[j] += A[i][j];
    }
    cost += C[i];
  }
  //debug_print(state, cost);
  //vec_print(P);
  REP(i,M){
    if(P[i]<X) return INFLL;
  }
  return cost;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  IN(N,M,X);
  C.resize(N);
  A.resize(N, vll(M, 0));
  REP(i,N){
    IN(C[i]);
    REP(j,M){
      IN(A[i][j]);
    }
  }

  ll ans = INFLL;
  REP(i,1<<N){
    chmin(ans, search(i));
  }

  if(ans==INFLL) ans = -1;
  OUT(ans);


  return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
using namespace std;

int main(){
    long n, k, maxi=1, sum = 0;
    cin >> n >> k;
    vector< pair<long, long> > v(n); 

    for(long i=0; i<n; i++) {
        long m;
        cin >> m;
        v[m].first++;
    }

    sort(v.begin(), v.end());

    for(long i=v.size()-1; i > n - k - 1; i--) sum += v[i].first;
    
    cout << n - sum << endl;
}

Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-8;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    sort(rall(a));
    priority_queue<int> que;
    int ans = 0;
    que.push(a[0]);
    reps(i, n - 1) {
        auto p = que.top();
        que.pop();
        ans += p;
        que.push(a[i]);
        que.push(a[i]);
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 6900
/*************************************************************************
  >         File: Main.java
  >       Author: Riho.Yoshioka
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Sun 07 Aug 2016 12:44:17 AM CST
*************************************************************************/
import java.io.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    
    TaskE solver = new TaskE();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskE {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();
      int[] numbers = new int[n];
      for (int i = 0; i < n; i++) {
        numbers[i] = in.nextInt();
      }
      Arrays.sort(numbers);
      for (int i = 0, j = n - 1; i < j; i++, j--) {
        int tmp = numbers[i]; numbers[i] = numbers[j]; numbers[j] = tmp;
      }
      int now = 0;
      for (int i = 0; i < n; i++) {
        if (numbers[i] >= now + 1) now++;
        else {
          break;
        }
      }
      int a = (numbers[now - 1] - now);
      int b = 0;
      int idx = now;
      while (idx < n && numbers[idx] == now) {
        b++; idx++;
      }
      b--; a++;
      if ((a & 1) == 0 || (b & 1) == 0) {
        out.println("First");
      }
      else {
        out.println("Second");
      }
    }
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }
}


Measured memory_bytes: 23836
#coding: utf-8

n = int(input())
color = ["white" for i in range(n)]
d = [[] for i in range(n)]
global t
t = 0
M = [[False for i in range(n)] for j in range(n)]
for i in range(n):
    data = list(map(int,input().split()))
    u = data[0]
    k = data[1]
    if i == 0:
        start = u
    for v in data[2:2+k]:
        M[u-1][v-1] = True


def search(u,t):
    t += 1
    color[u-1] = "gray"
    d[u-1].append(t)
    for v in range(1,n+1):
        if M[u-1][v-1] and color[v-1] == "white":
            t = search(v,t)
    color[u-1] = "black"
    t += 1
    d[u-1].append(t)
    return t

t = search(start, t)
for i in range(1,n+1):
    if color[i-1] == "white":
        t = search(i, t)

for i in range(n):
    print(i+1, d[i][0], d[i][1])



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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

int main(void)
{
  ll s,w; cin >> s >> w;
  cout << ((s > w) ? "safe" : "unsafe") << endl;
}


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

#define MAX 100002

int n;

long long int a[MAX];


vector<int> v[MAX];

void er(){
	puts("NO");
	exit(0);
}

inline int dfs(int b,int pr=-1){
	vector<long long int> cnt;
	long long int sum = 0;
	bool leaf = true;
	for (int i = 0; i < v[b].size(); i++){
		if (pr == v[b][i]){
			continue;
		}
		leaf = false;
		cnt.push_back(dfs(v[b][i], b));
		sum += cnt.back();
	}
	if (leaf){
		return a[b];
	}
	if (sum < a[b]){
		er();
	}
	long long int path = sum - a[b];
	long long int r = sum - path * 2LL;
	for (int i = 0; i < cnt.size(); i++){
		long long int rest = sum - cnt[i];
		if (rest < cnt[i]){
			sum -= cnt[i] - rest;
			cnt[i] = rest;
		}
	}
	if (sum < path * 2LL){
		er();
	}
	return r;
}

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
	}
	for (int i = 1; i < n; i++){
		int b, c;
		scanf("%d%d", &b, &c);
		b--;
		c--;
		v[b].push_back(c);
		v[c].push_back(b);
	}
	if (n == 2){
		if (a[0] != a[1]){
			er();
		}
		else{
			puts("YES");
		}
		return 0;
	}
	for (int i = 0; i < n; i++){
		if (v[i].size() > 1){
			int have=dfs(i);
			if (have){
				er();
			}
			puts("YES");
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 13568
#!/usr/bin/env python3
n, m = map(int, input().split())
ab = [map(int, input().split()) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]

for i in range(1, n + 1):
    ac = a.count(i)
    bc = b.count(i)
    print(ac + bc)


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

int main() {
  int a,b,d1,d2,d11,d12,d21,d22;
  vector<int> r(9);
  for (int i=0; i<9; i++) {
    cin >> r[i];
  }
  d1 = r[1] - r[0];
  d2 = r[2] - r[1];
  d11 = r[4] - r[3];
  d12 = r[5] - r[4];
  d21 = r[7] - r[6];
  d22 = r[8] - r[7];
  if(d1 == d11 && d11 == d21) {
    if(d2 == d12 && d12 == d22) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
  string a,b;
  cin >> a >> b;
  int n=a.size();
  int m=b.size();
  string ans;
  if(n>m)ans="GREATER";
  else if(n<m)ans="LESS";
  else if(n==m){
     bool c=true;
     rep(i,n){
        int aa=a.at(i)-'0';
        int bb=b.at(i)-'0';
        if(aa>bb){
           ans="GREATER";
           c=false;
           break;
        }
        else if(bb>aa){
           ans="LESS";
           c=false;
           break;
        }
     }
     if(c)ans="EQUAL";
  }
   cout << ans << endl;
}

Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()
  if s.count('RRR')>0:
    return 3
  if s.count('RR')>0:
    return 2
  if s.count('R')>0:
    return 1
  return 0

# main()
print(main())


Measured memory_bytes: 10708
n,k=map(int,input().split())
R,S,P=map(int,input().split())
t=input()

ans=0
win=[]
for tt in t:
 if tt=='r':
  win+='p'
  ans+=P
 elif tt=='s':
  win+='r'
  ans+=R
 else:
  win+='s'
  ans+=S

for i in range(k):
 l=win[i::k]
# print(l)
 for j in range(1,len(l)):
  if l[j]==l[j-1]:
   if l[j]=='p':
    ans-=P
   elif l[j]=='r':
    ans-=R
   else:
    ans-=S
   l[j]='z'

print(ans)

Measured memory_bytes: 4980
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, _ := strconv.ParseInt(readString(), 0, 64)
	// if err != nil {
	// 	panic(err.Error())
	// }
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

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

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}
func main() {
	N := readInt()
	M := readInt()
	Q := readInt()
	var data [510][510]int
	for i := 0; i < M; i++ {
		l, r := readInt(), readInt()
		data[l][r]++
	}

	for i := N; i >= 1; i-- {
		for j := 1; j <= N; j++ {
			data[i][j] += data[i+1][j]
			data[i][j] += data[i][j-1]
			data[i][j] -= data[i+1][j-1]
		}
	}

	for i := 0; i < Q; i++ {
		p, q := readInt(), readInt()
		println(data[p][q])
	}
	stdout.Flush()
}

Measured memory_bytes: 6272
#include<stdio.h>
#include<math.h>
int main()
{
    long long int H;
    scanf("%llu",&H);
    long long int sum=1,i=1;
    while(H>1)
    {
        H=H/2;
        sum+=pow(2,i);
        i++;
    }
    printf("%llu",sum);
}


Measured memory_bytes: 256
use proconio::{fastout, input};

const MOD: u64 = 1_000_000_007;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [u64; n],
    }

    let mut ans = 0;
    let mut sum: u64 = a.iter().sum();

    for i in a {
        sum -= i;
        ans += (sum % MOD) * (i % MOD) % MOD;
        ans %= MOD;
    }

    println!("{}", ans)
}


Measured memory_bytes: 5560