akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct { template <typename T> operator T() { T x; cin >> x; return x; } } IN;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int m=IN;
    cout<<(24-m)+24<<endl;
    return 0;
}


Measured memory_bytes: 764
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 998244353
#define mod MOD
#define sec setprecision
constexpr double eps = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll 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;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
long long com(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a) % mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	
	string s;
	cin >> s;
	if (s[0] == 'S')cout << "Cloudy" << endl;
	else if (s[0] == 'R')cout << "Sunny" << endl;
	else cout << "Rainy" << endl;
}
int main() {
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long   ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ii, ll>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e18;
const double PI = acos(-1);
#define tam 1620000
#define offset 
const ll MOD= 1e9+7;
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll minn,maxx,answer;
void go(ll h,ll w)
{
    assert(h>0);
    assert(w>0);
    minn=-1e9;maxx=1e9;
    if (w==1)return;
    minn=(h*(ll)(w/2));
    maxx=(h*(w-(ll)(w/2)));
    assert(maxx>=minn);
}
void calc(ll num)
{
    //cout<<minn<<" "<<maxx<<' '<<num<<endl;
    minn=min(minn,num);
    maxx=max(maxx,num);

    answer=min(answer,maxx-minn);

}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    ll h,w;
    cin>>h>>w;answer=1e18;
    if ((h*w)%3==0)
    {
        cout<<0<<endl;
        return 0;
    }

    forr(i,1,h)
    {
        go(h-i,w);
        calc(i*w);

        go(w,h-i);
        calc(i*w);
    }
    forr(i,1,w)
    {
        go(h,w-i);
        calc(i*h);

        go(w-i,h);
        calc(i*h);
    }
    //answer=0;
    cout<<answer<<endl;
}
// PLUS ULTRA!ac

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
#include <iostream>

