akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE
  ScopedTypeVariables, BangPatterns, TupleSections, ExplicitForAll,
  LambdaCase, MultiWayIf, Unsafe, RecordWildCards, FlexibleContexts, CPP,
  NoMonomorphismRestriction, GADTs,
  RankNTypes, EmptyDataDecls, EmptyCase, ViewPatterns #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import qualified Data.IntMap.Lazy as IML
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import Data.Word
import System.IO
import Data.Function
import Control.Monad.Primitive
import qualified Data.Vector.Primitive.Mutable as VPM
import qualified Data.Vector.Generic.Mutable as VGM
import Data.STRef
import Data.IORef


main :: IO ()
main = do
  [k,a,b] <- map readInt . words <$> getLine
  print $ if b - a <= 1 || k <= a - 1 then k+1 else
    let left = k - (a - 1)
        mults = left `shiftR` 1
        more = if testBit left 0 then 1 else 0
    in a + more + (b-a) * mults
        

rInt :: StateT BSL.ByteString Maybe Int
rInt = StateT $ BSL.readInt . BSL.dropWhile (<'!')

#define D(f,r,d) f::Integral a=>a->d;f=fromIntegral;r::String->d;r=read
#define C(f,r,g,h,d) D(f,r,d);g,h::RealFrac a=>a->d;g=floor;h=ceiling
C(_toInteger_,readInteger,floorInteger,ceilInteger,Integer)
C(toInt,readInt,floorInt,ceilInt,Int)
C(toI8,readI8,floorI8,ceilI8,Int8)
C(toI16,readI16,floorI16,ceilI16,Int16)
C(toI32,readI32,floorI32,ceilI32,Int32)
C(toI64,readI64,floorI64,ceilI64,Int64)
C(toWord,readWord,floorWord,ceilWord,Word)
C(toW8,readW8,floorW8,ceilW8,Word8)
C(toW16,readW16,floorW16,ceilW16,Word16)
C(toW32,readW32,floorW32,ceilW32,Word32)
C(toW64,readW64,floorW64,ceilW64,Word64)
D(toDouble,readDouble,Double)
D(toFloat,readFloat,Float)
#undef D
#undef C


#define N(f,g,a,m)\
  f :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> e -> m (a i e); f=A.newArray;\
  g :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> m (a i e); g=A.newArray_
#define C(a,m)
N(newIOA,newIOA_,IOArray,IO)
N(newSTA,newSTA_,STArray s,ST s)
#undef C
#define C(a,m) MArray (a) e (m), 
N(newIOUA,newIOUA_,IOUArray,IO)
N(newSTUA,newSTUA_,STUArray s,ST s)
#undef C
#undef N



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

namespace ABC154
{
    class E
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int K = int.Parse(Console.ReadLine());

            int[,,] dp = new int[105, 4, 2];
            dp[0, 0, 0] = 1;

            for (int i = 0; i < N.Length; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        int nd = N[i] - '0';
                        for (int d = 0; d < 10; d++)
                        {
                            int ni = i + 1;
                            int nj = j;
                            int nk = k;
                            if (d != 0) nj++;
                            if (nj > K) continue;
                            if (k == 0)
                            {
                                if (d > nd) continue;
                                if (d < nd) nk = 1;
                            }
                            dp[ni, nj, nk] += dp[i, j, k];
                        }
                    }
                }
            }
            Console.WriteLine(dp[N.Length, K, 0] + dp[N.Length, K, 1]);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main(){
    speed();
    int n; cin >> n;
    int A[n];
    rep(i, 0, n) cin >> A[i];
    int O[n];
    rep(i, 0, n) O[A[i]-1] = i + 1;
    rep(i, 0, n) cout << O[i] << " ";
    return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 300000;
const int MaxM = 100000;

int n, m;
int sum[MaxM + 2];

struct interval
{
	int l, r;
	interval() {}
	interval(const int &_l, const int &_r)
		: l(_l), r(_r) {}

	inline int length() const
	{
		return r - l + 1;
	}

	friend inline bool operator<(const interval &lhs, const interval &rhs)
	{
		return lhs.r - lhs.l < rhs.r - rhs.l;
	}
};
interval a[MaxN];

int bit[MaxM + 2];

void bit_add(int x, int d)
{
	for (int i = ++x; i <= m + 2; i += i & -i)
		bit[i] += d;
}

int bit_query(int x)
{
	int res = 0;
	for (int i = ++x; i; i ^= i & -i)
		res += bit[i];
	return res;
}

int main()
{
	cin >> n >> m;

	sum[1] = n;
	for (int i = 0; i < n; ++i)
	{
		a[i].l = getint();
		a[i].r = getint();
		--sum[min(m, a[i].r - a[i].l + 1) + 1];
	}

	for (int i = 2; i <= m; ++i)
		sum[i] += sum[i - 1];

	sort(a, a + n);

	int cur = 0;
	for (int i = 1; i <= m; ++i)
	{
		for (int k = 0; k <= m; k += i)
			sum[i] += bit_query(k);

		printf("%d\n", sum[i]);

		while (cur < n && a[cur].length() == i)
		{
			bit_add(a[cur].l, 1);
			bit_add(a[cur].r + 1, -1);
			++cur;
		}
	}

	return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int min = a+b;
  if(b+c<min) min=b+c;
  if(a+c<min) min=a+c;
  cout << min << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
int main()
{
    fastio();
    string s;
    cin>>s;
    if(s=="MON")
        cout<<6;
    else if(s=="TUE")
        cout<<5;
    else if(s=="WED")
        cout<<4;
    else if(s=="THU")
        cout<<3;
    else if(s=="FRI")
        cout<<2;
    else if(s=="SAT")
        cout<<1;
    else if(s=="SUN")
        cout<<7;
}

Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
#define LL long long
typedef pair<int,int> PII;
map<PII,int>Q;
int ans[10],cnt;
int main()
{
	int n,m,k,u,v;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<k;i++)
	{
		scanf("%d%d",&u,&v);
		for(int i=-2;i<=0;i++)
		{
			if(i+u<=0) continue;
			if(i+u>=n-1) break;
			for(int j=-2;j<=0;j++)
			{
				if(v+j<=0) continue;
				if(v+j>=m-1) break;
				Q[PII(i+u,j+v)]++;
			}
		}
	}
	for(map<PII,int>::iterator it=Q.begin();it!=Q.end();it++)
	{
		ans[it->second]++;
		cnt++;
	}
	LL tot=1LL*(n-2)*(m-2)-cnt;
	printf("%lld\n",tot);
	for(int i=1;i<=9;i++)
		printf("%d\n",ans[i]);
}

Measured memory_bytes: 56448
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }



