akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
ll sum,ans;
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	int m=read();
	For(i,1,m){
		int d=read(); ll c=read();
		ans+=c; sum+=c*d;
	}
	cout<<ans-1+(sum-1)/9<<endl;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

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

	string ans;

	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == '0') ans.push_back('0');
		else if (S[i] == '1') ans.push_back('1');
		else
		{
			if (ans.size() != 0) ans.pop_back();
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author YahiaAshraf74
 */

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el  '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define sz(a) (int)(a).size()
const long long N = (int) 2e5 + 74, OO = 0x3f3f3f3f, MOD = (int) 1e9 + 7;

int n;
int a[N][3];
int mem[N][3];
int dp[N][3];

class CVacation {
public:
    void init() {
        clr(mem, -1);
        clr(dp, 0);
    }

    int solve(int i, int last) {
        if (i == n)
            return 0;
        if (last != -1 && mem[i][last] != -1)
            return mem[i][last];
        mem[i][last] = 0;
        for (int j = 0; j < 3; j++) {
            if (last != j)
                mem[i][last] = max(mem[i][last], solve(i + 1, j) + a[i][j]);
        }
        return mem[i][last];
    }

    void solve(istream &cin, ostream &cout) {
        init();
        cin >> n;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++)
                cin >> a[i][j];
        }
//        dp[0][0] = max(a[0][1], a[0][2]);
//        dp[0][1] = max(a[0][0], a[0][2]);
//        dp[0][2] = max(a[0][0], a[0][1]);
        for (int i = 0; i < n; i++) {
            for (int k = 0; k < 3; k++) {
                for (int j = 0; j < 3; j++) {
                    if (k != j)
                        dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
                }
            }
        }
//        cout << solve(0, -1);
        cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
    }
};
int main() {
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	CVacation solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 6400
#include <stdio.h>
#include <algorithm>

int gcd(int, int);

int main(){
  int x, y, z;
  scanf("%d %d", &x, &y);
  z = gcd(x, y);

  printf("%d\n", z);
 
return 0;
}

int gcd(int x,int y){
    int r;      

    while (y > 0){
        r = x % y;
        x = y;
        y = r;
    }
    return x;
    
}

Measured memory_bytes: 2692
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int n, k;
int a[1<<18];

int main(){
	cin >> n >> k;
	
	if(k >= (1 << n) || (k == 1 && n == 1)) cout << -1 << endl;
	else if(k == 0){
		for(int i = 0; i < (1 << n); i++){
			cout << i << " " << i;
			if(i != (1<<n)-1) cout << " ";
		}
		cout << endl;
	}
	else if(k < (1 << n)/2){
		for(int i = 0; i <= (1 << n); i++){
			if(i == ((1 << n)/2)){ cout << k << " "; continue;}
			if(abs((1 << n)/2 - i)-1 == k) continue;
			cout << abs((1 << n)/2 - i)-1 << " ";
			
		}
		for(int i = 0; i <= (1 << n); i++){
			if(i == ((1 << n)/2)) cout << k << " ";
			else cout << (1 << n)/2 + abs((1 << n)/2 - i)-1 << " ";
		}
		cout << endl;
	}
	else{
		for(int i = 0; i <= (1 << n); i++){
			if(i == ((1 << n)/2)) cout << k << " ";
			else cout << abs((1 << n)/2 - i)-1 << " ";
		}
		for(int i = 0; i <= (1 << n); i++){
			if(i == ((1 << n)/2)){ cout << k << " "; continue;}
			if((1 << n)/2 + abs((1 << n)/2 - i)-1 == k) continue;
			cout << (1 << n)/2 + abs((1 << n)/2 - i)-1 << " ";
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>

const int MAX_N = 50;
long long d[MAX_N][2];

int main() {
  int n, p, x;
  scanf("%d%d", &n, &p);
  d[0][0] = 1LL;
  for(int i = 1; i <= n; ++i) {
    scanf("%d", &x);
    x = x % 2;
    d[i][0] = d[i - 1][0] + d[i - 1][0 ^ x];
    d[i][1] = d[i - 1][1] + d[i - 1][1 ^ x];
  }
  printf("%lld", d[n][p]);
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int N, L;
    cin >> N >> L;

    vector<string> S(N);
    rep(i, N) cin >> S[i];

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

    for (auto &i : S) cout << i;
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int c[10][10];
int h, w, a, ans;

int main() {
    cin >> h >> w;
    rep(i, 10) {
        rep(j, 10) {
            cin >> c[i][j];
        }
    }

    rep(k, 10) {
        rep(i, 10) {
            rep(j, 10) {
                if(c[i][j] > c[i][k] + c[k][j]) {
                    c[i][j] = c[i][k] + c[k][j];
                }
            }
        }
    }

    rep(i, h) {
        rep(j, w) {
            cin >> a;
            if(a >= 0) {
                ans += c[a][1];
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

int d[100], a[100];
int id[1000000];
vector<int>re[5040];
int dp[100][5040];
int h(vector<int>&v) {
	int p = 1, res = 0;
	for (int i : v)res += p*i, p *= 7;
	return res;
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &d[i]);
	rep(i, n)scanf("%d", &a[i]);
	vector<int>v(7); iota(v.begin(), v.end(), 0);
	int p = 0;
	do {
		id[h(v)] = p; re[p] = v;
		int cnt = 0;
		bool t[7]{};
		for (int i : v) {
			rep(j, 7) {
				if (t[j] && abs(j - i) <= d[j])cnt += a[j];
			}
			t[i] = 1;
		}
		dp[0][p] = cnt;
		p++;
	} while (next_permutation(v.begin(), v.end()));
	int ans = 0;
	for (int i = 1; i + 6 < n; i++)rep(j, 5040)rep(k, 8) {
		auto t = re[j].begin();
		int cnt = 0, o = 0;
		bool p[8]{};
		vector<int>q(7);
		rep(l, 8) {
			if (k == l) {
				rep(y, 8) {
					if (p[y] && y + d[i - 1 + y] >= 7)
						cnt += a[i - 1 + y];
				}
				p[7] = 1; q[o++] = 6;
			}
			else {
				if (p[7] && 7 - d[i + 6] <= *t)cnt += a[i + 6];
				p[*t] = 1;
				if (*t)q[o++] = *t - 1;
				t++;
			}
		}
		int v = id[h(q)];
		dp[i][v] = max(dp[i][v], dp[i - 1][j] + cnt);
		ans = max(ans, dp[i][v]);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 7484
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main(void)
{
  long long int x[200000], y[200000], distance, number, ans = 0, i;
  
  scanf("%lld%lld", &number, &distance);

  for (i = 0; i < number; i++)
  {
    scanf("%lld%lld", &x[i], &y[i]);

    if ((x[i] * x[i] + y[i] * y[i]) <= distance * distance)
    {
      ans++;
    }
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 4828
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)

int main(){
	int a,b;
	while(cin >> a >> b){
		int c=a+b;
		if(c==0){
			cout << 0 << endl;
			continue;
		}
		int count = 1;
		while(c >= 10){
			c/=10;
			count++;
		}
		cout << count << endl;
	}
	return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

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

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

  int n = s.size();
  for (int begin = 0; begin < n; begin++) {
    for (int end = begin; end <= n; end++) {
      string t = "";
      for (int k = 0; k < n; k++) {
        if (begin <= k && k < end) {
          continue;
        } else {
          t += s[k];
        }
      }
      if (t == "keyence") {
        puts("YES");
        return 0;
      }
    }
  }

  puts("NO");

  return 0;
}

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

using namespace std;

int main(void){
  string s;
  cin >> s;
  bool C = false;
  bool F = false;
  for(int i = 0; i < s.length(); i++){
    if(C) if(s[i] == 'F') F = true;
    else; else if(s[i] == 'C') C = true;
  }
  if(F) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

bool IsPrime(int num, vector<int> list){
  for(int i : list){
    if(num < i)
      return true;
    if(num == i)
      return true;
    if(num % i == 0) 
      return false;
  }
  return true;
}

vector<int> GetInitialPrimeList(int max){
  vector<int> ret;
  ret.push_back(2);
  for(int i = 3; i < max; i+=2){
    if(IsPrime(i, ret))
      ret.push_back(i);
  }
  return ret;
}

int main(){
  ios::sync_with_stdio(false);
  int N, count = 0;
  cin >> N;
  vector<int> primes = GetInitialPrimeList(10000);
  for(int i = 0; i < N; i++){
    int num;
    cin >> num;
    if(IsPrime(num, primes))
      count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1240
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include "fstream"
#include  <unordered_set>
using namespace std;
#define PI acos(-1)
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(int i=0;i<n;i++)
#define loop2(i,n) for(int i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-8
void display(vector<int> v1){loop(i,v1.size()){cout<<v1[i]<<" ";}cout<<endl;}
int dx[8] = {0,1,0,-1,1,1,-1,-1};
int dy[8] = {1,0,-1,0,1,-1,1,-1};
using namespace  std;




set<int>s1;
vector<int>v1;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    map<int , int>m1;
    int ans =0  ;
    for (int i =  0; i<n; i+=1) {
        int x;
        cin>>x;
        v1.pb(x);
        m1[x]+=1;
        s1.insert(x);
    }
    
    ans = s1.size();
    if(ans<k)
    {
        cout<<0;
        return 0;
    }
    int toremove = ans-k;
    v1.clear();
    for (auto itr :m1) {
        v1.push_back(itr.second);
    }
    int diff = ans-k;
    sort(v1.begin(), v1.end());
     ans =0 ;
    for (int i = 0 ; i<diff; i+=1) {
        ans+=v1[i];
    }
    cout<<ans<<endl;
    
    return 0 ;
}


Measured memory_bytes: 19828
# -*- coding: utf-8 -*-
from string import ascii_letters
from collections import defaultdict
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

M = {s:i//13 for i, s in enumerate(ascii_letters)}
D = defaultdict(int)
ans = ""

input()
for s in input():
    D[M[s]] += 1

if D[0] > D[1]:
    ans = "a" * (D[0] - D[1])
else:
    ans = "z" * (D[1] - D[0])

if D[2] > D[3]:
    ans += "A" * (D[2] - D[3])
else:
    ans += "Z" * (D[3] - D[2])

print(len(ans))
print(ans)


Measured memory_bytes: 6788
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#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;
    }
}


Measured memory_bytes: 256
toll[7][7]={
	{0},
	{300},
	{500,350},
	{600,450,250},
	{700,600,400,250},
	{1350,1150,1000,850,600},
	{1650,1500,1350,1300,1150,500}
},
far[7][7]={
	{0},
	{0},
	{0},
	{0},
	{0},
	{1},
	{1,1,1}
},
p1,h1,m1,p2,h2,m2,t,f,d;
main(){
	for(;scanf("%d%d%d%d%d%d",&p1,&h1,&m1,&p2,&h2,&m2),p1;){
		p1--,p2--;
		t=toll[p1>p2?p1:p2][p1>p2?p2:p1];
		f=far[p1>p2?p1:p2][p1>p2?p2:p1];
		m1+=h1*60;
		m2+=h2*60;
		m1=m1>=17*60+30&&m1<=19*60+30;
		m2=m2>=17*60+30&&m2<=19*60+30;
		d=(m1||m2)&&!f;
		printf("%d\n",d?(t/2+49)/50*50:t);
	}
	exit(0);
}

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

int main() {
  long long int N, A, B;
  cin >> N >> A >> B;
  if (N == 1 && A == B) cout << 1 << endl;
  else if (N == 1) cout << 0 << endl;
  else {
    long long int ans = (N - 2) * (B - A) + 1;
    if (ans > 0) cout << ans << endl;
    else cout << 0 << endl;
  }
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
#define ll long long
int n,q,l,r;
ll z,ans;
const ll mod=998244353;
struct madoka{
	int l;
	int r;
	int f;
	ll z;
	ll t;
}ma[2000000];
long long int pow(long long int x,long long int n,long long int mod)
{
    long long int res=1;
	while(n>0)
	{
	   if(n%2==1)
	   {
	   	 res=res*x;
	   	 res=res%mod;
	   }
	   x=x*x;
	   x=x%mod;
	   n>>=1;
	}
	return res;
}
void build(int l,int r,int k){
	ma[k].l=l;
	ma[k].r=r;
	ma[k].f=-1;
	if(l==r){
		ma[k].z=pow(10,n-l,mod);
		ans=(ans+ma[k].z)%mod;
		ma[k].t=1;
		return;
	}
	int mid=(l+r)/2;
	build(l,mid,k*2);
	build(mid+1,r,k*2+1);
	ma[k].z=(ma[k*2].z+ma[k*2+1].z)%mod;
	if(ma[k*2].t==ma[k*2+1].t){
		ma[k].t=ma[k*2].t;
	}
	else ma[k].t=-1;
}
void down(int k){
	if(ma[k].f!=-1&&ma[k].l!=ma[k].r){
		ma[k*2].t=ma[k].f;
		ma[k*2+1].t=ma[k].f;
		ma[k*2].f=ma[k].f;
		ma[k*2+1].f=ma[k].f;
		ma[k].f=-1;
		return;
	}
}
ll qry(int k,int l,int r,ll z){
	down(k);
	if(l<=ma[k].l&&ma[k].r<=r&&ma[k].t!=-1){
		return (z*ma[k].z-ma[k].t*ma[k].z+mod)%mod;
	}
	int mid=(ma[k].l+ma[k].r)/2;
	ll ans1=0,ans2=0;
	if(l<=mid){
		ans1=qry(k*2,l,r,z);
	}
	if(mid<r){
		ans2=qry(k*2+1,l,r,z);
	}
	return (ans1+ans2)%mod;
}
void up(int k,int l,int r,ll z){
	down(k);
	if(l<=ma[k].l&&ma[k].r<=r){
		ma[k].t=z;
		ma[k].f=z;
		return;
	}
	int mid=(ma[k].l+ma[k].r)/2;
	if(l<=mid){
		up(k*2,l,r,z);
	}
	if(mid<r){
		up(k*2+1,l,r,z);
	}
	if(ma[k*2].t==ma[k*2+1].t){
		ma[k].t=ma[k*2].t;
	}
	else ma[k].t=-1;
}
int main(){
	scanf("%d%d",&n,&q);
	build(1,n,1);
	ll now=0;
	while(q--){
		cin>>l>>r>>z;
		now=qry(1,l,r,z);
		ans=(ans+now+mod)%mod;
		printf("%lld\n",ans);
		up(1,l,r,z);
	}
}


Measured memory_bytes: 20116
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

i64 modpow(i64 a, int p = MOD - 2)
{
	if (p == 0) return 1;
	i64 ret = modpow(a, p / 2);
	ret = ret * ret % MOD;
	if (p % 2 == 1) ret = ret * a % MOD;
	return ret;
}

int N, M; i64 X;
int A[2020], B[2020]; i64 W[2020];
vector<pair<i64, pair<int, int>>> edges, mst, red;

int uf[1010];
void clear()
{
	for (int i = 0; i < N; ++i) uf[i] = -1;
}
int root(int p)
{
	return uf[p] < 0 ? p : (uf[p] = root(uf[p]));
}
bool join(int p, int q)
{
	p = root(p); q = root(q);
	if (p == q) return false;
	uf[p] += uf[q];
	uf[q] = p;
	return true;
}

i64 compute_mst()
{
	i64 ret = 0;
	for (int i = 0; i < edges.size(); ++i) {
		int u = edges[i].second.first, v = edges[i].second.second;
		if (join(u, v)) {
			ret += edges[i].first;
		}
	}
	return ret;
}
int main()
{
	scanf("%d%d%lld", &N, &M, &X);
	if (N <= 2) {
		puts("0");
		return 0;
	}
	for (int i = 0; i < M; ++i) {
		scanf("%d%d%d", A + i, B + i, W + i);
		--A[i]; --B[i];

		edges.push_back({ W[i], { A[i], B[i] }});
	}
	clear();
	sort(edges.begin(), edges.end());

	int p = 0;
	i64 mstw = 0;
	while (p < edges.size()) {
		int q = p;
		while (q < edges.size() && edges[p].first == edges[q].first) ++q;

		for (int i = p; i < q; ++i) {
			int u = edges[i].second.first, v = edges[i].second.second;
			if (root(u) == root(v)) red.push_back(edges[i]);
			else mst.push_back(edges[i]);
		}
		for (int i = p; i < q; ++i) {
			int u = edges[i].second.first, v = edges[i].second.second;
			if (join(u, v)) {
				mstw += edges[i].first;
			}
		}

		p = q;
	}

	if (mstw == X) {
		i64 ret = modpow(2, mst.size()) + MOD - 2;
		ret = ret * modpow(2, red.size()) % MOD;
		printf("%lld\n", ret);
		return 0;
	}

	// edges in mst have the same color
	int nle = 0, neq = 0, ngt = 0;
	for (int i = 0; i < red.size(); ++i) {
		clear();
		join(red[i].second.first, red[i].second.second);
		i64 cost = red[i].first + compute_mst();

		if (cost < X) ++nle;
		else if (cost == X) ++neq;
		else ++ngt;
	}

	i64 ret = 2; // black or white
	ret *= modpow(2, neq) + MOD - 1; ret %= MOD;
	ret *= modpow(2, ngt); ret %= MOD;

	printf("%lld\n", ret);

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main() {

	int n;
	scanf("%d", &n);

	int point_taro = 0;
	int point_hanako = 0;

	for (int i = 0; i < n; i++) {
		char taro[101], hanako[101];
		scanf("%s", taro);
		scanf("%s", hanako);

		int flag = strcmp(taro, hanako);
		
		if (flag > 0) {
			point_taro += 3;
		}
		else if (flag < 0) {
			point_hanako += 3;
		}
		else {
			point_taro += 1;
			point_hanako += 1;
		}
	}

	printf("%d %d\n", point_taro, point_hanako);

	return 0;
}

Measured memory_bytes: 1188
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,a = na()

print((h-1)//a+1)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define INF 1e9+5

using namespace std;
using llong = long long;
using VI = vector<int>;
using PII = pair<int, int>;

int n;
vector<vector<int>> hpy(3);
vector<vector<int>> dp(3);

int dfs(int t, int curHpy) 
{
	if (t == n) return 0;
	if (dp[curHpy][t] != -1) return dp[curHpy][t];
	int maxx = -1;
	rep(i, 0, 3)
	{
		if (i == curHpy) continue;
		maxx = max(maxx, dfs(t + 1, i) + hpy[curHpy][t]);
	}
	return dp[curHpy][t] = maxx;
}

int main()
{
	IOS;

	cin >> n;
	rep(i, 0, 3)
	{
		hpy[i].resize(n);
		dp[i].resize(n);
		fill(all(dp[i]), -1);
	}
	rep(i, 0, n)
		cin >> hpy[0][i] >> hpy[1][i] >> hpy[2][i];

	cout << max({ dfs(0,0),  dfs(0, 1), dfs(0,2) });

	return 0;
}



Measured memory_bytes: 13388
from collections import Counter

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

L = []
R = []

for i in range(N):
    L.append(A[i] + i)
    R.append(i - A[i])

L = list(Counter(L).items())
R = dict(list(Counter(R).items()))

ans = 0

for i ,j in L:
    if i in R:
        ans += j * R[i]

print(ans)
    

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

int main() {
  int n;
  cin >> n;
  int w[n];
  int sum[n];
  int sum_before = 0;
  for (int i = 0; i < n; ++i) {
    cin >> w[i];
    sum[i] = sum_before + w[i];
    sum_before = sum[i];
  }
  for (int i = 0; i < n; ++i) {
    if (sum[i] > sum[n - 1] / 2) {
      if (sum[n - 1] / 2 - sum[i - 1] < w[i] / 2) {
        cout << sum[n - 1] - 2 * sum[i - 1] << endl;
      } else { 
        cout << 2 * sum[i] - sum[n - 1] << endl;
      }
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	int n;
	cin>>n;
	int h,m;
	char co;
	for(int i=0;i<n;i++){
		double d=0;
	cin>>h>>co>>m;
		d=double(360)/12*h;
		d+=double(360)/12/60*m;
		d-=double(360)/60*m;
		d=abs(d);
		if(d>180)
			d=360-d;
		if(d>=0&&d<30)
			cout<<"alert"<<endl;
		else if(d>=90&&d<=180)
			cout<<"safe"<<endl;
		else
			cout<<"warning"<<endl;
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAX
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define mod 1000000007
#define ar array
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
int n;
int ans = 0;
void dfs(int x, bool a = 0, bool b = 0, bool c = 0) {
  if (x > n)
    return;
  if (a and b and c)
    ++ans;
  dfs(x * 10 + 7, 1, b, c);
  dfs(x * 10 + 3, a, 1, c);
  dfs(x * 10 + 5, a, b, 1);
}
void init() {
  cin >> n;
  dfs(0);
  cout << ans << endl;
}
int32_t main() {
  IOS;
  init();
  return 0;
}


Measured memory_bytes: 3520
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>
 
using namespace std;
typedef long long int ll;
 
#define C cout<<
#define E <<endl
#define CE cout<<endl
 
ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[1010];
bool r,ra,rb,rc[200010];
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc,vd,ve,vaa,vbb;
set<int> st;
 


template<typename MAIN> ostream & operator<<(ostream & osys,const vector<MAIN> target){ for(MAIN it:target)osys<<it<<" "; return osys; }

int main(){
    cin>>n;
    r=true;
    for(int i=0;i<n;i++){
        cin>>aa[i];

        aa[i]--;
        if(i){
                if(aa[i-1]>aa[i]){
                        aa[i]++;
                }
        }
    }
    for(int i=0;i<n;i++){

        if(i){
                if(aa[i-1]>aa[i]){
                        r=false;
                }
        }
    }


    C (r ? "Yes":"No") E;
    
}

//g++ atcoder.cpp ; ./a.exe


Measured memory_bytes: 2304
#include <stdio.h>
    #include <string.h>

    int main(void)
    {
        int A,B,C,D;
        int x,y;
        scanf("%d %d %d %d",&A,&B,&C,&D);
        x = (A+D-1)/D;
        y = (C+B-1)/B;
        if(x >= y){printf("Yes\n");}
        else{printf("No\n");}
        return 0;
    }

Measured memory_bytes: 1624
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int tmpmin=1e9;
int main(int argc,char const* argv[])
{
  int n;
  string s;
  cin >> n;
  cin >> s;
  int tmpmax=0;
  for(int i=0;i<n;i++)
    {
      set<char> st;
      set<char> tt;
      for(int j=0;j<i;j++)
	{
	  st.insert(s[j]);
	}
      for(int j=i;j<n;j++)
	{
	  tt.insert(s[j]);
	}
      int tmp1=0;
      int tmp2=0;
      for(auto it=st.begin();it!=st.end();it++)
	{
	  if(tt.find(*it)!=tt.end()) tmp1++;
	}
      for(auto it=tt.begin();it!=tt.end();it++)
	{
	  if(st.find(*it)!=st.end()) tmp2++;
	}
      tmp1=max(tmp1,tmp2);
      tmpmax=max(tmpmax,tmp1);
    }
  cout << tmpmax << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int cnt[3] = {};
	REP(i, s.size()){
		cnt[s[i]-'a']++;
	}
	sort(cnt, cnt+3);
	if(cnt[2]-cnt[0] <= 1){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}


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

void test_case(){

}

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

	vector<int> v(n);
	unordered_set<int> s;
	
	for(int i=0;i<n;i++){
		cin >> v[i];
		s.insert(v[i]);
	}

	if(n==0){
		cout << X << endl;
		return 0;
	}

	int mini = *min_element(v.begin(), v.end());
	int maxi = *max_element(v.begin(), v.end());

	int mindif = 99999999;
	int num;

	if(X < mini || X > maxi){
		cout << X << endl;
		return 0;
	}
 
	for(int i = maxi+1 ; i>=mini-1 ; i--){
		if(s.count(i)>0) continue;
		
		if(abs(i-X) <= mindif){
			mindif = abs(i-X);
			num = i;
		}
	}
	
	cout << num << endl;

	return 0;
}

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

int main()
{
	int n, m;
	while (scanf("%d %d", &n, &m), n){
		typedef pair<int, int> P;
		vector<P> v;
		int res = 0;
		for (int i = 0; i < n; i++){
			int a, b;
			scanf("%d %d", &a, &b);
			v.push_back(P(b, a));
			res += a * b;
		}
		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());
		
		int p = 0;
		while (m > 0 && p < n){
			if (v[p].second == 0){
				++p;
				continue;
			}
			int t = min(m, v[p].second);
			res -= v[p].first * t;
			v[p].second -= t;
			m -= t;
		}
		
		printf("%d\n", res);
	}
	
	return 0;
}

Measured memory_bytes: 1320
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {

	public static void main(String[] args) {
		Task task = new Task();
		task.solve();
	}

	public static class Task {
		static final long MOD = (long) 1e9 + 7;

		public void solve() {
			Scan sc = new Scan();
			int n = (int) sc.scanLong();
			int res = 1;
			long[] arr = new long[n];
			for (int i = 0; i < n; ++i) {
				arr[i] = sc.scanLong();
			}
			Arrays.sort(arr);
			for (int i = 0; i < n; ++i)
				if (i > 0)
					arr[i] += arr[i - 1];
			for (int i = n - 2; i >= 0; --i) {
				if (arr[i] * 2 >= (arr[i + 1] - arr[i])) {
					++res;
				} else
					break;
			}
			System.out.println(res);
		}
	}

	public static class Scan {
		private byte[] buf = new byte[1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanLong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public char scanChar() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			return (char) n;
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}


Measured memory_bytes: 36108
#include <iostream>
#include <fstream>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define bit __builtin_popcount
#define all(x) x.begin(),x.end()

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const ll INF=1e18+123;
const ld EPS=1e-9;
const int inf=1e9+123;
const int MOD=1e9+7;
const int N=1e5+123;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    if(a+b==15)cout<<"+";
    else if(a*b==15)cout<<"*";
    else cout<<"x";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;
 
int N,K;
vint g[2020];
int dist[2020];

void dfs(int now,int par,int cost){
    for(auto e:g[now]){
        if(e==par)continue;
        if(dist[e]!=INF)continue;
        dist[e]=cost;
        dfs(e,now,cost+1);
    }
}

signed main() {
    IOS();
    cin>>N>>K;
    rep(i,0,N-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    int ans=INF;
    if(K%2){
        rep(i,0,N){
            for(auto j:g[i]){
                if(i>=j)continue;
                rep(k,0,N){
                    if(k==i||k==j)dist[k]=0;
                    else dist[k]=INF;
                }
                dfs(i,-1,1);
                dfs(j,-1,1);
                int tmp=0;
                rep(k,0,N)if(dist[k]>(K-1)/2)tmp++;
                chmin(ans,tmp);
            }
        }
    }else{
        rep(i,0,N){
            rep(k,0,N){
                if(k==i)dist[k]=0;
                else dist[k]=INF;
            }
            dfs(i,-1,1);
            int tmp=0;
            rep(k,0,N)if(dist[k]>K/2)tmp++;
            chmin(ans,tmp);
        }
    }
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
const int inf = (int) 1e9 + 10;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, n;
  cin >> h >> n;
  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; i++) {
  	cin >> p[i].first >> p[i].second;
	}
	sort(p.begin(), p.end());
	int k = 0;
	vector<int> a, b;
	for (int i = 0; i < n; i++) {
		if (p[i].first == p[i - 1].first && i > 0) {
			++k;
			continue;
		}
		a.push_back(p[i].first);
		b.push_back(p[i].second);
	}
	n -= k;
	vector<int> dp(h + 1, inf);
	dp[0] = 0;
	for (int k = 1; k <= h; k++) {
		for (int i = 0; i < n; i++) {
			int cnt = 1;
			while (true) {
				if (cnt * a[i] > k) {
					dp[k] = min(dp[k], cnt * b[i]);
					break;
				} else {
					dp[k] = min(dp[k], cnt * b[i] + dp[k - cnt * a[i]]);
					++cnt;
				}
			}
		}
	}
	cout << dp[h] << '\n';
  return 0;
}
 




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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int a,b;cin >> a >> b;
   string s;
   cin >> s;
   if(s[a] != '-'){
      cout << "No";
      return 0;
   }
   for(int i=0;i<s.size();i++){
      if(i != a){
         if(isdigit(s[i]) == 0){
            cout << "No";
            return 0;
         }
      }
   }
   cout << "Yes";
   return 0;
}

Measured memory_bytes: 256
# AOJ 0239: Calorie Counting
# Python3 2018.6.25 bal4u
 
while 1:
    n = int(input())
    if n == 0: break
    s, p, q, r = [0]*1002, [0]*1002, [0]*1002, [0]*1002
    for i in range(n):
        s[i], p[i], q[i], r[i] = map(int, input().split())
    P, Q, R, C = map(int, input().split())
    f = False
    for i in range(n):
        c = ((p[i]+r[i]) << 2) + (q[i] << 3) + q[i]
        if p[i] > P or q[i] > Q or r[i] > R or c > C: pass
        else:
            print(s[i])
            f = True
    if not f: print("NA")


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

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a,b,c,k;
	cin >> a >>b>>c>>k;
	if(a >= k){
		cout << k << endl;
	}
	else if(a + b >= k){
		cout << a << endl;
	}
	else {
		cout << a - (k -a-b) << endl;
	}
	return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node {
  int key;
  int priority;
  struct node *right;
  struct node *left;
};

typedef struct node* Nodepointer;
Nodepointer nil=NULL, root=NULL;

Nodepointer delete(Nodepointer*, int);
Nodepointer _delete(Nodepointer*, int);

Nodepointer Node(int key, int priority){
 Nodepointer z;
  z = (Nodepointer)malloc(sizeof(struct node));
  z->key = key;
  z->priority = priority;
  z->left = nil;
  z->right = nil;
  return z;
}

Nodepointer rightRotate(Nodepointer t){
  Nodepointer s = t->left;
  t->left = s->right;
  s->right = t;
  return s;
}

Nodepointer leftRotate(Nodepointer t){
  Nodepointer s = t->right;
  t->right = s->left;
  s->left = t;
  return s;
}

Nodepointer insert(Nodepointer *t, int key, int priority){
  Nodepointer new;
  if( (*t) == nil ) return new = Node(key, priority);
  if( key == (*t)->key ) return *t;

  if( key < (*t)->key ){
    (*t)->left = insert(&(*t)->left, key, priority);
    if( (*t)->priority < (*t)->left->priority ) (*t) = rightRotate((*t));
  }
  else{
    (*t)->right = insert(&(*t)->right, key, priority);
    if( (*t)->priority < (*t)->right->priority ) (*t) = leftRotate((*t));
  }
  return *t;
}


Nodepointer delete(Nodepointer *t, int key){
  if( (*t) == nil ) return nil;
  if( key < (*t)->key ) (*t)->left = delete(&((*t)->left), key);
  else if( key > (*t)->key ) (*t)->right = delete(&((*t)->right), key);
  else {
    return _delete(t, key);
  }
  return *t;
}

Nodepointer _delete(Nodepointer *t, int key){
  if( (*t)->left == nil && (*t)->right == nil ) return nil;
  else if( (*t)->left == nil ) (*t) = leftRotate(*t);
  else if( (*t)->right == nil ) (*t) = rightRotate(*t);
  else {
    if( (*t)->left->priority > (*t)->right->priority ) (*t) = rightRotate(*t);
    else (*t) = leftRotate(*t);
  }
  return delete(t, key);
}


int find(Nodepointer u, int k){
  while( u != nil ){
    if( u->key == k ) return 1;
    else if( k < u->key ) u = u->left;
    else u = u->right;
  }
  return 0;
}

void inorder(Nodepointer u){
  if( u->left != nil ) inorder(u->left);
  printf(" %d", u->key);
  if( u->right != nil ) inorder(u->right);
  return;
}

void preorder(Nodepointer u){
  printf(" %d", u->key);
  if( u->left != nil ) preorder(u->left);
  if( u->right != nil ) preorder(u->right);
  return;
}

void print(Nodepointer u){
  inorder(u);
  printf("\n");
  preorder(u);
  printf("\n");
  return;
}

int main(){
  int m, i, x, y;
  char com[8];
  Nodepointer t=nil;

  scanf("%d", &m);

  for( i = 0 ; i < m ; i++ ){
    scanf("%s",com);

    switch(com[0]){
    case 'f': scanf("%d", &x);
      if( find(root, x)) printf("yes\n");
      else printf("no\n");
      break;

    case 'i':  scanf("%d%d", &x, &y);
      root = insert(&root,x,y);
      break;

    case 'p':  print(root);
      break;

    case 'd': scanf("%d", &x);
      root = delete(&root, x);
      break;
    }
  }
  return 0;
}



Measured memory_bytes: 8052
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline


def main():
    n = input()
    if int(n[0]) == 7 or int(n[1]) == 7 or int(n[2]) == 7:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
#include<bits/stdc++.h>
#define LL long long
#define int long long
inline LL read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	LL k=0,kk=1;if (c=='-')c=getchar(),kk=-1;
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(LL x){if (x<0)x=-x,putchar('-');if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(LL x){write(x);puts("");}
int n,a[1000010],ans;
signed main(){
	n=read();for (int i=1;i<=n;i++)a[i]=read(),ans+=abs(a[i]-a[i-1]);ans+=abs(a[n]-0);
	for (int i=1;i<=n;i++)writeln(ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]));
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    for(int i=0;i<n;i++)cin >> l.at(i);
    sort(l.rbegin(),l.rend());
    int ans =0;
    for(int i=0;i<k;i++){
        ans += l.at(i);
    }
    cout << ans << endl;
}


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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()


int main() {
    int N,M;
    cin >> N >> M;
    vector< vector<int> > s(M);

    for(int i=0;i<M;i++){
        int k;
        cin >> k;
        for(int j=0;j<k;j++){
            int tmp;
            cin >> tmp;
            s[i].push_back(tmp);
        }
    }

    vector<int> p(M);
    for(int i=0;i<M;i++){
        cin >> p[i];
    }
    int ans = 0;

    for(int bit = 0 ; bit<(1<<N);bit++){
        for(int i=0;i<M;i++){
            int onswitch = 0;
            for(int j=0;j<s[i].size();j++){
                if((1<<(s[i][j]-1))&bit)onswitch++;

            }
            if(onswitch%2!=p[i])break;
            if(i==M-1) ans++;
        }
    }

    cout << ans << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long

//#########################################
const int mod = 998244353;
// a^n mod を計算する
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;
}
vector<int> f = {1},fi = {1};
int fact(int x){
    while((int)f.size() <=x)f.push_back((f.back()*f.size())%mod);
    return f[x];
}
int ifact(int x){
    return modpow(fact(x),mod-2,mod);
}
int C(int x,int y){
    if(x < y)return 0;
    return fact(x)*ifact(y)%mod*ifact(x-y)%mod;
}
signed main(){
    int n,m,k;cin >> n >> m >> k;
    int ret = 0;
    for(int i = 0;i <= k;i++){
        int tmp = 1;
        tmp = (tmp*C(n-1,i))%mod;
        tmp = (tmp*modpow(m-1,n-i-1,mod))%mod;
        tmp = (tmp*m)%mod;
        ret = (ret + tmp)%mod;
    }
    cout << ret << endl;
    return 0;
}

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

int main()
{
	int N,Y,x,y,z;
	
	cin>>N>>Y;
	
	for(x=0;x<=Y/10000;x++)
		for(y=0;y<=Y/5000;y++)
		{
			z=N-x-y;
			if(z>=0 && x*10000+y*5000+z*1000==Y)
			{
				cout<<x<<" "<<y<<" "<<z;
				return 0;
			}
		}
		
		cout<<"-1 -1 -1";
		
		return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  int cnt = 0;
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    tmp = a[tmp];
    cnt++;
    if (tmp == 1) {
      cout << cnt << endl;
      return 0;
    }
  }
  cout << - 1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,c,k,t[100000],b=0,p=0,u=0;
    cin>>n>>c>>k;
    for(int i=0;i<n;i++){
        cin>>t[i];
    }
    sort(t,t+n);
    p=c;
    for(int i=0;i<n;i++){
        if(p==c||t[i]>u){
            b++;
            p=1;
            u=t[i]+k;
        }else{
            p++;
        }
    }
    cout<<b<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int a, b; cin >> a >> b;
    int ans = max(a + b, a - b);
    ans = max(ans, a * b);
    cout << ans << endl;
}

Measured memory_bytes: 256
#D 後ろから考えると一意に定まる、つまり答えは常に存在し、ただ一通りしかない。
import sys
n = int(input())
a=list(map(int,input().split()))
b=[0 for i in range(n)] #玉を入れていく配列
for i in range(n-1,-1,-1): #大きい方から見ていく
    limit=n//(i+1) #倍率の限界値
    if limit==1: #限界値が１、つまりその数自身しか参照しない場合
        b[i]=a[i] #玉を入れるかの判断はa[i]にしか依らない
    else:
        modcontainer=0 #剰余の格納容器
        for j in range(limit,0,-1): #倍率も大きい方からチェック
            modcontainer+=b[(i+1)*j-1] #実際に入っているところを参照
            modcontainer%=2
        if modcontainer!=a[i]:
            b[i]=1
print(b.count(1))
if b.count(1)==0:
    sys.exit()
else:
    c=list(enumerate(b))
    d=[str(i+1) for i in range(len(b)) if c[i][1]==1]
    print(" ".join(d))

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


int main() {
    int N, K;
    //配列の初期化
    cin >> N >> K;
    vector<int> H(N);
    rep(i, N) cin >> H.at(i);

    sort(H.begin(), H.end(), greater<int>());
    
    long long count = 0;
    
    if(K >= N){
        cout << count << endl;
    }
    else{
        for(int i = K; i < N; i++){
            count += H.at(i);
        }
        cout << count << endl;
    }


    return 0;
}

Measured memory_bytes: 1024