akhauriyash/Code-Regression huggingface dataset:
# NK=list(map(int,input().split()))
N = int(input())
'''
An = list(map(int,input().split()))
Q = int(input())
Bn = [0] * Q
Cn = [0] * Q
for c in range(Q):
    Bn[c], Cn[c] = map(int, input().split())
'''

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"]

columnName = ""
modulo =0

while N>0:
    modulo = (N-1)%26
    columnName = alphabet[modulo]+columnName
    N = int((N-modulo)/26)


print(columnName)

Measured memory_bytes: 9192
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n := r.nextInt()

	a := ""
	for {
		if n <= 0 {
			break
		}
		a = string([]byte{byte('a' + (n%26+25)%26)}) + a
		n = (n - 1) / ('Z' - 'A' + 1)
	}

	fmt.Fprintln(stdout, a)
}


Measured memory_bytes: 1740
fn read() -> i32 {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn isprime(p: i32) -> bool {
    if p == 1 {
        return false;
    }
    for i in 2..p {
        if p % i == 0 {
            return false;
        }
    }
    return true;
}

fn main() {
    let mut n = read();
    let mut ans = vec![];
    let mut i = 31;
    while i < 55555 + 1 {
        if isprime(i) {
            ans.push(i.to_string());
            n -= 1;
        }
        if n == 0 {
            break;
        }
        i += 30;
    }

    println!("{}", ans.join(" "));
}


Measured memory_bytes: 4352
#include <iostream>
#include <math.h>
#include <set>
#include<vector>
#include<string>
#include <algorithm>
#include<queue>
#include<map>
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define per(i,j,k) for(int i = (int)j;i >= (int)k;i --)
#define F(i,k) for(int i=(int)0;i<(int)k;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
typedef long long ll;
const int maxn = 1e6 + 5;
using namespace std;
ll m,n;
struct jb {
	ll v, d;
	bool operator < (const jb&b) const {
		return v < b.v;
	}
}a[maxn];
bool cmp(jb a, jb b) {
	return a.d < b.d;
}
priority_queue<jb> Q;
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >>n>> m;
	rep(i, 1, n)cin >> a[i].d >> a[i].v;
	sort(a + 1, a + 1 + n,cmp);
	ll ans = 0;
	int p = 1;
	per(day, m, 0) {
		while (p<=n&&a[p].d + (ll)day <= m)Q.push(a[p]), p++;
		if (!Q.empty()) {
			ans += Q.top().v;
			Q.pop();
		}
		//if (p > n)break;
	}
	cout << ans;
		cin >> m;
}

/*
5 3
1 2
1 3
1 4
2 1
2 3
*/

Measured memory_bytes: 3956
#include<iostream>

using namespace std;

int main(){
	
  	int a, b;
  	while( cin >> a >> b ) {
  		
  		switch(a) {
  			
  			case 1:
  			cout << (long long) b * 6000 << "\n";
  			break;
  			
  			case 2:
  			cout << (long long) b * 4000 << "\n";
  			break;
  			
  			case 3:
  			cout << (long long) b * 3000 << "\n";
  			break;
  			
  			case 4:
  			cout << (long long) b * 2000 << "\n";
  			break;
		  }
  					
	  }
	 
  return 0;

}


Measured memory_bytes: 3076
n = gets.chomp.to_i
a = []
n.times do
  a.push(gets.chomp.to_i)
end
a.sort!

def sum(array)
  if array.empty?
    0
  else
    array.inject(:+)
  end
end

if a.size.even?
  a_zen = a[0..a.size/2 - 1]
  a_kou = a[a.size/2..a.size-1]
  a_zen_last = a_zen.pop
  a_kou_last = a_kou.shift
  p sum(a_kou) * 2 + a_kou_last - sum(a_zen) * 2 - a_zen_last
else
  a_zen = a[0..a.size/2 - 1]
  a_kou = a[a.size/2..a.size-1]
  a_harf = a_kou.shift
  a_zen_last = a_zen.pop
  a_kou_last = a_kou.shift
  total = sum(a_kou) * 2 + a_kou_last - sum(a_zen) * 2 - a_zen_last
  p total + [a_harf - a_zen_last, a_kou_last - a_harf].max
end


Measured memory_bytes: 3704
n, t = map(int, input().split())
ct_list = [tuple(map(int, input().split())) for i in range(n)]
ans = 1001

for i in ct_list:
    if i[1] > t:
        continue
    if ans > i[0]:
        ans = i[0]

if ans < 1001:
    print(ans)
else:
    print("TLE")

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	char s[100000];
	int cnt = 0;
	
	while(scanf("%s", s) != EOF){
		string t(s);
		
		reverse(t.begin(), t.end());
		
		if (t == s){
			cnt++;
		}
	}
	
	printf("%d\n", cnt);
	
	return(0);
}

