akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll INF = 1e11+7;
ll N, dat[2222222];
void init(ll n){
    N = 1;
    while(N < n) N *= 2;
    for(ll i=0;i<2*N-1;i++) dat[i] = INF;
}

void update(ll idx, ll val){
    idx += N-1;
    dat[idx] = val;
    while(idx>0){
        idx = (idx-1)/2;
        dat[idx] = min(dat[idx*2 + 1], dat[idx*2+2]);
    }
}

// query(a,b,0,0,N) → [a,b)
ll query(ll a, ll b, ll k, ll l, ll r){
    if(r<=a || b<=l) return INF;
    if(a<=l && r<=b) return dat[k];
    else{
        ll vl = query(a,b,k*2+1,l,(l+r)/2);
        ll vr = query(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    
    ll n;
    cin>>n;
    ll l[n],r[n];
    init(n);
    array<ll,2> a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>l[i]>>r[i];
        a[i] = {l[i],r[i]};
        b[i] = {-r[i],-l[i]};
    }
    sort(a,a+n);
    sort(b,b+n);
    for(int i=0;i<n;i++){
        update(i,a[i][1]);
    }
    sort(r,r+n);
    ll ans = 0;
    for(int i=0;i<n-1;i++){
        ll ret = max(0LL,query(0,i+1,0,0,N)-a[i][0]+1) + max(0LL,query(i+1,n+1,0,0,N)-a[n-1][0]+1);
        ans = max(ans,ret);
        ll ma = r[0];
        if(ma == a[i][1]) ma = r[1];
        ret = a[i][1] - a[i][0] + 1 + max(0LL, ma-a[n-1][0]+1);
        ans = max(ans,ret);
    }

    init(n);
    for(int i=0;i<n;i++){
        update(i,b[i][1]);
    }
    for(int i=0;i<n-1;i++){
        ll ret = max(0LL,query(0,i+1,0,0,N)-b[i][0]+1) + max(0LL,query(i+1,n+1,0,0,N)-b[n-1][0]+1);
        ans = max(ans,ret);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 9088
from sys import stdin
def I(): return int(stdin.readline().rstrip())
    
coin = [I() for _ in range(3)]
x = I()
ans = 0
for i in range(coin[0]+1):
    sum = 500*i
    if sum<=x:
        for j in range(coin[1]+1):
            tmp = sum + 100*j
            if tmp<=x:
                for k in range(coin[2]+1):
                    if tmp+50*k==x:
                        ans += 1
                        break
                    elif x<tmp+50*k:
                        break
            else:
                break
    else:
        break

print(ans)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	S := sc.next()
	if S == "Sunny" {
		fmt.Println("Cloudy")
	}
	if S == "Rainy" {
		fmt.Println("Sunny")
	}

	if S == "Cloudy" {
		fmt.Println("Rainy")
	}
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
using ll = long long;
using ld = long double;
using namespace std;
int main(){
    ll n;
    cin>>n;
    if(n%11==0){
        cout<<n/11*2<<endl;
        return 0;
    }
    if(n%11<=6){
        cout<<(n/11)*2+1<<endl;
    }else{
        cout<<(n/11)*2+2<<endl;
    }

}

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

int main()
{
	int n, m;

	cin >> n >> m;

	int a[200],  b[200];

	for (int i = 0; i < 2 * n; i++){
		a[i] = i + 1;
	}

	for (int i = 0; i < m; i++){
		
		for (int j = 0; j < 2 * n; j++){
			b[j] = a[j];
		}	

		int k;
		cin >> k;

		if (k == 0){
			for (int j = 0; j < 2 * n; j++){
				if (j % 2 == 0){
					a[j] = b[j / 2];
				}
				else {
					a[j] = b[j / 2 + n];
				}
			}
		}
		else {
			for (int j = 0; j < 2 * n - k; j++){
				a[j] = b[j + k];
			}
			for (int j = 2 * n - k; j < 2 * n; j++){
				a[j] = b[j + k - 2 * n];
			}
		} 
	}
	for (int i = 0; i < 2 * n; i++){
		cout << a[i] << endl;
	}
	return (0);
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n,m; cin >>n >>m;
  int b[n+1]; memset(b,1,sizeof(b));
  for(int i=0; i<m; i++){
    int x; cin >>x;
    b[x]=0;
  }
  int dp[n+1]; memset(dp,0,sizeof(dp)); dp[0]=1;
  for(int i=0; i<n; i++) for(int j=i+1; j<=min(n,i+2); j++) if(b[j]){
    dp[j]+=dp[i]; dp[j]%=MOD;
  }
  cout <<dp[n];
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

Measured memory_bytes: 4428
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

long long arr[4];
long long K;

int main()
{
	for(int i = 0; i < 3; i++) {
		scanf("%lld", &arr[i]);
	}
	scanf("%lld", &K);

	sort(arr, arr + 3);

	long long sum = 0;

	for(int i = 0; i < K; i++) {
		arr[2] *= 2;
	} 

	for(int i = 0; i < 3; i++) {
		sum += arr[i];
	}
	
	printf("%lld\n", sum);
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())

    if K&1: # Kが奇数
        tmp = N//K
        print(tmp**3)
    else:   # Kが偶数
        tmp = N//K
        tmp2 = tmp
        if N%K >= K//2:
            tmp2 += 1
        print(tmp**3 + tmp2**3)

if __name__ == "__main__":
    main()

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

while True:
    n = int(raw_input())

    if n == 0:
        break

    columns = []
    for i in range(n):
        columns.append([])

    maxrows = []
    for i in range(n):
        row = map(int, raw_input().split())
        maxrows.append(min(row))
        for j in range(n):
            columns[j].append(row[j])

    maxcolumns = map(max, columns)

    result = 0
    for c in columns:
        if max(c) in maxrows:
            result = max(c)
            
    print result
    

Measured memory_bytes: 4228
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from copy import deepcopy
from collections import deque
def main():
    N, Q = map(int, readline().split())
    m = map(int, read().split())
    n = deepcopy(m)
    to = [[] for _ in range(N)]
    for a, b in [(a-1, b-1) for a, b in zip(m, m)][:N-1]:
        to[a].append(b)
        to[b].append(a)
    score = [0 for _ in range(N)]
    for p, x in [(p-1, x) for p, x in zip(n, n)][N-1:]:
        score[p] += x

    dq = deque()
    dq.append(0)
    done = [0 for _ in range(N)]
    done[0] = 1
    while len(dq)>0:
        node = dq.popleft()
        for nx in to[node]: 
            if done[nx] == 1:
                continue 
            done[nx] = 1
            score[nx] += score[node]
            dq.append(nx)
    for i in score:
        print(i, end=' ')
if __name__ == '__main__':
    main()

Measured memory_bytes: 135444
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e10;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

ll ruijou(ll n, ll k){
    if(k==0) return 1;
    ll x=k/2;
    long long t=ruijou(n,x);
    t=(t*t);
    if(k%2==1) return (n*t);
    else return t;
}

vec LIST;
P Solve(ll x){
  P ret;
  ll N=LIST.size();
  rep(i,N) REP(j,i,N) if(LIST[j]-LIST[i]==x) {
    //cout<<LIST[j]<<' '<<LIST[i]<<endl;
    ret=mp(j-200,i-200);
    return ret;
  }
  return ret;
}

int main(){
  REP(i,-200,201) LIST.pb(ruijou(i,5));
  ll X; cin>>X;
  P ans=Solve(X);
  cout<<ans.first<<' '<<ans.second<<endl;

}

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

public class Main {
	/**
	 * ????§???¢??????????????\???????????¨???????§???¢????????\??????????????¨??????????±???????
	 *
	 * @param args
	 *            ?????¨?????????
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			int lineNum = Integer.parseInt(br.readLine());
			for (int i = 0; i < lineNum; i++) {
				String line = br.readLine();
				String[] temp = line.split(" ");
				float x1 = Float.parseFloat(temp[0]);
				float y1 = Float.parseFloat(temp[1]);
				float x2 = Float.parseFloat(temp[2]);
				float y2 = Float.parseFloat(temp[3]);
				float x3 = Float.parseFloat(temp[4]);
				float y3 = Float.parseFloat(temp[5]);
				Circle circle = new Circle(x1, y1, x2, y2, x3, y3);
				System.out.printf("%.3f %.3f %.3f\n", circle.getCenterX(), circle.getCenterY(), circle.getRadius());
			}
		}
	}

	public static class Circle {
		private float centerX;
		private float centerY;
		private float radius;

		public Circle(float x1, float y1, float x2, float y2, float x3, float y3) {

			/**
			 * ?¨???????????????????????????????(x1, y1)???????????¨????????§?¨???????????????????
			 */
			x2 = x2 - x1;
			y2 = y2 - y1;

			x3 = x3 - x1;
			y3 = y3 - y1;

			/**
			 * X^2 + Y^2 - 2mX - 2nY + l = 0 ????§£?????????????????¨??????????±???????
			 */
			centerX = ((x3 * x3 + y3 * y3) * y2 - (x2 * x2 + y2 * y2) * y3) / (2.0f * (x3 * y2 - x2 * y3));
			centerY = ((x3 * x3 + y3 * y3) * x2 - (x2 * x2 + y2 * y2) * x3) / (2.0f * (y3 * x2 - y2 * x3));

			radius = (float) Math.sqrt(centerX * centerX + centerY * centerY);

			/**
			 * ????????§?¨???????????????????
			 */
			centerX += x1;
			centerY += y1;
		}

		public float getCenterX() {
			return centerX;
		}

		public float getCenterY() {
			return centerY;
		}

		public float getRadius() {
			return radius;
		}
	}

}

Measured memory_bytes: 24704
N = int(input())
A = list(map(int,input().split()))
odd = 0
even2 = 0
even4 = 0
for i in A :
    if not i % 4 :
        even4 += 1
    elif not i % 2 :
        even2 += 1
    else :
        odd += 1
#print(odd,even2,even4)
if (odd <= even4) or (N//2 <= even4) :
    ans = "Yes"
else :
    ans = "No"

print(ans)


Measured memory_bytes: 15020
#include<iostream>
using namespace std;
int main(){
  int a,s1,s2,s3;
  int n=0;
  cin>>a;
  s1 = a/100;
  s2 = (a-s1*100)/10;
  s3 = a-s1*100-s2*10;
  if(s1==1) n++;
  if(s2==1) n++;
  if(s3==1) n++;
  cout<<n<<endl;
  return 0;
}

  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

// A = B * C <-> A % N = (B % N) * (C % N) % N 
// A = B + C <-> A % N = (B % N) + (C % N) % N

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

    boost::dynamic_bitset<> X;
    //string X;
    cin >> X;
    
    // pre cal
    u64 bcnt = X.count();
    u64 bcnt_p = bcnt + 1;
    u64 bcnt_m = (bcnt > 1) ? bcnt - 1 : 1;
    vector<u64> mod_p(N, 1);
    vector<u64> mod_m(N, 1); 
    u64 pre_ans_p = 0;
    u64 pre_ans_m = 0;
    for(u64 i=0; i<N; i++) {
        mod_p[i] = (i > 0) ? mod_p[i-1] * 2 % bcnt_p : 1 % bcnt_p;
        mod_m[i] = (i > 0) ? mod_m[i-1] * 2 % bcnt_m : 1 % bcnt_m;
        if(X[i]) {
            pre_ans_p = (pre_ans_p + mod_p[i]) % bcnt_p;
            pre_ans_m = (pre_ans_m + mod_m[i]) % bcnt_m;
        }
    }

    for(s64 i=N-1; i>=0; i--) {
        boost::dynamic_bitset<> Xi = X;
        Xi.flip(i);

        // all 0
        if(Xi.none()) {
            cout << 0 << endl;
            continue;
        }

        // firstly
        u64 val;
        if(Xi[i]) {
            val = (pre_ans_p + mod_p[i]) % bcnt_p;
        } else {
            val = (pre_ans_m >= mod_m[i]) ? (pre_ans_m - mod_m[i]) % bcnt_m : (pre_ans_m + bcnt_m - mod_m[i]);;
        }

        // secondly
        u64 ans = 1;
        while(val > 0) {
            ans++;
            u64 nxt = val;
            u64 mod = 0;
            while(val > 0) {
                mod += val & 1;
                val /= 2;
            }
            val = nxt % mod;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 6384
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

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



signed main(){
	ll n,m,ans = 0;
	cin >> n >> m;
	P p[n];
	
	rep(i,0,n){
		ll a,b;
		cin >> a >> b;
		p[i].fs = a;
		p[i].sc = b;
	}
	
	sort(p,p+n);
	
	ll i = 0;
	while(m){
		
		ans += min(m,p[i].sc)*p[i].fs;
		m = max((ll)0,m - p[i].sc);
		
		i++;
	}
	
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int x, a, b; cin >> x >> a >> b;
    x -= a;

    cout << x %b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s; cin >>s;
  string t[7]={"SAT","FRI","THU","WED","TUE","MON","SUN"};
  for(int i=0;i<7;i++) if(s==t[i]) cout<<i+1<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int i,n,count=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        if(i%2==0 && a[i]%2==1) count++;
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 1712
#include <algorithm>
#include <iostream>
#include <stdio.h>

typedef long long ll;

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  if (N > M) {
    swap(N, M);
  }
  ll res = 0;
  if (M == 1) {
    res = 1;
  } else if (N == 2 || M == 2) {
    res = 0;
  } else if (N == 1) {
    res = M - 2;
  } else {
    res = (ll)(N - 2) * (M - 2);
  }
  printf("%lld\n", res);
}

Measured memory_bytes: 3160
#include <iostream>
#include <cmath>
#include <utility>
#include <vector>

using namespace std;
int main (){
    int n;
    cin >> n;
    vector<pair<int,bool>> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i].first;
        a[i].second=false;
    }
    int index=1;
    int count=1;
    while(a[index-1].first!=2){
        if(a[index-1].second!=true){
            a[index-1].second=true;
            index=a[index-1].first;
            count++;
        }
        else{
            count =-1;
            break;
        };
    }
    cout << count << "\n";
}

Measured memory_bytes: 1024
from math import sqrt

def judge(a,b):
    s = 0
    for i in range(len(a)):
        s+=(a[i]-b[i])**2
    q = sqrt(s)
    return q.is_integer()


n,d = map(int,input().split())
x = []

for i in range(n):
    p = list(map(int,input().split()))
    x.append(p)

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans += judge(x[i],x[j])
    
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i, n) for (ll i = 1; i < (int)(n); i++)
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
#define PI 3.14159265358979
//#define rep(i,init,n) for(ll i=init;i<=n;++i)
using P = pair<ll , ll>;
using map = map<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main(){
    string t;
    cin >> t;
    rep(i, t.size()){
        if(t.at(i) == '?'){
            if(i == t.size()-1) {
                t.at(i) = 'D';
                break;
            }
            if(t.at(i-1) == 'P') t.at(i) = 'D';
            else t.at(i) = 'D';
        }
    }

    if(t.at(0) == '?') t.at(0) = 'D';

    cout << t << endl;

    return 0;
}

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

int main() {
    char N[200010];
    scanf("%s", N);
    
    int len = strlen(N);
    int sum = 0;
    for (int i = 0; i < len; i++) {
        sum += (N[i] - '0');
    }
    if (sum % 9 == 0) {
        printf("%s\n", "Yes");
    } else {
        printf("%s\n", "No");
    }
}

Measured memory_bytes: 3752
import numpy as np 

class union_find:
	def __init__(self, size):
		# 負の値はルート (集合の代表) で集合の個数
		# 正の値は次の要素を表す
		self.size=size
		self.table = [-(i+1) for i in range(size)]
		self.num=[0 for i in range(size)]

	# 集合の代表を求める O(log(n))
	def find(self, x):
		if self.table[x] < 0:
			self.size+=-1
			return(x)
		else:
			# 経路の圧縮 木の高さ=2
			self.table[x] = self.find(self.table[x])
			return(self.table[x])

	# 併合 O(log(n))
	def unite(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] <= self.table[s2]:
				# 小さいほうが個数が多い
				self.table[s1] += self.table[s2]
				self.table[s2] = s1
			else:
				self.table[s2] += self.table[s1]
				self.table[s1] = s2
			return(True)
		return(False)

	# チェック
	def same(self, x, y):
		if self.find(x)==self.find(y):
			return(True)
		else:
			return(False)

	# 確定 O(nlog(n))
	def definite(self):
		for i in range(self.size):
			self.num[i]=self.find(i)
		return(True)


N = int(input())
xl,yl = [], []
for i in range(N):
	x,y = map(int,input().split())
	xl.append(x)
	yl.append(y)

edge = []

argxl = np.argsort(xl)
argyl = np.argsort(yl)
soxl = np.sort(xl)
soyl = np.sort(yl)

for i in range(N-1):
	edge.append((soxl[i+1]-soxl[i], argxl[i], argxl[i+1]))
	edge.append((soyl[i+1]-soyl[i], argyl[i], argyl[i+1]))

edge.sort(key=lambda x:x[0])

uni = union_find(N)
res = 0
for dis, i, j in edge:
	if not uni.same(i,j):
		uni.unite(i,j)
		res += dis

print(res)












Measured memory_bytes: 64352
#include<vector>
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<deque>
#define ll long long
using namespace std;
#define BUF_SIZE 1048576
char _buf[BUF_SIZE],*_is=_buf,*_it=_buf;
inline char rdc(){
	if (_is==_it) _it=(_is=_buf)+fread(_buf,1,BUF_SIZE,stdin);
	return *_is++;
}
inline void rdi(int &x){
	int f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	if(f) x=-x;
}
inline void rdi(ll &x){
	ll f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	if(f) x=-x;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(int x){
	write(x);
	putchar(' ');
}
inline void print(int x){
	write(x);
	putchar('\n');
}
inline void write(ll x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(ll x){
	write(x);
	putchar(' ');
}
inline void print(ll x){
	write(x);
	putchar('\n');
}
#define int ll
int res,n,d;
int a[200005];
int dpl[200005],dpr[200005]; 
signed main(){
	rdi(n),rdi(d);
	int i,j;
	for(i=0;i<n;++i) rdi(a[i]),res+=a[i];
	res+=(n-1)*d;
	dpr[0]=a[0];
	for(i=1;i<n;++i) dpr[i]=min(a[i],dpr[i-1]+d);
	dpl[n-1]=a[n-1];
	for(i=n-2;~i;--i) dpl[i]=min(a[i],dpl[i+1]+d);
	for(i=1;i<n-1;++i) res+=min(dpl[i],dpr[i]);
	print(res);
	return 0;
}

Measured memory_bytes: 5888
N, Q = map(int, input().split())
S = input()
lr = [tuple(map(int, input().split())) for i in range(Q)]

s = [0]*(N)
for i in range(1, N):
    s[i] = s[i-1]
    if S[i-1:i+1] == 'AC':
        s[i] += 1


for l, r in lr:
    l -= 1
    r -= 1
    if S[l] == 'C':
        print(s[r] - s[l])
    else:
        print(s[r] - s[max(0, l - 1)])


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;
	
	vector<ll> a;
	vector<ll> s;
	for(int i=0; i<n; i++){
		ll t;
		cin >> t;
		a.pb(t);
		if(s.size() > 0){
			s.pb(s[s.size()-1] + t);
		}else{
			s.pb(t);
		}
	}

	ll ans = INF;
	for(int i=0; i<n-1; i++){
		ans = min(abs(s[n-1] - 2*s[i]), ans);
	}

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


Measured memory_bytes: 3564
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int compare_int(const void *a, const void *b)
{
    return *(int *)b - *(int *)a;
}

int main(void)
{
    long ans = 0;
    int n, k, h[200001];

    scanf("%d%d", &n, &k);
    rep(i, n)
        scanf("%d", &h[i]);

    qsort(h, n, sizeof(int), compare_int);

    for (int i = k; i < n; i++)
        ans += h[i];

    printf("%ld\n", ans);

    return 0;
}

Measured memory_bytes: 1788
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

P = (A1 - B1) * T1
Q = (A2 - B2) * T2
if P > 0:
	P *= -1
	Q *= -1

if P + Q < 0:
	print(0)
elif P + Q == 0:
	print("infinity")
else:
	S = (-P) // (P + Q)
	T = (-P) % (P + Q)
	if T != 0:
		print(S * 2 + 1)
	else:
		print(S * 2)


Measured memory_bytes: 38496
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template <class T> void read(T &);
template <class T> void write(const T &);

typedef long long ll;
typedef unsigned long long ull;
typedef const long long &cll;
typedef const int &ci;
typedef std::pair<int, int> pii;
const int iinf = 2147483647;
const ll llinf = 9223372036854775807ll;
using std::abs;
using std::max;
using std::min;

int main() {
  int a;
  read(a);
  write(a ^ 1), EL;
  return 0;
}

template <class T> inline void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!isNum(ch)) {
    if (ch == '-') {
      flag = -1;
    }
    ch = getchar();
  }
  while (isNum(ch)) {
    k = (k << 1) + (k << 3) + ch - '0';
    ch = getchar();
  }
  Re = flag * k;
}
template <class T> inline void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-');
    write(-Wr);
  } else {
    if (Wr < 10) {
      putchar(Wr + '0');
    } else {
      write(Wr / 10);
      putchar((Wr % 10) + '0');
    }
  }
}


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

