akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <utility>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main () {
    int n;
    cin >> n;
    vector<pair<int,int> > a(n);
    rep (i, n) {
        cin >> a.at(i).first;
        a.at(i).second = i;
    }

    sort(a.begin(), a.end());

    rep (i, n) {
        cout << a.at(i).second + 1 << endl;
    }

    return 0;
}

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

using namespace std;

#define int long long

const int mod = 1e18;
// Warning: Change mod and N according to the question

inline int add(int x, int y, int mod = ::mod) {
  x += y;
  if (x >= mod or x < 0) x %= mod;
  if (x >= 0) return x;
  return x + mod;
} 
inline int mul(int x, int y, int mod = ::mod) {
  if (x >= mod or x + mod < 0) x %= mod;
  if (y >= mod or y + mod < 0) y %= mod;
  x *= y;
  if (x >= mod or x + mod < 0) x %= mod;
  if (x >= 0) return x;
  return x + mod;
}
inline int sub(int x, int y, int mod = ::mod) {
  x -= y;
  if (x + mod < 0 or x >= mod) {
    x %= mod;
  }
  if (x >= 0) return x;
  return x + mod;
}
int po(int x, int n, int mod = ::mod) {
  int res = 1;
  for (;n > 0;) {
    if (n & 1) {
      res = mul(res, x, mod);
    }
    x = mul(x, x, mod);
    n /= 2;
  }
  return res;
}


signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  vector<pair<int,int>> v;
  v.push_back({0, 0});
  for (int i = 1; i <= 200; ++i) {
    v.push_back({po(i, 5), i});  
    v.push_back({-v.back().first, -i});
  } 

  int x;
  cin >> x;
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); ++i) {
    int cur = x + v[i].first;
    auto it = lower_bound(v.begin(), v.end(), make_pair(cur, -1LL)) - v.begin();
    if (it == v.size()) continue;
    if (v[it].first == cur) {
      // cout << cur << '\n';
      assert(v[it].first - v[i].first == x);
      cout << v[it].second << ' ' << v[i].second << '\n';
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3628
def gcd(a, b):
    if a<b:
        a,b = b,a
    r = a%b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b

a,b = list(map(int,input().split()))
c = gcd(a,b)
c0 = c
r = 2
lis = [1]
count = 1
while c != 1:
    if c%r == 0:
        c = c//r
        lis.append(r)
        r = 2
    else:
        r += 1
    if r > int(pow(c0,0.5))+1:
        lis.append(c)
        break
d = list(set(lis))
print(len(d))

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<pair<int64_t, pair<int, int>>> clue;
    for(int i=0;i<n;++i){
        int x, y, h;
        cin >> x >> y >> h;
        clue.push_back({h, {x, y}});
    }
    sort(clue.rbegin(), clue.rend());
    
    for(int cx=0;cx<=100;++cx){
        for(int cy=0;cy<=100;++cy){
            int64_t h = clue[0].first + abs(clue[0].second.first - cx) + abs(clue[0].second.second - cy);
            if(clue[0].first == 0) h = 1;
            for(int i=0;i<n;++i){
                if(clue[i].first != max(0L, h - abs(clue[i].second.first - cx) - abs(clue[i].second.second - cy))) goto ng;
            }
            cout << cx << " " << cy << " " << h << endl;
            return 0;
            ng:;
        }
    }
    return 0;
}

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

int main() {
  int A, B, M; cin >> A >> B >> M;
  vector<int> a(A), b(B), x(M), y(M), c(M);
  rep(i,A) cin >> a[i];
  rep(i,B) cin >> b[i];
  rep(i,M) {
    cin >> x[i] >> y[i] >> c[i];
  }
  int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
  rep(i,M){
    ans = min(a[x[i]-1] + b[y[i]-1] - c[i], ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  string s,t;
  cin>>s>>t;
  int n=s.size();
  int m=t.size();

  int ans=100000;
  rep(i,n){
    if(i+m-1>=n) continue;
    string a=s.substr(i,m);
    int cnt=0;
    rep(j,m){
      if(a[j]!=t[j]) cnt++;
    }
    chmin(ans,cnt);
  }



  cout << ans << endl;
}

Measured memory_bytes: 3656
n=int(input())
import itertools as it

ans=0
for i in range(3,len(str(n))+1):
    pr=list(it.product("753",repeat=i))
    
    for j in pr:
        s=set(j)
        if len(s)==3:
            num=int(''.join(j))
            if num<=n:
                ans+=1
print(ans)

Measured memory_bytes: 6756
from itertools import chain

def cut(lst, k):
    return lst[k:] + lst[:k]

def riffle(lst):
    n = len(lst)//2
    return list(chain.from_iterable(zip(lst[:n], lst[n:])))

n = int(input().strip())
m = int(input().strip())
cards = list(range(1, 2*n+1))
klist = [int(input().strip()) for _ in range(m)]

for k in klist:
    if k == 0:
        cards = riffle(cards)
    else:
        cards = cut(cards, k)

for card in cards:
    print(card)



Measured memory_bytes: 5692
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int a,b,c,d,e;
  cin>>a>>b>>c;
  d=b-a;
  e=c-b;
  if(d==e)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
D = [0]*(n+1)
mod = 10**9+7

for i in range(2, n+1):
  target = i
  for j in range(2, n+1):
    while target%j==0:
      D[j] += 1
      target = target//j

ans = 1

if n==1:
  print(ans)
else:
  for k in range(2, n+1):
    ans = ans*(D[k]+1)%mod
  print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://agc020.contest.atcoder.jp/tasks/agc020_a>
問題文============================================================
 N 個のマスに区切られた細長い紙切れの上でゲームを行います。マスには 1 から N までの番号が順に付けられています。
 
 アリスの駒はマス A に、ボリスの駒は別のマス B に置かれています。
 
 二人にはターンが交互に訪れます。アリスが先手です。
 ターンが回ってきたプレイヤーは、
 自分の駒を現在のマス X から左隣のマス X−1 か右隣のマス X+1 のどちらかに動かさなければなりません。
 ただし、駒を紙切れの外に出したり、相手の駒と同じマスに動かしてはいけません。
 また、駒の移動は一ターンに一度だけ行わなければなりません。
 
 駒を動かせなくなった人が負けで、相手の勝ちとなります。
 
 二人とも、勝ちたいと思っています。二人とも最適にプレイするとき、どちらが勝つでしょうか？
=================================================================

解説=============================================================

 アリスとボリスのマスの位置の差が偶数ならば　アリスが
 そうでなければ                        ボリスがかつ
 
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N,A,B; cin >> N >> A >> B;
    if(abs(A-B)%2 != 0){
        cout<< "Borys" << endl;
    }else{
        cout << "Alice" << endl;
    }
	return 0;
}


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

int main() {
	int n, m, h[N], ma[N];

	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> h[i];
		ma[i] = 0;
	}

	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		ma[a] = max(ma[a], h[b]);
		ma[b] = max(ma[b], h[a]);
	}

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (ma[i] < h[i]) {
			ans++;
		}
	}

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

