akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;
constexpr ll linf = MOD * MOD;
inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
array<long long, 3> dv = {2ll, 3ll, 5ll};
vector<long long> cost(3);
long long solve()
{
    long long n, add;
    cin >> n >> cost[0] >> cost[1] >> cost[2] >> add;
    // agora quero saber qual a forma mais barata de chegar de n ate 1
      
    unordered_map<long long, long long> memo;
    memo[0ll] = 0ll; 
    memo[1ll] = add;
    // nunca vou chamar a recursao para cima, porque ai vai dar merda!!!
    
    function<long long(long long)> recur = [&] (long long val) 
    {
        if(memo.count(val)) return memo[val];
        long long ans = linf;
        for(int i = 0; i < 3; ++i) {
            if(val % dv[i] == 0) {
                long long nxt = val / dv[i];
                long long delta = val - nxt;
                long long price = cost[i];
                if(delta < MOD) price = min(price, delta * add);
                ans = min(ans, recur(nxt) + price);
            }
            else
            {
                // ai vamos ter duas solucoes, chamar pra cima e chamar pra baixo
                // pra baixo...
                long long nxt = val / dv[i];
                long long delta = val - nxt;
                long long price = cost[i] + (val % dv[i]) * add;
                if(delta < MOD) price = min(price, delta * add);
                ans = min(ans, recur(nxt) + price);

                // pra cima...
                nxt = val / dv[i] + 1;
                delta = val - nxt;
                price = cost[i] + (dv[i] - (val % dv[i])) * add;
                if(delta < MOD) price = min(price, delta * add);
                ans = min(ans, recur(nxt) + price);
            }
        }
        return memo[val] = ans;
    };
    recur(n);
    return memo[n];
}

int main() 
{
    buff();
    int t;
    cin >> t;
    while(t--) 
    {
        cout << solve() << '\n';
    } 
    return 0;
}



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

typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mkmap;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<vi> vv;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const ll mod=1000000007;
const int sz=1000001;
#define endl "\n"
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(i=a;i<b;++i)
#define rrep(i,a,b) for(i=a;i>=b;--i)
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define db(x) cout << (#x) << " = " << x << endl;

inline ll mult(ll a, ll b) {return (((a % mod) * (b % mod)) % mod);}



int main(){
    fast;
    int t,tt,tti,n,m,x,y,z,i,j,k,temp,count,o,e,f,ans=0,sum,l,r,mx,mn;
    ll lx,ly,lz,ltemp;
    double fx,fy,fz;
    string s;
    
    cin>>n;
    rep(i,0,n){
        cin>>x;
        if(i&1^1 && x&1) ans++;
    }
    cout<<ans;
}

/*
    
*/

Measured memory_bytes: 3608
n, c = gets.chomp.split(" ").map(&:to_i)

N_MAX = 10**5

rs = Array.new(c + 1){Array.new(N_MAX*2 + 2, 0)}

n.times do
  si, ti, ci = gets.chomp.split(" ").map(&:to_i)
  (si*2 - 1).upto(ti*2) do |i|
    rs[ci][i] = 1
  end
end

ans = Array.new(N_MAX*2 + 2, 0)
rs.each do |r|
  (N_MAX*2 + 2).times do |i|
    ans[i] += r[i]
  end
end
puts ans.max

Measured memory_bytes: 51836
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author aps
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FLCS solver = new FLCS();
        solver.solve(1, in, out);
        out.close();
    }

    static class FLCS {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            String t = in.next();

            int m = s.length(), n = t.length();

            int[][] dp = new int[m + 1][n + 1];
            for (int i = 0; i <= m; i++) {
                for (int j = 0; j <= n; j++) {
                    if (i == 0 || j == 0) dp[i][j] = 0;
                    else if (s.charAt(i - 1) == t.charAt(j - 1)) {
                        dp[i][j] = 1 + dp[i - 1][j - 1];
                    } else {
                        dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                    }
                }
            }

            String ans = "";
            int i = m, j = n;
            while (i > 0 && j > 0) {
                if (s.charAt(i - 1) == t.charAt(j - 1)) {
                    ans += s.charAt(i - 1);
                    i--;
                    j--;
                } else if (dp[i - 1][j] > dp[i][j - 1]) i--;
                else j--;
            }

            String ret = new StringBuffer(ans).reverse().toString();
            out.println(ret);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 103124
# -*- encoding:utf-8 -*-
l = str(input())

mod = int(1e9) + 7

dp1 = 0 #確定
dp2 = 1 #未確定

for i in l: 
    if i == "0": # i と l を間違えるな
        dp1 = (dp1 * 3) % mod
    else:
        dp1 = (dp1 * 3 + dp2) % mod #dp1は(A_i, B_i) = (0, 0), (1,0), (0, 1) dp2は(A_i, B_i)=(0, 0)のとき確定となる
        dp2 = (dp2 * 2) % mod #(A_i, B_i) = (0, 1), (1, 0)

res = (dp1 + dp2) % mod #未確定で終わったらそれも条件を満たしているからdp2も足す

print(res)

Measured memory_bytes: 3188
# ABC163a


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    r = int(input())
    print(r*2*3.141592653589793238)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61872
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define do(x) for(int i = 1; i <= x; i++){ solve(); }
#define sz(x) (int)x.size()
#define pii pair < int, int >
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
const ll MAXN = 1e9;
const ll SIZE = 5e4+2; //are u sure?
const ll mod = 1e9+7;

void solve(){
	ll a, b, k;
	cin >> a >> b >> k;
	ll first = min(a, k);
	a -= first;
	k -= first;
	first = min(k, b);
	b -= first;
	cout << a << " " << b << endl;
}


int main(){
	speedhack()
	// int it; cin >> it;
	int it = 1;
	do(it);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=20,mod=1e9+7;
inline int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=(ll)res*x%mod;
		y>>=1;
		x=(ll)x*x%mod;
	}
	return res;
}
inline void add(int &x,int y){
	x+=y;
	if(x>=mod) x-=mod;
}
int ans,a[maxn];
int dp[maxn][1<<16];
int fac[1<<16],ifac[1<<16];
inline int C(int n,int m){
	if(n<m) return 0;
	return (ll)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main(){
	int n=read(),m=read();
	REP(i,1,m) a[i]=read();
	dp[m][0]=fac[0]=1;
	sort(a+1,a+m+1);
	int All=(1<<n);
	REP(i,1,All-1) fac[i]=(ll)i*fac[i-1]%mod;
	ifac[All-1]=ksm(fac[All-1],mod-2);
	DREP(i,All-1,1) ifac[i-1]=(ll)i*ifac[i]%mod;
	DREP(i,m,1) REP(j,0,All-1) if(dp[i][j]){
		add(dp[i-1][j],dp[i][j]);
		REP(k,0,n-1) if((j&(1<<k))==0)
			add(dp[i-1][j|(1<<k)],(ll)dp[i][j]*C(All-a[i]-j,(1<<k)-1)%mod*fac[(1<<k)]%mod);
	}
	REP(i,0,(1<<n)-1) ans=(ans+(ll)(__builtin_popcount(i)%2==0?1:(mod-1))*dp[0][i]%mod*fac[iend-i])%mod;
	printf("%lld\n",(ll)ans*ksm(2,n)%mod);
	return 0;
}


Measured memory_bytes: 4480
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        ArrayList<Long> h = new ArrayList<Long>();

        for(int i=0;i<N;i++){
            h.add(Long.parseLong(scan.next()));
        }

        for(int i=N-1;i>=1;i--){
            Long l = h.get(i-1);
            if(h.get(i) < h.get(i-1)){
                h.remove(i-1);
                h.add(i-1,l-1);
            }
        }

        int i=0;
        for(i=0;i<N-1;i++){
            if(h.get(i)<=h.get(i+1)){

            }else{
                break;
            }
        }

        if(i==N-1)
            System.out.println("Yes");
        else
            System.out.println("No");

    }
}


