akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	m := intScanner()
	for i := 0; i < m; i++ {
		n -= intScanner()
	}
	if n >= 0 {
		fmt.Println(n)
	} else {
		fmt.Println(-1)
	}
}


Measured memory_bytes: 1800
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define F(i,N) for(int i=0;i<N;i++)
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    int D[9]; F(i,K) cin >> D[i];
    
    while(1){
        vector<int> num; int temp = N; bool flag = false;
        while(temp != 0){   
          	num.push_back(temp % 10);
            temp /= 10;
        }
        F(i,K){
            F(j, num.size()){
              	//cout << num[j] << " " << D[i] << endl;
                if(num[j] == D[i])
                {
                  flag = true;
                  break;
                }
            }
        }
        if(flag) N++;
        else break;
    }
    cout << N;
}

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

using namespace std;
typedef long long ll;

#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define MAX_N 200000

class UnionFind {
private:
  // 親と木の深さ
  int par[MAX_N];
  int rank[MAX_N];
public:
  void init(int n);
  int find(int x);
  void unite(int x, int y);
  bool same(int x, int y);
};

// 要素数nで初期化
void UnionFind::init (int n) {
  for(int i=0; i<n; i++) {
    par[i] = i;
    rank[i] = 0;
  }
}

// 要素xの親を求める
int UnionFind::find(int x) {
  if(par[x] == x) return x;
  else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void UnionFind::unite(int x, int y) {
  // xとyの親
  x = find(x);
  y = find(y);
  if(x == y) return;

  // yのほうが深さが深い　xの親はyの親
  if(rank[x] < rank[y]) par[x] = y;
  else {
    par[y] = x;
    if( rank[x] == rank[y] ) rank[x]++;
  }
}

// xとyが同じ集合に属するか
bool UnionFind::same(int x, int y) { return find(x) == find(y);}

map<pair<int, int>, int> p;
UnionFind ar, br;

int main(void)
{
  int n = 0, k = 0, l = 0;
  cin >> n >> k >> l;
  ar.init(n); br.init(n);

  for(int i=0; i<k; i++) {
    int p = 0, q = 0;
    cin >> p >> q;
    p--; q--;
    ar.unite(p, q);
  }
  for(int i=0; i<l; i++) {
    int r = 0, s = 0;
    cin >> r >> s;
    r--; s--;
    br.unite(r, s);
  }

  for(int i=0; i<n; i++) p[make_pair(ar.find(i), br.find(i))]++;
  for(int i=0; i<n; i++) cout << p[make_pair(ar.find(i), br.find(i))] << ' ';
  cout << endl;

  return 0;
}

Measured memory_bytes: 15104
package main

import (
	"fmt"
	"math"
)

func getMaxInt(numbers []int) int {
	var max int
	max = numbers[0]
	for _, v := range numbers {
		if max < v {
			max = v
		}
	}
	return max
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	max := getMaxInt(a)
	median := int(max / 2)
	diff := 1 << 31
	diff_index := 0
	for i := 0; i < n; i++ {
		if a[i] == max {
			continue
		}
		if int(math.Abs(float64(median - a[i]))) < diff {
			diff_index = i
			diff = int(math.Abs(float64(median - a[i])))
		}
	}
	fmt.Println(max, a[diff_index])
}


Measured memory_bytes: 5504
use std::io::stdin;
use std::io::BufRead;

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let mut buf = String::new();

    stdin.read_line(&mut buf).unwrap();
    buf = String::new();
    stdin.read_line(&mut buf).unwrap();

    println!("{}", buf.split_whitespace().rev().collect::<Vec<_>>().join(" "))

}


Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  string n;
  cin >> n;
  string a = "YAKI";
  if (a.length() > n.length()) {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < a.length(); i++) {
    if (a[i] != n[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math


def solve(A: int, B: int, N: int):
    # for x in range(N):
    #     math.floor(A * x / B) - A * math.floor(x / B)
    x = min(B - 1, N)
    print(math.floor(A * x / B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(A, B, N)

if __name__ == '__main__':
    main()


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

using namespace std;


#define MOD 1000000007
#define ll long long int
#define ff first
#define ss second
#define N 1000001


template <typename T,typename G>
ostream& operator << (ostream& out, const pair<T,G> &a) 
{return out<<"( "<<a.ff<<", "<<a.ss<<")";}

template <typename T>
ostream& operator << (ostream& out, const vector<T> &a) 
{out<<"[ ";for(const auto &i:a)out<<i<<", ";return out<<"]"<<endl;}

template <typename T>
ostream& operator << (ostream& out, const set<T> &a) 
{out<<"{ ";for(const auto &i:a)out<<i<<", ";return out<<"}"<<endl;}

template <typename T,typename G>
ostream& operator << (ostream& out, const map<T,G> &a) 
{out<<"< ";for(const auto &i:a)out<<i<<", ";return out<<">"<<endl;}
    

void solve()
{
	ll n,w;
	cin>>n>>w;

    ll dp[n+1][w+1],wgh[n+1],val[n+1];
	memset(dp,0,sizeof dp);
	memset(wgh,0,sizeof wgh);
	memset(val,0,sizeof val);
	for(int i=1;i<=n;i++)
		cin>>wgh[i]>>val[i];

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(j<wgh[i])
				dp[i][j]=dp[i-1][j];
			else
				dp[i][j]=max(dp[i-1][j],val[i]+dp[i-1][j-wgh[i]]);
		}
	}
	cout<<dp[n][w]<<"\n";
}


int32_t main()
{

 
    //your code goes here...
    int t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }    
}

Measured memory_bytes: 79104
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 6001000;
int n, m, q;
struct Q{
	int l, r, id;
	bool operator < ( const Q& a ) const {
		return r < a.r;
	}
}a[N], b[N];
int c[N], vec[N], psz = 1, id[N], res[N];
void update( int x, int v ){
	for( int i = x; i <= n; i += i & -i )
		c[i] += v;
}
int sum( int x ){
	int ret = 0;
	for( int i = x; i; i -= i & -i )
		ret += c[i];
	return ret;
}
int main(){
	scanf("%d%d%d", &n, &m, &q);
	for( int i = 1; i <= m; ++i ){
		scanf("%d%d", &a[i].l, &a[i].r);
		vec[psz++] = a[i].l;
		vec[psz++] = a[i].r;
	}
	for( int i = 1; i <= q; ++i ){
		scanf("%d%d", &b[i].l, &b[i].r);
		b[i].id = i;
		vec[psz++] = b[i].l;
		vec[psz++] = b[i].r;
	}
	sort(vec+1, vec+psz);
	n = unique(vec+1, vec+psz) - vec;
	for( int i = 1; i <= m; ++i ){
		a[i].l = lower_bound(vec+1, vec+n, a[i].l) - vec;
		a[i].r = lower_bound(vec+1, vec+n, a[i].r) - vec;
	}
	for( int i = 1; i <= q; ++i ){
		b[i].l = lower_bound(vec+1, vec+n, b[i].l) - vec;
		b[i].r = lower_bound(vec+1, vec+n, b[i].r) - vec;
	}
	
	sort(a+1, a+1+m);
	sort(b+1, b+1+q);
	int j = 1;
	for( int i = 1; i <= q; ++i ){
		while( j <= m && a[j].r <= b[i].r )
			update(a[j++].l, 1);
		res[b[i].id] = j - sum(b[i].l - 1)-1;
	}
	for( int i = 1; i <= q; ++i )
		printf("%d\n", res[i]);
	return 0;
}

Measured memory_bytes: 10112
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
  ll N,a=pow(10,9)+7;
  cin >> N;
  vector<ll> vec(N);
  ll cnt=0;
  for(int i=0;i<N;i++){
    cin >> vec[i];
    cnt+=vec[i];
    cnt%=a;
  }
  ll ans=0;
  for(int i=0;i<N;i++){
    cnt-=vec[i];
    if(cnt<0){
      cnt+=a;
    }
    ans+=cnt*vec[i];
    ans%=a;
  }
  cout << ans <<endl;
}
  

Measured memory_bytes: 4816
#include <stdio.h>
int main()
{
    int n,m,i,j,x,y;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    scanf("%d",&m);
    for(i=0;i<m;i++)
    {
        scanf("%d %d",&x,&y);
        int sum=0;
        for(j=0;j<n;j++)
        {
            if(j==x-1)
            sum=sum+y;
            else
            sum=sum+a[j];
        }
        printf("%d\n",sum);
    }
    return 0;
}

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

int main(void)
{
    int n, x, l_i;
    cin >> n >> x;
    int sum = 0;
    int count = 1;
    for (int i = 1; i <= n; i++)
    {
        cin >> l_i;
        sum += l_i;
        if (sum <= x)
        {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
int gcd(int a,int b){
    if(a%b==0){
        return b;
    }    
    return gcd(b,a%b);
}
/*
int main(void){
	printf("nyan");
	printf("%d",gcd(gcd(24,6),12));
}
 
*/
 
 
int main(void){
    //printf("input\n");
 
    int i,j,k;
    // int l,m,n;
    int K;
    int ret;
    // scanf("%d",&K);
    // scanf("%d",&j);
    ret = scanf("%d",&K);
    //printf("line1\n");
    int total = 0; 
 
    for(i=1;i<=K;i++){
    	//printf("line3\n");
        for(j=1;j<=K;j++){
    	    //printf("line4\n");
            //printf("%d \n",gcd(i,j));
            for(k=1;k<=K;k++){
		//printf("line5\n");
		//printf("%d:%d:%d \n",i,j,k);
                total += gcd(gcd(i,j),k);                
               	//printf("total:%d\n",total);
 
            }   
        }   
    }
 
 
    
    printf("%d",total);
    
}

Measured memory_bytes: 1700
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int t,h,n,f;
	vector<int> u,v;
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		u.clear();
		v.clear();
		rep(i,n){
			scanf("%d",&t);
			u.push_back(t);
		}
		sort(u.begin(),u.end());
		t=h=0;
		reps(i,1,n*2){
			if(t<n && u[t]==i)t++;
			else v.push_back(i);
		}
		t=0;
		while(u.size() && v.size()){
			vector<int>::iterator it;
			if(t%2){
				it=lower_bound(v.begin(),v.end(),h);
				if(it!=v.end()){
					h=*it;
					v.erase(it);
				}else h=0;
			}
			else{
				it=lower_bound(u.begin(),u.end(),h);
				if(it!=u.end()){
					h=*it;
					u.erase(it);
				}else h=0;
			}
			t++;
		}
		printf("%d\n%d\n",v.size(),u.size());
	}
	return 0;
}

Measured memory_bytes: 1216
#include <cstdio>
#include <algorithm>
using std::sort;
int a[300];
int main() {
    int n, ans = 0;
    scanf("%d", &n);
    for(int i=1;i<=2*n;i++)scanf("%d", &a[i]);
    sort(a+1, a+n*2+1);
    for(int i=1;i<=2*n;i+=2) ans+=a[i];
    printf("%d\n", ans);
}

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

// CAT := "" | "m" + CAT + "e" + CAT + "w"

// s[l..r) が CAT かどうか返す.
bool is_cat(const string& s, int l, int r){
	if( l >= r ) return true;
	if( s[l] != 'm' || s[r-1] != 'w' ) return false;
	
	int k=0, deep = 0;
	for(int i=l+1 ; i < r-1 ; i++ ){
		if( deep == 0 && s[i] == 'e' ){
			k = i;
			break;
		}
		if( s[i] == 'm' ) deep++;
		if( s[i] == 'w' ) deep--;
		if( deep < 0 ) return false;
	}
	return is_cat(s, l+1, k) && is_cat(s, k+1, r-1);
}

int main(){
	string s;
	cin >> s;
	cout << (is_cat(s, 0, s.size())? "Cat" : "Rabbit") << endl;
}

Measured memory_bytes: 1184
import java.util.*;

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

		// input
		final int NUM = scan.nextInt();
		int[][] pos = new int[NUM][2];
		for(int i = 0; i < NUM; i++){
			pos[i][0] = scan.nextInt();
			pos[i][1] = scan.nextInt();
		}
		
		// search
		double sum = 0.0;
		int count = 0;
		for(int i = 0; i < NUM; i++){
			for(int j = 0; j < NUM; j++){
				if(i == j){
					continue;
				}
				sum += Math.sqrt(Math.pow(pos[i][0] - pos[j][0], 2) + Math.pow(pos[i][1] - pos[j][1], 2));
				count++;
			}
		}
		double avg = sum / (double)count;
		
		// answer
		System.out.println(avg * (NUM-1));
		
	}
}

