akhauriyash/Code-Regression huggingface dataset:
import bisect,sys
import math
from collections import deque

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac =fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV
        
    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s+=a
        yield s


sys.setrecursionlimit(200005)


def main():
    S =sRaw()
    return "ABC" if S=="ARC" else "ARC"
    
if __name__ == "__main__":
    print(main())


Measured memory_bytes: 67452
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

string n;

int main(int argc, char const* argv[])
{
    cin >> n;
    if(n[0] == n[1] && n[1] == n[2]) puts("Yes");
    else if(n[2] == n[3] && n[1] == n[2]) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
queue<int>x[200001];
int main(void){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
      int a,b;
      cin>>a>>b;
      x[a].push(b);
  }
    while(!x[1].empty()){
      int s=x[1].front();
        x[1].pop();
        while(!x[s].empty()){
            if(x[s].front()==n){
                cout<<"POSSIBLE\n";
                return 0;
            }
            x[s].pop();
        }
    }
    cout<<"IMPOSSIBLE\n";
    return 0;
}


Measured memory_bytes: 135040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll MAXN = 100005;

int n, a, ans;
multiset<int> ed;
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> n;
    REP (i, n) {
        cin >> a;
        auto ptr = ed.lower_bound(a);
        if (ptr != ed.begin()) {
            int x = *prev(ptr);
            ed.erase(ed.find(x));
            ed.insert(a);
        } else {
            ed.insert(a);
            ans++;
        }
    }

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


Measured memory_bytes: 4992
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll GetDigit(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}


