akhauriyash/Code-Regression huggingface dataset:
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut cards = sc
        .vec::<u64>(n)
        .into_iter()
        .map(|x| (x, 1))
        .collect::<Vec<_>>();
    for _ in 0..m {
        let b: usize = sc.read();
        let c: u64 = sc.read();
        cards.push((c, b));
    }
    cards.sort();

    let mut ans = 0;
    let mut count = n;
    for (num, c) in cards.into_iter().rev() {
        let add = cmp::min(c, count);
        ans += (add as u64) * num;
        count -= add;
    }
    println!("{}", ans);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 13720
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>

using namespace std;

int main(void) {
    int N,K;
    cin>>N>>K;
    int A=0;
    vector<int>H(N);
    for(int i=0;i<N;i++){
        cin>>H[i];

        if(H[i]>=K){
            A++;
        }
    }

    cout<<A<<endl;

}


Measured memory_bytes: 640
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        x: usize,
        y: usize,
        a: usize,
        b: usize,
        c: usize,
        mut p: [usize; a],
        mut q: [usize; b],
        mut r: [usize; c],
    }
    p.sort_by(|a, b| b.cmp(a));
    q.sort_by(|a, b| b.cmp(a));
    r.sort_by(|a, b| b.cmp(a));
    let mut apples: Vec<usize> = std::iter::empty()
        .chain(p[0..x].iter())
        .chain(q[0..y].iter())
        .chain(r.iter())
        .copied()
        .collect();
    apples.sort_by(|a, b| b.cmp(a));
    let ans: usize = apples[0..(x + y)].iter().sum();
    println!("{}", ans);
}


Measured memory_bytes: 10604
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

///////////////////////////////////////////////////////////////////////////

int main(){
	string s;
    cin >> s;
    set<char> ns,we;

    rep(i,0,sz(s)){
        if(s[i] == 'N' || s[i] == 'S')ns.it(s[i]);
        else we.it(s[i]);
    }

    if(sz(ns)%2 == 0 && sz(we)%2 == 0)Yes;
    else No; 
	return  0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main()  {
	var n int
	fmt.Scan(&n)
	a := make([]int, n+1)
	for i:= range a {
		fmt.Scan(&a[i])
	}
	b := make([]int, n)
	for i:= range b {
		fmt.Scan(&b[i])
	}

	var tmp, ans int
	for i:=n; i>0; i-- {
		//fmt.Println(int(math.Min(float64(b[i-1]), float64(a[i]))))
		tmp = int(math.Min(float64(b[i-1]), float64(a[i])))
		ans += tmp
		b[i-1] -= tmp
		a[i] -= tmp
		//fmt.Println(a,b)
		//fmt.Println(tmp)

		//fmt.Println(int(math.Min(float64(b[i-1]), float64(a[i-1]))))
		tmp = int(math.Min(float64(b[i-1]), float64(a[i-1])))
		ans += tmp
		b[i-1] -= tmp
		a[i-1] -= tmp
		//fmt.Println(a,b)
		//fmt.Println(tmp)
	}
	fmt.Println(ans)
}

Measured memory_bytes: 7296
h,w=map(int,input().split())
g=[input() for _ in range(h)]
def search(y,x):
  que=[(y,x)]
  vis=[[-1]*w for _ in range(h)]
  vis[y][x]=0
  while que:
    cy,cx=que.pop(0)
    for dy,dx in ((1,0),(-1,0),(0,1),(0,-1)):
      ny,nx=cy+dy,cx+dx
      if 0<=ny<h and 0<=nx<w and g[ny][nx]=="." and vis[ny][nx]==-1:
        vis[ny][nx]=vis[cy][cx]+1
        que.append((ny,nx))
  return max(max(l) for l in vis)
ans=0
for i in range(h):
  for j in range(w):
    if g[i][j]==".":
      ans=max(search(i,j),ans)
print(ans)

Measured memory_bytes: 45020
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      
      // 判定
      int result = 0;
      if(x == 0){
        result = 1;
      }
      
      // 出力
      System.out.println(result);
    }

}

