akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	int a,b,m,mn=1e9;
	cin>>a>>b>>m;
	int c[a][b+1];
	forr(i,0,a)
	{
		forr(j,0,b+1)
		{
			int x;
			cin>>x;
			c[i][j]=x;	
		}
	}
	int v[(1<<a)][a];
	forr(i,0,(1<<a))
	{
		int ct=0,flag=0, ans[b+1]={};
		forr(j,0,a)
		{
			if(i&(1<<j))
				v[i][j]=1;
			else
				v[i][j]=0;		
		}
		forr(j,0,a)
		{
			if(v[i][j]==1)
			{
				forr(k,1,b+1)
					ans[k]+=c[j][k];
				ct+=c[j][0];
			}
		}
		//cout<<i<<"  ";
		forr(j,1,b+1)
		{
			//cout<<ans[j]<<' ';
			if(ans[j]>=m)
				continue;
			else
			{
				flag=1;
				break;
			}
		}
		//cout<<'\n';
		if(!flag)
		{
			mn=min(mn,ct);
		}
	}
	if(mn!=1e9)
	cout<<mn;
	else 
		cout<<-1;
	return 0;
}

Measured memory_bytes: 3844
n, k= list(map(int, input().split()))
if k<=n:
    if n%k == 0:
        print("0")
        exit()
amari = n%k
n = amari
while(True):
    new_n = abs(k-n)
    if new_n < n:
        n = new_n
    else :
        break
print(n)

Measured memory_bytes: 2940
<?php
  $n = intval(fgets(STDIN));

  $work = [];
  $limit = [];
  for($i=0; $i<$n; $i++){
    $tmp = explode(" ", trim(fgets(STDIN)));
    
    $work[] = $tmp[0];
    $limit[] = $tmp[1];
  }

  array_multisort($limit, SORT_ASC, $work);

  $time = 0;
  $result = true;
  for($i=0; $i<$n; $i++){
  	$time += $work[$i];
    if($time>$limit[$i]){
      $result = false;
      break;
    }
  }
echo $result ? "Yes\n" : "No\n";
  
  


Measured memory_bytes: 55916
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Gosu_Hiroo
 */

#include <iostream>
#include <fstream>

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

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, _begin, _end) for (__typeof(_end) end = _end, begin = _begin,  i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0, _len = (end); i < (_len); i += 1)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define readint ({int t;cin >> t;t;})
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}

template <typename T>
ostream& operator << (ostream& os, const vector<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

template <typename T>
ostream& operator << (ostream& os, const set<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

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

//#define int ll

class ATriangle {
public:
    void solve(std::istream& cin, std::ostream& cout) {
    ll S;
    cin >> S;
    ll y3 = 1e9, x2 = (S + y3 -1)/y3;
    ll y2 = x2 * y3 - S;
    cout << 0 << " " << 0 << " " << x2 << " " << y2 << " " << 1 << " " << y3 << endl;
}


};


#undef int
int main() {


	ATriangle solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(0); ios::sync_with_stdio(0); out<<fixed<<setprecision(20);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 764
def solve(string):
    n, *a = map(int, string.split())
    ans = [sum(a) - 2 * sum(a[1::2])]
    for _a in a[:-1]:
        ans.append(2 * _a - ans[-1])
    return " ".join(map(str, ans))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 20172
#include <stdio.h>
#include <math.h>

int isprime(int x){
	int i;
	i=3;
	if(x==2){
		return 1;
	}else if(x<2 || x%2==0){
		return 0;
	}else {
		while (i<=sqrt(x)){
			if(x%i==0){
				return 0;
			} 
			
			i=i+2;
		}
		return 1;
	}
}

int main(void){
	int n,i,count;
	int a[10000];
	count=0;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	for(i=0;i<n;i++){
		count=count+isprime(a[i]);
	}
	printf("%d\n",count);
	return 0;
}


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

int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	if(a[0]==5 && a[1]==5 && a[2]==7) cout << "YES" << "\n";
	else cout << "NO" << "\n";
	return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: u64,
        a: [u64; n],
    }

    let mut v = vec![0; (n + 1) as usize];
    for i in &a {
        v[*i as usize] += 1;
    }

    let mut p = vec![0; (n + 1) as usize];
    for i in 0..v.len() {
        if v[i as usize] < 2{
            continue; // 0
        } else {
            p[i as usize] = (v[i as usize] * (v[i as usize] - 1)) / 2;
        }
    }
    // println!("a: {:?}", a);
    // println!("v: {:?}", v);
    // println!("p: {:?}", p);
    // return;
    let total_equal_counts: u64 = p.iter().sum();
    // println!("base: {}", total_equal_counts); // pass

    // for i in 1..n + 1 {
    for i in 0..n {
        let a_current = a[i as usize];
        let num_of_current_a = v[a_current as usize];
        // println!("i: {}, {}", i, v[a[i as usize] + 1 as usize]);
        if num_of_current_a < 2 {
            println!("{}", total_equal_counts);
        } else {
            println!("{}", total_equal_counts - (num_of_current_a - 1));
        }
    }
}


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

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

typedef pair<int, int> Point;
typedef vector<Point> Line;

void normalize1(Line& line) {
    int offset_x = line[0].first;
    int offset_y = line[0].second;
    for (auto& p : line) {
        p.first -= offset_x;
        p.second -= offset_y;
    }

    while (line[1].first <= 0 || line[1].second != 0) {
        for (auto& p : line) {
            p = make_pair(-p.second, p.first);
        }
    }
}

void normalize2(Line& line) {
    Line reversed(line);
    normalize1(line);
    reverse(reversed.begin(), reversed.end());
    normalize1(reversed);
    if (reversed < line)
        line = reversed;
}

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

    int n;
    while (cin >> n, n) {
        vector<Line> lines(n+1);

        REP(i, n+1) {
            int m; cin >> m;
            lines[i].resize(m);
            REP(j, m) {
                cin >> lines[i][j].first >> lines[i][j].second;
            }
            normalize2(lines[i]);
        }

        FOR(i, 1, n+1) {
            if (lines[i] == lines[0])
                cout << i << '\n';
        }

        cout << "+++++\n";
    }
}