int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	int grid[n][m];
	memset(grid, 0, sizeof grid);
	int q;
	cin >> q;
	int ans = n * m;
	forn(i, q){
		int x, y, a;
		cin >> x >> y >> a;
		if(a == 1){
			forn(i, x)forn(j, m)grid[i][j] = 1;
			//ans -= (x * m);
		}else if(a == 2){
			fore(i, x, n - 1)forn(j, m)grid[i][j] = 1;
			//ans -= (n - x) * m;
		}else if(a == 3){
			forn(i, n)forn(j, y)grid[i][j] = 1;
			//ans -= n * y;
		}else{
			forn(i, n)fore(j, y, m - 1)grid[i][j] = 1;
			//ans -= n * (m - y);
		}
	}
	int firstx = n + 1, lastx = -1, firsty = m + 1, lasty = -1;
	forn(i, n){
		forn(j, m){
			//cout << grid[i][j] << ' ';
			if(grid[i][j] == 0){
				firstx = min(firstx, i);
				lastx = max(lastx, i);
				firsty = min(firsty, j);
				lasty = max(lasty, j);
			}
		}
		//cout << '\n';
	}
	if(firstx == n + 1 || lastx == -1 || firsty == m + 1 || lasty == -1){
		cout << 0;
		return 0;
	}
	deb(firstx, lastx, firsty, lasty);
	cout << (lastx - firstx + 1) * (lasty - firsty + 1);
	return 0;
}


Measured memory_bytes: 384
use std::str::FromStr;
use std::io::{ self };
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    let lines = stdin.lock().lines();

    for line in lines {
        if let Ok(line) = line {
            let sum = line.trim().split(" ").collect::<Vec<&str>>()
                .iter()
                .map(|v|{
                    u32::from_str(v).unwrap()
                })
                .fold(0, |a,b|a+b);
            let l = sum.to_string().len();
            println!("{}",l);
        } else { break }
    }
}


