akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
    long long A,B;
    cin>>A>>B;
    
    if(A>=B){
        if(A%B==0){
            cout<<A<<endl;
        }
        else{
            for(int i=1;i<A*B+1;i++){
                if(A*i%B==0){
                    cout<<A*i<<endl;
                    break;
                }
            }
        }
    }
    else{
        if(B%A==0){
            cout<<B<<endl;
        }
        else{
            for(int i=1;i<A*B+1;i++){
                if(B*i%A==0){
                    cout<<B*i<<endl;
                    break;
                }
            }
        }
    }
    
}

Measured memory_bytes: 256
/* **********************************JAI SAI RAM ************************************* */
//HELP IN CODEFORCES ROUND 641
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll P=1000000007;
ll MAX=1e15;
ll MIN=-1*(1e15);
ll a[3020],f[3020];
void  solve()
{
    ll n,i,j,k,l,m,o,q,r,t;
    cin>>n;
    if(n%1000!=0)
    cout<<(1000-n%1000);
    else 
    cout<<0<<endl;
}
int main()
{
    ll t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3596
package main

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

func chmax(a *int, b int) bool {
	if *a < b {
		*a = b
		return true
	}
	return false
}

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	var n int
	n, _ = strconv.Atoi(newLine())

	dp := make([][]int, n+10)
	for i := 0; i < n+10; i++ {
		dp[i] = make([]int, 3)
	}
	//fmt.Println(dp)
	var inputLine []string
	temp := make([]int, 3)
	for i := 1; i < n+1; i++ {
		inputLine = strings.Split(newLine(), " ")
		for j := 0; j < 3; j++ {
			temp[j], _ = strconv.Atoi(inputLine[j])
		}
		//fmt.Println(temp)

		for j := 0; j < 3; j++ {
			//fmt.Println((j + 1) % 3)
			chmax(&dp[i][j], dp[i-1][(j+1)%3]+temp[j])
			chmax(&dp[i][j], dp[i-1][(j+2)%3]+temp[j])
		}
		//fmt.Println(dp)
	}

	ans := dp[n][0]
	if ans < dp[n][1] {
		ans = dp[n][1]
	}
	if ans < dp[n][2] {
		ans = dp[n][2]
	}
	fmt.Println(ans)
}


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

int main(){
	ios::sync_with_stdio(false);
	
	int i,j,n,q;
	int count=0;
	
	cin >> n;
	vector<int> S(n);
	for (i=0;i<n;i++){
		cin >> S[i];
	}
	cin >> q;
	int T[q];
	for (i=0;i<q;i++){
		cin >> T[i];
	}
	
	for (j=0;j<q;j++){
		for (i=0;i<n;i++){
			if(S[i]==T[j]){
				count++;
				break;
			}
		}
	}
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll k,n;cin>>k>>n;
    ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
    ll ans = a[n-1] - a[0];
    for(ll i=1;i<n;i++){
        ll val = a[n-1] - a[i] + k - a[n-1] + a[i-1];
        ans = min(ans , val);
    }
    cout<<ans;
}


