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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

ll pow_mod(ll a, ll n, ll p)
{
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res*a%p;
        a = a*a%p;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll MOD)
{
    ll b = MOD, u = 1, v = 0;
    while(b){
        ll t = a/b;
        a -= t*b;   swap(a,b);
        u -= t*v;   swap(u,v);
    }
    u %= MOD;
    if(u < 0) u+= MOD;
    return u;
}

int main()
{
    ll MOD = 1e9+7;
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    unordered_map<ll,ll> mp;
    vector<map<ll,ll>> vmp(n);
    for(i = 0;i < n;++i){
        ll tmp = a.at(i);
        ll sn = sqrt(tmp);
        vector<pair<ll,ll>> insuu;
        ll so = 2;
        ll num = 0;
        while(true){
            if(tmp%so == 0){
                tmp /= so;
                ++num;
            }else{
                if(num != 0){
                    insuu.emplace_back(so,num);
                    num = 0;
                }
                ++so;
            }
            if(tmp == 1){
                insuu.emplace_back(so,num);
                break;
            }
            if(so > sn){
                insuu.emplace_back(tmp,1);
                break;
            }
        }
        for(auto x:insuu){
            vmp.at(i)[x.first] = x.second;
            if(mp.count(x.first)){
                if(mp[x.first] < x.second) mp[x.first] = x.second;
            }else{
                mp[x.first] = x.second;
            }
        }
    }
    ll ans = 0;
    ll lsd = 1;
    for(auto x:mp){
        ll so = x.first;
        ll num = x.second;
        ll tmp = pow_mod(so, num, MOD);
        lsd *= tmp;
        lsd %= MOD;
    }
    unordered_map<ll,ll> somap;
    for(i = 0;i < n;++i){
        ll tmp = lsd;
        for(auto x:vmp.at(i)){
            ll so =  x.first;
            ll num = x.second;
            ll tmp2;
            if(somap.count(so)){
                tmp2 = somap[so];
            }else{
                tmp2 = modinv(so, MOD);
                somap[so] = tmp2;
            }
            ll tmp3 = pow_mod(tmp2, num, MOD);
            tmp *= tmp3;
            tmp %= MOD;
        }
        ans += tmp;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3968
from collections import Counter
N = int(input())
x = []
for _ in range(N):
    x.append(input())
c = Counter(x)
print("AC x {}".format(c["AC"]))
print("WA x {}".format(c["WA"]))
print("TLE x {}".format(c["TLE"]))
print("RE x {}".format(c["RE"]))

Measured memory_bytes: 16612
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	denom := 1
	for i := n; i >= 1; i-- {
		denom *= i
	}

	arrx := make([]int, n)
	arry := make([]int, n)

	for i := 0; i < n; i++ {
		arrx[i] = sc.NextInt()
		arry[i] = sc.NextInt()
	}

	sum := 0.0
	//	magic := float64((n - 1) * 2)
	magic := 1.0
	for i := n - 1; i >= 1; i-- {
		magic *= float64(i)
	}
	magic *= 2
	//	fmt.Printf("%+v\n", magic) // output for debug

	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			tmp := math.Sqrt(
				float64((arrx[i]-arrx[j])*(arrx[i]-arrx[j])) +
					float64((arry[i]-arry[j])*(arry[i]-arry[j])))
			//			fmt.Printf("%+v\n", tmp) // output for debug

			sum += tmp * magic
		}
	}
	fmt.Printf("%v\n", sum/float64(denom))

}

/*
	tmp := math.Sqrt(
		float64((arrx[i]-arrx[j])*(arrx[i]-arrx[j])) +
			math.Sqrt(float64((arry[i]-arry[j])*(arry[i]-arry[j]))))
*/

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import itertools
n = int(input())
p = "".join([i for i in input().split(" ")])
q = "".join([i for i in input().split(" ")])
yes = "".join([str(i) for i in range(1, n+1)])
perms = sorted(list(set(["".join(i) for i in list(itertools.permutations(yes))])))
a = perms.index(p)
b = perms.index(q)
print(abs(a-b))

Measured memory_bytes: 10868
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	vector<ll> b(n);
	REP(i,n) cin>>a[i];
	REP(i,n) cin>>b[i];
	set<ll>  s;
	REP(i,n) s.insert(b[i]);
	if((ll)s.size()==n) cout<<"Yes"<<endl;
	else {
		cout<<"No"<<endl;
		REP(i,n) {
			if(s.count(i+1)==0) {
				REP(j,n) {
					if(a[j]!=i+1) cout<<1;
					else cout<<n-1;
					if(j==n-1) cout<<endl;
					else cout<<" ";
				}
				REP(j,n) {
					if(a[j]!=i+1) cout<<1;
					else cout<<n;
					if(j==n-1) cout<<endl;
					else cout<<" ";
				}
				return 0;
			}
		}
	}
}



