akhauriyash/Code-Regression huggingface dataset:
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

func bitCount(n uint) int {

        x := uint64(n)

        const m = 1<<64 - 1
        const m0 = 0x5555555555555555
        const m1 = 0x3333333333333333
        const m2 = 0x0f0f0f0f0f0f0f0f

        x = x>>1&(m0&m) + x&(m0&m)
        x = x>>2&(m1&m) + x&(m1&m)
        x = (x>>4 + x) & (m2 & m)
        x += x >> 8
        x += x >> 16
        x += x >> 32

        return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
        return ((n >> uint(i)) & 1) == 1
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()

        spl := strSprit(line)
        N := parseInt(spl[0])
        M := parseInt(spl[1])

        sum := make([]int, M+1)
        for i := 0; i < N; i++ {
                l := nextLine()
                n := intSprit(l)
                for j := 1; j <= n[0]; j++ {
                        sum[n[j]]++
                }
        }

        r := 0
        for i := 1; i <= M; i++ {
                if sum[i] == N {
                        r++
                }
        }
        fmt.Println(r)
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
vector<int> G[300000];
int64_t dist[100001];
bool visited[100001];
map<pair<int,int>,int64_t> p;
void dfs(int k){//地点kから距離を探索
    visited[k]=true;
    rep(i,G[k].size()){//kの隣接点を探索
        int next = G[k][i];
        if(!visited[next]){//まだ探索してない
            dist[next] = dist[k] + p[mp(next,k)];
            dfs(next);
        }
    }
}
int main(){
    int n;
    cin>>n;
   vector<int> a(n),b(n),c(n);
    rep(i,n-1){
        cin >> a[i]>>b[i]>>c[i];
        a[i]--,b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
        p[mp(a[i],b[i])]=c[i];
        p[mp(b[i],a[i])]=c[i];
    }
    rep(i,n){
        visited[i]=false;
    }
    int q,k;
    cin>>q>>k;
    k--;
    dist[k]=0;
    dfs(k);
    rep(i,q){
        int x,y;
        cin>>x>>y;
        x--,y--;
        cout<<dist[x]+dist[y]<<endl;
    }
}

Measured memory_bytes: 40296
import collections
N,K=map(int,input().split())
a=list(map(int,input().split()))
c=collections.Counter(a)
l=len(c)
c=list(c.items())
c.sort(key=lambda x: x[1])
ans=0
for i in c:
  if l<=K:
    break
  ans+=i[1]
  l-=1
print(ans)

Measured memory_bytes: 41336
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=998244353;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};


ll l[1000010];
ll r[1000010];


int main(){
    int N,K;
    vector<pair<ll,ll>> v(10);
    cin >> N >> K;
    v.resize(K);
    rep(i,K) {
	ll l,r;
	cin >> l >> r;
	v[i] = make_pair(l,r);
    }

    ll cuml = 0;
    ll cumr = 0;
    for(auto itr : v) {
	l[1+itr.first] += 1;
	r[1+itr.second+1] += 1;
    }

//    rep(i,N) {cout << l[i+1] - r[i+1] << endl;}
    
    for(int i=1; i<=N; i++) {
	cuml += l[i];
	cumr += r[i];
	cuml %= mod;
	cumr %= mod;
	ll tmp;
	if(cuml - cumr < 0) tmp = mod + cuml - cumr;
	else tmp = cuml - cumr;
				
	for(auto itr : v) {
	    l[i+itr.first] += tmp;
	    r[i+itr.second+1] += tmp;
	}
///	printf("i:%d cuml:%lld cumr %lld\n",i, cuml, cumr);
    }
    ll ans = cuml - cumr;
    if(ans < 0) cout << ans + mod << endl;
    else cout << ans << endl;
    return 0;
}



