akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

MOD = 10**9 +7

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret *= kaijo(n)
  ret %= MOD;
  ret *= gyaku_kaijo(r)
  ret %= MOD;
  ret *= gyaku_kaijo(n-r)
  ret %= MOD;
  return ret




 
n,k = map(int, input().split())
 
################
#p = 10**9 + 7
#def comb(n,k,p):
#  ans = 1
#  for i in range(1,k+1):
#    ans = ans * (n - (i-1)) % p
#    ans = ans * pow(i, p-2, p)
#  return ans
################
 
if k >= n:
  ans = nCr(2*n-1, n) % MOD
else:
  ans = 0
  for i in range(0,k+1):
    temp = (nCr(n-1, i) % MOD) * (nCr(n, i) % MOD) % MOD
    ans = (ans + temp) % MOD
    
print(ans)


Measured memory_bytes: 67952
// Created by Tanuj Jain
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int INF = 0x3f3f3f3f;
int knight_moves[8][2]={{-2,-1},{-1,-2},{1,-2},{2,-1},{-2,1},{-1,2},{1,2},{2,1}};
int moves[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	//#ifndef ONLINE_JUDGE
	//freopen("inputf.in","r",stdin);
	//freopen("outputf.in","w",stdout);
	//#endif

	int t;
	cin>>t;
	vector<ll>v(t);
	for(int i=0;i<t;i++)
		cin>>v[i];
	sort(v.begin(),v.end());
	ll ans=0;
	for(int i=t/2;i<t;i++)
		 ans+=v[i];
	ans*=2;
	ans-=v[t-1];
	if(t%2!=0)
	{
		ans-=v[t/2];
	}
	cout<<ans;
}	

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

int main() {
    int W , H , x , y , r;
    cin >> W >> H >> x >> y >> r;
    if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n, k; cin >> n >> k;
	VI a(n); REP(i,n) cin >> a[i];
	REP(i,n-k){
		if(a[i]<a[i+k])
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

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

const int MAX = 1e6;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();
    ll n,k;
    cin>>n>>k;
    V a(n);
    rep(i,n){
        cin>>a[i];
        a[i]%=MOD;
    }
    sort(a.begin(),a.end());
    ll ans=0;
    rep(i,n){
        if(i+1>=k){
            ans+=COM(i,k-1)*a[i];
            ans%=MOD;
        }
        if(i+k<=n){
            ans-=COM(n-i-1,k-1)*a[i];
            ans%=MOD;
        }
    }
    ans=(ans+MOD)%MOD;
    cout<<ans<<endl;
}


Measured memory_bytes: 24448
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);
#define asc(A) sort(A.begin(),A.end())
#define dsc(A) sort(A.begin(),A.end(),greater<ll>())
#define input(A,N) for(ll i=0;i<N;i++) cin>>A[i];
int main()
{
    fasino
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    #endif
    ll n;
    cin>>n;
    int A[n][3];
    for(auto &i:A){
        for(auto &j:i){
            cin>>j;
        }
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            int x,y,z;
            if(j==0) 
                x=0;
            else 
                x = A[i-1][0];
            if(j==1) 
                y=0;
            else 
                y = A[i-1][1];
            if(j==2) 
                z=0;
            else 
                z = A[i-1][2];
            
            A[i][j]+=max({x,y,z});
        }
    }
    cout<<max({A[n-1][0],A[n-1][1],A[n-1][2]});
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int a, b, m;
    cin >> a >> b >> m;
    vi ap(a);
    int a_min = INF;
    REP(i, a) {
        cin >> ap[i];
        chmin(a_min, ap[i]);
    }
    vi bp(b);
    int b_min = INF;
    REP(i, b) {
        cin >> bp[i];
        chmin(b_min, bp[i]);
    }
    int ans = a_min + b_min;
    int x, y, c;
    REP(i, m) {
        cin >> x >> y >> c;
        x--; y--;
        chmin(ans, ap[x] + bp[y] - c);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

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

	long long sum = 0;
	for (int i = 1; i <= N; ++i) {
		if (i % 3 != 0 && i % 5 != 0) {
			sum += i;
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3192
list = [x+1 for x in xrange(int(input()))]
tmp = 0
for i in xrange(int(input())):
    ch = [int(x) for x in raw_input().split(",")]
    tmp = list[ch[0]-1]
    list[ch[0]-1] = list[ch[1]-1]
    list[ch[1]-1] = tmp
for x in list:
    print x

Measured memory_bytes: 5012
#include<bits/stdc++.h>
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define F first
#define S second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const int MX=5000;
const ll inf=(1ll<<60);
const ll mod=1e9+7;
ll n,sum,k,ans;
int main(){
    scanf("%lld",&n);
    sum=n*800;
    n/=15;
    k+=n*200;
    printf("%lld\n",sum-k);
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val n = readInt
    val list = for(i <- 1 to n) yield {
      val Array(a,b,_*) = readLine.split(" ")
      (a, b.toInt)
    }

    List("S","H","C","D").flatMap { mark => (1 to 13).map{(mark, _)} }
    .filterNot(list.contains).map{ t => println(t._1+" "+t._2) }
  }
}

Measured memory_bytes: 43984
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRT(v) sort(v.begin(),v.end())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int a,b,c,k;
    cin >> a >> b >> c >>k;
    //処理
    int d = max(max(a,b),c);
    //出力
    cout << a+b+c+d*pow(2,k)-d << ENT;
    return 0;
}

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


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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
lis=[1]*10**6
#A*B
ans=1
for i in range(1,N-1):
    now=i+1
    while now<=10**6:
        lis[now-1]+=1
        
        now+=(i+1)
    ans+=lis[i]
#print(lis[:10])
print(ans)

Measured memory_bytes: 75556
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
    int n,x[100],y[100];
        cin>>n;
        for(int i=0;i<n;i++)
        cin>>x[i];
        for(int i=0;i<n;i++)
        cin>>y[i];
        
        double d[4];
        for(int i=0;i<4;i++)d[i]=0.0;
        
        for (int p=1;p<=3;p++){
            for(int i=0;i<n;i++){
                d[p] +=pow(fabs(x[i]-y[i]),p);
            }
            d[p]=pow(d[p],1.0/p);
        }
        for(int i=0;i<n;i++){
            d[0]=(d[0]<fabs(x[i]-y[i])?fabs(x[i]-y[i]):d[0]);
        }
        printf("%lf\n",d[1]);
        printf("%lf\n",d[2]);
        printf("%lf\n",d[3]);
        printf("%lf\n",d[0]);
    
    return 0;
    
}