Measured memory_bytes: 23764
// AtCoder Beginner Contest 173
// A - Payment

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <random>
#include <vector>
#include <chrono>

using namespace std;
//using namespace std::chrono;


int main()
{
	//steady_clock::time_point start = steady_clock::now();
	int N;

	cin >> N;
	int res,criteria;
	int cnd1, cnd2;
	if ( N < 1000) {
		res = 1000 - N;
	} else if ( (N % 1000) == 0) {
		res = 0;
	} else {
		criteria = N / 1000;
		//cout << "余り:" << criteria << endl;
		res = (criteria+1)*1000 - N;
	}
	
	cout << res << endl;
	//計算時間集計
	/*
	steady_clock::time_point end = steady_clock::now();
    steady_clock::duration d = end - start;
	cout << "計算時間は" << duration_cast<milliseconds>(d).count() << "ミリ秒です。\n";
	*/
}




Measured memory_bytes: 3624
/**
*    author:  souzai32
*    created: 02.08.2020 21:01:51
**/

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

int main() {

    int n;
    cin >> n;
    long long int d;
    cin >> d;
    long long x,y;
    int count=0;
    rep(i,n){
        cin >> x >> y;
        if(x*x+y*y<=d*d) count++;
    }
    
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>

using namespace std;

long long gcd(long long a, long long b){
    long long r;
    while(b != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

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

int main()
{
    int n;
    cin >> n;
    vector<long long> t(n);
    for (int i=0; i<n; ++i){
        cin >> t[i];
    }
    long long ans = t[0];
    for (int i=1; i<n; ++i){
        ans = lcm(ans, t[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#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 all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main(){
  double t, x; cin >> t >> x;
  cout << fixed << setprecision(10) << t / x << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    string s;
    cin>>s;
    long long sum=0,x;
    for(int i=0;i<=s.size()-1;i++)
    {
    	x=s[i]-'0';
    	sum+=x;
	}
	if(sum%9==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3764
#include <iostream>
using namespace std;
int main(void){
    int i,m,nmin,nmax,a[200],gap,n;
    
    while(1){
        
        cin >> m >> nmin >> nmax;
        if(m==0 && nmin == 0 && nmax == 0) break;
        
        for(i=1;i<m+1;i++){
            cin >> a[i];
        }
        
        gap = a[nmin] - a[nmin+1];
        n = nmin;
        
        for(i=nmin;i< nmax+1;i++){
            if(a[i] - a[i+1] >= gap ){
                gap = a[i]-a[i+1];
                n = i;
               
            }
             //cout << gap << " " << n << endl;
             
        }
        
        cout << n << endl;
        
    }
    
    return 0;
}



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

int main(){
  int n;cin>>n;
    vector<double>v(n);
    for(int i=0;i<n;i++)cin>>v.at(i);
  sort(v.begin(),v.end());
 double ans=v.at(0);
  for(int i =1;i<n;i++){
  	ans=(ans+v.at(i))/2.0;
  }
         cout <<ans<<endl;
}


Measured memory_bytes: 256
//ABC107B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <numeric>
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for(int i=0;i<h;i++){
		cin >> s.at(i);
	}
	vector<bool> t(h), y(w);
	for(int i=0;i<h;i++){
		t.at(i) = false;
	}
	for(int i=0;i<w;i++){
		y.at(i) = false;
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(s.at(i).at(j) == '#'){
				t.at(i) = true;
				y.at(j) = true;
			}
		}
	}
	for(int i=0;i<h;i++){
		bool flag = false;
		for(int j=0;j<w;j++){
			if(t.at(i) && y.at(j)){
				cout << s.at(i).at(j);
				flag = true;
			}
		}
		if(flag){
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const  int maxn=1e5+10;
const int mod=1e9+7;
int depth[maxn];
int out_put[maxn];
struct Node
{
    int x,y;
};
vector<int>s[maxn];
ll pows(ll a,ll b)
{ ll re=1;
    while(b)
    {
        if(b&1)
            re=re*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return re%mod;
}
ll C(ll n,ll r)
{
    if(r<0)
        return 0;
     long long i=2,ret=1;
    for(i=2;i<=n;i++)
        ret=(ret*i)%mod;
    for(i=2;i<=r;i++)
    ret=(ret*pows(i,mod-2))%mod;
    for(i=2;i<=n-r;i++)
    ret=(ret*pows(i,mod-2))%mod;

    return ret;
}
int main()
{
    int n,k;
    cin>>n>>k;

cout<<n-k+1<<endl;
    int sum=n-k+1;
    for(int i=2;i<=k;i++)
    {
        ll ans=C(k-1,i-1)%mod;
        ans=(ll)ans*C(sum,sum-i)%mod;
        cout<<ans<<endl;

    }
    return 0;
}
/*#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
ll mod=1e9+7;
ll inv(ll a){
    ll n=mod-2,ans=1;
    while(n>0){
        if(n%2) ans=ans*a%mod;
        n=n/2;
        a=a*a%mod;
    }
    return ans;
}
ll nCr(ll a,ll b){
    if(b<0) return 0;
    ll ans=1;
    rep(i,b) ans=ans*(a-i)%mod*inv(i+1)%mod;
    return ans;
}
int main(){
    ll n,k,ans,r;
    cin>>n>>k;
    r=n-k;
    rep(i,k){
        ll x=i+1;
        ans=nCr(k-1,i);
        ans=ans*nCr(r+1,r-x+1)%mod;
        cout<<ans<<endl;
    }
}*/


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

int main(){
    int s[3];
    int x;

    cin >> x;

    for (int i = 2; i >= 0; i--) {
        s[i] = x%10;
        x /= 10;
    }

    cout << count(s,s+3,1) << endl;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    cin>>n;
    int even = n/2;
    int odd = n-even;
    double ans = (double)odd/n;
    cout<<ans<<endl;
    
    return 0;
}

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

int main() {
  string a,b;
  cin >> a >> b;
  for(int i = 0; i < 3; i++){
    if(a.at(i) != b.at(2-i)){
      cout << "NO" << endl;
      break;
    }
    if(i == 2){
      cout << "YES" << endl;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i;
  cin >> n;
  
vector<long int> b(n),c(n);
  for(i=0;i<n;++i)
  {
  cin >> b.at(i);
  c.at(i)=b.at(i);
  }
  
  sort(c.begin(),c.end());
  
  for(i=0;i<n;++i)
  {
   if(c.at(n/2-1)==c.at(n/2)) cout << c.at(n/2) << endl;
   else{
   if(b.at(i)<=c.at(n/2-1)) cout << c.at(n/2) << endl;
   else cout << c.at(n/2-1) << endl;
   }
  }
  
return 0;
}

Measured memory_bytes: 6348
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

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


Measured memory_bytes: 3620
a,b,m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = []
for i in range(m):
    x,y,c = map(int, input().split())
    ans += [A[x-1] + B[y-1] - c]
ans += [min(A) + min(B)]

print(min(ans))

Measured memory_bytes: 97988
#include <stdio.h>
#include <stdlib.h>
 
#define MAX 100
#define NIL -1
#define INFTY (1<<21);
 
int M[MAX][MAX];
int *key, *p;
int n;
 
void input() {
    int i, j;
 
    scanf("%d", &n);
 
    for (i = 0; i < n; i++){
        for (j = 0; j < n; j++){
            scanf("%d", &M[i][j]);
            if (M[i][j] == NIL) {
                M[i][j] = INFTY;
            }
        }
    }
}
 
void init() {
    int i;
 
    key = (int *)malloc(sizeof(int) * n);
    p = (int *)malloc(sizeof(int) * n);
 
    for (i = 0; i < n; i++) {
        key[i] = INFTY;
        p[i] = NIL;
    }
 
    key[0] = 0;
}
 
int MSTPrim() {
    int i, j, k, u, sum = 0;
 
    init();
 
    while (1) {
        u = NIL;
 
        for (i = 0; i < n; i++) {
            if (p[i] == 1) continue;
            if (u == NIL || key[i] < key[u]) {
                u = i;
            }
        }
 
        if (u == NIL) break;
        p[u] = 1;
        for (i = 0; i < n; i++) {
            if (key[i] > M[u][i] && p[i] == NIL) {
                key[i] = M[u][i];
            }
        }
    }
 
    for (i = 0; i < n; i++) {
        sum += key[i];
    }
 
    return sum;
}
 
void Free() {
    free(key);
    free(p);
}
 
main() {
 
    input();
    printf("%d\n", MSTPrim());
    Free();
 
    return 0;
}

Measured memory_bytes: 636
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

ll N, X, M;
vector<ll> repeat;
ll ans = 0;

void fun(ll total, ll idx) {
	if (find(all(repeat), total) != repeat.end()) {
		int i = 0;
		for (;;++i) {
			if (total == repeat[i]) break;
			ans += repeat[i];
		}

		int pre_cycle_terms = i;
		ll cycle_sum= accumulate (all(repeat), -ans);
		ll cycle_terms = repeat.size() - i;
		ll x = (N - i) / cycle_terms;
		ll y = (N - i) % cycle_terms;

		ans = accumulate (repeat.begin() + i, repeat.begin() + i + y, ans + cycle_sum * x);
		return;
	}

	if (idx == N) {
		repeat.pb(total);
		ans = accumulate(all(repeat), 0);
		return;
	}

	repeat.pb(total);
	fun((total * total) % M, idx + 1);
}

int main() {
	cin>>N>>X>>M;
	fun(X, 1);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5944
S = input()
T = input()

ans = []
for l in range(len(S) - len(T) + 1):
    U = S[l: l + len(T)]
    for u, t in zip(U, T):
        if u == '?':
            continue
        if u != t:
            break
    else:
        ans.append((S[:l] + T + S[l + len(T):]).replace('?', 'a'))

ans.sort()
print(ans[0] if len(ans) > 0 else 'UNRESTORABLE')


Measured memory_bytes: 3060
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
// 検索タグ
int main() {
	// 入力
	ll N,M;cin>>N>>M;
	ll A[N];
    REP(i,N)cin>>A[i];
    
	// 解法
	ll sum = 0;
	REP(i,N) sum+= A[i];
	sort(A, A + N, greater<ll>());
	bool ans = (A[M-1]*4*M>=sum);

	//出力
	if (ans) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 256
function rl()
   local r = {}
   for word in io.read():gmatch("%S+") do
      table.insert(r, tonumber(word))
   end
   return r
end

function ru()
   return unpack(rl())
end

function pu(x, ...)
   if x then
      io.write(x, ' ')
      return pu(...)
   else
      io.write('\n')
   end
end

N = ru()

pu(math.fmod(1000000 - N, 1000))


Measured memory_bytes: 2572
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
template<class T> void read(T &x) {
	x = 0; int f = 1, ch = getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=getchar();}
	x *= f;
}
typedef long long ll;
const int mod = 998244353;
const int maxn = 1e5 + 10;
int n;
char s[maxn * 3];
int main() {
	read(n); 
	scanf("%s", s + 1);
	int an = 1;
	int t = n, r = 0, b = 0, g = 0, rb = 0, rg = 0, bg = 0; 
	for(int i = 1; i <= n * 3; ++i) {
		if(s[i] == 'R') {
			if(bg) {
				an = (ll)an * bg % mod;
				--bg;
			}
			else if(b) {
				an = (ll)an * b % mod;
				--b, ++rb;
			}
			else if(g) {
				an = (ll)an * g % mod;
				--g, ++rg;
			}
			else {
				an = (ll)an * t % mod;
				--t, ++r;
			}
		}
		else if(s[i] == 'B') {
			if(rg) {
				an = (ll)an * rg % mod;
				--rg;
			}
			else if(r) {
				an = (ll)an * r % mod;
				--r, ++rb;
			}
			else if(g) {
				an = (ll)an * g % mod;
				--g, ++bg;
			}
			else {
				an = (ll)an * t % mod;
				--t, ++b;
			}
		}
		else if(s[i] == 'G') {
			if(rb) {
				an = (ll)an * rb % mod;
				--rb;
			}
			else if(b) {
				an = (ll)an * b % mod;
				--b, ++bg;
			}
			else if(r) {
				an = (ll)an * r % mod;
				--r, ++rg;
			}
			else {
				an = (ll)an * t % mod;
				--t, ++g;
			}
		}
	} 
	printf("%d\n", an);
	return 0;
}

Measured memory_bytes: 512
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n,m;
const int MAX_N =120;
const int MAX_M =120;
double dp[MAX_N][MAX_M];//dp[i][j]:=直前にjを与え、i回目に肥料を与えたときの最大の成長
double memo[MAX_N][MAX_N];
int main(){
	while(1){
		cin>>n>>m;
		if(n==0&&m==0){
			break;
		}
		int a =max(n,m);
		for(int i =0;i <=a;i++){
			for(int j =0;j <=a;j++){
				dp[i][j] =0;
				memo[i][j]=0;
			}
		}
		rep(i,n){
			rep(j,n){
				cin>>memo[i][j];
			}
		}
		rep(i,n)dp[1][i] =1.00;

		double ans =0;
		for(int i =1;i <m;i++){
			for(int j =0;j <n;j++){//直後
				for(int k =0;k <n;k++){//直前
					dp[i+1][j] =max(dp[i+1][j],dp[i][k]*memo[k][j]);
				}
			}
		}
		rep(i,n)ans=max(ans,dp[m][i]);
		ans =ans*100;
		ans =round(ans)/100;
		printf("%.2lf\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1448
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,pair<int,int>> ddp;
typedef pair<long long,pll> ldp;

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi(n) for(int i=0;i<(n);i++)
#define fj(n) for(int j=0;j<(n);j++)
#define fk(n) for(int k=0;k<(n);k++)
#define mod 1000000007
#define MAX 100000+5;

int main()
    {
        fastio
        string a;
        cin >> a;
        if(a[0]==a[1] || a[1]==a[2] || a[2]==a[3])
        cout << "Bad";
        else
        cout << "Good";
        return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;
	if(m % 2 == 0 && m >= 2 * n && m <= 4 * n){
		cout << "Yes" << endl; 
	}else{
		cout << "No" << endl;
	}
	return 0;
} 

Measured memory_bytes: 3624
#ifdef __GNUC__
#include <bits/stdc++.h>
#else
#include "bits/stdc++.h"
#define scanf scanf_s
#endif
#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define WHL(i) while(i)
#define putn printf("\n")
#define all(container) container.begin(), container.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<class T> istream& operator >> (istream &is, vector<T> &vec) {
	for (T &x : vec)is >> x;
	return is;
}

int main ()
{
	int A[3] = {0};
	int output = 0;
	ios::sync_with_stdio (false);
	cin.tie (NULL);
	cout.tie (NULL);

	REP(i, 3) {
		cin >> A[i];
	}

	sort(A, A + 3);

	FOR(i,1, 3) {
		output += A[i] - A[i-1];
	}
	cout << output << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL n,m,ans;
int main()
{
	cin>>n>>m;
	if(n>m) swap(n,m);
	if(n>2&&m>2){
		ans=(n-2)*(m-2);
	}
	if(n==2){
		ans=0;
	}
	if(n==1){
		if(m==1) ans=1;
		else ans=m-2;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
{
  const run = (input: string) => {
    let split = input.trim().split("\n")
    const [n, d] = split[0].split(" ").map(v => parseInt(v))

    let count = 0

    for (let i = 1; i <= n; i++) {
      const [a, b] = split[i].split(" ").map(v => parseInt(v))
      if (Math.sqrt(a ** 2 + b ** 2) <= d) count++
    }

    return count
  }

  const Main = (input: string) => {
    console.log(run(input))
  };

  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}


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

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b >= 24) {
		cout << a + b - 24 << endl;
	}
	else {
		cout << a + b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    double a[200];
    REP(i, n)
    {
        double tmp;
        cin >> tmp;
        a[i] = 1.0 / tmp;
    }
    double ans = 0.0;
    REP(i, n)
    {
        ans += a[i];
    }
    printf("%.16lf\n", 1.0 / ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w",stdout);
    #endif
    int x,n;
    cin>>x>>n;
    vector<int> vec(n);
    unordered_set<int> s;
    for(int i = 0 ; i < n ;  i++){
        cin>>vec[i];
        s.insert(vec[i]);
    }

    int fin = INT_MAX;
    int res = INT_MAX;
    for(int i=0;i<=101;i++){
        if(s.find(i) != s.end()){
            continue;
        }else{
            int d = abs(x-i);
            if(d<fin){
                fin = d;
                res = i;
            }
        }
    }

    cout<<res;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    stack<int> st;
    int no_rem = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'S') {
            st.push(0);
        } else {
            if (!st.empty()) {
                no_rem++;
                st.pop();
            }
        }
    }
    cout << s.length() - no_rem * 2;
}

Measured memory_bytes: 3960
package main

import (
	"fmt"
	"math"
)

var N int
var S string
var ans, res int

func main() {
	fmt.Scan(&N)
	fmt.Scan(&S)

	for i := 0; i < N; i++ {
		if string(S[i]) == "I" {
			res++
		}
		if string(S[i]) == "D" {
			res--
		}
		ans = max(ans, res)
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */
func lcm(x, y uint64) uint64 {
	return (x / gcd(x, y)) * y
}

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}


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

int main(){
    string s1,s2,s3;
    char diff='A'-'a';
    cin>>s1>>s2>>s3;
    printf("%c%c%c\n",s1[0]+diff,s2[0]+diff,s3[0]+diff);
    //cout<<s1[0]+diff<<s2[0]+diff<<s3[0]+diff<<endl;
    return 0;
}

Measured memory_bytes: 256
D = [0, 1, 3, 3, 7, 7, 7, 14, 22, 22, 22, 33, 33, 46, 60, 0]
E = [0, 1, 2, 2, 3, 3, 3,  4,  5,  5,  5,  6,  6,  7,  8, 0]

N = int(input())

s = N//15
t = (60*s)*(s)

m = s*15

t += D[N-m] + 15*E[N-m]*s

print(t)


Measured memory_bytes: 9196
#include <stdio.h>
    #include <math.h>
    
    int main(void){
        double r,f1,f2;

        scanf("%lf",&r);
        f1 = (r*r)*M_PI;
        f2 = 2*r*M_PI;
    
        printf("%lf %lf\n",f1,f2);
    }


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const int EPS = 1e-9;

int main(){
    cin.sync_with_stdio(false);
    int x, n;
    cin >> x >> n;
    if(x < n){
        cout << 0 << endl;
    }else cout << 10 << endl;
    return 0;
}



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

int main(){
  int i,j,cnt=0;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  cnt=1;
  int b[n];
  b[0]=a[0];
  for(i=1;i<n;i++){
     if(a[i-1]!=a[i])b[cnt++]=a[i];
  }
  n=cnt;cnt=1;
  int flg=0;
  for(i=0;i<n-1;i++){
     if(b[i]<b[i+1] && flg==-1){
       cnt++;
       flg=0;
     }
     else if(b[i]>b[i+1] && flg==1){
       cnt++;
       flg=0;
     }
     else if(b[i]<b[i+1] && flg==0){
       flg=1;
     }
     else if(b[i]>b[i+1] && flg==0){
       flg=-1;
     }
  }
  cout<<cnt;
}

Measured memory_bytes: 1024
#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;
int main() {
	int N;
	cin >> N;
	int F[110][12];
	int P[110][15];
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 10; ++j) {
			cin >> F[i][j];
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 11; ++j) {
			cin >> P[i][j];
		}
	}
	ll ans = -10000000000;
	for (int i = 1; i < 1 << 10; ++i) {
		ll sum = 0;
		int k = i;
		vector<int>v(10);
		for (int j = 0; j < 10; ++j) {
			v[j] = k % 2;
			k /= 2;//どの時間帯で働くかを表記
		}
		for (int j = 0; j < N; ++j) {
			int count = 0;
			for (int k = 0; k < 10; ++k) {
				if (v[k]==1 && F[j][k])count++;
			}
			sum += P[j][count];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
	}

Measured memory_bytes: 256
package main

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

var stdInScanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	stdInScanner.Scan()
	i, _ := strconv.Atoi(stdInScanner.Text())
	return i
}

func nextString() string {
	stdInScanner.Scan()
	return stdInScanner.Text()
}

func main() {
	stdInScanner.Split(bufio.ScanWords)

	N := nextInt()

	answer := make([]string, 0)
	for N > 0 {
		N--
		answer = append(answer, string(0x61+(N%26)))
		N /= 26

	}
	for i := len(answer) - 1; 0 <= i; i-- {
		fmt.Print(answer[i])
	}
}


Measured memory_bytes: 1776
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <tuple>
#include <vector>

// lib/quo.hpp
#ifndef QUO_H
#define QUO_H

/*
a == tools:quo(a, b) * b + tools::mod(a, b)
0 <= tools::mod(a, b) < std::abs(b)
*/

namespace tools {
  template <typename T>
  constexpr T quo(const T lhs, const T rhs) {
    return lhs > 0 ? lhs / rhs : rhs > 0 ? -((-lhs - 1 + rhs) / rhs) : (-lhs - 1 + -rhs) / -rhs;
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/extgcd.hpp
#ifndef EXTGCD_HPP
#define EXTGCD_HPP


/*
usage:

std::tuple<int, int, int> result = tools::extgcd(4, 5);
int gcd = std::get<0>(result);
int x0 = std::get<1>(result);
int y0 = std::get<2>(result);
*/

namespace tools {
  template <typename T>
  std::tuple<T, T, T> extgcd(T prev_r, T r) {
    T prev_s = 1;
    T prev_t = 0;
    T s = 0;
    T t = 1;
    while (r != 0) {
      const T q = quo(prev_r, r);
      const T next_r = prev_r - q * r;
      prev_r = r;
      r = next_r;
      const T next_s = prev_s - q * s;
      prev_s = s;
      s = next_s;
      const T next_t = prev_t - q * t;
      prev_t = t;
      t = next_t;
    }
    return std::make_tuple(std::abs(prev_r), prev_s, prev_t);
  }
}

#endif

// main.cpp

int main() {
  i64 K;
  std::cin >> K;

  i64 answer = 0;
  for (i64 a = 1; a <= K; ++a) {
    for (i64 b = 1; b <= K; ++b) {
      for (i64 c = 1; c <= K; ++c) {
        answer += std::get<0>(tools::extgcd(std::get<0>(tools::extgcd(a, b)), c));
      }
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <math.h>
using namespace std;

const int MOD = 1000000007;

long long int perm(int n, int r) {
  r = n - r;
  long long int sum = 1;
  for ( int i=n; i>=r+1; i-- ) {
    sum = (sum * i) % MOD;
  }
  return sum;
}

int main(void)
{
  int n, m;
  long long int c;
  cin >> n >> m;
  if ( abs(n-m) > 1 ) {
    c = 0;
  } else {
    if ( n == m ) {
      c = (perm(n, n) * perm(m, m) * 2) % MOD;
    } else {
      c = (perm(n, n) * perm(m, m)) % MOD;
    }
  }
  
  cout << c << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
#include<iomanip>

using namespace std;

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

	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		cout << "x";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll arr[200][15],money[200][15],ans,res[20],n;
void check(int used[])
{
    int cnt[n+5]= {0};
    for(int i=0; i<10; i++)
    {
        if(used[i])
        {
            for(int j=0; j<n; j++)
            {
                if(arr[j][i])
                    cnt[j]++;
            }
        }
    }
    ll sum=0;
    for(int i=0; i<n; i++)
    {
        sum+=money[i][cnt[i]];
    }
    ans=max(ans,sum);
}
void recur(int pos,int used[])
{
    for(int i=pos; i<10; i++)
    {
        if(!used[i])
        {
            used[i]=1;
            check(used);
            recur(i+1,used);
            used[i]=0;
        }
    }
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n;
    for(int i=0; i<n; i++)
        for(int j=0; j<10; j++)
            cin>>arr[i][j];
    for(int i=0; i<n; i++)
        for(int j=0; j<=10; j++)
            cin>>money[i][j];
    ans=-INT_MAX;
    int used[15]= {0};
    recur(0,used);
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int n, utang, bunga;
int main(){
	utang = 100000;
	cin >> n;
	for(int i = 1; i <= n; i++){
		bunga = utang * 5 / 100;
		if(bunga % 1000 == 0)
			bunga = bunga/1000 * 1000;
		else
			bunga = bunga/1000 * 1000 + 1000;
		
		utang = utang + bunga;
	}
	cout << utang << "\n";
	return 0;
}

Measured memory_bytes: 2972
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
using namespace std;

main()
{
   int N, a[2000001], maxv = 0;
   scanf("%d", &N);

   rep(i, N)
      scanf("%d", a+i),
      maxv = max( maxv, a[i] );

   int cnt[maxv + 1] = {-1};
   int ret[N];

   rep(i, N) ++cnt[ a[i] ];
   reps(i, 1, maxv) cnt[i] += cnt[i-1];

   for(int i=N-1; i>=0; --i){
      int& p = cnt[ a[i] ];
      ret[p] = a[i];
      --p;
   }

   rep(i, N) printf("%d%c", ret[i], i+1 < N ? ' ' : '\n' );
}




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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int r;
  cin >> r;
  cout << r*r << endl;  
  return 0;
}


Measured memory_bytes: 256
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

x = input_a
puts x.find_index(0) + 1


Measured memory_bytes: 14316
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
r = len(s)
t = ''

for l in range(len(s), -1, -1):
  if r - l >= 5:
    if s[l:r] in words:
      t = s[l:r] + t
      r = l

if s == t:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3436
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  for (int i = 0; i < S.length(); i++) {
    putchar('A' + (S[i] + N - 'A') % 26);
  }
  putchar('\n');
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <cmath>
#include <queue>
#include <ctime>
#include <utility> // std::pair
#include <functional> // std::greater <int> ()
#define int long long
#define MAXN 500000 // check
#define inf 1000000000000000001
#define BASE 29 // hashings mod, can be rand'd
#define mod 998244353 // can be 1000000007
#define pi 3.1415926535897
#define pii pair <int, int>
#define fii first
#define see second

typedef long long ll;
typedef long double ld;
using namespace std;

int n, x, t;

// functions
void input(){
	cin >> n >> x >> t;
	return;
}

void solve(){
	cout << n/x*t+(n%x>0)*t;
	return;
}

void output(){
	return;
}

signed main(){
/*
//  REMEMBER TO TURN OFF IFDEF IN PROBLEMS WITH FILE I/O
*/
#ifdef sheeep
	freopen("forces.inp", "r", stdin);
	freopen("forces.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
//	int t;
//	cin >> t;
//	for(int i=1; i<=t; i++){
		input();
		solve();
		output();
//	}
	return 0;
}
// Author: NamSPro

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  string str;
  char s0, sE;
  int len = 0;
  cin >> str;
  len = str.size();
  s0 = str[0];
  sE = str[len - 1];
  cout<<s0<<len-2<<sE<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <stack>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define lMin(a,b)a<b?a:b

using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    ll n; cin >> n;
    ll Min = 10000000000000;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    vector<ll> s(n+1,0);
    rep(i,n) s[i+1] = s[i] + a[i];

    for(int i = 1; i <= n; i ++){
        Min = lMin(Min,abs((s[i]-s[0]) - (s[n]-s[i])));
    }
    cout << Min;
    return 0;
}











Measured memory_bytes: 6424
import java.util.Scanner;

public class Main {
  static int W, H, N;
  static int[] x, y, a;

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

    W = sc.nextInt(); H = sc.nextInt(); N = sc.nextInt();
    x = new int[N]; y = new int[N]; a = new int[N];
    for(int i = 0; i < N; i++){
      x[i] = sc.nextInt();  y[i] = sc.nextInt();  a[i] = sc.nextInt();
    }

    int x0 = 0, y0 = 0, x1 = W, y1 = H;
    for(int i = 0; i < N; i++){
      switch(a[i]){
        case 1:
          x0 = Math.max(x0, x[i]);
          break;
        case 2:
          x1 = Math.min(x1, x[i]);
          break;
        case 3:
          y0 = Math.max(y0, y[i]);
          break;
        case 4:
          y1 = Math.min(y1, y[i]);
          break;
      }
    }

    int S = 0;
    if(x0 < x1 && y0 < y1){
      S = (x1 - x0) * (y1 - y0);
    }

    System.out.println(S);
  }
}


Measured memory_bytes: 10196