akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
#import numba

def sum_between(a, b):
    l, r = min(a,b), max(a,b)
    return (r-l+1) * (r+l) // 2

def run():
    N = int(input())
    n_dots = 0
    for i in range(1, N+1):
        n_dots += (1+i) * i // 2
    #print(n_dots)
    ans = (N-1) * (N+1) * N // 2
    #print(ans)
    for i in range(N-1):
        u, v = map(int, input().split())
        l, r = min(u, v), max(u, v)
        tmp = 0
        if l > 1: tmp += sum_between(r-1, r-l+1)
        tmp += r-l
        tmp += sum_between(N-l, 1)
        #print(tmp)
        ans -= tmp

    print(n_dots - ans)


    ans = (N-1) * N * N


if __name__ == "__main__":
    run()

Measured memory_bytes: 9276
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
#define INF 1LL<<60

ll dp[1100][5000];

int main()
{
  int n,m;
  cin >> n >> m;
  vector<ll> a(m), b(m), c(m,0);
  REP(i,m){
    cin >> a[i] >> b[i];
    REP(j,b[i]){
      int t;
      cin >> t;
      t--;
      c[i] += (1<<t);
    }
  }
  
  REP(i,1100){
    REP(j,5000){
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  
  REP(i,m){
    REP(j,(1<<n)){
      if(dp[i+1][j] > dp[i][j]) dp[i+1][j] = dp[i][j];
      int nj = j | c[i];
      if(dp[i+1][nj] > dp[i][j]+a[i]) dp[i+1][nj] = dp[i][j]+a[i];
    }
  }
  cout << (dp[m][(1<<n)-1] < INF ? dp[m][(1<<n)-1] : -1) << endl;
  return 0;
}


Measured memory_bytes: 43264
import math
n,d=map(int,input().split())

x = [list(map(int, input().split())) for _ in range(n)]

co=0

for i in range(n-1):
    for j in range(i+1,n):
        kyori=0
        mi=0
        for k in range(d):
            mi=mi+(abs(x[i][k]-x[j][k]))**2
        kyori=math.sqrt(mi)
        if kyori.is_integer()==True:
            co=co+1

print(co)

Measured memory_bytes: 3064
S = set(input())

alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}

a = alphabet.difference(S)

ans = list(a)
ans.sort()

try:
    print(ans[0])
except:
    print("None")

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;

bool foo() {
    int a[100000];
    uint64_t n;
    uint64_t s = 0;
    cin >> n;
    if (n == 1) return true;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s += a[i];
    }

    uint64_t m = n * (n + 1) / 2;
    if (s % m != 0) return false;

    uint64_t k = s / m;
    for (int i = 0; i < n; i++) {
        int j = i == 0 ? n - 1 : i - 1;
        int d = -(a[i] - a[j] - k);
        if (d < 0 || d % n != 0) return false;
    }
    return true;
}