Measured memory_bytes: 5036
#include <bits/stdc++.h>
#include <stdlib.h>
#define MAX 1e9
using namespace std;
int main(){
    int d,g;
    cin>>d>>g;
    int p[d],c[d],i;
    for(i=0;i<d;i++) cin>>p[i]>>c[i];
    
    int ans=MAX,j;
    for(j=0; j<(1<<d);j++){
        int s=0,num=0,r_max=-1;
        for(i=0;i<d;i++){
            if(j>>i&1){
                s+= 100*(i+1)*p[i]+c[i];
                num+=p[i];
            }
            else r_max=i;
        }
        int s1,need;
        if(s<g){
            s1=100*(r_max+1);
            need=(g-s+s1-1)/s1;
            if(need>=p[r_max]) continue;
            num+=need;
        }
        ans=min(ans,num);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    if(N==2) dame;
    vector<ll> ans(N,0);
    priority_queue<ll,vector<ll>,greater<ll>> qu;
    reps(i,1,N) qu.emplace(i+1);
    ans[0]=1;
    reps(i,1,N-1){
        if(A[ans[i-1]-1]==qu.top()){
            ll x=qu.top(); qu.pop();
            ans[i]=qu.top(); qu.pop();
            qu.emplace(x);
        }
        else{
            ans[i]=qu.top(); qu.pop();
        }
    }
    ans[N-1]=qu.top();
    ll yy=ans[N-1];
    ll here=N-1;
    while(here!=0 and A[ans[here-1]-1]==ans[N-1]){
        --here;
    }
    priority_queue<ll,vector<ll>,greater<ll>> qu2;
    reps(i,here,N-1) qu2.emplace(ans[i]);
    ans[here]=yy;
    reps(i,here+1,N-1){
        if(A[ans[i-1]-1]==qu2.top()){
            ll x=qu2.top(); qu2.pop();
            ans[i]=qu2.top(); qu2.pop();
            qu2.emplace(x);
        }
        else{
            ans[i]=qu2.top(); qu2.pop();
        }
    }
    if(!qu2.empty()) ans[N-1]=qu2.top();
    ll x1=ans[N-3],x2=ans[N-2],x3=ans[N-1];

    vector<ll> r={x1,x2,x3};
    SORT(r);
    do{
        ans[N-3]=r[0],ans[N-2]=r[1],ans[N-1]=r[2];
        bool ok=true;
        reps(i,1,N){
            if(A[ans[i-1]-1]==ans[i]) ok=false;
        }
        if(ok) break;
    }while(next_permutation(r.begin(),r.end()));

    rep(i,N){
        cout<< ans[i] <<" ";
    }
    cout<<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

signed main(){
  int n,m;cin>>n>>m;
  vector<int> ball(n,1);
  vector<int> re(n,0);
  re[0]++;
  while(m--){
    int x,y;cin>>x>>y;x--;y--;
    re[y]|=re[x];
    ball[x]--;ball[y]++;
    if(!ball[x])re[x]=0;
  }
  int ans=0;
  for(int i=0;i<n;i++)ans+=re[i];
  cout<<ans<<endl;
}


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

int main() {
   int a, b, c;
   cin >> a >> b >> c;
   int x = (a + b + c) / 2;
   if((a + b + c) & 1) puts("No");
   else if(x == a or x == b or x == c) puts("Yes");
   else puts("No");
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	string T;
	cin >> T;
	rep(i, T.size()) {
		if (T[i] == '?') {
			T[i] = 'D';
		}
	}
	cout << T << endl;
}

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

using namespace std;
using ll = long long;

int main() {
	int q;
	scanf("%d", &q);

	multiset<int> lo, hi;
	ll slo = 0, shi = 0;
	ll sum = 0;
	while(q--) {
		int t;
		scanf("%d", &t);
		if(t == 1) {
			int a, b;
			scanf("%d %d", &a, &b);
			sum += b;
			lo.insert(a);
			slo += a;
			if(!hi.empty() and *lo.rbegin() > *hi.begin()) {
				shi += *lo.rbegin();
				slo -= *lo.rbegin();
				hi.insert(*lo.rbegin());
				lo.erase(prev(lo.end()));
			}
			int tot = int(lo.size() + hi.size());
			int me = tot / 2;
			while((int)hi.size() < me) {
				shi += *lo.rbegin();
				slo -= *lo.rbegin();
				hi.insert(*lo.rbegin());
				lo.erase(prev(lo.end()));
			}
			while((int)hi.size() > me) {
				shi -= *hi.begin();
				slo += *hi.begin();
				lo.insert(*hi.begin());
				hi.erase(hi.begin());
			}
		}
		else {
			int x = *lo.rbegin();
			ll val = sum + 1LL * x * int(lo.size()) - slo;
			val += shi - 1LL * x * int(hi.size());
			printf("%d %lld\n", x, val);

		}
	}
}


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

void get_dict(int n, vector<int> nums, vector<vector<int>> &dict)
{
  if (nums.size() == n)
  {
    dict.push_back(nums);
    return;
  }
  for (int i = 1; i <= n; i++)
  {
    bool contain = false;
    for (int j = 0; j < nums.size(); j++)
    {
      if (i == nums.at(j))
      {
        contain = true;
        break;
      }
    }
    if (!contain)
    {
      nums.push_back(i);
      get_dict(n, nums, dict);
      nums.pop_back();
    }
  }
}

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

  vector<int> P(N);
  vector<int> Q(N);
  for (int i = 0; i < N; i++)
  {
    cin >> P.at(i);
  }
  for (int i = 0; i < N; i++)
  {
    cin >> Q.at(i);
  }

  vector<vector<int>> dict;
  vector<int> nums;
  get_dict(N, nums, dict);

  int p_i = 0;
  int q_i = 0;
  for (int i = 0; i < dict.size(); i++)
  {
    if (P == dict.at(i))
    {
      p_i = i;
    }
    if (Q == dict.at(i))
    {
      q_i = i;
    }
  }
  cout << abs(p_i - q_i) << endl;
}


Measured memory_bytes: 3256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    
    println!("{}", ((n - n/2) as f64 / n as f64) as f64);
}



Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <ctime>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <vector>
#include <iostream>
#include <cstring>
#include <set>
#include <map>
#include <string>

namespace fastinput
{
	/** Interface */

	inline int readChar();
	template <class T = int> inline T readInt();
	template <class T> inline void writeInt(T x, char end = 0);
	inline void writeChar(int x);
	inline void writeWord(const char *s);