Measured memory_bytes: 3328
def prepare(n, mod, x)
  dp = Array.new(n, 1)
  return [0, 0, dp] if mod == 0
  score = 0
  (1 ... n).each do |i|
    dp[i] = (dp[i - 1] * 2) % mod
  end
  (1 .. n).each do |i|
    score += dp[n - i] if x[i - 1] == '1'
  end
  [mod, score, dp]
end

def f(x)
  for i in 0 .. 100
    return i if x == 0
    popcount = 32.times.count{|j| x[j] > 0 }
    x %= popcount
  end
end

N = gets.to_i
X = gets.chomp
popcount = X.count('1')
mod1, score1, dp1 = prepare(N, popcount + 1, X)
mod2, score2, dp2 = prepare(N, popcount - 1, X)

(1 .. N).each do |i|
  if X[i - 1] == '0'
    puts f((score1 + dp1[N - i]) % mod1) + 1
  elsif popcount == 1
    puts 0
  else
    puts f((score2 - dp2[N - i]) % mod2) + 1
  end
end


Measured memory_bytes: 17748
# C
# Skill Up

import itertools
import numpy as np

n, m, x = map(int, input().split())

data_tensor = np.empty((n,m))
c_list = np.empty((n,1))

ans = 100000000
flag = True

for i in range(n):
    _list = list(map(int, input().split()))
    c_list[i], data_tensor[i] = _list[0], _list[1:]
    
buy_tensor = itertools.product([0,1],repeat=n)

for _list in buy_tensor:
    _list_np = np.array(_list)
    _list_np = _list_np.reshape(-1,1)
    _sum_list = np.sum(data_tensor * _list_np, axis=0)
    if np.min(_sum_list) >= x:
        _ans = np.sum(c_list * _list_np)
        if _ans < ans:
            ans = int(_ans)
            flag = False
        
if flag:
    ans = -1

print(ans)

Measured memory_bytes: 27200
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

void solve(){
    int a, b;
    cin >> a>>b; 
    if(a>=10 || b>=10)cout << -1 << endl;
    else cout << a*b<<endl;
}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int y = in.nextInt();
        if (2 * x <= y && y <= 4 * x && y % 2 == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 35844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;

  for(int i= sy; i<ty; i++) cout << "U";
  for(int i= sx; i<tx; i++) cout << "R";
  for(int i= sy; i<ty; i++) cout << "D";
  for(int i= sx; i<tx; i++) cout << "L";
  cout << "L";
  for(int i= sy; i<ty; i++) cout << "U";
  cout << "U";
  for(int i= sx; i<tx; i++) cout << "R";
  cout << "R";
  cout << "D";
  
  cout << "R";
  for(int i= sy; i<ty; i++) cout << "D";
  cout << "D";
  for(int i= sx; i<tx; i++) cout << "L";
  cout << "L";
  cout << "U";
  
  
  return 0;
    

}


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