int main() {
    cout << (foo() ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;

int main() {
  int a,b;
  cin >> a>> b;
  int tmp,tmps;
  vector<int> list(a);
  vector<int> flags(a);
  for (int i = 0; i < a; i++) {
    cin >> list[i];
  }
  int ans =0;
  rep(i, b) {
    cin >> tmp >> tmps;
    tmp--;
    tmps--;
    if (list[tmp] >= list[tmps]) {
      flags[tmps]=1;
    }
    if (list[tmp] <= list[tmps]) {
      flags[tmp] = 1;
    }
  }
  rep(i, a) {
    if (flags[i] == 0) {
      ans++;
    }
  }
  cout << ans;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 4024
// https://atcoder.jp/contests/apc001/tasks/apc001_c
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    int n;
    string s, t = "";
    cin >> n;
    int l = 0, r = n;
    cout << 0 << endl;
    cin >> s;
    if (s == "Vacant")
        return 0;
    while (t != "Vacant") {
        int m = (l + r) / 2;
        cout << m << endl;
        cin >> t;
        if (m % 2 ^ s == t)
            l = m;
        else
            r = m;
    }

    return 0;
}


Measured memory_bytes: 852
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

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

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

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

    ll ans = 0;
    for(int bit = 0; bit < (1 << s.size() - 1); bit++){
        vector<int> l;
        for(int i = 0; i < s.size() - 1; i++){
            if(bit & (1 << i)){
                l.push_back(i);
            }
        }
        if(l.size() == 0){
            
        }
        
        ll tmp = 0;
        if(l.size() == 0){
            for(int i = 0; i < s.size(); i++){
                tmp *= 10;
                tmp += s[i] - '0';
            }
            ans += tmp;
            continue;;
        }

        tmp = 0;
        for(int i = 0; i <= l[0]; i++){
            tmp *= 10;
            tmp += s[i] - '0';
        }

        ans += tmp;

        for(int i = 1; i < l.size(); i++){
            int tmp2 = 0;
            for(int j = l[i - 1] + 1; j <= l[i]; j++){
                tmp2 *= 10;
                tmp2 += s[j] - '0';
            }
            ans += tmp2;
        }
        
        tmp = 0;
        for(int i = l[l.size() - 1] + 1; i < s.size(); i++){
            tmp *= 10;
            tmp += s[i] - '0';
        }
        ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	int n, m;
	cin >> n >> m;
	vi x(n);
	rep(i,0,n) {
		cin >> x[i];
	}
	map<int, int> r;
	rep(i,0,n) {
		r[x[i]]++;
	}
	vector<vi> b(m);
	for(auto e:r) {
		int idx = e.F % m;
		b[idx].pb(e.S);
	}
	int ret = 0;
	for(int k=0; k<=m/2; ++k) {
		int total = 0;
		rep(i,0,sz(b[k])) {
			total += b[k][i];
		}
		if((2*k)%m == 0) {
			ret += total/2;
			continue;
		}
		int rtotal = 0;
		rep(i,0,sz(b[m-k])) {
			rtotal += b[m-k][i];
		}
		int idx;
		int limit = abs(total - rtotal)/2;
		if(total == rtotal) {
			ret += total;
			idx = -1;
		} else if(total > rtotal) {
			ret += rtotal;
			idx = k;
		} else {
			ret += total;
			idx = m-k;
		}
		if(idx == -1) continue;
		total = 0;
		rep(i,0,sz(b[idx])) {
			total += b[idx][i]/2;
		}
		ret += min(limit, total);
	}
	cout << ret << '\n';
	return 0;
}


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

int main(int argc, char *argv[]) {
  int N;
  cin >> N;
  int ans = N;
  for(int i = 0; i <= N; i++) {
    int count = 0;
    int t = i;
    int j = 0;
    while(t >= pow(6, j)) {
      count += (int)(t / pow(6, j)) % 6;
      j++;
    }

    t = N - i;
    j = 0;
    while(t >= pow(9, j)) {
      count += (int)(t / pow(9, j)) % 9;
      j++;
    }

    ans = min(ans, count);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
# coding: utf-8
dic={'N':(0,1),'E':(1,0),'S':(0,-1),'W':(-1,0)}

def move(v,robot):
    return (robot[0]+dic[v][0],robot[1]+dic[v][1])
while True:
    n=int(input())
    if n==0:
        break
    field=[[False for i in range(21)] for i in range(21)]
    for i in range(n):
        x,y=map(int,input().split())
        field[y][x]=True
    m=int(input())
    robot=(10,10)
    if field[10][10]:
        n-=1
        field[10][10]=False
    for i in range(m):
        v,f=input().split()
        for j in range(int(f)):
            robot=move(v,robot)
            if field[robot[1]][robot[0]]:
                n-=1
                field[robot[1]][robot[0]]=False
    print('Yes' if n==0 else 'No')


Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int x,y;
int main(){
	cin >> x >> y;
	if(y%2==1 or y>x*4 or y<x*2)puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 3600
#!/usr/bin/python

import sys

def main(argv):
    n = sys.stdin.readline().rstrip()

    while n:
        t = [int(i) for i in raw_input().split()]
        m = int(raw_input())
        total = sum(t)
        for i in xrange(1, m + 1):
            p, x = [int(j) for j in raw_input().split()]
            print total - t[p - 1] + x

        n = sys.stdin.readline().rstrip()

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2568
#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 = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int X;
  cin >> X;
  ll ans = 0;
  P n ;
  for (int i = 1; i < 1001; i++) {
    for (int j = 2; j <= 10; j++) {
      ll num = pow(i, j);
      if(num<=X&&ans<=num){
        n=P(i, j);
        ans = max(ans, num);
      }
    }
  }
  cout << pow(n.first,n.second) << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include <climits>
#include<cstdio>
using namespace std;

const int MAX = 2 * 100000;
long long count=0;
int a[MAX];


void Merge(int a[],int l,int mid,int r){
  int n1 = mid - l+1,n2 = r-mid;
  int L[n1+1],R[n2+1];
  for(int i=0;i<n1;i++){
    L[i]=a[l+i];
  }
  for(int i=0;i<n2;i++){
    R[i]=a[mid+i+1];
  }
  L[n1]=R[n2]=INT_MAX;
  int pr =0,pl = 0;
  for(int i=l;i<r+1;i++){
    if ( L[pl] <= R[pr]){
      a[i]=L[pl++];
    }
    else if (L[pl]>R[pr]){
      ::count+=n1-pl;
      //cout << R[pr] << endl;
      a[i]=R[pr++];
    }
  }
  
}

void MergeSort(int a[],int l,int r){
  if (l < r){
    int q = (r+l)/2;
    MergeSort(a,l,q);
    MergeSort(a,q+1,r);
    Merge(a,l,q,r);
  }

}

int main(){
  string in;
  cin >> in;
  int n = in.size();
  ::count = 0;
  for(int i = 0;i < n;i++){
    if (in[i] == 'W'){
      a[i] = 0;
    } else if (in[i] == 'B'){
      a[i] = 1;
    }
  }
  MergeSort(a, 0, n-1);
  cout << ::count << endl;
}


/*
int main(){
  string in;
  cin >> in;
  int n = in.size();
  long long ans=  0;
  int bcnt = 0;
  for(int i = 0;i < n;i++){
    if (in[i] == 'W'){
      ans += bcnt;
    } else if (in[i] == 'B'){
      bcnt++;
    }
  }
  cout << ans << endl;
}
*/


Measured memory_bytes: 2180
def run(N, T, A, H):
    ret = 0
    diff = 999
    for i in range(len(H)):
        tmp = T - H[i]*0.006
        if diff > abs(tmp - A):
            ret = i+1
            diff = abs(tmp - A)
    return ret


def main():
    N = int(input())
    T, A= map(int, input().split())
    H = list(map(int, input().split()))
    print(run(N, T, A, H))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
(let ((a (read))
    (b (read))
    (ans -1))
    (loop for i from 1 below 10000 do
        (if (and (= (floor (* i (rationalize 0.08))) a)
            (= (floor (* i (rationalize 0.1))) b))
                (setq ans i)
        )
        (if (not (= ans -1))
        (return))
    )
    (princ ans)
)

Measured memory_bytes: 24748
N = int(input())
B = list(map(int,input().split(' ')))
A = [10**5+1]*N
for i in range(N - 1):
    A[i] = A[i] if A[i]<B[i] else B[i]
    A[i + 1] = A[i + 1] if A[i + 1]<B[i] else B[i]
    
print(sum(A))
    

Measured memory_bytes: 3060
#![allow(dead_code)]
use std::collections::VecDeque;
use std::io::*;
struct Io<'a> {
    r: BufReader<StdinLock<'a>>,
    w: BufWriter<StdoutLock<'a>>,
    buf: VecDeque<String>,
    buf_str: String,
}
impl<'a> Io<'a> {
    fn r<T: std::fmt::Debug, S: std::str::FromStr<Err = T>>(&mut self) -> S {
        if self.buf.len() == 0 {
            self.r.read_line(&mut self.buf_str).unwrap();
            for w in self.buf_str.split_whitespace() {
                self.buf.push_back(w.to_owned());
            }
            self.buf_str.clear();
        }
        self.buf.pop_front().unwrap().parse().unwrap()
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.w, "{}", v).unwrap();
    }
    fn iter<'b, T: std::fmt::Debug, S: std::str::FromStr<Err = T>>(
        &'b mut self,
    ) -> IoIter<'a, 'b, T, S> {
        IoIter {
            io: self,
            p: std::marker::PhantomData,
            q: std::marker::PhantomData,
        }
    }
}
struct IoIter<'a: 'b, 'b, T: std::fmt::Debug, S: std::str::FromStr<Err = T>> {
    io: &'b mut Io<'a>,
    p: std::marker::PhantomData<T>,
    q: std::marker::PhantomData<S>,
}
impl<'a, 'b, T: std::fmt::Debug, S: std::str::FromStr<Err = T>> Iterator for IoIter<'a, 'b, T, S> {
    type Item = S;
    fn next(&mut self) -> Option<S> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let r = BufReader::new(stdin.lock());
    let w = BufWriter::new(stdout.lock());
    let io = Io {
        r: r,
        w: w,
        buf: VecDeque::new(),
        buf_str: String::new(),
    };
    problem(io);
}

fn problem(mut io: Io) {
    let k: usize = io.r();

    let mut d: Vec<usize> = vec![0];
    let mut p = 0;

    let mut count = 0;

    loop {
        if p == 0 {
            if d[0] == 9 {
                d.push(0);
                d[0] = 1;
            } else {
                d[0] += 1;
            }
        } else if d[p - 1] + 1 == d[p] || d[p] == 9 {
            p -= 1;
            continue;
        } else {
            d[p] += 1;
        }

        for i in (p + 1)..d.len() {
            d[i] = std::cmp::max(0, d[i - 1] as isize - 1) as usize;
        }
        p = d.len() - 1;
        count += 1;
        if count == k {
            break;
        }
    }

    let mut s = String::new();
    for i in d {
        s.push(std::char::from_digit(i as u32, 10).unwrap());
    }

    io.w(s);
}


Measured memory_bytes: 4352
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = in.nextInt();
        int c = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        Arrays.sort(a);

        int start = a[0];
        int count = 1;
        int t = 0;
        for (int i = 1; i < n; i++) {
            if (start + k < a[i]) {
                count = 0;
                start = a[i];
                t++;
            }
            count++;
            if (count >= c) {
                count = 0;
                start = i + 1 < n ? a[i + 1] : -1;
                t++;
            }
        }
        if (count > 0) {
            t++;
        }

        out.println(t);
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

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

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

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

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}


