akhauriyash/Code-Regression huggingface dataset:
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    vi a(n);
    map<int,int> m;
    i64 s0=0;
    forn(i,n){
        cin>>a[i];
        m[a[i]]++;
        s0 += a[i];
    }
    int q;
    cin>>q;
    while(q--){
        int b,c;
        cin>>b>>c;
        if(m.find(b)!=m.end()){
            i64 d = c-b;
            i64 si = s0 + d*m[b];
            m[c] += m[b];
            m[b] = 0;
            s0=si;
            cout<<s0<<endl;
        }
        else{
            cout<<s0<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 7472
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

int dp[201][101];
int T[201];
int A[200];
int B[200];
int C[200];

int main() {
  int d,n;
  while(cin >> d >> n) {
    REP(i,d) cin >> T[i];
    REP(i,n) cin >> A[i] >> B[i] >> C[i];        
    memset(dp,-1,sizeof(dp));
    dp[0][0] = 0;
    REP(i,d) {
      REP(k,101) {
        if (dp[i][k] == -1) continue;      
        REP(j,n) {
          if (A[j]<=T[i] && T[i]<=B[j]) {
            if (i) {
              chmax(dp[i+1][C[j]], dp[i][k] + abs(k-C[j]));
            } else {
              chmax(dp[i+1][C[j]], dp[i][k]);
            }
          }
        }
      }
    }
    int ans = 0;
    REP(i,101) chmax(ans, dp[d][i]);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1252
import java.util.Scanner;

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

		// 標準入力からデータを読み込む準備
		Scanner sc = new Scanner(System.in);

		// 最初の文字の固まりを整数値と想定して読み込む
		while (true) 	{
			int H = sc.nextInt();
			int W= sc.nextInt();
			if (H == 0 && W == 0) {
				break; 
			}
			// 二重ループ(forの中にfor)を書いて、. と # を交互に表示しよう!
			for(int i=1;i<=H;i++){
				for(int j=1;j<=W;j++){
					if(((j%2==0)&&(i%2!=0))||((j%2!=0)&&(i%2==0)))
						System.out.printf(".");
					else
						System.out.printf("#");
				}
				System.out.printf("\n");
			}
			System.out.printf("\n");
		}
	sc.close();
	}

}


Measured memory_bytes: 63876
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define in(j,n) for(j=0;j<n;j++)
#define inp(j,n) for(j=1;j<=n;j++)
#define lo(i,st,n) for(i=st;i<n;i++)
#define pb push_back
#define csbits(n) __builtin_popcount(n)
int main()
{
	ll i,j,n;
	cin>>n;
	ll mi=n-1;
	inp(i,(ll)sqrt(n))
	{
		if(n%i==0)
		{
			ll u=n/i;
			mi=min(mi,i+u-2);
		}
	}
	cout<<mi<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
	ll x;
	cin>>x;
	return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 
 
vector <vector <int> > g;
vector <int> val;
vector <int> a;
 int dfs(vector <bool> &visited,int s);
 vector <int> test;
  vector <int> ans;
  void rerooting(int s,vector <bool> &visited);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector <int> v={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k=nxt();
    cout<<v[k]<<endl;

    return 0;   
}


 
 


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

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

  bool flag = false;
  for(int i=0; i<=x; i++){
    int j = x-i;
    if(2*i + 4*j == y)
      flag = true;
  }
    
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

  

Measured memory_bytes: 3608
#include <stdio.h>

int max(int a, int b) {
  return a > b ? a : b;
}

int main(void) {
  int n, i, j, h;
  scanf("%d%d", &h, &n);
  int a[4][h], dp[6][h];
  for(j = 0; j < h; ++j) {
    for(i = 0; i < 4; ++i) a[i][j] = 1;
    for(i = 0; i < 5; ++i) dp[i][j] = 0;
  }
  for(i = 0; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[x][y] = 0;
  }
  /*for(i = 0; i < h; ++i) {
    for(j = 0; j < 4; ++j) printf("%d",a[j][i]);
    printf("\n");
  }*/
  if(a[0][0] && a[0][1] && a[1][0] && a[1][1]) dp[1][1] = 1;
  if(a[2][0] && a[2][1] && a[1][0] && a[1][1]) dp[2][1] = 1;
  if(a[3][0] && a[3][1] && a[2][0] && a[2][1]) dp[3][1] = 1;
  if(dp[1][1] && dp[3][1]) dp[4][1] = 2;
  else dp[4][1] = max(dp[1][1], max(dp[2][1], dp[3][1]));
  for(i = 2; i < h; ++i) {
    int s = 1;
    dp[0][i] = dp[4][i - 1];
    if(a[0][i - 1] && a[0][i] && a[1][i - 1] && a[1][i]) dp[1][i] = max(dp[3][i - 1] + 1, dp[4][i - 2] + 1);
    else s = 0;
    if(a[2][i - 1] && a[2][i] && a[1][i - 1] && a[1][i]) dp[2][i] = dp[4][i - 2] + 1;
    if(a[3][i - 1] && a[3][i] && a[2][i - 1] && a[2][i]) dp[3][i] = max(dp[1][i - 1] + 1, dp[4][i - 2] + 1);
    else s = 0;
    for(j = 1; j < 4; ++j) if(!dp[j][i]) dp[j][i] = dp[0][i];
    if(s) dp[4][i] = dp[4][i - 2] + 2;
    else dp[4][i] = max(dp[1][i], max(dp[2][i], dp[3][i]));
  }
  /*for(i = 0; i < h; ++i) {
    for(j = 0; j < 5; ++j) printf("%d ", dp[j][i]);
    printf("\n");
  }*/
  printf("%d\n", dp[4][h - 1]);
  return 0;
}


Measured memory_bytes: 3112
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();
            var data = int.Parse(line);
            int result = CalcUresisa(data);
            Console.WriteLine(result);
#if false
            Console.ReadLine();
#endif
        }

        private static int CalcUresisa(int data)
        {
            int result = 0;
            while (data >= 500)
            {
                result += 1000;
                data -= 500;
            }

            while (data >= 5)
            {
                result += 5;
                data -= 5;
            }

            return result;
        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	while(true) {
    		int H = sc.nextInt();
    		int W = sc.nextInt();
    		if(H == 0 && W == 0) {
    			break;
    		}
    		for(int h = 0; h < H; h ++) {
    			for(int w = 0; w < W; w ++) {
    				if(w == 0 || w == W - 1 || h == 0 || h == H - 1) {
    					System.out.print("#");
    				}
    				else {
    					System.out.print(".");
    				}
    			}
    			System.out.println("");
    		}
    		System.out.println("");
    	}
    }
}


Measured memory_bytes: 32240
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
int bsr(int x) { return 31 - __builtin_clz(x); }

string S = "FESTIVAL";
const int BS = 9;
const int BN = 1<<BS;

ll calc(string s) {
    ll d[9] = {};
    d[0] = 1;
    for (char c: s) {
        int p = -1;
        for (int i = 0; i < 8; i++) {
            if (c == S[i]) {
                p = i;
                break;
            }
        }
        if (p == -1) continue;
        d[p+1] += d[p];
//        for (int i = 0; i <= 8; i++) {
//            cout << d[i] << ", ";
//        } cout << endl;
    }
    return d[8];
}
int main() {
    ios::sync_with_stdio(0);
    cout << setprecision(20);
    ll k;
    cin >> k;

    string s = "FESTIVA";
    // 1,1,1...1

    ll sm = 0;
    for (int i = 0; i < 7; i++) {
        ll u = k % BN; k /= BN;
//        s += string(u, S[7]); // use
        if (u % 2) {
            s += S[7];
        }
        u /= 2;
        //x256
//        if (i == 6) break;
        for (int fe = 0; fe < BS; fe++) {
            for (int j = 6; j >= i+1; j--) {
                s += S[j];
            }
            ll c = 1<<(fe+1);
            c -= 1<<fe;
            s += string(c, S[i]);
            if (u % 2) {
                s += S[7];
            }
            u /= 2;
        }
//        cout << u << endl;
    }
//    cout << sm << endl;
    assert(s.size() <= 5000);
//    cout << s.size() << endl;
    cout << s << endl;
//    cout << calc(s) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define ll long long int
#define ld long double
#define pi acos(-1)
#define pb push_back
using namespace std;

int main()
{
    ll i,j,a,k,b,c,n,t,m,p,q,d,e,f,y,g,z,h,r,l,x;
    ld aa,bb,ee,dd,ff,kk,gg;
    
    ios_base::sync_with_stdio(false);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

        cin>>n;
        if(n>=30)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
}

Measured memory_bytes: 3644
#include <stdio.h>

void swap(int *a,int *b){
	int temp=*a;
	*a=*b;
	*b=temp;
}
int main(){
	int A,B,C;
	
	scanf("%d%d%d",&A,&B,&C);
	swap(&A,&B);
	swap(&A,&C);
	printf("%d %d %d\n",A,B,C);
	return 0;
}

Measured memory_bytes: 128
local n, l = io.read("*n", "*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local pos = 0
for i = 1, n - 1 do
  if l <= a[i] + a[i + 1] then
    pos = i
    break
  end
end
if pos == 0 then
  print("Impossible")
else
  print("Possible")
  for i = 1, pos - 1 do
    print(i)
  end
  for i = n - 1, pos + 1, -1 do
    print(i)
  end
  print(pos)
end


Measured memory_bytes: 8568
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
using namespace std;
double h_len,m_len,h,m;
int main()
{
    while(cin>>h_len>>m_len>>h>>m)
    {
        double theta = abs(30*h-5.5*m);
        theta = theta*(pi/180);
        //cout<<theta<<'\n';
        double part_1 = pow(h_len,2);
        //cout<<part_1<<'\n';
        double part_2 = pow(m_len,2);
        //cout<<part_2<<'\n';
        double part_3 = cos(theta);
        //cout<<part_3<<'\n';
        double part_4 = 2*h_len*m_len*part_3;
        //cout<<part_4<<'\n';
        double ans = sqrt(part_1+part_2-part_4);
        cout<<fixed<<setprecision(20)<<ans<<'\n';
    }
}


Measured memory_bytes: 4160
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#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>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,a[3005],ans[3005],k;
vector<int> v[3005];
int dfs(int x,int y){
    for(int i=0;i<v[x].size();++i)if(v[x][i]!=y&&a[v[x][i]]<a[x]&&!dfs(v[x][i],x)) return 1;
    return 0;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",a+i);
    for(int i=1;i<n;++i){
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].pb(y),v[y].pb(x);
    }
    for(int i=1;i<=n;++i)if(dfs(i,0))ans[++k]=i;
    for(int i=1;i<k;++i)printf("%d ",ans[i]);
    if(k)printf("%d\n",ans[k]);
    //system("pause");
    return 0;
}


Measured memory_bytes: 384
def F(x):
    return x[0:len(x)//2] == x[::-1][0:len(x)//2]

s = input()
n = len(s)
sf = s[0:(n-1)//2]
sb = s[(n+3)//2-1:]
if F(sf) and F(sb) and F(s):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    // Your code here!
    int i, j, k, l, n;
    int data[4][3][10] = {{{0}}};
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        int b, f, r, v;
        scanf("%d %d %d %d", &b, &f, &r, &v);
        data[b-1][f-1][r-1] += v;
    }
    for(j=0; j<4; j++){
        for(k=0; k<3; k++){
            for(l=0; l<10; l++){
                printf(" %d", data[j][k][l]);
            }
            printf("\n");
        }
        if(j==3)break;
        printf("####################\n");
    }
    return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll a, b, c;
    cin >> a >> b >> c;

    if(a+b+c >= 22) cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
}

Measured memory_bytes: 256
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print('F')
    elif (m + f) >= 80:
        print('A')
    elif 65 <= (m + f) < 80:
        print('B')
    elif 50 <= (m + f) < 65:
        print('C')
    elif 30 <= (m + f) < 50:
        if r >= 50:
            print('C')
        else:
            print('D')
    elif (m + f) < 30:
        print('F')



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define N 666666
int n;
vector<pair<int,int> > v[N],ans;
map<int,int> mp;
void dfs(int node,int fa){
	for(int i=0;i<v[node].size();i++){
		
		int to=v[node][i].first;
		int w=v[node][i].second;
		if(to==fa) continue;
		if(mp[node]==1){
			if(w%2){
				mp[to]=-1;
			}else{
				mp[to]=1;
			}
		}else{
			if(w%2==0){
				mp[to]=-1;
			}else{
				mp[to]=1;
			}
		}
		dfs(to,node);
	}
}
signed main(){
	cin>>n;
	for(int i=1;i<n;i++){
		int a,b,c;
		cin>>a>>b>>c;
		v[a].push_back(make_pair(b,c));
		v[b].push_back(make_pair(a,c));
	}
	mp[1]=1;
	dfs(1,0);
	for(int i=1;i<=n;i++){
		if(mp[i]==-1) cout<<"0"<<'\n';
		else cout<<"1"<<'\n';
	}
	return 0;
} 

Measured memory_bytes: 30848
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

int main() {
    int N; cin >> N;
    vl A(N); rep(i, N) cin >> A[i];

    map<int, ll> G;
    rep(i, N) G[A[i]]++;

    ll sum = 0;
    map<int, ll> G2;
    for (auto x : G) {
        ll y = x.second * (x.second - 1) / 2;
        G2[x.first] = y;
        sum += y;
    }

    rep(i, N) {
        ll res = sum;
        ll x = G2[A[i]];
        res -= x;

        ll y = G[A[i]];
        y--;
        res += y * (y - 1) / 2;
        
        cout << res << endl;
    }
}


Measured memory_bytes: 20644
#include <stdio.h>

#define MAX 10000
#define NIL -1

typedef struct { int parent, left, right;} Node;

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d) {
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL)
    h1 = setHeight(T[u].left) + 1;
  if(T[u].right != NIL)
    h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

// 接点 u の兄弟を返す
int getSibling(int u) {
  if( T[u].parent == NIL ) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].left  != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
  
  if(T[u].parent == NIL) {
    printf("root\n");
  } else if(T[u].left == NIL && T[u].right == NIL) {
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

int main(void) {
  int v, l, r, root = 0;
  scanf("%d",&n);
  for(int i=0;i<n;i++) T[i].parent = NIL;
  for(int i=0;i<n;i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].left  = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }
  
  for(int i=0; i<n; i++)
  if(T[i].parent == NIL) root = i;
  
  setDepth(root,0);
  setHeight(root);
  
  for(int i=0;i<n;i++) print(i);
  
  return 0;
}


Measured memory_bytes: 1988
#include <iostream>
#include <cmath>

long long gcd(long long m, long long n) {
  if (n==0) return std::abs(m);
  else return gcd(n, m % n);
}

bool solv(long long init,
          long long buy,
          long long check,
          long long reload) {
  if (init < buy) return false;
  if (reload < buy) return false;

  auto a = init % buy;
  if (check < a) return false;
  if (reload % buy == 0) return true;

  auto g = gcd(buy, reload);
  auto m = (check + 1 - a) / g;
  m += ((check + 1 - a) % g) == 0 ? 0 : 1;

  if (a + m * g < buy) return false;

  return true;
}

int main() {
  size_t N;

  std::cin >> N;

  for (size_t i=0; i<N; i++) {
    long long init;
    long long buy;
    long long check;
    long long reload;

    std::cin >> init;
    std::cin >> buy;
    std::cin >> check;
    std::cin >> reload;

    std::cout << (solv(init, buy, check, reload) ? "Yes" : "No")
              << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    string s;cin >>s;
    char ans='1';
    int n=s.size();
    for (char i ='a'; i <='z'; ++i) {
        bool flg=false;
        for (int j = 0; j < n; ++j) {
            if(i==s[j]){
                flg=true;
            }
        }
        if(!flg){
            ans=i;
            break;
        }
    }
    if(ans=='1')puts("None");
    else cout <<ans <<endl;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define INF 1e9
#define int long long
#define Rep(i, n, a) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, n, 0)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, m;
    cin >> n >> m;
    vector<int> cnt(n);
    vector<bool> f(n);
    rep(i, n)
    {
        cnt[i] = 1;
        f[i] = false;
    }
    f[0] = true;
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        cnt[a]--;
        cnt[b]++;
        if (f[a])
        {
            if (cnt[a] == 0)
            {
                f[a] = false;
                f[b] = true;
            }
            else
            {
                f[b] = true;
            }
        }
    }
    int ans = 0;
    rep(i, n) if (f[i]) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
vector<string> ans;
string a3[3] = {
	"aa.",
	"..a",
	"..a"
};
string a4[4] = {
	"aacd",
	"bbcd",
	"cdaa",
	"cdbb"
};
string a5[5] = {
	"aacca",
	"bbd.a",
	"c.dcc",
	"c..bd",
	".aabd"
};
string a6[6] = {
	"abcc..",
	"abdd..",
	"..abcc",
	"..abdd",
	"cc..ab",
	"dd..ab"
};
string a7[7] = {
	"aa.cd..",
	"bb.cd..",
	"c....cd",
	"c....cd",
	"..aacaa",
	"..bbc.b",
	".cc.ddb"
};
void solve(int n){
	if(n >= 8){
		n -= 4;
		for(int i=0;i<4;i++) for(int j=0;j<4;j++) ans[n+i][n+j] = a4[i][j];
		solve(n);
	}
	else{
		if(n == 4) for(int i=0;i<4;i++) for(int j=0;j<4;j++) ans[i][j] = a4[i][j];
		else if(n == 5) for(int i=0;i<5;i++) for(int j=0;j<5;j++) ans[i][j] = a5[i][j];
		else if(n == 6) for(int i=0;i<6;i++) for(int j=0;j<6;j++) ans[i][j] = a6[i][j];
		else for(int i=0;i<7;i++) for(int j=0;j<7;j++) ans[i][j] = a7[i][j];
	}
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ans.resize(n, "");
    for(int i=0;i<n;i++){
    	for(int j=0;j<n;j++){
    		ans[i] += ".";
    	}
    }
    if(n == 2){
    	cout << -1 << endl;
    	return 0;
    }
    if(n == 3){
    	for(int i=0;i<3;i++) cout << a3[i] << endl;
    	return 0;
    }
    solve(n);
    for(int i=0;i<n;i++){
    	cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define scan(a,n) for(long long int index=0;index<n;index++) cin>>a[index];
#define print(a,n) for(long long int index=0;index<n;index++) cout<<a[index]<<" ";cout<<endl;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define vli vector<long long int>
#define vlli vector<pair<long long int,long long int>>
#define vsi vector<string>
#define vci vector<char>
#define all(n) n.begin(),n.end()
#define forr(i,a,b) for(i=a;i<b;i++)
#define forrr(i,a,b) for(i=b-1;i>=a;i--)


 
int main() {
   #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ll t;
    t=1;
    while(t--){
      ll n;
      cin>>n;
      ll x,y,i,f=0,sum=0;
      for(i=0;i<n;i++){
        cin>>x>>y;
        if(x==y) sum++;
        else sum=0;
        if(sum>=3) f=1;
      }
      cout<<(f?"Yes":"No")<<endl;

        }
   
return 0;    
 }  

Measured memory_bytes: 3632
n = int(input())
 
g = [[-1 for j in range(n)] for i in range(n)]
 
for i in range(n):
	a = int(input())
	for _ in range(a):
		x, y = map(int, input().split())
		g[i][x-1] = y
 
ans = 0
for s in range(2**n):
    ok = True
    for i in range(n):
        if (s>>i&1) == 1:
            for j in range(n):
                if g[i][j] == -1: continue
                if (s>>j&1) != g[i][j]: ok = False
    if ok:#あっているなら、ビット内に何個1があるかを数える
        #print("s = ", s)
        t = 0
        x = s#xを変えてもsは変化しない
        t = str(bin(x)).count("1")
        ans = max(ans, t)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int a;
	cin >> a;
	char s[100], t[100];
	
	for (int i = 0; i < a; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < a; i++) {
		cin >> t[i];
	}
	for (int i = 0; i < a; i++) {
		cout << s[i] << t[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define read(a) scanf("%d", &a)
#define readf(a) scanf("%lf", &a)
#define pb push_back
#define mk make_pair
#define _rand mt19937 RAND(time(0))
#define mem(a) memset(a, 0, sizeof(a))
#define Buff ios::sync_with_stdio(false)
typedef long long ll;
using namespace std;
const int INF = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 1e6 + 7;
//const ll mod = 998224353;
const ll mod = 998244353;

ll sum[N << 2], power[N << 2], pow10[N];
int color[N << 2];

#define lson rt << 1
#define rson rt << 1 | 1
#define ls lson, l, mid
#define rs rson, mid + 1, r

void pushUp(int rt)
{
    sum[rt] = (sum[lson] + sum[rson]) % mod;
    if(color[lson] != color[rson]) color[rt] = -1;
    else color[rt] = color[lson];
}

void build(int rt, int l, int r)
{
    if(l == r)
    {
        color[rt] = 1;
        sum[rt] = 1;
        power[rt] = pow10[l];
        return;
    }
    int mid = l + r >> 1;
    build(ls); build(rs);
    pushUp(rt);
    power[rt] = (power[lson] + power[rson]) % mod;
}

void pushDown(int rt)
{
    if(color[rt] == -1) return;
    color[lson] = color[rson] = color[rt];
    sum[lson] = power[lson] * (ll)color[rt] % mod;
    sum[rson] = power[rson] * (ll)color[rt] % mod;
    color[rt] = -1;
}

void update(int rt, int l, int r, int L, int R, int x)
{
    if(L <= l && r <= R)
    {
//        printf("power[%d] = %lld\n", rt, power[rt]);
        sum[rt] = power[rt] * (ll)x % mod;
        color[rt] = x;
        return;
    }
    pushDown(rt);
    int mid = l + r >> 1;
    if(L <= mid) update(ls, L, R, x);
    if(R > mid) update(rs, L, R, x);
    pushUp(rt);
}
signed main()
{
//    freopen("rand.txt", "r", stdin);
//    freopen("my.txt", "w", stdout);
    Buff;
    int n, q;
    cin >> n >> q;
    pow10[n] = 1ll;
    for(int i = n-1; i; i--) pow10[i] = pow10[i + 1] * 10ll % mod;
    build(1, 1, n);
    int Case = 0;
    while(q--)
    {
        int l, r, x;
        cin >> l >> r >> x;
        update(1, 1, n, l, r, x);
//        cout << "Case " << ++Case << ": ";
        cout << sum[1] << "\n";
    }
    return 0;
}
/**
**/


Measured memory_bytes: 15460
#include<iostream>

int main() 
{

	char c;
	std::cin >> c;
	if (c == 'a') {
		std::cout << "vowel" << std::endl;
	}
	else if (c == 'e') {
		std::cout << "vowel" << std::endl;
	}
	else if (c == 'i') {
		std::cout << "vowel" << std::endl;
	}
	else if (c == 'o') {
		std::cout << "vowel" << std::endl;
	}
	else if (c == 'u') {
		std::cout << "vowel" << std::endl;
	}
	else {
		std::cout << "consonant" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N=int(input())
#N=10**18

lst=defaultdict(int)
lst2=[]
lst3=[]
for i in range(2,int(N**.5)+100):
    if N%i==0:
        lst2.append(i)
        lst3.append(N//i)
lst3.reverse()
lst2+=lst3

for i in lst2+[N]:
    while N>1 and N%i==0:
        N//=i
        lst[i]+=1
c=0
#print(lst)
for s in lst:
    l=lst[s]
    i=1
    while l>=i:
        l-=i
        c+=1
        i+=1
print(c)


Measured memory_bytes: 73560
#include<stdio.h>
 
int main(){
    int x, y, min, max, rem;
 
    scanf("%d %d", &x, &y);
 
    if(x == y){
        printf("%d\n", x);
        return 0;
    }
 
    if(x < y){
        min = x;
        max = y;
    }else{
        min = y;
        max = x;
    }
 
    while(min > 0){
        rem = max%min;
        max = min;
        min = rem;
    }
 
    printf("%d\n", max);
 
    return 0;
}

Measured memory_bytes: 592
/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 21-Jul-2018 18:01:06
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;

int a[4];

int solve() {
    cin >> a[1] >> a[2] >> a[3];
    vector <int> v = {1, 2, 3};

    int res = inf;
    do {
        int tmp = abs(a[v[1]] - a[v[0]]) + abs(a[v[1]] - a[v[2]]);
        umin(res, tmp);
    } while (next_permutation(all(v)));

    cout << res << endl;

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0; //Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
const int N=500005;
int n,k;
int tot;
struct tre{
	int ls,rs;
}t[N*14];
int rt[N];
int p,a[N],b[N];
struct edge{
	int r,next;
}e[N*41];
int rd[N*14],h[N*14],st,cd[N*14];
void add(int x,int y){
	rd[y]++;cd[x]++;
	e[++st].next=h[x];h[x]=st;e[st].r=y;
}
int tt,val[N];
void hins(int x){
	val[++tt]=x;int k;
	for(int i=tt;a[val[i]]<a[val[i>>1]]&&(i>>1);k=val[i],val[i]=val[i>>1],val[i>>1]=k,i>>=1);
}
void hdel(){
	val[1]=val[tt--];
	int k;
	for(int i=1;(i<<1)<=tt;){
		int mn=i<<1;
		if((i<<1|1)<=tt){
			if(a[val[i<<1|1]]<=a[val[mn]])mn=i<<1|1;
		}
		if(a[val[mn]]<a[val[i]])k=val[mn],val[mn]=val[i],val[i]=k,i=mn;
		else break;
	}
}
void connect(int l,int r,int now,int ml,int mr,int k){
	if(!now)return;
	if(ml==l&&mr==r){
		add(now,k);
		return;
	}
	int mid=l+r>>1;
	if(ml>mid)connect(mid+1,r,t[now].rs,ml,mr,k);
	else if(mr<=mid)connect(l,mid,t[now].ls,ml,mr,k);
	else connect(l,mid,t[now].ls,ml,mid,k),connect(mid+1,r,t[now].rs,mid+1,mr,k);
}
void ins(int l,int r,int &now,int las,int pos,int k){
	if(cd[las]){
		now=++tot;
		t[now]=t[las];
	}
	else now=las;
	add(k,now);
	if(l==r)return;
	int mid=l+r>>1;
	if(mid>=pos)ins(l,mid,t[now].ls,t[las].ls,pos,k);
	else ins(mid+1,r,t[now].rs,t[las].rs,pos,k);
}
int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x;
}
int stpd[N*14],cnmd;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		p=read();
		a[p]=i;
	}
	tot=n;cd[0]=1;
	for(int i=1;i<=n;i++){
		connect(1,n,rt[i-1],a[i],min(a[i]+k-1,n),i);
		ins(1,n,rt[i],rt[i-1],a[i],i);
	}
	for(int i=1;i<=n;i++){
		if(!rd[i])hins(i);
	}
	for(int i=1;i<=n;i++){
		int x=val[1];
		while(x>n){
			hdel();
			for(int i=h[x];i;i=e[i].next){
				if(!(--rd[e[i].r])){
					if(e[i].r<=n)hins(e[i].r);
					else stpd[++cnmd]=e[i].r; 
				}
			}
			while(cnmd){
				x=stpd[cnmd--];
				for(int i=h[x];i;i=e[i].next){
					if(!(--rd[e[i].r])){
						if(e[i].r<=n)hins(e[i].r);
						else stpd[++cnmd]=e[i].r; 
					}
				}
			}
			x=val[1];
		}
		b[i]=a[x];
		hdel();
		for(int i=h[x];i;i=e[i].next){
			if(!(--rd[e[i].r])){
				if(e[i].r<=n)hins(e[i].r);
				else stpd[++cnmd]=e[i].r; 
			}
		}
		while(cnmd){
			x=stpd[cnmd--];
			for(int i=h[x];i;i=e[i].next){
				if(!(--rd[e[i].r])){
					if(e[i].r<=n)hins(e[i].r);
					else stpd[++cnmd]=e[i].r; 
				}
			}
		}
	}
	for(int i=1;i<=n;i++)a[i]=0;
	for(int i=1;i<=n;i++)a[b[i]]=i;
	for(int i=1;i<=n;i++)printf("%d\n",a[i]);
} 


Measured memory_bytes: 241152
N=int(input())
T, A=map(int, input().split())
H=list(map(int,input().split()))
diffmin=10**9
for i in range(N):
  Ti = T-0.006*H[i]
  diff = abs(A-Ti)
  if diff<diffmin:
    diffmin=diff
    ans=i+1
    
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
 
int main(){
  char s[4];
  int i,j,count;
  count=0;
  scanf("%s",&s);
  for(i=0;i<4;i++){
    for(j=0;j<4;j++){
      if(s[i]==s[j]) count++;
    }
  }
  if(count==8) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#                         author:  kagemeka 
#                         created: 2019-11-08 02:12:52(JST)
## internal modules
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version) 

def main():
    n = int(sys.stdin.readline().rstrip())
    if n < 1000:
        ans = 'ABC'
    else:
        ans = 'ABD'
    
    print(ans)



if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 3316
import itertools
import fractions
def main():
  b = input()
  if b == 'A':
    print('T')
  elif b == 'T':
    print('A')
  elif b == 'G':
    print('C')
  elif b == 'C':
    print('G')
if __name__ == '__main__':
  main()

Measured memory_bytes: 5048
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

D = [ai - bi for ai, bi in zip(A, B)]
M = [di for di in D if di < 0]
P = [di for di in D if di > 0]

sum_m = sum(M)
if sum_m == 0:
    print(0)
    exit()

P.sort(reverse=True)
for i, pi in enumerate(P):
    sum_m += pi
    if sum_m >= 0:
        print(len(M) + i + 1)
        exit()
print(-1)


Measured memory_bytes: 19068
a, b, c, d = map(int, input().split())
if a <= c <= b <= d:
	print(b - c)
elif c <= a <= d <= b:
	print(d - a)
elif a <= c <= d <= b:
	print(d - c)
elif c <= a <= b <= d:
	print(b - a)
else:
	print(0)


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

int main() {
	int A,B,sum = 0;
	cin >> A >> B;
	vector<int> remList;
	for (int i = A; i <= B; i++)
	{
		int j = i;
		while (j)
		{
			remList.emplace_back(j % 10);
			j /= 10;
		}
		if (remList[0] == remList[4] && remList[1] == remList[3])
		{
			sum++;
		}
		remList.clear();
	}
	cout << sum << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

vector<ll> inv,fact,invfact;
void mod_build(int n=101010){
    fact.resize(n+1);
    inv.resize(n+1);
    invfact.resize(n+1);
    fact[0]=inv[0]=invfact[0]=1;
    inv[1]=1;
    rep(i,n){
        fact[i+1]=fact[i]*(i+1)%mod;
        if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
}
ll perm(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll pow(ll n,ll k){
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

bool used[2][1234567];
int main(){
    int n,m;
    cin>>n>>m;
    pint a[n+m];
    rep(i,n){
        cin>>a[i].first;
        a[i].second=0;
    }
    rep(i,m){
        cin>>a[i+n].first;
        a[i+n].second=1;
    }
    sort(a,a+n+m);
    int cnt=0,cnt0=0,cnt1=0;
    int sum=n*m;
    mod_build(1010101);
    ll ans=1;
    rep(i,n+m-1){
        int x=a[i].first,y=a[i].second;
        if(used[y][x]){
            cout<<0<<endl;
            return 0;
        }
        used[y][x]=true;
        if(y==0&&i+1<n+m&&a[i].first==a[i+1].first){
            ans*=perm(x-1-cnt,m-1-cnt1);
            ans%=mod;
            cnt+=m-cnt1;
            ++cnt0;
        }
        else if(y==0){
            ans*=comb(x-1-cnt,m-1-cnt1);
            ans%=mod;
            ans=ans*fact[m-cnt1]%mod;
            cnt+=m-cnt1;
            ++cnt0;
        }
        else if(y==1&&i>0&&a[i].first==a[i-1].first){
            ans*=perm(x-cnt,n-cnt0);
            ans%=mod;
            cnt+=n-cnt0;
            ++cnt1;
        }
        else if(y==1){
            ans*=comb(x-1-cnt,n-1-cnt0);
            ans%=mod;
            ans=ans*fact[n-cnt0]%mod;
            cnt+=n-cnt0;
            ++cnt1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 23936
import heapq
N = int(input())
v_list = list(map(int, input().split()))

v_list.sort()

heapq.heapify(v_list)

while len(v_list) > 1:
    a = heapq.heappop(v_list)
    b = heapq.heappop(v_list)
    heapq.heappush(v_list, (a+b)/2)
print(heapq.heappop(v_list))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;

using namespace std;
const int maxn=2e5+100;
int n,t;
int k,p[5555],vis[5050],f[5055];
ll c[5555];
ll dp[5505];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    ll ans=0;
    rep(i,1,n)cin>>p[i];
    rep(i,1,n)cin>>c[i];
    vector<pair<int,int> >v;
    rep(i,1,n){
        if(!vis[i]){
            int to=i;ll tot=0;int cnt=0;
            while(!vis[to]){
                vis[to]=1;
                ++cnt;
                tot+=c[p[to]];
                to=p[to];
                f[to]=i;
            }
            v.push_back(make_pair(cnt,(tot)));
            ll k1=k%cnt,k2=k/cnt,t1=0;
            if(k-k%cnt>cnt){
                k1=(k-k%cnt-cnt)/cnt;
                k2=cnt+k%cnt;
            }
            else {
                k1=0,k2=k;
            }
            if(tot>0)t1=k1*tot;
		
            vector<int>vv;
            vector<ll>ss;
            int aa=i,bb=p[i];vv.push_back(aa);
            while(bb!=aa){
                vv.push_back(bb);
                bb=p[bb];
            }
            int q=2*vv.size(),st=0,ct=0;
            while(ct<=q){
            	vv.push_back(vv[st++]);++ct;
			}
//			tmp(cnt);
//			tmp(k2);
//			for(auto pp:vv)cout<<pp<<' ';
//			cout<<endl<<endl;
            ll sum=0;ss.push_back(0);
            for(int j=0;j<vv.size()-1;++j){
                sum+=c[vv[j]];
                ss.push_back(sum);
            }
//            tmp(t1);
//            tmp(ss.size());
            ll mx=-1e18;int del=0;
            rep(j,0,ss.size()-1){
                rep(u,j+1,ss.size()-1){
//                	tmp(ss[u]-ss[j]);
                    if((mx<ss[u]-ss[j]&&u-j<=k2))mx=ss[u]-ss[j];
                }
            }
//            tmp(22222);
//            tmp(mx);tmp(mx+t1);tmp(2222);
            t1+=mx;
            
            


            if(i!=1)ans=max(ans,t1);
            else ans=t1;
//            tmp(ans);
        }
    }
    cout<<ans;

    return 0;
}

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

using namespace std;
#define int long long


signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<pair<int,int> > v;
    for(int i = 1; i <= n; i ++) {
        int x , l;
        cin >> x >> l;
        v.push_back({x+l , x-l});
    }
    sort(v.begin() , v.end());
    int cnt = 1 , last = v[0].first;
    for(int i = 1; i < n; i ++) {
        if(v[i].second >= last) {
            cnt ++;
            last = v[i].first;
        }
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 3444
package main

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

func max(a, b uint) uint {
	if a >= b { return a}
	return b
}

func main(){
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var H, W int
	fmt.Fscan(r, &H, &W)
	grid := make([]string, H)
	for i := 0; i < H; i++ { fmt.Fscan(r, &grid[i]) }

	dx := []int{0,0,1,-1,1,-1,1,-1}
	dy := []int{1,-1,1,-1,0,1,-1,0}
	for h := 0; h < H; h++ {
		for v := 0; v < W; v++ {
			cnt := 0
			if grid[h][v] == '#' { continue }
			for i := 0; i < 8; i++ {
				nv, nh := v + dx[i], h+dy[i]
				if nv < 0 || nv >= W || nh < 0 || nh >= H { continue }
				if grid[nh][nv] == '#' { cnt++ }
			}
			grid[h] = strings.Replace(grid[h], ".", strconv.Itoa(cnt), 1)
		}
	}

	for _, s := range grid {
		fmt.Fprintln(w, s)
	}
}

Measured memory_bytes: 896
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        
        int N = Integer.parseInt(line[0]);
        int M = Integer.parseInt(line[1]);
        
        int[] array = new int[N+1];

        for(int i = 0;i < M;i++){

            String[] input = sc.nextLine().split(" ");
            
            int a = Integer.parseInt(input[0]);
            int b = Integer.parseInt(input[1]);

            array[a]++;
            array[b]++;
        }

        for(int i = 1;i <= N;i++){
            System.out.println(array[i]);
        }

    }
       
}


Measured memory_bytes: 21716
#include <iostream>
#define N_MAX 100
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int K,N,A,B,i,j,k;
string S,Sa;
int x[N_MAX];
int y[N_MAX];
int num[N_MAX] = {0};
double ans=0;

int main(){
  cin >> N >> K;
  for (i=0;i<N;i++) cin >> x[i];
  sort(x, x + N, greater<int>());
  for (i=0;i<K;i++) ans+=x[i];
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//N枚のカードが伏せられている
//Aには1か2が書かれている
//i番目に伏せられているカードをA[i]とする

// 以下の情報がM個与えられる
// A[Xi] + A[Yi] + Ziは偶数である

//Mの情報を使用しても特定できないカードは何個あるか
//(一つわかれば片方は自明、などもあるかもしれないことに注意する)

//Aの情報をまとめたい
//i 番目は i+1番目の反対、など
//UnionFindでいいのでは??

struct UnionFind {

    vector <ll> par;
    
    // new
    UnionFind(ll n):par(n, -1){}

    //初期化
    void init(ll n){par.assign(n, -1); } 


    ll root(ll x)
    {
        if(par[x] < 0)return x;
        else return par[x] = root(par[x]);//親の番号を返す(親が子になっていたら困るので取り込まれてたら代入も行う)
    }

    //同じグループに属するか
    bool issame(ll x, ll y)
    {
        //rootが同じであるか
        return root(x) == root(y);
    }

    //併合
    bool merge(ll x, ll y)
    {

        x = root(x);
        y = root(y);
        if(x == y)return false;
        if(par[x] > par[y])swap(x, y);
        //多い方に足し合わせる
        par[x] += par[y];
        //従属(ここで0以上となる)
        par[y] = x;
        return true;
    }

    ll size(ll x)
    {
        return -par[root(x)];
    }

};

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

    UnionFind uf(N);

    int res = N;
    REP(i,M)
    {
        int x,y,z;
        cin >> x >> y >> z;
        --x;
        --y;
        //同じグループに属するか
        if(uf.issame(x,y))continue;

        //サイズ取得
        int sx = uf.size(x);
        int sy = uf.size(y);
        //xとyは一致
        uf.merge(x,y);
        --res;
        //cout << x + 1 << " " << y + 1 << endl;

    }
    cout << res << endl;

    return 0;    
}



Measured memory_bytes: 1024
N = int(input())
ans=0
result = 0
for i in range(N):
  a,b = map(int,input().split())
  if a == b:
    ans += 1
    if ans >= 3:
      result += 1
  else:
    ans = 0
if result >=1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define pb push_back
#define pll pair<long long, long long>
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll dx[] = {1,-1,0,0};
ll dy[] = {0,0,1,-1};
const ll sz = 3e5+5,mod = 998244353;
ll t,n,m,k;
vector<ll> p(sz),sp(sz),fac(sz);

const ll lim = 1e18;
const ll inf = 1e15;

ll Power(ll a, ll b)
{
    if(a==0)
        return 0;
    if(b==0)
        return 1;
    ll ans=Power((a*a)%mod,b/2);
    if(b&1)
        return (a*ans)%mod;
    return ans%mod;
}
ll Inv(ll a)
{
    return Power(a,mod-2);
}


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


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

typedef long long ll;

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

    int N, W;
    cin>>N>>W;

    int w[N], v[N];
    ll dp[N+1][W+1];

    for (int i=0;i<N;++i) cin>>w[i]>>v[i];

    for (int j=0;j<=W;++j) dp[0][j] = 0;
    for (int i=1;i<=N;++i) dp[i][0] = 0;

    for (int i=1;i<=N;++i){
        for (int j=0;j<=W;++j){
            dp[i][j] = dp[i-1][j];
            if (w[i-1]<=j) 
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]] + v[i-1]);
        }
    }
    ll ans = 0;
    for (int j=0;j<=W;++j) ans = max(ans, dp[N][j]);
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp> 

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

int main(void){
	long long n;
	cin >> n;
	string ans = "";
	while(n){
		int rem = n % 26;
		n /= 26;
		if(!rem){
			rem += 26;
			--n;
		}
		ans += (rem + 'a' - 1);
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(a < b){
			if(b < c){
				System.out.println("Yes");
			}
			else if(b > c){
				System.out.println("No");
			}
		}
		else
			System.out.println("No");
		sc.close();
		}
	}


Measured memory_bytes: 26352
#include <stdio.h>
#include <stdlib.h>
int main(void){
    // Your code here!
    int x_1, x_2, x_3, x_4, x_5;
    scanf("%d%d%d%d%d", &x_1, &x_2, &x_3, &x_4, &x_5);
   
   if(x_1 == 0){printf("1");
   }
   
   else if(x_2 == 0){printf("2");
   }
   
   else if(x_3 == 0){printf("3");
   }
   
   else if(x_4 == 0){printf("4");
   }
   
   else if(x_5 == 0){printf("5");
   }
   
    return 0;
    
}


Measured memory_bytes: 1612