int main()
{
    int n;
    std::cin >> n;
    
    std::vector<int> a;
    for (int i = 0; i < n; i++)
    {
        int temp;
        std::cin >> temp;
        a.push_back(temp);
    }

    while(a.size() > 1){
        std::sort(a.begin(),a.end());
        std::vector<int> result;
        result.push_back(a[0]);
        for (int i = 1; i < a.size(); i++)
        {
            if (a[i] % a[0])
            {
                result.push_back(a[i] % a[0]);
            }
        }
        a = result;
    }
    std::cout << a[0] << std::endl;
    return 0;
}


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

using namespace std;

int main() {
    int A, B, C;
    cin >> A, cin >> B, cin >> C;
    int minV = min(A, B);
    int maxV = max(A, B);
    cout << (minV <= C && C <= maxV ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e5 +15;
pair < ll , ll > p[N];
ll n;
int main()
{
    cin >> n;
    for ( ll i = 1; i <= n; i ++ )
    {
        cin >> p[i].first;
        p[i].second= i;
    }
    sort ( p + 1 , p + 1 + n);
    for ( ll i = 1; i <= n; i ++ )
    {
        cout << p[p[i].first].second << " ";
    }
}


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

int main() {
	long long int sum = 0, max = -1000000, min = 1000000, a[100000],n, i, j, k, l;
	cin >> n;
	for (i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (j = 1; j <= n; j++) {
		sum += a[j];
	}
	for (k = 1; k <= n; k++) {
		if (max < a[k]) {
			max = a[k];
		}
	}

	for (l = 1; l <= n; l++) {
		if (min > a[l]) {
			min = a[l];
		}
	}
	cout << min << " " << max << " " << sum << endl;

}


Measured memory_bytes: 3156
#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++)

int main() {
  int n,q;
  cin >>n>>q;
  vector<int> a(n-1),b(n-1);
  vector<int>t[n],c(n);

  rep(i,n-1) {
    cin>>a.at(i)>>b.at(i);
    a.at(i)--;
    b.at(i)--;
    t[b.at(i)].push_back(a.at(i));
    t[a.at(i)].push_back(b.at(i));
  }
  vector<int>p(q),x(q);
  rep(i,q){
    cin>>p.at(i)>>x.at(i);
    p.at(i)--;
    c[p.at(i)]+=x.at(i);
  }
  vector<int>ans(n);
  queue<int>que;
  que.push(0);
  ans.at(0)=c.at(0);
  vector<bool>v(n,false);
  v.at(0)=true;
  while(!que.empty()){
    int p=que.front();que.pop();
    rep(j,t[p].size()){
      if(!v.at(t[p].at(j))){
        que.push(t[p].at(j));
        ans.at(t[p].at(j))=ans.at(p)+c.at(t[p].at(j));
        v.at(t[p].at(j))=true;
      }
    }
  }
  
  rep(i,n){
    printf("%ld%c",ans[i],' ');
  }
}



Measured memory_bytes: 20516
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int a;
	cin >> a;
	cout << a / 3 << endl;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
N = int(input())

#N以下で先頭と末尾がkのやつ
TTS = [1,1,10,100,1000,10000,100000]
TTW = [0,1,10,100,1000,10000,100000]
def ttk(N,k):
    c = 0
    Nd = len(str(N))
    #print("Nd",Nd)
    for i in range(Nd-1):
        #print(TTS[i])
        c += TTS[i]
    if Nd >= 3:
        for i in range(10**(Nd-2)):
            a = int(str(k) + (Nd-2-len(str(i)))*"0" + str(i) + str(k))
            #print("a=",a)
            if a <= N:
                c += 1
            else:
                break
    elif Nd == 2:
        a = int(str(k)*2)
        if a <= N:
            c += 1
    elif Nd == 1:
        a = k
        if a <= N:
            c += 1
    return c

#(i)先頭末尾が同じもの
"""
y = 0
for i in range(1,10):
    y += ttk(N,i)**2
print(y)
"""


def ttpq(N,p,q):
    c = 0
    Nd = len(str(N))
    #print("Nd",Nd)
    for i in range(Nd-1):
        #print(TTW[i])
        c += TTW[i]
    if Nd >= 3:
        for i in range(10**(Nd-2)):
            a = int(str(p) + (Nd-2-len(str(i)))*"0" + str(i) + str(q))
            #print(a)
            if a <= N:
                c += 1
            else:
                break
    elif Nd == 2:
        a = int(str(p)+str(q))
        if a <= N:
            c += 1
    elif Nd == 1:
        c = 0
    return c
#(ii)先頭末尾が違うもの

y=0
for i in range(1,10):
    for j in range(i,10):
        # print("i:{},j,{}".format(i,j))
        if i == j:
            # print("   added",ttk(N,i)**2)
            y += ttk(N,i)**2
        else:
            # print("   added",ttpq(N,i,j)**2)
            y += ttpq(N,i,j)*ttpq(N,j,i)*2
        # print(y)
print(y)



Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];

    for(int i = 1; i < n-1; ++i){
        if((p[i-1]-p[i])*(p[i+1]-p[i]) < 0){
            ++ans;
        }
    }

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


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define N 110
#define INF 0x3f3f3f3f
using namespace std;
typedef struct {
    int w;
    int s;
    int e;
}Edge;
Edge edge[N*N];
int m[N][N];
int father[N];
int n;
int k = 0;  //edge的下标
int result = 0;
int findfather(int x){
    return x == father[x] ? x : findfather(father[x]);
}
int cmp(Edge a, Edge b){
    return a.w < b.w;
}
void Kruscal(){
    for(int u = 0; u < k; u++){
        int s = edge[u].s;
        int e = edge[u].e;
        if(findfather(s) != findfather(e)){
            father[findfather(e)] = s;
            result += edge[u].w;
        }
    }
    printf("%d\n", result);
}
int main(){

    scanf("%d", &n);
    for(int i = 1; i <= n; i++) father[i] = i;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            int b;
            scanf("%d", &b);
            m[i][j] = b;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n ;j++){
            if(m[i][j] != -1) {
                edge[k].w = m[i][j];
                edge[k].s = i;
                edge[k].e = j;
                k++;
            }
        }
    }
    sort(edge, edge+k, cmp);
    Kruscal();
    return 0;
}