Measured memory_bytes: 1792
def main():
    days = int(input())
    falliness = [int(x) for x in input().split()]
    satisfactions = [0]  # Never use index 0.
    for _ in range(days):
        satisfactions.append([int(x) for x in input().split()])
    types = []
    for _ in range(days):
        types.append(int(input()))

    last = [0] * 26
    sat = 0
    for date, typ in enumerate(types):
        date += 1
        typ -= 1
        last[typ] = date
        sat += satisfactions[date][typ]
        sat -= sum(falliness[i] * (date - last[i]) for i in range(26))
        print(sat)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9368
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  vector<string> S(h); rep(i, h) cin >> S[i];
  int n = h*w;
  mcf_graph<int, ll> G(n+2);
  auto id = [&](int i, int j) {
    return i*w+j;
  };
  int s = n, t = n+1;
  ll ans = 0;
  rep(i, h) rep(j, w) {
    if(S[i][j] == '#') continue;
    int cur = id(i, j);
    if(S[i][j] == 'o') {
      G.add_edge(s, cur, 1, 0);
      ans += (h-i-1) + (w-j-1);
    }
    G.add_edge(cur, t, 1, (h-i-1) + (w-j-1));
    if(i+1 < h && S[i+1][j] != '#') G.add_edge(cur, id(i+1, j), 100, 0);
    if(j+1 < w && S[i][j+1] != '#') G.add_edge(cur, id(i, j+1), 100, 0);
  }
  auto ret = G.flow(s, t);
  ans -= ret.second;
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 4248
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int h,w,n;cin >> w >> h >> n;
    vector<vector<int>> a(h);
    for (int i = 0; i < n; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        a[y].pb(x);
    }
    for (int i = 0; i < h; i++) {
        a[i].pb(w);
        sort(ALL(a[i]));
    }
    int ans = w;
    int x = 0;
    int t = 0;
    int p = 0;
    for (int i = 0; i < h; i++) {
        if(x>=w) break;
        if(t < a[i].size()){
            ans = min(ans,a[i][t]);
            p = a[i][t];
        }
        if(i+1<h){
            t = 0;
            x++;
            while(t<a[i+1].size()&&a[i+1][t]<x){
                t++;
            }
            while(t<a[i+1].size()&&a[i+1][t]==x){
                t++;
                x++;
            }
            if(x >= p) break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11392
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
int main(){
  int kazu = 0;
  int as,bs,ag,bg;
  cin >> kazu >> as >> bs >> ag >> bg;
  string masu;
  cin >> masu;
  int kotae = 0;
  int iwa = 0;
  for(int i = as - 1;i <= max(ag,bg) - 1;i++){
    if(masu[i] == '#'){
      iwa++;
    }
    else{
      iwa = 0;
    }
    if(iwa >= 2){
      kotae = 1;
      i = max(ag,bg);
    }
  }
  if(kotae == 0 && ag > bg){
    int ikeru = 0;
    int nukeruka = 0;
    for(int i = bs - 2;i <= bg;i++){
      if(masu[i] == '.'){
        ikeru++;
      }
      else{
        ikeru = 0;
      }
      if(ikeru >= 3){
        nukeruka = 1;
        i = ag;
      }
    }
    if(nukeruka == 0){
      kotae = 1;
    }
  }
  if(kotae == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

struct 
{ 
	int i, p; 
} E[500005];
int A[500005], D[500005], P[500005]{}, F[500005]{}, T[500005]{}, N, Q;
int main() 
{
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	cin >> N >> Q;
	
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
	}
	int K = 0;
	for(int i=0;i<Q;i++)
	{
		int l, r;
		cin>>l>>r; --l, --r;
		E[i+1]={l, F[r]}, F[r]=i+1;
	}
	for(int r=0;r<N;r++)
	{
		int x=A[r]-1;
		if(P[x])
		{ 
			for(int j=P[x]; j<=N; j+=j&-j)
			{
				T[j]--;
			}
		}
		else 
		{
			K++;
		}
		for(int j=P[x]=r+1; j<=N; j+=j&-j) 
		{
			T[j]++;
		}
		for(int k=F[r]; k; k=E[k].p) 
		{
			D[k]=K;
			for(int j=E[k].i; j; j-=j&-j)
			{ 
				D[k]-=T[j];
			}
		}
	}
	for(int i=0;i<Q;i++)
	{
		cout<<D[i+1]<<'\n';
	}

	return 0;
}


Measured memory_bytes: 17380
#include <stdio.h>
#include <math.h>
int main() {
	int N, I;
	double h, m, a;
	scanf("%d", &N);
	for(I = 0; I < N; ++ I) {
		scanf("%lf:%lf", &h, &m);
		h = 30 * h + m / 2;
		m = 6 * m;
		a = fabs(((m - h) < 0)? fmod(((m - h) - 180), 360) + 180: fmod(((m - h) + 180), 360) - 180);
		if(a < 30) printf("alert\n");
		else if(a < 90) printf("warning\n");
		else printf("safe\n");
	}
	return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	scanf("%d",&n);
	if(n<=599)
		k=8;
	else if(n<=799)
		k=7;
	else if(n<=999)
		k=6;	
	else if(n<=1199)
		k=5;
	else if(n<=1399)
		k=4;
	else if(n<=1599)
		k=3;	
	else if(n<=1799)
		k=2;
	else if(n<=1999)
		k=1;
	printf("%d",k);	
 } 

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

int main()
{
	int D,T,S;
	cin >> D >> T >> S;
	if (S * T >= D) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3620
n, m = map(int,input().split())
pay = [[] for i in range(m+1)]
for i in range(n):
    a, b = map(int,input().split())
    if a <= m:
        pay[a].append(b)


import heapq as hq 
ans = 0
stack = []
for i in range(m+1):
    for j in pay[i]:
        hq.heappush(stack, -j)
    ans -= hq.heappop(stack) if stack else 0

print(ans)

Measured memory_bytes: 18328
#include<bits/stdc++.h>
//#include<atcoder/all>

typedef long long ll;

using namespace std;

int main(){
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1;i < n;i ++){
        ans += (n-1)/i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;

int main(){
    int n;
    std::cin >> n;
    ll x[3][n];
    ll dp[3][n];
    rep(i,n){
        std::cin >> x[0][i] >> x[1][i] >> x[2][i];
    }
    dp[0][0]=x[0][0];
    dp[1][0]=x[1][0];
    dp[2][0]=x[2][0];
    for(int i=1;i<n;++i){
        dp[0][i]=x[0][i]+std::max(dp[1][i-1],dp[2][i-1]);
        dp[1][i]=x[1][i]+std::max(dp[0][i-1],dp[2][i-1]);
        dp[2][i]=x[2][i]+std::max(dp[0][i-1],dp[1][i-1]);
    }
    std::cout << std::max(dp[0][n-1],std::max(dp[1][n-1],dp[2][n-1])) << std::endl;
    return 0;
}


Measured memory_bytes: 4992
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc126/tasks/abc131_c

def gcd(a, b):
    while b > 0:
        tmp = a
        a = b
        b = tmp % b
    return a

def lcm(a, b):
    return a // gcd(a, b) * b

def f(x, c, d):
    res = x
    res -= x // c 
    res -= x // d 
    res += x // lcm(c, d)
    return res

a, b, c, d = map(int, input().strip().split())
res = f(b, c, d) - f(a-1, c, d)
print(int(res))


Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<ll> a(n);
	ll cnt=0;
	rep(i,n){
		cin>>a[i];
		cnt+=a[i];
	}
	vector<ll> b(a);
	sort(begin(b),end(b));
	vector<ll> sum(n+1,0);
	rep(i,n) sum[i+1]=sum[i]+b[i];
	vector<ll> ans(n,0);
	ll now=0;
	rep(i,n){
		if(now<a[i]){
			int ind=upper_bound(begin(b),end(b),a[i])-begin(b);
			ll ncnt=sum[n]-sum[ind]-a[i]*(n-ind);
			ans[i]=cnt-ncnt;
			cnt=ncnt;
			now=a[i];
		}
	}
	cout<<ans<<endl;
}

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

const int maxn = 200010;
int n, m, ans, s[maxn], f[maxn];
pair<int, int> p[maxn];

struct SEG {
#define mid (l + r >> 1)
#define ls (k << 1)
#define rs (k << 1 | 1)
    int mx[maxn << 2];
    SEG() { memset(mx, -0x3f, sizeof(mx)); }
    void modify(int k, int l, int r, int p, int v) {
        if (l == r) { mx[k] = v; return; }
        if (mid >= p) modify(ls, l, mid, p, v);
        else modify(rs, mid + 1, r, p, v);
        mx[k] = max(mx[ls], mx[rs]);
    }
    int qmax(int k, int l, int r, int ql, int qr) {
        if (l >= ql && r <= qr) return mx[k];
        int ans = -0x3f3f3f3f;
        if (mid >= ql) ans = qmax(ls, l, mid, ql, qr);
        if (mid < qr) ans = max(ans, qmax(rs, mid + 1, r, ql, qr));
        return ans;
    }
} t1, t2;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &s[i]);
        s[i] ? ans++ : s[i] = -1;
        s[i] += s[i - 1];
    }
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
        scanf("%d %d", &p[i].first, &p[i].second);
    }
    sort(p + 1, p + m + 1);
    auto chk = [&](int &x, int y) {
        if (x < y) x = y;
    };
    memset(f, -0x3f, sizeof(f));
    for (int i = 1; i <= m; i++) {
        int t = p[i].first == 1 ? 0 : t1.qmax(1, 1, n, 1, p[i].first - 1);
        chk(f[p[i].second], max(0, t) + s[p[i].second] - s[p[i].first - 1]);
        t = t2.qmax(1, 1, n, p[i].first, p[i].second);
        chk(f[p[i].second], t + s[p[i].second]);
        t1.modify(1, 1, n, p[i].second, f[p[i].second]);
        t2.modify(1, 1, n, p[i].second, f[p[i].second] - s[p[i].second]);
    }
    printf("%d\n", ans - max(0, *max_element(f + 1, f + n + 1)));
    return 0;
}