int N;
string S, T;

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

    for(int i = 0; i < N; i++) {
        bool ok = true;
        for(int j = i; j < N; j++) {
            if(S[j] != T[j - i]) {
                ok = false;
                break;
            }
        }
        if(ok) {
            cout << N + i;
            return 0;
        }
    }
    cout << 2*N;
}


Measured memory_bytes: 256
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	q := getNextInt(scanner)
	for i := 0; i < q; i++ {
		b := getNextInt(scanner)
		e := getNextInt(scanner)
		t := getNextInt(scanner)
		for j := b; j < e; j++ {
			aa[j], aa[t+j-b] = aa[t+j-b], aa[j]
		}
	}

	for i := 0; i < n; i++ {
		if i > 0 {
			fmt.Fprint(writer, " ")
		}
		fmt.Fprint(writer, aa[i])
	}
	fmt.Fprintln(writer, "")
}



Measured memory_bytes: 1248
#include <iostream>
#include <vector>
#include <cassert>

using namespace std;
typedef long long ll;

ll count_rect(const vector<vector<ll>>& cs,
              ll x1, ll y1, ll x2, ll y2){
    x1 = min(max(x1, 0LL), (ll)cs.size() - 1LL);
    x2 = min(max(x2, 0LL), (ll)cs.size() - 1LL);
    y1 = min(max(y1, 0LL), (ll)cs.front().size() - 1LL);
    y2 = min(max(y2, 0LL), (ll)cs.front().size() - 1LL);
    ll ret = cs.at(x2).at(y2) - cs.at(x1).at(y2) - cs.at(x2).at(y1)
        + cs.at(x1).at(y1);
    assert(ret >= 0);
    return ret;
}

int main(){
    ll n, k;
    cin >> n >> k;
    const ll m = 2 * k;
    vector<vector<ll>> map(m, vector<ll>(m, 0LL));
    for(int i = 0; i < n; ++i){
        ll x, y;
        char c;
        cin >> x >> y >> c;
        if(c == 'W'){
            x += k;
        }
        map.at(x % m).at(y % m)++;
    }

    vector<vector<ll>> cs(m + 1, vector<ll>(m + 1, 0LL));
    for(int i = 1; i <= m; ++i){
        for(int j = 1; j <= m; ++j){
            cs.at(i).at(j) = 
                cs.at(i).at(j - 1) + cs.at(i - 1).at(j)
                - cs.at(i - 1).at(j - 1) + map.at(i - 1).at(j - 1);
        }
    }

    ll ans = 0;
    for(ll i = 0; i < m; ++i){
        for(ll j = 0; j < m; ++j){
            ll tmp = 0;
            for(ll u = -2; u <= 2; ++u){
                for(ll v = -2; v <= 2; ++v){
                    if((u + v) % 2){ continue; }
                    tmp += count_rect(
                        cs, i + u * k, j + v * k,
                        i + u * k + k, j + v * k + k);
                }
            }
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 62976
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;

	public Graph() {
		totalVertex = 0;
	}

	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for (int i = 0; i < totalVertex; i++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			for (int j = 0; j < degree; j++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}
			adjList.add(tmp);
		}
		in.close();
	}
	
	private int[] previsit = new int[totalVertex];
	private int[] postvisit = previsit;
	public int DFShelper(int vertex, int time) {
		previsit[vertex] = time;
		LinkedList<Integer> list = adjList.get(vertex);
		Iterator<Integer> iterator = list.iterator();
		while(iterator.hasNext()) {
			int temp = iterator.next();
			if (previsit[temp] == Integer.MIN_VALUE) {
				time++;
				time = DFShelper(temp, time);
			}
		}
		postvisit[vertex] = time + 1;
		return time + 1;
		
	}
	public void DFS () {
		previsit = new int[totalVertex];
		postvisit = new int[totalVertex];
		int time = 0;
		for (int i = 0; i < totalVertex; i++)
			previsit[i] = Integer.MIN_VALUE;
		for (int i = 0; i < totalVertex; i++)
			if (previsit[i] == Integer.MIN_VALUE)
				time = DFShelper(i, time) + 1;
		display(previsit, postvisit);
	}
	
	public void display (int[] previsit, int[] postvisit) {
		for (int i = 0; i < totalVertex; i++)
			System.out.println((i+1)+" "+(previsit[i]+1)+" "+(postvisit[i]+1));
	}
}

public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.DFS();
	}
}