Measured memory_bytes: 3356
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool vis[10005]={false};
int a[105],n;

int main()
{
	int i,sum=0;
	cin>>n;
	for(i=0;i<n;i++)
        {cin>>a[i];
        sum = sum +a[i];
        }
        sort(a,a+n);
        if(sum%10==0)
        {i=0;
            while(i<n)
            {
                if(a[i]%10!=0)
                    break;
            i++;
            }
        if(i!=n)
            sum = sum-a[i];
        else
            sum=0;
        }
        cout<<sum;


return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <cstring>
#include <sstream>
#include <stdlib.h>

using namespace std;

int main (void)
{
	for (int u = 0; u < 5; u++)
	{
		int co = 0;
		int a = 0;
		cin >> a;
		if (a == 0)
		{
			break;
		}

		int o = 0;
		o = 1000 - a;
        for (int i = 0; i < 100; i++)
        {
	        if (o == 0)
	        {
		        break;
	        }
	        if (o >= 500)
		    {
			    co++;
			    o -= 500;
		    }
		    else if (o >= 100)
		    {
			    co++;
			    o -= 100;
		    }
		    else if (o >= 50)
		    {
			    co++;
			    o -= 50;
		    }
		    else if (o >= 10)
		    {
			    co++;
			    o -= 10;
		    }
		    else if (o >= 5)
		    {
			    co++;
			    o -= 5;
		    }
		    else if (o >= 1)
		    {
			    co++;
			    o -= 1;
		    }
        }
		cout << co << endl;
	}
}



Measured memory_bytes: 3040
inf = 10 ** 15
mod = 10 ** 9 + 7
n,k = map(int, input().split())
tmp = n//k
ans = (tmp*tmp*tmp)
if k % 2 == 1:
    print(ans)
if k % 2 == 0:
    tmp = (2*n+k)//(2*k)
    ans += (tmp*tmp*tmp)
    print(ans)

Measured memory_bytes: 38384
#%%
n = int(input())
x, y = [0] * n, [0] * n
for i in range(n):
    x[i], y[i] = map(float, input().split())

dis = [[0]*n for _ in range(n)] 
ans = 0

for i in range(n):
    for j in range(n):
        tmp = (x[i] - x[j])**2 + (y[i] - y[j])**2
        tmp = tmp**(1/2)
        dis[i][j] = tmp
        if i != j :
            ans += tmp

#print(dis)
#print(ans)
#print(ans/(n*(n-1)))
print(ans/n)

Measured memory_bytes: 3188
#include<stdio.h>

int main(){
  char s[200001],t[200001];
  int i,count=0;
  
  scanf("%s",s);
  scanf("%s",t);

  for(i=0;s[i] != '\0';i++){
    if(s[i] != t[i])
      count++;
  }
  printf("%d",count);
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod=1e9+7;

int main(){
  int n,m;cin>>n>>m;
  int reached[n]={};
  VI G[n];
  int a,b;
  rep(i,m){
    cin>>a>>b;
    G[--a].push_back(--b);
    G[b].push_back(a);
  }
  reached[a]=reached[b]=1;
  VI p;
  p.push_back(a);
  int cur=a;
  while(true){
    bool isC=0;
    for(auto v:G[cur]){
      if(reached[v])continue;
      reached[v]=1;
      isC=1;p.push_back(v);
      cur=v;break;
    }
    if(!isC)break;
  }
  reverse(all(p));
  p.push_back(b);
  cur=b;
  while(true){
    bool isC=0;
    for(auto v:G[cur]){
      if(reached[v])continue;
      reached[v]=1;
      isC=1;p.push_back(v);
      cur=v;break;
    }
    if(!isC)break;
  }
  cout<<(int)p.size()<<endl;
  rep(i,p.size()){
    cout<<p[i]+1<<endl;
  }
}


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

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> target;
	int tmp;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		target.emplace_back(tmp);
	}
	for (int i = 0; i < n;i++){
		for (int j = 0; j < i; j++) {
			if (target[i] < target[j])swap(target[i], target[j]);
		}
		for (int j = 0; j < n - 1; j++) {
			cout << target[j] << " ";
		}
		cout << target[n-1] << endl;
	}
}