int main(void){
  ll n;
  cin>>n;

  map<ll, ll> m;
  
  REP(i, n){
    ll x;
    cin>>x;
    m[x]++; 
  }

  if(m.size()>3){
    cout<<"No"<<endl;
    return 0;
  }else if(m.size()==1){
    decltype(m)::iterator it = m.find(0);
    if(it==m.end()){
      cout<<"No"<<endl;
      return 0;
    }
  }else if(m.size()==2){
    if(m[0]!=n/3 || n%3!=0){
      cout<<"No"<<endl;
      return 0;
    }
  }else{
    if(n%3!=0){
      cout<<"No"<<endl;
      return 0;
    }  
     

    for(auto i=m.begin(); i!=m.end() ;i++){
      if (i->second !=n/3){
        cout<<"No"<<endl;
        return 0;
      }
    }

    ll a,b,c;
    a = m.begin() -> first;
    b = next(m.begin(), 1) -> first;
    c = next(m.begin(), 2) -> first;
  
    if(a!=(b^c) && b!=(a^c) && c!=(a^b)){
      cout<<"No"<<endl;
      return 0;
    }

  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 5120
import qualified Control.Arrow         as Arrow
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Vector.Unboxed   as VU

type Parser a = BSC8.ByteString -> Maybe (a, BSC8.ByteString)

parseInt :: Parser Int
parseInt = fmap (Arrow.second BSC8.tail) . BSC8.readInt
parseAN :: Int -> IO (VU.Vector Int)
parseAN n = VU.unfoldrN n parseInt <$> BSC8.getLine

main :: IO ()
main = do
  n  <- readLn :: IO Int
  xv <- parseAN n
  print $ solver xv

solver :: VU.Vector Int -> Int
solver xv
  | VU.all even xv = 1 + solver (VU.map (flip div 2) xv)
  | otherwise      = 0


Measured memory_bytes: 4184
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    cout << --n * --m << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N;
  cin >> N;
  vector<i64> A(N);
  for (i64 i = 0; i < N; i++)
    cin >> A[i];
  map<i64, i64> m;
  auto pri = [&](i64 i) {
    i64 tmp = A[i];
    for (long long a = 2; a * a <= tmp; a++)
    {
      if (tmp % a != 0)
        continue;
      while (tmp % a == 0)
        tmp /= a;
      m[a]++;
    }
    if (tmp != 1)
      m[tmp]++;
    return 0;
  };
  for (i64 i = 0; i < N; i++)
    pri(i);
  bool p = true;
  for (pair<i64, i64> i : m)
    if (i.second != 1)
      p = false;
  if (p)
  {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  i64 ok = true;
  for (pair<i64, i64> i : m)
    if (i.second == N)
      ok = false;
  if (ok)
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}


Measured memory_bytes: 15708
#include<stdio.h>
main(void){
    int a,h=0,m=0,s=0;
    scanf("%d",&a);
    while(a>=3600){
        a=a-3600;
        h++;
    }
      while(a>=60){
        a=a-60;
        m++;
    }
    s=a;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <ctime>
#include <map>
#include <queue>
#include <functional>

using namespace std; using ll=long long; using P=pair<ll,ll>; const int INF=1e9; const ll LNF=1e18;

int main(){
  int n; cin>>n;
  string s; cin>>s;
  
  bool ok = false; int ans[n];
  for(int i=0;i<4;i++) {
    fill(ans, ans+n, -1);
    ans[0]=i/2, ans[1]=i%2;

    for(int j=2;j<n;j++) {
      ans[j] = ans[j-2] ^ (s[j-1]=='x') ^ (ans[j-1]==1);
      // ひつじさんが「o」→同じひと
    }

    bool o1 = (ans[n-1] ^ (s[0]=='x') ^ (ans[0]==1)) == ans[1];
    bool o2 = (ans[n-2] ^ (s[n-1]=='x') ^ (ans[n-1]==1)) == ans[0];
    if (o1 && o2) {ok=true; break;}
  }
  if (ok) {
    for(int i=0;i<n;i++) {
      if (ans[i]==0) cout<<"S";
      else cout<<"W";
    }cout<<endl;
  } else {  
    cout<<-1<<endl;
  }
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    string s; cin >> s;
    int res = 0;
    rep(i,s.size()){
        if(i % 2 == 0 and s[i] == '0')++res;
        else if(i % 2 and s[i] == '1')++res;
    }
    int temp = 0;
    rep(i,s.size()){
        if(i % 2 == 0 and s[i] == '1')++temp;
        else if(i % 2 and s[i] == '0')++temp;
    }
    cout << min(temp,res) <<endl;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    
    char a, b;
    cin >> a >> b;
    if(a < b)cout << "<" << endl;
    if(a > b)cout << ">" << endl;
    if(a == b)cout << "=" << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
/*
Problem Statement
There are N items, numbered 1,2,…,N. For each i (1≤i≤N), Item i has a weight of wi and a value of vi.
Taro has decided to choose some of the N items and carry them home in a knapsack.
The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.
Find the maximum possible sum of the values of items that Taro takes home.
Constraints
All values in input are integers.
1≤N≤100
1≤W≤10^5
1≤wi≤W
1≤vi≤10^9
*/

#include<bits/stdc++.h>
using namespace std;
#define iso ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define clr(x) memset((x), 0, sizeof(x))
#define mod 1000000007
#define MAX 1000005
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_tree;*/

ll w[105],v[105],dp[105][1000005],max_val=0;
int n;

int main()
{
    iso;
    int i,j,k;
    cin>>n>>k;
    for(i=0;i<105;i++)
        for(j=0;j<1000005;j++)
            dp[i][j]=INT_MAX;
    for(i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
        max_val+=v[i];
    }

    for(i=0;i<=n;i++)
        dp[i][0]=0;

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=max_val;j++)
        {
                dp[i][j]=dp[i-1][j];
                if(j-v[i]>=0)
                {
                    dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
                }

        }
    }

    for(i=max_val;i>=0;i--)
    {
        if(dp[n][i]<=k)
        {
            cout<<i;
            return 0;
        }
    }

    return 0;
}




Measured memory_bytes: 820608
ab = list(map(int, input().split())) 
a= ab[0]
b=ab[1]
 
x=[]
x.append(a/0.08)
x.append((a+1)/0.08)
x.append(b/0.1)
x.append((b+1)/0.1)
if x[0]<= x[2] and x[2]<x[1]:
    print(int(x[2]))
elif x[2]<= x[0] and x[0] < x[3]:
    if x[0]>int(x[0]):
        print(int(x[0])+1)
    else:
        print(int(x[0]))
else:
    print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int mod=1e9+7;
const int maxn=2e5+5;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,k,pre[maxn],suf[maxn];
signed main(){
	n=read(),k=read();
	n++;
	for(int i=1;i<=n;i++){
		pre[i]=pre[i-1]+i;
		pre[i]=pre[i]%mod; 
		suf[i]=suf[i-1]+(n-i+1);
		suf[i]=suf[i]%mod;
	}
	int ans=0;
	for(int i=k;i<=n;i++){
		ans=(ans+(suf[i]-pre[i]+1+mod)%mod)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 6772
#include <iostream>
#include <queue>
#include <cstring>
#include <set>
using namespace std;

int dx[]={0,-1,0,1,-1,-1,1,1};
int dy[]={-1,0,1,0,-1,1,-1,1};

class State
{
public:
	int h,c,x,y;
	State(int x, int y, int h, int c)
		:h(h),c(c),x(x),y(y)
	{}
};

bool tf[5][5];

set<pair<int, int> > hs;

int ch(bool f[5][5],int N)
{
	int ret=0,cnt=0;
	for(int i=0; i<N; i++)
	for(int j=0; j<N; j++)
	{
		ret|=(f[j][i]<<cnt);
		cnt++;
	}

	return ret;
}

void mov(int x, int y, bool f[5][5], int N)
{
	memset(tf,0,sizeof(tf));
	f[x][y]=1;
	int cnt[5][5]={0};
	for(int i=0; i<N; i++)
	for(int j=0; j<N; j++)
	{
		if(!f[j][i]) continue;
		for(int k=0; k<8; k++)
		{
			int tx=j+dx[k], ty=i+dy[k];
			if(tx<0||ty<0||tx>=N||ty>=N) continue;

			cnt[tx][ty]++;
		}
	}

	for(int i=0; i<N; i++)
	for(int j=0; j<N; j++)
	{
		if(f[j][i]&&(cnt[j][i]==2||cnt[j][i]==3)) 
		{
			tf[j][i]=1;
		}
		if(!f[j][i]&&cnt[j][i]==3)
		{
			tf[j][i]=1;
		}
	}

	tf[x][y]=0;
	f[x][y]=0;
}

int main()
{
	int N;
	while(cin >> N, N)
	{
		hs.clear();
		bool f[5][5]={0};
		int sx,sy;

		for(int i=0; i<N; i++)
		{
			cin.ignore();
			for(int j=0; j<N; j++)
			{
				char c;
				cin >> c;
				if(c=='@')
				{
					sx=j;
					sy=i;
				}
				if(c=='#') f[j][i]=1;
			}
		}

		queue<State> q;
		q.push(State(sx,sy,ch(f,N), 0));

		int ans=-1;
		while(!q.empty())
		{
			State s=q.front(); q.pop();
			if(s.h==0)
			{
				ans=s.c;
				break;
			}
			
			bool sf[5][5];
			int tcnt=0;
			for(int i=0; i<N; i++)
			for(int j=0; j<N; j++)
			{
				sf[j][i]=(s.h&(1<<tcnt));
				tcnt++;
			}
			
			for(int i=0; i<8; i++)
			{
				int tx=s.x+dx[i], ty=s.y+dy[i];
				if(tx<0||ty<0||tx>=N||ty>=N) continue;
				if(sf[tx][ty]) continue;

				mov(tx,ty,sf,N);
				int h=ch(tf,N);
				if(hs.count(make_pair(tx*5+ty, h))) continue;
				hs.insert(make_pair(tx*5+ty, h));

				q.push(State(tx,ty, h, s.c+1));
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1524
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 1001000
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    cin.sync_with_stdio(false);
    ll n,m;cin>>n>>m;
    ll s=0;
    ll a[n+1];
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    ll cnt=0;
    for(ll i=1;i<=n;i++)
    {
        if(a[i]*4*m>=s)
            cnt++;
    }
    if(cnt>=m)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
const int N = 2e5+5;
 
struct edge{
	int x,y,d;
}a[N];
int n,h,w,c[N],fa[N];
long long ans;

int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}

int main(){
	scanf("%d%d%d",&n,&h,&w);
	rep(i,1,n)scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].d),a[i].y+=h;
	sort(a+1,a+n+1,[](edge x,edge y){return x.d>y.d;});
	
	rep(i,1,h+w)fa[i]=i,c[i]=1;
	rep(i,1,n){
		int x = find(a[i].x), y = find(a[i].y);
		if(x!=y) fa[x] = y, c[y] += c[x];
		if(c[y]) c[y]--, ans+=1ll*a[i].d;
	} 
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    multiset<int> s;
    for (;N--;){
        int D; cin >> D;
        s.emplace(D);
    }
    int M; cin >> M;
    for (;M--;){
        int T; cin >> T;
        if (!s.count(T)){cout << "NO" << '\n'; return 0;}
        s.erase(s.lower_bound(T));
    }
    cout << "YES" << '\n';
}

Measured memory_bytes: 9600
def examA():
    N = I()
    if N==1:
        ans = "Hello World"
    elif N==2:
        A = I(); B = I()
        ans = A + B
    try:
        print(ans)
    except:
        print()
    return

def examB():
    N, T = LI()
    ans =  10**9
    for _ in range(N):
        c, t = LI()
        if T>=t and ans>c:
            ans = c
    if ans==10**9:
        ans = "TLE"
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
int A[500005],n;
void maxH(int i){
	int l=2*i,r=2*i+1,big;
	if(l<=n && A[l]>A[i]) big = l;
	else big = i;
	if(r<=n && A[r]>A[big]) big = r;
	if(big!=i){
		swap(A[i],A[big]);
		maxH(big);
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&A[i]);
	for(int i=n/2;i>0;i--)
		maxH(i);
	for(int i=1;i<=n;i++){
		printf(" %d",A[i]);
	}
	puts("");
	return 0;
}



Measured memory_bytes: 5084
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJSort1
{
    class Program
    {
        static int c = 0;
        static void Swap(ref int a,ref int b)
        {
            int c = b;
            b = a;
            a = c;
        }
        static int[] Sort(int []a,int count)
        {
            int min = a.Length - count;
            for (int i = a.Length - count; i < a.Length; i++)
            {
                if (a[i] < a[min])
                {
                    min = i;
                }
            }
            Swap(ref a[min], ref a[a.Length - count]);
            if (min != a.Length - count) { c++; }
            if (count >1) { Sort(a, --count); }
            return a;
        }
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            a = Sort(a,N);
            for(int i = 0; i < a.Length; i++)
            {
                Console.Write(a[i]);
                if (i != a.Length - 1)
                {
                    Console.Write(" ");
                }
            }
            Console.WriteLine();
            Console.WriteLine(c);
        }
    }
}

Measured memory_bytes: 9628
#include<iostream>
#include<cmath>
#include<map>
#include<queue>
#include<string>

using namespace std;
#define N 3
#define M 9
 int i,j;
//?§????????????????
struct Puzzle{
  int f[M];
  int space;
  string path;

  bool operator < (const Puzzle &p)const{
    for( i=0;i<M;i++){
      if(f[i]==p.f[i])continue;
      return f[i]>p.f[i];
    }
    return false;
  }
  
};
////

static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
static const char dir[4]={'u','l','d','r'};
///
void swapp(int *p,int *q){
  int tmp;
  tmp=*p;
  *p=*q;
  *q=tmp;
}
///
bool Target(Puzzle p){
  for(i=0;i<M;i++)if(p.f[i]!=(i+1))return false;
  return true;

}
///

///
string bfs(Puzzle s){
  map<Puzzle, bool> V;
  Puzzle u,v;
  queue<Puzzle> Q;
  s.path="";
  Q.push(s);
  V[s]=true;

  while(!Q.empty()){
    u=Q.front();
    Q.pop();
    if(Target(u))return u.path;
    int sx=u.space/N;
    int sy=u.space%N;

    for(int r=0;r<4;r++){
      int tx=sx+dx[r];
      int ty=sy+dy[r];
      if(tx<0 || ty<0 || tx>=N || ty>=N)continue;
      v=u;
      swapp(&v.f[u.space],&v.f[tx*N+ty]);
      v.space=tx*N+ty;
      if(!V[v]){
	V[v]=true;
	v.path+=dir[r];
	Q.push(v);
      } 
    }
  }
  return "unsolvable";
}
///

int main(){
  Puzzle in;

  for(i=0;i<M;i++){
    cin >>in.f[i];
    if(in.f[i]==0){
      in.f[i]=M;
      in.space=i;
    }
  }

  string ans=bfs(in);
  cout << ans.size() << endl;
  return 0;

}

Measured memory_bytes: 30560
n=int(input())
a=[int(x) for x in input().rstrip().split()]
a.sort(reverse=True)

ans=max(a)
cnt=0
for i in range(1,n):
  now=a[i]
  for s in range(2):
    if cnt+1<=n-2:
      ans+=now
      cnt+=1
print(ans)

Measured memory_bytes: 31488
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];

	var n = parseInt(line0, 10);
	var result = '';

	const dogs = 1000000000000001;
	const abcs = 'abcdefghijklmnopqrstuvwxyz';

	while (0 < n) {
		var m = n%26;
		if (m === 0) {
			m = 26;
		}
		result = abcs.substr(m-1, 1) + result;
		n = (n - m) / 26;
	}

	// console.log({
	// 	dogs: dogs,
	// 	n: n,
	// 	result: result
	// });

	console.log(result);

	// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

	//出力
	// console.log('%d %s',a+b+c,s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)


Measured memory_bytes: 29672
let digits n =
  let rec aux m ans =
    if m < 1 then ans else aux (m / 10) (succ ans)
  in
  aux n 0

let solve n =
  let b = sqrt n |> int_of_float in
  let intn = int_of_float n in
  let rec aux b' =
    if intn mod b' = 0 then max (digits b') (digits (intn / b'))
    else aux (pred b')
  in
  aux b

let () = Scanf.scanf "%f\n" solve |> Printf.printf "%d\n"

Measured memory_bytes: 384
t = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

c = [t[0]*a[0],t[1]*a[1]]
d = [t[0]*b[0],t[1]*b[1]]

if sum(c)==sum(d):
    print('infinity')
    exit()
elif c[0]==d[0]:
    print('infinity')
    exit()

if sum(d)>sum(c) and d[0]>c[0]:
    print(0)
    exit()
elif sum(c)>sum(d) and c[0]>d[0]:
    print(0)
    exit()
else:
    n = (c[0]-d[0])/(sum(d)-sum(c))
    if n==int(n):
        print(2*int(n))
    else:
        print(2*int(n)+1)


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

int N; long long S;
#define MAX_N 100000
long long X[MAX_N], P[MAX_N];
int I;
int L, R;
deque<long long> W;
long long D;

int main() {
  cin >> N >> S;
  for(int i = 0; i < N; ++i) {
    cin >> X[i] >> P[i];
    if(X[i] < S) I = i;
  }
  L = 0, R = N - 1;
  while(!(R <= I || I < L)) {
    if(P[L] >= P[R]) {
      P[L] += P[R]; W.push_front(X[R]); --R;
    } else {
      P[R] += P[L]; W.push_front(X[L]); ++L;
    }
  }
  if(R <= I) W.push_front(X[L]);
  else W.push_front(X[R]);
  long long p = S;
  while((int)W.size() > 0) {
    D += abs(p - W.front()); p = W.front(); W.pop_front();
  }
  cout << D << endl;
  return 0;
}


Measured memory_bytes: 2560
s = int(input())
hashtable = {s:1}
counter = 1
flag = True
while flag:
    if s%2 == 0:
        s /= 2
    else:
        s = 3*s + 1
    counter += 1
    
    if s in hashtable.keys():
        flag = False
    else:
        hashtable[s] = 1
    
print(counter)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
	int n,a[1000];
	scanf("%d",&n);
	for(int i = 0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i = n-1;i>0;i--){
		printf("%d ",a[i]);
	}
	printf("%d\n",a[0]);
}

Measured memory_bytes: 2708
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, M, K; cin >> N >> M >> K;
  vector<ll> A(N), B(M), SA(N+1), SB(M+1);
  for (ll i = 0; i < N; i++) {
    cin >> A.at(i);
    SA.at(i+1) = SA.at(i) + A.at(i);
  }
  for (ll i = 0; i < M; i++) {
    cin >> B.at(i);
    SB.at(i+1) = SB.at(i) + B.at(i);
  }
  ll ans = 0;
  ll i = 0;
  while (i < N && SA.at(i+1) <= K) i++;
  if (SA.at(i) > K) i--;
  ll j = 0;
  while (true) {
    while (j < M && SA.at(i) + SB.at(j) <= K) j++;
    if (SA.at(i) + SB.at(j) > K) j--;
    ans = max(ans, i + j);
    if (i == 0) break;
    i--;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 9496
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int k;cin>>k;
	for (int i=0; i<k; i++)
		if (s[i]!='1'){
			cout<<s[i];
			return 0;
	    }
	cout<<1;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = list(map(int, inputs))
    B = copy.copy(A)
    B.sort()
    first_num = B[-1]
    second_num = B[-2]
    ret = ''
    for a in A:
        if a == first_num:
            ret += str(second_num) + '\n'
        else:
            ret += str(first_num) + '\n'
    return ret.strip()


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)


Measured memory_bytes: 29236
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
#include <float.h>
using namespace std;


int main() {
	int n, a[100];
	unsigned long long int alice = 0, bob = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		if (i % 2 == 0) {
			alice += a[n - 1 - i];
		}
		else {
			bob += a[n - 1 - i];
		}
	}
	cout << alice - bob << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair < int, int >
#define pll pair < ll, ll >
#define pb push_back
#define maxn 100005
using namespace std;

int main()
{
    int l, b = 0;
    string s;

    cin >> l >> s;

    vector < int > r, g;
    map < int, bool > mp;

    for(int i = 0; i < l; i++){
        if(s[i] == 'R') r.pb(i);
        else if(s[i] == 'G') g.pb(i);
        else b++, mp[i] = 1;
    }

    int rs = r.size(), gs = g.size();
    ll ans = 0;

    for(int i = 0; i < rs; i++){
        for(int j = 0; j < gs; j++){
            int tmp = abs(r[i] - g[j]);

            ans += b;

            if(mp[r[i] + tmp]) ans--;
            if(mp[r[i] - tmp]) ans--;
            if(mp[g[j] + tmp]) ans--;
            if(mp[g[j] - tmp]) ans--;
            if((r[i] + g[j]) % 2 == 0 && mp[(r[i] + g[j]) / 2]) ans--;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4160
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define REP(i, k) for (decltype(k) i = 0; i < k; i++)
#define LOOP(k) REP (ngtkana_is_a_genius, k)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    u32 n, k; std::string s;
    std::cin >> n >> k >> s;

    bool rev = false; u32 pos = 0;
    auto flip = [&](char& c) { c=c=='A'?'B':'A'; };
    auto move = [&] {
        if (rev^(s.at(pos%n)=='A')) flip(s.at(pos%n));
        else rev^=1, ++pos;
    };
    for (; k; k--, move()) {
        if (pos==n) {
            if (k%2) k--, move();
            break;
        }
    }
    std::rotate(s.begin(), s.begin()+pos%n, s.end());
    if (rev) for (char& c: s) flip(c);
    std::cout << s << '\n';
}


Measured memory_bytes: 792
#include <stdio.h>

typedef struct _tree_t {
	int id;
	struct _tree_t *p, *l, *r;
} tree_t;

tree_t* tree_insert(tree_t* root, int id){
	tree_t *y = NULL;
	tree_t *x = root;
	tree_t *z = (tree_t*)malloc(sizeof(tree_t));
	z->id = id;
	z->l = z->r = z->p = NULL;

	while(x != NULL) {
	    y = x;
	    if(z->id < x->id) {
	        x = x->l;
	    } else { 
	        x = x->r;
	    }
	}
	z->p = y;
	if(y == NULL) {
    	root = z;
	} else if(z->id < y->id) {
	    y->l = z;
	} else { 
	    y->r = z;
	}
	
	return root;
}

void print_preorder(tree_t *tree) {
    printf(" %d", tree->id);
    if(tree->l != NULL) print_preorder(tree->l);
    if(tree->r != NULL) print_preorder(tree->r);
}

void print_inorder(tree_t *tree) {
    if(tree->r == NULL && tree->l == NULL) {
        printf(" %d", tree->id);
    } else if(tree->r == NULL) {
        print_inorder(tree->l);
        printf(" %d", tree->id);
    } else if(tree->l == NULL) {
        printf(" %d", tree->id);
        print_inorder(tree->r);
    } else {
        print_inorder(tree->l);
        printf(" %d", tree->id);
        print_inorder(tree->r);
    }
}

int main(void) {
	int i, n, id;
	char buff[100];
	tree_t *root = NULL;
	scanf("%d\n", &n);
	for(i=0;i<n;i++) {
		scanf("%s %d\n", buff, &id);
		if(buff[0] == 'i') {
			root = tree_insert(root, id);
		} else if(buff[0] == 'p') {
			print_inorder(root);
			printf("\n");
			print_preorder(root);
			printf("\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 24044
#include <bits/stdc++.h>
using namespace std;
 
#define mem(arr,x) memset(arr,x,sizeof(arr))
#define pb push_back
#define ll long long
#define mp make_pair
#define rep(i,n)  for(ll i=0;i<n;i++)
#define repi(i,n)  for(ll i=1;i<=n;i++)
#define all(x)   (x.begin(),x.end())
 
const double PI = 3.1415926535897932;
const int mod = 1e9 + 7;  
const int inf = 1e9 + 7;
 
int max(int a,int b)
{
	if(a>b)
	return a;
	return b;
}
 
int main()
{
	
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n,x,t;
cin>>n>>x>>t;
ll ans=0,sum=0;
while(sum<n)
{
	ans+=t;
	sum+=x;
}
cout<<ans<<"\n";
	

}


Measured memory_bytes: 3612
N = int(input())
W = list(map(int, input().split()))

l = []
sum_w = sum(W)
remain = sum_w
diff = sum_w

for i in range(N-1):
    l.append(W[i])
    sum_l = sum(l)
    remain = sum_w - sum_l
    diff = min(max(remain, sum_l) - min(remain, sum_l), diff)

print(diff)


Measured memory_bytes: 39892
import sys
from pprint import pprint

def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    has_nagative_cycle = False
    for i in range(n):
        if d[i][i] < 0:
            has_nagative_cycle = True
            break
    for i in range(n):
        d[i][i] = 0
    return has_nagative_cycle

H, W = map(int, sys.stdin.readline().strip().split())
numbers = [[] for _ in range(10)]
for i in range(10):
	numbers[i] = list(map(int, sys.stdin.readline().strip().split()))

walls = [[] for _ in range(H)]
for i in range(H):
	walls[i] = list(map(int, sys.stdin.readline().strip().split()))

warshall_floyd(numbers, 10)
# pprint(numbers)

ans = 0
for h in range(H):
	for w in range(W):
		n = walls[h][w]
		ans += 0 if n == -1 or n == 1 else numbers[n][1]
		# print(n, numbers[n][1])

print(ans)

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

// int/long:            -2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:      -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n)      for (auto i=0; i<n; i++)
#define Rep1(i, n)      for (auto i=1; i<=n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P)  reverse(P.begin(), P.end())

int     main() {
        int N;
        cin >>N;
        vector<int> A(N, 0);
        Rep0(i, N)
                cin >>A.at(i);
        //Rep0(i, N) {
        //      int AA=A.at(i);
        //vector<int> AA(500000, 0);
        //vector<D> AA;
        map<ll, int> AA;
        ll S=0;
        Rep0(i, N) {
                ll ix=i-A.at(i);
                S +=AA[ix];
                AA[A.at(i)+i]++;
        }
        cout <<S <<endl;
        return 0;
}

Measured memory_bytes: 26536
# -*- coding: utf-8 -*-

import io
import sys
import math

def solve(n, p_lst):
    # implement process
    xmin = p_lst[0]
    cnt = 0
    for x in p_lst:
        if x <= xmin:
            cnt+=1
            xmin = x
            if xmin == 1:
                break
    return cnt

def main():
    # input
    n = int(input())
    p_lst = list(map(int, input().split()))
    
    # process
    ans = str( solve(n, p_lst ) )
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
1
1
"""
_EXPECTED = """\
3
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Measured memory_bytes: 32932
#define IN_MAX 10000
char primes[IN_MAX+1];
int prime[300];
int table[IN_MAX+1];

void createtable(){
  int i=2,j,n=0;
  primes[1]=1;
  for(;i<=IN_MAX;i++)
    if(!primes[i])
      for(j=i*2;j<=IN_MAX;j+=i)
        primes[j]=1;

  for(i=2;i<=IN_MAX;i++)
    if(!primes[i])prime[n++]=i;
    
  for(i=0;i<n;i++){
    int x=prime[i];
    table[x]++;
    for(j=i+1;;j++){
      x+=prime[j];
      if(x>IN_MAX)break;
      table[x]++;
    }
  }
}

int main(){
  int n;
  createtable();
  while(1){
    scanf("%d",&n);
    if(!n)return 0;
    printf("%d\n",table[n]);
  }
}

Measured memory_bytes: 648
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N = int(input())
    p_list = list(map(int, input().split()))

    p_list = sorted(p_list)
    f = p_list[int(N/2 - 1)]
    c = p_list[int(N/2)]

    print(c - f)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14468
#include <algorithm>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

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

  int matrix[N + 2][N + 2];
  int indeies[N + 2];
  memset(matrix, -1, sizeof(matrix));
  memset(indeies, 0, sizeof(indeies));

  int a;

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N - 1; ++j) {
      cin >> a;

      matrix[i + 1][j] = a;
    }
  }

  for (int d = 1; d <= N * N; ++d) {
    bool updated = false;
    bool checked[N + 2];
    memset(checked, false, sizeof(checked));

    for (int i = 1; i <= N; ++i) {
      if (checked[i]) continue;

      int b = indeies[i];

      if (b >= N - 1) continue;

      int opo = matrix[i][b];

      if (checked[opo]) { 
        // fprintf(stderr, "Already fighted %d\n", opo);
        continue;
      }

      int c = indeies[opo];
      int opoopo = matrix[opo][c];

      if (opoopo == i) {
        // fprintf(stderr, "Day %d: %d - %d\n", d, i, opo);
        updated = true;
        ++indeies[i];
        ++indeies[opo];
        checked[i] = true;
        checked[opo] = true;
      }
    }

    if (!updated) {
      cout << -1 << endl;
      return 0;
    }

    bool finished = true;

    for (int i = 1; i <= N && finished; ++i) {
      if (indeies[i] < N - 1) finished = false;
    }

    if (finished) {
      cout << d << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 4224
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

struct Apple {
  int color;
  ll value;

  Apple(int color = -1, ll value = -1) {
    this->color = color;
    this->value = value;
  }

  bool operator>(const Apple &n) const {
    return value < n.value;
  }
};

int main() {
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vector<ll> P;
  vector<ll> Q;
  vector<ll> R;

  priority_queue <Apple, vector<Apple>, greater<Apple>> pque;

  int RED = 0;
  int GREEN = 1;
  int WHITE = 2;

  int p, q, r;
  for (int i = 0; i < A; ++i) {
    cin >> p;
    pque.push(Apple(RED, p));
  }

  for (int i = 0; i < B; ++i) {
    cin >> q;
    pque.push(Apple(GREEN, q));
  }

  for (int i = 0; i < C; ++i) {
    cin >> r;
    pque.push(Apple(WHITE, r));
  }

  int cnt = X + Y;
  ll ans = 0;

  while (cnt > 0) {
    Apple apple = pque.top();
    pque.pop();

    if (apple.color == RED) {
      if (X > 0) {
        ans += apple.value;
        X--;
      } else {
        continue;
      }
    } else if (apple.color == GREEN) {
      if (Y > 0) {
        ans += apple.value;
        Y--;
      } else {
        continue;
      }
    } else {
      ans += apple.value;
    }

    --cnt;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 10604
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    ll N;
    cin>>N;
    v f(N+1,0);
    rep(x,1,101)rep(y,1,101)rep(z,1,101){
        if(x*x + y*y + z*z +x*y +y*z + z*x > N)continue;
        f[x*x + y*y + z*z +x*y +y*z + z*x]++;
    }
    rep(i,1,N+1)cout<<f[i]<<endl;
    return 0;
}

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

namespace ConsoleApp15
{
    class Class316
    {
        static int N;
        static long K;
        static int[] A;
        static long loop = 0;
        static long s = 0;
        static int[] T1;
        static int[] T2;
        static void Main()
        {
            var NK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            N = (int)NK[0];
            K = NK[1];
            A = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            T1 = Enumerable.Repeat(-1, N).ToArray();
            T2 = Enumerable.Repeat(-1, N).ToArray();
            Search(0, 0);

            if (K >= s)
            {
                Console.WriteLine(T2.ToList().IndexOf((int)((K-s)%loop))+1);
            }
            else
            {
                Console.WriteLine(T1.ToList().IndexOf((int)K)+1);
            }
        }
        static void Search(int now, int count)
        {
            T1[now] = count;
            if (T1[A[now]]==-1)
            {
                Search(A[now], ++count);
            }
            else { Search2(A[now], 0); s = count + 1; }
        }
        static void Search2(int now, int count)
        {
            T2[now] = count;
            if (T2[A[now]]==-1)
            {
                Search2(A[now], ++count);
            }
            else
            {
                loop = count + 1;
            }
        }
    }
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    LL x;
    cin>>x;
    LL ans=(x/500)*1000+((x%500)/5)*5;
    cout<<ans;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = TEN(9) + 10;
const int mod = TEN(9) + 10;



signed main()
{
	double r; cin >> r;
	const double PI = 3.141592653589;

	printf("%.10f\n", 2*PI*r);
}




Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 int i,j,l,n,s;
 l=s=0;
 cin >> n;
 int a[n];
 for(i=0;i<n;i++)
 cin >> a[i];
 sort(a,a+n);
 for(i=0;i<n;i++)
 l+=(a[i]-a[0])*(a[i]-a[0]);
 for(j=a[0];j<=a[n-1];j++)
 {
  s=0;
  for(i=0;i<n;i++)
  s+=(a[i]-j)*(a[i]-j);
  l=min(l,s);
 }
 cout << l;
 return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define rrep(i, n) for(int i=n-1; i > -1; i--)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 100000000
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

ll mod = 1000000007;

// a^n mod を計算 再帰
ll modpow(ll a,ll n,ll &mod){
  if(!n) return 1;
  ll x = modpow(a,n/2,mod)%mod;
  x *=x;
  if(n%2==1)x*=a;
  return x%mod;
}

// a^n mod を計算する bit
ll modpow2(ll a,ll n,ll &mod){          // n=45,a=3
  ll res = 1;
  while(n>0){                          //桁数比較 with 000001
    if(n & 1) res = res * a%mod;     // flag たってるところで何乗か済のaかける
    a = a*a%mod;                       //毎度倍々
    n >>=1;                            //右シフト
  }
  return res;
}

//逆元求める
ll inv(ll x,ll &mod){
  return modpow2(x,mod-2,mod);
}

//------階乗と逆元の前処理--modC2用--------------------------------------------------------------
ll f[1010101],rf[1010101];
void init(){
  f[0]=1;
  reps(i,1010100) f[i]=(f[i - 1] * (i)) % mod; //階乗メモ化
  rf[1010101-1]=inv(f[1010101-1],mod);
  rrep(i,1010100) rf[i] = (rf[i+1]*(i+1)) % mod;
}
//---------------------------------------------------------------------------------------------------

//big N like N=10^9 but adding only FEW times
ll modC(ll n,ll a,ll &mod){
  ll fac=1;
  ll ifac=1;
  rep(i,a)fac = (n-i) * fac%mod;
  reps(i,a)ifac= i*ifac%mod;
  return modpow2(ifac,mod-2,mod)*fac%mod;
}

//middle N like N=10^5 but adding MANY times
ll modC2(ll n,ll a,ll &mod){
  ll fac=f[n];         // = n!
  ll ifac=(rf[n-a]*rf[a])%mod; //=(n-a)! a!
  return ifac*fac%mod;
}


int main() {
  init();
  ll n,k;
  cin >> n >> k;
  k=min(k,n-1);
  ll ans=0;
  for(int i=0;i<=k;i++){
    ans += (modC2(n,i,mod)*modC2(n-1,i,mod))%mod;
    ans = ans%mod;
  }

  cout << ans;
}

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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> counts(k + 1, 0);
    vector<int> v(n);
    
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    
    int total = 0;
    
    int ans = 1000000000;
    for (int l = 0, r = 0; r < n; r++) {
        if (v[r] > k) {
            continue;
        } 
        counts[v[r]]++;
        if (counts[v[r]] == 1) {
            total++;
        }
        while (l < r && (v[l] > k || (total == k && counts[v[l]] > 1))) {
            if (v[l] <= k) {
                counts[v[l]]--;
            }
            l++;
        }
        if (total == k) {
            ans = min(ans, r - l + 1);
        }
        
    }
    
    cout << (total == k? ans : 0) << endl;
    
    
    return 0;
}

Measured memory_bytes: 3584