Measured memory_bytes: 28360
#include <stdio.h>

long int SOSUU(long int n){
        long int m, count;
        count=0;
        for(m=1; m<=n; m++){
            if(n%m==0){
                count++;
            }
        }
        if(count==2){
            return 1;
        }
        else{
            return 0;
        }
    }
    
int main(void){
    long int a, b, temp_a, temp_b, i, min, MAX;
    
    while(scanf("%d %d", &a, &b)!=EOF){
        if(a>b){
            temp_a=b;
            temp_b=a;
        }
        else{
            temp_a=a;
            temp_b=b;
        }
        min=1;
        i=2;
        while(i<=temp_a){
            if(SOSUU(i)){
                while(temp_a%i==0 && temp_b%i==0){
                    min=min*i;
                    temp_a=temp_a/i;
                    temp_b=temp_b/i;
                }
            }
            i++;
        }
        MAX=a*b/min;
        printf("%ld %ld\n", min, MAX);
    }
    return 0;
}



Measured memory_bytes: 2068
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>
#define INF 10000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int R,C,N;
int r[100001],c[100001];
ll a[100001];
vector<P> xid[100001],yid[100001];
vector<P> xlimit[100001];
vector<P> ylimit[100001];
ll mini[100001],mini2[100001];

bool checked[100001];
ll dist[100001];
bool flag=true;
vector<int> route;
ll dmini;
void dfs(int v,ll s){
	dist[v]=s;
	checked[v]=true;
	dmini=min(dmini,dist[v]);
	route.push_back(v);
	for(int i=0;i<xlimit[v].size();i++){
		P p=xlimit[v][i];
		if(!checked[p.first]){
			dfs(p.first,s+p.second);
		}else if(dist[v]+p.second!=dist[p.first])flag=false;
	}
}

void dfs2(int v,ll s){
	dist[v]=s;
	checked[v]=true;
	for(int i=0;i<ylimit[v].size();i++){
		P p=ylimit[v][i];
		if(!checked[p.first]){
			dfs2(p.first,s+p.second);
		}else if(dist[v]+p.second!=dist[p.first])flag=false;
	}
}

int main(void){
	scanf("%d%d%d",&R,&C,&N);
	for(int i=0;i<max(C,R);i++){
		mini[i]=INF;
		mini2[i]=INF;
	}
	for(int i=0;i<N;i++){
		scanf("%d%d%lld",&r[i],&c[i],&a[i]);
		r[i]--;
		c[i]--;
		xid[r[i]].push_back(P(c[i],a[i]));
		yid[c[i]].push_back(P(r[i],a[i]));
		mini[c[i]]=min(mini[c[i]],a[i]);
		mini2[r[i]]=min(mini2[r[i]],a[i]);
	}

	for(int i=0;i<R;i++){
		if(xid[i].size()<=1)continue;
		int f=xid[i][0].first;
		for(int j=1;j<xid[i].size();j++){
			int t=xid[i][j].first;
			ll c=xid[i][0].second-xid[i][j].second;
			xlimit[f].push_back(P(t,-c));
			xlimit[t].push_back(P(f,c));
			if(mini[f]-c<0)flag=false;
			if(mini[t]+c<0)flag=false;
		}
	}
	for(int i=0;i<C;i++){
		if(yid[i].size()<=1)continue;
		int f=yid[i][0].first;
		for(int j=1;j<yid[i].size();j++){
			int t=yid[i][j].first;
			ll c=yid[i][0].second-yid[i][j].second;
			ylimit[f].push_back(P(t,-c));
			ylimit[t].push_back(P(f,c));
			if(mini2[f]-c<0)flag=false;
			if(mini2[t]+c<0)flag=false;
		}
	}

	for(int i=0;i<R;i++){
		if(!checked[i]){
			dmini=INF;
			dfs(i,0);
			for(int j=0;j<route.size();j++){
				if(mini[route[j]]-(dist[route[j]]-dmini)<0)flag=false;
			}
			route.clear();
		}
	}
	memset(checked,false,sizeof(checked));
	memset(dist,0,sizeof(dist));
	for(int i=0;i<C;i++){
		if(!checked[i]){
			dmini=INF;
			dfs2(i,0);
			for(int j=0;j<route.size();j++){
				if(mini[route[j]]-(dist[route[j]]-dmini)<0)flag=false;
			}
			route.clear();
		}
	}
	printf("%s\n",flag?"Yes":"No");
	return 0;
}

