akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
int main()
{
    list <ll> list1;
    list<ll>:: iterator it=list1.end();
    list<ll>:: iterator mt=list1.end();
    ll query;
    cin>>query;

    for(ll i=0;i<query;i++)
    {
        ll cmd;
        cin>>cmd;
        if(cmd==0)
        {
            ll x;
            cin>>x;
            list1.insert(it,x);
            advance(it,-1);
        }
        else if(cmd==1)
        {
                ll x;
                cin>>x;
                advance(it,x);
        }
        else if(cmd==2){
                mt=it;

            advance(it,1);
            list1.erase(mt);
        }
    }

    for(it=list1.begin();it!=list1.end();it++)
    {
        cout<<*it<<'\n';
    }
    return 0;
}



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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
#define N 100010
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll result(ll a, ll b, ll p){
    ll ans=1;
    if(b==(-1))
        b=p-2;
    while(b){
        if(b&1){
            ans=(ans*a)%p;
        }
        a=(a*a)%p;
        b>>=1;
    }
    return ans;
}

ll T,n,m;

int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin >> s;
    if(s.size() == 6){
        if(s[2]==s[3] && s[4]==s[5]){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";

    return 0;
}


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

using namespace std;


int main() {
	long long L, R;
	cin >> L >> R;

	if (R - L >= 2019) {
		cout << 0 << endl;
	}
	else {
		long long ans = 9223372036854775807LL;

		for (long long i = L; i <= R; ++i) {
			for (long long j = i + 1; j <= R; ++j) {
				ans = min(ans, i * j % 2019);
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

int main() {
	int N, M, C, *B, A, sum, count = 0;;
	cin >> N >> M >> C;

	B = new int[M];

	for (int i =0; i < M; i++) {
		cin >> B[i];
	}
	
	for (int i = 0; i < N; i++) {
		sum = 0;
		for (int j =0; j < M; j++) {
			cin >> A;
			sum += B[j] * A;
		}

		if (sum + C > 0) count += 1;

	}

	cout << count;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> p(n);
  rep(i,n)cin>>p[i];
  sort(p.begin(),p.end());
  int ans =0 ;
  for(int i=0;i<k;i++){
    ans += p[i];
  }
  cout<<ans;
    



}


Measured memory_bytes: 3592
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
pair<ll, int> x[111111];
pair<ll, int> y[111111];
vector< pair< ll, pair<int, int> > > edge;
int par[111111]; ll ans, n;

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

void unite(int u, int v)
{
	if(find(u)==find(v)) return;
	par[find(u)]=v;
}

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n; int i, j;
	for(i=1 ; i<=n ; i++) par[i]=i;
	for(i=1 ; i<=n ; i++) cin>>x[i].first>>y[i].first;
	for(i=1 ; i<=n ; i++) x[i].second=y[i].second=i;
	sort(x+1,x+n+1); sort(y+1,y+n+1);
	for(i=1 ; i<=n-1 ; i++) edge.push_back(make_pair(x[i+1].first-x[i].first,make_pair(x[i].second,x[i+1].second)));
	for(i=1 ; i<=n-1 ; i++) edge.push_back(make_pair(y[i+1].first-y[i].first,make_pair(y[i].second,y[i+1].second)));
	sort(edge.begin(),edge.end());
	for(i=0 ; i<edge.size() ; i++)
	{
		int u=edge[i].second.first;
		int v=edge[i].second.second;
		if(find(u)==find(v)) continue;
		unite(u,v); ans+=edge[i].first;
	}
	cout<<ans; return 0;
}

// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 9968
#include <iostream>
#include <cstdio>
#include <cstring>
#define il inline
#define ri register
#define Size 800050
using namespace std;
int D[Size];
struct graph{
	struct point{
		int next,to;
	}ar[Size];
	int head[Size],art=1;
	il void link(int u,int v){
		ar[++art]={head[u],v},head[u]=art;
		ar[++art]={head[v],u},head[v]=art;
	}
}G,G1;
int ans[Size],a[Size];
il void read(int&),dfs(int,bool);
int main(){
	int N,M;read(N),read(M);
	for(int i(1);i<=N;++i)read(D[i]);
	for(int i(1),u,v;i<=M;++i)
		read(u),read(v),G.link(u,v),ans[i]=1e9;
	for(int i(1),j,i1;i<=N;++i){
		for(j=G.head[i],i1=0;j;j=G.ar[j].next)
			if(!i1||make_pair(D[G.ar[j].to],G.ar[j].to)<
			   make_pair(D[G.ar[i1].to],G.ar[i1].to))i1=j;
		if(D[G.ar[i1].to]>D[i])return puts("-1"),0;
		ans[i1>>1]=D[i],G1.link(i,G.ar[i1].to);
	}memset(a,-1,sizeof(a));
	for(int i(1);i<=N;++i)if(!~a[i])dfs(i,0);
	for(int i(1);i<=N;++i)putchar(a[i]?'B':'W');
	putchar('\n');
	for(int i(1);i<=M;++i)printf("%d\n",ans[i]);
	return 0;
}
il void dfs(int x,bool c){a[x]=c;
	for(int i(G1.head[x]),i1;i;i=G1.ar[i].next)
		if(!~a[i1=G1.ar[i].to])dfs(i1,c^1);
}
il void read(int&x){
	x^=x;ri char c;while(c=getchar(),c<'0'||c>'9');
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}


Measured memory_bytes: 20864
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


ll dp[60][205000];
int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,k;
    cin >> n >> k;
    rep(i, n){
        cin >> dp[0][i];
        dp[0][i]--;
    }
    rep(i, 59){
        rep(j, n){
            dp[i + 1][j] = dp[i][dp[i][j]];
        }
    }
    int v = 0;
    for(int i = 59; i >= 0; --i){
        if(k & (1LL << i)) v = dp[i][v];
    }
    print(v + 1);


}



Measured memory_bytes: 97624
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
ans = 0
count = 0
i = 0
while i < len(s) - 1:
    if s[i]== 'A':
        count += 1
        i += 1
    elif s[i:i+2] == 'BC':
        ans += count
        i += 2
    else:
        count = 0
        i += 1
print(ans)

Measured memory_bytes: 10484
#include <stdio.h>

int main()
{
  int n[32] = {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;
  scanf("%d", &k);
  printf("%d\n", n[k - 1]);
  
  return 0;
}

Measured memory_bytes: 128
input()
*s, = map(int, input().split())
base = min(s)

while True:
  s = [i%base for i in s]
  s.append(base)
  s = list(set(s))
  s.remove(0)

  if base > min(s):
    base = min(s)
    continue
  else:
    break

print(base)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1000000007;
ll const N=1e6+5;
void rec(int n,vector<string>&ans,string temp,int i,char c){
    if(i==n){
        ans.pb(temp);
        return ;
    }
    char ma='a';
    rep(i,n)ma=max(ma,temp[i]);
    for(char d='a';d<=c;d++){
        temp[i]=d;
        ma=max(ma,d);
        rec(n,ans,temp,i+1,ma+1);
    }
    return ;
}
int main() {
  
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        int n;cin>>n;
        vector<string> ans;
        string temp;
        rep(i,n)temp.pb('a');
        // ans.pb(temp);
        rec(n,ans,temp,1,'b');
        sort(all(ans));
        rep(i,sz(ans)){
            cout<<ans[i]<<endl;
        }
    }
    return 0;   
}
 

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

int gcd(unsigned long a,unsigned long b){
	unsigned long c;
	while(b!=0){
		c=a%b;
		a=b;
		b=c;
	}
	return a;
}

unsigned long p[101]={};
unsigned long q[101]={};
int r[101]={};
int b[101]={};
unsigned long long w[101]={};

int det_w(int i){
	if(w[r[i]]==0){
		det_w(r[i]);
	}
	if(w[b[i]]==0){
		det_w(b[i]);
	}
	w[i]=w[r[i]]*w[b[i]]*(p[i]+q[i])/gcd(w[r[i]]*p[i],w[b[i]]*q[i]);
	return 0;
}
	
int main() {
	int n;
	int m[101]={};
	while(1){
		cin >> n;
		if(n==0){return 0;}
		w[0]=1;
		for(int i=1;i<=n;i++){
			m[i]=0;
		}
		for(int i=1;i<=n;i++){
			cin >> p[i] >> q[i] >> r[i] >> b[i];
			w[i]=0;
			m[r[i]]=i;
			m[b[i]]=i;
		}
		int i=1;
		while(m[i]!=0){
			i=m[i];
		}
		int ro=i;
		det_w(ro);
		cout << w[ro] << endl;
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
ifstream f("A.in");

int main()
{
    char S[15],T[15];
    cin>>S>>T;
    for(int i=0;i<strlen(S);i++)
    if(S[i]!=T[i])
    {
        cout<<"No";
        return 0;
    }cout<<"Yes";

    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
	int w,h,n,i,x,y,z[100000],cnt;
	scanf("%d %d %d",&w,&h,&n);
	for(i=0;i<h;i++) z[i]=0;
	for(i=0;i<n;i++){
		scanf("%d %d",&x,&y);
		if(z[x]<y) z[x]=y;
	}
	cnt=w-1; y=0;
	for(i=w-2;i>=0;i--){
		if(y<z[i+1]) y=z[i+1];
		if(cnt>i+y) cnt=i+y;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))
b = sum(a) / n
c = abs(a[0] - b)
d = 0

for i in range(1,n):
    if abs(a[i] - b) < c:
        c = abs(a[i] - b)
        d = i

print(d)

Measured memory_bytes: 9168
#include<cstdio>
#include<cstring>
int main() {
	char s[201];
	int m, h, i, n;
	while (true) {
		scanf("%s", s);
		if (strcmp(s, "-") == 0)break;
		scanf("%d", &m);
		n = 0;
		for (i = 0; i < m; i++) {
			scanf("%d", &h);
			n = (n + h) % strlen(s);
		}
		printf("%s", s + n);
		s[n] = '\0';
		printf("%s\n", s);
	}
	return 0;
}


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

int arr[3];
int main(){
    for(int i = 0;i<3;i++) scanf("%d",&arr[i]);
    sort(arr,arr+3);
    if(arr[0] == arr[1] && arr[1] != arr[2]){
        puts("Yes");
    }else if(arr[0] != arr[1] && arr[1] == arr[2]){
        puts("Yes");
    }else{
        puts("No");
    }


    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    string S;
    cin >> N >> S;
    
    string T;
    REP(i,0,N) {
        if(SZ(T) > 0 && T.back() == '(' && S[i] == ')') T.pop_back();
        else T.pb(S[i]);
    }
    string U, V;
    REP(i,0,SZ(T)) {
        if(T[i] == ')') U += '(';
        else V += ')';
    }
    PR(U+S+V);

    return 0;
}

/*



*/

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

vector<P> primes(ll n){
    vector<P> ans;
    for(ll i=2; i*i<=n; i++){
        int cnt = 0;
        if(n%i!=0)continue;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        ans.push_back(P(i,cnt));
    }
    if(n!=1)ans.push_back(P(n,1));
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    vector<P> a = primes(n-1);
    ll ans = 1;
    for(P p:a){
        ans *= p.second+1;
    }
    ans-=1;
    for(ll i=2; i*i<=n; i++){
        if(n%i!=0)continue;
        ll m = n;
        while(m>=i){
            if(m%i==0)m/=i;
            else m%=i;
        }
        if(m==1)ans++;
        m = n;
        ll j = n/i;
        if(j==i)continue;
        while(m>=j){
            if(m%j==0)m/=j;
            else m%=j;
        }
        if(m==1)ans++;
    }
    cout<<ans+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int top, M;
    cin >> top >> M;
    int bottom = 1;
    for(int i=0; i<M; i++){
        int L, R;
        cin >> L >> R;
        if(bottom<L) bottom = L;
        if(R<top) top = R;
    }
    int out;
    if(top<bottom) out = 0;
    else out = top-bottom+1;
    cout << out <<"\n";
    return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
	string s;
	cin >> s;
	if(s=="AAA"||s=="BBB"){
		cout<<"No";
	}
	else{
		cout<<"Yes";
	}
}





Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

char S[2000020];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	fread(S, 1, 2000020, stdin);

	char* c = S, ct;
	int N = 0;
	
	while ((ct = *c++) >= '0') N = N * 10 + ct - '0';

	int L = 0, R = 2000001;
	while (L + 1 < R) {
		int M = (L + R) / 2;
		if (*(c + M) >= ' ') L = M;
		else R = M;
	}

	if (*c == '0') {
		printf("0\n");
		return 0;
	}

	for (char* d = c; d < c + R - 8; d += 7) {
		ll tmp = *(ll*)(d);
		tmp += 0x1010101010101010;
		tmp ^= 0xcfcfcfcfcfcfcfcf;
		ll tmp2 = tmp + 0x0001000100010001;
		tmp = tmp + 0x0000010001000100;

		if (((tmp << 1 ^ tmp) & 0x0020002000200000) | ((tmp2 << 1 ^ tmp2) & 0x2000200020002000)) {
			printf("0\n");
			return 0;
		}
	}

	for (char* d = c + max(0, R - 10); d < c + R; d++) {
		if (*d == ' ' && *(d + 1) == '0') {
			printf("0\n");
			return 0;
		}
	}

	if (R >= N * 2 + 18) {
		printf("-1\n");
		return 0;
	}

	ll kotae = 1;
	auto owa = c + R;
	while (c < owa) {
		ll tmp = *(ll*)(c);
		if (tmp != 0x2031203120312031) {
			ll k = 0;
			while ((ct = *c++) >= '0') k = k * 10 + ct - '0';
			if (ll(1e18) / kotae < k) {
				printf("-1\n");
				return 0;
			}
			else kotae *= k;
		}
		else c += 8;
	}

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

	Would you please return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
#include <deque>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
	deque<int> A;
	int q, query, x, y;
	cin >> q;
	rep(i, q)
	{
		cin >> query;
		if (query == 0)
		{
			cin >> x >> y;
			if (x == 0)
			{
				A.push_front(y);
			}
			else
			{
				A.push_back(y);
			}
		}
		else if (query == 1)
		{
			cin >> x;
			cout << A[x] << endl;
		}
		else
		{
			cin >> x;
			if (x == 0)
			{
				A.pop_front();
			}
			else
			{
				A.pop_back();
			}
		}
	}
}


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

int main() {
  int n,m;
  cin>>n>>m;
  int A[n];
  
  for(int i=0;i<n;i++){
    A[i]=0;
  }
  
  
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    A[a-1]++;
    A[b-1]++;
  }
  
  for(int i=0;i<n;i++){
    cout<<A[i]<<endl;
  }
  
  
  
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort_by{|e| -e}

b = []
m.times do
    if a == []
        a = b
        b = [a.shift / 2]
    elsif b.empty? || a[0] > b[0]
        b << a.shift / 2
    else
        b << b.shift / 2
    end
end

puts (a + b).inject(:+)

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

int main() {
  string o, e; cin >> o >> e;
  REP(i, e.size()) cout << o.at(i) << e.at(i);
  if(o.size() > e.size()) cout << o.at(o.size() - 1);
  
  return 0;
}

Measured memory_bytes: 256
var s:string;
begin
readln(s);
if (s='RRR') then writeln(3);
if (s='RRS') then writeln(2);
if (s='RSR') then writeln(1);
if (s='RSS') then writeln(1);
if (s='SRR') then writeln(2);
if (s='SRS') then writeln(1);
if (s='SSR') then writeln(1);
if (s='SSS') then writeln(0);
end.

Measured memory_bytes: 1308
#include <iostream>
#include <vector>
#include <algorithm>

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

    int n; std::cin >> n;
    std::vector<int> v(n);
    for (auto &a : v) std::cin >> a;
    std::cout << (*max_element(v.begin(), v.end()) - *min_element(v.begin(), v.end())) << std::endl;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans=1;
  for (int i=0; i<n-1; i++){
    if (s.at(i)!=s.at(i+1)){
      ans++;
    }
    
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
using System;
using System.Linq;

class Problem {
    public static void Main() {
        var list = new int[4, 3, 10];
        var n = int.Parse(Console.ReadLine());
        for (var i = 0; i < n; i++) {
            var data = Console.ReadLine().Split().Select(int.Parse).ToArray();
            list[data[0] - 1, data[1] - 1, data[2] - 1] += data[3];
        }
        for (var b = 0; b < 4; Console.Write(++b != 4 ? "####################\n" : ""))
            for (var f = 0; f < 3; f++)
                for (var r = 0; r < 10; Console.Write(++r == 10 ? "\n" : ""))
                    Console.Write(" " + list[b, f, r]);
    }
}


Measured memory_bytes: 9620
n=int(input())
cnt,ans=0,0
h=list(map(int,input().split()))
h=h[::-1]
for i in range(n-1):
  if h[i]<h[i+1]:
    if abs(h[i]-h[i+1])>=2:
      print("No")
      exit()
    else:
      h[i+1]-=1
print("Yes")

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

using namespace std;
#define BUF (110)
#define INF (1000005)
#define ll long long 

int n;
int a[BUF];
int mn = INF;
int mx = -INF;
int mxi = 0;
int mni = 0;
int m=0;
int x[BUF];
int y[BUF];

int main(void){
	cin >> n;
	for(int i=1;i<=n;i++){ 
		cin >> a[i];
		if(mn>a[i]){
			 mn = a[i];
			 mni=i;
		}
		if(mx<a[i]){
			 mx = a[i];
			 mxi=i;
		}
	}


	if(mn<0 && mx>0 && mx+mn>=0){
	for(int i=1;i<=n;i++){
		if(i==mxi) continue;
		a[i]+=mx;
		m++;
		x[m] = mxi;
		y[m] = i;
	}
	mn=1;
	}


	if(mn<0 && mx>0 && mx+mn<0){
	for(int i=1;i<=n;i++){
		if(i==mni) continue;
		a[i]+=mn;
		m++;
		x[m] = mni;
		y[m] = i;
	}
	mx=-1;
	}


	if(mn>=0){//all pos
		for(int i=1;i<n;i++){
			if(a[i]>a[i+1]){
				a[i+1]+=a[i];
				m++;
				x[m]=i;
				y[m]=i+1;
			}
		}
	}

	if(mx<=0){//all neg
		for(int i=n;i>1;i--){
			if(a[i]<a[i-1]){
				a[i-1]+=a[i];
				m++;
				x[m]=i;
				y[m]=i-1;
			}
		}	
	}


	cout << m << "\n";
	for(int i=1;i<=m;i++){
		cout << x[i] << " " << y[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll INF =1e9+7;
    typedef pair<ll,ll> ii;
    #define f(i,a,b) for(long long i = a;i < b;i++)
    #define rf(i,a,b) for(long long i=a;i>=b;i--)
    #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define w(t) while(t--)
    #define c(n); cin>>n;
    #define p(n) cout<<n;
    #define pl(n) cout<<n<<endl;
    #define ps(n); cout<<n<<" ";
    int main(void){
        fastio;
        ll n;
        c(n);
        string s;
        c(s);
        if(n % 2 == 1){
            pl("No");
            return 0;
        }
        string t = "";
        f(i,0,n/2){
            t+=s[i];
        }
        t+=t;
        if(t == s){
            pl("Yes");
        }
        else{
            pl("No");
        }
   }


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
const int MOD = 1e9+7;
const int MOOD = 998244353;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

vector<int> graph[100001];

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int, int> > bri(m);
	for (int i = 0; i < m; i++){
		cin >> bri[i].second >> bri[i].first;
	}
	sort(bri.begin(), bri.end());

	int stop = 0, ans = 0; 

	for (int i = 0; i < m; i++){
		if (stop < bri[i].second){
			ans++;
			stop = bri[i].first - 1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(void) {
    int A[3][3] = {0};
    bool bing[3][3] = {false};
    bool ans = false;
    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            cin >> A[i][j];
        }
    }
    int N; cin >> N;
    int b[N+10] = {0};
    for(int i=0; i<N; i++) cin >> b[i];

    for(int k=0; k<N; k++) {
        for(int i=0; i<3; i++) {
            for(int j=0; j<3; j++) {
                if(b[k] == A[i][j]) bing[i][j] = true;
           }
        }
    }

    if(bing[0][0] && bing[1][0] && bing[2][0]) ans = true;
    else if(bing[0][1] && bing[1][1] && bing[2][1]) ans = true;
    else if(bing[0][2] && bing[1][2] && bing[2][2]) ans = true;

    if(bing[0][0] && bing[0][1] && bing[0][2]) ans = true;
    else if(bing[1][0] && bing[1][1] && bing[1][2]) ans = true;
    else if(bing[2][0] && bing[2][1] && bing[2][2]) ans = true;

    if(bing[0][0] && bing[1][1] && bing[2][2]) ans = true;
    else if(bing[0][2] && bing[1][1] && bing[2][0]) ans = true;

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#include<vector>
#include<queue>
#define ll long long
#define inf INT_MAX
int MinimumNumIncreasingSubsequences(ll int arr[],ll int n) 
{ 
    multiset<ll int> last; 
  
    // last element in each  increasing subsequence  
    // found so far 
    for (int i = 0; i < n; i++) { 
  
        // here our current element is arr[i] 
        multiset<ll int>::iterator it = last.lower_bound(arr[i]); 
  
        // iterator to the first element larger  
        // than or equal to arr[i] 
        if (it == last.begin()) 
  
            // if all the elements in last larger 
            // than or to arr[i] then insert it into last 
            last.insert(arr[i]); 
  
        else { 
            it--; 
  
            // the largest element smaller than arr[i] is the number 
            // before *it which is it-- 
            last.erase(it); // erase the largest element smaller than arr[i] 
            last.insert(arr[i]); // and replace it with arr[i] 
        } 
    } 
    return last.size(); // our answer is the size of last 
} 
  

main()
{
ll int n;
cin>>n;
ll int a[n];
for(int i=0;i<n;i++)
{
	cin>>a[i];
}
cout<<MinimumNumIncreasingSubsequences(a,n)<<endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;
int kyori(int x, int y) {
  if(x >= y) return x - y;
  else return y - x;
}

bool ok(int l, int k, bool &isok) {
  if(l > k) isok = false;  
} 
int main() {
  vector<int> a(5);
  rep(i, 5) cin >> a[i];
  int k;
  cin >> k;
  bool b = true;
  for(int i = 0; i<=4; i++) {
    for(int j = i+1; j<=4; j++) {
      int l = kyori(a[i], a[j]);
      ok(l, k, b);
    }
  }

  b ? cout << "Yay!" << endl : cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val map = HashMap<String, Long>()
    var ans = 0L
    repeat(n) {
        val line = readLine()!!.toCharArray().sorted().joinToString("")
        ans += map.getOrElse(line) { 0 }
        map[line] = map.getOrElse(line) { 0 } + 1
    }
    println(ans)
}

Measured memory_bytes: 79748
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int A, P; cin >> A >> P;
    P = P + (A*3);
    cout << P / 2 << endl;
}

Measured memory_bytes: 256
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)


Measured memory_bytes: 13840
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
	//ceil() != floor()
	int ans = 0;
	double n, d, sum = 0.0;
	double x[10][10];
	cin >> n >> d;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < d; j++)
		{
			cin >> x[i][j];
		}
	}

	for (int i = 0; i < n - 1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			for (int n = 0; n < d; n++)
			{
				sum += pow(x[i][n] - x[j][n],2);
			}
			if (ceil(sqrt(sum)) == floor(sqrt(sum)))
			{
				ans++;
			}
			sum = 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	Scanner sc = new Scanner(System.in);
	int[] f = new int[123456 * 2 + 1];
	public void run() {
		furui();
		while(sc.hasNext()){
			int n = sc.nextInt();
			if(n == 0) break;
			else calc(n);
		}
	}
	public void calc(int n){
		int sum = 0;
		for(int i = n + 1; i < n * 2 + 1; i++){
			sum = sum + f[i];
		}
		System.out.println(sum);
	}
	public void furui(){
		Arrays.fill(f, 1);
		f[0] = 0;
		f[1] = 0;
		for(int i = 2; i < f.length; i++){
			if(f[i] == 1){
				for(int j = i * 2; j < f.length; j = j + i){
					f[j] = 0;
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 23192
#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;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

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

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
ll dp[125252][3];

int main(){
  scanf("%d",&n);
  REP(i,n){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    CHMAX(dp[i+1][0], dp[i][1]+a);
    CHMAX(dp[i+1][0], dp[i][2]+a);

    CHMAX(dp[i+1][1], dp[i][0]+b);
    CHMAX(dp[i+1][1], dp[i][2]+b);

    CHMAX(dp[i+1][2], dp[i][0]+c);
    CHMAX(dp[i+1][2], dp[i][1]+c);
  }
  ll ans = 0;
  CHMAX(ans, dp[n][0]);
  CHMAX(ans, dp[n][1]);
  CHMAX(ans, dp[n][2]);
  printf("%lld\n",ans);
  return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;

#define llset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define en '\n'
#define S second
#define F first
#define pll pair<ll,ll>
#define PB push_back

const ll N = 1e6+7;
ll mod = 1e9+7;
#define calncr for(int i=1  ;i<=1e6;i++) fac[i] = (fac[i-1]*i)%mod;
ll fac[N] = {0};

ll gen_base(const ll before, const ll after) {
    auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
    std::mt19937 mt_rand(seed);
    int base = std::uniform_int_distribution<ll>(before+1, after)(mt_rand);
    return base % 2 == 0 ? base-1 : base;
}

ll pow(ll a,ll b)
{
    if(!b)
        return 1;
    ll p = pow(a,b/2);
    if(b%2)
        return (a*((p*p)%mod))%mod;
    else
        return (p*p)%mod;
}

ll modInv(ll a)
{
    //cout<<a<<" "<<mod<<en;
    return pow(a%mod,mod-2);
}

ll nCr(ll n,ll r)
{
    return (fac[n]*modInv((fac[r]*fac[n-r])%mod))%mod;
}

ll hashf(ll r,ll x,ll mod)
{
    return (x+r)%mod;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    fac[0] = 1;
    calncr;
    ll n,d;
    cin>>n>>d;
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll p,q;
        cin>>p>>q;
        if(p*p+q*q<=(d*d))
            ans++;
    }
    cout<<ans<<en;
}


Measured memory_bytes: 11468
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int n,m,x;
const int maxn = 1e5+10;
long long gcd(long long a, long long b){
    return a == 0 ? b : gcd(b % a, a);
}
long long a[maxn],b[maxn];
int main(){
    long long i,j,k;
    long long ans;
    long long now;
    long long comm;
    while(~scanf("%d",&n)){
        ans = 0;
        now = 0;
        for(i=1;i<=n;i++){
            scanf("%lld%lld",&a[i],&b[i]);
        }
        
        for(i=n;i>=1;i--){
            a[i] += ans;
            for(j=a[i]/b[i];;j++){
                if(j*b[i]>=a[i]){
                    break;
                }
            }
            comm = j*b[i] - a[i];
            ans += comm;
        }
        printf("%lld\n",ans);
    }
    
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

signed main() {
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m1!=m2) cout<<'1'<<endl;
    else cout<<'0'<<endl;

    // cout << ans << endl;
    return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    sort(A.begin(), A.end(), greater<int>());
    
    int A_sum = accumulate(A.begin(), A.end(), 0);
    double line = (A_sum / (4.0 * M));
    for (int i = 0; i < M; i++) {
        if (A.at(i) < line) {
            cout << "No" << endl;
            return 0;
        }    
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>

struct Data {
    int price;
    int number;
};

int main(void) {

    int N, M;
    Data* data;

    std::cin >> N >> M;

    data = new Data[N];

    for(int n=0; n<N; n++) {
        int a, b;
        std::cin >> a >> b;
        data[n] = {a, b};
    }

    std::sort(data, data + N, [](const Data& d1, const Data& d2){ return d1.price < d2.price; });

    int64_t price = 0;
    Data* cdata = data;
    for(int m=0; m<M; m++) {
        if(!cdata->number) cdata++;
        price += cdata->price;
        cdata->number--;
    }

    std::cout << price << std::endl;

    return 0;
}

Measured memory_bytes: 1024
// 5/1
// 過去問攻略

#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;

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

    int ans[3] = {-1, -1, -1};
    // cout << "initial ans: " << ans[0] << ans[1] << ans[2] << endl;
    bool have_answer = true;

    for (int i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;

        s--;

        if (ans[s] == -1) {
            ans[s] = c;
        }
        else if (ans[s] == c) {
            continue;
        }
        else {
            have_answer = false;
        }

        // cout << "s, c: " << s << " " << c << endl;
        // cout << "ans: " << ans[0] << ans[1] << ans[2] << endl;

    }

    if (N != 1 && ans[0] == 0) have_answer = false;

    if (ans[0] == -1) {
        if (N == 1) {
            ans[0] = 0;
        } else {
            ans[0] = 1;
        }
    }

    for (int i = 0; i < 3; i++) {
        if (ans[i] == -1) ans[i] = 0;
    }

    if (!have_answer) {
        cout << "-1" << endl;
    }
    else {
        if (N == 1) cout << ans[0] << endl;
        else if (N == 2) cout << ans[0] * 10 + ans[1] << endl;
        else cout << ans[0] * 100 + ans[1] * 10 + ans[2] << endl;
    }

    return 0;


    // ここからやり直し！
    // int N, M;
    // cin >> N >> M;

    // int ans[N];
    // memset(ans, -1, sizeof(ans));

    


}


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

int main() {
  int n; cin >> n;
  vector<int> p(n), q(n), a(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  for (int i = 0; i < n; i++)
    a[i] = i+1;
  int cnt = 0, P = 1, Q = 1;
  do {
    cnt++;
    int pp = 0, qq = 0;
    rep(i, n) if (a[i] == p[i]) pp++;
    rep(i, n) if (a[i] == q[i]) qq++;
    if (pp == n) P = cnt;
    if (qq == n) Q = cnt;
  } while (next_permutation(a.begin(), a.end()));
  cout << abs(P - Q) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n)  for(int i=0; i<n; i++)
ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
 
int main(){
  ll n;
  cin >>n;
  ll a[n];
  rep(i,n) cin>>a[i];
  ll right[n-1]={0},left[n-1]={0};
  right[0]=a[n-1];
  left[0]=a[0];
  
  for(int i=1;i<n-1;i++){
    left[i]=GCD(left[i-1],a[i]);
  }
  for(int i=1;i<n-1;i++){
    right[i]=GCD(right[i-1],a[n-1-i]);
  }
  
  ll ans=1,gcd;
  for(int i=0;i<n-2;i++){
    gcd=GCD(left[i],right[n-3-i]);
    ans=max(gcd,ans);
  }
  ans=max({left[n-2],right[n-2],ans});
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int k=0; k<N; k++){
    cin >> vec.at(k);
  }
  int counter = 1;
  bool kaburi = false;
  for(int i=1; i<N; i++){
    kaburi = false;
    for(int j=0; j<i; j++){
      if(vec.at(j) == vec.at(i)){
        kaburi = true;
      }
      if(j == i-1 && kaburi == false){
        counter++;
      }
    }
  }
  cout << counter << endl;
  return 0;
}

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

const int maxN = 200000;

int N, M;
string s;

set<int> G[maxN];
int neighbourA[maxN], neighbourB[maxN];
bool isDead[maxN];

void selectNodes() {
    queue<int> Q;

    for (int u = 0; u < N; u++) {
        if (neighbourA[u] == 0 or neighbourB[u] == 0) {
            isDead[u] = true;
            Q.push(u);
        }
    }

    while (!Q.empty()) {
        int u = Q.front(); Q.pop();

        for (int to : G[u]) {
            if (isDead[to] or u == to) continue;

            if (s[u] == 'A') neighbourA[to]--;
            else neighbourB[to]--;

            if (neighbourA[to] == 0 or neighbourB[to] == 0) {
                isDead[to] = true;
                Q.push(to);
            }
        }
    }
}

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

    cin >> N >> M;
    cin >> s;

    map<char, int*> F = {{'A', neighbourA}, {'B', neighbourB}};
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        if (G[a].count(b) == 0) {
            F[s[b]][a]++;
            G[a].insert(b);
        }

        if (G[b].count(a) == 0) {
            F[s[a]][b]++;
            G[b].insert(a);
        }
    }

    selectNodes();

    string ans = "No";
    for (int u = 0; u < N; u++) {
        if (!isDead[u]) ans = "Yes";
    }
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;

ll pow_mod(ll a, ll n, ll p)
{
    if(n == 1){
        return a%p;
    }else if(n%2 == 1){
        return a*pow_mod(a,n-1,p)%p;
    }else{
        ll t = pow_mod(a,n/2,p);
        return t*t%p;
    }
}

int main()
{
    ll i,j;
    ll m,n;
    cin >> m >> n;
    ll MOD = 1e9+7;
    ll ans = pow_mod(m,n,MOD);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3092
# vim: fileencoding=utf-8

import math


def main():
    li = list(map(int, input().split()))
    li.sort(reverse=True)
    m = li[0] - li[1]
    n = li[0] - li[2]
    p = n - m
    ans = m + math.ceil(p / 2) + (p % 2)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61936
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(int t=1; ; ++t){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<vector<int> > a(n, vector<int>(n));
        int y = 0;
        int x = 0;
        int m = 0;
        for(;;){
            a[y][x] = ++ m;
            if(m == n * n)
                break;

            if(y == 0 && x % 2 == 0 && x < n-1){
                ++ x;
            }else if(y == n-1 && (y + x) % 2 == 1){
                ++ x;
            }else if(x == 0 && y % 2 == 1){
                ++ y;
            }else if(x == n-1 && (y + x) % 2 == 0){
                ++ y;
            }else if((y + x) % 2 == 0){
                -- y;
                ++ x;
            }else{
                ++ y;
                -- x;
            }
        }

        cout << "Case " << t << ':' << endl;
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j)
                cout << setw(3) << a[i][j];
            cout << endl;
        }
    }
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
#include<algorithm>
#include<stdio.h>
int main()
{
    int n,num=0;
    int a[100005];
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    for(int i=0; i<n; )
    {
        if(a[i]==a[i+1])
        {
            i=i+2;
        }
        else
        {
            num++;
            i++;
        }
    }
    printf("%d\n",num);
    return 0;
}




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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	string sa,sb,sc;
	cin >> sa >> sb >> sc;
	char cur = 'a';
	int flag=0;
	while(1)
	{
		if(cur=='a')
		{
			if(sa.size()==0)
			{
				flag=1;
				break;
			}
			else
			{
				cur = sa[0];
				sa.erase(sa.begin());
				continue;
			}
		}
		else if (cur=='b')
		{
			if(sb.size()==0)
			{
				flag=2;
				break;
			}
			else
			{
				cur = sb[0];
				sb.erase(sb.begin());
				continue;
			}
		}
		else if(cur=='c')
		{
			if(sc.size()==0)
			{
				flag=3;
				break;
			}
			else
			{
				cur = sc[0];
				sc.erase(sc.begin());
				continue;
			}
		}
	}
	if(flag==1)
		cout << "A" << endl;
	else if(flag==2)
		cout << "B" << endl;
	else if(flag==3)
		cout << "C" << endl;
}


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

using namespace std;

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

#define INF 2<<29
#define F first
#define S second

int main(){
  int q;
  int c,a,n;
  int ans;
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    scanf("%d %d %d",&c,&a,&n);
    
    ans=0;
    while(1){
      if(c>0&&a>0&&n>0){
	ans++;
	c--;
	a--;
	n--;
      }else if(c>1&&a>0){
	ans++;
	c-=2;
	a--;
      }else if(c>2){
	ans++;
	c-=3;
      }else{
	break;
      }
    }
    printf("%d\n",ans);
  }
	
  
  return (0);
}



Measured memory_bytes: 3216