Measured memory_bytes: 35668
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int n, m;
    cin >> n >> m;
    int INF = 1001001001;
    vector<int> dp(n + 10, INF);
    vector<int> c(m);
    for (int i = 0; i < m; i++)
    {
        cin >> c[i];
    }
    dp[0] = 0;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (i - c[j] >= 0)
            {
                dp[i] = min(dp[i - c[j]] + 1, dp[i]);
            }
        }
    }
    cout << dp[n] << endl;

    return 0;
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3+7;
int mat[N][N];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int h,w,sI,sJ,eI,eJ; cin >> h >> w >> sI >> sJ >> eI >> eJ;
    sI--; sJ--; eI--; eJ--;
    for (int i = 0; i < h; i++) {
        string s; cin >> s;
        for (int j = 0; j < w; j++) {
            if (s[j]=='#') mat[i][j]=1;
            else mat[i][j]=0;
        }
    }
    deque<pair<int,int>> q;
    vector<vector<int>> d(h, vector<int>(w, 1e9+7));
    q.push_front({sI,sJ});
    d[sI][sJ]=0;
    int dir[] = { 1,0,-1,0,1 };
    while (!q.empty()) {
        int cI,cJ;
        tie(cI,cJ) = q.front();
        q.pop_front();
        for (int i = 0; i < 4; i++) {
            int nI=cI+dir[i];
            int nJ = cJ+dir[i+1];
            if (nI >= h || nI < 0 || nJ >= w || nJ < 0) continue;
            if (mat[nI][nJ]) continue;
            if (d[nI][nJ] > d[cI][cJ]) {
                d[nI][nJ] = d[cI][cJ];
                q.push_front({nI,nJ});
            }
        }
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                int nI=cI+i;
                int nJ = cJ+j;
                if (nI >= h || nI < 0 || nJ >= w || nJ < 0) continue;
                if (mat[nI][nJ]) continue;
                if (d[nI][nJ] > d[cI][cJ]+1) {
                    d[nI][nJ] = d[cI][cJ]+1;
                    q.push_back({nI,nJ});
                }
            }
        }
    }
    if (d[eI][eJ]==1e9+7) cout << -1 << endl;
    else cout << d[eI][eJ] << endl;
    
    return 0;
}

Measured memory_bytes: 11564
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MAXN 4000007
#define ll long long
#define mo 19930726
using namespace std;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
int n;
ll clac(ll x)
{
	ll cnt=0;
	while(x) cnt+=x%10,x/=10;
	return cnt;
}
int main()
{
	ll x=0,x1,x2,m=1;
	cin>>n;
	for(int i=1;i<=n;i++){
		x1=x+m;x2=x+m*10;
		if(x1*clac(x2)<=x2*clac(x1))
			x=x1;
		else x=x2,m*=10;
		printf("%lld\n",x);
	}
}

Measured memory_bytes: 256
fun main(args: Array<String>) = ABC164C.main()

object ABC164C {
    fun log(message: Any?) {
        println(message)// TODO: ←消す
    }

    fun main() {
        val N = readInt()
        val S = (1..N).map { readString() }
        val ans = S.toSet().size
        println(ans)
    }


    /*####################################################################################*/

    fun readString() = readLine()!!
    fun readStrings() = readLine()!!.split(" ")
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
    fun readLong() = readLine()!!.toLong()
    fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
    fun readMatrixRows(height: Int) = (1..height).map { readLine()!!.toList() }

    fun Boolean.yesOrNo() = if (this) "Yes" else "No"
    fun Double.toNaturalExpr() = println("%f".format(this))
}

Measured memory_bytes: 75124
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        Holder[] holders = new Holder[5];
        for (int i = 0; i < 5; i++) {
            holders[i] = new Holder(scan.nextInt());
        }
        int answer = 0;
        Arrays.sort(holders, new HolderComparator());
        for (int i = 0; i < 4; i++) {
            answer += Math.ceil((double) holders[i].need_time / 10) * 10;
        }
        answer += holders[4].need_time;
        System.out.println(answer);
    }
    class Holder {
        int need_time = 0;
        int loss_time = 0;
        Holder(int x) {
            this.need_time = x;
            if (x % 10 != 0) {
                this.loss_time = 10 - x % 10;
            } else {
                this.loss_time = 0;
            }
        }
    }
    class HolderComparator implements Comparator<Holder> {
        @Override
        public int compare(Holder o1, Holder o2) {
            if (o1.loss_time != o2.loss_time) {
                return Integer.compare(o1.loss_time, o2.loss_time);
            } else {
                return Integer.compare(o1.need_time, o2.need_time);
            }
        }
    }
}