Measured memory_bytes: 37012
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
   string a;
   int max=0,i,n,s=0;
   cin>>n>>a;
   for(i=0;i<n;i++){
   	   if(a[i]=='I'){
   	   	    s++;
   	   	      if(s>max){
   	   	      	max=s;
			}
		  }
		if(a[i]=='D'){
   	   	      s--;
   	   	      if(s>max){
   	   	      	max=s;
			}
		  }
   }
   cout<<max<<endl;
}


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

int gcd(int a, int b){
return (b > 0)? gcd(b, a % b) : a ;
}

int main(void){
 int W,H,C; cin >> W >> H >> C;
 int min = gcd(W,H);
 
 cout << (W * H / (min*min)) * C<< endl;
 
 
 return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	ll ans = 0;
	vi a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];
	
	for(int i = n - 1; i >= 0; i--){
		ll t = (ans + a[i]) % b[i];
		if(t != 0) t = b[i] - t;
		ans += t;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
# Aizu Problem ITP_1_8_A: Toggling Cases
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


out = ""
for char in input().strip():
    o = ord(char)
    if 65 <= o <= 90:
        out += chr(o + 32)
    elif 97 <= o <= 122:
        out += chr(o - 32)
    else:
        out += char
print(out)

Measured memory_bytes: 7468
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::array<i64, 3> A;
  tools::read(A);
  std::cout << (std::accumulate(A.begin(), A.end(), static_cast<i64>(0)) >= 22 ? "bust" : "win") << std::endl;
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int X, A, B;
  cin >> X >> A >> B;
  cout << (X - A) % B <<endl; 
} 


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