Measured memory_bytes: 4396
n,s = map(int,input().split())
a = list(map(int,input().split()))
mod = 998244353
dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    for j in range(s+1):
        if j - a[i] >= 0:
            dp[i+1][j] = (dp[i][j-a[i]]+dp[i][j]*2) % mod
        else:
            dp[i+1][j] = dp[i][j]*2 % mod
print(dp[n][s])

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> cnt(M, 0);
    rep(i, N) {
        int K; cin >> K;
        rep(j, K) {
            int A; cin >> A; --A;
            ++cnt[A];
        }
    }
    int ans = 0;
    rep(i, M) {
        if(cnt[i] == N) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define all(z) (z).begin(),(z).end() 
#define MOD 1000000007
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll isprime(ll n)
{
	for(int i=2;i<n;i++)
		if(n%i==0)
		return 0;
		
	return 1;	
}
int main()
{ 
    FAST;
	ll n;
	cin>>n;
	if(n>=30)cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 3620
use std::cmp::min;
 
fn main() {
    let nm: Vec<i32> = read_vec();
    let (n, m) = (nm[0], nm[1]);

    let mut v: Vec<(i32, i32)> = (0..m).map(|_| {
        let ab: Vec<i32> = read_vec();
        (ab[0], ab[1])
        }).collect();

    v.sort();
    let mut ans = 1;
    let mut b = n;
    for i in 0..m as usize {
        if v[i].0 < b {
            b = min(b, v[i].1);
        } else {
            b = v[i].1;
            ans += 1;
        }
    }
    
    println!("{}", ans);
}
 
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().split_whitespace().map(|e|
        e.parse().ok().unwrap()
    ).collect()
}

Measured memory_bytes: 4352
sx,sy,tx,ty=map(int,input().split())
x=tx-sx
y=ty-sy
ans="R"*x+"U"*y
ans+="L"*x+"D"*y
x+=1
y+=1
ans+="L"+"U"*y+"R"*x+"D"
ans+="R"+"D"*y+"L"*x+"U"
print(ans)

Measured memory_bytes: 9016
/* ex3_3
    suuxxu */

#include <stdio.h>

int main(void){
    int n, k, i;
    int fac; // factorial
    
    // get inputs
    scanf("%d %d", &n, &k);

    // calculate answer
    i = 0;
    fac = 1;
    while(1){
        i++;
        fac = fac * k;
        if(n < fac) break;
    }
    printf("%d\n", i);

    return 0;
}



Measured memory_bytes: 128
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.Queue

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val graph = Array.fill[List[Int]](N+1)(Nil)
  for (_ <- 1 to M) {
    val u, v = in.next().toInt
    graph(u) = v :: graph(u)
  }

  val S, T = in.next().toInt

  //
  val dp = new Array[Boolean](N+1)
  val dp2 = Array.fill[List[Int]](N+1)(Nil)

  val q = new Queue[Info]
  q.enqueue(Info(S, 3, 0))
  dp(S) = true

  var ans = -1
  breakable {
    while(!q.isEmpty) {
      val Info(node, restMove, cnt) = q.dequeue()

      if (restMove == 0) {
        if (!dp(node)) {
          if (node == T) {
            ans = cnt + 1
            break
          }
          else {
            dp(node) = true
            for (e <- graph(node))
              q.enqueue(Info(e, 2, cnt+1))
          }
        }
      }
      else if (!dp2(node).contains(restMove)){
        dp2(node) = restMove :: dp2(node)
        for (e <- graph(node))
          q.enqueue(Info(e, restMove-1, cnt))
      }
    }
  }

  println(ans)
}