Measured memory_bytes: 25172
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int N;
    cin >> N;
    vector<int> d(N);

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

    long long ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            ans += d[i] * d[j];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
int main(){
    ll n,a,b;cin>>n>>a>>b;
    ll ans=n/(a+b)*a;
    n%=(a+b);
    if(n<=a)ans+=n;
    else ans+=a;
    out(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,m;
	cin>>n>>m;
	priority_queue<ll> pq;
	for(ll i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		pq.push(a);
	}
	while(m--)
	{
		ll t=pq.top();
		pq.pop();
		pq.push(t/2);
	}
	long long ans=0;
	while(!pq.empty())
	{
		ans+=pq.top();
		pq.pop();
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1400
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse = True)
Q.sort(reverse = True)
R.sort(reverse = True)

count = X + Y
p = 0
q = 0
r = 0
ans = 0
for _ in range(count):
    tmp = 0
    next_ = None
    if X > 0:
        tmp = P[p]
        next_ = 'P'
    if Y > 0 and Q[q] > tmp:
        tmp = Q[q]
        next_ = 'Q'
    if r < C and R[r] >= tmp:
        tmp = R[r]
        next_ = 'R'
    
    ans += tmp
    if next_ == 'P':
        X -= 1
        p += 1
    elif next_ =='Q':
        Y -= 1
        q += 1
    else:
        r += 1
    
print (ans)
# print (P)
# print (Q)
# print (R)
    

Measured memory_bytes: 105444
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int ans = c - (a - b);
        if(ans < 0) ans = 0;
        System.out.println(ans);
    }
}

Measured memory_bytes: 35644
import java.util.*;

public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int h=Integer.parseInt(scan.next());
		int w=Integer.parseInt(scan.next());
		String[] s=new String [h];
		for (int y=0;y<h;++y){
			s[y]=scan.next();
		}
		boolean ans =true;
		boolean check;
		for (int y=0;y<h;++y){
			for (int x=0;x<w;++x){
				if(s[y].charAt(x)=='#'){
					//check
					check=false;
					for(int i=-1;i<=1;++i){
						if (0<=(y+i) && (y+i)<h && i!=0){
							if (s[y+i].charAt(x)=='#')check=true;

						}
						if (0<=(x+i) && (x+i)<w && i!=0){
							if (s[y].charAt(x+i)=='#')check=true;

						}
					}
					if (!check){
						ans=false;
						break;
					}
				}
			}
		}
		System.out.print(ans?"Yes":"No");





	}
}
//end

Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		int h[] = new int[N];
		int cnt = 0;


		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();

			if(h[i]>=K)cnt++;
		}
		System.out.println(cnt);

	}

}


Measured memory_bytes: 50884
# -*- coding: utf-8 -*-

n = int(raw_input())
a = map(int, raw_input().split())
b = [i for i in range(n)]

j = 0
if n % 2 == 1:
    for i in range(n-1,-1,-2):
        b[j] = a[i]
        j += 1
    for i in range(1,n,2):
        b[j] = a[i]
        j += 1
else:
    for i in range(n-1,0,-2):
        b[j] = a[i]
        j += 1
    for i in range(0,n,2):
        b[j] = a[i]
        j += 1

print ' '.join(map(str,b))


