akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;
const LL MAXN = 100000, INF = 1e18, mod = 1e9 + 7;
vector<PLL> g[MAXN];
LL dp[2][MAXN], N, M, S, T, sp[2][MAXN];
void shortest(LL S, LL* dp, LL* sp) {
  priority_queue<PLL, vector<PLL>, greater<PLL>> pq;
  fill(dp, dp + N, INF), fill(sp, sp + N, INF);
  dp[S] = 1;
  sp[S] = 0;
  pq.push({sp[S], S});
  while (pq.size()) {
    auto P = pq.top(); pq.pop();
    LL cur = P.first, v = P.second;
    if (cur != sp[v]) continue;
    for (PLL Q: g[v]) {
      LL d = Q.second, u = Q.first;
      if (d + cur == sp[u]) dp[u] = (dp[u] + dp[v]) % mod;
      else if (d + cur < sp[u]) sp[u] = d + cur, dp[u] = dp[v], pq.push({sp[u], u});
    }
  }
}

int main() {
  scanf("%lld%lld", &N, &M);
  scanf("%lld%lld", &S, &T), --S, --T;
  LL v, u, d;
  for (int i = 0; i < M; ++i)
    scanf("%lld%lld%lld", &v, &u, &d), --u, --v, 
    g[u].push_back({v, d}), g[v].push_back({u, d});
  shortest(S, dp[0], sp[0]), shortest(T, dp[1], sp[1]);
  LL D = sp[0][T], ans = dp[0][T] * dp[0][T] % mod;
  assert(dp[0][T] == dp[1][S]);
  auto sq = [=](LL x){x %= mod; return x * x % mod;};
  for (int i = 0; i < N; ++i) if (sp[0][i] * 2 == D and sp[1][i] * 2 == D) 
    ans = (ans - sq(dp[0][i] * dp[1][i])) % mod;
  for (int v = 0; v < N; ++v) for (PLL P: g[v]) {
    LL u = P.first, dis = P.second;
    if (sp[0][u] * 2 < D and sp[1][v] * 2 < D and sp[0][u] + sp[1][v] + dis == D)
      ans = (ans - sq(dp[0][u] * dp[1][v])) % mod;
  }
  printf("%lld\n", (ans + mod) % mod);
}