Measured memory_bytes: 9600
#include<stdio.h>

int main(void){
	int R;
	do{
		scanf("%d", &R);
	}while(R <= 0 && R >= 4208);

	if (R < 1200)	printf("ABC\n");

	else if (R < 2800)	printf("ARC\n");

	else	printf("AGC\n");

	return 0;
}

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

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

Measured memory_bytes: 3068
/*
* ID: juryc
* PROG: Snake
* LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lcm(a,b) ((a)*(b))/(__gcd(a,b))
int main(){
ll a,b; cin>>a>>b;
cout<<lcm(a,b)<<endl; 
return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

int main(){
	int n;
	cin >> n;
	vector<string> s(n);
	REP(i,n) cin >> s[i];
	
	map<char,ll> m;
	REP(i,n) m[s[i][0]]++;
	
	ll ans = 0;
	char a[5] = {'M','A','R','C','H'};
	for(int i=0; i<5; i++){
		for(int j=i+1; j<5; j++){
			for(int k=j+1; k<5; k++){
				ans += m[a[i]]*m[a[j]]*m[a[k]];
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 6364
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
map<ll,bool> mp;
int main(){
ll n,d,a;
cin>>n>>d>>a;
V<ll> x(n),h(n);
V<P> dd(n);
for(int i=0;i<n;i++){
    cin>>x[i]>>h[i];
    if(mp[x[i]])exit(1);
    mp[x[i]]=1;
    dd[i].fi=x[i];dd[i].se=h[i];
}
ll ans=0,now=0;
V<ll> t(n+1,0);
sort(all(x));
sort(all(dd));
for(int i=0;i<n;i++){
    now-=t[i];
    if(dd[i].se-now<=0)continue;
    int it=upper_bound(all(x),x[i]+2*d)-x.begin();
    ans+=(dd[i].se-now+a-1)/a;
    t[it]+=(dd[i].se-now+a-1)/a*a;
    now+=(dd[i].se-now+a-1)/a*a;
}
cout<<ans<<endl;
}


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

int main() {
	double x;
	string u;
	double btc = 380000.0;
	
	double ans = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x >> u;
		if (u == "JPY") {
			ans += x;
		}
		else {
			ans += x * btc;
		}
	}
	printf("%.14f\n", ans);
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())

card = [[] for _ in range(n)]

for _ in range(m):
    x, y, _ = map(int, input().split())
    card[x-1].append(y-1)
    card[y-1].append(x-1)

checked = [False] * n

count = 0
for i in range(n):
    if checked[i]:
        continue
    count += 1
    q = [i]
    while q:
        j = q.pop()
        checked[j] = True
        for k in card[j]:
            if not checked[k]:
                q.append(k)
print (count) 

Measured memory_bytes: 97760
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(AtCoder: str, s: str, Contest: str):
    print("A"+s[0]+"C")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    AtCoder = next(tokens)  # type: str
    s = next(tokens)  # type: str
    Contest = next(tokens)  # type: str
    solve(AtCoder, s, Contest)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7; // change if needed

struct Modint {
  ll val;
  
  Modint (ll _val = 0)
    : val(_val % MOD) {}

  Modint operator+ (Modint other) const {
    return Modint(val + other.val);
  }

  void operator+= (Modint other) {
    val += other.val;
    val %= MOD;
  }

  Modint operator- () const {
    return Modint(MOD - val);
  }

  Modint operator- (Modint other) const {
    return Modint(val + MOD - other.val);
  }

  void operator-= (Modint other) {
    val += MOD - other.val;
    val %= MOD;
  }

  Modint operator* (Modint other) const {
    return Modint(val * other.val);
  }

  void operator*= (Modint other) {
    val *= other.val;
    val %= MOD;
  }

  bool operator== (Modint other) const {
    return val == other.val;
  }

  bool operator!= (Modint other) const {
    return val != other.val;
  }
};

Modint exp (Modint a, int k) {
  if (k == 0) {
    return Modint(1);
  } else if (k % 2 == 0) {
    Modint half = exp(a, k / 2);
    return half * half;
  } else {
    return a * exp(a, k - 1);
  }
}

Modint inv (Modint a) {
  return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
  out << p.val;
  return out;
}


const int MAX_N = 55;

Modint choose [MAX_N][MAX_N];
Modint dp [MAX_N][MAX_N][MAX_N][MAX_N];

int main () {
  choose[0][0] = Modint(1);
  for (int i = 1; i < MAX_N; i++) {
    choose[i][0] = Modint(1);
    for (int j = 1; j < MAX_N; j++) {
      choose[i][j] = choose[i - 1][j - 1] + choose[i - 1][j];
    }
  }
  
  int n;
  cin >> n;

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  
  dp[0][1][0][n] = Modint(1);
  for (int t = 0; t < n; t++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; i + j <= n; j++) {
        for (int l = i + j; l <= n; l++) {
          if (dp[t][i][j][l] == Modint(0)) continue;
          // cerr << t << " " << i << " " << j << " " << l << ": " << dp[t][i][j][l] << endl;
          for (int ni = 0; ni < n; ni++) {
            for (int k = 0; k <= i + j; k++) {
              int kp = i + j - k;
              int dnj = 2 * ni - i + j + k - kp;
              if (dnj % 2 != 0) continue;
              int nj = dnj / 2;
              if (i == 0 && j == 0 && ni + nj > 0) continue;
              if (nj < 0 || n <= nj || l - i - j < ni + nj) continue;
              dp[t + 1][ni][nj][l - i - j] += dp[t][i][j][l] * choose[l][k] * choose[l - k][kp];
              /*
              if (t + 1 == 2 && ni == 1 && nj == 1 && l - i - j == 2) {
                cerr << " " << t << " " << i << " " << j << " " << l << " " << k << " "
                     << kp << ": " << dp[t][i][j][l] * choose[l][k] * choose[l - k][kp] << endl; 
              }
              */
              //cerr << t + 1 << " " << ni << " " << nj << " " << l - i - j << endl;
            }
          }
        }
      }
    }
  }

  cout << dp[n][0][0][0] << endl;
}