Measured memory_bytes: 31444
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;
int main(){
    cin >> n >> k;

    ll res = 0;
    for(ll i=k; i<=n+1; i++){
        ll max = i*(2*n-i+1)/2;
        ll min = i*(i-1)/2;
        res += (max - min+1)%mod;
    }
    out(res%mod);

 
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll k;
    cin>>k;
    string s;
    cin>>s;
    if(s.length()<=k)cout<<s<<endl;
    else {
        for(int i=0;i<k;i++)cout<<s[i];
        cout<<"..."<<endl;
    }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<typename T>
struct Max_Flow{
    struct edge{
        int to; T cap; int rev;
        edge(int to, T cap, int rev) : to(to), cap(cap), rev(rev) {}
    };

    vector<vector<edge>> es;
    vector<bool> used;
    const T INF_T;

    Max_Flow(int n) : INF_T(numeric_limits<T>::max()){
        es.resize(n), used.resize(n);
    }

    void add_edge(int from, int to, T cap, bool directed = true){
        es[from].eb(to, cap, sz(es[to]));
        es[to].eb(from, directed? 0 : cap, sz(es[from])-1);
    }

    T dfs(int now, int t, T flow){
        if(now == t) return flow;
        used[now] = true;
        for(auto &e: es[now]){
            if(!used[e.to] && e.cap > 0){
                T f = dfs(e.to, t, min(flow, e.cap));
                if(f > 0){
                    e.cap -= f;
                    es[e.to][e.rev].cap += f;
                    return f;
                }
            }
        }
        return 0;
    }

    T max_flow(int s, int t){
        T flow = 0;
        for(;;){
            fill(all(used), false);
            T f = dfs(s, t, INF_T);
            if(f == 0) return flow;
            flow += f;
        }
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    Max_Flow<int> G(N+M+2);
    int s = N+M, t = N+M+1;
    rep(i, N) G.add_edge(s, i, 1);
    rep(i, M) G.add_edge(N+i, t, 1);
    rep(i, N){
        int K; cin >> K;
        while(K--){
            int j; cin >> j; j--;
            G.add_edge(i, N+j, 1);
        }
    }
    cout << (G.max_flow(s, t) == M? "Bob" : "Alice") << endl;
}


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

const int mod = 1e5;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, M, S;
	while (cin >> N >> M >> S, N | M | S) {
		N *= N;
		vector<vector<int>> dp(S + 1, vector<int>(N + 1));
		dp[0][0] = 1;
		for (int i = 1; i <= M; i++) {
			auto tmp = dp;
			for (int j = 0; j + i <= S; j++) {
				for (int k = 0; k < N; k++) {
					(dp[j + i][k + 1] += tmp[j][k]) %= mod;
				}
			}
		}
		printf("%d\n", dp[S][N]);
	}
	return 0;
}



Measured memory_bytes: 4520
extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::fmt::{Display, Error, Formatter, Binary, Pointer};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet};

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}

fn main() {
    loop {
        let_all!(n: usize, i: i64, j: i64);
        if n == 0 {
            return
        }
        println!("{}", f(n, i, j));
    }
}
fn f(n: usize, i: i64, j: i64) -> String{
    let mut d = 1_i64 << n as i64;
    let mut u = d - i;
    let mut res = Vec::with_capacity(n);
    for _ in 0 .. n {
        d >>= 1;
        if d <= u {
            res.push(true);
            u = d * 2 - u - 1;
        }else {
            res.push(false);
        }
    }
    let mut result = Vec::with_capacity(n);
    let mut j = j - 1;
    let mut length = 1_i64 << n as i64;
    res.reverse();
    for r in res {
        length >>= 1;
        if r {
            if length <= j {
                j = length * 2 - j - 1;
                result.push('R');
            }else {
                j = length - j - 1;
                result.push('L');
            }
        }else {
            if length <= j {
                j -= length;
                result.push('L');
            }else {
                result.push('R');
            }
        }
    }
    result.iter().collect()
}