Measured memory_bytes: 1212
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

void call(int n)
{
	int i = 1;
	int x;

	do {
		x = i;
		if (x % 3 == 0) {
			printf(" %d", i);
		}
		else {
			do {
				if (x % 10 == 3) {
					printf(" %d", i);
					x = 0;
				}
				else x /= 10;
			} while (x);
		}
	} while (++i <= n);
	putchar('\n');
}

#if 1
int main()
{
	int n;

	scanf("%d", &n);
	call(n);
	return 0;
}
#endif



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int d, t, s;
    cin>>d>>t>>s;
    int r = (d+s-1)/s;
    if(r<=t)cout<<"Yes\n";
    else cout<<"No\n";
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

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

using namespace std;

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


int main() {
  int n,m;
    cin>>n>>m;
    int g=gcd(n,m);
    cout<<(long long int)(n/g)*m;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
int k;
ll mx,mi,a[100010];
int main()
{
	scanf("%d",&k);
	for(int i=1;i<=k;i++)
		scanf("%lld",&a[i]);
	if(a[k]!=2) {puts("-1");return 0;}	
	mx=mi=2;
	for(int i=k;i>1;i--)
	{
		if(mi%a[i-1]!=0&&a[i-1]-mi%a[i-1]-a[i]>=0) mi+=a[i]*((a[i-1]-mi%a[i-1]-a[i])/(a[i]%a[i-1])+1);
		if(mi%a[i-1]!=0)mi+=a[i-1]-mi%a[i-1];	
		mx+=(a[i]-1);
		if(mx%a[i-1]-a[i]>=0) mx-=((mx%a[i-1]-a[i])/(a[i]%a[i-1])+1)*a[i];
		mx-=mx%a[i-1];

		if(mi>mx) {puts("-1");return 0;}
	}
	mx+=(a[1]-1);
	printf("%lld %lld",mi,mx);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

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

  vector<int> num(N+1);
  for(int i = 0;i < M;i++) {
    int a,b;
    cin >> a >> b;
    num.at(a)++;
    num.at(b)++;
  }

  for(int i = 1;i <= N;i++) {
    if(num.at(i) % 2 != 0) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
}

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

using i64 = int64_t;

constexpr i64 MOD = 1e9+7;

int main(){
    string s;
    cin >> s;
    vector<vector<i64>> dp(s.size()+1, vector<i64>(13, 0));
    dp[0][0] = 1;
    for(int i=0;i<(int)s.size();++i){
        for(int j=0;j<13;++j){
            if(s[i] == '?'){
                for(int k=0;k<=9;++k){
                    dp[i+1][(10*j+k)%13] += dp[i][j];
                    dp[i+1][(10*j+k)%13] %= MOD;
                }
            }else{
                dp[i+1][(10*j+(s[i]-'0'))%13] += dp[i][j];
                dp[i+1][(10*j+(s[i]-'0'))%13] %= MOD;
            }
        }
    }

    cout << dp[(int)s.size()][5] << endl;

    return 0;
}


Measured memory_bytes: 13696
def increment(digits)
  incrementable = [10, *digits].reverse_each.each_cons(2).find_index { |a, b| a <= b && a < 9 }
  if incrementable
    return [
      *digits[0...-incrementable - 1],
      digits[-incrementable - 1] + 1,
      *incrementable.times.map { |n|
        [digits[-incrementable - 1] - n, 0].max
      }
    ]
  end

  [1] + [0] * digits.size
end

k = gets.to_i

if k <= 9
  puts k
  exit
end

k -= 10
digits = [1, 0]

k.times { digits = increment(digits) }
puts digits.join

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

int main()
{
    long long N;
    long long K;

    cin >> N >> K;

    long long ans1 = 0;
    long long ans2 = 0;

    //Nの方が大きい場合
    if (N > K)
    {
        ans1 = N - floor(N / K) * K;
        ans1 = N%K;
        ans2 = K - ans1;
        if (ans1 < ans2)
        {
            cout << ans1 << endl;
            return 0;
        }

        cout << ans2 << endl;
        return 0;
    }

    //Nの方が小さい場合
    //何もしない場合
    ans1 = N;

    ans2 = K - N;

    if (ans1 < ans2)
    {
        cout << ans1 << endl;
        return 0;
    }
    cout << ans2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
 int A,B,C,ans = 3;
  cin >> A >> B >> C;
  if(A == B){
    if(B == C){
      cout << 1 << endl;
    }else{
      cout << 2 << endl;
    }
  }else{
    if(A == C || B == C){
      cout << 2 << endl;
    }else{
      cout << 3 << endl;
    }
  }
}

Measured memory_bytes: 256
import collections,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
A = sorted(LI())
counter_A = collections.Counter(A)
sequence = [0]*(10**6+1)
ans = 0
for k,v in counter_A.items():
    if sequence[k]==1:
        continue
    if v==1:
        ans += 1
    for i in range(k,10**6+1,k):
        sequence[i] = 1
print(ans)


Measured memory_bytes: 39912
import scala.io.StdIn

import scala.annotation.tailrec

object Main extends App {

  @tailrec
  def gdc(x:Long, y:Long):Long = {
    if(y == 0) x
    else gdc(y, x % y)
  }

  def lcm(ex:Long, ey:Long):Long = {
    val x = if(ex >= ey) ex else ey
    val y = if(ex >= ey) ey else ex
    x * (y / gdc(x, y))
  }

  val n = StdIn.readInt
  val ans = Iterator.continually(StdIn.readLine.toLong)
    .take(n)
    ./:(1L)(lcm(_,_))

  println(ans)
}

Measured memory_bytes: 27340
#include<stdio.h>
#include<string.h>

int main(){
	char string[15];
	char hasil[15];
	scanf("%s", string);
	int batas=strlen(string);
	int index=0;
	for(int i=0; i<batas;i++){
		if(string[i]=='B'){
			index--;
			if(index<0){
				index=0;
			}
		}
		else{
			hasil[index++]=string[i];
		}
	}
	hasil[index]='\0';
	printf("%s\n", hasil);
	return 0;
}

Measured memory_bytes: 1636
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int n, m;
vector<int> v[55];
bool f[55];

void dfs(int k){
    for(auto x : v[k]){
        if(!f[x]){
            f[x] = true;
            dfs(x);
        }
    }
}

int main()
{
    cin >> n >> m;
    REP(i, m){
        int a, b;
        cin >> a >> b;
        a--;b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    int ans = 0;
    REP(i, n){
        REP(j, v[i].size()){
            int t = v[i][j];
            v[i].erase(v[i].begin() + j);
            int l, tt;
            REP(l, v[t].size()){
                if(v[t][l] == i){
                    tt = v[t][l];
                    v[t].erase(v[t].begin() + l);
                    break;
                }
            }
            REP(k, n){
                f[k] = false;
            }
            dfs(0);
            int k;
            for(k = 0; k < n; k++){
                if(!f[k])break;
            }
            if(k != n){
                ans++;
            }
            v[i].insert(v[i].begin() + j, t);
            v[t].insert(v[t].begin() + l, tt);
        }
    }

    cout << ans / 2 << endl;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define EPS (1e-7)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX=1e9;
const int MAX_V=10000;

int n;
int main(){
	cin>>n;
	int a[n];
	REP(i,n){
		cin>>a[i];
	}
	sort(a,a+n);
	int res=max(a[0],a[n-1]-a[0]);
	int ans=0;
	for(int i=1;i<n-1;i++){
		if(max(a[i],a[n-1]-a[i])<res){
			res=max(a[i],a[n-1]-a[i]);
			ans=i;
		}
	}
	cout<<a[n-1]<<" "<<a[ans]<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define hoge cout << hoge << endl;
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,sum,ans;
ll a,b,c,d,e,f,g,h,w;
ll x[1000005],y[1000005],z[1000005];
bool flag,dame;
char s[500005];

int main(){	
	cin >> n;
	if(n == 7 || n == 5 || n == 3){
		p("YES");
	}else{
		p("NO");
	}

	return 0;
}

Measured memory_bytes: 25088
#include<iostream>
#include<string>
#include<algorithm>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,cnt=1,sum=0;
	cin>>n;
	int h[n];
	lp2(i,n){
		cin>>h[i];
		if(h[i]==h[i-1]){
			cnt++;
			if(i==n-1){
				sum+=cnt/2;
			}
		}
		else {
			sum+=cnt/2;
			cnt=1;
		}
		//cout<<cnt<<endl;
	}
	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
#include <atcoder/all>
using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    dsu uf(n);
    rep (_, q) {
        int c, u, v; cin >> c >> u >> v;
        if (c == 0) uf.merge(u, v);
        else cout << uf.same(u, v) << "\n";
    }
    return 0;
}

Measured memory_bytes: 4028
taro_p = 0
hana_p = 0
n = gets.strip.to_i

n.times do
	line = gets.strip.split(" ")
	if line[0] > line[1]
		taro_p += 3
	elsif line[0] == line[1]
		taro_p += 1
		hana_p += 1
	else
		hana_p += 3
	end
end
puts "#{taro_p} #{hana_p}"


Measured memory_bytes: 8856