int main(void){
  int n;
  long long int x;
  long long int nums[100];
  int count = 0;
  long long int sum = 0;

  cin >> n >> x;

  for(int i =0;i<n;i++){
    cin >> nums[i];
  }

  while(true){
    int min = -1;
    int mini = -1;
    for(int i =0;i<n;i++){
      if((min == -1 || min > nums[i] )&& nums[i]!=-1){
        min =nums[i];
        mini =i;
      }
    }
    if (mini!=-1){
      sum+=min;
      if(sum>x){
        break;
      }
      count +=1;
      nums[mini]=-1;
      if(sum == x){
	break;
      }
    }else{
      count -= 1;
      break;
    }
  }

  cout <<  count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef vector<ll> lnum;
const ll base = 1000*1000*1000;
#define pb push_back
#define mp make_pair


const ll mod = 1000 * 1000 * 1000 + 7;
const ll INF = 1000 * 1000 * 1000;
const ll LINF = (ll)INF * INF;
ll n;
vector<vector<ll> > g(100);
vector<pair<ll , ll> > edges;
ll maxDepth;
queue<int> q;
ll dp[102];
ll dist[105];
vector<int> byDist[105];
void bfs()
{
	while(!q.empty())
	{
		int u = q.front();
		maxDepth = max(maxDepth , dist[u]);
		byDist[dist[u]].pb(u);
		q.pop();
		for(int i = 0; i < g[u].size(); i++)
		{
			int v = g[u][i];
			if(dist[v] == -1)
			{
				dist[v] = dist[u] + 1;
				q.push(v);
			}
		}
	}

}

int main()
{
	//memset(dpT , -1 , sizeof dpT);
	//freopen("input.txt" , "r" , stdin);
	cin >> n;
	if(n == 2)
	{
		cout << 1 << " " << 2;
		return 0;
	}
	for(ll i = 1; i < n; i++)
	{
		ll u , v;
		cin >> u >> v;
		u--;v--;
		edges.pb({u , v});
		g[u].pb(v);
		g[v].pb(u);
	}
	ll ans1 = INF ,  ans2 = 0;
	for(int i = 0; i < 63; i++)
		ans2 |= (1 << i);
	for(ll i = 0; i < n; i++)
	{
		maxDepth = 1;
		memset(dist , -1 , sizeof dist);
		dist[i] = 0;
		byDist[0].pb(i);
		for(ll j = 0; j < g[i].size(); j++)
		{

			ll u = g[i][j];

			dist[u] = 1;
			//byDist[1].pb(u);
			q.push(u);


		}
		bfs();


		memset(dp , 0 , sizeof dp);
		for(int i = 100; i >= 0; i--)
		{
			int mxSons = 0;
			for(int j = 0; j < byDist[i].size(); j++)
			{
				int u = byDist[i][j];
				//cout << u << " ";
				int sons = g[u].size() - 1 + (i == 0);
				mxSons = max(sons , mxSons);
			}
			//if(byDist[i].size())
				//cout << endl;
			if(!dp[i + 1])
			{
				dp[i] = mxSons;

			}
			else
				dp[i] = mxSons* dp[i + 1];

			byDist[i].clear();
		}
		maxDepth++;
		//cout << maxDepth << " " << dp[0] << endl;
		if(maxDepth < ans1)
		{
			ans1 = maxDepth;
			ans2 = dp[0];
		}
		else if(maxDepth == ans1 && dp[0] < ans2)
		{
			ans2 = dp[0];
		}
	}


	for(ll i = 0; i < edges.size(); i++)
	{
		maxDepth = 1;


		memset(dist , -1 , sizeof dist);
		dist[edges[i].first] = 1;
		dist[edges[i].second] = 1;
		byDist[1].pb(edges[i].first);
		byDist[1].pb(edges[i].second);
		q.push(edges[i].first);
		q.push(edges[i].second);

		bfs();

		memset(dp , 0 , sizeof dp);
		for(int i = 100; i >= 1; i--)
		{
			int mxSons = 0;
			for(int j = 0; j < byDist[i].size(); j++)
			{
				int u = byDist[i][j];
				int sons = g[u].size() - 1;
				mxSons = max(sons , mxSons);
			}
			if(!dp[i + 1])
			{
				dp[i] = mxSons;
			}
			else
				dp[i] = mxSons * dp[i + 1];
			byDist[i].clear();
		}

		//cout << maxDepth << " " << dp[1] << endl;

		if(maxDepth < ans1)
		{
			ans1 = maxDepth;
			ans2 = dp[1] * 2;
		}
		else if(maxDepth == ans1 && dp[1] * 2 < ans2)
		{
			ans2 = dp[1] * 2;
		}

	}
	cout << ans1 << " " << ans2;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, k;
  cin >> n >> k;
  vector<int> v(n, 0);

  rep(i, 0, k) {
    int d;
    cin >> d;
    rep(j, 0, d) {
      int a;
      cin >> a;
      a--;
      v[a]++;
    }
  }

  int ans = 0;
  rep(i, 0, n) {
    if (v[i] == 0)
      ans++;
  }
  cout << ans << endl;
}


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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
int n ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int ans = 0 , cnt = 0 ;
	char prv = '#' ;
	for(int i = 0 ; i < 3 ; ++i)
	{
		char c ;
		cin>>c ;
		if(c == prv)
			cnt++ ;
		else
			cnt = 1 ;
		if(c == 'R')
			ans = max(ans , cnt) ;
		prv = c ;
	}
	if(prv == 'R')
		ans = max(ans , cnt) ;
	return cout<<ans<<"\n" , 0 ;
}		

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    ll n, k;
    cin >> n >> k;
    cout << n - k + 1<< endl;
}

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