Measured memory_bytes: 1072
#include<bits/stdc++.h>
using namespace std;
int main(){
char graph[10][10];
int n,m;
int row[10];
memset(row,0,sizeof row);
cin>>n>>m;
getchar();
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
        cin>>graph[i][j];
        if(graph[i][j]=='#')row[i]++;
    }
    getchar();
}
int ck=0;
int j=0,i=0;
while(i<n){
        int cnt=0;
    while(j<m){
        if(graph[i][j]=='.')
            break;
        if(graph[i][j]=='#')
        cnt++;
        j++;
    }
    j--;
//cout<<cnt<<" "<<row[i]<<""<<j<<endl;
if(cnt!=row[i])
    {
        ck=1;
        break;
    }
i++;
}
    if(ck)
        printf("Impossible\n");
    else
        printf("Possible\n");
        /*#include<bits/stdc++.h>
using namespace std;
char a[10][10];
int main(){
    int n,m;
    cin>>n>>m;
    int i,j;
    int c1=0,c2=0;
    for(i=1;i<=n;i++)for(j=1;j<=m;j++){
            cin>>a[i][j];
            if(a[i][j]=='#')c1++;
    }
    //if(a[1][1]=='.')cout<<"Impossible"<<endl;
    for(i=1,j=1;j<=m && i<=n;){
        //cout<<j<<' ';
        if(a[i][j]=='#'){
            //cout<<1<<' ';
            c2++;
            j++;
        }
        else {
            //cout<<j<<' ';
            i++;
            j--;
        }
    }
    j--;
    cout<<i<<' '<<j<<endl;
    cout<<c1<<' '<<c2<<endl;
    if(c1==c2 && i==n && j==m)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}*/

}


Measured memory_bytes: 256
#include <stdio.h>
#include <inttypes.h>

/* https://ncode.syosetu.com/n2267be/ */
#define RIZERO return 0

int main(void) {
	int64_t X;
	int64_t answer = 1;
	int64_t b;

	if (scanf("%" SCNd64, &X) != 1) return 1;

	for (b = 2; b <= X; b++) {
		int64_t t;
		for (t = b * b; t <= X; t *= b) {
			if (t > answer) answer = t;
		}
	}

	printf("%" PRId64 "\n", answer);

	RIZERO;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
    char p[100] = {}, s[100] = {};
    int c_1 = 0, c_2 = 0, flag = 1, e = 0, dummy = 0;
    
    for(int i = 1;;i++){
        scanf("%c", &s[i]);
        if(s[i] == '\n')    break;
        c_1++;
    }
    for(int i = 1;;i++){
        scanf("%c", &p[i]);
        if(p[i] == '\n')    break;
        c_2++;
    }
    for(int i = 1;i <= c_1;i++){
        flag = 0;
        for(int w = 1;w <= c_2;w++){
            dummy = i;
            dummy = dummy + w - 1;
            if(dummy > c_1) dummy = dummy - c_1;
            if(s[dummy] == p[w])    flag++;
            if(flag == c_2){
                e = 1;
                break;
            }
        }
    }
    if(e == 1){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int count0 = 0,count1 = 0;
    for(int i = 0;i < s.size();i++)
    {
        if(s[i] == '0')
        {
            count0++;
        }
        else
        {
            count1++;
        }
    }
    cout << min(count0,count1) * 2;

    return 0;
}

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


using namespace std;


using ll = long long;


const long long MAX = 510000;
const long long MOD = 1000000007;


ll pow(ll x, ll n)
{
    ll ret = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ret = (ret * x) % MOD;
        }
        x = (x * x) % MOD;
        n >>= 1;
    }
    return ret;
}


ll perm(ll x, ll y)
{
    ll ret = 1;
    for (ll i = x; i > x - y; i--) {
        ret = (ret * i) % MOD;
    }
    return ret;
}


ll fact(ll x)
{
    ll ret = 1;
    for (ll i = 2; i <= x; i++)
        ret = (ret * i) % MOD;
    return ret;
}


int main()
{
    ll n, a, b;
    cin >> n >> a >> b;

    ll ca = (perm(n, a) * pow(fact(a), MOD - 2)) % MOD;
    ll cb = (perm(n, b) * pow(fact(b), MOD - 2)) % MOD;
    ll ans = (pow(2, n) - 1 - ca - cb) % MOD;
    if (ans < 0)
        ans += MOD;
    cout << ans << endl;
}


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

using lint = long long int;
using P = pair<int, int>;
constexpr lint MOD = 998244353;