Measured memory_bytes: 3104
a,b,c = input().split()

a = int(a)
b = int(b)
c = int(c)

if 1 <= a <= 100:
    if 1 <= b <= 100:
        if 1<= c <= 100:

            x = b / a
            if x >= c:
                print(int(c))
            else:
                print(int(x))

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;

class Main
{
	public static void main(String[] args)
	{
		FastReader reader = new FastReader();
		PrintWriter writer = new PrintWriter(System.out);

		int k = reader.nextInt();
		writer.print((k/2)*((k+1)/2));

		writer.close();
	}

	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}
}

Measured memory_bytes: 22740
#include <iostream>
#include <string>

using namespace std;

string revstr( string str ) {
	string ret;
	for(int i = str.length() - 1; i >= 0; i--)
		ret += str[i];
	return ret;
}

int main(void){
	string str;
	cin >> str;
	cout << revstr( str ) << endl;
	return 0;
}

Measured memory_bytes: 1180
object Main extends App {
	val KAB = scala.io.StdIn.readLine.split(" ").map(_.toLong)

	val sum: Long = KAB(1) - KAB(2)

	if(sum <=0){
		if(KAB(0) <= KAB(1)) println(1)
		else println(-1)
	}else{
		val k1 = KAB(0) - KAB(1)
		val a = k1/sum

		if(a*sum >= k1) println(2*a + 1)
		else println(2*(a+1)+1)
	}
}

Measured memory_bytes: 27188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int h, n;
  cin >> h >> n;
  int d = 0;
  rep(i, n) {
    int a;
    cin >> a;
    d += a;
  }
  cout << (h <= d ? "Yes" : "No") << endl;
}

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

int n;
string s;
string ans;

char swap(char c) {
  return (c == 'S' ? 'W' : 'S');
}