Measured memory_bytes: 5028
#include<stdio.h>
int main()
{
	int i,j,k;
	int a[10];
	for(i=0;i<10;i++)
		scanf("%d",&a[i]);
	for(i=0;i<10;i++)
	{
		for(j=0;j<10-i-1;j++)
			if(a[j]<a[j+1])
			{
				k=a[j];
				a[j]=a[j+1];
				a[j+1]=k;
			}
	}
	for(i=0;i<3;i++)
		printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 600
<?php
while(true){
$n = trim(fgets(STDIN));
if($n == '-'){
    break;
}
$length = strlen($n);
$m = trim(fgets(STDIN)); 
for($i = 0; $i < $m; $i++){
    $cnt = trim(fgets(STDIN)); 
    $n2 = substr($n,0,$cnt);
    $k = $length - $cnt;
    $n3 = substr($n,-$k);
    $n = $n3.$n2;
}
echo $n.PHP_EOL;
}
?>


Measured memory_bytes: 9224
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  int a[2*n];
  for(int i=0;i<2*n;i++)
       cin>>a[i];
  int ans=0;
  sort(a,a+2*n);
  for(int i=0;i<2*n;i+=2)
  {
    ans+=min(a[i],a[i+1]);
    
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int MAX_V = 1000;
vector<int> G[MAX_V];
int match[MAX_V], p[500], q[500];
bool used[MAX_V];

int gcd_rec(int a, int b) {
  return !b ? a : gcd_rec(b, a % b);
}

int gcd(int a, int b) {
  return a < b ? gcd_rec(b, a) : gcd_rec(a, b);
}

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int main() {
  for (;;) {
    int m, n;
    cin >> m >> n;
    if (!m && !n) return 0;
    for (int i = 0; i < m; i++)
      cin >> p[i];
    for (int i = 0; i < n; i++)
      cin >> q[i];
    for (int i = 0; i < m; i++)
      for (int j = 0; j < n; j++)
        if (gcd(p[i], q[j]) > 1)
          add_edge(i, m+j);
    int r = 0, V = m + n;
    fill(match, match+V, -1);
    for (int v = 0; v < V; v++)
      if (match[v] < 0) {
        fill(used, used+V, false);
        if (dfs(v))
          r++;
      }
    cout << r << endl;
    for (int v = 0; v < V; v++)
      G[v].clear();
  }
}

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

typedef long long ll;
using namespace std;

ll n,pd,a[200005];


int pot (ll q, ll w){
	ll qw = q;
	q = 1;
	for (int i = 0; i<w; i++)
		q*= qw;
	return q;
}

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

cin >> n;

for (int i = 0; i<n; i++)
	cin >> a[i];
	
sort (a,a+n);

for (int i = 0; i<n; i++)
	if (a[i] == a[i+1]){
		pd++;
		break;
		}



if (pd==0)
	cout << "YES";
else
	cout << "NO";


return 0;
}



Measured memory_bytes: 1792
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	int n ; cin >> n ;
	cout << (n-2)*180 << endl ;
}


Measured memory_bytes: 256
#include<iostream>


#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 IN cin >> 
#define OUT cout <<
#define E  << endl;

using namespace std;


int goal_time = 0;

int a, b, c;

int x = 0;

void input() {
	IN a >> b >> c;
}

int main() {
	input();
	int memo = 0;

	x = 60.0 / (a + b);
	if (x == 0)x = 1;

	bool flag = false;
	goal_time += c;
	while (true) {
		int n = memo;
		while (true){
			if ((a + b) * n <= goal_time && (a + b) * n + a >= goal_time) {
				OUT goal_time E
				flag = true;
				break;
			}
			if ((a + b) * n > goal_time) {
				memo = n;
				break;
			}
			if (n > 5000) {
				OUT -1 E
				flag = true;
				break;
			}
			n += 1;
			if (goal_time > 60) {
				if ((60 % (a + b) == 0) && c > a) {
					OUT - 1 E
						return 0;
				}
			}

		}
		if (flag)break;
		goal_time += 60;
	}
	

	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
 
#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())
#define debug(x) cerr << #x " = " << (x) << '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
 
lli MOD  = 1000000007;
lli inf = 1e15;
 
void scan(scantype &x);

lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli div(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

bool isprime(long long int n)
{
    if(n ==1 )
        return false;
    if(n == 2)
        return true;
    for(long long int i =2;i<=n/i;i++)
    {
        if(n%i == 0)
            return false;
    }
    return true;
}
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    int t;
    t = 1;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n];
        int ans = 0;
        for (int i = 0; i < n; ++i)
        {
            cin>>a[i];
            ans += a[i];
        }
        sort(a,a+n);
        if(ans%10==0)
            for(int i = 0;i<n;i++)
            {
                if(a[i]%10)
                {
                    ans -= a[i];
                    break;
                }
            }
        if(ans%10==0)
            cout<<0;
        else 
            cout<<ans;
    }    


    
    return 0;    
}
 