Measured memory_bytes: 9564
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	int i;
	string str;
	long ans=0;
	cin>>str;
	for(i=0;i<4;i++){
		if(str.at(i)=='+'){
			ans++;
		}else{
			ans--;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
s=int(input())

x=[]

def collatz(n):
    if(n%2==0):
        return n/2
    else:
        return 3*n+1


count=0
if(s>4 or s==3):
    while(True):
        s=collatz(s)
        count+=1
        if(s==4):
            break


    
        

print(count+4)

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

struct event { ll type; ll t; ll pos; };

int main() {
  ll N, Q; cin >> N >> Q;
  vector<event> e;
  rep(i,N) {
    ll s, t, x; cin >> s >> t >> x;
    e.push_back({-1, 2*(s-x) - 1, x});
    e.push_back({1, 2*(t-x) - 1, x});
  }
  rep(i,Q) {
    ll d; cin >> d;
    e.push_back({0, 2*d, 0});
  }
  sort(e.begin(), e.end(), [](const event &x, const event &y){return x.type<y.type;});
  sort(e.begin(), e.end(), [](const event &x, const event &y){return x.t<y.t;});
  multiset<ll> se;
  for (auto x: e) {
    // for (auto y: se) cout << y << " "; cout << endl;
    if (x.type==-1) se.insert(x.pos);
  	else if (x.type==1){
  		auto it = se.find(x.pos);
  		se.erase(it);
  	}
    else if (x.type==0) {
      ll result = se.size() ? *(se.begin()) : -1 ;
      cout << result << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 26088
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

vector<P> v;

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        int num;
        cin >> num;
        v.push_back(P(-num, i));
    }
    sort(v.begin(), v.end());
    map<long long int, int> m;
    m[-1] = -1;
    m[N] = 1;
    long long int ans = 0;
    for(P p : v){
        int pos = p.second;
        m[pos] = 1;
        auto ite = m.find(pos);
        auto pre = prev(ite);
        auto nex = next(ite);
        if(pre != m.begin()){
            auto pp = prev(pre);
            ans += -p.first * (nex->first - pos) * (pre->first - pp->first);
        }
        auto nn = next(nex);
        if(nn != m.end()){
            ans += -p.first * (nn->first - nex->first) * (pos - pre->first);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

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

    ll n,k;
    cin >> n >> k;
    vector<ll> a(n),f(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> f[i];

    sort(a.begin(),a.end());
    sort(f.rbegin(),f.rend());

    ll left = -1, right = (ll)1e12+1;
    while(right-left > 1){
        ll mid = (right+left)/2;
        ll tk = k;
        //cout << mid << endl;
        for(int i = 0; i < n; i++){
            if(a[i]*f[i] > mid) tk -= a[i]-(mid/f[i]);
        }
        //cout << mid << " " << tk << endl;
        if(tk >= 0) right = mid;
        else left = mid;
    }
    cout << right << endl;
    return 0;
}

Measured memory_bytes: 6340
#include "bits/stdc++.h"
using namespace std;



// 数列dp：i番目の項は足場iへ行くために必要最低限のコスト
int h[100001];
int memo[100001];
int solve(int i){
	if(i == 0) return 0;
	if(i == 1) return 0;
	if(memo[i] != -1) return memo[i];
	return memo[i] = min(solve(i-2)+abs(h[i]-h[i-2]),solve(i-1)+abs(h[i]-h[i-1]));
}

// L_n = min(L_n-2 + |h_n-2 - h_n|, L_n-1 + |h_n-1 - h_n|)
// L_2 = |h_2|
// L_1 = 0
// (L_0 = 0)

int main(){

	int n;
	cin >> n;
	/*
	int dp[100001];
	dp[0] = 0;
	dp[1] = 0;*/
	
	for(int i = 1; i <= n; i++){
		cin >> h[i];
		memo[i] = -1;
	}
	h[0] = h[1];

	/*for(int i = 2; i <= n; i++){
		dp[i] = min(
			dp[i-2] + abs(h[i] - h[i-2]),
			dp[i-1] + abs(h[i] - h[i-1]));
	}

	cout << dp[n];*/

	cout << solve(n) << endl;

    return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int h,w,k;
int c[10][10];
int main(){
    scanf("%d%d%d",&h,&w,&k);
    for(int i=0;i<h;i++){
        char s[100];
        scanf("%s",s);
        for(int j=0;j<w;j++){
            if(s[j]=='#')c[i][j]=1;
            else c[i][j]=0;
        }
    }
    int hn=(1<<h)-1,wn=(1<<w)-1,ans=0;
    for(int a=0;a<=hn;a++){
        for(int b=0;b<=wn;b++){
            int tmp=0;
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if((a&(1<<i))==0&&(b&(1<<j))==0)tmp+=c[i][j];
                }
            }
            if(tmp==k)ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

namespace ABC152A {
    class Program {
        static void Main(string[] args) {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var attack = input[0] / input[1] + (input[0] % input[1] == 0 ? 0 : 1);
            Console.WriteLine(attack);
        }
    }
}

Measured memory_bytes: 13396
#include<stdio.h>
#include<string.h>
int main()
{
    char a[100];
    scanf("%s",a);;
    int l=strlen(a);
    if(l>=3)
    {
        int k=l-2;
        printf("%c%d%c\n",a[0],k,a[l-1]);
    }
    return 0;
}

Measured memory_bytes: 128
A, B, C = map(int, input().split())

la = [A]
lb = [B]
lc = [C]

ans = 0
while la[ans] % 2 == 0 and lb[ans] % 2 == 0 and lc[ans] % 2 == 0 and ans < 100001:
    la.append((lb[ans] + lc[ans]) / 2)
    lb.append((lc[ans] + la[ans]) / 2)
    lc.append((la[ans] + lb[ans]) / 2)
    ans += 1

if ans == 100001:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 12608
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int a[maxn],sk[5];
int main() {
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	for(int i=2;i<n;i++)
		if(a[i-1]!=i-1&&a[i]!=i&&a[i+1]!=i+1)return puts("No"),0;
	for(int l=1,r=1;l<=n;l=r+1) {
		int top=0;
		for(r=l;r<n&&(a[r]==r)!=(a[r+1]==r+1);r++);
		for(int i=l;i<=r;i++) {
			if(a[i]<l||a[i]>r)return puts("No"),0;
			if(a[i]!=i) {
				if(!top||a[i]<sk[top])sk[++top]=a[i];
				else if(a[i]<sk[1])sk[2]=a[i];
				else sk[1]=a[i];
				if(top>=3)return puts("No"),0;
			}
		}
	}
	puts("Yes");
	return 0;
}

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


int main()
{
ll n , l ;
cin >> n >> l ;
vector<ll> a(n+1);
vector<ll> ans;

rep(i, n){
  cin >> a[i+1];
}
rep(i,n){
  if(a[i]+a[i+1]>=l){
    for(ll j=i;j>0;j--)ans.push_back(j);
    for(ll j=i+1;j<n;j++)ans.push_back(j);
    cout << "Possible" << endl;
    rep(i,n-1){
      cout << ans[n-i-2] << endl;
    }
    return 0;
  }
}
cout << "Impossible" << endl;

return 0;
}


Measured memory_bytes: 2548
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    
    int[] inf = new int[N+1];
    int now = 0;
    int paint = 1;
    int max = 0;
    int[][] val = new int[N-1][4];
    for(int i = 0; i < N-1; i++){
      String[] S = sc.nextLine().split(" ");
      val[i][0] = Integer.parseInt(S[0]);
      val[i][1] = Integer.parseInt(S[1]);
      val[i][2] = i;
    }
    Arrays.sort(val, (a,b)->Integer.compare(a[0],b[0]));
    
    for(int i = 0; i < N-1; i++){
      int a = val[i][0];
      int b = val[i][1];
      if(i == 0){
        now = a;
      }else{
        if(a == now){
          paint++;
        }else{
          now = a;
          paint = 1;
        }
        if(inf[a] == paint){
          paint++;
        }
      }
      val[i][3] = paint;
      inf[b] = paint;
      if(max < paint){
        max = paint;
      }
    }
    
    Arrays.sort(val, (a,b)->Integer.compare(a[2],b[2]));
    System.out.println(max);
    for(int i = 0; i < N-1; i++){
      System.out.println(val[i][3]);
    }
  }
}
    
    

Measured memory_bytes: 133092
N, M = list(map(int,(input()).split()))
po = 0

if N == 1 and M == 1:
  po = 1
elif (N-1) * (M-1) == 0:
  po = max(N-2,M-2)
else:
  po = (N-2) * (M-2)
    
print(po)

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

#define MAX 1000
int T[MAX];
int TT[MAX];
int n, k, p;


int solve(int i,int m){
	if (m == 0)return 1;
	if (i >= n) return 0;
	int res = solve(i + 1, m) || solve(i + 1, m - T[i]);
	return res;
}


int main(){
	int i = 0;
	int q;
	int M;
	long long ans;

	scanf("%d", &n);

	for (i = 0; i < n; i++){
		scanf("%d", &T[i]);
	}

	scanf("%d", &q);

	for (i = 0; i < q; i++){
		scanf("%d", &M);
		if (solve(0, M)) printf("yes\n");
		else printf("no\n");
	}

return 0;

}


int check(long long p){
	long long sum = 0;
	int i = 0;
	int j;

	for (j = 0; j < k; j++){
		sum = 0;
		while (sum + T[i] <= p){
			sum += T[i];
			i++;
			if (i == n) return n;
		}
	}
	return i;

}

Measured memory_bytes: 584
#include <iostream>

# define REP(i,n) for(int i=0; i<n;i++)

using namespace std;

int main(){
	int primes[55] = {11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381};
	int n;
	cin >> n;
	REP(i,n-1){
		cout << primes[i] << " ";
	}
	cout << primes[n-1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int price[4]={6000,4000,3000,2000};

void doit(){
  int t,n;

  if(scanf("%d %d",&t,&n)!=EOF){
    printf("%d\n",price[t-1]*n);
    doit();
  }
}

int main(){
  doit();
  return 0;
}

Measured memory_bytes: 600
using System;

namespace C___Divide_the_Problems
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var di = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            Array.Sort(di);
            Console.WriteLine(di[N / 2] - di[N / 2 - 1]);
        }
    }
}


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

using namespace std;

int main(){
    int n,k,muki[100010],R=0,L=0,max = 0,ans=0;
    string s;
    cin >> n >> k;
    cin >> s;
    for(int i=0;i<n;i++){
        if(s[i] == 'L'){
            muki[i] = -1;
        }
        else{
            muki[i] = 1;
        }
    }
    for(int i=0;i<n-1;i++){
        if(muki[i] == muki[i+1])ans++;
        else if(muki[i+1] == 1)R++;
        else L++;
    }
    max = min(R,L);
    if(max >= k)ans += k*2;
    else {
        ans += max*2;
    }
    if(max+1 <= k){
        if(R != L){
            ans += 1;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

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

	int a[3][20];

	//Ai入力
	for (int i = 0; i < N; i++) {
		cin >> a[0][i];
	}

	//Bi入力
	for (int i = 0; i < N; i++) {
		cin >> a[1][i];
	}

	//Ci入力
	for (int i = 0; i < N-1; i++) {
		cin >> a[2][i];
	}

	//答え
	int point=0;

	for (int i = 0; i < N; i++) {
		
		if (i > 0) {
			if (a[0][i] == a[0][i - 1] + 1) {
				point = point + a[1][a[0][i]-1] + a[2][a[0][i-1]-1];
			}
			else {
				point = point + a[1][a[0][i] - 1];
			}

		}
		else {
			point = point + a[1][a[0][i]-1];
		}
		
	}
	

	cout << point << endl;
	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int k, s;
  cin >> k >> s;
  ll ans = 0;
  for (int x = 0; x <= k; ++x) {
    for (int y = 0; y <= k; ++y) {
      int z = s - x - y;
      if (z >= 0 && z <= k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

	double d;
	while(cin >> d) {
		for(int i = 1;; i++) {
			double y = sqrt(5.*(i - 1) / 4.9);
			if(9.8 * y >= d) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3204
N, M = map(int, input().split())
ks = []
for i in range(M):
    ks.append(list(map(int, input().split())))
p = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
    f = True
    for j in range(M):
        s = 0
        for k in ks[j][1:]:
            s += (i >> (k - 1)) & 1
        if s % 2 != p[j]:
            f = False
    if f:
        ans += 1
print(ans)

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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(0);

  int H, W;
  cin >> H >> W;

  vector<vector<char>> grid(H, vector<char> (W));
  rep(i, 0, H) {
    rep(j, 0, W) {
      cin >> grid[i][j];
    }
  }

  rep(i, 0, H) {
    rep(k, 0, 2) {
      rep(j, 0, W) {
        cout << grid[i][j];
      }
      cout << endl;
    }
  }


  return 0;
};


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

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

    if(s[0]=='R' && s[1]=='R' && s[2]=='R')
    {
        cout<<"3";
    }
    else if((s[0]=='R' && s[1]=='R') || (s[1]=='R' && s[2]=='R'))
    {
        cout<<"2";
    }
    else if(s[0]=='R' || s[1]=='R' || s[2]=='R')
    {
        cout<<"1";
    }
    else
    {
        cout<<"0";
    }
    
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<cassert>
#include<string.h>
#define LEN 10000

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

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

void enqueue(P x){
  Q[tail] = x;
  if ( tail == LEN ) tail = 1;
  else tail++;
}

P dequeue(){
  P x = Q[head];
  if ( head == LEN ) head = 1;
  else head++;
  return x;
}
int min(int a, int b) {return a < b ? a : b;}
int max(int a, int b) {return a > b ? a : b;}

void trace(){
  int i;
  //  printf("(%d-%d)\n", head, tail);
  if ( head <= tail ){
    for ( i = head; i < tail; i++ ){
      printf("%s[%d] - ", Q[i].name, Q[i].t);
    }
    printf("\n");
  } else {
    for ( i = head; i <= LEN; i++ ){
      printf("%s[%d] - ", Q[i].name, Q[i].t);
    }
    for ( i = 1; i < tail; i++ ){
      printf("%s[%d] - ", Q[i].name, Q[i].t);
    }
    printf("\n");
  }
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  assert( 1 <= n && n <= 1000);
  assert( 1 <= q && q <= 1000);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    assert( strlen(Q[i].name) <= 10);
    scanf("%d", &Q[i].t);
    assert( 1 <= Q[i].t && Q[i].t <= 1000);
  }
  head = 1; tail = n+1;

  while( head != tail ){
    //    trace();
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if ( u.t > 0 ) enqueue(u);
    else {
      printf("%s %d\n",u.name, elaps);
    }
  }
  

  return 0;
}

Measured memory_bytes: 0
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;

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

ll N,ans=0,candi=0,h1=0,h2=0;

int main(){
  cin >> N;
  REP(i,N){
    scanf("%lld",&h2);
    if(h1>=h2){candi++;}
    else{
      ans=max(ans,candi);
      candi=0;
    }
    h1=h2;
  }
  ans=max(ans,candi);
  printf("%lld",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define si(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define sl(a) scanf("%ld",&a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%ld\n",a)
#define pll(a) printf("%lld\n",a) 
#define sc(a) scanf("%c",&a)a
#define pc(a) printf("%c",a)
#define ll long long
#define mod 1000000007
#define w while
#define pb push_back
#define mp make_pair
#define f first
#define s second
//#define INF INT_MAX
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define VI vector<int>
#define VL vector<ll>
#define PI pair<int,int>
#define PL pair<ll,ll>
long double PIE=acos(-1);
//////////////////////////////////////////////////////////////
const ll N=1e5+5;
ll Ans=1;
bool done[1000009];
vector < ll > primes;

void FindPrime(ll N)
{
    done[1] = 1;
    for(int i=2;i<=N;i++)
	{
        if(done[i]) continue;
        for(int j=i*2;j<=N;j+=i)
		{
            done[j] = 1;
        }
        primes.push_back(i);
    }
}

ll solve(ll Num)
{
    for(int i=0;i<primes.size();i++)
	{
    	int p=primes[i];
        if(p*p*p > Num) break;
        ll Count = 1;
        while(Num%p == 0)
		{
            Num /= p,Count++;
        }
        Ans *= Count;
    }
    ll sq = (ll)sqrt(Num);
    if(!done[Num]) 
	Ans *= 2;
    else if(sq*sq == Num && !done[sq]) 
	Ans *= 3;
    else if(Num != 1) 
	Ans *= 4;
    return Ans;
}


ll fact[N], invfact[N];



ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

ll modinv(ll k)
{
	return pow(k, mod-2, mod);
}


ll nCr(ll x, ll y)
{
	if(y>x)
		return 0;
	ll num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}

void initinv()
{
	fact[0]=1;
	fr(i,1,N)
	{
		fact[i]=(i*fact[i-1])%mod;
	}
	invfact[N]=modinv(fact[N]);
	for(int i=N-1;i>=1;i--)
	{
		invfact[i]=((i+1)*invfact[i+1])%mod;
	}
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
ll dp[405][405];
ll sum[405];
ll INF=1000000000000000005;
int main()
{
	int n;
	cin>>n;
	ll a[n+1];
	fr(i,1,n)
	{
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}
	for(int l=n;l>=1;l--)
	{
		for(int r=l;r<=n;r++)
		{
			if(l==r)
			{
				dp[l][r]=0;
			}
			else
			{
				dp[l][r]=INF;
				for(int i=l;i<=r-1;i++)
				{
					dp[l][r]=min(dp[l][r],(dp[l][i]+dp[i+1][r]+sum[r]-sum[l-1]) );
				}
			}
		}
	}
	cout<<dp[1][n];
    return 0;
}

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

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

    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class EStringsOfImpurity {
public:
void solve(std::istream& cin, std::ostream& cout) {
    string s, t;
    cin >> s >> t;

    int64_t n = s.length();
    vector<vector<int>> A(27);

    for (int i = 0; i < n; i++){
        A[s[i] - 'a'].push_back(i);
    }

    int64_t ans = 0;
    int64_t prev = -1;

    for (const auto &T: t){
        const auto &B = A[T - 'a'];
        auto a = upper_bound(B.begin(), B.end(), prev);
        if (a != B.end()){
            prev = *a;
            continue;
        }
        if (B.size() == 0){
            cout << -1 << endl;
            return;
        }
        prev = B[0];
        ans++;
    }

    cout << n * ans + prev + 1LL << endl;
}
};

int main() {
	EStringsOfImpurity solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1216
import sys,collections
input = sys.stdin.readline

N = int(input())
a = list(map(int,input().split()))
ac = collections.Counter(a)
dc = sorted(ac.items(),key = lambda x:(-x[1],x[0]))

ans = 0
for i in range(len(dc)):
    key = dc[i][0]
    val = dc[i][1]
    if ans > 3*val:
        print(ans)
        exit()
    ans = max(ans,ac[key-1]+ac[key]+ac[key+1])
print(ans)


Measured memory_bytes: 25180
S=input()
if S[0]=='0' and S[1]!='0':
    if S[2]=='0' and S[3]!='0':
        print('AMBIGUOUS')
    elif S[2]=='1' and (S[3]=='0' or S[3]=='1' or S[3]=='2'):
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif S[0]=='1' and(S[1]=='0' or S[1]=='1' or S[1]=='2'):
    if S[2]=='0' and S[3]!='0':
        print('AMBIGUOUS')
    elif S[2]=='1' and (S[3]=='0' or S[3]=='1' or S[3]=='2'):
        print('AMBIGUOUS')
    else:
        print('MMYY')
 
else:
    if S[2]=='0' and S[3]!='0':
        print('YYMM')
    elif S[2]=='1' and (S[3]=='0' or S[3]=='1' or S[3]=='2'):
        print('YYMM')
    else:
        print('NA')

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    vector<double> abc(3);
    ll ans1=0, ans2=0, ans3=0, ans4=0;
    while (true) {
        rep(i, 3) cin >> abc[i];
        sort(abc.begin(), abc.end());
        double a=abc[0], b=abc[1], c=abc[2];
        if (c<b+a) {
            ans1++;
            double tmp = a*a+b*b-c*c;
            if (tmp == 0) ans2++;
            else if (tmp > 0) ans3++;
            else if (tmp < 0) ans4++;
        }
        else {
            break;
        }
    }
    cout << ans1 << ' ' << ans2 << ' ' << ans3 << ' ' << ans4 << endl;
    return 0;
}



Measured memory_bytes: 3244
n = int(input())
s = []
p = []
items = []
for i in range(n):
    a, b = (x for x in input().split())
    s.append(a)
    p.append(int(b))
    items.append({'i':i+1, 's':a, 'p':-int(b)})
sorted_items = sorted(items,key = lambda x: (x['s'],x['p']))
for i in range(n):
    print(sorted_items[i]['i'])
        

Measured memory_bytes: 3064
N, W = list(map(int, input().split()))

dp = [[0 for _ in range(W + 10)] for _ in range(N + 10)]
value, weight = [], []
for _ in range(N):
    v, w = list(map(int, input().split()))
    value.append(v)
    weight.append(w)

for i in range(N):
    for w in range(W + 1):
        dp[i + 1][w] = max(dp[i][w - weight[i]] + value[i],
                           dp[i][w]) if w >= weight[i] else dp[i][w]

print(dp[N][W])



Measured memory_bytes: 43116
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define FASTIO() cin.tie(0),ios::sync_with_stdio(0);
#define dbg(x) cout<<#x<<": "<<x<<endl

ll x, y;

int main() {
    cin >> x >> y;

    ll ans = 0, cur = 1;
    while (1) {
        if (x > y) break;
        ans++;
        x = x * 2;
        cur++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

vector<ll> evaluation(vector<ll>& C, vector<vector<ll>>& S, vector<ll>& T) {
  ll D = T.size();
  vector<ll> res(D, 0);
  vector<ll> last(26, 0);
  ll score = 0;
  for (ll i = 0; i < D; ++i) {
    ll contest = T.at(i) - 1;
    last.at(contest) = i + 1;
    score += S.at(i).at(contest);
    for (ll j = 0; j < 26; ++j) {
      score -= (i + 1 - last.at(j)) * C.at(j);
    }
    res.at(i) = score;
  }
  return res;
}

int main() {
  //-----------input-------------
  ll D;
  cin >> D;
  vector<ll> C(26), T;
  vector<vector<ll>> S(D, vector<ll>(26));
  for (ll i = 0; i < 26; ++i) {
    cin >> C.at(i);
  }
  for (ll i = 0; i < D; ++i) {
    for (ll j = 0; j < 26; ++j) {
      cin >> S.at(i).at(j);
    }
  }
  //--------------------------------------

  for (ll i = 0; i < D; ++i) {
    vector<ll> temp = T;
    temp.push_back(0);
    ll max_contest = 0;
    ll max_score = -INF;
    for (ll j = 0; j < 26; ++j) {
      temp.at(i) = j + 1;
      vector<ll> temp_vec = evaluation(C, S, temp);
      ll temp_score = temp_vec.at(temp_vec.size() - 1);
      if (temp_score > max_score) {
        max_score = temp_score;
        max_contest = j + 1;
      }
    }
    T.push_back(max_contest);
  }

  for (ll i = 0; i < D; ++i) {
    cout << T.at(i) << "\n";
  }

  // vector<ll> ans = evaluation(C, S, T);
  // for (ll i = 0; i < ans.size(); ++i) {
  //   cout << ans.at(i) << "\n";
  // }
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int n,ans=1;
    string s;
    cin>>n>>s;
    for(int i=1;i<n;i++){ //前と比較
        if(s[i]!=s[i-1])ans++;
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std ;
int main()
{ int n,i,flag=0;
  cin>>n;
 char arr[n];
 if(n%2==0)
 {  
 for(i=0;i<n;i++)
 {
   cin>>arr[i];
 }
 for(i=0;i<=n/2-1;i++)
 {
   if(arr[i]==arr[i+n/2])
   {
     flag=1;
   }
   else if(n==1||arr[i]!=arr[i+n/2])
   {
     flag=0;
     break;
     
   }
 }
 if(flag==1)
 {
     cout<<"Yes";
 }
 else if (flag==0)
 {
     cout<<"No";
    
 }
 }
 else
 {
   cout<<"No";
 }
 
  
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] inputs = br.readLine().split(" ");
		int n = Integer.parseInt(inputs[0]);

		Node[] nodes = new Node[n];
		for ( int i = 0; i < n; i++ ) {
			nodes[i] = new Node();
		}

		for ( int i = 0; i < n - 1; i++ ) {
			inputs = br.readLine().split(" ");
			int u = Integer.parseInt(inputs[0]) - 1;
			int v = Integer.parseInt(inputs[1]) - 1;
			int w = Integer.parseInt(inputs[2]);
			nodes[u].nexts.add(new Edge(v, w));
			nodes[v].nexts.add(new Edge(u, w));
		}
		br.close();

		ArrayDeque<Integer> q = new ArrayDeque<>();
		q.add(0);
		int[] tree = new int[n];
		tree[0] = 1;
		while ( !q.isEmpty() ) {
			int idx = q.poll();

			for ( Edge e : nodes[idx].nexts ) {
				if ( tree[e.to] == 0 ) {
					q.add(e.to);

					if ( e.dist % 2 == 0 ) tree[e.to] = tree[idx];
					else tree[e.to] = tree[idx] * (-1);
				}
			}
		}

		StringBuilder sb = new StringBuilder();
		for ( int i : tree ) {
			sb.append(Math.max(i, 0) + "\n");
		}
		System.out.println(sb);
	}
}

class Node {
	ArrayList<Edge> nexts = new ArrayList<>();
}

class Edge {

	int	to		= 0;
	int	dist	= 0;

	public Edge(int t, int d) {
		to = t;
		dist = d;
	}
}

Measured memory_bytes: 72120
void main()
{
    long[] tmp = readln.split.to!(long[]);
    long n = tmp[0], a = tmp[1], b = tmp[2], c = tmp[3];
    long[] l = new long[n];
    foreach (i; 0 .. n)
    {
        l[i] = readln.chomp.to!long;
    }

    long dfs(long d, long x, long y, long z)
    {
        if (d == n)
        {
            if (min(x, y, z) > 0)
                return abs(x-a) + abs(y-b) + abs(z-c);
            else
                return 10 ^^ 9;
        }

        long result = dfs(d+1, x, y, z);
        result = min(result, dfs(d+1, x+l[d], y, z)+(x?10:0));
        result = min(result, dfs(d+1, x, y+l[d], z)+(y?10:0));
        result = min(result, dfs(d+1, x, y, z+l[d])+(z?10:0));

        return result;
    }

    dfs(0, 0, 0, 0).writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define ll long long
#define out(a) printf("%d",a)
#define outl(a) printf("%lld",a)
#define writeln printf("\n")
#define rep(i,a,b) for (int i=a;i<=b;i++)
using namespace std;
int a,b;
int num,now,cnt;
char c;
bool f1,f2;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	a=read(); b=read(); f1=false; f2=false;
	if (a==1||b==1) {
	  if (a==1&&b!=1) b++,f1=true;
	  if (b==1&&a!=1) a++,f2=true;
    }
	a--; b--;
	out(100); cout<<' '; out(100); writeln,num++;
    now=cnt=0;
	while (true) {
	  if (a==0) break;
	  cout<<'.'; cout<<'#'; now++; cnt++; 
	  if (cnt==a) {
	    if (now<50) {
	      rep(i,now*2+1,100)
	        cout<<'#';
	      }
	      now=50;
	  }
	  if (now==50) {
	    writeln,num++;
	    rep(i,1,100)
	    cout<<'#';
	    writeln,num++; now=0;
	  }
	  if (cnt==a) break;
    }
    if (b!=0||not f2) {
	  rep(i,1,100)
      cout<<'.';
    writeln,num++;
  }
    now=cnt=0;
	while (true) {
		if (b==0) {
		  rep(i,1,100)
		  cout<<'#';
		  break;
	  }
	  cout<<'#'; cout<<'.'; now++; cnt++;
	  if (cnt==b) {
	    if (now<50) {
	      rep(i,now*2+1,100)
	        cout<<'.';
	      }
	      now=50;
	  }
	  if (now==50) {
	    writeln,num++;
	    rep(i,1,100)
	    cout<<'.';
	    if (cnt!=b) writeln,num++; now=0;
	  }
	  if (cnt==b) break;
    }
    writeln;
    c='.';
	if (f2) c='#';
	if (a==b&&a==0) c='#';
    rep(i,num+1,100) {
      rep(j,1,100)
	    cout<<c;
	    writeln,num++;
	}
	//out(num);
    return 0;
}
    
	  
	  

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
#include<math.h>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int A,B; cin >> A >> B;
    if((A + B) % 2 == 1){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    cout << (A+B) / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <map>
#include <iterator>
#include <math.h>
#include <sstream>
#include <algorithm>

using namespace std;

#define INF 99999

int** getDistCount(int** graph, const int V) {
    /* dist[][] will be the output matrix
    that will finally have the shortest
    distances between every pair of vertices */

    int** dist, i, j, k;
    dist = new int* [V];
    //map<int, int> res;
    for (int i = 0; i < V; i++) {
        dist[i] = new int[V];
    }

    /* Initialize the solution matrix same
    as input graph matrix. Or we can say
    the initial values of shortest distances
    are based on shortest paths considering
    no intermediate vertex. */
    for (i = 0; i < V; i++)
        for (j = 0; j < V; j++)
            dist[i][j] = graph[i][j];

    /* Add all vertices one by one to
    the set of intermediate vertices.
    ---> Before start of an iteration,
    we have shortest distances between all
    pairs of vertices such that the
    shortest distances consider only the
    vertices in set {0, 1, 2, .. k-1} as
    intermediate vertices.
    ----> After the end of an iteration,
    vertex no. k is added to the set of
    intermediate vertices and the set becomes {0, 1, 2, .. k} */
    for (k = 0; k < V; k++)
    {
        // Pick all vertices as source one by one  
        for (i = 0; i < V; i++)
        {
            // Pick all vertices as destination for the  
            // above picked source  
            for (j = 0; j < V; j++)
            {
                // If vertex k is on the shortest path from  
                // i to j, then update the value of dist[i][j]  
                if (dist[i][k] + dist[k][j] < dist[i][j]) {
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
    }
    return dist;
}

int main()
{
    
    int n = 7, a, b;
    string inp;// = "7 3 7";
    getline(cin, inp);

    stringstream ss(inp);
    ss >> n;
    ss.ignore(1);
    ss >> a;
    ss.ignore(1);
    ss >> b;
    map<int, int> out;
    int dist = 0;
    int _min = min(a, b);
    int _max = max(a, b);


    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            dist = j - i;
            dist = min(dist, abs(j - _max) + abs(_min - i) + 1);
            dist = min(dist, abs(j - _min) + abs(_max - i) + 1);
            if (out.find(dist) != out.end()) {
                out[dist]++;
            }
            else {
                out[dist] = 1;
            }
        }
    }

    

    /*for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << arr[i][j] << " ";
        }
        cout << endl;
    }*/

    for (int i = 1; i < n; i++) {
        if (out.find(i) != out.end()) {
            cout << out[i] << endl;
        }
        else {
            cout << 0 << endl;
        }
    }

}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

#define M 1000000007

int main(){
	int n, k;
	cin>>n>>k;
	vector<int> a(n);
	rep(i, n) cin>>a[i];

	if(n==k){
		ll ans=1;
		rep(i, k) ans=(ans*((a[i]+M)%M))%M;
		cout << ans << endl;
		return 0;
	}

	int nump=0, numm=0, num0=0;
	vector<int> ap, am;
	rep(i, n){
		if(a[i]>=0) ap.push_back(a[i]);
		if(a[i]<0) am.push_back(a[i]);
	}

	if(am.size()==n && k%2==1){
		sort(am.rbegin(), am.rend());
		ll ans=1;
		rep(i, k) ans=(ans*((am[i]+M)%M))%M;
		cout << ans << endl;
		return 0;
	}

	sort(ap.rbegin(), ap.rend());
	sort(am.begin(), am.end());

	int nm=min((k/2)*2, (int)(am.size()/2)*2);
	int np=k-nm;
	while(np+2<=ap.size() && nm-2>=0 && (ll)ap[np]*ap[np+1] > (ll)am[nm-1]*am[nm-2]){
		np+=2;
		nm-=2;
	}

	ll ans=1;
	rep(i, np) ans=(ans*ap[i])%M;
	rep(i, nm) ans=(ans*((am[i]+M)%M))%M;

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 5084
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace kyoupuro
{
    class MainClass
    {
        public static void Main()
        {
            MainClass mainClass = new MainClass();
            mainClass.Start();
        }

        void Start() {
            var something = Console.ReadLine().Split(' ');
            var a = something.Select(int.Parse).ToArray();
            int m = Math.Min(a[0], a[1]);
            var list = new List<int>();

            for (int i = 1; i <= m; i++) {
                if(a[0] % i == 0 &&a[1]%i==0) {
                    list.Add(i);
                }
            }

            Console.WriteLine(list[list.Count - a[2]]);
        }
    }
}


Measured memory_bytes: 13396
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1000000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<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 int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

struct edge{
	int to, cost;
};
vector<edge> G[100000];

int main(){
	int n;
	cin >> n;
	REP(i, n-1){
		int a, b, c;
		cin >> a >> b >> c;
		edge e;
		e.to = b-1;
		e.cost = c;
		G[a-1].pb(e);
		e.to = a-1;
		e.cost = c;
		G[b-1].pb(e);
	}
	int t, k;
	cin >> t >> k;
	ll length[n] = { };
	queue<int> q;
	q.push(k-1);
	while(q.size()){
		int v = q.front();
		q.pop();
		for(auto it = G[v].begin(); it != G[v].end(); ++it){
			if(length[(*it).to] == 0 && (*it).to != k-1){
				q.push((*it).to);
				length[(*it).to] = length[v] + (*it).cost;
			}
		}
	}
	REP(i, t){
		int x, y;
		cin >> x >> y;
		cout << length[x-1] + length[y-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 9088
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}
#endif


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

    string S; cin >> S;
    ll K; cin >> K;

    char ans;
    if (K == 1) ans = S[0];
    else { // K>=2
        int pos = 0;
        REP(i,S.size()) {
            if (S[i]!='1') {
                pos = i;
                break;
            }
        }

        if (K-1 < pos) ans = '1';
        else ans = S[pos];
    }

    cout << ans << endl;

    return 0;
}

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

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

Measured memory_bytes: 256
N=input()
def alpha2num(alpha):
    num=0
    for index, item in enumerate(list(alpha)):
        num += pow(26,len(alpha)-index-1)*(ord(item)-ord('A')+1)
    return num
S=alpha2num(N)+1
num2alpha = lambda c: chr(c+64)

print(num2alpha(S))

Measured memory_bytes: 9040
let () = Scanf.scanf "%d %d %d\n" @@ fun h w k ->
  let cs = Array.init h @@ fun _ -> Scanf.scanf "%s\n" @@ fun cs -> cs in
  Printf.printf "%d\n" @@
  Array.fold_left (Array.fold_left ( + )) 0 @@
  Array.init (1 lsl h) @@ fun column ->
    Array.init (1 lsl w) @@ fun row ->
      if
        ( = ) k @@
        Array.fold_left (Array.fold_left ( + )) 0 @@
        Array.init h @@ fun i ->
          Array.init w @@ fun j ->
            if cs.(i).[j] = '#' && column land (1 lsl i) = 0 && row land (1 lsl j) = 0 then 1 else 0
      then 1
      else 0

Measured memory_bytes: 5880
#include <stdio.h>

int main(void)
{
	long a[10000], n, i, mb,ms, sum = 0;
	scanf("%ld",&n);
	for (i = 0; i < n; i++){
		scanf("%ld",&a[i]);
		sum += a[i];
	}
	mb = ms = a[0];
	for (i = 1; i < n; i++){
		if (ms>a[i]){
			ms = a[i];
		}
	}
	for (i = 1; i < n; i++){
		if (mb<a[i]){
			mb = a[i];
		}
	}
	printf("%ld %ld %ld\n",ms,mb,sum);
	return 0;
}

Measured memory_bytes: 1796