lint power(lint x, lint n, lint mod)
{
    lint ans = 1;
    while (n>0)
    {
        if (n & 1) ans = ans * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return ans;
}

vector<P> ps;

bool collinear(P p, P q, P r)
{
    return (q.second - p.second) * (r.first - p.first) == (q.first - p.first) * (r.second - p.second);
}

int N;

int main()
{
    cin >> N;
    ps.resize(N);
    for (int i=0; i<N; i++) cin >> ps[i].first >> ps[i].second;

    lint ans = (power(2LL, (lint)N, MOD) - 1 - N + MOD) % MOD;

    vector<vector<bool> > edge(N, vector<bool>(N, false));

    for (int i=0; i<N; i++)
    {
        for (int j=i+1; j<N; j++)
        {
            if (edge[i][j]) continue;
            vector<int> kyosen = {i, j};
            for (int k=j+1; k<N; k++)
            {
                if (collinear(ps[i], ps[j], ps[k])) kyosen.push_back(k);
            }
            ans = (ans - power(2LL, (lint)kyosen.size(), MOD) + 1 + kyosen.size() + MOD) % MOD;

            for (int k=0; k<kyosen.size(); k++)
            {
                for (int l=k+1; l<kyosen.size(); l++)
                {
                    edge[kyosen[k]][kyosen[l]] = edge[kyosen[l]][kyosen[k]] = true;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

string S;
int Q;

int main()
{
	cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
	cin >> S;
	cin >> Q;
	int flag = 1;
	string st = "";
	string ed = "";
	for (int t = 1; t <= Q; t++) {
		int k;
		cin >> k;
		if (k == 1) {
			flag ^= 1;
		}
		else {
			char tmp;
			cin >> k;
			cin >> tmp;
			if (k == 1) {
				if (flag) st.push_back(tmp);
				else ed.push_back(tmp);
			}
			else {
				if (flag) ed.push_back(tmp);
				else st.push_back(tmp);
			}
		}
	}

	if (flag) {
		reverse(st.begin(), st.end());
		cout << st << S << ed;
	}
	else {
		reverse(ed.begin(), ed.end());
		reverse(S.begin(), S.end());
		cout << ed << S << st;
	}
}


Measured memory_bytes: 1040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

//		long ans2 = 0;
		double ans = 0;

		Scanner sc = new Scanner(System.in);
		int  n = sc.nextInt();
//		int  k = sc.nextInt();

//		int  k = sc.nextInt();
//		long d = sc.nextLong();

//		String string = sc.next();
//		StringBuilder s = new StringBuilder(string);

//		boolean f = true;
//
//		int[] a = new int[m];
//		int[] b = new int[m];
//		for (int i = 0; i < n; i++) {
//			a[i] = sc.nextInt();
//		}
//		for (int i = 0; i < k; i++) {
//			b[i] = sc.nextInt();
//		}
//		for (int i = 1; i <n; i++) {
//			b[i] = sc.nextInt();
//		}
//		int[][] c = new int[h][w];
//		for (int i = 0; i < h; i++) {
//			for(int j = 0; j < w; j++) {
//				c[i][j] = 0;
//			}
//		}

//		int tmp_a = 0;
//		int tmp_b = 0;

		if(n%2 == 0) {
			ans = 0.5;
		} else {
			double tmp = n/2 +1;
			ans = tmp/n;
		}


		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 22996
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int[][] input = new int[3][6];
		
		for(int i = 0; i < 3; i++){
			String[] tmpArray = br.readLine().split(" ");
			for(int j = 0; j < 6; j++){
				input[i][j] = Integer.parseInt(tmpArray[j]);
			}
		}
		
		for(int i = 0; i < 3; i++){
			int seconds = calcTime(input[i]);
			
			System.out.println(seconds/3600 + " "+ (seconds%3600)/60 + " " + seconds%60) ;
		}
	}
	
	static int calcTime (int[] input){
		int start = input[0]*3600 + input[1]*60 + input[2];
		int end = input[3]*3600 + input[4]*60 + input[5];
	
		return end - start;
	}

}

Measured memory_bytes: 24104
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const ll mod = 1e9 + 7;

int main() {
    int N; ll K;
    cin >> N >> K;
    int A[N];
    for(int i = 0; i < N; ++i) cin >> A[i];
    
    vector<int> s;
    vector<int> ord(N+1,-1);
    int c = 1, l = 0;//周期c, ループ前l

    int v = 1;
    while(ord[v] == -1){ //初期値-1なら未踏
        ord[v] = s.size(); //vは何番目に来たか
        s.push_back(v); //vec s末尾にv追加
        v = A [v-1]; //次のv
    } //ループ1回目が終わるとbreak
    c = s.size() - ord[v]; //今書いた数-前回来た時の数
    l = ord[v]; //前回来た時の数 = ループするまで

    if(K < l) cout << s[K] << endl;
    else cout << s[(K - l) % c + l] << endl;
}

Measured memory_bytes: 5884
N, M = map(int, input().split())
S = input()

steps = []
c = N
flg = True
while flg:
    if c <= M:
        steps.append(c)
        break
    for i in reversed(range(1, M + 1)):
        if S[c - i] == "0":
            steps.append(i)
            c -= i
            break
        if i == 1:
            steps = [-1]
            flg = False

print(*steps[::-1])



Measured memory_bytes: 50416
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define MAX 100

void bubbleSort(int A[], int N);

static int count = 0;

int main()
{
    int A[MAX];
    int N;

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

    for (int i = 0; i < N; i++) {
        int minj = i;
        for(int j = i; j < N; j++) {
            if(A[j] < A[minj]) minj = j;
        }
        if(A[i] != A[minj]) ::count++;
        int temp = A[i];
        A[i] = A[minj];
        A[minj] = temp;
    }

    for (int i = 0; i < N; i++) {
        cout << A[i];
        if(i < N-1) cout << " ";
    }
    cout << endl;

    cout << ::count << endl;

    return 0;
}



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

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int n,m;
	cin>>n>>m;

	vector<int> arr(n);
	priority_queue<int,vector<int>,greater<int>> pq;
	for(int i = 0; i < n; i++){
		int tmp;cin>>tmp;
		pq.push(tmp);
	}

    vector<pair<int,int>> p(m);
	for(int i = 0; i < m; i++){
		int a,b;
		cin>>a>>b;
		p.emplace_back(b,a);
	}
	sort(p.rbegin(),p.rend());

	ll ans = 0;

	for(int i = 0; i < m; i++){
		if(pq.top()>p[i].first || pq.empty()) break;
		int cnt = p[i].second;
		while(pq.top()<p[i].first && cnt-- && !pq.empty()){
			ans+=p[i].first;
			pq.pop();
		}
	}
	while(!pq.empty()){
		ans+=pq.top();
		pq.pop();
	}

	cout<<ans;



}

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

int main() {
  int N;
  cin >> N;
  vector<int> l(N), r(N);
  for (int i = 0; i < N; i++) {
    cin >> l.at(i) >> r.at(i);
  }
  vector<int> A(100000);
  for (int i = 0; i < N; i++) {
    for (int j = l.at(i) - 1; j < r.at(i); j++) {
      A.at(j) = 1;
    }
  }
  int ans = 0;
  for (int i = 0; i < 100000; i++) {
    ans += A.at(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

cumulative_sum = Array.new(n + 1)
cumulative_sum[0] = 0
n.times { |i| cumulative_sum[i+1] = a[i] + cumulative_sum[i] }

half = a.inject(&:+) / 2.0

i = cumulative_sum.map { |s| (s - half).abs }.min

puts (i * 2).to_i

Measured memory_bytes: 21380
// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#define pb emplace_back
#define LOCAL
  
using namespace std;
  
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+5;
typedef long long ll;
typedef pair<int,int> Pii;
 
template <typename T>inline void read(T& t){
    char c=getchar();t=0;
    int f=1;
    while(!isdigit(c)){
       if(c=='-')f=-1;
        c=getchar();
    }
    while(isdigit(c))t=t*10+c-48,c=getchar();
    t=f*t;
}
  
template <typename T,typename... Args> inline void read(T& t,Args&... args){
    read(t);read(args...);
}

char s[1005],t[1005];
  
int main(){
    scanf("%s",s+1);
    scanf("%s",t+1);
    int len1=strlen(s+1);
    int len2=strlen(t+1);
    int ans=inf;
    for(int i=1;i<=len1-len2+1;i++){
        int tmp=0;
        for(int j=1,x=i;j<=len2;j++,x++){
            if(s[x]!=t[j]){
                tmp++;
            }
        }
        ans=min(ans,tmp);
    }   
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a, n) priority_queue<int>a(n)
#define PQmin(a, n) priority_queue< int, std::vector<int>, std::greater<int> >a(n)

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    cin>>n;
    vector<pair<string, int> > sp(n);
    vector<pair<string, int> > sp_(n);
    for(int i=0;i<n;i++){
        cin>>sp.at(i).first;
        cin>>sp.at(i).second;
        sp_.at(i).first=sp.at(i).first;
        sp_.at(i).second=sp.at(i).second;
    }
    sort(sp.begin(), sp.end());
    for(int i=0;i<n-1;i++){
        int k=1;
        while(sp.at(i).first==sp.at(i+k).first){
            k++;
            if(i+k>=n)break;
        }
        k--;
        vector<pair<string, int> > tmp(k+1);
        for(int p=0;p<=k;p++){
            tmp.at(p).first=sp.at(i+p).first;
            tmp.at(p).second=sp.at(i+p).second;
        }
        sort(tmp.begin(),tmp.end());
        reverse(tmp.begin(),tmp.end());
        for(int p=0;p<=k;p++){
            sp.at(i+p).second=tmp.at(p).second;
        }
        i+=k;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(sp.at(i).first==sp_.at(j).first && sp.at(i).second==sp_.at(j).second){
                cout<<j+1<<endl;
            }
        }
    }




    // for(int i=0;i<n;i++){
    //     for(int j=0;j<n;j++){
    //         if(sp.at(i).first==sp_.at(j).first){
    //             int k=1;
    //             if(sp.at(i+1).first==sp.at(i).first){
    //                 while(sp.at(i+k+1).first==sp_.at(i).first){
    //                 k++;
    //                 }
    //                 for(int x=k;x>=0;x--){
    //                     if(sp.at(i+x).second==sp_.at(j).second){
    //                         cout<<j<<endl;
    //                     }
    //                 }

    //             }
    //             break;
    //         }
    //     }
    // }







    return 0;
}


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


int main() {

  int n,d;
  cin>>n>>d;

  vector<vector<int>> x(n, vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>x.at(i).at(j);
    }
  }
  
  int64_t cnt=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int64_t sum=0;
      for(int k=0;k<d;k++){
        sum+=(x.at(i).at(k)-x.at(j).at(k))*(x.at(i).at(k)-x.at(j).at(k));
      }
      int64_t dist = (int64_t)sqrt(sum);
      if(dist*dist==sum)
        cnt++;
    }
  }
  
  cout<<cnt<<endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,s;
    cin>>a>>s;
    if(a==s)cout<<"Draw"<<endl;
    else if(a==1)cout<<"Alice"<<endl;
    else if(s==1)cout<<"Bob"<<endl;
    else if(a>s)cout<<"Alice"<<endl;
    else cout<<"Bob"<<endl;
}
  


Measured memory_bytes: 256
from math import sqrt, factorial

n = int(input())
XY = [list(map(int, input().split())) for _ in range(n)]
total = sum(
    factorial(n - 1) * sqrt((XY[i][0] - XY[j][0])**2 + (XY[i][1] - XY[j][1])**2)
    for i in range(n)
    for j in range(i + 1, n)
)

print(2 * total / factorial(n))


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

#define Set(a, b) memset(a, b, sizeof (a))
#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)

using namespace std;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * p;
}