void scan(scantype &x)
{
    register int c = getchar(); //for negative/positive
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar());
    if(c=='-') {neg=1;c=getchar();}
    for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    int Q;
    cin >> Q;

    map<ll, ll> cnt;
    ll sum = 0;
    for (auto a: A) {
        cnt[a]++;
        sum += a;
    }

    ll B, C;
    rep(_, Q) {
        cin >> B >> C;
        if (cnt[B]) {
            sum -= cnt[B] * B;
            sum += cnt[B] * C;

            cnt[C] += cnt[B];
            cnt[B] = 0;
        }
        cout << sum << endl;
    }
}


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

int main() {
  int n,alice=0,bob=0;
  cin >> n;
  vector<int> card(n);
  for(int i=0; i<n; i++) cin >> card.at(i);
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  for(int i=0; i<n; i++) {
    if(i%2 == 0) alice += card.at(i);
    else bob += card.at(i);
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  ll n, m;
  cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  ans = (n * 2 + m) / 4;
  chmin(ans, m / 2);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b == c + d){
    cout << "Balanced" << endl;
  }
  else if (a + b < c + d) {
    cout << "Right" << endl;
  }
  else {
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int V, E, s, t, f, vis[103]; vector<int> G[103];
void rec(int pos, int c, int s) {
	if(pos == s && c) { f |= 1; return; }
	if(c) vis[pos] = true;
	for(auto &e : G[pos]) {
		if(!vis[e]) rec(e, c + 1, s);
	}
}
int main() {
	cin >> V >> E;
	for(int i = 0; i < E; i++) {
		cin >> s >> t;
		G[s].push_back(t);
	}
	for(int i = 0; i < V; i++) {
		fill(vis, vis + V, false);
		if(!vis[i]) rec(i, 0, i);
	}
	cout << (f ? 1 : 0) << endl;
}

Measured memory_bytes: 3156
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
  int sum{0};
  int n;
  cin >> n;
  int B1{INT_MAX};

  int B2;
  while (n > 0) {    
    cin >> B2;
    B1 = min(B1, B2);
    sum+=B1;
    // cout << sum << " ";
    B1=B2;
  	n--;  
  }
  
  cout << sum << endl;
  return 0;  
}

Measured memory_bytes: 256
n = int(input())
XY = [tuple(map(int, input().split())) for _ in range(n)]

def f(x, y):
    r = 0
    for xi, yi in XY:
        d = ((x - xi)**2 + (y - yi)**2)**0.5
        if d > r:
            r = d
    return r

def g(x):
    l, r = 0, 1000
    for _ in range(75):
        c1, c2 = (2 * l + r) / 3, (l + 2 * r) / 3
        if f(x, c1) > f(x, c2):
            l = c1
        else:
            r = c2
    return f(x, l)

l, r = 0, 1000
for _ in range(75):
    c1, c2 = (2 * l + r) / 3, (l + 2 * r) / 3
    if g(c1) > g(c2):
        l = c1
    else:
        r = c2

print(g(l))


Measured memory_bytes: 3064
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU
package main

import (
	"bufio"; "fmt"; "os"; "strconv"; "strings"
)

func atoi(s string) int { v, _ := strconv.Atoi(s); return v }
func atou(s string) uint64 { v, _ := strconv.ParseUint(s, 10, 64); return v }
func atof(s string) float64 { v, _ := strconv.ParseFloat(s, 64); return v }
func max(a, b int) int { if a > b { return a }; return b }
func min(a, b int) int { if a < b { return a }; return b }

var (_ = fmt.Println; _red = bufio.NewScanner(os.Stdin); _tok []string)
func init() { _red.Buffer(make([]byte, 1e7), 1e7) }
func gettok() (t string, e bool) {
	if len(_tok) == 0 { if !_red.Scan() { return }; _tok = strings.Split(_red.Text(), " ") }
	t = _tok[0]; _tok = _tok[1:]; e = len(_tok) == 0; return
}
func read(vs ...interface{}) {
	for _, v := range vs {
		switch v := v.(type) {
		case *int: t, _ := gettok(); *v = atoi(t)
		case *uint64: t, _ := gettok(); *v = atou(t)
		case *float64: t, _ := gettok(); *v = atof(t)
		case *string: *v, _ = gettok()
		case *[]int:
			if len(*v) == 0 { for { t, e := gettok(); *v = append(*v, atoi(t)); if e { break } }
			} else { for j := range *v { t, _ := gettok(); (*v)[j] = atoi(t) } }
		case *[]uint64:
			if len(*v) == 0 { for { t, e := gettok(); *v = append(*v, atou(t)); if e { break } }
			} else { for j := range *v { t, _ := gettok(); (*v)[j] = atou(t) } }
		case *[]float64:
			if len(*v) == 0 { for { t, e := gettok(); *v = append(*v, atof(t)); if e { break } }
			} else { for j := range *v { t, _ := gettok(); (*v)[j] = atof(t) } }
		case *[]string:
			if len(*v) == 0 { *v = append(*v, _tok...); _tok = _tok[:0]
			} else { for j := range *v { (*v)[j], _ = gettok() } }
		}
	}
}

func main() {
    var n int
    read(&n)
    tr := make([][]int, n + 1)
    for i := 1; i < n; i++ {
        var a, b int
        read(&a, &b)
        if tr[a] == nil { tr[a] = []int{} }
        if tr[b] == nil { tr[b] = []int{} }
        tr[a] = append(tr[a], b)
        tr[b] = append(tr[b], a)
    }
    
    // 解説読後
    // https://atcoder.jp/img/arc078/editorial.pdf
    
    fenneclen := make([]int, n + 1)
    fenneclen[1] = 1
    tmp1 := []int{1}
    for len(tmp1) > 0 {
        sz := len(tmp1) - 1
        x := tmp1[sz]
        tmp1 = tmp1[:sz]
        for _, v := range tr[x] {
            if fenneclen[v] > 0  { continue }
            fenneclen[v] = fenneclen[x] + 1
            tmp1 = append(tmp1, v)
        }
    }
    snukelen := make([]int, n + 1)
    snukelen[n] = 1
    tmp1 = []int{n}
    for len(tmp1) > 0 {
        sz := len(tmp1) - 1
        x := tmp1[sz]
        tmp1 = tmp1[:sz]
        for _, v := range tr[x] {
            if snukelen[v] > 0  { continue }
            snukelen[v] = snukelen[x] + 1
            tmp1 = append(tmp1, v)
        }
    }
    fennec := 0
    snuke := 0
    for i:=1;i<=n;i++ {
        if fenneclen[i] <= snukelen[i] {
            fennec++
        } else {
            snuke++
        }
    }
    if fennec > snuke {
        fmt.Println("Fennec")
    } else {
        fmt.Println("Snuke")
    }
}


Measured memory_bytes: 13440
#include <iostream>
#include <vector>

using namespace std;

void printData(vector<int> Data, int N) {
   for(int i = 0; i < N; i++) {
      cout << Data[i];
      if(i != N - 1) {
         cout << " ";
      }
   }

   cout << endl;
}

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

   vector<int> A;
   for(int i = 0; i < N; i++) {
      int r;
      cin >> r;
      A.push_back(r);
   }
   
   printData(A, N);
   for(int i = 1; i <= N - 1; i++) {
      int v = A[i];
      int j = i - 1;
      while(j>= 0 && A[j] > v) {
         A[j + 1] = A[j];
         j --;
      }
      A[j + 1] = v;
      printData(A, N);
   }
}



   
      