bool search(int c0, int c1) {
  if (c0) ans = (c1 ? "SS" : "SW");
  else ans = (c1 ? "WS" : "WW");

  rep(i, n-2) {
    if (s[i+1] == 'o') {
      ans += (ans[i+1] == 'S' ? ans[i] : swap(ans[i]));
    } else {
      ans += (ans[i+1] == 'S' ? swap(ans[i]) : ans[i]);
    }
  }

  bool ok = true;
  rep(i, 2) {
    if (s[(n+i-1)%n] == 'o') {
      ok &= ans[i] == (ans[(n+i-1)%n] == 'S' ? ans[(n+i-2)%n] : swap(ans[(n+i-2)%n]));
    } else {
      ok &= ans[i] == (ans[(n+i-1)%n] == 'S' ? swap(ans[(n+i-2)%n]) : ans[(n+i-2)%n]);
    }
  }
  return ok;
}

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

  cin >> n;
  cin >> s;

  cerr << search(0, 0) << endl;
  cerr << ans << endl;
  cerr << endl;
  cerr << search(0, 1) << endl;
  cerr << ans << endl;
  cerr << endl;
  cerr << search(1, 0) << endl;
  cerr << ans << endl;
  cerr << endl;
  cerr << search(1, 1) << endl;
  cerr << ans << endl;
  cerr << endl;

  rep(i, 2) {
    rep(j, 2) {
      if (search(i, j)) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 720
/*
  -------------
  Prateek Celly
  DA-IICT
  -------------
*/
#include<bits/stdc++.h>
using namespace std;

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin>>s;
  for(ll i=0;i<s.length()-1;i++) if(s[i]==s[i+1]) {cout<<"Bad"; return 0;}
  cout<<"Good";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    int X;
    cin >> X;

    if(X >= 400 && X <= 599){
        cout << 8 << endl;
    }else if(X >= 600 && X <= 799){
        cout << 7 << endl;
    }else if(X >= 800 && X <= 999){
        cout << 6 << endl;
    }else if(X >= 1000 && X <= 1199){
        cout << 5 << endl;
    }else if(X >= 1200 && X <= 1399){
        cout << 4 << endl;
    }else if(X >= 1400 && X <= 1599){
        cout << 3 << endl;
    }else if(X >= 1600 && X <= 1799){
        cout << 2 << endl;
    }else if(X >= 1800 && X <= 1999){
        cout << 1 << endl;
    }

}

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

using namespace std;

string n;

vector<vector<int64_t>> cache;

int64_t calc(int len, int k) {
  if (k < 0)
    return 0;
  if (k == 0)
    return 1;
  auto& result = cache[len][k];
  if (!result) {
    int64_t res = 1;
    for (int64_t i = 0; i < k; ++i) {
      res *= (len - i);
    }
    for (int64_t i = 1; i <= k; ++i) {
      res /= i;
    }
    for (int i = 0; i < k; ++i) {
      res *= 9;
    }
    result = res;
  }
  // cout << " calc " << len << " " << k << " " << result << endl;
  return result;
}

int64_t entry_point(int idx, int k) {
  if (k == 0) {
    return 1;
  }
  if (idx == n.size()) {
    return 0;
  }
  assert(k > 0);
  assert(idx < n.size());
  auto m = n[idx] - '0';
  // cout << " idx k m " << idx << " " << k << " " << m << endl;
  assert(m != '0');
  auto len = n.size() - idx;
  auto res = calc(len - 1, k);
  // cout << " res A " << res << endl;
  res += (m - 1) * calc(len - 1, k - 1);
  // cout << " res B " << res << endl;
  for (int i = idx + 1; ; ++i) {
    if (i == n.size() || n[i] != '0') {
      return res + entry_point(i, k - 1);
    }
  }
}

void solve() {
  int k;
  cin >> n >> k;
  cache.resize(n.size() + 1, vector<int64_t>(k + 1));
  cout << entry_point(0, k) << endl;
}

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

  // cache.resize(100, vector<int64_t>(100));
  // cout << calc(2, 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>

void view(const std::vector<T> &v)
{
#ifndef ONLINE_JUDGE
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
#endif
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    int ok = 0;
    rep(i, n)
    {
        int d1, d2;
        cin >> d1 >> d2;
        ok += d1 == d2;
        ok *= d1 == d2;
        if (ok == 3)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
    int n, q;
    cin >> n >> q;
    vector< stack<int> > v(n);
    for(int i = 0; i < q; i++){
	   int cmd;
	   cin >> cmd;
	   if (cmd == 0){
		  int t, x;
		  cin >> t >> x;
		  v[t].push(x);   
		}
	  if (cmd == 1){
		  int t;
		  cin >> t;
		  if(!v[t].empty()) cout << v[t].top() << endl;
		}
	  if (cmd == 2){
		  int t;
		  cin >> t;
		  if(!v[t].empty()) v[t].pop();  
		}	
    }	
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



Measured memory_bytes: 4940
/* 実行時間1s制限の場合10^6 1,000,000 : 余裕をもって間に合う10^7
  10,000,000 : おそらく間に合う10^8 100,000,000 : 非常にシンプルな処理
  でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

const ll INF = LONG_MAX;
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; }

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    //std::ifstream in(string(argv[0]) + ".txt");
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int k;
    string s;

    cin >> k >> s;

    if (s.size() <= k) {
        cout << s;
    }
    else {
        cout << s.substr(0, k);
        //rep(i, s.size() - s.substr(0, k).size()) cout << ".";
        cout << "...";
    }



    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));  // 2次元配列初期化
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
using namespace std;

// bad knowhow
#define REP(i,n) for(long long i=0;i<(long long)n;++i)


struct Score {
	Score() {}
	Score(int c, int p) : collects(c), penalty(p) {}
	bool operator<(const Score & other) const {
		if (collects == other.collects){
			if (penalty == other.penalty) return id < other.id;
			return penalty < other.penalty;
		}
		return collects > other.collects;
	}
	int collects;
	long long penalty;
	int id;
};

int wrong[50][10];
bool collect[50][10];
Score score[50];


int main() {
	while (true) {
		int t, p, r;
		cin >> t >> p >> r;
		if (t == 0) break;

		fill(score, score + 50, Score(0,0));
		fill(*collect, *collect + 500, false);
		fill(*wrong, *wrong + 500, 0);
		REP(i, t) score[i].id = i;

		REP(i, r) {
			int tid, pid, time;
			string message;
			cin >> tid >> pid >> time >> message;
			tid--; pid--;
			if (collect[tid][pid]) continue;
			if (message == "CORRECT") {
				score[tid].collects++;
				collect[tid][pid] = true;
				score[tid].penalty += wrong[tid][pid] * 1200 + time;
			} else {
				wrong[tid][pid]++;
			}
		}

		sort(score, score+t);
		REP(i, t) {
			cout << score[i].id + 1 << " " << score[i].collects << " " << score[i].penalty << endl;
		}
	}
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int ctoi(char c) { return (int)c - '0'; }
int main() {
   while (true) {
      string s;
      cin >> s;
      if (s.size() == 1 && stoi(s) == 0) {
         break;
      }
      int ans = 0;
      rep(i, s.size()) { ans += ctoi(s[i]); }
      cout << ans << endl;
   }
   return 0;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  ll T; scanf("%lld", &T);
  vector<ll> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &A[i]);
  }
  ll ans = 0, left = 0;
  for (int i = 0; i < N; ++i) {
    ans += A[i] + T - max(left, A[i]);
    left = A[i] + T;
  }
  printf("%lld\n", ans);
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1L << 30
#define long long long

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

int X, Y, Z;
int main(){
	cin >> X >> Y >> Z;
	cout << Z << " " << X << " " << Y;


}

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

int main(){
	for (;;){
		int N;
		cin >> N;
		if (N == 0) break;

		int ans = 0;
		for (int a = 1; a <= N / 2 + 1; a++){
			for (int b = 1; b <= a - 1; b++){
				if (a * (a + 1) - b * (b - 1) == 2 * N) ans ++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

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

int main() {
  cout << setprecision(18);
  string S;
  cin >> S;
  vector<i32> Num(4);
  for (u32 i = 0; i < 4; ++i) {
    Num[i] = S[i] - '0';
  }
  for (u32 i = 0; i < 8; ++i) {
    i32 res = Num[0];
    for (u32 b = 0; b < 3; ++b) {
      if ((i >> b) & 0x01) {
        res -= Num[b + 1];
      } else {
        res += Num[b + 1];
      }
    }
    if (res == 7) {
      cout << Num[0];
      for (u32 b = 0; b < 3; ++b) {
        if ((i >> b) & 0x01) {
          cout << '-';
        } else {
          cout << '+';
        }
        cout << Num[b + 1];
      }
      cout << "=7" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PPQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define MOD 1000000007
using namespace std;
//
long long N,L[87];
int main(){
  cin>>N;
  L[0]=2;L[1]=1;
  FOR(i,2,N+1){
    L[i]=L[i-1]+L[i-2];
  }
  cout<<L[N]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch ForkInTheRoad | diff ForkInTheRoad.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address ForkInTheRoad.cpp && ./a.out

/*
 
 10/27/2019
 
 6:21-6:35 give up
 
 10:40-11:26 read editorial and got AC
 
 https://img.atcoder.jp/abc144/editorial.pdf
 
 */

const int MAX_N=600+1;
int N,M;

VI G[MAX_N];
double dp[MAX_N];
void solve() {
  ZERO(dp);
  for(int u=N-2; u>=0; --u) {
    double sum=0;
    FORR(v,G[u]) sum+=dp[v];
    dp[u]=1+sum/SZ(G[u]);
  }
  double res=dp[0];
  REP(u,N-1) {
    if(SZ(G[u])<=1) continue;
    double maxe=dp[G[u][0]];
    FORR(v,G[u]) SMAX(maxe,dp[v]);
    double temp=dp[u];
    double sum=SZ(G[u])*(temp-1);
    dp[u]=1+(sum-maxe)/(SZ(G[u])-1);
    for(int i=u-1; i>=0; --i) {
      double sum=0;
      FORR(j,G[i]) sum+=dp[j];
      dp[i]=1+sum/SZ(G[i]);
    }
    SMIN(res,dp[0]);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>M;
  REP(i,M) {
    int u,v; cin>>u>>v;
    --u,--v;
    G[u].push_back(v);
  }
  solve();
  
  return 0;
}


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		
		int n = sc.nextInt();
		int w = sc.nextInt();
		int[] weights = new int[n];
		int[] values = new int[n];
		long[][] dp = new long[n+1][w+1];
		
		for (int i = 0; i < n; i++) {
			weights[i] = sc.nextInt();
			values[i] = sc.nextInt();
		}
		
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= w; j++) {
				if (j >= weights[i-1]) {
					dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j - weights[i-1]] + values[i-1]);
				} else {
					dp[i][j] = dp[i-1][j];
				}
			}
		}
		
		System.out.println(dp[n][w]);

	}

}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int a, b, c, d;cin >> a >> b >> c >> d;
    if(a+b > c+d){
        cout << "Left" << endl;
    }else if(a+b < c+d){
        cout << "Right" << endl;
    }else{
        cout << "Balanced" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){
  int n,k; cin >> n >> k;
  vector<int> a(n);
  ll sum = 0;
  rep(i,n) cin >> a[i],sum += a[i];
  set<ll> candidates;
  for(int i = 1; i*i <= sum; i++){
    if(sum%i == 0){
      candidates.insert(i);
      candidates.insert(sum/i);
    }
  }
  
  ll ans = 1;
  
  for(ll x:candidates){
    ll need = 1LL << 60;
    vector<ll> r(n);
    rep(i,n) r[i] = a[i]%x;
    sort(r.begin(),r.end());
    ll B = 0;
    rep(i,n) B += x-r[i];
    ll A = 0;
    rep(i,n){
      A += r[i];
      B -= x-r[i];
      need = min(need, max(A,B));
    }
    if(need <= k) chmax(ans,x);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
const int N=1e4+10;
int a[N];
int main(){
	cin>>n;
	for(int i=1;i<=110;i++){
		for(int j=1;j<=110;j++){
			for(int k=1;k<=110;k++){
				if((long long)i*i+j*j+k*k+i*j+i*k+j*k>n){
					break;
				}
				else a[i*i+j*j+k*k+i*j+i*k+j*k]++;
			}
		}
	}
	for(int i=1;i<=n;i++)
	printf("%d\n",a[i]);
	
	
	return 0;
} 

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

struct st{
	int op;
	int a,b,c;
};
st dp[200000][4][4][4];
string s[200000];
char S[4];

int main(){
	int n,a,b,c;cin>>n>>a>>b>>c;
	rep(i,n){
		scanf("%s",S);
		s[i]=S;
	}
	a=min(a,3);b=min(b,3);c=min(c,3);
	rep(i,n+1)rep(j,4)rep(k,4)rep(t,4){
		dp[i][j][k][t]={-1,-1,-1,-1};
	}
	dp[0][a][b][c]={0,0,0,0};
	rep(i,n)rep(j,4)rep(k,4)rep(t,4){
		if(dp[i][j][k][t].op==-1)continue;
		if(s[i]=="AB"){
			if(j-1>=0){
				dp[i+1][j-1][min(3,k+1)][t]={'B',j,k,t};
			}
			if(k-1>=0){
				dp[i+1][min(3,j+1)][k-1][t]={'A',j,k,t};
			}
		}
		else if(s[i]=="AC"){
			if(j-1>=0){
				dp[i+1][j-1][k][min(3,t+1)]={'C',j,k,t};
			}
			if(t-1>=0){
				dp[i+1][min(3,j+1)][k][t-1]={'A',j,k,t};
			}
		}
		else if(s[i]=="BC"){
			if(k-1>=0){
				dp[i+1][j][k-1][min(3,t+1)]={'C',j,k,t};
			}
			if(t-1>=0){
				dp[i+1][j][min(3,k+1)][t-1]={'B',j,k,t};
			}
		}
	}
	st cur={-1,-1,-1,-1};
	int x=n,ni=-1,nj=-1,nk=-1;
	rep(i,4)rep(j,4)rep(k,4){
		if(dp[n][i][j][k].op!=-1){
			cur=dp[n][i][j][k];
			ni=i;nj=j;nk=k;
		}
	}
	if(cur.op==-1){
		puts("No");return 0;
	}
	puts("Yes");
	vector<char>ans;
	while(x){
		assert(cur.op!=-1);
		ans.push_back((char)cur.op);
		ni=cur.a;nj=cur.b;nk=cur.c;
		cur=dp[x-1][ni][nj][nk];
		x--;
	}
	reverse(ans.begin(),ans.end());
	for(char c:ans){
		cout<<c<<endl;
	}
}

Measured memory_bytes: 110068
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int next2(int a) {
    int ret = 1;
    while(ret <= a) {
        ret *= 2;
    }
    return ret;
}

int main() {
    int N;
    cin >> N;
    vector<int> power;
    int p = 1;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(All(A));
    map<int, int> mp;
    rep(i, N) { mp[A[i]]++; }
    int res = 0;
    for(int i = N - 1; i >= 0; i--) {
        if(mp[A[i]] > 0) {
            mp[A[i]]--;
            int n = next2(A[i]);
            int s = n - A[i];
            if(mp[s] > 0) {
                mp[s]--;
                res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 19712
#include<stdio.h>
int main(){
  int a,b,c,count=0;
  int i;

  while(1){
    scanf("%d%d%d",&a,&b,&c);
    if(1<=a && c<=10000 && a<=b) break;
  }

  for(i=a;i<=b;i++){
    if(c % i == 0) count++;
  }

  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 596
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define rep(i,j,k) for(register int i = j; i <= k; i++)
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define ll long long
using namespace std;

inline int read() { 
    int s = 0, t = 1; char c = getchar();
    while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
    while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
    return s * t;
}

inline void Max(int &x,int v) { if( v > x ) x = v; }

const int N = 2e5+5;
int n, m, head[N], cnt = 0; bool a[N], b[N]; 
inline void add(int x,int y) { 
    if( x > y ) swap(x,y);
    if( x == 1 ) b[y] = 1;
    if( y == n ) a[x] = 1;
}

int main() { 
    n = read(), m = read();
    rep(i,1,m) add(read(),read());
    rep(i,1,n) if( a[i] && b[i] ) puts("POSSIBLE"), exit(0);
    puts("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 640
from heapq import heappush, heappop

N = int(input())
vec = [[] for _ in range(N)]
for i in range(N) :
    for j, v in enumerate(input()) :
        if v == '1' :
            vec[i].append(j)

def bfs(s) :
    dist = [float('inf')] * N
    queue = [(1, s)]
    dist[s] = 1
    
    while queue :
        co, cur = heappop(queue)
        if dist[cur] < co :
            continue
            
        for nex in vec[cur] :
            if co + 1 < dist[nex] :
                dist[nex] = co + 1
                heappush(queue, (co + 1, nex))
                
    for i in range(N) :
        for j in vec[i] :
            if abs(dist[i] - dist[j]) != 1 :
                return -1
    
    return max(dist)

ret = -1
for i in range(N) :
    ret = max(ret, bfs(i))
    
print(ret)

Measured memory_bytes: 58460
md = 10 ** 9 + 7
h, w = map(int, input().split())
a = [input() for _ in range(h)]
t = [[1] * w for _ in range(h)]
for i, ai in enumerate(a):
    ti = t[i]
    for j, aij in enumerate(ai):
        if aij == "#":
            ti[j] = 0
        else:
            if j == 0:
                if i > 0:
                    ti[j] = t[i - 1][j]
            elif i == 0:
                if j > 0:
                    ti[j] = ti[j - 1]
            else:
                ti[j] = (ti[j - 1] + t[i - 1][j]) % md
print(t[-1][-1])


Measured memory_bytes: 43616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    string s;
    cin >> s;
    vector<int> ans(s.size(), 0);

    int odd_count = 0;
    int even_count = 0;
    int r_num = 0;
    int l_num = 0;
    s += 'R';
    char check_char = 'R';
    int flag = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'R') {
            if(check_char == 'L') {
                if(r_num % 2 == 0) {
                    ans[r_num] = odd_count;
                    ans[l_num] = even_count;
                }
                else {
                    ans[r_num] = even_count;
                    ans[l_num] = odd_count;
                }
                odd_count = 0;
                even_count = 0;
            }
            
            check_char = 'R';
        }
        else {
            if(check_char == 'R') {
                r_num = i-1;
                l_num = i;
            }
            
            check_char = 'L';
        }
        if(i % 2 == 0) {
            odd_count++;
        }
        else {
            even_count++;
        }
    }

    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    int a1,a2,a3;
    cin >> a1 >> a2 >> a3;

    cout << (a1+a2+a3>=22? "bust" : "win") << endl;
}

Measured memory_bytes: 888
K = int(input())
S = lambda n: sum(map(int,str(n)))
R = lambda n: n/S(n)

arr = []
for i in range(1,200):
    for j in range(1,15):
        arr.append(int(str(i) + '9'*j))

arr.sort(reverse=True)
min_r = arr[0]
snukes = []
for a in arr:
    r = R(a)
    if r < min_r:
        min_r = r
        snukes.append(a)

for i in range(min(9,K)):
    print(i+1)
if K <= 9:
    exit()
K -= 9

print(*snukes[:-K-1:-1],sep='\n')

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef vector<lo> vl;
typedef vector<vl>vll;
#define all(v) (v).begin(), (v).end()
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define REPV(a, b, c) for (lo(a) = b; (a) < (c); (a)++) 
#define REP(a,b) for(lo i =(a) ;i<(b);i++)

template <typename T>

istream &operator>>(istream &in, vector<T> &v)
{
	for (unsigned i = 0; i < v.size(); i++)
		in >> v[i];
	return in;
}


void solve(){

		lo N;
		cin>>N;
		if(N%1000==0){cout<<0<<endl;return;}
		lo a = 1000 - (N%1000);
		cout<<a<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(20);
	solve();
	return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>



int main(void)
{
	int a, p;
	int sum = 0;
	int i, j, index = 0;
	int work;
	
	scanf("%d%d", &a, &p);
	
	sum = a * 3 + p;
	
	printf("%d\n", sum / 2);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF 100000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int root;
bool flag=true;
int n,k;
vector<int> G[500001];
int ans[500001];
int mini[500001];
int maxi[500001];
int dist[500001];
int kos[500001];
vector<int> bro[500001];

void dfs(int v,int p,int c){
	dist[v]=c;
	for(int i=0;i<G[v].size();i++){
		int nex=G[v][i];
		if(G[v][i]!=p){
			if(ans[nex]==-1){
				mini[nex]=max(mini[v]-1,mini[nex]);
				maxi[nex]=min(maxi[v]+1,maxi[nex]);
			}else{
				//printf("%d %d\n",abs(ans[nex]-ans[root])%2,c%2);
				if(abs(ans[nex]-ans[root])%2==c%2)flag=false;
				mini[nex]=max(mini[v]-1,mini[nex]);
				maxi[nex]=min(maxi[v]+1,maxi[nex]);
			}
			dfs(nex,v,c+1);
		}
	}
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--;
		v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=0;i<n;i++){
		ans[i]=-1;
		mini[i]=-1145140;
		maxi[i]=INF;
	}
	scanf("%d",&k);
	for(int i=0;i<k;i++){
		int v,p;
		scanf("%d%d",&v,&p);
		v--;
		ans[v]=p;
		mini[v]=p;
		maxi[v]=p;
	}
	for(int i=0;i<n;i++){
		if(ans[i]!=-1){
			root=i;
			dfs(i,-1,0);
			break;
		}
	}
	queue<int> que;
	for(int i=0;i<n;i++){
		kos[i]=G[i].size();
		if(kos[i]==1)que.push(i);
	}
	while(que.size()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			int ne=G[v][i];
			mini[ne]=max(mini[ne],mini[v]-1);
			maxi[ne]=min(maxi[ne],maxi[v]+1);
			kos[ne]--;
			if(kos[ne]==1){
				que.push(ne);
			}
		}
	}
	for(int i=0;i<n;i++){
		bro[dist[i]].push_back(i);
	}
	for(int i=n;i>=0;i--){
		for(int j=0;j<(int)bro[i].size();j++){
			int v=bro[i][j];
			for(int k=0;k<G[v].size();k++){
				mini[G[v][k]]=max(mini[G[v][k]],mini[v]-1);
				maxi[G[v][k]]=min(maxi[G[v][k]],maxi[v]+1);
			}
		}
	}
	dfs(root,-1,0);
	for(int i=0;i<n;i++){
		kos[i]=G[i].size();
		if(kos[i]==1)que.push(i);
	}
	while(que.size()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			int ne=G[v][i];
			mini[ne]=max(mini[ne],mini[v]-1);
			maxi[ne]=min(maxi[ne],maxi[v]+1);
			kos[ne]--;
			if(kos[ne]==1){
				que.push(ne);
			}
		}
	}
	for(int i=0;i<n;i++){
		if(ans[i]!=-1){
			if(ans[i]!=mini[i])flag=false;
			if(ans[i]!=maxi[i])flag=false;
		}else{
			ans[i]=mini[i];
			if(maxi[i]<mini[i])flag=false;
		}
	}
	dfs(root,-1,0);
	if(!flag){
		puts("No");
		return 0;
	}
	puts("Yes");
	for(int i=0;i<n;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 48128
#include <bits/stdc++.h>
 
#define REP(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define fi first
#define sc second
#define pb push_back
#define double long double
#define all(x) x.begin(), x.end()
 
using namespace std;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<int, int> pii;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
 
const i64 MOD = 1000000007;
const i64 INF = 2e15;

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

	int n;
	cin >> n;
	
	vi64 a(n+1), b(n);
	REP(i, 0, n) cin >> a[i];
	REP(i, 0, n-1) cin >> b[i];

	i64 ans = 0;

	REP(i, 0, n-1) {
		if (b[i] >= a[i]) {
			ans += a[i];
			b[i] -= a[i];
			a[i] = 0;
		} else {
			ans += b[i];
			a[i] -= b[i];
			b[i] = 0;
		}
    	if (b[i] >= a[i+1]) {
			ans += a[i+1];
			b[i] -= a[i+1];
			a[i+1] = 0;
		} else {
			ans += b[i];
			a[i+1] -= b[i];
			b[i] = 0;
		}
	}

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
N,M=map(int,input().split())
a = [list(map(int,input().split())) for l in range(N)]
a.sort()
cost=0
for i in range(N):
    if M<=a[i][1]:
        cost+=a[i][0]*M
        break
    elif M>a[i][1]:
        M-=a[i][1]
        cost+=a[i][0]*a[i][1]
print(cost)

Measured memory_bytes: 27756
#include <iostream>

int digitsSum(int n)
{
  int total = 0;

  while(n > 0)
  {
    total += (n % 10);
    n /= 10;
  }
  return total;
}

int main()
{
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n;
  std::cin >> n;
  if (n%digitsSum(n) == 0) std::cout << "Yes\n";
  else std::cout << "No\n";
}


Measured memory_bytes: 256
N=int(input())
list=[list(map(int,input().split())) for _ in range(N)]
#print(list)
list.sort(key=lambda x:x[1])
#print(list)
      
time=0
for a,b in list:
  time=time+a
  if time>b:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 53600
import bisect

INF = 10 ** 10


N = int(input())
dp = [INF] * (N + 1)
dp[0] = -1

ans = 0
for i in range(N):
    a = int(input())
    j = bisect.bisect_left(dp, a)
    dp[j]=a
    ans = max(j,ans)
print(ans)





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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

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

const double eps = 1e-10;
const int MOD = 1000000007;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, s.size()) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int a0, l; cin >> a0 >> l;
    if(a0 == 0 && l == 0) break;
    map<int, int> m;
    int next = a0;
    m[next] = -1;
    int k = 1;
    while(1) {
      vi a(l);
      REP(i, l) {
        a[i] = next % 10;
        next /= 10;
      }

      sort(ALL(a));
      int ma = 0;
      int dig = 1;
      REP(i, l) {
        ma += a[i] * dig;
        dig *= 10;
      }

      reverse(ALL(a));
      int mi = 0;
      dig = 1;
      REP(i, l) {
        mi += a[i] * dig;
        dig *= 10;
      }

      next = ma - mi;

      if(m[next] != 0) {
        cout << max(0, m[next]) << " " << next << " " << k - max(0, m[next]) << endl;
        break;
      } else {
        m[next] = k;
        k++;
      }

    }
    
  }
  
}



Measured memory_bytes: 3136
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
unsigned long long H,W;
unsigned long long ans=0;
unsigned long long ans1=0,ans2=0;
int main(){
    cin>>H>>W;
    ans=H*W;
    if(H==1){
        cout<<"1"<<endl;
        return 0;
    }
    if(W==1){
        cout<<"1"<<endl;
        return 0; 
    }
    if(ans%2){
        ans/=2;
        ans+=1;
    }
    else
    {
        ans/=2;
    }
    
    cout<<ans<<endl;
    return 0;
    
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int A,B;
    int max;
    scanf("%d %d",&A,&B);
    
    max = A + (A-1);
    if(A + B > max){
        max = A+B;
    }
    if(B + (B-1) > max){
        max = B + (B-1);
    }
    printf("%d\n",max);
    return 0;
}


Measured memory_bytes: 128