int main() {
    string s[3];
    cin >> s[0] >> s[1] >> s[2];

    int now = 0; // 誰のターンであるか
    while (1) {
        if (s[now].size() == 0) {
            cout << char('A' + now) << endl;
            return 0;
        }
        int next = s[now][0] - 'a'; // 次に読み込まれるもの
        s[now].erase(s[now].begin()); // 今のやつを消す
        now = next;
    }

    return 0;
}

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

int main() {
        while(true) {
                int n;
                cin >> n;
                if(n == 0) break;
                vector<int> score(27,0);
                int fn = 26,sn = 26;
                score[26] = 0;
                pair<char,int> ans = make_pair('A',-1);
                for(int i = 0;i < n;i++) {
                        char user;
                        cin >> user;
                        score[user - 'A']++;
                        int idx = user - 'A';
                        if(score[idx] > score[fn]) {
                                sn = fn;
                                fn = idx;
                        } else if(idx != fn && score[idx] > score[sn] ) {
                                sn = idx;
                        }
                        if(score[fn] - score[sn]  > n - (i+1) ) {
                                //cout << (char)(fn + 'A') << " " << i+1 << endl;
                                //break;
                                if(ans.second == -1) {
                                        ans = make_pair((char)(fn+ 'A'),i+1);
                                }
                        }

                }
                if(ans.second == -1){
                cout << "TIE" << endl;
                } else {
                        cout << ans.first << " " << ans.second << endl;
                }

        }


        return 0;
}