Measured memory_bytes: 3164
#include<iostream>
#include<string>
#include<cstdlib>
#include<math.h>
using namespace std;
int main(void){
    long long a,b;
    cin >> a >> b ;
    
    if(a*b<=0){
        printf("Zero");
    }else if(a>0||(a+b)%2==-1){
        printf("Positive");
    }else if((a+b)%2==0){
        printf("Negative");
    }
    return 0;
}

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

int main() {
	int N, D[100];
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> D[i];
	}
	int c = 0, m = 0, mi,bm;
	for (int j = 0; j < N;j++) {
		for (int i = 0; i < N; i++) {
			if (bm == D[i]) {
				D[i] = 0;
			}
			if (m < D[i]) {
				m = D[i];
				mi = i;
			}
		}
		if (m!=0) {
			c++;
		}
		D[mi] = 0;
		bm = m;
		m = 0;
	}
	cout << c;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll N, K;
  cin >> N >> K;
  N = N % K;
  ll m = min(abs(N - K), N);
  COUT(m);
  return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  int a;
  cin >> a;
  a--;
  int c=0;
  rep(i,n-1){
    int q;
    cin >> q;
    if(q==a)continue;
    if(q>a)a=q-1;
    else c=1;
  }
  if(c==1)cout << "No" << endl;
  else cout << "Yes" << endl;
}  