	/** Read */

	static const int buf_size = 16384;

	inline int getChar() {
		static char buf[buf_size];
		static int len = 0, pos = 0;
		if (pos == len)
			pos = 0, len = fread(buf, 1, buf_size, stdin);
		if (pos == len)
			return -1;
		return buf[pos++];
	}

	inline int readChar() {
		int c = getChar();
		while (c <= 32)
			c = getChar();
		return c;
	}

	template <class T>
	inline T readInt() {
		int s = 1, c = readChar();
		T x = 0;
		if (c == '-')
			s = -1, c = getChar();
		while ('0' <= c && c <= '9')
			x = x * 10 + c - '0', c = getChar();
		return s == 1 ? x : -x;
	}

	/** Write */

	static int write_pos = 0;
	static char write_buf[buf_size];

	inline void writeChar(int x) {
		if (write_pos == buf_size)
			fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
		write_buf[write_pos++] = x;
	}

	template <class T>
	inline void writeInt(T x, char end) {
		if (x < 0)
			writeChar('-'), x = -x;

		char s[24];
		int n = 0;
		while (x || !n)
			s[n++] = '0' + x % 10, x /= 10;
		while (n--)
			writeChar(s[n]);
		if (end)
			writeChar(end);
	}

	inline void writeWord(const char *s) {
		while (*s)
			writeChar(*s++);
	}

	struct Flusher {
		~Flusher() {
			if (write_pos)
				fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
		}
	} flusher;
}

using namespace fastinput;
using namespace std;