Measured memory_bytes: 26496
import java.util.Scanner;
import java.util.TreeMap;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int L = scan.nextInt();
		int[]a = new int[N];
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		scan.close();
		for(int i = 0; i < L; i++) {
			map.merge(a[i], 1, (val1, val2) -> val1 + val2);
		}
		int min = map.firstKey();
		StringBuilder sb = new StringBuilder();
		sb.append(min);
		for(int i = L; i < N; i++) {
			if(map.get(a[i - L]) == 1) {
				map.remove(a[i - L]);
			}else {
				map.merge(a[i - L], -1, (val1, val2) -> val1 + val2);
			}
			map.merge(a[i], 1, (val1, val2) -> val1 + val2);
			sb.append(" ").append(map.firstKey());
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 301768
#include<cstdio>
int main(){
	long long n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a>b) printf("0\n");
	else if((a!=b) && (n==1)) printf("0\n");
	else{
		printf("%lld\n",(b-a) * (n-2) + 1);
	}
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = b - 1; i >= a; i--)
#define RREP(i, n) RFOR(i, 0, n)
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rrep(i, a, b) for (auto i = a; i > b; i--)
#define range(i, a, b) (a <= i && i < b)
#define fi first
#define fs first
#define se second
#define sc second
#define int long long
using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
typedef pair<int, int> P;
 
int dx[] = { 0, 1, 0, -1 };
int dy[] = { 1, 0, -1, 0 };
 
int n, m, c, s, g;
int x, y, d, co;
int INF = 1LL << 60;
vec p(20);
mat q(20, vec(55,0)), r(20, vec(55,0)),cost(20,vec(55,0));
 
struct edge {
    int x, y, d;
    edge(int a, int b, int c):x(a),y(b),d(c){};
};
 
vector<edge> e[20];
 