case class Info(node: Int, restMove: Int, cnt: Int)

class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 75960
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
int N;
ll X,a[2000],mn[2000];
int main(){
	cin>>N>>X;
	rep(i,N) cin>>a[i];
	ll ans=1e18;
	rep(i,N) mn[i]=1e18;
	rep(i,N){
		ll tmp=i*X;
		rep(j,N){
			chmin(mn[j],a[(i+j)%N]);
			tmp+=mn[j];
		}
		chmin(ans,tmp);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, d; cin >> n >> d;
    vector<int> v(n), ans(n), p(n+1), r(n+1);
    for (int i = 0; i < n; i++) cin >> v[i];
    p[0] = d; r[n] = 1; 
    for (int i = 0; i < n; i++) {
        p[i+1] = min(abs(p[i]-v[i]), p[i]);
    }
    for (int i = n-1; i >= 0; i--) {
        r[i] = r[i+1] + v[i];
        if (v[i] - r[i+1] >= r[i+1]) {
            r[i] = min(r[i], v[i] - r[i+1]);
        }
        if (abs(r[i+1]-v[i]) >= r[i+1]) {
            r[i] = min(r[i+1], r[i]);
        }
    }
    /*
    for (int i = 0; i < n; i++) {
        cout << i << " " << p[i] << " " << r[i+1] << endl;
    }
    */
    int q; cin >> q;
    while (q--) {
        int c; cin >> c; c--;
        if (p[c] < r[c+1]) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 9728
import std.stdio;
import std.typecons;
import std.algorithm;

void main() {
	long n, m;
	scanf("%ld %ld", &n, &m);
	Tuple!(long, long)[] ss;
	foreach(i;0..n) {
		long a, b;
		scanf("%ld %ld", &a, &b);
		ss ~= tuple(a, b);
	}
	ss.sort!((a, b) => a[0] < b[0]);
	long p;
	foreach(s; ss) {
		if (m <= 0) break;
		p += s[0] * min(m, s[1]);
		m -= s[1];
	}
	write(p);
}


Measured memory_bytes: 3068
#pragma GCC optimize("O3")

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define For(i, a, b)    for(int i = (a); (i) < (b) ; ++(i))
#define CtoI(c)         int((c)) - int('0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

bool isPrime(int n){
    if(n < 2) return false; else if(n == 2) return true; else if(n%2 == 0) return false;
    double sqrtNum = sqrt(n); for(int i = 3;i <= sqrtNum; i += 2) if(n%i == 0) return false;
    return true;
    }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];

    int min = INF9;
    int cnt = 0;
    for(auto &x : p){
        if(chmin(min, x)) ++cnt; 
    }

    cout << cnt << endl;

return 0;
}

Measured memory_bytes: 3968
package main

import "fmt"

type vec struct {
	x int
	y int
}

func main() {
	var n int
	fmt.Scan(&n)
	rr := make([]vec, n)
	for i := range rr {
		var x, y int
		fmt.Scan(&x, &y)
		rr[i] = vec{x: x, y: y}
	}
	br := make([]vec, n)
	for i := range br {
		var x, y int
		fmt.Scan(&x, &y)
		br[i] = vec{x: x, y: y}
	}
	re := make([]bool, n)
	be := make([]bool, n)

	ans := 0
	for i := 0; i < n; i++ {
		leftb := -1
		for j := 0; j < n; j++ {
			if be[j] {
				continue
			}
			if leftb == -1 {
				leftb = j
				continue
			}
			if br[j].x < br[leftb].x {
				leftb = j
			}
		}
		be[leftb] = true
		tr := -1
		for j, v := range rr {
			if re[j] {
				continue
			}
			if v.x < br[leftb].x && v.y < br[leftb].y {
				if tr == -1 {
					tr = j
					continue
				}
				if rr[tr].y < v.y {
					tr = j
				}
			}
		}
		if tr != -1 {
			ans++
			re[tr] = true
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <map>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <cmath>
#include <queue>
#include <ctime>
#include <utility> // std::pair
#include <functional> // std::greater <int> ()
#define int long long
#define MAXN 500000 // check
#define inf 1000000000000000001
#define BASE 29 // hashings mod, can be rand'd
#define mod 998244353 // can be 1000000007
#define pi 3.1415926535897
#define pii pair <int, int>
#define fii first
#define see second

typedef long long ll;
typedef long double ld;
using namespace std;

int n;
int a[MAXN+5], b[MAXN+5];
int ans=0;

// functions
void input(){
	cin >> n;
	for(int i=1; i<=n+1; i++) cin >> a[i];
	for(int i=1; i<=n; i++) cin >> b[i];
	return;
}

void solve(){
	for(int i=1; i<=n; i++)
	{
		int t=min(b[i], a[i]);
		b[i]-=t;
		a[i]-=t;
		ans+=t;
		t=min(b[i], a[i+1]);
		b[i]-=t;
		a[i+1]-=t;
		ans+=t;
	}
	return;
}

void output(){
	cout << ans;
	return;
}

signed main(){
/*
//  REMEMBER TO TURN OFF IFDEF IN PROBLEMS WITH FILE I/O
*/
#ifdef sheeep
	freopen("forces.inp", "r", stdin);
	freopen("forces.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
//	int t;
//	cin >> t;
//	for(int i=1; i<=t; i++){
		input();
		solve();
		output();
//	}
	return 0;
}
// Author: NamSPro

Measured memory_bytes: 5120
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()
#define uniq(xs) (xs.erase(unique(xs.begin(), xs.end()), xs.end()))

template<class T>
ostream& operator<<(ostream& os, const vector<T>& vs) {
    if (vs.empty()) return os << "[]";
    os << "[" << vs[0];
    for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
    return os << "]";
}

const int IINF = 1<<28;
const Long LINF = 1LL<<56;
#define INF IINF

int V, E;

struct Edge {
    int s, t, w;
    Edge(int s, int t, int w) : s(s), t(t), w(w) {}
    bool operator<(const Edge& e) const {
        return w < e.w;
    }
};

vector<Edge> G;

void Input() {
    cin >> V >> E;
    for (int i = 0; i < E; i++) {
        int s, t, w; cin >> s >> t >> w;
        G.push_back(Edge(s, t, w));
    }
}

struct UnionFind {
    int N;
    vector<int> P;
    UnionFind(int N) : N(N) {
        P.clear(); P.resize(N, -1);
    }
    int query(int x) {
        if (P[x] == -1) return x;
        return P[x] = query(P[x]);
    }
    void merge(int x, int y) {
        x = query(x); y = query(y);
        if (x == y) return;
        P[y] = x;
    }
};

void Solve() {
    sort(whole(G));
    UnionFind uf(V);
    int Ans = 0;
    for (int i = 0; i < E; i++) {
        Edge& e = G[i];
        if (uf.query(e.s) == uf.query(e.t)) continue;
        Ans += e.w;
        uf.merge(e.s, e.t);
    }
    cout << Ans << endl;
}

int main() {
    Input(); Solve();
    return 0;
}

Measured memory_bytes: 2704
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

int H, W, N;
int sr, sc;
std::string S, T;

int main(){
	int aP[4] = {}; //L, U, R, D
	int bP[4] = {};
	int mP[4];

	std::map<char, int> cton;
	cton['L'] = 0, cton['R'] = 2, cton['U'] = 1, cton['D'] = 3;

	std::cin >> H >> W >> N;
	std::cin >> sr >> sc;

	mP[0] = sc - 1, mP[2] = W - sc, mP[1] = sr - 1, mP[3] = H - sr;

	std::cin >> S >> T;

	int n = 0;
	int bdir, brdir;
	while(N--){
		if(n != 0){
			bP[bdir] = std::min(bP[bdir] + 1, mP[bdir] + aP[brdir]);
		}
		int dir = cton[S[n]];
		int rdir = (dir + 2) % 4;
		++aP[dir];
		if(aP[dir] - bP[rdir] > mP[dir]){
			std::cout << "NO" << std::endl;
			return 0;
		}
		bdir = cton[T[n]];
		brdir = (bdir + 2) % 4;
		++n;
	}

	std::cout << "YES" << std::endl;

	return 0;
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int main(){
    LL n,a,b;
    scanf("%lld %lld %lld",&n,&a,&b);
    if((b-a)%2==0){
        printf("%lld\n",(b-a)/2);
    }
    else{
        LL res1=((b-1)+(a-1)+1)/2;
        LL res2=((n-a)+n-b+1)/2;
        printf("%lld\n",min(res1,res2));
    }
}
/*
35
2 1
3 1
4 1
5 1
6 1
8 1
9 1
10 1
11 1
12 1
14 1
15 1
16 1
17 1
18 1
20 1
21 1
22 1
23 1
24 1
26 1
27 1
28 1
29 1
30 1
32 1
33 1
34 1
35 1
36 1
38 1
39 1
40 1
41 1
42 1
335943.04760763
*/

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

int main(){
    int num[100];
	char s[2];
	int count=0;

	while(scanf("%s",s)!=EOF){
		if(s[0]=='+'){
			num[count-2]=(num[count-2]+num[count-1]);
			count--;
		}else if(s[0]=='-'){
			num[count-2]=(num[count-2]-num[count-1]);
			count--;
		}else if(s[0]=='*'){
			num[count-2]=(num[count-2]*num[count-1]);
			count--;
		}else{
			num[count++]=atoi(s);
		}/*
		for(int i=0;i<count;i++){
			printf("%d ",num[i]);
		}printf("\n");*/
	}
	
	printf("%d\n",num[0]);

	return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
using namespace std;

int main(){
  int n;
  cin >> n; cin.ignore();

  if (n < 2) {
    cout << 0 << endl;
    return 0;
  }

  int ary[n];
  for (uint32_t i = 0; i < n; i++) {
    cin >> ary[i];
#if defined(DEBUG)
    printf("D(L%3d): ary[%3d] = %d\n", __LINE__, i, ary[i]);
#endif
  }

  int maxProf = ary[1] - ary[0];
  int minRi = ary[0];
  for (uint32_t i = 2; i < n; i++) {
    if (minRi > ary[i-1])
      minRi = ary[i-1];

    int profit = ary[i] - minRi;
    if (maxProf < profit)
      maxProf = profit;
  }

  cout << maxProf << endl;
  return 0;
}

Measured memory_bytes: 3848
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<numeric>
#include<map>
#include<math.h>

using namespace::std;

int main(void)
{

  int N , M;

  while( cin >> N >> M ,!(N == 0 && M == 0))
    {

      vector<int> map(N + 1);
      vector<int> dice(M + 1);

      for(int i = 1; i <= N; i++)
	{
	  cin >> map[i];
	}

      for(int i = 1; i <= M; i++)
	{
	  cin >> dice[i];
	}

      int now = 1;

      for(int i = 1; i <= M; i++)
	{
	  now += dice[i];
	  now += map[now];
	  if( now >= N )
	    {
	      cout << i << endl;
	      break;
	    }
	}
    }
  return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>

using namespace std;

const int INF=100000000;


class Node{
public:
	int now_mission,ship,sum;
	Node(int now_mission,int ship,int sum):now_mission(now_mission),ship(ship),sum(sum){};
};

bool operator < (Node a,Node b){
	return a.sum>b.sum;
}


int main()
{
	int N,M;
	while(cin>>N>>M && N!=0){
		vector<vector<int> > dist_ground(N,vector<int>(N,INF));
		vector<vector<int> > dist_sea(N,vector<int>(N,INF));

		for(int i=0;i<M;i++){
			int x,y,t; char c;
			cin>>x>>y>>t>>c;
			x--;y--;
			if(c=='L'){
				dist_ground[x][y]=min(dist_ground[x][y],t);
				dist_ground[y][x]=min(dist_ground[y][x],t);
			}
			else{
				dist_sea[x][y]=min(dist_sea[x][y],t);
				dist_sea[y][x]=min(dist_sea[y][x],t);
			}
		}
		for(int i=0;i<N;i++){
			dist_sea[i][i]=dist_ground[i][i]=0;
		}
		int R;cin>>R;
		vector<int> mission(R);
		for(int i=0;i<R;i++){cin>>mission[i];mission[i]--;}


		for(int k=0;k<N;k++){
			for(int i=0;i<N;i++){
				for(int j=0;j<N;j++){
					dist_sea[i][j]=min(dist_sea[i][j],dist_sea[i][k]+dist_sea[k][j]);
					dist_ground[i][j]=min(dist_ground[i][j],dist_ground[i][k]+dist_ground[k][j]);
				}
			}
		}
		
		vector<vector<int> > memo(R,vector<int>(N,INF));
		memo[0][mission[0]]=0;
		for(int i=1;i<R;i++){
			int area=mission[i-1];
			for(int j=0;j<N;j++){
				memo[i][j]=min(memo[i][j],memo[i-1][j]+dist_ground[area][mission[i]]);


				for(int k=0;k<N;k++){
					memo[i][j]=min(memo[i][j],
						memo[i-1][k]+dist_ground[area][k]+dist_sea[k][j]+dist_ground[j][mission[i]]
					);
				}
			}
		}

		int ans=INF;
		for(int i=0;i<N;i++){
			ans=min(ans,memo[R-1][i]);
		}
		cout<<ans<<endl;


/*		priority_queue<Node> que;
		que.push(Node(0,mission[0],0));



		while(!que.empty()){
			Node info=que.top(); que.pop();
			if(info.sum>=memo[info.now_mission][info.ship]) continue;
//			cout<<"now "<<info.now_mission<<" "<<info.ship<<" "<<info.sum<<endl;
			memo[info.now_mission][info.ship]=info.sum;

			if(info.now_mission==R-1){cout<<info.sum<<endl;break;}
			int target=mission[info.now_mission+1];
			
			int now_area=mission[info.now_mission];
			que.push(Node(info.now_mission+1,info.ship,info.sum+dist_ground[now_area][target]));

			for(int relay=0;relay<N;relay++){
				int next_cost=dist_ground[now_area][info.ship]+dist_sea[info.ship][relay]+dist_ground[relay][target];
				if(next_cost<INF)
					que.push(Node(info.now_mission+1,relay,info.sum+next_cost));
			}
		}*/
	}
	return 0;
}

Measured memory_bytes: 2032
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var union = new UnionFind<int>();
        var nm = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        for (var i = 0; i < nm[0]; i++)
            union.MakeSet(i);
        for(var i = 0; i < nm[1]; i++)
        {
            var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
            union.Union(ar[0], ar[1]);
        }
        var qu = ToInt32(ReadLine());
        var res = new string[qu];
        for(var i = 0; i < qu; i++)
        {
            var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
            res[i] = union.IsSame(ar[0], ar[1]) ? "yes" : "no";
        }
        WriteLine(string.Join("\n", res));
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}

public class UnionFind<T>
{
    private class Vertex
    {
        public T Key { get; set; }
        public Vertex Parent { get; set; }
        public int Rank { get; set; }

        public Vertex(T key) : this(key, null, 0)
        {

        }
        public Vertex(T key, Vertex Parent, int rank)
        {
            this.Key = key;
            this.Parent = Parent;
            this.Rank = rank;
        }
    }
    private readonly Dictionary<T, Vertex> dics;
    private readonly Vertex NIL;

    public int Count { get; private set; }

    public UnionFind()
    {
        NIL = new Vertex(default(T));
        dics = new Dictionary<T, Vertex>();
    }

    public T parent(T key)
        => FindSet(dics[key].Parent).Key;

    public bool IsSame(T key1, T key2)
    {
        if (!dics.ContainsKey(key1) || !dics.ContainsKey(key2))
            throw new ArgumentException("対応する頂点が存在しません");
        return ReferenceEquals(FindSet(dics[key1]),FindSet(dics[key2]));
    }

    public bool MakeSet(T key)
    {
        if (dics.ContainsKey(key))
            throw new ArgumentException($"{key}をキーとして持つ頂点が既に存在します");
        dics[key] = new Vertex(key, NIL, 0);
        dics[key].Parent = dics[key];
        Count++;
        return true;
    }

    public bool Union(T key1, T key2)
    {
        if (!dics.ContainsKey(key1) || !dics.ContainsKey(key2))
            throw new ArgumentException("対応する頂点が存在しません");
        if (IsSame(key1, key2)) return false;
        Link(FindSet(dics[key1]), FindSet(dics[key2]));
        Count--;
        return true;
    }

    private bool Link(Vertex vex1, Vertex vex2)
    {
        if (vex1.Rank > vex2.Rank)
            vex2.Parent = vex1;
        else
        {
            vex1.Parent = vex2;
            if (vex1.Rank == vex2.Rank)
                vex2.Rank++;
        }
        return true;
    }

    private Vertex FindSet(Vertex vex)
    {
        if (!ReferenceEquals(vex.Parent, vex))
            vex.Parent = FindSet(vex.Parent);
        return vex.Parent;
    }
}



Measured memory_bytes: 34696
/*
        ***Fresher***
    Md Mahfujur Rahman Khan
    Dept. of CSE
    CSE-28 Batch
    JU-48 Batch
    Jahangirnagar University

*/
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
using namespace std;
#define V_ vector
#define Q_ queue
#define S_ set
#define ST_ stack
#define M_ map
#define DQ_ deque

#define pii pair<ll,ll>
#define pci pair<char,ll>
#define psi pair<string, ll>
#define pis pair<ll,string>
#define pic pair<ll, char>

#define mii map<ll,ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define mib map<ll,bool>
#define msb map<string,bool>

#define vi vector<ll>
#define vs vector<string>

#define ivi vector<ll> :: iterator
#define ivs vector<string> :: iterator
#define imii map<ll,ll> :: iterator
#define imsi map<string,ll> :: iterator
#define imis map<ll, string> :: iterator
#define imib map<ll, bool> :: iterator
#define imsb map<string, bool> :: iterator

#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define F first
#define S second
#define pi 2*acos(0.0)
#define PB(x) push_back(x)
#define PP(x) push(x)
#define RSZ(n) resize(n)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN_ length()
#define SZ_ size()
#define CNT_ count()
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN_ insert
#define ER_  erase
#define GT getline
#define NL_   "\n"
#define SP_ " "

#define fr(i, n) for( ll i = 0; i < n; i++)
#define fe(x, n) for( ll i = x; i <= n; i++)

#define ul unsigned long long int
#define ll long long int
#define  MAX 250000

ll i, T, N, tc =0, t= 0;
mib mp;
void tt(ll n)
{
    t++;
//    cout << n << NL_;
    if(mp.count(n))
    {
        return ;
    }
    else mp[n] = true;
    if(n%2) tt(3*n+1);
    else tt(n/2);
    return;

}


int main()
{
ll n;
 cin >> n;
 tt(n);
 cout << t;
return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <stack>

using namespace std;

static const int N = 100;

static const int WHITE = 0;

static const int GRAY = 1;

static const int BLACK = 2;




//用递归的方式实现图深度优先搜索


/**
 * color 标记访问状态的数组，
 * M[N][N] 邻接矩阵 如果存在定点i到顶点j的边，则M[i][j]=trul
**/
int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs(int u) {
    int v;
    color[u] = GRAY;

    d[u] = ++tt;

    for (v = 0; v < n; v++) {
        if (M[u][v] == 0)
            continue;
        if (color[v] == WHITE) {
            dfs(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs() {
    int u;
    for (u = 0; u < n; u++) {
        if (color[u] == WHITE) {
            dfs(u);
        }
    }

    for (u = 0; u < n; u++) {
        cout << u + 1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main() {
    int u, k, v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int i = 0; i < k; i++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    dfs();
    return 0;
}


Measured memory_bytes: 3108
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define K 1000000000000000000

int main(){
long long ans = 1;
int n;
bool flag = false;
cin >> n;
for(int i=0;i<n;++i){
  long long b;
  cin >> b;
  if (b == 0){
    cout << 0 << endl;
    return 0;
  }


  if(flag || (K+1) / ans < b || ans * b > K){
    flag = true;
  }
  ans *= b;

}

if (flag){
  cout << -1 << endl;
  return 0;
}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	long long a, b, k;
	cin >> a >> b >> k;
	a -= k;
	if (a < 0) {
		b += a;
		a = 0;
	}
	if (b < 0) { b = 0; }
	printf("%lld %lld", a, b);
	return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";
        int32_t main()
        {
            tani_nachi_ke  
            
            
            int n;
            cin >> n;
            n %= 1000;
            if(n == 0)
                cout << 0 << '\n';
            else
                cout << 1000 - n << '\n';




           return 0;
        }
          

Measured memory_bytes: 3648
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = LI()
q = I()
ans = sum(A)
cnt = Counter(A)
for _ in range(q):
    b, c = LI()
    ans += cnt[b] * (c - b)
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(ans)



Measured memory_bytes: 109460
#!/usr/bin/env ruby

n = gets.chomp!.to_i

n.times do
  balls = gets.chomp!.split(" ").map(&:to_i)
  a,b=0,0

  ng = false
  balls.each do |ball|
    if a < ball
      a = ball
    elsif b < ball
      b = ball
    else
      ng = true
    end
  end

  puts (ng) ? "NO" : "YES"
end

Measured memory_bytes: 8652
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <cmath>
#include <cassert>

#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, MOD = 1e9 + 7;

int N, K, h[MN], dp[MN];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N >> K;
    for (int i = 1; i <= N; i++) cin >> h[i];
    memset(dp, 0x3f, sizeof(dp));
    dp[1] = 0;
    for (int i = 2; i <= N; i++) {
        for (int j = max(1, i - K); j < i; j++) {
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    cout << dp[N] << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

#define int long long 

void show_ans(ll ans) {
  cout << ans << endl;
}

signed main() {
  int n,k;
  cin >> n >> k;
  map<int, int> mp;
  // ネタの種類
  ll total = 0;
  vector<pair<int,int> > data;

  ll t,s;
  rep(i,n) {
    cin >> t >> s;
    // ネタのおいしさ、ネタの種類
    data.pb(make_pair(s,t));
    if (mp[t] == 0) total++;
    mp[t] += 1;
  }

  // ネタのおいしさで昇順にsort
  sorti(data);
  // どのネタを食べたかチェックするmap
  map<ll,ll> check;
  ll kd = 0, cnt = 0, itr = n-1, ans = 0;
  // ネタのおいしさを降順に
  priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > sushi;
  for (int i = n-1; i >= 0; --i) {
    ll various = data[i].second, value = data[i].first;
    cnt += 1;
    itr = i;
    ans += value;
    sushi.push(data[i]);
    if (check[various] == 0) kd++;
    check[various] += 1;
    
    if (cnt == k) break;
  }
  
  ll tmpans = ans;
  ans = ans + (kd * kd);
  if (itr == 0 or total == kd) {
    show_ans(ans);
    return 0;
  }

  for (int i = itr; i >= 0; --i) {
    if (sushi.size() == 0) break;
    ll various = data[i].second, value = data[i].first;
    if (check[various] > 0) continue;
    
    bool flag = false;
    while (sushi.size()) {
      pair<int,int> p = sushi.top();
      sushi.pop();
      if (check[p.second] > 1) {
        // ネタを1つ減らす
        check[p.second] -= 1;
        // おいしさを減らす
        tmpans -= p.first;
        break;
      } else {
        if (sushi.size() == 0) {
          flag = true;
        }
      }
    }

    if (flag) {
      break;
    }
    kd += 1;
    check[various] += 1;
    tmpans += value;
    ans = max(ans, tmpans + (kd * kd));
    if (kd == k) break;
  }

  show_ans(ans);
}


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

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; }

using ll = long long;
using P = pair<int,int>;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    vector<vector<P>> v(10);
    rep(i,10){
        v[i].push_back(make_pair(0,0));
        v[i].push_back(make_pair(0,i));
    }
    rep(i,10){
        while(true){
            P p = *v[i].rbegin();
            int t = i*10 + p.second;
            int cnt = 0;
            while(t>=10){
                t = t/10+t%10;
                cnt++;
            }
            v[i].push_back(make_pair(p.first+cnt,t));
            if(t==i) break;
        }
    }
    v[0][2].first = 1;
    ll M;
    cin>>M;
    vector<ll> d(M),c(M);
    rep(i,M) cin>>d[i]>>c[i];
    ll ans = 0;
    vector<ll> rest(M);
    rep(i,M){
        ll t = d[i],s=c[i];
        ll l = v[t].size();
        ans+=v[t][l-1].first*((s-1)/(l-2));
        s = s - ((s-1)/(l-2))*(l-2);
        ans += v[t][s].first;
        rest[i]=v[t][s].second;
    } 
    ll cnt = 0;
    while(cnt!=M-1){
        while(rest[cnt]!=0){
            ll a = rest[cnt],b=rest[cnt+1];
            rest[cnt] = (a+b)/10;
            rest[cnt+1] = (a+b)%10;
            ans++;
        }
        cnt++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8016
#include<bits/stdc++.h>
using namespace std;
#define outc cout
#define int long long
signed main(){
  int a,g[1000000]={};
  int b=0,c=1,d,e=0,f=0,l=0;
  cin>>g[0]>>g[1]>>g[2];
  while(1){
  for(int i=0;i<3;i++){
    if(g[i]%2==1) e=1;
    else{
      b=(g[0]/2);
      c=(g[1]/2);
      d=(g[2]/2);
      //outc<<b<<" "<<c<<" "<<d<<"\n";
    }
   }
  if(e) break;
    if(f==100){
      l=1;
      break;
    }
  ++f;
    
  g[0]=c+d;
  g[1]=b+d;
  g[2]=c+b;
    //cout<<g[0]<<" "<<g[1]<<" "<<g[2]<<"\n";
  }
  if(l) cout<<"-1\n";
  else cout<<f<<"\n";
  }


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

int main(void) {
    int a, b, c, ans;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> c;
    if (a == b) {
        ans = c;
    } else if(b == c) {
        ans = a;
    } else {
        ans = b;
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << max(0LL, C - (A - B)) << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int cup, ctr;
    int psn[ 50 ] = { 0 };
    int n, p;

    scanf ( "%d%d", &n, &p );
    if ( !( n | p ) ) break ;

    cup = p;
    for ( ctr = 0; psn[ ctr ] != p; ctr = ( ctr + 1 ) % n )
    {
      if ( cup )
      {
        ++psn[ ctr ];
        --cup;
      }
      else
      {
        cup = psn[ ctr ];
        psn[ ctr ] = 0;
      }
    }

    printf ( "%d\n", ctr );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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 (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    vi h(N);
    REP(i,N) cin >> h[i];

    bool ok = true;
    h[N-1]++;
    for (int i=N-1; i>=1; i--) {
        if (i != N-1) if (h[i] < h[i+1]) h[i]++;
        if (h[i-1] > h[i]) ok = false;
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define bash push_back
#define alles(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,-1,1,-1,1};
const int INF=1 << 30;
bool inside(int x,int y,int w,int h){
  return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vit;
typedef map<string,int> mstit;
typedef priority_queue<int> pqit;





int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  string s,t;
  int n;;
  cin >>n;
  cin >>s>>t;
  int minv=n*2;

  FOR(i,n){
    string ss = s,tt = t;
    bool m=true;;
    iFOR(j,i,n){
      if(s[j]!=t[j-i]) {
        m=false;
        break;
      }
    }
    if(m){
      minv=min(minv,n*2-(n-i));
    }
  }
  cout <<minv fin;
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

int main() {
    double x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    
    printf("%.5lf\n", sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)));
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

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...);
}

int main(){
	int n,m;
	int a,b;
	cin >> n>>m;
	int ans[n];
	FOR(i,n) ans[i]=0;
	for(int i=0;i<m;i++){
		cin >> a >> b;
		ans[a-1]++;
		ans[b-1]++;
	}	
	FOR(i,n) cout << ans[i]<<"\n";
	return 0;
}

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

int n;
priority_queue<int> q;

int main(void){
    cin >> n;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        q.push(a);
    }
    int s;
    s = 0;
    for(int i = 0; i < n; i++){
        if(i%2==0) s+=q.top();
        else s-=q.top();
        q.pop();
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3628