Measured memory_bytes: 3024
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var answer = "";
            while (n != 0)
            {
                if (n % 2 != 0)
                {
                    n = (n - 1) / -2;
                    answer = "1" + answer;
                }
                else
                {
                    n /= -2;
                    answer = "0" + answer;
                }
            }
            if (answer == "") answer = "0";
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 11092
from collections import defaultdict as dd
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for i in range(M)]

cards = dd(int)
for a in A:
    cards[a] += 1
for b, c in BC:
    cards[c] += b

ans = 0
for k, v in sorted(cards.items(), key=lambda x: -x[0]):
    if N > v:
        ans += k*v
    else:
        ans += k*N
        break
    N -= v
print(ans)


Measured memory_bytes: 114712
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define mod 1000000007

int main(void)
{
  int n, m;
  int broken[100001];
  scanf("%d %d", &n, &m);

  int bridge;
  int i;
  for (i = 0; i < m; i++)
  {
    scanf("%d", &bridge);
    broken[bridge] = 1;
  }

  int dp[100001] = {0};
  dp[0] = 1;
  if (broken[1] == 0)
    dp[1] = 1;
  for (i = 2; i <= n; i++)
  {
    if (broken[i] == 0)
      dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
  }

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

  return 0;
}


Measured memory_bytes: 896
import java.util.*;
 