Measured memory_bytes: 49844
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() { string N;
  cin >> N;
  int ans = 0;
  REP(i,N.size()){
    if (N[i] == '2') ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, k, q;
int a[2010];

int calc(int idx) {
    int thresh = a[idx];
    int l = 0, r = 0;
    vector<int> cand;
    vector<int> c;
    while (l < n) {
        while (l < n && a[l] < thresh) l++;
        r = l;
        while (r < n && a[r] >= thresh) r++;
        c.clear();
        for (int i = l; i < r; i++) c.push_back(a[i]);
        sort(ALL(c));
        for (int i = 0; i <= (int)c.size()-k; i++) cand.push_back(c[i]);
        l = r;
    }
    sort(ALL(cand));
    if (cand.size() < q) return inf;
    return cand[q-1] - cand[0];
}

int solve() {
    int res = inf;
    for (int i = 0; i < n; i++) {
        res = min(res, calc(i));
    }
    return res;
}

void input() {
    cin >> n >> k >> q;
    for (int i = 0; i < n; i++) cin >> a[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
    int a, b, c, a_x, c_x;

    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);

    a_x = a - b;
    c = c - a_x;

    if(c<0){
        printf("0");
        return 0;
    }

    printf("%d", c);

    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int c[3][3];
  for (int j = 0; j < 3; j++) {
    for (int i = 0; i < 3; i++) {
      cin >> c[i][j];
    }
  }
  int a[3], b[3];
  a[0] = 0;
  b[0] = c[0][0];
  b[1] = c[0][1];
  b[2] = c[0][2];
  a[1] = c[1][0] - c[0][0];
  a[2] = c[2][0] - c[0][0];
  for (int j = 0; j < 3; j++) {
    for (int i = 0; i < 3; i++) {
      if (c[j][i] != a[j] + b[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, max1 = 0, A = 0;
    cin >> N;
    vector<int> V(N);
    vector<int> C(N);
    vector<int> D(N);

    for (int i = 0; i < N; i++)
    {
        cin >> V.at(i);
    }
    for (int i = 0; i < N; i++)
    {
        cin >> C.at(i);
    }
    for (int i = 0; i < N; i++)
    {
        D.at(i) = V.at(i) - C.at(i);
        if (D.at(i) > 0)
        {
            max1 = D.at(i);
            A = A + max1;
            max1 = 0;
        }
      else {
         A= A+0;
      }
    }

    cout << A << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
  r := bufio.NewReader(os.Stdin)
  w := bufio.NewWriter(os.Stdout)
  defer w.Flush()

  var n int
  var d, x, y float64
  fmt.Fscan(r, &n, &d)
  cnt := 0
  for i := 0; i < n; i++ {
    fmt.Fscan(r, &x, &y)
    if math.Sqrt(x * x + y * y) <= d {
      cnt++
    }
  }
  fmt.Fprintln(w, cnt)
}

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

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string S, T; cin >> S >> T;
    int N = S.size();
    for(int i = 0; i < N; i++){
         if(S[i] != T[i]){
              cout << "No";
              exit(0);
         }
    }
    cout << "Yes";
}

Measured memory_bytes: 3632
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


primes = [1] * (10 ** 6 + 1)
primes[0] = 0
primes[1] = 0
for p in range(10 ** 3 + 1):
    if primes[p]:
        for n in range(p * p, 10 ** 6 + 1, p):
            primes[n] = 0
prime_list = [p for p in range(10 ** 6 + 1) if primes[p] == 1]


def solve_d(a, b):
    d = gcd(a, b)
    res = 1
    for p in prime_list:
        if d % p == 0:
            res += 1
        while d % p == 0:
            d = d // p
    if d > 1:
        res += 1

    return res


def main():
    a, b = map(int, input().split())
    res = solve_d(a, b)
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 53212
#include <iostream>
#include <algorithm>

long long gcd(long long a, long long b) {
    if (a < b) std::swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

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

int main() {
    long long n, t, ret = 1;
    std::cin >> n;
    for (auto i = 0; i < n; i++) {
        std::cin >> t;
        ret = lcm(ret, t);
    }

    std::cout << ret << std::endl;

    return 0;
}

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

using namespace std;
#define debug(x) cout<<#x<<"-"<<x<<"\n"
#define time_assert(x) if(!(x))while(true)
#define fi first
#define se second
#define int long long
#define inf 1e16
const int mod=(int)1e9+7;

int sum(int n){
  return (n*(n+1)/2)%mod;
}


void test_case(){
  int n,k;
  cin>>n>>k;
  int ans=0;
  for(int i=k;i<=n+1;i++){
    ans=(ans+(sum(n)-sum(n-i)+mod)%mod-sum(i-1)+1+mod)%mod;
  }
  cout<<ans;
}

signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)test_case();
}

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

int main()
{
	ll h,n;
	cin>>h>>n;
	ll arr[n];
	ll sum = 0;
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		sum += arr[i];
	}
	if(sum>=h)
	{
		cout<<"Yes"<<endl;
	}
	else
	cout<<"No"<<endl;
	
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>  // std::accumulate(m.begin(), m.end(), 0LL);
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int N, K; std::cin >> N >> K;
  std::vector<int> x(N); for(int i=0; i<N; i++) std::cin >> x[i];

  int ans = 0;
  for(int i=0; i<N; i++) ans += std::min( std::abs(x[i]),std::abs(K-x[i]) );
  std::cout << ans*2 << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm> 
using namespace std;
int main(int argc, char *argv[]) {
	int n,k;
	cin>>n>>k;
	long long arr[n],sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	sort(arr,arr+n);
	int j=n-1;
	
	for(int i=0;i<k;i++)
	{
		if(sum<=0)
		{
			sum=0;
			break;
		}
		sum-=arr[j];
		j--;
	}
	cout<<sum;
	}

Measured memory_bytes: 1792
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f

[<EntryPoint>]
let main argv =
    let [|a;b;c|] = reads int
    printfn "%i" (min (b / a) c)
    0

Measured memory_bytes: 14044
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	queue<P> que;
	rep(i, h)rep(j, w) if (s[i][j] == '#') que.emplace(i, j);
	vector<vector<int>> d(h + 1, vector<int>(w + 1));
	rep(i, h)rep(j, w) if(s[i][j] == '.') d[i][j] = -1;
	while (que.size()) {
		P p = que.front(); que.pop();
		rep(i, 4) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
			if (d[nx][ny] != -1) continue;
			d[nx][ny] = d[p.first][p.second] + 1;
			que.emplace(nx, ny);
		}
	}
	int ans = 0;
	rep(i, h)rep(j, w) if (s[i][j] == '.') ans = max(ans, d[i][j]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 13456
unittest
{
	assert( [ "3 4", "1 1", "2 2", "3 3" ].parse.expand.solve == 3 );
	assert( [
		"10 500000",
		"1 100000",
		"1 100000",
		"1 100000",
		"1 100000",
		"1 100000",
		"100000 100000",
		"100000 100000",
		"100000 100000",
		"100000 100000",
		"100000 100000"
	].parse.expand.solve == 1 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	auto abs = new long[ 2 ][ nk[ 0 ] ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	return tuple( nk[ 1 ], abs );
}

auto solve( long k, long[ 2 ][] abs )
{
	abs.sort();
	
	auto i = 0L;
	foreach( ab; abs )
	{
		i += ab[ 1 ];
		if( k <= i ) return ab[ 0 ];
	}
	
	assert( false );
}


Measured memory_bytes: 4604
n=int(input())
l=list(map(int,input().split()))
e,o=l[0::2],l[1::2]
a=[0]*n
a[0]=sum(l)-sum(o)*2
p=o[0]
m=n//2
s=o+e
for i in range(m):
  a[i*2+2]=a[i*2]-s[m+i]*2+p*2
  p=s[i+1]
s=e+o
for i in range(m):
  a[i*2+1]=a[i*2-1]-s[m+i]*2+p*2
  p=s[i+1]
print(*a)

Measured memory_bytes: 16320
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

signed main() {
	IOS;
	int a; cin>>a;
	if(a%2==1){
		a=(a/2)+1;
	}
	else{
		a=a/2;
	}
	cout<<a;

}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

#include <queue>
int const inf = 1<<29;
int n;
int p[100010];
int d[100010];

int main(){
    while(cin>>n && n){
        rep(i,n)cin>>p[i];
        rep(i,n)d[i] = inf;
        queue<int> q;
        q.push(0);
        d[0] = 0;
        while(q.size()){
            int x = q.front(); q.pop();
            if(x == n) break;
            dump(x,p[x]);
            if(p[x]){
                if(d[x+p[x]] > d[x]){
                    d[x+p[x]] = d[x];
                    q.push(x+p[x]);
                }
            }else{
                for(int i=1;i<=6;i++){
                    if(d[x+i] > d[x]+1){
                        d[x+i] = d[x]+1;
                        q.push(x+i);
                    }
                }
            }
        }
        cout << d[n-1] << endl;
    }
}

Measured memory_bytes: 2020
import java.util.*;
public class Main{
	public static void main(String[] args){
      	Scanner sc = new Scanner(System.in);
      	String[] abc = new String[3];
      	for(int i = 0; i < 3; i++){
        	abc[i] = sc.next().toUpperCase();
        }
      	for(int i = 0; i < 3; i++){
        	System.out.print(abc[i].charAt(0));
        }
    }
}

Measured memory_bytes: 35376
from collections import Counter
import math
def combination(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a = list(map(int,input().split()))
t = [0]
for i in range(n):
	if i == 0:
		t.append(a[0])
	else:
		t.append(t[i]+a[i])
b = Counter(t)
ans = 0
for i in b:
	if b[i] != 1:
		ans += combination(b[i],2)
print(ans)

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

int main(){
  long long n, a, b;
  cin >> n >> a >> b;
  if((b-a) % 2 == 0){
    cout << (b-a) / 2 << endl;
  }else{
    long long center = (n + 1) / 2;
    long long centerOfTwo = (a + b) / 2;
    if(centerOfTwo < center){
      cout << (a-1) + 1 + ((b-a-1)/2) << endl;
    }else{
      cout << (n-b) + 1 + ((b-a-1)/2) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0), ios::sync_with_stdio(false);
	int n; cin >> n;
	const int MAX = 1e6+1;
	int cnt[MAX] = {};
	vi a(n);
	set<int> st;
	rep(i,n){
		cin >> a[i];
		if(st.count(a[i])){
			cnt[a[i]]++;
			continue;
		}
		st.insert(a[i]);
		for(int j = a[i]; j <= MAX; j += a[i]){
			cnt[j]++;
		}
	}
	int ans = 0;
	rep(i,n) if(cnt[a[i]] == 1) ans++;
	cout << ans;
	cout << "\n";
	return 0;
}


Measured memory_bytes: 17204
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    set<int> st;
    rep(i, 0, n){
        int a;
        cin >> a;
        if(st.count(a)) st.erase(a);
        else st.insert(a);
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 4992
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    string t;cin>>t;
    int n=SIZE(t);

    int c1=0;
    int c0=0;
    int len=0;
    VI podd;
    VI peven;
    LL result=0;
    REP(i,n){
        if(t[i] == '0'){
            c0++;
            if(len%2==0){
                peven.PB(i);
            }
            else{
                len++;
                result+=(len+1)/2;
                podd.PB(i);
            }
        }
        else{
            c1++;
            len++;
            result+=(len+1)/2;
        }
    }

    int zm=0;
    int zz=0;



    PER(i,SIZE(peven)){
        len++;
        int change = SIZE(peven)-i-1;
        auto itr = upper_bound(ALL(podd),peven[i]);
        change += podd.end()-itr;
        //dump(i)
        //dump(peven[i])
        //dump(change)
        //dump(zm)
        //dump(zz)

        int a = zm+zz-change;
        int zza = zz-a;
        swap(zza,zm);
        zz = a+zza;
        
        //dump(zm)
        //dump(zz)

        int b = n-peven[i];
        if(len%2 == 0){
            if(b%2 == 0){
                zm++;
            }
            else{
                zz++;
            }
        }
        else{
            if(b%2 == 0){
                zz++;
            }
            else{
                zm++;
            }
        }
        //dump(zm)
        //dump(zz)

        result+=(len+1)/2-zm;

    }

    std::cout<<result<<endl;




}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	std::cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===



int bsearch(const Vi& vec, const int& a)
{
	int left = -1, right = (int)vec.size();
	while (right - left > 1) {
		int mid = (right + left) / 2;
		if (vec[mid] > a) right = mid;
		else left = mid;
	}
	return right;
}


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

	int N;
	cin >> N;

	Vi L(N);
	for (int i = 0; i < N; ++i) {
		cin >> L[i];
	}

	sort(L.begin(), L.end());

	int ans = 0;
	for (int i = 1; i < N - 1; ++i) {
		for (int j = i + 1; j < N; ++j) {
			int b = L[i], c = L[j];

			int num = bsearch(L, c - b);

			ans += max(i - num, 0);
		}
	}

	cout << ans << endl;

	return 0;
}

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

int euclid(int A, int B){
    if(A < B){
        euclid(B, A);
    }else if(A == B){
        return A;
    }else if(B <= 1){
        return 1;
    }else{
        int amari = A % B;
        if(amari == 0){
            return B;
        }else{
            euclid(B, amari);
        }
    }
}

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

    saidai = euclid(A, B);
    cout << (A/saidai) * (B/saidai) * saidai << endl;

    return 0;
}

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

using namespace std;

int main() {
    int N;
    long long A, B;
    cin >> N >> A >> B;
    vector<long long> h(N);
    for (int i = 0; i < N; i++) {
	cin >> h[i];
    }

    long long ans = 0, lft = 0, rght = 1 << 30;;

    while (lft <= rght) {
	long long mid = (lft + rght) / 2;
	long long cnt = 0;
	
	for (int i = 0; i < N; i++) {
	    long long tmp = h[i] - B * mid;
	    if (tmp > 0) {
		cnt += (tmp + A - B - 1) / (A - B);
	    }
	    
	}

	if (cnt <= mid) {
	    ans = mid;
	    rght = mid - 1;
	} else {
	    lft = mid + 1;
	}
    }

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


Measured memory_bytes: 1152
package main

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

const MaxBuf = 200100
var buf []byte
var sc = bufio.NewScanner(os.Stdin)

func init() {
   sc.Split(bufio.ScanWords)
   sc.Buffer(buf,MaxBuf)
}

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

func readInt64() int64 {
   sc.Scan()
   r,_ := strconv.ParseInt(sc.Text(),10,64)
   return r
}

func readInt() int {
   sc.Scan()
   r,_ := strconv.Atoi(sc.Text())
   return r
}

func main() {
	n := readInt()
	ans := 0
	for i := 0; i < n ; i++ {
		l := readInt()
		r := readInt()
		ans += r - l + 1
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
from sys import stdin

N, M, X, Y = [int(i) for i in stdin.readline().rstrip().split()]
x = [int(i) for i in stdin.readline().rstrip().split()]
y = [int(i) for i in stdin.readline().rstrip().split()]
x.append(X)
y.append(Y)

x.sort()
y.sort()

if x[len(x) - 1] < y[0]:
    print('No War')
else:
    print('War')


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define pb push_back
#define mp make_pair
#define err(x) cout<<#x<<"= "<<x<<endl;
#define rep(i,n) for(int i =0; i< n; i++)
#define ff first
#define ss second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define SIZE 100010
#define eps 1e-13

ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main(){
//	#ifdef ONLINE_JUDGE
//	freopen("little.in", "r" , stdin);
//	freopen("little.out", "w", stdout);
// cin.tie(false); cout.tie(false);	
//	#endif
	ios::sync_with_stdio(false);
	ll n,m,t1,t2,ans;
	cin>>n>>m;
	t1 = n/gcd(n,m);t2 =  m/gcd(m,n);
	ll g  = gcd(n,m);
	ans = (n*m)/gcd(n,m);

	char S[SIZE],T[SIZE],T1[SIZE], S1[SIZE];
	cin>>S>>T;
	int fl=1;
	rep(i,g){
		if(T[t2*i] != S[t1*i])fl=0;
	}
	if(fl){
		cout<<ans<<endl;
	}
	else cout<<-1<<endl;


	

	return 0;
};


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



int main(){
    int n;
    double ans;
    cin >> n;
    vector<double> v(n);
    rep(i,n)cin >> v.at(i);
    sort(v.begin(),v.end());
    while(v.size()>2){
            v.at(0)=(v.at(0)+v.at(1))/2;
            v.erase(v.begin()+(1));
            sort(v.begin(),v.end());
    }
    if(v.size()==2) ans=(v.at(0)+v.at(1))/2;
    else ans=v.at(0);
    printf("%.6lf",ans);
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<cstring>
#include<string>
using namespace std;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int a,b,c,x;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&x);
	int ans=0;
	for(int i=0;i*500<=x&&i<=a;i++){
		for(int j=0;j*100+i*500<=x&&j<=b;j++){
			for(int k=0;k*50+j*100+i*500<=x&&k<=c;k++){
				if(i*500+j*100+k*50==x)ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
import Data.List.Split

import Data.List
import Control.Monad

getLineRepeat :: Int -> IO [String]
getLineRepeat times = replicateM times getLine

div' a b = if r == 0 then d else d + 1
    where
        r = a `mod` b
        d = a `div` b

main = do
    input <- getLineRepeat 6
    let p = read $ head input :: Integer
    let d = map read $ tail input :: [Integer]
    let r = p `div'`(minimum d)
    putStrLn . show $ 4 + r

Measured memory_bytes: 508
#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  
  int memo1[128], memo2[128];
  
  for(int i=0;i<=127;i++){
    
    int maxv=-1, a, b;
    
    for(int j=0;j<=127;j++){
      if(maxv < j+(j^i)-i){
	maxv=j+(j^i)-i;
	a=j;
	b=(j^i);
      }
    }
    
    memo1[i]=a;
    memo2[i]=b;
  }
  
  int t;
  cin>>t;

  while(t--){
    
    int n;
    cin>>n;
    
    priority_queue<int,vector<int>,greater<int> > q;
    
    int a;
    cin>>a;
    q.push(a);
    
    n--;
    
    while(n--){
      
      int num=q.top(); q.pop();
      q.push(memo1[num]);
      q.push(memo2[num]);
    }
    
    int ans=0;
    
    while(!q.empty()){
      ans+=q.top();
      q.pop();
    }
    
    cout<<ans<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a;
  vector<int> num_a;
  vector<int> num_b;  
  vector<int> num_c;
  int sum=0;
  cin>>a;
  for(int i=0;i<a;i++){
    int tmp;
    cin>>tmp;
    num_a.push_back(tmp);
  }
  for(int i=0;i<a;i++){
    int tmp;
    cin>>tmp;
    num_b.push_back(tmp);
  }
  for(int i=0;i<a-1;i++){
    int tmp;
    cin>>tmp;
    num_c.push_back(tmp);
  }

  for(int i=0;i<a-1;i++){
    if(num_a[i]+1==num_a[i+1]){
      sum = sum+ num_c[num_a[i]-1];
    }
  }
  sum =sum+ accumulate(num_b.begin(), num_b.end(), 0); 
  cout<<sum<<endl; 
}

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

b=[]
for i in range(n):
    b.append(a[i]-i-1)

b=sorted(b)
if n%2==1:
    ave = b[(n-1)//2]
else:
    ave = (b[n//2] + b[(n//2)-1])//2


ans = 0
for j in range(n):
    ans += abs(b[j]-ave)

print(ans)

Measured memory_bytes: 30832
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        x: u64, a: u64
    }
    println!("{}", if x < a {0} else {10});
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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 (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

struct edge {
    int from, to, cost;
};

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<vector<P> > graph(n);
    rep (i, n - 1) {
        int f, t, c; cin >> f >> t >> c; f--; t--;
        graph[f].emplace_back(t, c);
        graph[t].emplace_back(f, c);
    }
    vector<ll> dist(n); rep (i, n) dist[i] = (ll)1e18;
    priority_queue<P, vector<P>, greater<P> > que;
    int q, k; cin >> q >> k; k--;  
    dist[k] = 0; que.push({0, k});
    while (!que.empty()) {
        P p = que.top(); que.pop();
        if (dist[p.second] < p.first) continue;
        for (auto e : graph[p.second]) {
            if (chmin(dist[e.first], dist[p.second] + e.second)) {
                que.emplace(dist[e.first], e.first);
            }
        }
    }
    rep (_, q) {
        int x, y; cin >> x >> y; x--; y--;
        cout << dist[x] + dist[y] << "\n";
    }
    return 0;
}

Measured memory_bytes: 9332
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  vector<int> rate(9,0);
  for(int i=0;i<n;i++){
    if(a[i]<=3199){
      ++rate[a[i]/400];
    }else{
      ++rate[8];
    }
  }
  int min1=0;
  for(int i=0;i<8;i++){
    if(rate[i]!=0){
      min1+=1;
    }
  }
  int max1=min1+rate[8];
  min1=max(1,min1);
  cout<<min1<<" "<<max1<<endl;
  return 0;
}

Measured memory_bytes: 256
MOD = 10**9+7

N, K = map(int, input().split())
A = [tuple(map(int, input().split())) for _ in range(N)]

def power(base, exp, op=lambda x, y: x * y, ie=1):
    res = ie
    while exp:
        if exp & 1:
            res = op(res, base)
        base = op(base, base)
        exp >>= 1
    return res

matrix_id = [[i == j for j in range(N)] for i in range(N)]

def matrix_mul(A, B):
    res = [[0 for j in range(N)] for i in range(N)]
    for i in range(N):
        for j in range(N):
            for k in range(N):
                res[i][j] += A[i][k] * B[k][j]
                res[i][j] %= MOD
    return res

P = power(A, K, matrix_mul, matrix_id)

res = 0

for i in range(N):
    for j in range(N):
        res += P[i][j]
        res %= MOD

print(res)

Measured memory_bytes: 42860
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
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 (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main()
{
        string s;
        ll N, K;
        cin >> s >> K;
        N = len(s);

        vector<string> ans;
        rep(k, 1, 100) {
                rep(i, 0, N - k + 1) {
                        ans.push_back(s.substr(i, k));
                } 
        }
        sort(all(ans));
        ans.erase(unique(all(ans)), ans.end());

        cout << ans[K-1] << endl;
}


Measured memory_bytes: 47468
def main():
    from sys import exit
    s=input()
    x,y=map(int,input().split())

    def groupby(a):
        a2=[[a[0],1]]
        for i in range(1,len(a)):
            if a2[-1][0]==a[i]:
                a2[-1][1]+=1
            else:
                a2.append([a[i],1])
        return a2

    s=groupby(s)
    a,b=[],[]
    turn=True
    #初めまっすぐの場合
    if s[0][0]=="F":
        x-=s[0][1]
        s.pop(0)
    for i in s:
        if i[0]=="F":
            if turn:
                a.append(-i[1])
            else:
                b.append(-i[1])
        elif i[1]%2==1:
            turn=not turn
    a.sort()
    b.sort()
    for i in a:
        x=abs(x)-abs(i)
    if x!=0:
        print("No")
        exit()
    for i in b:
        y=abs(y)-abs(i)
    if y!=0:
        print("No")
        exit()
    print("Yes")
main()

    

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 1e9;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
int main() {
    int n, x;
    cin >> n >> x;
    int l[n];
    REP(i, n) cin >> l[i];
    int bound = 0;
    int cnt = 0;
    int sum[n+1];
    sum[0] = 0;
    FOR(i, 1, n+1) {
        sum[i] = l[i-1] + sum[i-1];
    }
    FOR(i, 0, n+1){
        if(sum[i] <= x) cnt++;
        else break;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 998244353;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    long i, o, t, j, l, s, z;
    cin >> i >> o >> t >> j >> l >> s >> z;
    // only use i, o, j, l
    
    if (j && l && i) {
        // can make jli
        long j2, l2, i2;
        j2 = j - 1;
        l2 = l - 1;
        i2 = i - 1;
        long ans = 3;
        ans += l2 / 2 * 2 + i2 / 2 * 2 + j2 / 2 * 2 + o;
        
        long ans2 = i / 2 * 2 + l / 2 * 2 + j / 2 * 2 + o;
        cout << max(ans, ans2) << endl;
        return 0;
    } else {
        cout << i / 2 * 2 + l / 2 * 2 + j / 2 * 2 + o << endl;
    }
}


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

const int MAX_N = 100000 * 3;

map<int,int> Best;


int get ( int x ) {
  if ( Best.count(x) == 0 ) return MAX_N + 1;
  else return ( Best[x] );
}

void add ( int x , int val ) {
  if ( Best.count(x) == 0 ) Best[x] = val;
  else Best[x] = min( Best[x] , val );
}



int dp[MAX_N];

int main() {
  
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  
  
  string s;
  cin >> s;
  
  int n = s.length();
  
  Best[0] = 0;
  
  int Cur = 0;
  
  for ( int i = 0 ; i < n ; i++ ) {
    
    Cur ^= 1<<( s[i] - 'a' );
    
    
    int best = MAX_N + 1;
    
    int tmp = get(Cur) + 1;
    if ( tmp < best ) best = tmp; // try all paired
    
    for ( int bit = 0 ; bit < 27 ; bit++ ) {
      tmp = get(Cur ^ ( 1 << bit ) ) + 1;
      if ( tmp < best ) best = tmp;
    }
    
    
    dp[i] = best;
    
    //cout << "dp[" << i << "] = " << dp[i] << endl;
    
    add ( Cur , best );
    
  }
  
  
  
  
  cout << dp[n-1] << endl;
  
  return 0;
}


Measured memory_bytes: 10644
#include<bits/stdc++.h>
#define ll long long
#define fastio  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD=1000000007;
#define PI acos(-1)
using namespace std;
int main(){
      int x,y; cin >> x >> y;
      if(x>=0 && x <= 9 && y >=0 && y <= 9 )
      cout << x*y << endl;
      else cout << -1 << endl;
}

Measured memory_bytes: 3612