int main(){
  char s[32];
  char sun[] = "Sunny";
  char cloud[] = "Cloudy";
  char rain[] = "Rainy";
  scanf("%s",s);
  unsigned long ptr;

  if(memcmp(sun,s,5)==0){
    std::cout << "Cloudy" << std::endl;
  }else if(memcmp(cloud,s,6)==0){
    std::cout << "Rainy" << std::endl;
  }else if(memcmp(rain,s,5)==0){
    std::cout << "Sunny" << std::endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
using namespace std;
int t, n, k, X[100000], A[100000], total;
int main(){
	cin >> t;
	for (int i=0; i<t; i++){
		cin >> n >> k;
		for (int j=0; j<n; j++){
			cin >> X[j];
			total=total+X[j];
		}
		for (int l=0; l+1<n; l++) A[l]=X[l+1]-X[l];
		sort(A,A+n-1);
		total=0;
		for (int m=0; m<max(0,n-k); m++) total=total+A[m];
		cout << total << endl;
	}
}

Measured memory_bytes: 1956
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 2e5;

ll N, X;

ll gcd (ll x, ll y) {
  if (x > y) swap(x, y);
  while (x > 0) {
    ll k = y;
    y = x;
    x = k%x;
  }
  return y;
}

ll solve() {
  if (X*2 == N) return X*3;
  if (X*2 > N) X = N-X;

  ll ans = 1;
  while (1) {
    ll x = gcd(X, N);
    if (x == 1) {
      return ans*3*(N-1);
    }
    N /= x;
    X /= x;
    ans *= x;
  }
}

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

  ll ans = solve();

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
l, r = map(int, input().split())
if (r-l) >= 2018:
    print(0)
else:
    num = 2019
    for i in range(l, r+1):
        for j in range(i+1, r+1):
            ans = (i*j)%2019
            if ans < num:
                num = ans
    print(num)

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

int main()
{
    int n;
    string s;
    cin >> n >> s ;
    int m = 0;
    int t = 0;
    for(int i = 0 ; i < s.length() ; i++){
        if(s[i]== 'I'){
            t += 1;;
        }else{
            t -= 1;
        }
        m = max(m , t);
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for (char x, lst = 0; n--; )
    {
        cin >> x;

        if (x != lst)
        {
            ++ans;
            lst = x;
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
mx,my;pn[7];px[7][1000],py[7][1000];M[5][7][1000];a0;Calc(a1,a2){int n1,n2,m,mm;for(n2=0;n2<pn[a2];n2++){mm=1e9;for(n1=0;n1<pn[a1];n1++){m=M[a0][a1][n1]+abs(px[a1][n1]-px[a2][n2])+abs(py[a1][n1]-py[a2][n2]);if(m<mm)mm=m;}M[a0][a2][n2]=mm;}}main(){int x,y,c,a,am;for(;scanf("%d%d\n",&mx,&my),mx;){memset(pn,0,sizeof(pn));for(y=0;y<my;y++){for(x=0;x<=mx;x++){c=getchar();if(c>='1'){if(c<='5')a=c-'0';else if(c=='S')a=0;else if(c=='G')a=6;px[a][pn[a]]=x;py[a][pn[a]++]=y;}}}am=0;for(a0=0;a0<5;a0++){M[a0][0][0]=0;Calc(0,1+(a0+1)%5);for(a=0;a<3;a++)Calc(1+(a0+a+1)%5,1+(a0+a+2)%5);Calc(1+(a0+4)%5,6);if(M[a0][6][0]<M[am][6][0])am=a0;}printf(M[am][6][0]!=1e9?"%d %d\n":"NA\n",1+am,M[am][6][0]);}{int n;for(n=900000;n--;)getchar();}exit(0);}

Measured memory_bytes: 600
N, K = map(int, input().split())
S = input()
Nums = []
now = 1
now_cnt = 0
for i in range(N):
    if S[i] == str(now):
        now_cnt += 1
    else:
        Nums.append(now_cnt)  # S[0] = 0のとき、1の数は0なので、Numsの左に0が来る
        now = 1 - now
        now_cnt = 1
Nums.append(now_cnt)

if len(Nums) % 2 == 0:
    Nums.append(0)

Add = 2 * K + 1  # 足す要素数
sum_ = 0
sum_max = 0
sum_list = [0] * (len(Nums)+1)
for i in range(len(Nums)):  # 累積和
    sum_list[i+1] = sum_list[i] + Nums[i]

for i in range(0, len(Nums), 2):
    left = i
    right = min(i + Add, len(Nums))  # 指示はなくても良い
    sum_ = sum_list[right] - sum_list[left]
    sum_max = max(sum_, sum_max)

print(sum_max)

Measured memory_bytes: 46956
{-# LANGUAGE BangPatterns, OverloadedStrings #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

unew :: VUM.Unbox a => Int -> VUM.IOVector a
unew !n = accursedUnutterablePerformIO $ VUM.unsafeNew n

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uset :: VUM.Unbox a => a -> VUM.IOVector a -> VUM.IOVector a
uset !a !v = accursedUnutterablePerformIO $ VUM.set v a >> return v

solve :: B.ByteString -> B.ByteString -> B.ByteString
solve !s !t = walk
 where
  toIndex !i !j = j * succ (B.length s) + i
  fromIndex !n = (n `mod` succ (B.length s), n `div` succ (B.length s))

  dp :: VU.Vector Int16
  dp = ufreeze $ fst $ B.foldl'
    ( \(!dp, !i) (!si) -> flip (,) (i + 1) $ fst $ B.foldl'
      ( \(!dp, !j) (!tj) -> flip (,) (j + 1) $ uwrite
        (toIndex (i + 1) (j + 1))
        ( if si == tj
          then uread (toIndex i j) dp + 1
          else max (uread (toIndex (i + 1) j) dp) (uread (toIndex i (j + 1)) dp)
        )
        dp
      )
      (dp, 0)
      t
    )
    (uset 0 $ unew $ succ (B.length s) * succ (B.length t), 0)
    s

  walk =
    fst
      $ B.unfoldrN (fromIntegral $ dp VU.! toIndex (B.length s) (B.length t))
                   (\(x:xs) -> Just $ (,) (B.index s x) xs)
      $ fst
      $ fix
          ( \(!f) (!acc, (!i, !j)) -> if i == 0 || j == 0
            then (acc, (i, j))
            else if s `B.index` (i - 1) == t `B.index` (j - 1)
              then f ((i - 1) : acc, (i - 1, j - 1))
              else if dp VU.! toIndex (i - 1) j < dp VU.! toIndex i (j - 1)
                then f (acc, (i, j - 1))
                else f (acc, (i - 1, j))
          )
          ([], (B.length s, B.length t))

main = do
  s <- B.getLine
  t <- B.getLine
  B.putStrLn $ solve s t


Measured memory_bytes: 19452
#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") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> va(a+1), vb(b+1);

    int mna = 1<<30, mnb = 1 << 30;
    REP(i,a) {
        cin >> va[i+1];
        mna = min(mna,va[i+1]);
    }
    REP(i,b) {
        cin >> vb[i+1];
        mnb = min(mnb,vb[i+1]);
    }
    int ans = mna + mnb;
    REP(i,m) {
        int x, y, c;
        cin >> x >> y >> c;
        int price = va[x] + vb[y] - c;
        ans = min(ans,price);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define all(obj) (obj).begin(), (obj).end()
static const int dx[4] = {0, 1, 0, -1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'u', 'r', 'd', 'l'};
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
int N;

signed main() {
  cin >> N;
  vector<ll> a, b(N);
  rep(i, N) {
    cin >> b[i];
    --b[i];
  }
  rep(i, N) {
    int pivot = -1;
    for (int j = (int)b.size() - 1; j >= 0; --j) {
      if (b[j] == j) {
        pivot = j;
        break;
      }
    }
    if (pivot == -1) {
      cout << -1 << endl;
      return 0;
    }
    a.push_back(pivot + 1);
    b.erase(b.begin() + pivot);
  }
  reverse(all(a));
  for (auto ele : a) {
    cout << ele << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N,K=list(map(int,input().split()))
R,S,P=list(map(int,input().split()))
T=input()
ans=0

jlist=[]
for i in range(K):
    jlist.append(T[i:N+1:K])
    
jlist2=[]
for i in range(len(jlist)):
    ind=0
    for j in range(len(jlist[i])-1):
        if jlist[i][j]==jlist[i][j+1]:
            continue
        else:
            jlist2.append(jlist[i][ind:j+1])
            ind=j+1
    jlist2.append(jlist[i][ind:])

for i in range(len(jlist2)):
    if len(jlist2[i])%2!=0:
        if jlist2[i][0]=='r':
            ans+=P*(len(jlist2[i])//2+1)
        elif jlist2[i][0]=='s':
            ans+=R*(len(jlist2[i])//2+1)
        elif jlist2[i][0]=='p':
            ans+=S*(len(jlist2[i])//2+1)
    else:
        if jlist2[i][0]=='r':
            ans+=P*(len(jlist2[i])//2)
        elif jlist2[i][0]=='s':
            ans+=R*(len(jlist2[i])//2)
        elif jlist2[i][0]=='p':
            ans+=S*(len(jlist2[i])//2)
print(ans)

Measured memory_bytes: 9588
n,k = map(int, input().split())
a = []
for i in range(n):
    a.append(int(input()))
a.reverse()
# dp[i] := i番目の数字から始めたときの最大値
dp = [0 for i in range(n)]
#####segfunc######
def segfunc(x,y):
    return max(x,y)

def init(init_val):
    #set_val
    for i in range(len(init_val)):
        seg[i+num-1]=init_val[i]   
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

max_a = 300020
#####単位元######
ide_ele = 0
num =2**(max_a-1).bit_length()
seg=[ide_ele]*(2*num - 1)
#阪堺区間に注意
dp[0] = 1
update(a[0], 1)
for i in range(1,n):
    # print("{} {}".format(max(a[i]-k, 0), min(max_a, a[i]+k+1)))
    dp[i] = query(max(a[i]-k, 0), min(max_a, a[i]+k+1)) + 1
    update(a[i], dp[i])
print(max(dp))

Measured memory_bytes: 121824
#include <stdio.h>
#include <string.h>
#define LEN 1000005
#define MAX 1000


typedef struct pp{
  char name[100];
  int t;
}P;


P Q[LEN+1];
int head, tail, n;


void initialize();
//?????\?????????????¨????
int Empty();
//?????\?????????????????????
int isFull();
//?????\?????????????????????
void enqueue(P);
//tail???????????´??????x?????????, MAX??\???????????£??????????????´??????tail???0??¨???????????°
P dequeue();
//head??????????????\???????????????????´?????????°x????????????????¨??????????head???1?¢????????????????x?????????


int main(){

  int elaps=0,c;
  int i,q;
  P u;

  scanf("%d %d", &n, &q);
  initialize();

  for ( i = 1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }

  for ( i = 1; tail != head; i++){



    if( Q[i].t > q){  
      Q[i].t = Q[i].t - q;
      elaps += q;
      Q[i] = dequeue();
      enqueue(Q[i]);
    }

    else{
     elaps += Q[i].t;
     printf("%s %d\n",Q[i].name,elaps);
     //u = dequeue();
     head++;
   }

 }
 return 0;
}


void initialize(){
  head = 0;
  tail = n;
}


void enqueue(P x){
  tail++;
  Q[tail] = x;
  //if(tail + 1 == MAX) tail = 0;
  //else

}


P dequeue(){

  P x;
  head++;
  x = Q[head];
  /*if(head + 1 == MAX) head = 0;
  else head++;*/
  return x;
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;
int main(){
    ll N,K;
    cin >> N >> K;
    ll c=N%K;
    if(c<K-c) cout << c << endl;
    else cout << K-c << endl;
    
    return 0;
}

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

using namespace std;

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

	for (int i = 0;i<26; i++) {
		char search ='a';
		if (s.find(search+i) == string::npos) {
			printf("%c", search + i);
			return 0;
		}
	}
	printf("None");
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//桁数
ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//約数全列挙
vector<ll> enum_div(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

//累乗(xのn乗%mod)
ll modpow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//階乗
ll factorial(ll n)
{
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}

ll modinv(ll a, ll mod)
{
  ll b = mod, u = 1, v = 0;
  while (b)
  {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}

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

void Main()
{
  ll n, m;
  cin >> n >> m;
  vll x(m), y(m);
  rep(i, m)
  cin >> x[i] >> y[i];
  map <ll, ll> flag;
  flag[0];
  vll ans(n, 1);
  rep(i, m)
  {
    if(flag.count(x[i] - 1)) flag[y[i] - 1];
    ans[x[i] - 1]--;
    ans[y[i] - 1]++;
    if(ans[x[i] - 1] == 0&&flag.count(x[i] - 1)) flag.erase(x[i] - 1);
  }
  fin(flag.size());
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


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

int main() {
	int a, b, c, d;

	cin >> a >> b >> c >> d;

	while (1) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			break;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int temp = 0;

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        temp = a;
        a = b;
        b = temp;

        temp = a;
        a = c;
        c = temp;

        System.out.println(a + " " + b + " " + c);
    }
}


Measured memory_bytes: 21972
import numpy as np

N = int(input())
T = [int(i) for i in input().split()]

M = int(input())

P = np.ones(M)
X = np.ones(M)

for i in range(M):
    
    P[i],X[i] = [int(i) for i in input().split()]
    
ans = sum(T)

for i in range(M):
    ans_ = int(ans + X[i] - T[int(P[i])-1])
    print(ans_)

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

using namespace std;

const int N = 100010;

int n;
vector<int> a[N];
int b[N], cnt;
int f = 0, dead = 0;

void dfs(int u, int p) {
  b[++cnt] = u;
  if (u == n) {
    f = 1;
    return;
  }
  for (int v : a[u]) {
    if (v == p) {
      continue;
    }
    dfs(v, u);
    if (f) {
      return;
    }
  }
  cnt--;
}

int go(int u, int p) {
  int res = 1;
  for (int v : a[u]) {
    if (v == p || dead == v) {
      continue;
    }
    res += go(v, u);
  }
  return res;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    a[u].push_back(v);
    a[v].push_back(u);
  }
  dfs(1, 0);
  dead = b[(cnt + 1) / 2 + 1];
  int foo = go(1, 0);
  if (foo * 2 <= n) {
    puts("Snuke");
  } else {
    puts("Fennec");
  }
  return 0;
}


Measured memory_bytes: 10752
x,y=map(int,input().split())

X=abs(x)
Y=abs(y)

if x<y:
    if x*y>0:
        print(abs(X-Y))
    elif x*y==0:
        print(abs(X-Y))
    else:
        print(abs(X-Y)+1)
else:
    if x*y>0:
        print(abs(X-Y)+2)
    elif x*y==0:
        print(abs(X-Y)+1)
    else:
        print(abs(X-Y)+1)

Measured memory_bytes: 3064
N = int(input())
h = list(map(int, input().split()))
a = list(map(int, input().split()))

num = 2
while num <= N+1:
    num *= 2

seg = [0]*(2*num-1)

#update(i,x):Aiをxに更新する
def update(i,x):
    k = i + num - 1
    while k >= 0:
        seg[k] = max(x,seg[k])
        k = (k-1)//2

#query(a,b,0,0,num):[a,b)の最大値
def query(a,b,k,l,r):
    if r <= a or b <= l:
        return -float("inf")
    elif a <= l and r <= b:
        return seg[k]
    else:
        return max(query(a,b,2*k+1,l,(l+r)//2),query(a,b,2*k+2,(l+r)//2,r))


for i in range(N):
    update(h[i], query(0,h[i],0,0,num) + a[i])

print(max(seg))

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; ++i) {
    cin >> A.at(i);
  }
  long long L=0;
  
  for (int i=0; i<N-1; ++i) {
    if (A.at(i) <= A.at(i+1)) {
    }
    
    else if ( A.at(i) > A.at(i+1)) {
      L = L + (A.at(i)-A.at(i+1));
      A.at(i+1) = A.at(i);
    }
  }
  cout << L << endl;

}

Measured memory_bytes: 4012
#include <iostream>
#include <string>
using namespace std;
int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d;
	e = c - a;
	f = d - b;
	cout << string(f, 'U') << string(e, 'R')
		<< string(f, 'D') << string(e, 'L')
		<< 'L' << string(f + 1, 'U') << string(e + 1, 'R') << 'D'
		<< 'R' << string(f + 1, 'D') << string(e + 1, 'L') << 'U' << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

class Vec {
private:
    double m_x;
    double m_y;

public:
    Vec(double x, double y)
        : m_x(x), m_y(y) {}

    double x() const { return m_x; }
    double y() const { return m_y; }

    double operator*(Vec& vec)
    {
        return (m_x * vec.y() - m_y * vec.x());
    }
};

int sign(double x);

int main()
{
    double x1, y1, x2, y2, x3, y3;
    double xp, yp;

    while (std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
        Vec vec12(x2 - x1, y2 - y1);
        Vec vec1p(xp - x1, yp - y1);
        Vec vec23(x3 - x2, y3 - y2);
        Vec vec2p(xp - x2, yp - y2);
        Vec vec31(x1 - x3, y1 - y3);
        Vec vec3p(xp - x3, yp - y3);

        double cross01 = vec12 * vec1p;
        double cross02 = vec23 * vec2p;
        double cross03 = vec31 * vec3p;
        int judge = sign(cross01) + sign(cross02) + sign(cross03);

        if (judge == 1 + 1 + 1 || judge == -1 - 1 - 1) {
            std::cout << "YES" << std::endl;
        } else {
            std::cout << "NO" << std::endl;
        }
    }

    return 0;
}

int sign(double x)
{
    return ((x >= 0)? 1: (-1));
}

Measured memory_bytes: 1224
def main():
    N, M = map(int, input().split())
    A = sorted(list(map(int, input().split())))
    BC = []
    for _ in range(M):
        B, C = map(int, input().split())
        BC.append((B, C))
    BC = sorted(BC, key=lambda x: x[1], reverse=True)
    i = 0
    for b, c in BC:
        for _ in range(b):
            if i >= len(A) or A[i] >= c:
                break
            A[i] = c
            i += 1
    print(sum(A))


main()


Measured memory_bytes: 23260
N, D = map(int, input().split())
X = [[int(x) for x in input().split()] for _ in range(N)]

def issq(n):
    """n is a square number."""
    for i in range(n + 1):
        if i * i == n:
            return True
        if i * i > n:
            return False

def distsq(X, Y):
    return sum((x - y) ** 2 for x, y in zip(X, Y))

n = sum(1 for i in range(len(X))
          for j in range(i + 1, len(X))
          if issq(distsq(X[i], X[j])))

print(n)


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

int main()
{
  string s;
  int k = 0, u = 0, p = 0, c = 0;
  cin >> s;

  for(int i=0; i<s.size(); i++) {
    if( s[i] == 'K' ) {
      k++;
    }
    else if( s[i] == 'U' ) {
      u++;
    }
    else if( s[i] == 'P' ) {
      p++;
    }
    else if( s[i] == 'C' ) {
      c++;
    }
  }

  cout << min(k, min(u, min(p, c))) << endl;

}

Measured memory_bytes: 1188
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


A, B, K = invr()
r1 = []
r2 = []
k = K
for i in range(A, B+1):
    if k > 0:
        r1.append(i)
        print(i)
    else:
        break
    k -= 1
k = K
for i in range(B, A-1, -1):
    if k > 0:
        if i not in r1:
            r2.append(i)
    else:
        break
    k -= 1
r2 = sorted(r2)
for i in r2:
    print(i)


Measured memory_bytes: 3064
// Reconstruction of tree by pre-order and in-order
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
void reconstruction(int, int);
int n;
std::vector<int> in,post;
std::queue<int> pre;
int main(){
  std::cin>>n;
  for(int i=0, tmp;i<n;i++) std::cin>>tmp, pre.push(tmp);
  for(int i=0, tmp;i<n;i++) std::cin>>tmp, in.push_back(tmp);
  reconstruction(0, n);
  for(int i=0;i<n;i++){
    if(i) std::cout<<" ";
    std::cout<<post[i];
  }
  std::cout<<std::endl;
  return 0;
}
void reconstruction(int l, int r){
  if(l >= r) return;
  int c;
  c=pre.front(), pre.pop();
  int m=distance(in.begin(), find(in.begin(), in.end(),c));
  reconstruction(l, m), reconstruction(m+1, r);
  post.push_back(c);
}

Measured memory_bytes: 3164
module Main where

main :: IO ()
main = do
  [a, b, c] <- map read . words <$> getLine
  print $ countOperation a b c

countOperation :: Integer -> Integer -> Integer -> Integer
countOperation a b c = foldl count init m 
  where 
    m = format a b c
    max = maximum m
    init = if [a, b, c] /= m then 1 else 0
    count acc y = acc + (max - y) `div` 2


format :: Integer -> Integer -> Integer -> [ Integer ]
format a b c | hoge = xs
                     | poyo = toEven
                     | bazz = toOdd
 where
  xs     = [a, b, c]
  hoge   = length (filter even xs) == 3 || length (filter odd xs) == 3
  poyo   = length (filter odd xs) == 2
  bazz   = length (filter even xs) == 2
  toEven = map fuga xs
  toOdd  = map fizz xs
  fuga x = if odd x then x + 1 else x
  fizz x = if even x then x + 1 else x


Measured memory_bytes: 508
#include <stdio.h>

int main(void) {
	int a,b;
	a=0;
	b=0;
	scanf("%d %d",&a,&b);
	if(a<=b){
	printf("%d",a);
	}
	else{
		a=a-1;
		printf("%d",a);
	}
	return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))

ans = 'APPROVED'

for a in A:
    if a%2==0:
        if a%3==0 or a%5==0:
            continue
        else:
            ans = 'DENIED'
            break


print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdlib>

using namespace std;
typedef long long ll;

int h,w,k;
ll field[1001][1001];
ll loop[1001][1001];

typedef pair<ll,ll> P;

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


void dp(){
	memset(loop,0,sizeof(loop));
	loop[0][0]=k-1;
	for(ll i = 0; i < h; i++){
		for(ll j = 0; j < w; j++){
			ll prvy=i-1;
			ll prvx=j;
			if(prvy>=0&&prvx>=0&&prvy<h&&prvx<w&&loop[prvy][prvx]!=0){
				ll p=field[prvy][prvx];
				if(loop[prvy][prvx]%2==0)
					p=1;
				loop[i][j]+=loop[prvy][prvx]/2+!p;
			}
			prvy=i;
			prvx=j-1;
			if(prvy>=0&&prvx>=0&&prvy<h&&prvx<w&&loop[prvy][prvx]!=0){
				ll p=field[prvy][prvx];
				if(loop[prvy][prvx]%2==0)
					p=0;
				loop[i][j]+=loop[prvy][prvx]/2+p;
			}
		}
	}
}

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

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

int main(){

	while(cin>>h>>w>>k&&!(h==0&&w==0&&k==0)){
		for(ll i = 0; i < h; i++){
			for(ll j = 0; j < w; j++){
				ll t;
				cin>>field[i][j];
			}
		}
		dp();

		for(ll i = 0; i < 1; i++){
			ll cx,cy;
			cx=cy=0;
			while(1){
				if(cx>=w||cy>=h)
					break;
				if(loop[cy][cx]%2==0){
					if(field[cy][cx]){
						field[cy][cx]=0;
						cx++;
					}
					else{
						field[cy][cx]=1;
						cy++;
					}
				}
				else{
					if(!field[cy][cx]){
						field[cy][cx]=0;
						cx++;
					}
					else{
						field[cy][cx]=1;
						cy++;
					}
				}
			}
			cout<<cy+1<<" "<<cx+1<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 16000
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
ll d[2][500][500];
vector<ll> v[2];
typedef pair<int, P> speP;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
bool used[2][500][500];
void solve() {
	int r;
	while (cin >> r,r) {
		int w[2], h[2], x[2], y[2];
		rep(i, 2) {
			cin >> w[i] >> h[i] >> x[i] >> y[i]; x[i]--; y[i]--;
			rep(j, h[i]) {
				rep(k, w[i]) {
					cin >> d[i][j][k];
					used[i][j][k] = false;
				}
			}
			v[i].clear(); v[i].resize(w[i] * h[i] + 1, 0);
		}
		rep(id, 2) {
			int cnt = 1;
			priority_queue<speP,vector<speP>,greater<speP>> q;
			q.push({ 0,{y[id],x[id]} });
			used[id][y[id]][x[id]] = true;
			int num = 1;
			while (!q.empty()) {
				speP p = q.top(); q.pop();
				int ix = p.second.first; int iy = p.second.second;
				num = max(num, p.first);
				v[id][cnt] = num; cnt++;
				rep(j, 4) {
					int nx = ix + dx[j];
					int ny = iy + dy[j];
					if (nx < 0 || ny < 0 || nx >= h[id] || ny >= w[id])continue;
					if (used[id][nx][ny])continue;
					used[id][nx][ny] = true;
					q.push({ (int)d[id][nx][ny],P{nx,ny} });
				}
			}
		}
		ll ans = mod;
		rep(i, h[0] * w[0] + 1) {
			int j = r - i;
			if (j<0 || j>w[1] * h[1])continue;
			//cout << v[0][i] << " " << v[1][j] << endl;
			ans = min(ans, v[0][i] + v[1][j]);
		}
		cout << ans << endl;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(7);
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 11820
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








int main() {
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i, h){
        cin >> s[i];
    }
    
    const ll dy[4] = {-1, 0, 1, 0};
    const ll dx[4] = {0, 1, 0, -1};
    vector<vector<bool>> used(h, vector<bool>(w));
    ll ans = 0;
    REP(i, h){
        REP(j, w){
            if(used[i][j] || s[i][j] == '.') continue;
            
            used[i][j] = true;
            queue<pair<pair<ll, ll>, char>> que;
            que.push({{i, j}, '#'});
            ll p_cnt = 0, s_cnt = 0;
            while(!que.empty()){
                auto tmp = que.front(); que.pop();
                ll y = tmp.first.first, x = tmp.first.second, e = tmp.second;
                if(s[y][x] == '.'){
                    p_cnt++;
                }
                else{
                    s_cnt++;
                }
                REP(k, 4){
                    ll yy = y + dy[k], xx = x + dx[k];
                    char c;
                    if(e == '#'){
                        c = '.';
                    }
                    else{
                        c = '#';
                    }
                    if(yy >= 0 && yy < h && xx >= 0 && xx < w && s[yy][xx] == c && !used[yy][xx]){
                        used[yy][xx] = true;
                        que.push({{yy, xx}, c});
                    }
                }
            }
            
            ans += s_cnt * p_cnt;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
using namespace std;

class str{
public:
  string s;
  int n = 0;
};

int main(){
  int n; cin >> n;
  map<string, int> m;
  for(int i = 0; i < n; i++){
    string si; cin >> si;
    m[si]++;
  }
  int maxk = 0;
  for(const auto &e : m){
    maxk = max(e.second, maxk);
  }
  for(const auto &e : m){
    if(e.second == maxk) cout << e.first << endl;
  }

  return 0;
}


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

using namespace std;

int main(){

    int  a;
    cin >> a;

    int b,c,d,e;

    b=a/1000;
    c=(a-b*1000)/100;
    d=(a-b*1000-c*100)/10;
    e=(a-b*1000-c*100-d*10);

    if((b==c||c==d)||d==e){
      cout << "Bad" <<endl;
    }
    else cout << "Good" <<endl;

    return 0;
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = (int)1e5 + 100;
int n;
ll a[maxN], b[maxN];
ll c[maxN], d[maxN];
bool check(int x) {
    ll val = 0;
    vector < ll > diff;
    for (int i = 1; i <= n; i++) {
        c[i] = -a[i];
        d[i] = max(b[i] - a[i], 0LL);
        val += d[i];
        diff.emplace_back(c[i] - d[i]);
    }
    sort(diff.begin(), diff.end());
    reverse(diff.begin(), diff.end());
    for (int i = 0; i < x; i++) val += diff[i];
    return val >= 0;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    bool ok = false;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        if (a[i] <= b[i]) {
            ok = true;
        }
    }
    if (!ok) {
        cout << 0 << " " << 1;
        return 0;
    }
    int l = 0;
    int r = n + 1;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (check(mid)) l = mid;
        else r = mid;
    }
    if (l == n) {
        cout << 1 << " " << 1;
        return 0;
    }
    ll bP = 0;
    ll bQ = 1;
    // l - good

    ll val = 0;
    vector < pair < ll, int > > diff;
    for (int i = 1; i <= n; i++) {
        c[i] = -a[i];
        d[i] = max(b[i] - a[i], 0LL);
        val += d[i];
        diff.emplace_back(c[i] - d[i], i);
    }
    sort(diff.begin(), diff.end());
    reverse(diff.begin(), diff.end());
    for (int who = 0; who < l; who++) {
        val += diff[who].first;
    }
    for (int who = 0; who < n; who++) {
        int ind = diff[who].second;
        ll new_val = val;
        if (who < l) {
            new_val -= diff[who].first;
            new_val += diff[l].first;
        }
        if (b[ind] < a[ind]) {
            new_val += b[ind] - a[ind];
        }
        if (new_val < 0) continue;
        ll nP = (new_val);
        ll nQ = b[ind];
        assert((ld)nP * bQ < 3e18 && (ld)nQ * bP < 3e18);
        if ((ld)nP * bQ > (ld)nQ * bP) {
            bP = nP;
            bQ = nQ;
        }
        //cout << bP / bQ << endl;
    }
    bP += bQ * l;
    assert((ld)bQ * l < 3e18);
    bQ *= n;
    ll d = __gcd(bP, bQ);
    cout << bP / d << " " << bQ / d;
    return 0;
}

Measured memory_bytes: 6456
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const string SALPHA="abcdefghijklmnopqrstuvwxyz";

string nstr(){
    static const int MAX_LEN = 1000001;
    static char res_[MAX_LEN];
    scanf("%s",res_);
    return string(res_);
}

int main(){
    string S = nstr();
    int N = sz(S);
    int maxLen = 20;
    
    each(a, SALPHA){
        
        rep(start, N){
            int len = 0, cnt = 0;
            FOR(i, start, min(N, start + maxLen)){
                if(S[i] == a)++cnt;
                ++len;
                if(len >= 2 && cnt > len / 2){
                    cout << (start + 1) << ' ' << (start + len) << endl;
                    exit(0);
                }
                
            }
        }
    }

    puts("-1 -1");
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int i,j=0,n,p,temp;
	int kouho[300];

		while(1){
			for(i=0;i<300;i++)
			kouho[i]=0;
			cin >> n >> p;
			temp =p;
			if(n==0) break;
			if(p!=0){
				for(i=0;;i++){
					if(i==n)	i=0;
					if(p!=0){
						kouho[i]+=1;
						p-=1;
					}
					else{
						if(kouho[i]==temp){
							cout << i;
							puts("");
							break;
						}else{
							//cout << kouho[i];
							p=kouho[i];
							kouho[i]=0;
						}
					}	//p=0
				}
			}
		}
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

bool solve(){
  int n, m;
  vector<pair<int,int> > vec;
  
  scanf("%d%d", &n,&m);

  if(n == 0)return false;
  
  for(int i=0;i<n;i++){
    int p, d;
    scanf("%d%d", &d, &p);
    vec.push_back({p, d});
  }

  sort(vec.begin(), vec.end(), greater<pair<int,int> >());

  ll ans = 0;
  
  for(int i=0;i<n;i++){
    int d = vec[i].second;
    int p = vec[i].first;

    if(d > m){
      d -= m;
      m = 0;
    }else{
      m -= d;
      d = 0;
    }

    ans += (ll)d * p;
  }


  printf("%lld\n",ans);
  return true;
}

int main(){
  while(solve());
  
  return 0;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

ld area(ld a, ld b, ld c)
{
  ld s = (a + b + c) / 2.0;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}

ld max_area(int l, int x){
  ld r = 0;
  for (ld i = 0.1; i < l + x; i += 0.1){
    ld a = l + x - i;
    r = max(r, area(l, i, a));
  }
  return r;
}

int main()
{
  int a, l, x;
  while (~scanf("%d %d %d", &a, &l, &x)){
    printf("%.10Lf\n", area(a, l, l) + 2 * max_area(l, x));
  }
  return 0;
}

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

int main() {
  string s,t;
  cin >> s >> t;
  
  if(s.at(0) == t.at(2) && s.at(1) == t.at(1) && s.at(2) == t.at(0)){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=(n)-1;i>j-1;i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,a,sum=0,low=N;
    vector<lli> vec;
    lli i,j,k;
    cin>>n;
    rep(i,0,n){
        cin>>a;
        vec.push_back(a);
    }
    sort(vec.begin(),vec.end(),greater<lli>());
    rep(i,0,n-1){
        if(i==0){
            sum+=vec[i];
//            cout<<vec[i]<<"を加える"<<endl;
        }
        else{
            sum+=vec[(i+1)/2];
//            cout<<vec[(i+1)/2]<<"を加える"<<endl;
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 5360
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include<unordered_map>
using namespace std;
const long long int mod1=1000000007;
const long long int mod2 = 998244353;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define inf mod1
#define all(x) x.begin(),x.end()
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
    fast;
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        ll n;
        cin >> n;
        ll h[n];
        for(int i = 0; i < n; i++){
            cin >> h[i];
        }
        ll dp[n];
        dp[0] = 0;
        dp[1] = abs(h[1] - h[0]);
        for(int i = 2; i < n; i++){
            dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
        }
        cout << dp[n - 1] << endl;
    }
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long double ld;

static const long long MOD = 1000000007;

int ans;

int main(void) {
    int A, B;
    cin >> A >> B;

    rep(i, 1, 200000) {
        int x = i*0.08;
        int y = i*0.1;
        if (x==A && y==B) {
            cout << i << endl;
            return 0; 
        }

    }


  
    puts("-1");

	return 0;
}


Measured memory_bytes: 256