public class Main {
    public static void main( String args[] ) {
        Scanner scan = new Scanner( System.in );
		
		while( true ) {
			int studentNum = scan.nextInt();
			
			if ( studentNum == 0 ) {
				break;
			}

			int[] point = new int[studentNum];
			
			// input, calculate sum
			int sum = 0;
			for( int i = 0; i < studentNum; i++ ) {
				point[i] = scan.nextInt();
				sum += point[i];
				
			}
			
			// calculate average
			double average = (double)sum / (double)studentNum;
			
			// calculate variance
			double variance = 0;
			for( int i = 0; i < studentNum; i++ ) {
				double deviation	=	point[i]	- average;
				variance			+=	deviation	* deviation;

			}
			variance = variance / studentNum;
			
			// calculate standardDeviation
			double standardDeviation = Math.sqrt( variance );
			
			System.out.println( standardDeviation );
		}
		
	}
}

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);

  ll N; cin >> N;
  ll ans = 0;

  for(ll i = 1; i <= N; i++){
    ll tmp = N / i;

    ans += tmp * (tmp+1) / 2 * i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in();
	vector<tuple<string,int,int>> SP;
	REP(i,N){
		string S=in<string>();
		int P=in();
		SP.emplace_back(S,P,i+1);
	}
	sort(ALL(SP),[&](tuple<string,int,int>& lhs,tuple<string,int,int>&rhs){
		return get<0>(lhs)!=get<0>(rhs) ? get<0>(lhs)<get<0>(rhs) : get<1>(lhs)>get<1>(rhs);});
	
	for(auto& x:SP){
		cout << get<2>(x) << endl;
	}
	return 0;
}

Measured memory_bytes: 892
// B - Two Arrays

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int a[10000];
int b[10000];

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

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

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

	ll a_rem = 0;
	ll b_need = 0;
	for (int i=0; i<N; i++) {
		if (a[i] < b[i]) {
			a_rem += (b[i] - a[i]) / 2;
		} else {
			b_need += a[i] - b[i];
		}
	}

	string ans;
	if (a_rem >= b_need) ans = "Yes";
	else ans = "No";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <map>

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

   int A;
   std::map<int,int> map;
   for(int i=0; i<N; ++i){
      std::cin >> A;
      map[A-1]++;
   }

   int ans = 0;
   for(auto itr=map.begin(); itr!=map.end(); ++itr){
      if(itr->second%2==1) ans++;
   }
   std::cout << ans << std::endl;

   return 0;
}


Measured memory_bytes: 4992
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve() 
	{
		int n = ni();
		int[] a = na(n);
		Arrays.sort(a);
		double ans = a[0];
		for(int i = 1; i < n; i++) {
			ans = (ans + a[i]) / 2.0;
		}
		out.println(ans);
	}
			
	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private float nf() {
		return Float.parseFloat(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 21204
import java.util.Scanner;

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

        boolean canMultiple = false;
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                if (i * j == n) {
                    canMultiple = true;
                }
            }
        }

        if (canMultiple) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	int a, b, c;
	cin >> a >> b >> c;
	if(b - a == c - b)cout << "YES";
	else cout << "NO";
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double PI=3.14159265358979323846;
ll dp;

int main(){
   ll x;
   cin>>x;
   REP(i,-500,501){
      REP(j,-500,501){
      
         if(((ll)i*i*i*i*i)-((ll)j*j*j*j*j)==x){
            cout<<i<<" "<<j<<endl;
            return 0;
         }
      }
   }
   // ll a=300;
   // cin>>a;
   // cout<<a*a*a*a*a;
}


Measured memory_bytes: 3616
//
// Created by Geoffrey West on 12/22/18.
//

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const long long int N = 10000000;
int lp[N+1];
vector<int> pr;