Measured memory_bytes: 9088
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    dica = {}
    for i in range(n):
        if a[i] in dica:
            dica[a[i]] += 1
        else:
            dica[a[i]] = 1
    count = list(dica.values())
    total = list(map(lambda x: x*(x-1)/2, count))
    sumtotal = sum(total)

    for i in range(n):
        test = a[i]
        valuetest = dica[test]
        subtract = valuetest*(valuetest-1)/2
        add = (valuetest-1)*(valuetest-2)/2
        print(int((sumtotal-subtract+add)))
resolve()

Measured memory_bytes: 91596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    
    ll now=1;
    rep(i,N){
        if(A[i]==now) now++;
    }
    
    if(now==1) cout<<-1;
    else cout<<N-(now-1);
}



Measured memory_bytes: 4828
function main(input){
  const lines = input.split('\n');
  const S = lines.shift().split('');
  const T = lines.shift().split('');

  dp = []
  for(var i=0;i<=S.length;i++){
    dp.push( Array(T.length+1).fill(0) );
  }

  for(var i=1;i<=S.length;i++){
    for(var j=1;j<=T.length;j++){
      if(S[i-1]==T[j-1]){
        dp[i][j]=Math.max(dp[i][j], dp[i-1][j-1]+1);
      }else{
        dp[i][j]=Math.max(dp[i-1][j], dp[i][j-1]);
      }
    }
  }

  var i = S.length;
  var j = T.length;
  var result = [];
  while(i!=0 &&  j!=0){
    if(S[i-1]==T[j-1]){
      result.unshift(S[i-1]);
      i--;
      j--;
    }else{
      if(dp[i-1][j] < dp[i][j-1]){
        j--;
      }else{
        i--;
      }
    }
  }

  console.log(result.join(''));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n, m;
    int a[50], b[50];
    cin >> n >> m;
    for (int i = 0; i < m; i++)
        cin >> a[i] >> b[i];

    int cnt = 0;
    for (int i = 0; i < m; i++)
    {
        int arr[51][51];
        for (int j = 1; j <= n; j++)
        {
            for (int k = 1; k <= n; k++)
            {
                if (j == k)
                    arr[j][k] = 0;
                else
                    arr[j][k] = INF;
            }
        }
        for (int j = 0; j < m; j++)
        {
            if (j != i)
            {
                arr[a[j]][b[j]] = 1;
                arr[b[j]][a[j]] = 1;
            }
        }

        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= n; k++)
                for (int l = 1; l <= n; l++)
                    arr[k][l] = min(arr[k][l], arr[k][j] + arr[j][l]);

        for (int j = 1; j <= n; j++)
            if (arr[1][j] == INF)
            {
                cnt++;
                break;
            }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int mat1[10000] = { 0 };
	int mat2[100] = { 0 };
	int c[100] = { 0 };
	int n, m;
	int i, j;

	scanf("%d %d", &n, &m);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%d", &mat1[i * m + j]);
		}
	}
	for (j = 0; j < m; j++)
	{
		scanf("%d", &mat2[j]);
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			c[i] += mat1[i * m + j] * mat2[j];
		}
		printf("%d\n", c[i]);
	}

	return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 0; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;