Measured memory_bytes: 75140
import java.util.*;

public class Main {

    public static int lcs(String s0, String s1) {
        if (s0.length() == 0)
            return 0;
        else if (s1.length() == 0)
            return 0;
        else;
            int[][] cache = new int[s0.length() + 1][s1.length() + 1];
            for(int i = 1; i <= s0.length(); i++) {
                for(int j = 1; j <= s1.length(); j++) {
                    int left  = cache[i][j - 1];
                    int top   = cache[i - 1][j];
                    int diag  = cache[i - 1][j - 1];
                    diag     += s0.charAt(i-1) - s1.charAt(j-1) == 0? 1 : 0;
                    cache[i][j] = Math.max(left, Math.max(top, diag));
                }
            }
            return cache[s0.length()][s1.length()];
    }
    
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        for(int i = 0; i < count; i++) {
            System.out.println(lcs(sc.next(), sc.next()));
        }
        sc.close();
    }
}



Measured memory_bytes: 63964
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define mci map<char,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf 10000000000000000ll
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define eps 1e-7
#define endl "\n"
/*ll gcd(ll a,ll b){if(a==0){return b;}return gcd(b%a,a);}
ll modexp(ll x,ll y,ll p)
{ll res=1;x%=p;while(y){if(y&1){res=(res*x)%p;}y=y>>1;x=(x*x)%p;}return res;}
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    if(n<=9)
    {
        cout<<n<<"\n";
    }
    else
    {
        if(n<=99)
        {
            cout<<9<<"\n";
        }
        else
            if(n<=999)
        {
            cout<<9+(n-99)<<"\n";
        }
        else
            if(n<=9999)
        {
            cout<<909<<"\n";
        }
        else
            if(n<=99999)
        {
            cout<<909+(n-9999)<<"\n";
        }
        else
            cout<<90909<<"\n";
    }

    return 0;

    /*check for long long or int*/
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> aij(H, vector<char>(W));
  vector<bool> row(H,false);
  vector<bool> col(W,false);

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> aij.at(i).at(j);
      if(aij.at(i).at(j)=='#'){
        row.at(i) = true;
        col.at(j) = true;
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
    if(row.at(i)){
      for (int j = 0; j < W; j++) {
        if(col.at(j)){
          cout << aij.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
n = int(input())
p = []
for i in range(n):
    x , y = input().split()
    y = int(y)
    p.append([i+1,x,y])

p.sort(key=lambda x: x[2], reverse=True)
p.sort(key=lambda x: x[1])
for i in range(n):
    print(p[i][0])


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d",6-a-b);
}

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

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

vector<int> a(N), b(N), c(N);
for(int i = 0; i < N; i++){ 
     cin >> a[i];
     cin >> b[i];
     cin >> c[i];
}

vector<int> da(N), db(N), dc(N);

da[0] = a[0];
db[0] = b[0];
dc[0] = c[0];

for(int i = 1; i < N; i++){ 
     da[i] = a[i] + max(db[i - 1], dc[i - 1]);
     db[i] = b[i] + max(da[i - 1], dc[i - 1]);
     dc[i] = c[i] + max(db[i - 1], da[i - 1]);
}

int ans = max(da[N - 1], max(db[N - 1], dc[N - 1]));
cout << ans << endl;

}

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

int main(){
    long A, B, N;
    cin >> A >> B >> N;

    long a = min(B-1, N);

    long b = (A*a)/B;

    cout << b << endl; 
}

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

using namespace std;

const int N = 1e5 + 10;

int dp[N][3];
int nums[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	
	int a, b, c;
	for(int i = 1; i <= n; i++) {
		cin >> a >> b >> c;
		dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a;
		dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b;
		dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c;
	}
	cout << max({dp[n][0], dp[n][1], dp[n][2]}) << "\n";
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> as(3);
  for (int i = 0; i < 3; i++) { cin >> as.at(i); }
  sort(as.begin(), as.end());
  cout << as.at(2) - as.at(0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,d[N],u[N],v[N],w[N],i,e[N];
char c[N];
void E(){puts("-1");exit(0);}
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)scanf("%d",d+i);memset(c+1,-1,n);
	for(i=1;i<=m;++i)scanf("%d%d",u+i,v+i),e[i]=i,w[i]=max(d[u[i]],d[v[i]]);
	sort(e+1,e+m+1,[&](int x,int y){return w[x]<w[y];});
	for(i=1;i<=m;++i){
		int x=u[e[i]],y=v[e[i]];
		if(c[x]==-1 && c[y]==-1){
			if(d[x]!=d[y])E();
			c[x]=0;c[y]=1;
		}else if(c[x]==-1 || c[y]==-1){
			if(c[x]==-1){
				if(d[x]<d[y])E();
				c[x]=c[y]^1;
			}else{
				if(d[y]<d[x])E();
				c[y]=c[x]^1;
			}
		}else w[e[i]]=1e9;
	}
	for(i=1;i<=n;++i)if(c[i]==-1)E();
	for(i=1;i<=n;++i)putchar(c[i]==0?'W':'B');puts("");
	for(i=1;i<=m;++i)printf("%d\n",w[i]);
}

Measured memory_bytes: 6528
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[100005]={0};
int main(void)
{
    int i,n,ans=0;
    scanf("%d",&n);
    for(i=1;i<=n;++i)scanf("%d",&a[i]);
    for(i=1;i<n;++i)
    {
        if(a[i]==i)++ans,swap(a[i],a[i+1]);
    }
    for(i=n;i>1;--i)
    {
        if(a[i]==i)++ans,swap(a[i],a[i-1]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    cin >> N;

    vll A(N);
    rep(i, N)
    {
        cin >> A[i];
    }

    int count = 0;
    rep(i, N)
    {
        if (A[i] < 0)
        {
            count++;
            A[i] *= -1;
        }
    }

    sort(all(A), greater<ll>());

    ll ans = 0;
    rep(i, N - 1) ans += A[i];

    if (count % 2 == 0)
    {
        ans += A.back();
    }
    else
    {
        ans -= A.back();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3988
#include<vector>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int inf = 987654321;

// ツ氾アツ閉可づ個鳴ウツ古シツグツδ可フツづ可妥篠つオツ、ツタツーツミツナツδ逆sツづ個要ツ素ツづーツ全ツづ甘慊づ楪催渉ャツづ個姪伉づ個コツスツトツづーツ仰づ淞づゥ
#define REP(i, N) for(int i = 0; i < (int)(N); ++i)

const int MAX_N = 150;
int g[MAX_N][MAX_N];
int minimum_steiner_tree(int n, const vector<int> ts) {
  static int dp[1 << 12][MAX_N];
  memset(dp, 0, sizeof(dp));
  int m = ts.size();
  if( m < 2 ) return 0;

  REP(k, n) REP(i, n) REP(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  REP(i, m) REP(j, n) dp[1 << i][j] = g[ts[i]][j];

  for(int i = 1; i < 1 << m; i++) if((i - 1) & i) {
      REP(j, n) {
        dp[i][j] = inf;
        for(int k = (i - 1) & i; k > 0 ; k = (k - 1) & i)
          dp[i][j] = min(dp[i][j], dp[k][j] + dp[i ^ k][j]);
      }
      REP(j, n) REP(k, n) dp[i][j] = min(dp[i][j], dp[i][k] + g[k][j]);
    }
  return dp[(1 << m) - 1][ts[0]];
}

int main() {
  for(int R, C; cin >> R >> C, (R || C); ) {
    REP(i, MAX_N) REP(j, MAX_N) g[i][j] = inf;
    REP(i, MAX_N) g[i][i] = 0;

    int table[R][C];
    REP(r, R) REP(c, C) cin >> table[r][c];

    const int dr[] = {0, 1, -1, 0};
    const int dc[] = {1, 0, 0, -1};
    REP(r, R) REP(c, C) REP(k, 4) {
      int nr = r + dr[k];
      int nc = c + dc[k];
      if( 0 <= nr && nr < R && 0 <= nc && nc < C )
        g[r * C + c][nr * C + nc] = 1;
    }
    vector<int> ts;
    REP(r, R) REP(c, C) if( table[r][c] == 1 ) ts.push_back(r * C + c);

    int temp = minimum_steiner_tree(R * C, ts);
    cout << R * C - temp - 1 << endl;
  }
}

Measured memory_bytes: 3400
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    struct Kuchen {
        int64_t x;
        int64_t y;
        int64_t z;
    };

    std::vector<Kuchen> K;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t x, y, z;
        std::cin >> x >> y >> z;
        K.push_back({x, y, z});
    }

    int64_t ans = INT64_MIN;

    for (uint32_t i = 0; i < 1 << 3; ++i) {
        std::vector<int64_t> points;
        for (auto k: K) {
            auto x = (i & 0x4) ? k.x : -k.x;
            auto y = (i & 0x2) ? k.y : -k.y;
            auto z = (i & 0x1) ? k.z : -k.z;

            points.push_back(x+y+z);
        }
        std::partial_sort(std::begin(points), std::begin(points) + M, std::end(points), [](auto l, auto r) {
                return l > r;
            });

        int64_t sum = std::accumulate(std::begin(points), std::begin(points) + M, 0LL);
        ans = std::max(ans, sum);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 200005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
ll sqr(ll x)
{
    return x*x;
}
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;  cin>>n;
    vl v(n);  f(n)cin>>v[i];
    sort(all(v));
    ll mid = (n/2);
    ll val  = v[mid-1];
    ll val2 = v[mid];
    cout << val2 - val;

    return 0;
}
    


Measured memory_bytes: 1024
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func perm(a []int) chan []int {
	ch := make(chan []int)

	var rec func(a []int, r []int)
	rec = func(a []int, r []int) {
		if len(a) == 0 {
			ch <- r
		}
		for i := 0; i < len(a); i++ {
			var na []int
			for j := 0; j < i; j++ {
				na = append(na, a[j])
			}
			for j := i + 1; j < len(a); j++ {
				na = append(na, a[j])
			}
			rec(na, append(r, a[i]))
		}
	}

	go func() {
		rec(a, []int{})
		close(ch)
	}()

	return ch
}

func main() {
	defer stdout.Flush()

	N := readInt()
	M := readInt()
	R := readInt()
	r := make([]int, R)
	for i := range r {
		r[i] = readInt()
	}
	G := make([][]int, N+1)
	for i := range G {
		G[i] = make([]int, N+1)
		for j := range G[i] {
			G[i][j] = math.MaxInt32
		}
	}
	for i := 0; i < M; i++ {
		a := readInt()
		b := readInt()
		c := readInt()
		if c < G[a][b] {
			G[a][b] = c
			G[b][a] = c
		}
	}

	for k := 1; k <= N; k++ {
		for i := 1; i <= N; i++ {
			for j := 1; j <= N; j++ {
				d := G[i][k] + G[k][j]
				if d < G[i][j] {
					G[i][j] = d
				}
			}
		}
	}
	//println(G)

	ans := math.MaxInt32
	for s := range perm(r) {
		//println(s)
		var tmp int
		for i := 0; i+1 < len(s); i++ {
			tmp += G[s[i]][s[i+1]]
		}
		ans = minInt(ans, tmp)
	}
	println(ans)
}


Measured memory_bytes: 3072
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
 
int main() {
    int N, K;
    scanf("%d", &N);
    scanf("%d", &K);
    
    char S[N];
    scanf("%s", S);
    
    if(S[K-1] == 'A'){
        S[K-1] = 'a';
    } else if(S[K-1] == 'B'){
        S[K-1] = 'b';
    } else if(S[K-1] == 'C'){
        S[K-1] = 'c';
    }
    
    printf("%s\n", S);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define int long long
#define P pair<int,int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'

int fibo[50];

signed main() {
    int n;
    cin >> n;
    memset(fibo,0,sizeof(fibo));
    fibo[0] = 1;
    fibo[1] = 1;
    for(int i = 2; i <= n; i++){
        fibo[i] = fibo[i-1] + fibo[i-2];
    }
    cout << fibo[n] << endl;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<pi>
#define size(a)  (int)(a.size())
#define fill(s,x,n) vector
 x(n); rep(i,0,n) cin>>x[i];
#define mod 1000000007
#define inf 1000000005
void solve(){
    int n;
    cin>>n;
    fill(double,p,n);
    double ans=0;
    vector<vector<double>> dp(n+1, vector<double> (n+1,1));
    for(int i=1; i<=n; i++){
        for(int j=0; j<=i; j++){
            dp[i][j] = (j>0?dp[i-1][j-1]*p[i-1]:0) + (i>=j+1?dp[i-1][j]*(1-p[i-1]):0);
            //cout<<dp[i][j];
            if(i==n && j>n/2){
                ans+=(dp[n][j]);
            } 
        }
    }
    cout<<fixed<<setprecision(10)<<ans;

}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);  
    #endif
    */
    int test;
    //cin>>test;
    test=1;
    //int cse=1;
    while(test--){
         //cout<<"Case #"<<cse<<": ";
         solve();
         cout<<endl;
         //cse++;
    }
    return 0;
}


Measured memory_bytes: 141056
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define in insert
#define rep(i,a,b) for(int i = a ; i < b ; i++)
#define repr(i,a,b) for(int i = b ; i > a ; i--)

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

signed main(){
    fast;
    int n, ans=0;
    cin >> n;
    string s;
    cin >> s;
    set<int> r, g, b;
    rep(i,0,n){
        if(s[i]=='R')
            r.insert(i);
        if(s[i]=='G')
            g.insert(i);
        if(s[i]=='B')
            b.insert(i);
    }
    ans+=r.size()*g.size()*b.size();
    for(auto i: r){
        for(auto j: g){
            if(b.count(max(i,j)+abs(i-j)))
                ans--;
            if(b.count(min(i,j)-abs(i-j)))
                ans--;
            if((i+j)%2==0 && b.count((i+j)/2))
                ans--;
        }
    }
    cout << ans ;
}

Measured memory_bytes: 3764
#include<iostream>
using namespace std;
#include<map>
#include<vector>
#include<cmath>
#define int long long int
int power(int a,int b)
{
	int x=pow(a,b);
	return x;
}
int solve(int val)
{
	int j;
	if(val>0)
	{
		int sum=0;
		for(j=0;;j+=2)
		{
			sum+=power(2,j);
			if(sum>=val)
			{
				return j;
			}
		}
	}
	else
	{
		int sum=0;
		val*=-1;
		for(j=1;;j+=2)
		{
			sum+=power(2,j);
			if(sum>=val)
			{
				return j;
			}
		}
	}
}
int32_t main()
{
     int n,k;
     cin>>n>>k;
     if(n%k==0)
        cout<<0<<endl;
     else
       cout<<1<<endl;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 200100;
long long n, a[N], b[N], ans;
priority_queue <pair<long long, long long>  > pq;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n;
	for(long long i = 0; i < n; i++)
		cin >> a[i];

	for(long long i = 0; i < n; i++) {
		cin >> b[i];
		if(b[i] != a[i])
			pq.push({b[i], i});
	}

	while(!pq.empty()) {
		auto p = pq.top();
		pq.pop();
		long long nxt = max({a[p.nd], b[(n + p.nd - 1) % n] , b[(p.nd + 1) % n]});
		// dbg(p);
		long long dif = p.st - nxt;
		dif /= (b[(n + p.nd - 1) % n] + b[(p.nd + 1) % n]);
		dif = max(dif, 1LL);
		ans += dif;
		p.st -= dif * (b[(n + p.nd - 1) % n] + b[(p.nd + 1) % n]);
		if(p.st != a[p.nd])
			pq.push(p);
		
		if(p.st < a[p.nd]) return cout << "-1\n", 0;
		b[p.nd] = p.st;
	}
	cout << ans << '\n';
}	


Measured memory_bytes: 9072
N = int(input())
A = [int(i) for i in input().split(" ")]
Min = float("inf")
index = 0
L = 0
R = sum(A)
for i in range(0,len(A)):
    L+=A[i]
    R-=A[i]
    diff = abs(L - R)
    if diff < Min:
        Min = diff
print(Min)

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


void solve(){
    int n;
    cin>>n;
    vector<int> heights(n);
    for(int i=0;i<n;i++){
        cin>>heights[i];
    }

    vector<int> dp(n, -1);
    dp[0] = 0;
    dp[1] = abs(heights[1] - heights[0]);
    for(int i=2;i<n;i++){
        dp[i] = min (  (dp[i-2] + abs(heights[i] - heights[i-2])) , (dp[i-1] + abs(heights[i] - heights[i-1])));
    }

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


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 t;
    t = 1;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3972
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [n] <- readInts
  inputs <- readInts
  print $ solve n inputs

solve :: Int -> [Int] -> Int
solve n inputs =
  case foldl' func (0, replicate n 0, 0) uniqsort of
    (count, _, _) -> count
  where
    func (count, !s, prevh) h = (count + countconseq h * d, map (+ d) s, h)
      where d = h - prevh
    countconseq h = fst $ foldl' countconseqfunc (0, False) inputs
      where
        countconseqfunc (count, flag) x =
          if flag
            then if x >= h then (count, True) else (count, False)
            else if x >= h then (count + 1, True) else (count, False)
    uniqsort = sort $ nub inputs

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

toTup2 :: [[a]] -> [(a, a)]
toTup2 = map (\ys -> case ys of y : z : zs -> (y, z))

encIdx2 :: Int -> (Int, Int) -> Int
encIdx2 mx (y, x) = y * mx + x

decIdx2 :: Int -> Int -> (Int, Int)
decIdx2 mx idx = (idx `div` mx, idx `mod` mx)

encIdx3 :: (Int, Int) -> (Int, Int, Int) -> Int
encIdx3 (my, mx) (z, y, x) = z * my * mx + y * mx + x

decIdx3 :: (Int, Int) -> Int -> (Int, Int, Int)
decIdx3 (my, mx) idx = (z, y, x)
  where
    basez = my * mx
    z = idx `div` basez
    y = (idx `mod` basez) `div` mx
    x = idx `mod` mx

while :: Monad m => m Bool -> m () -> m ()
while cond body = do
  b <- cond
  when b $ do
    body
    while cond body


Measured memory_bytes: 508
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i = 1; i <= N; i++) {
			map.put(i, sc.nextInt());
		}
		int cnt = 0;
		boolean can = false;
		for (int i = 1; cnt < N;) {
			cnt++;
			i = map.get(i);
			if (i ==  2) {
				can = true;
				break;
			}
		}
		if (can) {
			System.out.println(cnt);
		} else {
			System.out.println(-1);
		}
	}
}


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

char toupr(char c) {
  return (c - 0x20);
}

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << toupr(s1.at(0)) << toupr(s2.at(0)) << toupr(s3.at(0)) << "\n";
}

Measured memory_bytes: 256