Measured memory_bytes: 256
import math,sys
N = int(input())
A = list(map(int, input().split()))
ans = 1

if 0 in A:
    print(0)
    sys.exit()

for i in range(N):
    ans = ans*A[i]
    if ans > pow(10,18):#pythonはオーバーフローしないからこれでも行ける
        print(-1)
        sys.exit()

print(ans)


Measured memory_bytes: 22340
#include<iostream>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=1000000000LL;
typedef long long ll;
typedef pair<int,string> P;
ll N,M,K;
ll C,T;
ll A,B;
string str;
ll n[100002]={};
map<string,int> m;
int main(){
	cin>>N>>K;
	for(int i=0;i<N;++i){
		cin>>A>>B;
		n[A]+=B;
	}
	ll ans=0;
	for(int i=1;i<=100000;++i){
		ans+=n[i];
		if(ans>=K){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

#define INF 100000000;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
int main(){
    long double eps = 1.0E-14;
    long double A,B,C;
    cin >> A >> B >> C;
    long double AA,BB,CC;
    AA = sqrtl(A);
    BB = sqrtl(B);
    CC = sqrtl(C);

    if(AA + BB + eps < CC) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define mod 1000000007
using namespace std;


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

int a,b;
cin>>a>>b;

if(a%3 ==0 || b%3==0 || (a+b)%3 ==0)
    cout<<"Possible";
else
    cout<<"Impossible";


return 0;
}


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

long long n, a[2009], sum; const int MAX_N = 4000009;

int main() {
	cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; }
	bitset<MAX_N> BIT;
	BIT.set(0);
	for (int i = 1; i <= n; i++) {
		bitset<MAX_N> BIT2 = BIT;
		BIT2 <<= a[i];
		BIT = BIT | BIT2;
	}
	for (int i = (sum + 1) / 2; i <= sum; i++) {
		if (BIT.test(i) == true) { cout << i << endl; break; }
	}
	return 0;
}

Measured memory_bytes: 1664
//2019/3/14
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();

		int W = sc.nextInt();

		char[][] a = new char[H][W];

		ArrayList<Integer> h = new ArrayList<>();

		ArrayList<Integer> w = new ArrayList<>();

		boolean flag = false;


		//ついでに横チェック
		for(int i=0;i<H;i++) {

			String s = sc.next();

			flag = false;

			for(int j=0;j<W;j++) {

				a[i][j] = s.charAt(j);

				if(a[i][j] == '#') flag = true;
			}

			if(!flag) h.add(i);
		}

		//縦
		for(int j=0;j<W;j++) {

			flag = false;

			for(int i=0;i<H;i++) {

				if(a[i][j] == '#') flag = true;
			}

			if(!flag) w.add(j);
		}

		//表示 flag使い回し...
		for(int i=0;i<H;i++) {

			flag = false;

			for(int j=0;j<W;j++) {

				if(!h.contains(i) && !w.contains(j)) {

					System.out.print(a[i][j]);

					flag = true;
				}
			}
			if(flag)System.out.println();
		}

	}
}


Measured memory_bytes: 24564
n,m = map(int,input().split())
l = input().split()
for i in range(len(l)):
    l[i] = int(l[i])
l.sort()
l2 = []
for i in range(m-1):
    l2.append(l[i+1]-l[i])
l2.sort(reverse = True)
del l2[:(n-1)]
print(sum(l2))

Measured memory_bytes: 10888