int  main()
{
	int n; cin >> n;
	set <int> st;
	rep(i, n)
	{
		char c; cin >> c;
		st.insert(c);
	}
	if (st.size() == 4)
		cout << "Four\n";
	else
		cout << "Three\n";
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

const ll MOD=1'000'000'007;

ll mpow(ll x,ll n){
    if(n==0) return 1;
    else if(n%2) return x*mpow(x,n-1)%13;
    return mpow(x*x%13,n/2)%13;
}

string S;
ll length;
ll dp[13];

int main(){
    cin>>S;
    length=S.size();

    for(int i=length-1;i>=0;i--){
        ll m[13];
        fill(m,m+13,0);
        ll p10=mpow(10,(length-1)-i);
        if(S[i]!='?'){
            ll x=S[i]-'0';
            m[x*p10%13]++;
        }else{
            rep(j,10){
                m[j*p10%13]++;
            }
        }
        ll res[13];
        fill(res,res+13,0);
        if(i==length-1){
            rep(i,13){
                res[i]=m[i];
            }
        }else{
            rep(i,13){
                rep(j,13){
                    if(m[i]!=0 && dp[j]!=0) res[(i+j)%13]+=(m[i]*dp[j])%MOD;
                }
            }
        }
        rep(i,13){
            dp[i]=res[i];
        }
    }

    ll ans=dp[5]%MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 512
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll S = 0;

    cin >> S;

    //入力
    //出力
    ll dp[S];
    dp[0]=0;
    dp[1]=0;
    dp[2]=1;

    for(int i = 3; i<S;i++){
        dp[i]=(dp[i-1]+dp[i-3])%MOD;
        dp[i]%=MOD;
    }
    cout << dp[S-1];
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}



Measured memory_bytes: 3660
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    x = int(readline())

    for a in range(-120, 120):
        for b in range(-120, 120):
            if a**5 - b**5 == x:
                print(a, b)
                exit()


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
import sys
 
stdin = sys.stdin

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

a, b, c = na()
print(min(b // a, c))

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;


void enqueue( P x ){
	strcpy( Q[tail].name, x.name);
	Q[tail].t = x.t;

	tail++;
	if(tail>LEN) tail = 0;
	n++;
}

P dequeue(){

	int ptr = head;

	if(head==tail) NULL;
	
	head++;
	if(head>LEN) head = 0;
	n--;
	return Q[ptr];
}


int main(){
 	int elaps = 0, c;
 	int i, q;
 	P u;

	//
	head = 1;
	tail = 1;
 
	scanf("%d %d", &n, &q);

 	for ( i = 1; i <= n; i++){
 		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
		tail++;
	}


	while( n != 0){

		u = dequeue();
		
		if( u.t > q ){
			u.t = u.t - q;
			enqueue( u );
			elaps += q;
		}else{
			elaps += u.t;
			printf( "%s %d\n", u.name, elaps );
		}

	}

  	return 0;
}

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

int main()
{
	int n;
	int a,b;
	int c;
	int s[101];
	int x,y;


	cin >> n;
	
	cin >> a >> b;
	cin >> c;

	for(int i=1 ;i<n+1 ;i++){
		cin >> s[i];

	}
	for(int i=1 ;i<n+1 ;i++){
		for(int j=1 ;j<n+1 ;j++){
			if(s[i] > s[j]){
				x = s[i];
				s[i] = s[j];
				s[j] = x;
			}
		}
	}

	x = c;
	y = a;

	for(int i=1 ;i<n+1 ;i++){
		if((x / y) > ((x+s[i])/(y+b)))
			break;

		else{
			x += s[i];
			y += b;
		}
	}
	cout << x / y << endl;
	
             return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <string>
#include <cmath>
using namespace std;

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


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007

using namespace std;

int main(void){
  int a, b;

  cin >> a >> b;
  
  if (a < 10 && b < 10)
    cout << a * b << endl;
  else
    cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 256
<?php
define('MOD', 10 ** 9 + 7);
list($n) = ints();
$a = ints();
// 先頭を赤に固定して考える
$cnt = [0, 0, 0];
$ans = 1;
for ($i = 0; $i < $n; ++$i) {
    $tmp = 0;
    for ($k = 0; $k < 3; ++$k) {
        if ($a[$i] === $cnt[$k]) {
            $tmpk = $k;
            ++$tmp;
        }
    }
    ++$cnt[$tmpk];
    $ans = ($ans * $tmp) % MOD;
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 25908
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int n, m, r;
int city[10], order[10];
int dis[210][210];
int a, b, c;
long long ans = 0x3f3f3f3f, now;
int main()
{
	scanf("%d%d%d", &n, &m, &r);
	for (int i = 1; i <= r; i++)
		order[i] = i, scanf("%d", &city[i]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			dis[i][j] = 0x3f3f3f3f;
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d%d", &a, &b, &c);
		dis[b][a] = min(dis[b][a], c);
		dis[a][b] = dis[b][a]; 
	}
	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
	do
	{
		now = 0;
		for (int i = 1; i < r; i++)
			now += dis[city[order[i]]][city[order[i + 1]]];
		ans = min(ans, now);
	} while (next_permutation(order + 1, order + 1 + r));
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#define for1(i,a,b) for(int i=a;i<=b;++i)
#define for2(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
long long a,b,c,d;
inline long long gcd(long long a,long long b){return !b?a:gcd(b,a%b);}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	std::ios::sync_with_stdio(false);
	cin>>a>>b>>c>>d;
	long long q1=c*d/gcd(c,d),q2=b/q1-(a-1)/q1;
	cout<<b-a+1-b/c+(a-1)/c-b/d+(a-1)/d+q2;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n;
vector<int> G[MAX];
int col[MAX], cnt[2] = {0, 0}, ans[MAX];
pii p[MAX];

void dfs(int v, int pv, int c){
    col[v] = c;
    ++cnt[c];
    p[v] = {v, c};
    for(int nv: G[v])if(nv != pv){
        dfs(nv, v, c ^ 1);
    }
}

int main(){
    scanf("%d", &n);
    rep(i, n-1){
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1, 0);
    sort(p, p+n, [&](const pii &a, const pii &b){
        return cnt[a.se] == cnt[b.se] ? a.se > b.se : cnt[a.se] > cnt[b.se];
    });

    int s = div_ceil(n, 3), t = div_ceil(n-1, 3);
    memset(ans, 0, sizeof(ans));
    if(cnt[p[0].se] >= s + t){
        rep(i, s) ans[p[i].fi] = 1;
        rep(i, t) ans[p[i+s].fi] = 2;
    }
    else if(max(cnt[0], cnt[1]) >= s && min(cnt[0], cnt[1]) >= t){
        rep(i, s) ans[p[i].fi] = 1;
        rep(i, t) ans[p[i+max(cnt[0], cnt[1])].fi] = 2;
    }
    else{
        puts("-1");
        return 0;
    }

    for(int i=0, a=3, b=0, c=0; i<n; ++i){
        if(ans[i] == 0) ans[i] += a, a += 3;
        else if(ans[i] == 1) ans[i] += b, b += 3;
        else ans[i] += c, c += 3;
    }
    rep(i, n) printf("%d ", ans[i]);
}

Measured memory_bytes: 20608
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<deque>
#include<map>
#include<queue>
#define mod 1000000007
#define maxn 200010
using namespace std;
typedef long long ll;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
struct P{
    int x,v;
}p[maxn];
bool cmp(P a,P b)
{
    if(a.v!=b.v)  return a.v<b.v;
    return a.x<b.x;
}
int s[maxn],top;
struct X{
    int l,r;
}a[maxn];
bool cmpx(X x,X y)
{
    if(x.r!=y.r)   return x.r<y.r;
    return x.l<y.l;
}
int sum[maxn],f[maxn],ans;
int main()
{
    n=read();
    for(int i=1;i<=n;i++)  p[i].x=read(),p[i].v=read();
    sort(p+1,p+n+1,cmp);
    for(int i=1;i<=n;i++)
    {
        if(!top||p[i].x>p[s[top]].x)  s[++top]=i;
        int l=1,r=top;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(p[s[mid]].x>=p[i].x)
            {
                a[i].l=s[mid];
                r=mid-1;
            }
            else l=mid+1;
        }
    }
    top=0;
    for(int i=n;i>=1;i--)
    {
        if(!top||p[i].x<p[s[top]].x)  s[++top]=i;
        int l=1,r=top;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(p[s[mid]].x<=p[i].x)
            {
                a[i].r=s[mid];
                r=mid-1;
            }
            else l=mid+1;
        }
    }
    sort(a+1,a+n+1,cmpx);
    int pos=0;
    for(int i=1;i<=n;i++)
    {
        while(pos<n&&a[pos+1].r<a[i].l-1)  pos++;
        f[i]=(sum[i-1]-sum[pos]+mod)%mod;
        if(a[i].l==1)  f[i]=(f[i]+1)%mod;
        if(a[i].r==n)  ans=(ans+f[i])%mod;
        sum[i]=(sum[i-1]+f[i])%mod;
    }
    cout<<ans<<endl;
    return 0;
}

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


int main(){
	int N;
	cin>>N;
	set<string> s;
	string S[N];
	for(int i=0;i<N;i++){
		cin>>S[i];
		s.insert(S[i]);
	}
	if(s.size()!=N){
		cout<<"No"<<endl;
		return 0;
	}
	
	for(int i=1;i<N;i++){
		if(S[i][0]!=S[i-1][S[i-1].size()-1]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	
	cout<<"Yes"<<endl;
	
	return 0;
}

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<int> A;
    void input() {
        cin >> N;
        A.resize(N); cin >> A;
    }

    void solve() {
        int c = 0;
        vector<int> stack;
        stack.push_back(0);
        for (auto a : A) {
            while (stack.back() > a) {
                stack.pop_back();
            }
            if (stack.back() == a) continue;
            if (stack.back() < a) {
                stack.push_back(a);
                c++;
            }
        }
        cout << c << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

Measured memory_bytes: 4588
from collections import deque
from copy import deepcopy
n, m = map(int, input().split())
tree = [[] for i in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
result = 0
visit = [-1 for _ in range(n+1)]
visit[1] = 1
q = deque([[1, deepcopy(visit)]])
while q:
    p, v = q.pop()
    if v[p] == n:
        result += 1
    for j in tree[p]:
        if v[j]<0:
            next_v = deepcopy(v)
            next_v[j] = next_v[p]+1
            q.appendleft([j, next_v])
print(result)

Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
#define all(a) a.begin(), a.end()
#define show(ans)  cout << ans << endl;
const long MOD = 1000000007;


int main() {long N;
cin >> N;
vector<long> a(N+1);
erep(i, N){
    cin >> a[i];
    a[i] = a[i] - i;
} 
long b;
sort(a.begin()+1, a.end());
if(N % 2 == 0){
    b = a[N/2];
}
else b = a[(N+1)/2];
long ans = 0;
erep(i, N){
    ans += abs(b-a[i]);
}
show(ans);




  return 0;
 
}



Measured memory_bytes: 1792
var
    a,b,c,i,j,z:longint;
    s:array[1..100000]of string;
    k:array[1..100000]of longint;
    ans:qword;
begin
    read(a,b,c);
    for i:=1 to a do
    begin
        str(i,s[i]);
        for j:=1 to length(s[i]) do
        begin
            val(s[i][j],z);
            k[i]:=k[i]+z;
        end;
        if(k[i]>=b)and(k[i]<=c)then inc(ans,i); 
    end;
    writeln(ans);
end.


Measured memory_bytes: 1088
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
	
		Scanner stdIn = new Scanner(System.in);
		
		byte n = stdIn.nextByte();
		
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = stdIn.nextInt();
		}
		int total = 0;
		
		for (int i = 0; i < n; i++) {
			for (int j = 1; j < n; j++) {
				if (p[i] < p[j]) {
					p[i] = p[i] + p[j];
					p[j] = p[i] - p[j];
					p[i] = p[i] - p[j];
				}
			}
		}
	
		p[0] /= 2;
		
		for (int i = 0; i < n; i++) {
			total += p[i];
		}
		
		System.out.println(total);
		
	}
}

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

typedef long long ll;
char a[15];
ll v[100], cnt[10];
ll n, ans;

int main()
{
    ll i, j, k;

    cin >> n;
    for(i=0; i<n; i++)
    {
        cin >> a;
        v[a[0]]++;
    }

    cnt[0]=v['M'];
    cnt[1]=v['A'];
    cnt[2]=v['R'];
    cnt[3]=v['C'];
    cnt[4]=v['H'];

    for(i=0; i<5; i++)
        for(j=i+1; j<5; j++)
            for(k=j+1; k<5; k++)
                ans+=cnt[i]*cnt[j]*cnt[k];

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
typedef long long LL;

LL a,b;
int ans=1;

LL Gcd(LL x,LL y) {
	return y==0?x:Gcd(y,x%y);
}
int main() {
	scanf("%lld %lld",&a,&b);
	LL g=Gcd(a,b);
	for(LL i=2;i*i<=g;i++)
		if(g%i==0) {
			while(g%i==0)
				g/=i;
			ans++;
		}
	if(g!=1) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

int par[100100];
int rank1[100100];

void init(int n)
{
    for(int i = 0; i < n; i++){
        par[i] = i;
        rank1[i] = 0;
    }
}

int find(int x)
{
    if(par[x] == x){
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x == y){
        return ;
    }
    if(rank1[x] , rank1[y]){
        par[x] = y;
    } else {
        par[y] = x;
        if(rank1[x] == rank1[y]){
            rank1[x]++;
        }
    }
}

bool same(int x, int y)
{
    return find(x) == find(y);
}
int main() {
    //cout.precision(10);
    int n, m;
    cin >> n >> m;
    long long ans = 0;
    init(n);
    long long a[100100];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= m; i++){
        int in1, in2;
        cin >> in1 >> in2;
        unite(in1, in2);
    }
    for(int i = 0; i < n; i++){
        int dust = find(i);
    }
    vector<int> connected[100100];
    for(int i = 0; i < n; i++){
        connected[par[i]].push_back(a[i]);
    }
    int needed = 2 * (n - 1 - m);
    if(needed == 0){
        cout << 0 << endl;
        return 0;
    }
    /*for(int i = 0; i < n; i++){
        cout << "connected to " << i << endl;;
        for(int j = 0; j < connected[i].size(); j++){
            cout << connected[i][j] << endl;
        }
    }*/
    vector<int> rest;
    for(int i = 0; i < n; i++){
        if(connected[i].empty()){
            continue;
        }
        sort(connected[i].begin(), connected[i].end());
        ans += connected[i][0];
        needed--;
        for(int j = 1; j < connected[i].size(); j++){
            rest.push_back(connected[i][j]);
        }
    }
    sort(rest.begin(), rest.end());
    if(needed <= 0){
        if(needed % 2 == 0){
            cout << ans << endl;
            return 0;
        }
        if(rest.empty()){
            cout << "Impossible" << endl;
            return 0;
        }
        cout << ans + rest[0] << endl;
        return 0;
    }
    int k = 0;
    while(needed > 0){
        if(k >= rest.size()){
            cout << "Impossible" << endl;
            return 0;
        }
        ans += rest[k];
        k++;
        needed--;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    int i;
    long long int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<a[n-1]-a[0]<<endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n string
	fmt.Scan(&n)
	switch n {
	case "A":
		fmt.Println("T")
	case "T":
		fmt.Println("A")
	case "C":
		fmt.Println("G")
	case "G":
		fmt.Println("C")
	}
}


Measured memory_bytes: 512
#include <stdio.h>

#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196L
int main()
{
	double r = 0.0, enshu = 0.0, menseki = 0.0;
	scanf("%lf", &r);
	enshu = 2 * PI * r;
	menseki = PI * r * r;

	printf("%f %f\n", menseki, enshu);

	return 0;
}

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


using namespace std;


int main() {
    int K, N;

    cin >> K >> N;
    vector<int> A(N);
    vector<int> P(N);

    for (int i = 0; i < N; ++i) {
        cin >> A.at(i);
        P.at(i) = i;
    }
    
    int dist = 0, dist_sum = 0;
    int max_d = 0;

    const int left0 = abs(A.at(N - 1) - A.at(0));
    dist = min(left0, K - left0);
    dist_sum += dist;
    max_d = max(max_d, dist);


    for (int j = 1; j < N; ++j) {
        const int left = abs(A.at(j) - A.at(j - 1));
        dist = min(left, K - left);
        dist_sum += dist;
        max_d = max(max_d, dist);
    }


    cout << dist_sum - max_d << endl;
}


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

using namespace std;

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

const double pi = 3.14159265358979323846;

#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define VL vector< ll >

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

  ll a, b;
  cin >> a >> b;

  for (int i = 1; i <= 3; i++) {
    if (a * b * i % 2 == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;

int main(){
    //    cout<<fixed<<setprecision(2);
//cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
string s;
cin>>s;
if(s=="ABC"){cout<<"ARC";}
else{cout<<"ABC";}
}



Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	string s;
	cin>>s;
	if(s.length()>=4&&s.substr(0,4)=="YAKI")cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int c[100];
long long q[51];
int main(){
	long long n,p;cin>>n>>p;
	long long a=0,b=0;
	long long cnt=1;
	for(int i=0;i<51;i++){
		q[i]=cnt;
		cnt*=2;
	}
	for(long long i=0;i<n;i++){
		cin>>c[i];
		if(c[i]%2==0)b++;
		else a++;
	}
	if(p==0){
		if(a==0)cout<<q[n]<<endl;
		else cout<<q[n-1]<<endl;
	}
	else{
		if(a==0)cout<<"0"<<endl;
		else cout<<q[n-1]<<endl;
	}
	return 0;
}


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

int main(){
   int H, W;
   std::cin >> H >> W;

   std::vector<std::string> S(H);
   for(int i=0; i<H; ++i)
      std::cin >> S[i];

   int dx[8] = {-1,0,1,-1,1,-1,0,1};
   int dy[8] = {1,1,1,0,0,-1,-1,-1};
   int ans[H][W];
   for(int i=0; i<H; ++i){
      for(int j=0; j<W; ++j)
	 ans[i][j] = 0;
   }

   for(int i=0; i<H; ++i){
      for(int j=0; j<W; ++j){
	 if(S[i][j]=='#'){
	    for(int k=0; k<8; ++k){
	       int x = j + dx[k];
	       int y = i + dy[k];
	       if(x>=0 && x<W && y>=0 && y<H){
		  ++ans[y][x];
	       }
	    }
	 }
      }
   }
   for(int i=0; i<H; ++i){
      for(int j=0; j<W; ++j){
	 if(S[i][j]=='#') std::cout << '#';
	 else std::cout << ans[i][j];
      }
      std::cout << std::endl;
   }
   return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
string s;cin>>s;
int n=s.size();
rep(i,n)s[i]='x';
cout<<s<<endl;
}

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

int main() {

  int long long A,B,t=1;
  int long long ans=0;
  
  cin >> A >> B;

  ans=A*B;

  if (A<B)
  {
    t=A;
    A=B;
    B=t;
  }
  t=A%B;
  while (t!=0)
  {
    A=B;
    B=t;
    t=A%B;
  }
  
  ans=ans/B;
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;



int main() {
    

    long a,b;
    int k;
    cin >> a >> b >> k;
    for (int i=0;i<k;i++){
        if(i%2 == 0) {
            if (a % 2 == 1) {
                a -= 1;
            }
            a /= 2;
            b += a;
        }else {
            if (b % 2 == 1) {
                b -= 1;
            }
            b /= 2;
            a += b;
        }
    }
    cout << a << " " << b << endl;


}

Measured memory_bytes: 256
/* Coached by rainboy */
#include <stdio.h>
#include <stdlib.h>

#define INF 0x3f3f3f3f

char cc[64];
int cnt;

void encode(int n) {
	if (n == 0)
		return;
	if (n % 2 == 0) {
		encode(-n / 2);
		cc[cnt++] = '0';
	} else {
		encode(-(n - 1) / 2);
		cc[cnt++] = '1';
	}
}

int main() {
	int n;

	scanf("%d", &n);
	if (n == 0) {
		printf("0\n");
		return 0;
	}
	encode(n);
	printf("%s\n", cc);
	return 0;
}


Measured memory_bytes: 128
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, C, K, *T = map(int, read().split())
T.sort()

def main(N, C, K, T):
    INF = K + 100
    time = -INF
    people = 0
    bus = 0
    for t in T:
        if t > time + K:
            time = t
            people = 1
            bus += 1
            continue
        if people < C:
            # 乗れる
            people += 1
        else:
            # 乗れない
            time = t
            people = 1
            bus += 1
    return bus

print(main(N, C, K, T))

Measured memory_bytes: 18332
#include <stdio.h>

int F[50];

int fibonacci(int a){
	if (F[a] != 0)
		return F[a];
	if (a <= 1)
		return 1;
	return F[a] = fibonacci(a-1) + fibonacci(a-2);
}

int main(void) {
	int n;
	scanf("%d", &n);
	printf("%d\n",fibonacci(n));

	return 0;
}




Measured memory_bytes: 2112
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define M 301
#define MA 1e9+1

using namespace std;

int dis[M][M];

int main()
{
	int n, m, l;
	
	cin >> n >> m >> l;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			dis[i][j] = MA;

	for (int i = 1; i <= m; i++)
	{
		int from, to, cost;
		cin >> from >> to >> cost;
		dis[from][to] = dis[to][from] = cost;
	}

	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (dis[i][j] <= l)
				dis[i][j] = 1;
			else
				dis[i][j] = MA;

	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);

	int q;
	cin >> q;
	for (int i = 1; i <= q; i++)
	{
		int from, to;
		cin >> from >> to;
		if (dis[from][to] == MA)
			cout << -1 << endl;
		else
			cout << dis[from][to] - 1 << endl;
	}

	return 0;
}

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

using namespace std;

int n;
int x[100001], y[100001], t[100001];

int dist(int i, int j) {
	return (abs(x[i]-x[j]) + abs(y[i]-y[j]));
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}
	t[0] = 0;
	x[0] = 0;
	y[0] = 0;

	bool works = true;
	for (int i = 0; i < n; i++) {
		if (dist(i, i+1) > t[i+1] - t[i]) {
			works = false;
			break;
		} else if (((t[i+1]-t[i])-dist(i, i+1))%2 != 0) {
			works = false;
			break;
		}
	}

	if (works) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define fast_io              \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(), (c).end()
#define PRESENT(c, x) ((c).find(x) != (c).end())
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define REP(i, start, end) FOR(i, start, end + 1)
#define SQ(x) (x) * (x)
#define PII pair<int, int>

typedef long long LL;
using namespace std;

const int N = 1e5 + 5;
vector<int> h(N), cost(N, INT_MAX);

int main()
{
    fast_io;
    int n;
    cin >> n;
    FOR(i, 0, n)
    cin >> h[i];
    cost[0] = 0;

    FOR(i, 0, n)
    {
        if (i + 1 < n)
            cost[i + 1] = min(cost[i + 1], cost[i] + abs(h[i] - h[i + 1]));
        if (i + 2 < n)
            cost[i + 2] = min(cost[i + 2], cost[i] + abs(h[i] - h[i + 2]));
    }

    cout << cost[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
     int N;
    int a[1100000];
    cin >> N ;
    long int res = 0;
    for(int i=0;i<N*3;++i) cin >> a[i];
    sort(a,a+(N*3),greater<int>());
    for(int i = 0;i < N * 2;++i){
      if((i + 1) % 2 == 0) {
          res += a[i];
      }
    }
    cout << res << endl;
}

Measured memory_bytes: 4744
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace A_MSOL2020
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            int n = s[0];
            int ans = 0;
            if (n<600){
                ans = 8;
            }else if (n<800){
                ans = 7;
            }else if (n<1000){
                ans = 6;
            }else if (n<1200){
                ans = 5;
            }else if (n<1400){
                ans = 4;
            }else if (n<1600){
                ans = 3;
            }else if ( n<1800){
                ans = 2;
            }else{
                ans = 1;
            }
            WriteLine(ans);
        }

        public static int LowerBound<T>(T[] a, T v)
        {
            return LowerBound(a, v, Comparer<T>.Default);
        }

        public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res == -1) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
        public static int UpperBound<T>(T[] a, T v)
        {
            return UpperBound(a, v, Comparer<T>.Default);
        }

        public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res <= 0) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
    }
}


Measured memory_bytes: 28036
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    N, K = MAP()

    ans = 0
    for i in range(N):
        point = i + 1
        cnt = 0
        while point * (2 ** cnt) < K:
            cnt += 1
        ans += 1/N/(2**cnt)

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 39536
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int d[25][25][25][25];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, 20) rep(j, 20) rep(k, 20) rep(l, 20) d[i][j][k][l] = 1e9;
	rep(i, h) cin >> s[i];
	rep(i, h) rep(j, w) if(s[i][j] == '.') d[i][j][i][j] = 0;
	rep(i, h) rep(j, w) if(s[i][j] == '.'){
		rep(k, 4){
			int x = dx[k] + i;
			int y = dy[k] + j;
			if(x >= 0 && x < h && y >= 0 && y < w && s[x][y] == '.'){
				d[i][j][x][y] = 1;
			}
		}
	}
	rep(k, h) rep(k1, w) rep(i, h) rep(i1, w) rep(j, h) rep(j1, w) if(s[k][k1] == '.' && s[i][i1] == '.' && s[j][j1] == '.'){
		d[i][i1][j][j1] = min(d[i][i1][j][j1], d[i][i1][k][k1] + d[k][k1][j][j1]);
	}
	int ans = 0;
	rep(i, h) rep(j, w) rep(k, h) rep(l, w){
		if(s[i][j] == '.' && s[k][l] == '.'){
			if(d[i][j][k][l] != 1e9) ans = max(ans, d[i][j][k][l]);
		}
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1280
<?php
// Here your code !
    $a = str_split(trim(fgets(STDIN)));
    $input = str_split(trim(fgets(STDIN)));
    $x = 0;
    $max = 0;
    foreach ($input as $value) {
        if($value == "I"){
            $x++;
            if($x>$max){
                $max = $x;
            }
        } elseif($value == "D") {
            $x--;
        }
//        echo "x:",$x," max:",$max,PHP_EOL;
    }
    
    echo $max;
?>

Measured memory_bytes: 3700
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
using namespace std;

int inf = INT_MAX;
//int inf = LLONG_MAX;

long long int res[100001];
long long int n, m;

string s;

#define MAX_N 100001

//union-findここから-------------
int par[MAX_N];
int uf_rank[MAX_N];
long long int uf_size[MAX_N];

void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        uf_rank[i] = 0;
        uf_size[i] = 1;
    }
}

//根
int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}

//併合
void unite(int x, int y)
{
    x = find(x);
    y = find(y);

    if (x == y)
    {
        return;
    }

    if (uf_rank[x] < uf_rank[y])
    {
        par[x] = y;
        uf_size[y] += uf_size[x];
    }
    else
    {
        par[y] = x;
        uf_size[x] += uf_size[y];
        if (uf_rank[x] == uf_rank[y])
        {
            uf_rank[x]++;
        }
    }
}

//同じ集合か判定
bool same(int x, int y)
{
    return find(x) == find(y);
}

//木のサイズ取得
long long int get_size(int x)
{
    x = find(x);
    return uf_size[x];
}

//union-findここまで-------------

vector<int> a, b;

int main()
{
    cin >> n >> m;

    for (int i = 0; i < m; i++)
    {
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        a.push_back(tmp1 - 1);
        b.push_back(tmp2 - 1);
    }

    init(n);

    long long int tmp = 0;

    res[m - 1] = n * (n - 1) / 2;

    for (int i = m - 2; i >= 0; i--)
    {
        if (!same(a[i + 1], b[i + 1]))
        {
            res[i] = res[i + 1] - get_size(a[i + 1]) * get_size(b[i + 1]);
            unite(a[i + 1], b[i + 1]);
        }
        else
        {
            res[i] = res[i + 1];
        }
    }

    for (int i = 0; i < m; i++)
    {
        cout << res[i] << endl;
    }
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
string alp = "abcdefghijklmnopqrstuvwxyz";

int main(){ 
	long long n;
	cin >> n;
	string ans = "";

	while(n > 26){
		ans += alp[(n % 26 - 1 < 0 ? 25 : n % 26 - 1)];
		n -= (n % 26 - 1 < 0 ? 25 : n % 26 - 1);
		n /= 26;
	}

	ans += alp[(n - 1 < 0 ? 25 : n - 1)];

	reverse(ans.begin(), ans.end());

	cout << ans;

}

Measured memory_bytes: 3628