void solve() {
    cin >> n >> m >> c >> s >> g;
    if (!n) exit(0);
    REP(i, 20) e[i].clear();
    REP(_, m) {
        cin >> x >> y >> d >> co;
        x--; y--; co--;
        e[co].push_back(edge(x, y, d));
    }
    REP(i, c) cin >> p[i];
    REP(i, c) {
        REP(j, p[i] - 1) cin >> q[i][j+1];
        REP(j, p[i]) {
            cin >> r[i][j + 1];
            if(j != p[i]-1) cost[i][j + 1] = cost[i][j] + (q[i][j + 1]-q[i][j]) * r[i][j+1];
        }
    }
 
    mat dist(n, vec(n, INF));
    REP(i, n) dist[i][i] = 0;
    REP(z, c) {
        mat tmp(n, vec(n, INF));
        REP(j, n) tmp[j][j] = 0;
        for (auto t : e[z]) {
            //cout << t.x << " " << t.y << " " <<  t.d << endl;
            tmp[t.x][t.y] = min(tmp[t.x][t.y], t.d);
            tmp[t.y][t.x] = min(tmp[t.y][t.x], t.d);
        }
 
        REP(k,n){
            REP(i, n) {
                REP(j, n) {
                    tmp[i][j] = min(tmp[i][j], tmp[i][k] + tmp[k][j]);
                }
            }
        }
 
        //REP(i, n) {
        //  REP(j, n) {
        //      cout << tmp[i][j] << " ";
        //  }
        //  cout << endl;
        //}
 
        REP(i, n) {
            REP(j, n) {
                if (tmp[i][j] == INF || tmp[i][j] == 0)  continue;
                int val = -1;
                FOR(id, 1, p[z]) {
                    if (q[z][id] < tmp[i][j]) continue;
                    val = cost[z][id - 1] + (tmp[i][j] - q[z][id - 1])*r[z][id];
                    break;
                }
                if (val == -1) val = cost[z][p[z] - 1] + (tmp[i][j] - q[z][p[z] - 1])*r[z][p[z]];
                tmp[i][j] = val;
            }
        }
        REP(i, n) {
            REP(j, n) {
                dist[i][j] = min(tmp[i][j], dist[i][j]);
            }
        }
        REP(k, n) {
            REP(i, n) {
                REP(j, n) {
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
 
        //REP(i, n) {
        //  REP(j, n) {
        //      cout << dist[i][j] << " ";
        //  }
        //  cout << endl;
        //}
    }
    if (dist[s - 1][g - 1] == INF) cout << -1 << endl;
    else cout << dist[s - 1][g - 1] << endl;
}
 
signed main() {
    while (1) solve();
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {   if (y & 1)
        res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool is(string s)
{
	for(int i=0;i<s.size()/2;i++)
	{
		if(s[i]!=s[s.size()-i-1])
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
	IOS;
	ll n;
	cin>>n;
	ll a[n];
	vector<ll>v(n+1,0);
	rep(i,0,n){
	cin>>a[i];
	v[a[i]]++;
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=max((ll)0,(v[i]*(v[i]-1))/2);
	}
	for(int i=0;i<n;i++)
	{
		ll x=a[i];
		ll p=ans-max((ll)0,(v[x]*(v[x]-1))/2)+max((ll)0,((v[x]-1)*(v[x]-2))/2);
		cout<<p<<endl;
	}
}

Measured memory_bytes: 5760
def InsertionSort(A, n, g):
    cnt = 0

    for i in range(g, n):
        v = A[i]
        j = i - g

        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j -= g
            cnt += 1

        A[j + g] = v

    return cnt

def ShellSort(A, n):
    total_cnt = 0

    G = [1]
    span = 4

    while span < len(A):
        G.append(span)
        span = span * 3 + 1

    G.reverse()

    m = len(G)

    for i in range(m):
        total_cnt += InsertionSort(A, n, G[i])

    return m, G, total_cnt

n = int(input())
A = []

for i in range(n):
    A.append(int(input()))

m, G, cnt = ShellSort(A, n)

print(m)
print(*G)
print(cnt)

for a in A:
    print(a)

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

#define MIN(X,Y) (((X)>(Y))?(Y):(X))

int main () {
	int N;
	long long num = 0;
	int A[100001];
	cin >> N;
	for (int i=0; i<N+1; i++)
		cin >> A[i];
	for (int i=0; i<N; i++) {
		int b1;
		cin >> b1;
		int left = MIN (A[i], b1);
		num += left;
		b1 -= left;
		int right = MIN (A[i+1],b1);
		num += right;
		A[i+1] -= right;
	}
	cout << num << endl;
	return 0;
}

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

#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

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

#define int long long
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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 mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)


void solve(){
    int L, R, d;
    cin >> L >> R >> d;
    
    int ans = 0;
    for(int i=L; i<=R; i++)
        if(i%d==0) ans++;
    cout << ans << endl;

}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 3620
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
  x,y=map(int,input().split())
  a.append([x,y])
for i in range(m):
  x,y=map(int,input().split())
  b.append([x,y])
for i in a:
  ans=10**18
  t=0
  for j in range(m):
    if abs(i[0]-b[j][0])+abs(i[1]-b[j][1])<ans:
      t=j+1
      ans=abs(i[0]-b[j][0])+abs(i[1]-b[j][1])
  print(t)


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

int main(){
    double money = 100;
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        money *= 1.05;
        money = ceil(money);
    }
    cout << (int)(money*1000) << endl;
}

Measured memory_bytes: 1164
H,W=gets.split.map(&:to_i)
a = [('.'*(W+1)).chars]
H.times do
    a << ['.'] + gets.chomp.chars 
end
b = Array.new(H+1) { Array.new(W+1,999) }
b[1][0] = b[0][1] = 0

1.upto(H) do |y|
    1.upto(W) do |x|
        b[y][x] = [
          (a[y-1][x] == '.' && a[y][x] == '#' ? 1 : 0) + b[y-1][x],
          (a[y][x-1] == '.' && a[y][x] == '#' ? 1 : 0) + b[y][x-1],
        ].min
    end
end

p b[H][W]


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

int main() {
	ios_base::sync_with_stdio(false);
	int n, k; cin >> n >> k;
	long long res = 0;
	for (int i = k + 1; i <= n; ++i) {
		res += (n / i) * (i - k);
		int rem = n % i;
		if (rem >= k) {
			res += rem - k + (k > 0);
		}
	}
	cout << res << '\n';
}

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

int main(){
  int n,l;
  cin >> n >> l;
  string s[n];
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  sort(s,s+n);
  for(int i=0;i<n;i++){
    cout << s[i];
  }
  return 0;
}


Measured memory_bytes: 256
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

a=ll()
for i in range(5):
    if(a[i]==0):
        print(i+1)
        break

Measured memory_bytes: 65344
#include<stdio.h>
int main()
{
    long long int i,j;
    for(i=1;i<10;i++)
    {
        for(j=1;j<10;j++)
        {
           printf("%lldx%lld=%lld",i,j,i*j);
           printf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 524
use std::io::*;
use std::str::*;

const MOD: i32 = 1000000007;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: u64 = read().unwrap();
    let a: u64 = read().unwrap();
    let b: u64 = read().unwrap();

    if a > b {
        println!("{}", 0);
        return;
    }

    if n == 1 {
        if a == b {
            println!("{}", 1);
        } else {
            println!("{}", 0);
        }
        return;
    }

    println!("{}", b * (n - 2) - a * (n - 2) + 1);
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.ArrayList;


class Main {
	public static void main(String[] args) throws IOException {
		DecimalFormat df1 = new DecimalFormat("0.00000");
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = new String(in.readLine());
		String[] ss = s.split(" ");
		int a = Integer.parseInt(ss[0]);
		int b = Integer.parseInt(ss[1]);
		System.out.print((a/b)+ " ");
		System.out.print((a%b)+ " ");
		System.out.println(df1.format((double)a/(double)b));
	}

}

Measured memory_bytes: 17184
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
int a[105];
int main()
{
	int n,i,j,k,s=0,min=100000000;
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+1+n);
	for(i=a[i];i<=a[n];i++)
	{
		s=0;
		for(j=1;j<=n;j++)
		{
			s+=(i-a[j])*(i-a[j]);
			
		}
	if(s<min)  min=s;	
	}
	cout<<min;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long A, long long B, long long K)
{
    if (A <= K)
    {
        K -= A;
        A = 0;
    }
    else
    {
        A -= K;
        K = 0;
    }

    if (B <= K)
    {
        K -= B;
        B = 0;
    }
    else
    {
        B -= K;
        K = 0;
    }
    cout << A << " " << B << endl;
}

int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long K;
    scanf("%lld", &K);
    solve(A, B, K);
    return 0;
}


Measured memory_bytes: 256
def ceil(a,b):
    return -((-a)//b)
def floor(a,b):
    return a//b
K=int(input())
A=[int(i) for i in input().split()]
L=[0 for i in range(K+1)]
R=[0 for i in range(K+1)]
L[K]=2
R[K]=2
for i in range(1,K+1)[::-1]:
    L[i-1]=ceil(L[i],A[i-1])*A[i-1]
    R[i-1]=floor(R[i],A[i-1])*A[i-1]+A[i-1]-1
if L[0]<R[0]:
    print(L[0],R[0])
else:
    print(-1)


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

int main() {
    int n, ans;
    cin >> n;
    vector<int> b(n - 1);
    rep(i, n - 1) cin >> b.at(i);
    ans = b.at(0) + b.at(n - 2);
    rep(i, n - 2) ans += min(b.at(i), b.at(i + 1));
    cout << ans << endl;
}

Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n%M) * (f(n - 1) % M);
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll N, K; cin >> N >> K;

	cout << min(N%K, K - N % K) << endl;
}


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

int main(int argc, char const *argv[]) {
  int N, K, Q;
  cin >> N >> K >> Q;

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

  for (int i = 0; i < N; i++) {
    if (points[i] > (Q - K)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 1024
import math

class Point():
    def __init__(self, x=None, y=None):
        self.x = x
        self.y = y

class Vector():
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.abs = math.sqrt(x*x + y*y)

    def constant_multipled(self, c):
        return Vector(self.x*c, self.y*c)

    def inner_product(self, vec):
        return self.x*vec.x + self.y*vec.y

x1, y1, x2, y2 = list(map(int, input().split(' ')))
start = Point(x1, y1)
base_vec = Vector(x2-x1, y2-y1)
q = int(input())
vectors = []
for i in range(q):
    x, y = list(map(int, input().split(' ')))
    vectors.append(Vector(x-start.x, y-start.y))

for vec in vectors:
    if vec.abs == 0:
        ans_x, ans_y = 0, 0
        print('%.8f'%ans_x, '%.8f'%ans_y)
        continue
    cos = base_vec.inner_product(vec)/(base_vec.abs*vec.abs)
    b_cos = vec.abs*cos
    vec_x = base_vec.constant_multipled(b_cos/base_vec.abs)
    ans_x, ans_y = vec_x.x + start.x, vec_x.y + start.y
    print('%.8f'%ans_x, '%.8f'%ans_y)



Measured memory_bytes: 6100
L, R = map(int, input().split())

MOD = 2019
ub = max(R % MOD, L % MOD)
lb = min(R % MOD, L % MOD)

if ub == lb or R // MOD != L // MOD:
    print(0)
    exit()

ans = float('inf')
for i in range(lb, ub + 1):
    for j in range(i + 1, ub + 1):
        ans = min(ans, i * j % MOD)
print(ans)

Measured memory_bytes: 40812
#include <iostream>
#include <string>

using namespace std;

int main(){
	int N, K;
	string S;

	cin >> N;
	cin >> S;
	cin >> K;

	char chk = S[K-1];

	for(int i = 0; i < N; i++){
		if(S[i] != chk)
			S[i] = '*';
	}

	cout << S << endl;
}

Measured memory_bytes: 256
def g;gets.split.map &:to_i;end
while(c,n,m,s,d=g)[0]>0
l=(0..n).map{{}}
m.times{a,b,f=g;l[a][b]=l[b][a]=f}
q=[[0,s]+[0]*c]
until(o,i,*a=q.sort!.shift;i==d)
l.map{|h|h.delete i}
l[i].map{|k,v|t,*u=(a+[v]).sort;q<<[o+v/2+t/2,k]+u}
end
p o
end

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

int F(long int A,long int B){
    int da=0,db=0;

    while(A!=0){
        da ++;
        A = A/10;
    }

    while(B!=0){
        db ++;
        B = B/10;
    }

    return max(da,db);
}

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

    int ans=F(1,N);

    for(long int i=1;i<sqrt(N)+1;i++){
        if(N%i==0){
            if(F(i,N/i)<ans){
                ans = F(i,N/i);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

/* 二項係数 C(n,k) mod p を計算 */
const int MOD = 1000000007;
const int MAX = 100010;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll N, K;
vector<vector<ll>> ab(MAX);
ll ans;

void dfs(ll par, ll cv){
  //cvが葉
  if(ab[cv].size() == 1 && ab[cv][0] == par) return;
  
  ll t = ab[cv].size();
  if(par == -1){
    (ans *= COM(K-1,t) % MOD) %= MOD;
    (ans *= fac[t] % MOD) %= MOD;
  }else{
    (ans *= COM(K-2, t-1) % MOD) %= MOD;
    (ans *= fac[t-1] % MOD) %= MOD;
  }
  FOREACH(nv, ab[cv]){
    if(nv == par) continue;
    dfs(cv, nv);
  }
}

int main() {
  cin >> N >> K;
  COMinit();
  REP(i, N-1){
    ll a,b; cin >> a >> b;
    a--; b--;
    ab[a].push_back(b);
    ab[b].push_back(a);
  }
  ans = K;
  dfs(-1, 0);
  cout << ans << endl;
}

Measured memory_bytes: 11520
#include <iostream>
using namespace std;
int main(){

  int a, b;
  char op;
  
  while(1) {
    cin >> a >> op >> b;
    if(op == '+') cout << a+b <<"\n";
    if(op == '-') cout << a-b <<"\n";
    if(op == '*') cout << a*b <<"\n";
    if(op == '/') cout << a/b <<"\n";
    if(op == '?') break;
  }
  
  return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<utility>
#include<algorithm>

using namespace std;

typedef long long ll;

class BIT{
    /* 1-indexed BIT */
    public:
    int n;
    ll bit[200001];
    
    BIT(int n): n(n){
        fill(bit, bit+(n+1), 0);
    }

    void add(int i, ll x){
        for(int j=i;j<=n;j+=j&-j) bit[j] += x;
    }

    // [1,i]の和
    ll get_sum(int i){
        ll ret = 0LL;
        for(int j=i;j>=1;j-=j&-j) ret += bit[j];
        return ret;
    }
};

int main(){
    int n;
    cin >> n;
    pair<int, int> a[n];
    for(int i=0;i<n;i++){
        cin >> a[i].first;
        a[i].second = i+1;
    }
    sort(a, a+n);

    int b[n+1];
    for(int i=0;i<n;i++){
        b[a[i].second] = i+1;
    }

    BIT bit = BIT(n);
    ll ret = 0;
    for(int i=1;i<=n;i++){
        bit.add(b[i], 1);
        ret += i-bit.get_sum(b[i]);
    }
    cout << ret << endl;
}


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

int main(int argc, char const *argv[]) {
        int x; cin>>x;

        while (x--) {
                string s,t; cin>>s>>t;
                int n = s.length(); int m = t.length();
                vector<vector<int> > dp(n+1, vector<int>(m+1, 0));
                for (int i = 1; i <= n; ++i) {
                        for (int j = 1; j <= m; j++) {
                                if (s[i-1]==t[j-1]) dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
                                else {
                                        dp[i][j] = max(dp[i][j], max(dp[i-1][j], dp[i][j-1]));
                                }
                        }
                }
                cout << dp[n][m] << endl;
        }

        return 0;
}


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

int main(void) {
  int K, X;
  scanf("%d %d", &K, &X);
  for (int i = X-K+1; i < X+K; i++) {
    if (i>=-1000000&&i<=1000000) {
      printf("%d ", i);
    }
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 128