int main() {
    unsigned long long int n, p;
    cin >> n >> p;
    int d[1000000] = {0};
    if (n == 1){
        cout << p << endl;
        return 0;
    }
    long long int op = p;
    for (int i = 2; i <= N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back(i);
        }
        for (int j = 0; j < (int) pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
            lp[i * pr[j]] = pr[j];
    }
    int i = 0;
    while (p != 1 && i < pr.size()) {
        if (p % pr[i] == 0) {
            d[i]++;
            p /= pr[i];
        } else {
            i++;
        }
    }
    int res = 1;
    for(int j = 0; j < pr.size(); j++)
    {
        res *= pow(pr[j], d[j]/n);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 49392
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)1e5+100;


class Node {
   public:
   // long vertex;
   vector<long> to;
   int grp[3] = {0,0,0};
   // vector<long> length;
   // int grp;
   // bool seen = false;
   // bool finish = false;
   Node(){;};
};
vector<Node*> vGr;

queue<pair<int,int>> vq;
void bfs(int vertex, int group) {
   auto thisv = vGr[vertex];
   // thisv->seen = true;
   for(auto el : thisv->to) {
      if (vGr[el]->grp[(group+1)%3]<=0) {
         vGr[el]->grp[(group+1)%3] = vGr[vertex]->grp[(group)]+1;
         vq.push(make_pair(el, (group+1)%3));
      }
   }
   // thisv->finish = true;
   return;
}



int main(void) {
   ll N,M;
   cin>>N>>M;
   rep(i,0,N) vGr.push_back(new Node());
   rep(i,0,M) {
      ll u,v;
      cin>>u>>v;
      vGr[u-1]->to.push_back(v-1);
   }
   ll S,T;
   cin>>S>>T;
   vq.push(make_pair(S-1,0));
   while(1) {
      if (!vq.size()) break;
      bfs(vq.front().first,vq.front().second);
      // int v = vq.front();
      vq.pop();
      // bfs(v,0);
   }
   // cout<<vGr[T-1]->grp[0]<<endl;
   // cout<<vGr[T-1]->grp[1]<<endl;
   // cout<<vGr[T-1]->grp[2]<<endl;
   if (vGr[T-1]->grp[0]>0) cout<<vGr[T-1]->grp[0]/3<<endl;
   else cout<<-1<<endl;



   return 0;
}

Measured memory_bytes: 8820
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(){ 
    int N, M;
    cin >> N >> M;
    vector<int> A(N), B(N);
    vector<pair<int, int>> AB(N);
    for(int i = 0; i < N; ++i){
        int a, b;
        cin >> a >> b;
        AB[i] = make_pair(a, b);
    }
    sort(AB.begin(), AB.end());
    // cout << endl;
    // for(auto i : AB){
    //     cout << i.first << " " << i.second << endl;
    // }


    long long ans = 0;
    priority_queue<int> que;
    int nowIndex = 0;
    for(int i = 1; i <= M ; ++i){
        for(; nowIndex < N; ++nowIndex){
            if(AB[nowIndex].first > i) break;
            que.push(AB[nowIndex].second);
        }
        if(!que.empty()){
            ans += que.top();
            que.pop();
        }
    }
    
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

//vector< vector<int> > v (size1, vector<int>(size2) );


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll ai;
    FOR(i,0,n) {
        cin>>ai;
        if(i==0){
            a[i]=ai;
        }else{
            a[i]=a[i-1]+ai;
        }
    }

    ll ans= 2*1000000000+100;

    FOR(i,0,n-1){
        ans = min(ans,abs(a[n-1]-a[i]*2));
    }


	cout<<ans<<endl;
	
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a-1; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define rALL(x) x.rbegin(), x.rend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll a, b;    cin >> a >> b;
    cout << a*b << endl;
    gcd(a, b);

}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
//define
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define elif else if
//vectordefine
#define vint vector<int>
#define vc vector<char>
#define vtr vector<string>
#define pb(n) push_back(n)
//queuedefine
#define qint queue<int>
#define qc queue<char>
#define qstr queue<str>
//mapdefine
#define mint map<int>
#define mc map<char>
//pairdefine
#define pint pair<int,int>
#define pis pair<int,str>
#define pic pair<int,char>
#define pci pair<char,int>
#define mod 100000007

string syugei(int N){
  string ST="b";
  for(int i=0;i<N;i++){
    if(i%3==0||i==0)ST="a"+ST+"c";
    else if(i%3==1||i==1)ST="c"+ST+"a";
    else if(i%3==2||i==2)ST="b"+ST+"b";
  }
  return ST;
}
// int hantei(string S){
//   for(int i=0;i<S.size(),i++){
//     for(int j=0;j<)
//   }
// }
//main
signed main(){
  int N,M,O,P,X,count=0,count2=0;
  double D;
  int c='A'-'a';
  //char C;
  str S,T;
  cin>>N;
  int A[N]={},B[N]={},C[N-1]={};
  rep(0,N)cin>>A[i];
  rep(0,N)cin>>B[i];
  rep(0,N-1)cin>>C[i];
  rep(0,N){
    count+=B[A[i]-1];
    // cout<<B[A[i]-1]<<endl;
    if(A[i+1]-A[i]==1)count+=C[A[i]-1];
  }
  cout<<count<<endl;
}


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

int main()
{
	int n,l;
	cin  >> n>>l;
	vector<string> s(n);
	for(int i =0;i<n;i++)
	{cin >> s[i];}
	sort(s.begin(),s.end());
	for(auto i:s)cout<<i;cout<<endl;
}

Measured memory_bytes: 256