int main()
{
	::ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector <int> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	int res = 2e9;
	for (int x = -100; x <= 100; ++x)
	{
		int cur = 0;
		for (int i = 0; i < n; ++i)
		{
			cur += abs(v[i] - x) * abs(v[i] - x);
		}
		res = min(res, cur);
	}
	cout << res << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

string N;
ll dp[1123456][2];

ll dfs(int i, int kasu) {
	if (i == N.size()) return kasu;
	ll &res = dp[i][kasu];
	if (res != longINF) return res;
	
	int num = N[i] - '0';
	
	if (kasu) {
		chmin(res, 1 + num + dfs(i + 1, 0));
		chmin(res, 9 - num + dfs(i + 1, 1));
	}
	else {
		chmin(res, num + dfs(i + 1, 0));
		chmin(res, 10 - num + dfs(i + 1, 1));
	}
	return res;
}

int main() {
	cin >> N;
	fill(dp[0], dp[1123456], longINF);
	
	reverse(ALL(N));
	cout << dfs(0, 0) << endl;
	return 0;
}


Measured memory_bytes: 81412
#include <bits/stdc++.h>
using namespace std;
int a[3];
int main()
{
    for(int i=0;i<=2;i++)
        cin>>a[i];
    int mx=-1;
    for(int i=0;i<=2;i++)
        if(a[i]>mx)
        mx=a[i];
    int ans=1;
    for(int i=0;i<=2;i++)
        if(a[i]!=mx)
            ans*=a[i];
    cout<<ans/2<<endl;
    return 0;
}


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

int main(){
  int X, Y;
  cin >> X >> Y;
  int ans=0;
  if(X==1 && Y==1){
    ans+=400000;
  }
  if(X==1 || X==2 || X==3){
    ans+=100000+(3-X)*100000;
  }
  if(Y==1 || Y==2 || Y==3){
    ans+=100000+(3-Y)*100000;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
int main(void)
{
	int mansions[4][3][10];
	int m,w,h,d;
	int n;
	
	int i,j,k;
	
	for(m = 0;m < 4;m++){
		for(h = 0;h < 3;h++){
			for(w = 0;w < 10;w++){
				mansions[m][h][w] = 0;
			}
		}
	}
	
	scanf("%d",&n);
	
	for(i = 0;i < n;i++){
		scanf("%d %d %d %d",&m,&h,&w,&d);
		if(0<m&&m<5&&0<h&&h<4&&0<w&&w<11)
			mansions[m-1][h-1][w-1] += d;
	}
	
	for(m = 0;m < 4;m++){
		for(h = 0;h < 3;h++){
			for(w = 0;w < 10;w++){
				printf(" %d",mansions[m][h][w]);
			}
			printf("\n");
		}
		if(m != 3)printf("####################\n");		
	}
	return 0;
}

Measured memory_bytes: 612
# include <iostream>
# include <algorithm>
# include <vector>
# include <functional>
using namespace std;

int main() {
	char s[3];
	int count = 0;

	for (int i = 0;i<3; ++i) {
		cin >> s[i];
		if (s[i] == '1') ++count;
	}
	
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, P = (int(i) for i in input().split())
    A = [int(i) % 2 for i in input().split()]
    from collections import Counter
    c = Counter(A)
    if all(a == 0 for a in A):
        print(2**N if P == 0 else 0)
    else:
        print(2**(c[1]-1) * 2**c[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
# 2020/04/23
# AtCoder Beginner Contest 060 - B

# Input
a, b, c = map(int,input().split())

wkval = 0
ans = 'NO'

# Calc
for i in range(1, 100000):
    wkval = a * i
    if wkval % b == c:
        ans = 'YES'
        break

# Output
print(ans)


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

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
LL ave(LL, LL);

int main() {
	int n; cin >> n;
	cout << n / 3;
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}
LL ave(LL a, LL b) {
	return (a + b) / 2;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
#define MAX 100000
#define INF (1<<29)
 
typedef struct{
  char mark;
  int num;
} Card;
 
int getMarkNumber(char);
void swap(Card*,Card*);
int partition(int,int,Card*);
void quickSort(int,int,Card*);
void merge(int,int,int,Card*);
void mergeSort(int,int,Card*);
 
int main(){
  int n,i,isStable;
  Card A[MAX],B[MAX];
 
  scanf("%d\n",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%c%d\n",&A[i].mark,&A[i].num);
    B[i] = A[i];
  }
  quickSort(0,n-1,A);
  mergeSort(0,n,B);
  isStable = 1;
  for(i = 0 ; i < n ; i++){
    if(A[i].mark != B[i].mark || A[i].num != B[i].num){
      isStable = 0;
      break;
    }
  }
  printf("%s\n",(isStable ? "Stable" : "Not stable"));
  for(i = 0 ; i < n ; i++){
    printf("%c %d\n",A[i].mark,A[i].num);
  }
  return 0;
}
 
int getMarkNumber(char x){
  if(x == 'S'){ return 0; }
  if(x == 'H'){ return 1; }
  if(x == 'C'){ return 2; }
  return 3;
}
 
void swap(Card *a,Card *b){
  Card tmp = *a;
  *a = *b;
  *b = tmp;
}
 
int partition(int l,int r,Card *A){
  int x = A[r].num,i = l,j;
  for(j = l ; j < r ; j++){
    if(A[j].num <= x){
      swap(&A[i++],&A[j]);
    }
  }
  swap(&A[i],&A[r]);
  return i;
}
 
void quickSort(int l,int r,Card *A){
  int q;
  if(l < r){
    q = partition(l,r,A);
    quickSort(l,q-1,A);
    quickSort(q+1,r,A);
  }
}
 
void merge(int left, int mid, int right,Card *B){
  int n1 = mid - left,n2 = right - mid,i,j,k;
  Card L[n1+1],R[n2+1];
  
  for(i = 0 ; i < n1 ; i++){
    L[i] = B[left + i];
  }
  for(i = 0 ; i < n2 ; i++){
    R[i] = B[mid + i];
  }
  L[n1] = R[n2] = (Card){'#',INF};
  for(i = 0,j = 0,k = left ; k < right ; k++){
    if(L[i].num <= R[j].num){
      B[k] = L[i++];
    }else{
      B[k] = R[j++];
    }
  }
}
  
void mergeSort(int left,int right,Card *B){
  int mid;
  if(left + 1 < right){
    mid = (left + right) / 2;
    mergeSort(left,mid,B);
    mergeSort(mid,right,B);
    merge(left,mid,right,B);
  }
}


Measured memory_bytes: 4096
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    #l,r,d=map(int,input().split())
    n=int(input())
    aa=[0 for i in range(10**4+1)]
    for a, b, c in itertools.product(range(1,101), repeat=3):
        temp=a**2+b**2+c**2+a*b+b*c+c*a
        if temp<=10**4:
            aa[temp]+=1
    for i in range(1,n+1):
        print(aa[i])








if __name__ == "__main__":

    main()


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

const ll INF = 1001001001001001001;

int main(){
    int n, k; cin >> n >> k;
    vector<P> a(n);
    rep(i,n){
        int t; ll d; cin >> t >> d;
        a.at(i) = {d, t};
    }
    sort(a.begin(), a.end(), greater<P>());
    vector<int> num(n+1);
    vector<ll> ans(n+1, -INF);
    priority_queue<P, vector<P>, greater<P>> que;
    int cnt = 0; ll res = 0;
    rep(i,k){
        P p = a.at(i);
        res += p.first;
        int tmp = p.second;
        que.push(p);
        if(num.at(tmp) == 0) cnt++;
        num.at(tmp)++;
    }
    ans.at(cnt) = res;
    for(int i = k; i < n; i++){
        P p = a.at(i);
        if(num.at(p.second)) continue;
        num.at(p.second)++;
        cnt++;
        while(!que.empty()){
            P q = que.top(); 
            if(num.at(q.second) == 1){
                que.pop();
                continue;
            }
            else{
                que.pop();
                num.at(q.second)--;
                ans.at(cnt) = ans.at(cnt - 1) - q.first + p.first;
                break;
            }
        }
    }
    ll ANS = 0;
    for(ll i = 0; i <= n; i++){
        ANS = max(ANS, i*i + ans.at(i));
    }
    cout << ANS << endl;

}

Measured memory_bytes: 7968
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

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

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

  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll ab = lcm(c, d);
  ll total = b-a+1;
  a--;
  ll ans = total - ((b/c+b/d-b/ab)-(a/c+a/d-a/ab));
  cout << ans << endl;
}


Measured memory_bytes: 3644
#include <cstdio>

int main(){
	int n, table[20][20];

	while( scanf("%d", &n) , n ){
		for(int i=0 ; i<20 ; i++){
			for(int j=0 ; j<20 ; j++){
				table[i][j] = 0;
			}
		}
		for(int i=0 ; i<n ; i++){
			for(int j=0 ; j<n ; j++){
				scanf("%d", &table[i][j]);
			}
		}
		for(int i=0 ; i<n ; i++){
			for(int j=0 ; j<n ; j++){
				table[i][n] += table[i][j];
				table[n][j] += table[i][j];
			}
		}
		for(int i=0 ; i<n ; i++){
			table[n][n] += table[n][i];
		}
		for(int i=0 ; i<=n ; i++){
			for(int j=0 ; j<=n ; j++){
				printf("%5d", table[i][j]);
			}
			printf("\n");
		}

	}

	return 0;
}

Measured memory_bytes: 0
/**
 *    created by : PawPaw       
**/

#include<bits/stdc++.h>
using namespace std;

#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LL long long
#define N 1000001
#define MOD 1000000007

LL fact[N];

LL gcdExtended(LL a, LL b, LL *x, LL *y) 
{ 
  if (a == 0) 
  { 
      *x = 0, *y = 1; 
      return b; 
  } 

  LL x1, y1; 
  LL gcd = gcdExtended(b%a, a, &x1, &y1); 

  *x = y1 - (b/a) * x1; 
  *y = x1; 

    return gcd; 
} 

LL modInverse(LL b, LL m) 
{ 
  LL x, y; 
  LL g = gcdExtended(b, m, &x, &y); 

  if (g != 1) 
      return -1; 

  return (x%m + m) % m; 
} 
  
LL modDivide(LL a, LL b, LL m) 
{ 
  a = a % m; 
  LL inv = modInverse(b, m); 
  return (inv * a) % m; 
} 
  


void pre(){
  fact[0] = 1;
  F(i, 1, 1000000) fact[i] = (i*fact[i-1]) % MOD;
}

LL calc(int n, int k){
  return modDivide(fact[n], (fact[k] * fact[n-k]) % MOD, MOD);
}

int solve(){
  LL x, y, antidiagonal, ans = 0;
  cin >> x >> y;
  antidiagonal = x+y;
  int j = 0;
  pre();
  F(i, 0, N-1){
    if(i + j == antidiagonal){
      F(k, 0, i){
        if(i+k == x && j-k == y) ans = calc(i, k);
      }
      break;
    }
    j+=2;
  }
  cout << ans << '\n';
  return 0;
}

void fun(){
  int t = 1;
  // cin >> t;
  while(t--) solve();
} 

int main(){
  ios::sync_with_stdio(false); 
  cin.tie(0);
  // #ifndef ONLINE_JUDGE
  //   freopen("fi", "r", stdin);
  //   freopen("fo", "w", stdout);
  //   clock_t startClock, endClock;
  //   startClock = clock();
  // #endif

  fun();

  // #ifndef ONLINE_JUDGE
  //   endClock = clock(); 
  //   cout << "Time taken by program is : " << fixed <<  double(endClock - startClock) / double(CLOCKS_PER_SEC) << setprecision(5) << " sec " << endl; 
  // #endif
  
  return 0;
}

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

b0,b1,b2 = 0,0,0

for i in range(N):
    if a[i]%2==1:
        b0+=1
    elif a[i]%4==0:
        b2+=1
    else:
        b1+=1
# print('b0,b1,b2:',b0,b1,b2)
if b1==0:
    if b2>=b0-1:
        print('Yes')
    else:
        print('No')

else:
    b0+=1
    if b2>=b0-1:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 85024
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,Taro=0,Hanako=0;
	cin>>n;
	for(int i=0;i<n;i++){
		string t,h;
		cin>>t>>h;
		if(t<h) Hanako+=3;
		else if(t>h) Taro+=3;
		else{
			Hanako++;
			Taro++;
		}
	}
	cout<<Taro<<" "<<Hanako<<endl;
	return 0;
}



Measured memory_bytes: 3132
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ProgramingContest
{
    class Program
    {
        static void Main()
        {
            var arr = ReadLine().Split().Select(int.Parse).ToArray();
            if (arr[2] <= arr[0] + arr[1])
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
                        }

        }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>
int Counting(void);
int A[2000001], B[2000001], C[10001];
int  n, k=0;

int main(void){
  int i, j;
  scanf("%d",&n);
  for(i=1; i<=n; i++){
    scanf("%d",&A[i]);
    if(A[i] > k) k = A[i];
  }
  Counting();
    for(i=1; i<=n; i++){
      printf("%d",B[i]);
      if(i < n) printf(" ");
    }
  printf("\n");
  return 0;
}


int Counting(){
  int i, j;
  for(i=0; i<=k; i++) C[i] = 0;
  for(j=1; j<=n; j++) C[A[j]] = C[A[j]]+1;
  for(i=1; i<=k; i++) C[i] = C[i] + C[i-1];
  for(j=n; j>=1; j--){
    B[C[A[j]]] = A[j];
    C[A[j]] = C[A[j]]-1;
  }
}

Measured memory_bytes: 15000
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    Vec<i64> A(N + 1, 0);
    for (i32 i = 1; i <= N; i++) cin >> A[i];
    i64 ans = A[1];
    for (i32 i = 2; i <= N; i++) {
        ans = GCD(ans, A[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){

  string s;

  cin >> s;

  int value = 700;

  for(int i=0;i<s.length();i++){
    if(s[i] == 'o'){
      value = value + 100;
    }
  }

  cout << value << endl;

}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y;
	cin>>x>>y;
	if ((x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) && (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12))
		cout << "Yes";
	else if ((x == 4 || x == 6 || x == 9|| x == 11) && (y == 4 || y == 6 || y == 9 || y == 11))
		cout << "Yes";
	
	else if(x==2&&y==2)
        cout<<"Yes";
	else
        cout<<"No";
	
        
	return 0;
	}





Measured memory_bytes: 3608
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n, k;
	cin >> n >> k;

	vector<pair<int, int>> edge;

	rep(i, n - 1)edge.emplace_back(0, i + 1);

	int rem = k;
	for(int i=1;i<n;i++){
		for (int j = i + 1; j < n; j++) {
			if (rem == 0) {
				edge.emplace_back(i, j);
			}
			else {
				rem--;
			}
		}
	}
	

	if (rem == 0) {
		cout << edge.size() << endl;
		for (auto p : edge) {
			cout << p.first + 1 << ' ' << p.second + 1 << endl;
		}
	}
	else {
		cout << -1 << endl;
	}


	return 0;
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<ll>X(n), Y(n), h(n);
    int a=-1, b=-1;
    ll c=-1;
    rep(i, 0, n)cin >> X[i] >> Y[i] >> h[i];
    rep(x, 0, 101){
        rep(y, 0, 101){
            bool flag = true;
            ll temph;
            rep(i, 0, n){
                if(h[i]==0)continue;
                temph = h[i]+abs(X[i]-x)+abs(Y[i]-y);
                break;
            }
            rep(i, 0, n){
                if(h[i]!=max((temph-(abs(X[i]-(ll)x)+abs(Y[i]-(ll)y))),(ll)0))flag = false;
            }
            if(flag){
                a = x;
                b = y;
                c = temph; 
                cout << a << " " << b << " " << c << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ll long long
#define db double
#define iosks std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int N=2e5+10,M=3e4+10;
const ll inf=INT_MAX,mod=1e9+7;
const db pi=atan(1)*4;
ll pow2(ll a,ll b) {ll s=1; while(b) {if(b&1) s=(s*a)%mod; a=(a*a)%mod; b/=2; } return s;}
ll lcm(ll a,ll b) {return a/__gcd(a,b)*b; }
int read()
{
    int s=0,f=1; char ch=getchar();
    while(ch<'0'&&ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {s=s*10+ch-'0'; ch=getchar();} return s*f;
}

string s;

int main()
{
    iosks;
    int ans=0,t=0;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='R') t++;
        else t=0;
        ans=max(t,ans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int M, D; cin >> M >> D;
    int cnt = 0;
    for (int i = 4; i <= M; i++) {
        for (int j = 22; j <= D; j++) {
            if ((j / 10) * (j % 10) == i && j / 10 >= 2 && j % 10 >= 2) cnt++;
        }
    }
    printf("%d\n", cnt);
}


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

int n,m;
int a[100000];

signed main() {
  cin >> n >> m;
  rep(i,n) cin >> a[i];
  map<int ,int> mp;
  rep(i,m) {
    int b,c; cin >> b >> c;
    mp[c] += b;
  }
  //for(auto i = mp.rbegin(); i != mp.rend(); i++) {
  //  auto item = (*i);
  //  cout << item.first << ": " << item.second << endl;
  //}
  sort(a, a+n);
  ll ans = 0;
  rep(i,n) {
    if (!mp.empty()) {
      auto item = *mp.rbegin();
      if (a[i] < item.first) {
        a[i] = item.first;
        if(item.second==1) mp.erase(item.first);
        else mp[item.first]--;
      }
    }
    ans += a[i];
  }
  cout << ans << endl;
}


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

namespace A.Happy_Birthday_
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Console.ReadLine().Split().Select(int.Parse);

            Console.WriteLine(AB.Any(x => x > 8) ? ":(" : "Yay!");
        }
    }
}


Measured memory_bytes: 11220
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

long long int h[110000], L[110000], R[110000];

int main(){
	
	int N;
	cin >> N;
	
	for(int i = 0; i < N; i++){
		cin >> h[i];
	}
	
	stack<int> sta, sta2;
	
	for(int i = 0; i < N; i++){
		while(sta.size() > 0 && h[sta.top()] >= h[i]){
			sta.pop();
		}
		if(sta.empty()){
			L[i] = 0;
		}else{
			L[i] = sta.top() + 1;
		}
		sta.push(i);
	}
	
	while(!sta.empty()){
		sta.pop();
	}
	
	for(int i = N - 1; i >= 0; i--){
		while(sta.size() > 0 && h[sta.top()] >= h[i]){
			sta.pop();
		}
		if(sta.empty()){
			R[i] = N;
		}else{
			R[i] = sta.top();
		}
		sta.push(i);
	}
	
	long long int ans = 0;
	for(int i = 0; i < N; i++){
		ans = max(ans, h[i] * (R[i] - L[i]));
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long int ll;

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;

vector < ll > fact(N);

ll pwr (ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

ll inv (ll a) {
  return pwr(a, mod - 2);
}

ll comb (int n, int r) {
  if (r > n) return 0;
  return ((((fact[n] * inv(fact[n - r])) % mod) * inv(fact[r])) % mod);
}

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

  fact[0] = 1;
  for (int i = 1; i < N; i++) fact[i] = (i * fact[i - 1]) % mod;

  int n;
  cin >> n;
  vector < int > a(n + 2), pos(n + 1, -1);
  int distance = 0;
  for (int i = 1; i <= n + 1; i++) {
    cin >> a[i];
    if (pos[a[i]] != -1) {
      distance = i - pos[a[i]] - 1;
    } else pos[a[i]] = i;
  }

  ll ans = 0;
  for (int k = 1; k <= n + 1; k++) {
    ans = (comb(n + 1, k) - comb(n - distance - 1, k - 1) + mod) % mod;
    cout << ans << '\n';
  }
}


Measured memory_bytes: 2816
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    for(auto& in:a) cin >> in;
    
    deque<ll> dep;
    for(int i = 0 ;i < n;i++){
        if(i%2 == 0){
            dep.push_back(a[i]);
        }else{
            dep.push_front(a[i]);
        }
    }
    vector<ll> res(dep.begin(),dep.end());
    if(n%2==1)reverse(res.begin(), res.end());
    for(auto v:res){
        cout << v << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 6912
#include <iostream>
using namespace std;
    // Your code here!
    int d,n,s,t,sum;
    int main(void){
        while(cin>>d>>n,d){
            sum=0;
            for(int i=0; i<n; i++){
                cin>>s>>t;
                sum+=t-s;
            }
            if(sum<d)cout<<d-sum<<endl;
            else cout<<"OK"<<endl;
        }
    }



Measured memory_bytes: 3088
#include <stdio.h>



int count=0;
int temp[500000];    

void MergeSort(int *,int,int);


int main(void)
{
  int i,n;
 
  int A[1000000];
 
  scanf("%d",&n);
  for (i = 0; i < n; i++)
    scanf("%d",&A[i]);

  MergeSort(A,0,n-1);

  /*出力*/
  
  for (i=0;i<n-1;i++)
    printf("%d ",A[i]);
  printf("%d\n",A[n-1]);
  printf("%d\n",count);
  return 0;
}

/* left から right マージソート */
void MergeSort(int *A, int left, int right)
{
  int mid,i,j,k;
   /* 配列の要素が一つの場合 */
  if (left>=right)             
    return;                     

  
  mid=(left+right)/2;      
  MergeSort(A,left,mid);       
  MergeSort(A,mid+1,right);  

  /* left から mid*/
  for(i=left;i<=mid;i++)
    temp[i]=A[i];

  /* mid + 1からright */
  for(i=mid+1,j=right;i<=right;i++,j--)
    temp[i]=A[j];

  i=left;         
  j=right;       

  for(k=left;k<=right;k++){    
    if(temp[i]<=temp[j])      
      A[k]=temp[i++];
    
    else
      A[k]=temp[j--];

    count++;
  }
}



Measured memory_bytes: 6508
s = input()
n = len(s) + 1

a = [-1] * n
tmp = 0

if s[0] == '<':
    a[0] = 0
if s[-1] == '>':
    a[-1] = 0

for i in range(1,n-2):
    if s[i] == '>' and s[i+1] == '<':
        a[i+1] = 0

for i in range(n-1):
    if a[i] == 0:
        tmp = 1
    else:
        tmp += 1
    if s[i] == '<':
        a[i+1] = tmp
    else:
        tmp = 0

for i in range(n-1):
    i = i * (-1) - 1
    if a[i] == 0:
        tmp = 1
    else:
        tmp += 1
    if s[i] == '>':
        a[i-1] = max(tmp, a[i-1])
    else:
        tmp = 0

print(sum(a))


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

bool is_kaibun(const string &s){
    string r_s =s;
    reverse(r_s.begin(),r_s.end());
    if(s == r_s) return true;
    return false;
}

int main(){
    string s;
    cin >> s;
    bool ans1 = false,ans2 = false,ans3 = false;
    ans1 = is_kaibun(s);
    ans2 = is_kaibun(s.substr(0,(s.size() - 1)/2));
    ans3 = is_kaibun(s.substr((s.size() + 2)/2,(s.size() - 1)/2));
    if(ans1 && ans2 && ans3) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256