Measured memory_bytes: 19816
/**
*    author:  boutarou
*    created: 14.06.2020 21:07:39
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

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

const double PI = 3.1415926535897932;

int n;
int a[200005];
int used[1000005];
int ans = 0;

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

	cin >> n;
	rep(i, n) {
		cin >> a[i];
		used[a[i]]++;
	}
	rep(i, n) {
		int x = 1;
		used[a[i]]--;
		while (x * x <= a[i]) {
			if (a[i] % x == 0) {
				if (used[x]) goto bou;
				if (used[a[i] / x]) {
					goto bou;
				}
			}
			x++;
		}
		ans++;
	bou:;
		used[a[i]]++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8224
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)
int MOD=1000000000+7;

using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int h,w,n;
    cin>>h>>w>>n;
    int a[11000];
    rep(i,n){
        cin>>a[i];
    }
    int b[h][w];
    int pos=0;
    for(int i=0;i<h*w; ){
        while(a[pos]){
            if((i/w)%2){
                b[i/w][w-1-(i%w)]=pos+1;
            }
            else{
                b[i/w][(i%w)]=pos+1;
            }
            i++;
            a[pos]--;
        }
        pos++;
    }
    rep(i,h){
        rep(j,w){
            cout<<b[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
long long MOD = 1e9 + 7;

long long Ftr(long long x){
    if(x > 1) return ((x % MOD)  * (Ftr(x - 1) % MOD)) % MOD;
    else return 1;
}


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

    long long n, m, ans = 0;
    cin >> n >> m;
    if(abs(n - m) <= 1){
        ans = Ftr(n) % MOD;
        ans *= Ftr(m) % MOD;
        if(n == m) ans = (ans * 2) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

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

const int maxn=1e5+100;

queue <pair<int,int> > Q;
bool vis[maxn][3];
vector <int> g[maxn];
int n,m;
int st,ed;

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int fr,to;
		scanf("%d%d",&fr,&to);
		g[fr].push_back(to);
	}
	scanf("%d%d",&st,&ed);
	Q.push(make_pair(st,0));
	vis[st][0]=1;
	while(!Q.empty()){
		int x=Q.front().first;
		int h=Q.front().second;
		Q.pop();
		if(x==ed&&h%3==0){
			cout<<h/3<<endl;
			return 0;
		}
		h++;
		for(int i=0;i<g[x].size();i++){	
			int to=g[x][i];
			if(!vis[to][h%3]){
				Q.push(make_pair(to,h));
				vis[to][h%3]=1;
			}
		}
	}
	cout<<"-1"<<endl;
	return 0;
}

Measured memory_bytes: 6016
N, A, B = map(int, input().split())

if N == 1:
    if A == B:
        print(1)
    else:
        print(0)
elif A > B:
    print(0)
else:
    mini = A * (N - 1) + B
    maxi = B * (N - 1) + A
    ans = maxi - mini + 1
    print(ans)

Measured memory_bytes: 3060
#include <iostream>
int main () {
    int a,b;
    std::cin >> a >> b;
    int c = a * b;
    int d = c % 2;
    if (d == 0){
        std::cout << "Even" << std::endl;
    }
    else {
        std::cout <<"Odd" << std::endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
int ans[210];
int f(string s){
    return s=="Red";
}

void solve(){
    cin >> n;
    cout << "? ";rep(i,n) cout << i+1 << " ";cout << "" << endl;
    string first;cin >> first;
    int l=0,r=n,lc=f(first),rc=1-f(first);
    while(r-l>1){
        int mid=(l+r)/2;
        cout << "? ";rep(i,n) cout << i+1+mid << " ";cout << "" << endl;
        string s;cin >> s;
        if(f(s)==lc) l=mid;
        else r=mid;
    }
    ans[l]=lc;ans[r+n-1]=rc;
    rep(i,2*n){
        if(l<=i && i<=r+n-1) continue;
        cout << "? " << i+1 << " ";
        rep(j,n-1) cout << l+2+j << " ";cout << "" << endl;
        string s;cin >> s;ans[i]=f(s);
    }
    Rep(i,l+1,r+n){
        cout << "? " << i+1 << " "; 
        rep(j,l) cout << j+1 << " ";Rep(j,r+n,2*n) cout << j+1 << " ";cout << "" << endl;
        string s;cin >> s;ans[i]=f(s);
    }
    cout << "! ";
    rep(i,2*n){
        if(ans[i]) cout << "R";
        else cout << "B";
    }
    cout << "" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 724
using System;
using System.Linq;

namespace EDPC
{
    class A
    {
        static void Main(string[] args)
        {
            // input
            long N = long.Parse(Console.ReadLine());
            long[] h = Console.ReadLine().Split().Select(long.Parse).ToArray();

            //DP table
            long[] DP = new long[N].Select(x => x = int.MaxValue).ToArray();

            // Main
            DP[0] = 0;
            DP[1] = Math.Abs(h[1] - h[0]);
            for (long i = 2; i < N; i++)
            {
                for (long j = 1; j <= 2; j++)
                {
                    DP[i] = Math.Min(DP[i], DP[i - j] + Math.Abs(h[i] - h[i - j]));
                }
            }
            Console.WriteLine(DP[N - 1]);
        }
    }
}


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

int main(){
  int N, T[100], M, P[100], X[100];
  long int resultT = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    resultT += T[i];
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
    cout << resultT - T[P[i] - 1] + X[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int in;
    cin >> in;
    vector<int> list(in);
    for(int i = 0; i < list.size();i++) {
        cin >> list[i];
    }
    for(int r = list.size() - 1; r >= 0;r--) {
        cout << list[r];
        if(r != 0) {
            cout << " ";
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_W (50)
#define MAX_H (50)
#define INF (1000000000)
#define SIZE_BUF (30)

using namespace std;

const int dis[] = {1, 0, -1, 0}, djs[] = {0, 1, 0, -1};
void bellman_ford(char *fields, int H, int W, int i0, int j0, int *distances) {
  // initialize
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      distances[j + i * W] = INF;
    }
  }
  distances[j0 + i0 * W] = 0;

  // calculate shortest path
  for (int k = 0; k < H * W; k++) {
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        for (int d = 0; d < 4; d++) {
          const int i2 = i + dis[d], j2 = j + djs[d];
          if (i2 >= 0 && i2 < H && j2 >= 0 && j2 < W &&
              fields[j2 + i2 * W] == '.') {
            distances[j2 + i2 * W] =
                min(distances[j2 + i2 * W], distances[j + i * W] + 1);
          }
        }
      }
    }
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  int H, W;
  char fields[MAX_H * MAX_W], buf[SIZE_BUF];
  scanf("%d %d", &H, &W);
  fgets(buf, SIZE_BUF, stdin);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      scanf("%c", &fields[j + i * W]);
    }
    fgets(buf, SIZE_BUF, stdin);
  }

  // find shortest path
  int distances[MAX_H * MAX_W];
  bellman_ford(fields, H, W, 0, 0, distances);

  // count the number of white squares
  int count_white = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (fields[j + i * W] == '.') {
        count_white++;
      }
    }
  }

  if (distances[W * H - 1] < INF) {
    printf("%d\n", count_white - distances[W * H - 1] - 1);
  } else {
    printf("-1\n");
  }

  return 0;
}


Measured memory_bytes: 256
n=int(input())
l,d=[],[]
for i in range(n):
    x=int(input())
    if(x%10==0):
        l.append(x)
    else:
        d.append(x)
if(d==[]):
    print(0)
else:
    s=sum(l)+sum(d)
    if(s%10==0):
        print(s-min(d))
    else:
        print(s)


Measured memory_bytes: 62436
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N; cin >> N;
	long long H; cin >> H;
	int A[N], B[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
	}
	sort(A, A + N);
	sort(B, B + N);
	int sword = A[N - 1];
	int damage =0 ;
	int turn = 0;
	bool flag = true;
	int k = N - 1;
	while (flag) {
		if (B[k] >= sword) {
			damage += B[k];
			k--;
			turn++;
		}
		else {
			flag = false;
		}
		if (damage >= H) break;
	}
	if (damage < H) {
		while (damage < H) {
			damage += sword;
			turn++;
		}
	}
	cout << turn << endl;
}

Measured memory_bytes: 1024
import java.util.*

fun main() = Thread(null, ::abc173c, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc173c() {
    val (h, w, k) = readLine()!!.split(' ').map { it.toInt() }
    val grid = (1..h).map { readLine()!!.map { it == '#' }.toBooleanArray() }.toTypedArray()

    var answer = 0

    for (i in 0L until (1L shl h + w)) {
        val bitSet = BitSet.valueOf(longArrayOf(i))
        val currGrid = grid.map { it.copyOf() }
        (0 until h).filter { bitSet[it] }.forEach { h1 -> (0 until w).forEach { currGrid[h1][it] = false } }
        (h until h + w).filter { bitSet[it] }.forEach { w1 -> (0 until h).forEach { currGrid[it][w1 - h] = false } }
        if (currGrid.sumBy { it.count { it } } == k) answer++
    }

    println(answer)
}



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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M,Q;
vector<int> edge [100001];
pair<int,int> node [100001] [11];

int main()
{
	scanf("%d%d",&N,&M);
	FOR(i,0,M){
		int u,v;
		scanf("%d%d",&u,&v);
		edge [u].push_back(v);
		edge [v].push_back(u);
	}
	fill(node [0],node [N + 1],make_pair(0,0));
	scanf("%d",&Q);
	FOR(i,0,Q){
		int v,d,c;
		scanf("%d%d%d",&v,&d,&c);
		chmax(node [v] [d],make_pair(i + 1,c));
	}

	for(int i = 10;i > 0;i--){
		FOR(j,1,N + 1){
			for(const auto& it : edge [j]){
				chmax(node [it] [i - 1],node [j] [i]);
			}
		}
	}

	FOR(i,1,N + 1){
		int color = 0,mx = 0;
		FOR(j,0,11){
			if(mx < node [i] [j].first){
				mx = node [i] [j].first;
				color = node [i] [j].second;
			}
		}
		printf("%d\n",color);
	}

	return 0;
}


Measured memory_bytes: 15096
s = gets.chomp.chars
n = s.size
t = gets.chomp.chars
m = t.size

d = Array.new(n+1) {Array.new(m+1, 0)}
n.times do |i|
    m.times do |j|
        x = d[i][j] + (s[i] == t[j] ? 1 : 0)
        d[i+1][j+1] = [x, d[i][j+1], d[i+1][j]].max
    end
end

ans = ""
i = n
j = m
until i == 0 || j == 0
    if d[i-1][j] == d[i][j]
        i -= 1
    elsif d[i][j-1] == d[i][j]
        j -= 1
    else
        ans += s[i-1]
        i -= 1
        j -= 1
    end
end

puts ans.reverse

Measured memory_bytes: 89040
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() string {
	return scanString(sc)
}

func resolve(s string) int {
	pos := 0
	num := 0
	for i := 0; i < len(s); i++ {
		switch s[i] {
		case '0':
			if pos < 0 {
				num++
			}
			pos++
		case '1':
			if pos > 0 {
				num++
			}
			pos--
		}
	}
	return num << 1
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2088
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long LL;

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

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

    LL ans = 0;
    for (int i = 0; i < N; ++i) {
        int c = min(A[i], B[i]);
        ans += c;
        B[i] -= c;
        c = min(A[i+1], B[i]);
        ans += c;
        A[i+1] -= c;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main () {
	int n;
	cin >> n;
	int result = 0;
	for (int i = 1; i <= n; i+=2)
	{
		int count = 0;
		for (int j = 1; j <= i; ++j)
		{
			if(i % j == 0){
				count++;
			}
		}
		if(count == 8){
			//cout << i << endl;
			result++;
		}
	}
	cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>

using namespace std;

bool evaluatePN(int n) {
	stringstream ss;
	ss << n;
	string str = ss.str();
	string invStr = str;
	reverse(invStr.begin(), invStr.end());

	return (str == invStr);
}

int main() {
	int argA, argB;
	cin >> argA >> argB;

	int ret = 0;
	for (int i = argA; i <= argB; ++i) {
		if (evaluatePN(i)) {
			ret++;
		}
	}

	cout << ret;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,a,b,n,i,j,k,sum=0;
    cin>>n;
    ll A[n];
    for(i=1;i<=n;i++)
        cin>>A[i];
    for(i=2;i<n;i++)
    {
        if((A[i]>A[i-1]&&A[i]<A[i+1])||(A[i]<A[i-1]&&A[i]>A[i+1]))
            sum++;
    }
    cout<<sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  int n,m;cin>>n>>m;
  ll sum = 0;
  rep(i,m){
    int a;cin>>a;
    sum += a;
  }
  if(n - sum < 0){
    cout << -1 << endl;
  }else{
    cout << n-sum << endl;
  }
  return 0;
}

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

using namespace std;

vector<int> K_digit(int N, int K, vector<int> digit){
    int p = N%K;
    int q = N/K;
    if(N < K){
        digit.push_back(N);
        return digit;
    }else{
        digit.push_back(p);
        return K_digit(q, K, digit);
    }
}

int main(){
    

    int N, K;
    cin >> N >> K;
    vector<int> digit = {};
    digit = K_digit(N, K, digit);
    cout << digit.size() << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool isTriangle(int a, int b, int c)
{
    if (a != b && b != c && c != a)
    {
        if (a + b > c && b + c > a && c + a > b)
            return true;
        else
            return false;
    }
    else
        return false;
}
int main()
{
    int n, cnt;
    cin >> n;
    vector<int> l(n);
    cnt = 0;
    for (int i = 0; i < n; i++)
        cin >> l[i];
    for (int x = 0; x < n; x++)
    {
        for (int y = x; y < n; y++)
        {
            for (int z = y; z < n; z++)
            {
                if (isTriangle(l[x], l[y], l[z]))
                    cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int edges[22][33];
void addedge(int f,int t)
{
	edges[f][t]=1;
	edges[t][f]=1;
}
int dfs(int x)
{
	bool mrk=0;
	int ans=0;
	for(int i=1;i<=4;++i)
	{
		if(edges[x][i])
		{
			edges[i][x]=edges[x][i]=0;
			ans=max(dfs(i),ans);
			edges[i][x]=edges[x][i]=1;
			mrk=1;
		}
	}
	if(mrk==0)
	{
		for(int i=0;i<10;++i)
		{
			for(int j=0;j<10;++j)
			{
				if(edges[i][j])
				{
					return 0;
				}
			}
		}return 1;
	}
	return ans;
}
int main()
{
	for(int i=1;i<=3;++i)
	{
		int a,b;
		cin>>a>>b;
		addedge(a,b);
	}
	for(int i=1;i<=3;++i)
	{
		if(dfs(i))
		{
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.Map.Entry;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int y = scn.nextInt();
		int rn = scn.nextInt(), gn = scn.nextInt(), cn = scn.nextInt();
		PriorityQueue<Long> r = new PriorityQueue<>();
		PriorityQueue<Long> g = new PriorityQueue<>();
		PriorityQueue<Long> c = new PriorityQueue<>();

		for (int i = 0; i < rn; i++) {
			long v = scn.nextLong();
			if (i >= x) {
				if (r.peek() < v) {
					r.poll();
					r.add(v);
				}
			} else
				r.add(v);
		}
		for (int i = 0; i < gn; i++) {
			long v = scn.nextLong();
			if (i >= y) {
				if (g.peek() < v) {
					g.poll();
					g.add(v);
				}
			} else
				g.add(v);
		}
		for (int i = 0; i < cn; i++)
			c.add(scn.nextLong());
		PriorityQueue<Long> nc = new PriorityQueue<>(Collections.reverseOrder());
		while (!c.isEmpty())
			nc.add(c.poll());

		while (true) {
			long x1 = r.peek(), y1 = g.peek();
			if (nc.size() == 0 || Math.min(x1, y1) >= nc.peek())
				break;
			if (x1 < y1) {
				if (nc.peek() > x1) {
					r.poll();
					r.add(nc.poll());
				}
			} else {
				if (nc.peek() > y1) {
					g.poll();
					g.add(nc.poll());
				}
			}
		}
		long ans = 0;
		while (!r.isEmpty())
			ans += r.poll();
		while (!g.isEmpty())
			ans += g.poll();
		System.out.println(ans);
	}

	static class pair implements Comparable<pair> {
		int k, v;

		pair(int k, int v) {
			this.k = k;
			this.v = v;
		}

		@Override
		public int compareTo(pair o) {
			return this.v - o.v;
		}
	}

	static class Scanner {

		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

Measured memory_bytes: 63640
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    int N;
    GI(N);
    vector<int> p(N);
    REP(i,N)
        GI(p[i]);
    sort(ALL(p));
    int ans = 0;
    REP(i,N-1)
        ans += p[i];
    ans += p[N-1]/2;
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
 
#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
 int n; cin >> n;
  int t = 0;
  int ans = 0;
  
  for(int j=1;j<=n;j++){
  for(int i=1;i<=j;i++){
    if(j%i == 0 && i%2 == 1){
      t++;
    }
  }
  if(t == 8){
    ans++;
  }
    t=0;
  }
    cout << ans;
  
 return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long long MAX(long long a,long long b){return a<b?b:a;}
long long n,m,i,j,k,a[3][3],d[2][5010*5010]={};
int main(){
  scanf("%lld",&n);
  for(i=0;i<2;i++){
    for(j=0;j<3;j++)scanf("%lld",&a[i][j]);
  }
  for(j=0;j<3;j++)a[2][j]=a[0][j];
  for(k=0;k<2;k++){
    for(i=n;i;i--){
      for(j=0;j<3;j++){
	if(a[k][j]>i)continue;
	d[k][i-a[k][j]]=MAX(d[k][i-a[k][j]],d[k][i]+a[k+1][j]);
      }
    }
    for(i=m=0;i<=n;i++)m=MAX(m,d[k][i]+i);
    n=m;
  }
  printf("%lld\n",n);
  return 0;
}


Measured memory_bytes: 196992
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define pii pair<long long,long long>
#define reset(a,b) memset(a,b,sizeof a)
#define ll long long
#define MOD 1000000009
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define dalam fl<=l && r<=fr
#define kiwo 2*(idx),l,MID
#define tengen 2*idx+1,MID+1,r
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 100003
#define pc(x) putchar_unlocked(x);

long long jaw,a,b,c,x,y;

int main(){
	//freopen("1.in","r",stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>a>>b>>c>>x>>y;
	if(a+b>c*2){
		if(x>y){
			jaw+=(y)*c*2;
			x-=y;
			y=0;
		}
		else{
			jaw+=(x)*c*2;
			y-=x;
			x=0;
		}
	}
	if(c*2<a){
		jaw+=x*c*2,x=0;
	}
	if(c*2<b)
		jaw+=c*y*2,y=0;
	jaw+=x*a;
	jaw+=y*b;
	cout<<jaw<<endl;
}		

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <algorithm>
#include <map>
using namespace std;

typedef long long ll;
const int maxn = 200200;

int main()
{
    int n;
    cin >> n;
    map<string,int> m;
    string s[n + 1];
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        m[s[i]]++;
    }
    vector<pair<int,string>> v;
    for (int i = 0; i < n; i++){
        v.push_back({m[s[i]], s[i]});
    }
    sort(v.begin(),v.end());
    int i = n - 1;
    set<string> ans;
    while(v[i].first == v[i - 1].first && i > 0) {
        ans.insert(v[i].second);
        ans.insert(v[i - 1].second);
        //ans.push_back(v[i - 1].second);
        i--;
    }
    for (string t : ans){
        cout << t << endl;
    }
    return 0;
}





Measured memory_bytes: 39532
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
typedef long long ll;

using namespace std;

int main() {
    ll n;
    cin >> n;
    
    if(n % 2 != 0) {
        cout << 0 << endl;
    }
    else {
        ll ans = 0;
        int cnt = 1;
        for(ll i = 5; i <= n; i *= 5) {
            ans += (n / (i * 2));
        }
        
        cout << ans << endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int ret=0;
vector<int> ne;

void dfs(int key, vector<vector<int>> &t, vector<vector<int>> &x, vector<int> &c, int res){
    if(res==0){
        if(c[key]<0){
            ne.push_back(key);
            c[key]=ret;
        }
    }else{
        for(int i=0; i<t[key].size(); ++i){
            if(x[t[key][i]][res-1]==0){
                x[t[key][i]][res-1]=1;
                dfs(t[key][i], t, x, c, res-1);
            }
            
        }
    }
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> g(N+1);
	for(int i=0; i<M; ++i){
	    int u, v;
	    cin >> u >> v;
	    g[u].push_back(v);
	}
	int s, t;
	cin >> s >> t;
	vector<int> cnt(N+1, -1);
	vector<vector<int>> checked(N+1, vector<int>(4, 0));
	cnt[s]=0;
	ne.push_back(s);
	while(ne.size()>0){
	    ++ret;
	    vector<int> prep;
	    ne.swap(prep);
	    for(int i=0; i<prep.size(); ++i){
	        dfs(prep[i], g, checked, cnt, 3);
	    }
	}
	cout << cnt[t] << endl;
	return 0;
}


Measured memory_bytes: 11520
import java.util.Scanner;

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

		long a = sc.nextLong();
		long b = sc.nextLong();

		long ans = func(a - 1) ^ func(b);

		System.out.println(ans);

		sc.close();
	}

	public static long func(long n) {
		if (n <= 0)
			return 0;
		if (n % 2 == 0) {
			return n ^ (n % 4 == 0 ? 0 : 1);
		} else {
			return (n + 1) % 4 == 0 ? 0 : 1;
		}
	}

}


Measured memory_bytes: 23764
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = []
X = []
for i in range(M):
  p, x = map(int, input().split())
  P.append(p)
  X.append(x)

for i in range(M):
  t = T[:]
  t[P[i]-1] = X[i]
  print(sum(t))


Measured memory_bytes: 3060
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 M = sc.nextInt();
    
    int a[] = new int[A];
    int b[] = new int[B];
    
    int a_min = 100000;
    int b_min = 100000;
 
    int result = 0;

    
    for(int i = 0 ; i < A ; ++i){
      a[i] = sc.nextInt();
      if(a_min > a[i]){
        a_min = a[i];
      } 
    }
    
    for(int i = 0 ; i < B ; ++i){
      b[i] = sc.nextInt();
      if(b_min > b[i]){
        b_min = b[i];
      } 
    }
    //クーポンなし
    int sum = a_min + b_min;
 
    
    for(int i = 0 ; i < M ; ++i){
      result = a[sc.nextInt()-1] + b[sc.nextInt()-1] - (sc.nextInt());
      sum = Math.min(sum,result);
    }

    System.out.println(sum);
 
  }
}

Measured memory_bytes: 60488
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>//辞書順はnext_permutation
#include<set>
#include<string>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<utility>//swap(数値交換)
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define cncn int cnt=0
#define please return
#define AC 0

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　（A＋B）÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


int main(void) {
	int n;
	cin >> n;
	vint p(n);
	rep(i, n)cin >> p[i];
	asas;
	rep(i, n) {
		if (i + 1 != p[i])ans++;
	}
	YES(ans == 2||ans==0);
	please AC;
}

// abc : 141 , aoj : ITP1_6_D
//sort, abs, swap, reverse, max, min
//__gcd, sbstring, erase, push_back,stoll、stoi

Measured memory_bytes: 256
i = STDIN.read.split(" ").map{|a| a.to_i}
x1 = i[0]
y1 = i[1]
x2 = i[2]
y2 = i[3]
x3 = x2 + (y1 - y2)
y3 = y2 - (x1 - x2)
x4 = x3 + (x1 - x2)
y4 = y3 + (y1 - y2)
p x3, y3, x4, y4

Measured memory_bytes: 1788
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,l[2005]={},ans=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> l[i];
  }
  sort(l,l+n);
  for(int i=0; i<n; i++) {
    for(int j=i+1; j<n; j++) {
      int x=l[i],y=l[j];
      int itr=lower_bound(l,l+n,x+y)-l-1;
      ans+=itr-j;
    }
  }
  cout << ans << endl;
}

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

int main(){
  int h,w,k;
  cin >>h >>w >>k;
  string s[h];
  rep(i,h) cin >>s[i];
  int ans = 0;
  rep(is,1<<h)rep(js,1<<w){
    int cnt = 0;
    rep(i,h)rep(j,w){
      if(js>>j&1) continue;
      if(is>>i&1) continue;
      if(s[i][j]=='#') cnt++;
    }
    if(cnt==k) ans++;
  }
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

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

    int C[N-1], S[N-1], F[N-1];
    for(int i = 0; i < N-1; i++)cin >> C[i] >> S[i] >> F[i];

    long ans[N];
    for(int i = 0; i < N; i++)ans[i] = 0;

    for(int i = 0; i < N-1; i++){
        ans[i] = C[i] + S[i];
        for(int j = 0; j < i; j++){
            if(S[i] >= ans[j])ans[j]= ans[i];
            else if((ans[j] - S[i])%F[i] == 0)ans[j] += C[i];
            else ans[j] += C[i] + F[i] - (ans[j] - S[i])%F[i];
        }
    }
    
    for(int i = 0; i < N; i++)cout << ans[i] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	solve(){}
	ll operator()() {
		return 0;
	}
};

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

	for(;;)
	{
		int x;
		cin >> x;
		if(cin.fail()) break;
		bool ans=(x>=30);
		cout << (ans?"Yes":"No") << "\n";
	}
	return 0;
}


Measured memory_bytes: 3636
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

N,K = Ints()

mod = 10**9+7
ans = 0
for i in range(K,N+2):
    ans += (2*N-i+1)*i//2 - (i-1)*i//2 + 1
    ans %= mod
print(ans)

Measured memory_bytes: 63544
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <map>

using namespace std;

int main(void)
{
	int x, a, b;

	cin >> x >> a >> b;

	if (a >= b) {
		cout << "delicious" << endl;
	}
	else if (a < b && (b - a) <= x) {
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}



	return (0);
}

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


int main(){

  int n, s, i;
  double sum, sum2, x;

  while(scanf("%d", &n), n){
    sum=0;
    sum2=0;
    for(i=0;i<n;i++){
      scanf("%d", &s);
      sum+=s;
      sum2+=s*s;
    }

    sum/=n;
    x=sum2/n-sum*sum;

    printf("%f\n", sqrt(x));
  }

  return 0;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef pair<int, lint> pil;
typedef pair<lint, pii> plp;
typedef complex<double> xy_t;
typedef pair<pii, char> ppc;
typedef vector<lint> poly;

const lint mod = 1e9 + 7;
const int INF = mod;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    lint a[n+1];
    rep(i, n+1) a[i] = -1;
    rep(i, n)if((i==0 && s[i]=='<') || (s[i-1]=='>' && s[i]=='<')){
        lint cur = 0;
        For(j, i, n+1){
            a[j] = max(a[j], cur++);
            if(j < n && s[j] == '>') break;
        }
    }
    rFor(i, n+1, 1)if((i==n && s[n-1]=='>') || (s[i]=='<' && s[i-1]=='>')){
        lint cur = 0;
        rFor(j, i+1, 0){
            a[j] = max(a[j], cur++);
            if(j > 0 && s[j-1] == '<') break;
        }
    }

    lint ans = 0;
    rep(i, n+1) ans += a[i];
    printf("%lld\n", ans);
}

Measured memory_bytes: 4740
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	xs := make([]int, n)
	ys := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&xs[i], &ys[i])
	}

	var total float64
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i != j {
				d1 := xs[i] - xs[j]
				d2 := ys[i] - ys[j]
				d := math.Sqrt(float64(d1*d1 + d2*d2))
				total += d
			}
		}
	}

	avg := total / float64(n)
	fmt.Print(avg)
}

//
//func factorial(n int) int {
//	if n <= 1 {
//		return 1
//	}
//	return n * factorial(n-1)
//}


Measured memory_bytes: 512
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"

	"sort"
	"strconv"
	"strings"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}

func NewConsole() Console {
	return Console{bufio.NewWriter(os.Stdout)}
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}

func PrintList(list []int) {
	con := NewConsole()
	defer con.Flush()
	for i := range list {
		if i == 0 {
			con.Printf("%d", list[i])
		} else {
			con.Printf(" %d", list[i])
		}
	}
	con.Println("")
}

func main() {
	con := NewConsole()
	defer con.Flush()

	m := make(map[int]struct{})
	lines, _ := ReadLongLines(4)
	a := strings.Split(lines[1], " ")
	for i := range a {
		n, _ := strconv.Atoi(a[i])
		m[n] = struct{}{}
	}

	result := make([]int, 0, 200000)
	b := strings.Split(lines[3], " ")
	for i := range b {
		n, _ := strconv.Atoi(b[i])
		if _, ok := m[n]; ok {
			delete(m, n)
		}
	}
	for k, _ := range m {
		result = append(result, k)
	}
	sort.Slice(result, func(lhs, rhs int) bool {
		return result[lhs] < result[rhs]
	})
	for j := range result {
		con.Printf("%d\n", result[j])
	}
}



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

using namespace std;

int n;
string s;
long long a = 0, b = 0, c = 0, d = 0, e = 0;
long long cc = 0;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		cin >> s;
		if (s[0] == 'M') {
			a++;
		} else if (s[0] == 'A') {
			b++;
		} else if (s[0] == 'R') {
			c++;
		} else if (s[0] == 'C') {
			d++;
		} else if (s[0] == 'H') {
			e++;
		}
	}
	cc += a * b * (c + d + e);
	cc += a * c * (d + e);
	cc += a * d * e;
	cc += b * c * (d + e);
	cc += b * d * e;
	cc += c * d * e;
	printf("%lld", cc);
	return 0;
}

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

int main(){
  int n, k, h[100005];
  cin >> n >> k;
  
  for ( int i = 0; i < n; i++ ){
    cin >> h[i];
  }
  
  sort(h, h + n);
  
  int ans = 1e9;
  
  for(int i = 0; i < n - k + 1; i++ ){
    ans = min(ans, h[i + k - 1] - h[i]);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 640
info=gets.chomp.split(" ").map(&:to_i)
def cal(a,b,x)
	num1=a/x
	if a % x==0
		num1-=1
	end
	num2=b/x
	return num2-num1
end
num1=cal(info[0],info[1],info[2])
num2=cal(info[0],info[1],info[3])
num3=cal(info[0],info[1],info[2].lcm(info[3]))
print((info[1]-info[0]+1)-(num1+num2-num3))

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

int dp[4005][4005];

int main() {
	string s;
	while (cin >> s) {
		string sa;
		cin >> sa;
		for (int i = 0; i < 4003; i++)
			for (int j = 0; j < 4003; j++)dp[i][j] = 0;
		s.push_back('@');
		int ans = 0;
		for (int i = 0; i < s.size(); i++) {
			for (int j = 0; j < sa.size(); j++) {
				int a = s.size();

				if (s[i] == sa[j]) {
				dp[i+1][j + 1] = dp[i][j] + 1;
					ans = max(ans, dp[i+1][j + 1]);
				}
				else {
				dp[i+1][j + 1] = 0;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 65836
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
#define pf(a) push_front(a)
typedef long long ll;
#define MAX_N 100000
vector<int> G[MAX_N+1];
bool flag[MAX_N+1];
int main(){
  int N,M;
  cin >> N >> M;
  REP(i,M){
    int A,B;
    cin >> A >> B;
    G[A].pb(B);
    G[B].pb(A);
  }
  list<int> l;
  l.pb(1);
  flag[1] = true;
  l.pb(G[1][0]);
  flag[G[1][0]] = true;
  while(1){
    int v = l.front();
    bool f = true;
    REP(i,G[v].size()){
      if(! flag[G[v][i]]){
        flag[G[v][i]] = true;
        l.pf(G[v][i]);
        f = false;
        break;
      }
    }
    if(f) break;
  }
  while(1){
    int v = l.back();
    bool f = true;
    REP(i,G[v].size()){
      if(! flag[G[v][i]]){
        flag[G[v][i]] = true;
        l.pb(G[v][i]);
        f = false;
        break;
      }
    }
    if(f) break;
  }
  string ans = "";
  for(auto itr = l.begin();itr != l.end();itr++) ans += to_string(*itr) + " ";
  ans.pop_back();
  cout << l.size() << endl;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10244
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    D, N = map(int, readline().split())

    if N < 100:
        print(N * 100 ** D)
    else:
        print(100 * 100 ** D + 100 ** D)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61936
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
    long A, B;
    cin >> A >> B;
    vector<long> a;
    a.push_back(1);
    vector<long> b;
    b.push_back(1);
    if(A == 1 || B == 1){
        cout << 1 << endl;
    }
    else{
    while(1){
        bool w = false;
        for(long i=2;i<=sqrt(A);i++){
            if(A%i == 0){
                A /= i;
                if(a[a.size()-1] != i) a.push_back(i);
                w = true;
                break;
            }
        }
        if(w==false) {
            if(a[a.size()-1] != A) a.push_back(A);
            break;
        }
    }
    while(1){
        bool w = false;
        for(long i=2;i<=sqrt(B);i++){
            if(B%i == 0){
                B /= i;
                if(b[b.size()-1] != i) b.push_back(i);
                w = true;
                break;
            }
        }
        if(w==false) {
            if(b[b.size()-1] != B) b.push_back(B);
            break;
        }
    }
    long ans=0;
    /*
    for(int i=0;i<a.size();i++){
        cout << a[i] << endl;
    }
    cout << endl;
    for(int i=0;i<b.size();i++){
        cout << b[i] << endl;
    }
    cout << endl;
    */
    for(long i=0;i<a.size();i++){
     for(long j=0;j<b.size();j++){
         if(a[i] == b[j]) {
             ans++;
             break;
         }
     }   
    }
    cout << ans << endl;
    }
}

Measured memory_bytes: 888
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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)*}
    };
}

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:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        s: [chars; 3],
    }
    let mut cost = 0;
    for i in 0..n {
        let mut v = vec![0; 26];
        for j in 0..3 {
            let idx = s[j][i] as usize - 'a' as usize;
            v[idx] += 1;
        }
        let ma = v.iter().max().unwrap();
        cost += 3 - ma;
    }
    puts!("{}\n", cost);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

typedef long long int llint;

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

  int cnt = 700;

  for(int i = 0; i < 3; i++) if(s[i] == 'o') cnt += 100;

  cout<< cnt <<endl;

  return 0;
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int n,r;
    while (cin >> n >> r , n||r) {
        vector<int> a(n);
        REP(i,n) a[i] = n-i;
        REP(i,r) {
            int p,c;
            cin >> p >> c;
            vector<int> temp;
            REP(i,p-1) temp.pb(a[i]);
            a.erase(a.begin(), a.begin()+p-1);
            a.insert(a.begin()+c, ALL(temp));
        }
        cout << a[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 3156