inline void File() {
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
}

const int N = 12;
int n, k, vis[N], x;

inline bool check(int x) {
	while (x) {
		if (vis[x % 10]) return false; 
		x /= 10;
	}	
	return true;
}

int main() {
	n = read(), k = read();

	For(i, 1, k) vis[x = read()] = 1;

	for (; n; ++ n) if (check(n)) return printf("%d\n", n), 0;
	return 0;
}


Measured memory_bytes: 256
import itertools
ans = 0
n = int(input())

for k in range(1,10):
    s = itertools.product(["3","5","7"], repeat=k)
    for seq in s:
        x = set()
        for i in seq:
            x.add(i)
        if len(x) != 3:
            continue
        t = "".join(seq)
        if 1 <= int(t) <= n:
            ans += 1
print(ans)

Measured memory_bytes: 3188
n=int(input())
a=[]
sum_dict=0
for i in range(n):
    x,y=map(int,input().split())
    a.append((x,y))

for i in range(n):
    for j in range(n):
        sum_dict+=((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)**0.5
print(sum_dict/n)


Measured memory_bytes: 3060
global N, M, X
N, M, X = map(int, input().split())
global C, A
C, A = [], []
for i in range(N):
    tmp, *_ = map(int, input().split())
    C.append(tmp), A.append(list(_))
    
def adde(a, b):
    t = []
    for i in range(M):
        t.append(a[i] + b[i])
    return t
        


def solve(times, big, lists, cost):
    if times == N:
        if not len(list(filter(lambda x:x<X, lists))):
            return min(big, cost)
        else:
            return big

    big = solve(times + 1, big, adde(lists, A[times]), cost + C[times])
    big = solve(times + 1, big, lists, cost)
    
    return big

ans = solve(0, float('inf'), [0 for i in range(M)], 0)
print(ans if ans != float('inf') else -1)


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

using namespace std;

int main(void) {
	int n;
	int mn = -1;
	cin >> n;
	int sum = 0;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		sum += x;
		if((x % 10) != 0) {
			if(mn == -1) mn = x;
			else mn = min(mn, x);
		}
	}

	if((sum % 10) != 0) cout << sum << endl;
	else if(mn != -1) cout << sum - mn << endl;
	else cout << 0 << endl;
	
	return 0;
}

Measured memory_bytes: 256
/*
 * 16-8-21_AGC003_C.cpp
 *
 *  Created on: 2016/08/21
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>

using namespace std;

int N;
pair<int,int>A[100001];
int ans;
int main(){
	cin >> N;
	for (int i=0;i<N;i++){
		int x;
		cin >> x;
		A[i] = make_pair(x,i);
	}
	sort(A,A+N);
	for (int i=0;i<N;i+=2){
		if (A[i].second&1)
			ans++;
	}
	cout <<ans<< endl;
	return 0;
}




Measured memory_bytes: 1024
#include <cmath>
#include <iostream>
#include <vector>

using std::size_t;

size_t greatestCommonDivisor(size_t a, size_t b) {
  if (a < b) std::swap(a, b);
  size_t r = a % b;
  while (r > 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

size_t countPrimeFactors(size_t n) {
  size_t count = 0;
  const size_t max = std::sqrt(n);
  for (size_t pi = 2; pi <= max; ++pi) {
    if (n % pi == 0) {
      ++count;
      n /= pi;
      while (n % pi == 0) n /= pi;
    }
  }
  if (n > max) ++count;
  return count;
}

int main() {
  size_t a, b;
  std::cin >> a >> b;

  const auto gcd = greatestCommonDivisor(a, b);
  const auto n = countPrimeFactors(gcd) + 1;
  std::cout << n << std::endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M, X;
  cin >> N >> M >> X;

  vector<int> cs(N);
  vector<vector<int>> as(N, vector<int>(M));

  F0R(i, N) {
    cin >> cs[i];

    F0R(j, M) {
      cin >> as[i][j];
    }
  }

  vector<bool> buy(N, false);

  i64 result = INT64_MAX;

  auto judge = [&]() {
    i64 cost = 0;
    vector<i64> exp(M);
    F0R(i, N) {
      if (!buy[i]) continue;

      cost += cs[i];
      F0R(j, M) {
        exp[j] += as[i][j];
      }
    }

    bool valid = true;
    F0R(i, M) {
      if (exp[i] < X) {
        valid = false;
        break;
      }
    }
    if (valid) {
      chmin(result, cost);
    }
  };

  bool end = false;
  while (!end) {
    judge();

    auto it = --buy.end();
    while (true) {
      if (!*it) {
        *it = true;
        break;
      }
      if (it == buy.begin()) {
        end = true;
        break;
      }
      *it = false;
      it--;
    }
  }

  cout << (result == INT64_MAX ? -1 : result);
}
#endif


Measured memory_bytes: 3660
#define rep(i, m, n) for(int i = m; i < n; i++)
#define repM(i, m, n) for(int i = n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll; using namespace std;
//typedef pair<int,int> pii;
// d = distance(lower_bound(all(x)), upper_bound(all(x)));
int INF = 1e9;
int M = 1e9+7;
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>

int main(){
  int N; cin >> N; int K = pow(2,N); int b; multiset<int> p;
  for(int i=0; i<K; i++) {cin >> b; p.insert(b);}
  auto r=p.end(); r--;
  vector<int> v; v.push_back(*r); p.erase(r);
  //int mx = *min_element(p.begin(), p.end());
  //vector<int> v; v.push_back(mx); p.erase(mx);
  
  for(int i=1; i<=N; i++) {
    for(int j=0; j<pow(2,i-1); j++) {
      r = p.lower_bound(v[j]);
      //int r = distance(p.begin(), lower_bound(p.begin(), p.end(), v[j]));
      //cout << *r << " ";
      if (r == p.begin()) {cout << "No" << endl; return 0;}
      else {
        v.push_back(*(--r)); p.erase(r);
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 13692
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use 5.010;
my @args;
for (<>) {
    chomp $_;
    push @args, $_;
}

my ($N, $K) = split " ", shift @args;

my $half_count=0;
if ($K % 2 == 0) {
    my $half_first = $K / 2;
    my $hoge = ($N - $half_first) % $K;
    $half_count = ($N - $half_first - $hoge) / $K + 1;
#    $half_count = 1;
#    while (1) {
#        $half_first += $K;
#        if ($half_first <= $N) {
#            $half_count++;
#            next;
#        } else {
#            last;
#        }
#    }
}

my $bingo = 0;
{
    $a = $N % $K;
    $bingo = ($N - $a) / $K;
}

say $half_count ** 3 + $bingo ** 3;

__END__

7*11*1483

114191 - 54872

Measured memory_bytes: 1920
#include<iostream>
#include<cmath>

using namespace std;
int lcm(int x, int y);

int main(){
   long n,m;
   cin >> n >> m;
   int c = lcm(n,m);

   string s,t;
   cin >> s >> t;

   bool check = true;
   for(int i=0;i<c; i++){
      int a = i * (n/ c);
      int b = i * (m /c);
      if(s[a] != t[b]){
         check = false;
         break;
      }
   }

   cout << (check ? (n / c) * m : -1) << endl;
}

int lcm(int x, int y){
   if( x > y){
      return lcm(y, x);
   }
   if(y % x == 0){
      return x;
   }
   return lcm(y % x, x);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  if (abs(a - b) % 2 == 1)
    cout << "Borys" << endl;
  else
    cout << "Alice" << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
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();
        
        System.out.println(B-A == C-B ? "YES": "NO");
    }
}

Measured memory_bytes: 23892
n, m = map(int, input().split())
L = [[]*n for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    L[a-1] += [b]
    L[b-1] += [a]
#print(L)
for i in L[0]:
    if n in L[i-1]:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


Measured memory_bytes: 38368
//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

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

    let mut a = a;
    a.sort_by_key(|&x| x as u64);

    let n = a.pop().unwrap();

    let mut k = a[0];

    for &x in a[1..].iter() {
        if (n / 2. - x).abs() < (n / 2. - k).abs() {
            k = x;
        }
    }

    println!("{} {}", n as u64, k as u64);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P  = pair <int, int>;

#define rep(i, n)     for (int i = 0; i < (int) (n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp)   for (auto &i : mp)

const int INF = 1001001001;

int main()
{
  string s;
  cin >> s;
  ll tmp = 0;
  rep(i, s.size()) {
    tmp += (s[i] - '0');
  }
  string ans = "No";
  tmp = tmp % 9;
  if (tmp == 0) {
    ans = "Yes";
  }

  cout << ans << endl;

  return 0;
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define cout(d) cout<<d<<endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

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

int main(){
  string s;
  cin>>s;
  string ans="Yes";
  int n=s.size();
  rep(i,n){
    if((i+1)%2==0){
      if(!(s[i]=='L'||s[i]=='U'||s[i]=='D')) {
        ans="No";
      }
    }else{
      if(!(s[i]=='R'||s[i]=='U'||s[i]=='D')) ans="No";
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vector2d = vector<vector<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }

// 燃料満タン状態で補充無しで行ける所をつなぐ、その後warshall-floyd

// 一点からの最短距離
template<typename Edge, typename T>
void Dijkstra(const vector<vector<Edge>> &edge, int s, vector<T> &d) {
	using P = pair<T, int>;
	priority_queue<P, vector<P>, greater<P>> q;
	q.push({0, s});
	while(q.size()) {
		T dist;
		int v;
		tie(dist, v) = q.top(); q.pop();
		if(d[v] < dist) continue;
		for(auto&& e : edge[v]) {
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push({d[e.to], e.to});
			}
		}
	}
}

// WarshallFloyd
template <typename T>
void WarshallFloyd(vector<vector<T>> &link) {
    int N = link.size();
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                link[i][j] = min(link[i][j], link[i][k] + link[k][j]);
            }
        }
    }
}

struct Edge {
    int to;
    i64 cost;
};

const i64 INF = 1e15;

int main() {
    int N, M, L;
    cin >> N >> M >> L;
    vector<vector<Edge>> edge(N);
    for(int i = 0; i < M; i++) {
        int a, b;
        i64 c;
        cin >> a >> b >> c;
        a--, b--;
        edge[a].push_back({b, c});
        edge[b].push_back({a, c});
    }
    vector<vector<i64>> link(N, vector<i64>(N, INF));
    for(int i = 0; i < N; i++) {
        vector<i64> dist(N, INF);
        dist[i] = 0;
        Dijkstra(edge, i, dist);
        for(int j = 0; j < N; j++) {
            if(i == j) {
                link[i][j] = 0;
            }
            if(dist[j] <= L) {
                link[i][j] = 1;
            }
        }
    }

    WarshallFloyd(link);

    int Q;
    cin >> Q;

    for(int i = 0; i < Q; i++) {
        int s, t;
        cin >> s >> t;
        s--, t--;
        cout << (link[s][t] < INF ? link[s][t] - 1 : -1) << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include<map>
#include<cstring>
using namespace std;
int a[110000];
const int maxn=1e5;
string code="AKIHABARA",st;
int ans[100][100];
int main(int argc, const char * argv[]) {
    string st;
    cin>>st;
    ans[0][0]=1;
    int len0=code.length(),len1=st.length();
    for(int i=0;i<=len0;i++)for(int j=0;j<=len1;j++)
    {
        if(i>0&&j>0&&ans[i-1][j-1]&&code[i-1]==st[j-1])ans[i][j]=1;
        if(i>0&&ans[i-1][j]&&code[i-1]=='A')ans[i][j]=1;
       // cout<<"ans["<<i<<"]["<<j<<"]:"<<ans[i][j]<<endl;
    }
    if(ans[len0][len1])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
set<int>::iterator gt(set<int>& bst, int v) { return bst.upper_bound(v); }
set<int>::iterator ge(set<int>& bst, int v) { return bst.lower_bound(v); }
set<int>::iterator lt(set<int>& bst, int v) { return bst.lower_bound(v) == bst.begin() ? bst.end() : --bst.lower_bound(v); }
set<int>::iterator le(set<int>& bst, int v) { return bst.upper_bound(v) == bst.begin() ? bst.end() : --bst.upper_bound(v); }
map<int, int>::iterator gt(map<int, int>& bst, int v) { return bst.upper_bound(v); }
map<int, int>::iterator ge(map<int, int>& bst, int v) { return bst.lower_bound(v); }
map<int, int>::iterator lt(map<int, int>& bst, int v) { return bst.lower_bound(v) == bst.begin() ? bst.end() : --bst.lower_bound(v); }
map<int, int>::iterator le(map<int, int>& bst, int v) { return bst.upper_bound(v) == bst.begin() ? bst.end() : --bst.upper_bound(v); }
#define N 5000
#define M 500'000
struct nail {
    int a, b, x;
} nails[M];
map<int, int> intervals[N+1];
void insert_interval(int row, int s, int e) {
    if(intervals[row].empty()) {
        intervals[row][s] = e;
    } else {
        auto p = le(intervals[row], s);
        int cur;
        if(p != intervals[row].end() and p->second + 1 >= s) {
            intervals[row][p->first] = max(intervals[row][p->first], e);
            cur = p->first;
        } else {
            intervals[row][s] = e;
            cur = s;
        }
        vector<int> dead;
        for(auto it = gt(intervals[row], cur); it != intervals[row].end(); it++) {
            if(it->first - 1 <= intervals[row][cur]) {
                intervals[row][cur] = max(intervals[row][cur], it->second);
                dead.push_back(it->first);
            }
        }
        for(int x : dead) {
            intervals[row].erase(x);
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        cin >> nails[i].a >> nails[i].b >> nails[i].x;
    }
    sort(nails, nails + m, [](nail& n1, nail& n2) {
        return n1.b == n2.b ? n1.a < n2.a : n1.b < n2.b;
    });
    int max_row = 0;
    for(int i = 0; i < m; i++) {
        if(i == 0 or nails[i].b > nails[i-1].b) {
            max_row = nails[i].a;
        }
        for(int row = max(nails[i].a, max_row); row <= nails[i].a + nails[i].x; row++, max_row++) {
            insert_interval(row, nails[i].b, row - (nails[i].a - nails[i].b));
        }
    }
    int covered = 0;
    for(int i = 1; i <= n; i++) {
        for(auto p : intervals[i]) {
            covered += p.second - p.first + 1;
        }
    }
    cout << covered << endl;
    return 0;
}



Measured memory_bytes: 9480
def cnt(n):
    res = 0
    while True:
        n = n / 2
        if n.is_integer():
            res += 1
        else:
            return res


ans = 0
_ = input()
for a_str in input().split():
    a = int(a_str)
    if a % 2 == 0:
        ans += cnt(a)

print(int(ans))


Measured memory_bytes: 3828
#include<iostream>

using namespace std;

//int abs(long int n)
//{
//    if(n<0){ return n*(-1);}
//    else return n;
//}
int main()
{
    long int A,B;
    cin>>A>>B;
    if(abs(A-B)%2==0){
        cout<<(A+B)/2<<endl;
    }
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


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

int binarySearch(int S[],int key,int n){
	int left = 0,right = n;
	int mid;
	while(left<right){
		mid = (left + right)/2;
		if(key == S[mid]){
			return 1;
		}else if(key < S[mid]){
			right = mid;
		}else{//key???S[mid]????????§????????´????????????????????§?????£???????????????????????£?????´???
			left = mid + 1;
		}
	}
	return 0;
}

int main(){
	int n,S[100000];
	int q,T;
	int sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d",&T);
		if(binarySearch(S,T,n)) sum++;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 1416
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int a,b,n;
  cin >> a >> b >> n;
  if(n >= b){
    cout << a*(b-1)/b << endl;
  }
  else{
    cout << a*n/b << endl;
  }
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int q,q1,f=0;
	cin>>q>>q1;
	vector<int> v;
	for(int i=0;i<q1;i++){
		int z;
		cin>>z;
		if(z==q)
			f=1;
		v.push_back(z);
	}
	if(f==0){
		cout<<q;
	}
	else{
		sort(v.begin(),v.end());
		//cout<<"ff";
		int z=q-1;
		int x=q+1;
		auto c=lower_bound(v.begin(),v.end(),z);
		auto d=lower_bound(v.begin(),v.end(),x);
		while(*c==z && *d==x){
			z-=1;
			x+=1;
			c=lower_bound(v.begin(),v.end(),z);
			d=lower_bound(v.begin(),v.end(),x);
		}
		if(((*c!=z) && (*d!=x))||(*c!=z)){
			cout<<z;
		}
		else{
			cout<<x;
		}
	}
	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
using ll = long long;

int main(){
  int h,w,k;
  cin>>h>>w>>k;
  vector<string>s(h);
  rep(i,h)cin>>s[i];
  int ans=INF;
  rep(bits,1<<(h-1)){
    int g=0;
    vector<int>id(h);
    rep(i,h){
      id[i]=g;
      if(bits>>i&1)g++;
    }
    g++;
    int num=g-1;
    vector<int>sum(g);
    auto add=[&](int i){
      rep(j,h)sum[id[j]]+=(s[j][i]-'0');
      rep(j,g){
        if(sum[j]>k)return false;
      }
      return true;
    };
    rep(i,w){
      if(!add(i)){
        num++;
        sum=vector<int>(g);
        if(!add(i)){
          num=INF;
          break;
        }
      }
    }
    ans=min(ans,num);
  }
  cout<<ans<<endl;
  return(0);
}



Measured memory_bytes: 256
// unolight {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
// }}}

const int MAX_N = 100;
int n, m;
int A[MAX_N][MAX_N];
bitset<25601> dp[80][80];
const int C = 12800;
void input()
{
    RI(n, m);
    REP(i,n)
        REP(j,m)
            RI(A[i][j]);

    REP(i,n)
        REP(j,m){
            int t;
            RI(t);
            A[i][j] = abs(A[i][j] - t);
        }
}

void solve() {
    dp[0][0][C + A[0][0]] = 1;
    REP(i,n){
        REP(j,m){
            if(i) {
                dp[i][j] |= (dp[i - 1][j] << A[i][j]);
                dp[i][j] |= (dp[i - 1][j] >> A[i][j]);
            }
            if(j) {
                dp[i][j] |= (dp[i][j-1] << A[i][j]);
                dp[i][j] |= (dp[i][j-1] >> A[i][j]);
            }
        }
    }

    for (int k = 0; k + C < 25601;k++) {
        if (dp[n-1][m-1][C + k] || dp[n-1][m-1][C - k]) {
            printf("%d\n", k);
            break;
        }
    }
}

int main( int argc, char *argv[] ) {
    input();
    solve();
    return 0;
}


Measured memory_bytes: 20352
module Main where

import Control.Monad
import Control.Applicative

main :: IO ()
main = do
    n <- readLn :: IO Int
    xs <- replicateM n $ (\[x, u] -> conv (read x :: Double) u) . words <$> getLine
    print . sum $ xs


conv :: Double -> String -> Double
conv n t =
    if t == "JPY" then
        n
    else
        n * 380000.0


Measured memory_bytes: 636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC
{
	class Program
	{
		static void Main(string[] args)
		{
			var num = Console.ReadLine().Split(' ').Select(row => Convert.ToInt32(row)).ToArray();
			var post = Console.ReadLine();


			if(post.Count(row => row == '-') == 1)
			{
				if(post[num[0]] == '-' && post.Length == num[0] + num[1] + 1)
				{
					Console.WriteLine("Yes");
				}
				else
				{
					Console.WriteLine("No");
				}
			}
			else
			{
				Console.WriteLine("No");
			}
		}
	}
}


Measured memory_bytes: 13268