akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static class Bydo {
		String name;
		int cost, vocal, dance, looks;

		public Bydo(String name, int cost, int vocal, int dance, int looks) {
			super();
			this.name = name;
			this.cost = cost;
			this.vocal = vocal;
			this.dance = dance;
			this.looks = looks;
		}

		public Bydo(Bydo b) {
			this.name = b.name;
			this.cost = b.cost;
			this.vocal = b.vocal;
			this.dance = b.dance;
			this.looks = b.looks;
		}
	}

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

		while (sc.hasNext()) {

			final int N = sc.nextInt();
			final int M = sc.nextInt();

			Bydo[] in = new Bydo[N];
			for (int i = 0; i < N; i++) {
				sc.nextLine();
				in[i] = new Bydo(sc.nextLine(), sc.nextInt(), sc.nextInt(),
						sc.nextInt(), sc.nextInt());
			}

			int[] vocal_DP = new int[M + 1];
			int[] dance_DP = new int[M + 1];
			int[] looks_DP = new int[M + 1];

			for (int i = 1; i < (M + 1); i++) {
				vocal_DP[i] = -1;
				dance_DP[i] = -1;
				looks_DP[i] = -1;
			}

			vocal_DP[0] = 0;
			dance_DP[0] = 0;
			looks_DP[0] = 0;

			for (Bydo bydo : in) {
				for (int i = M; i >= 0; i--) {
					if (vocal_DP[i] != -1) {
						for (int j = 1; (j * bydo.cost + i) <= M; j++) {
							if (vocal_DP[j * bydo.cost + i] == -1
									|| vocal_DP[j * bydo.cost + i] < vocal_DP[i]
											+ j * bydo.vocal) {
								vocal_DP[j * bydo.cost + i] = vocal_DP[i] + j
										* bydo.vocal;
							}
						}
					}

					if (dance_DP[i] != -1) {
						for (int j = 1; (j * bydo.cost + i) <= M; j++) {
							if (dance_DP[j * bydo.cost + i] == -1
									|| dance_DP[j * bydo.cost + i] < dance_DP[i]
											+ j * bydo.dance) {
								dance_DP[j * bydo.cost + i] = dance_DP[i] + j
										* bydo.dance;
							}
						}
					}

					if (looks_DP[i] != -1) {
						for (int j = 1; (j * bydo.cost + i) <= M; j++) {
							if (looks_DP[j * bydo.cost + i] == -1
									|| looks_DP[j * bydo.cost + i] < looks_DP[i]
											+ j * bydo.looks) {
								looks_DP[j * bydo.cost + i] = looks_DP[i] + j
										* bydo.looks;
							}
						}
					}
				}
			}
			/*
			System.out.println(Arrays.toString(vocal_DP));
			System.out.println(Arrays.toString(dance_DP));
			System.out.println(Arrays.toString(looks_DP));
			*/
			int max = 0;
			for (int i = M; i >= 0; i--) {
				max = Math.max(max, vocal_DP[i]);
				max = Math.max(max, dance_DP[i]);
				max = Math.max(max, looks_DP[i]);
			}

			System.out.println(max);

		}
	}

}

Measured memory_bytes: 13000
"bit全探索の問題"

def calc(a, b)
  result = []
  result[0] = a + b
  result[1] = a - b
  result
end

a,b,c,d = gets.split("").map(&:to_i)
res = []

res1 = calc(a, b)
res2 = calc(res1[0], c)
res3 = calc(res1[1], c)

res4 = calc(res2[0], d)
res.push(res4).flatten!
res5 = calc(res2[1], d)
res.push(res5).flatten!
res6 = calc(res3[0], d)
res.push(res6).flatten!
res7 = calc(res3[1], d)
res.push(res7).flatten!

8.times do |i|
  if res[i] == 7 
    bit = i.to_s(2)
    bit = '0' + bit if bit.size == 2
    bit = '00' + bit if bit.size == 1
    op1 = (bit[0].to_i == 0) ? '+' : '-'
    op2 = (bit[1].to_i == 0) ? '+' : '-'
    op3 = (bit[2].to_i == 0) ? '+' : '-'
    puts "#{a}#{op1}#{b}#{op2}#{c}#{op3}#{d}=7"
    exit
  end
end

Measured memory_bytes: 1788
#include <iostream>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>

#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#define eps 1e-6
#define INF 0x3fffffff
#define PI acos(-1.0)
#define ll long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define N 100005
int dp[N][2],a[N];
#define fr(i,x,y) for(int i=x;i<=y;i++)
#define ms(x,y) memset(x,y,sizeof(x))
int n;
void doit()
{
    scanf("%d",&n);
    fr(i,1,n)scanf("%d",&a[i]);
    ms(dp,22);
    //printf("%d\n",dp[0][0]);
    dp[1][1]=dp[1][0]=1;

    fr(i,2,n)
    {   if (a[i]>=a[i-1])dp[i][0]=min(dp[i][0],dp[i-1][0]);
        if (a[i]<=a[i-1])dp[i][1]=min(dp[i][1],dp[i-1][1]);
        dp[i][0]=min(dp[i][0],dp[i-1][1]+1);
        dp[i][0]=min(dp[i][0],dp[i-1][0]+1);
        dp[i][1]=min(dp[i][1],dp[i-1][0]+1);
        dp[i][1]=min(dp[i][1],dp[i-1][1]+1);
    }
    printf("%d\n",min(dp[n][1],dp[n][0]));
}

int main() {
    //while (1)
    {
        doit();
    }
    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n,x,t;
    cin>>n>>x>>t;
    cout<<(n+x-1)/x*t<<endl;
}


Measured memory_bytes: 3464
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

N, M = map(int, input().split())
bridges = [list(map(int, input().split())) for _ in range(M)]
bridges = bridges[::-1]
uf = UnionFind(N)
ans = N * (N-1) // 2
res = []
for b in bridges:
    res.append(ans)
    x, y = b
    if uf.isSameGroup(x, y):
        pass
    else:
        ans -= uf.Count(x) * uf.Count(y)
        uf.Unite(x, y)

for a in res[::-1]:
    print(a)
    


Measured memory_bytes: 33500
#include <stdio.h>

int main(void) {
	char s[4];
	int i;
	int kugyu = 0;
	if (scanf("%3s", s) != 1) return 1;
	for (i = 0; i < 3; i++) {
		if (s[i] == '1') kugyu++;
	}
	printf("%d\n", kugyu);
	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll x[100000], y[100000];
ll sumX[100000], sumY[100000];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> x[i];
	for (int i = 0; i < m; i++) cin >> y[i];
	sumX[n - 1] = x[n - 1];
	for (int i = n - 2; i >= 0; i--) sumX[i] = (sumX[i + 1] + x[i]) % MOD;
	sumY[m - 1] = y[m - 1];
	for (int i = m - 2; i >= 0; i--) sumY[i] = (sumY[i + 1] + y[i]) % MOD;
	ll X = 0, Y = 0;
	for (int i = 0; i < n; i++) {
		ll t = sumX[i];
		(t += MOD - ((n - i)*x[i]) % MOD) %= MOD;
		(X += t) %= MOD;
	}
	for (int i = 0; i < m; i++) {
		ll t = sumY[i];
		(t += MOD - ((m - i)*y[i]) % MOD) %= MOD;
		(Y += t) %= MOD;
	}
	cout << (X*Y) % MOD << endl;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <valarray>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>

using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n, k;
  cin >> n >> k;
  vector<ll> x(n), y(n);
  for (int i = 0; i < n; ++i)
    cin >> x[i] >> y[i];

  ll nmin = 1e20;
  for (int l = 0; l < n; ++l)
  {
    for (int r = l + 1; r < n; ++r)
    {
      for (int d = 0; d < n; ++d)
      {
        for (int u = d + 1; u < n; ++u)
        {
          int cnt = 0;
          for (int i = 0; i < n; ++i)
          {
            if ((x[l] <= x[i] && x[i] <= x[r] && y[d] <= y[i] && y[i] <= y[u]) || (x[r] <= x[i] && x[i] <= x[l] && y[d] <= y[i] && y[i] <= y[u]) || (x[l] <= x[i] && x[i] <= x[r] && y[u] <= y[i] && y[i] <= y[d]) || (x[r] <= x[i] && x[i] <= x[l] && y[u] <= y[i] && y[i] <= y[d]))
              cnt++;
          }
          if (cnt >= k)
            nmin = min(nmin, abs(x[l] - x[r]) * abs(y[d] - y[u]));
        }
      }
    }
  }
  cout << nmin << endl;

  return 0;
}


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

int main() {
  int mod=1000000007;
  long n,k;
  cin>>n>>k;
  vector<long>a(n);
  vector<long>pl,mi;
  priority_queue<long>p;
  priority_queue<long>m;
  rep(i,n){
    cin>>a.at(i);
    if(a.at(i)>=0){
      pl.push_back(a[i]);
    }
    else if(a.at(i)<0){
      mi.push_back(a[i]);
    }
  }
  sort(pl.begin(),pl.end());
  reverse(pl.begin(),pl.end());
  sort(mi.begin(),mi.end());
  reverse(mi.begin(),mi.end());
  long ans=1;
  if(pl.size()==0){
    if(k%2==1){
      rep(i,k){
        ans*=abs(mi[i]);
        ans%=mod;
      }
      cout<<(mod-ans)%mod<<endl;
    }
    else{
      reverse(mi.begin(),mi.end());
      rep(i,k){
        ans*=abs(mi[i]);
        ans%=mod;
      }
      cout<<ans<<endl;
    }
  }
  else if(n==k){
    rep(i,n){
      ans*=abs(a[i]);
      ans%=mod;
    }
    if(mi.size()%2==0){
      cout<<ans<<endl;
    }
    else{
      cout<<(mod-ans)%mod<<endl;
    }
  }
  else{
    reverse(mi.begin(),mi.end());
    if(k%2==1){
      ans*=pl[0];
      rep(i,(pl.size()-1)/2){
        p.push(pl[i*2+1]*pl[i*2+2]);
      }
      k--;
    }
    else{
      rep(i,pl.size()/2){
        p.push(pl[i*2]*pl[i*2+1]);
      }
    }
    rep(i,mi.size()/2){
      m.push(mi[i*2]*mi[i*2+1]);
    }
    int co=0;
    while(co<k/2){
      if(!p.empty()&&!m.empty()){
        if(p.top()<m.top()){
          ans*=m.top()%mod;
          ans%=mod;
          m.pop();
        }
        else{
          ans*=p.top()%mod;
          ans%=mod;
          p.pop();
        }
      }
      else if(p.empty()){
        ans*=m.top()%mod;
        ans%=mod;
        m.pop();
      }
      else if(m.empty()){
        ans*=p.top()%mod;
        ans%=mod;
        p.pop();
      }
      co++;
    }
    cout<<ans<<endl;
  }  
}

Measured memory_bytes: 8152
#include "iostream"
using namespace std;
int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (0 <=x-r && x+r<=W && 0<=y-r && y+r<=H )
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int h[100005];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
	}
	for(int i=n;i>=2;i--)
	{
		if(h[i]<h[i-1]) h[i-1]--;
	}
	for(int i=1;i<=n-1;i++)
	{
		if(h[i]>h[i+1])
		{
			cout<<"No";
			return 0;
		}
		else continue;
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdlib>
#include<stack>

using namespace std;

int main(){
    string t;
    stack<int> s;
    while(cin >> t){
        if(t == "+"){
            int s1 = s.top();
            s.pop();
            int s2 = s.top();
            s.pop();
            s.push(s1 + s2);
        } else if(t == "*"){
            int s1 = s.top();
            s.pop();
            int s2 = s.top();
            s.pop();
            s.push(s1 * s2);
        } else if(t == "-"){
            int s1 = s.top();
            s.pop();
            int s2 = s.top();
            s.pop();
            s.push(s2 - s1);
        } else{
            s.push(atoi(t.c_str()));
        }
    }
    cout << s.top() << endl;
    return 0;
}

Measured memory_bytes: 1200
(* O(2^N) *)
let solve n vs cs =
  let rec loop i x y =
    if i >= n then
      x - y
    else
      max
        (loop (i + 1) (x + vs.(i)) (y + cs.(i)))
        (loop (i + 1) x y)
  in
    loop 0 0 0

let read_ints () = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let list_to_array n a xs =
  let res = Array.make n a in
  List.iteri (fun i x -> res.(i) <- x) xs;
  res

let _ =
  let n = read_int () in
  let vs = read_ints () |> list_to_array n 0 in
  let cs = read_ints () |> list_to_array n 0 in
  solve n vs cs |> string_of_int |> print_endline

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
int W[110];

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> W[i];
    }

    int d = 1001001001;

    for(int t=0;t<N;++t){
        int S1 = std::accumulate(W, W + t, 0), S2 = std::accumulate(W + t, W + N, 0);
        d = std::min(d, std::abs(S1 - S2));
    }

    std::cout << d << std::endl;
}


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

int main() {
    string s;
    cin >> s;
    if(s[0] != s[1] && s[1] != s[2] && s[2] != s[0]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(obj) (obj).begin(), (obj).end() //イテレータの簡略化（コンテナじゃないと使えない）
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 100100100;

// 最大公約数
int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

// 最小公倍数
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

/* 二分探索 */

//indexが条件を満たすかどうか
bool isOK(int index, int key, vector<int> a) {
    if (a[index] >= key) return true;
    else return false;
}

//汎用的な二分探索のテンプレ
int meguru_binary_search(int key, vector<int> A){
    int ng = -1; // lowerの時は-1, upperの時は(int)A.size() //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)A.size(); // lowerの時は(int)A.size(), upperの時は-1 // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if(isOK(mid, key, A)) ok = mid;
        else ng = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている(lowerだと) */
    return ok;
}
/* lower_boundとかでイテレータから配列の添え字を求めたいとき(lower_bound(v.begin(),v.end(),hoge)-v.begin())というようにする */
//distanceも使える

//三項演算子 ?:

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    if(a < c && c < b) cout << "Yes" << endl;
    else if (b < c && c < a) cout << "Yes" << endl;
    else cout << "No" << endl;
    

    
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

		
			var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long A = inputArray[0];
			long B = inputArray[1];

			//最大公約数を求める
			var gcd = getGcd(A, B);

			if (gcd==1) {
				Console.WriteLine(1);
				return;
			}



			//各素数で何回割れるか
			var primeSet = new HashSet<long>();

			long k = 2;
			var tmp = gcd;
			var kMax = Math.Ceiling(Math.Sqrt(long.MaxValue));
			while (k * k <= gcd) {

				if (tmp % k == 0) {

					tmp /= k;
					if (!primeSet.Contains(k)) {
						primeSet.Add(k);
					}
	
				}
				else {
					k++;
					if (k > kMax) {//N<long.maxなのでk<ルート(long.max)
						break;
					}
				}
			}
			if (tmp != 1) {//最後に残る素数(=Nが素数の場合など)
				if (!primeSet.Contains(tmp)) {
					primeSet.Add(tmp);
				}

			}

			//答えの出力
			var ans = primeSet.Count()+1;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}

		/// <summary>
		/// 最大公約数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		private static long getGcd(long a, long b) {
			if (a < b) {
				return getGcd(b, a);
			}
			if (b > 0) {
				return getGcd(b, a % b);
			}
			else {
				return a;
			}
		}
	}
}

Measured memory_bytes: 13524
x = int(input())
if  400<= x <= 599: ans = 8
elif 600 <= x <= 799: ans = 7
elif 800 <= x <= 999: ans = 6
elif 1000 <= x <= 1199: ans = 5
elif 1200 <= x <= 1399: ans = 4
elif 1400 <= x <= 1599: ans = 3
elif 1600 <= x <= 1799: ans = 2
else: ans = 1
print(ans)

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int long long
#define pb push_back
#define pii pair<int,int>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define nl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main()
{   fastio;

    int n;
    cin>>n;
    string s="";
    //n--;
    while(n != 0) {
        s += 'a' + (n-1)%26;
        n=(n-1)/26;
    }
    reverse(s.begin() , s.end());
    cout<<s<<endl;
}

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

int main() {
  int n, d, x; cin >> n >> d >> x;
  int ans = x;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    for (int j = 1; j <= d; j += a) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

struct Elem {
    ll pos, cost, hp;
    Elem() {}
    Elem(ll a, ll b, ll c) : pos(a), cost(b), hp(c) {}
    bool operator<(const Elem &e) const {
        if(cost != e.cost) return cost > e.cost;
        return hp < e.hp;
    }
};

ll L;
vector<int> calc(const vector< vector< pair<ll, ll> > > &G, int s) {
    int N = G.size();
    vector< pair<ll, ll> > dist(N, make_pair(INF, INF));
    dist[s] = make_pair(0, L);

    priority_queue<Elem> que;
    que.emplace(s, 0, L);
    while(que.size()) {
        Elem cur = que.top(); que.pop();

        ll cost = cur.cost, hp = cur.hp;
        if(make_pair(cost, -hp) > make_pair(dist[cur.pos].first, -dist[cur.pos].second)) continue;
        
        for(auto e : G[cur.pos]) {
            ll to, d; tie(to, d) = e;
            if(d > L) continue;

            bool chg = (cur.hp - d < 0);
            ll n_cost = cur.cost + chg;
            ll n_hp = chg ? L - d : cur.hp - d;

            ll x_cost, x_hp; tie(x_cost, x_hp) = dist[to];
            if(make_pair(n_cost, -n_hp) < make_pair(x_cost, -x_hp)) {
                dist[to] = make_pair(n_cost, n_hp);
                que.emplace(to, n_cost, n_hp);
            }
        }
    }

    vector<int> ans(N);
    for(int i=0; i<N; i++) ans[i] = dist[i].first == INF ? -1 : dist[i].first;
    return ans;
}

int main() {
    ll N, M; cin >> N >> M >> L;
    vector< vector< pair<ll, ll> > > G(N);
    for(int i=0; i<M; i++) {
        ll u, v, c; cin >> u >> v >> c;
        u--; v--;
        G[u].emplace_back(v, c);
        G[v].emplace_back(u, c);
    }

    vector< vector<int> > dist(N);
    for(int i=0; i<N; i++) dist[i] = calc(G, i);

    int Q; cin >> Q;
    while(Q--) {
        int u, v; cin >> u >> v; u--; v--;
        cout << dist[u][v] << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
console.log((args=>{
  const [[N,M],...req] = args.trim().split('\n').map( r=>r.split(' ').map(v=>v|0));
  req.sort((a,b)=>a[1]-b[1]);
  const mfl = [req[0][1]-1];
  for ( let i = 1; i < M; i++ ) {
    if ( mfl[mfl.length-1] < req[i][0] ) mfl.push( req[i][1]-1 );
  }
  return `${mfl.length}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 64756
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int MAX_N = 1010;
int N;
vector<int> cnt;
vector<pair<int, int>> T[MAX_N];
vector<int> used(MAX_N, 0);
int dfs(int depth)
{
    used[depth] = 1;
    int res = 0;
    for(int u = 0; u < (int)T[depth].size(); u++)
    {
        pair<int, int> e = T[depth][u];
        if(used[e.first]) continue;
        if(cnt[e.first] > 0) res += e.second;
        else res += min(e.second,dfs(e.first));
    }
    return res;
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    cnt.resize(N, 0);
    for(int i = 1; i < N; i++) cin >> cnt[i];
    for(int i = 0; i < N - 1; i++)
    {
        int u, v, p; cin >> u >> v >> p;
        T[u].push_back(make_pair(v, p));
        T[v].push_back(make_pair(u, p));
    }
    cout << dfs(0) << endl;
    return 0;
}




Measured memory_bytes: 3272
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<cstdio>
#include <iomanip>
#include <limits>
#include<vector>
using namespace std;

int main()
{
	int N,i,j,k,l,m,n,o,p;
	long long int sum, flag,cc,cnt;
	sum = 0;
	flag = 1;
	cc = 0;
	cnt = 0;
	int A[3] = {};
	cin >> A[0] >> A[1] >> A[2];
	sort(A, A + 3);
	cout << A[2] - A[0] << endl;
	
    return 0;
}



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

int main() {
    string a , b;
    cin >> a >> b;
    
    int n = 0;
    for (int i = 0; i < a.length(); i++) {
        n *= 10;
        n += a[i] - '0';
    }
    
    for (int i = 0; i < b.length(); i++) {
        n *= 10;
        n += b[i] - '0';
    }
    
    int s = sqrt(n);
    if (s * s == n) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
  #define DUMP(i) 
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());

using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

struct Edge{
public:
  int from,to,cost;
  Edge(){}
  Edge(int _from,int _to,int _cost){
    from = _from;
    to = _to;
    cost = _cost;
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


const int EPS = 1e-9;
const int MOD = 1e9+7;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi T(n);
  int sum = 0;
  REP(i,n){
    cin >> T[i];
    sum += T[i];
  }

  int m;
  cin >> m;
  REP(i,m){
    int p,x;
    cin >> p >> x;
    int ans = sum - T[p-1] + x;
    cout << ans << endl;
  }
  
  return 0;
}



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

#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define pll     pair<long long, long long>
#define ll      long long

struct UnionFind {
        int n;
        vector<int> parent;
        vector<int> rank;
        vector<int> num;
        int find(int x) {
                if (parent[x] == x) return  x;
                return parent[x] = find(parent[x]);
        }
        UnionFind(int n_) {
                n = n_;
                parent.resize(n);
                for (int i = 0; i < n; i ++) parent[i] = i;
                rank.assign(n, 0);
                num.assign(n, 1);
        }
        void unite(int x, int y) {
                if ((x = find(x)) != (y = find(y))) {
                        if (rank[x] < rank[y]) {
                                parent[x] = y;
                                num[y] += num[x];
                        } else {
                                parent[y] = x;
                                if (rank[x] == rank[y]) rank[x] ++;
                                num[x] += num[y];
                        }
                        n --;
                }
        }
        bool same(int x, int y) { return find(x) == find(y); }
        int get() { return n; }
        int get(int x) { return num[find(x)]; }
};

vector<int> g[100000], rg[100000];

int color[100000];
int A, B, C, edge;

int dfs(int v, int c) {
        if (color[v] == -1) { 
                color[v] = c;
                if (c == 0) A ++;
                else if (c == 1) B ++;
                else C ++;
        } else if (color[v] != c) return -1;
        else return 0;
        for (int u : g[v]) { 
                edge ++;
                if (dfs(u, (c + 1) % 3) == -1) return -1;
        }
        for (int u : rg[v]) { 
                edge ++;
                if (dfs(u, (c - 1 + 3) % 3) == -1) return -1;
        }
        return 0;
}

int main() {
        int n, m;
        cin >> n >> m;
        UnionFind uf(n + 1);
        for (int i = 0; i < m; i ++) {
                int a, b;
                cin >> a >> b;
                a --, b --;
                g[a].push_back(b);
                rg[b].push_back(a);
                uf.unite(a, b);
        }
        memset(color, -1, sizeof color);
        long long ans = 0;
        for (int i = 0; i < n; i ++) if (!uf.same(i, n)) {
                long long num = uf.get(i);
                uf.unite(i, n); //used
                A = 0, B = 0, C = 0, edge = 0;
                if (dfs(i, 0) == -1) ans += num * num;
                else if (C == 0 || B == 0) ans += edge / 2;
                else ans += 1LL * A * B + 1LL * B * C + 1LL * C * A;
        }
        cout << ans << endl;
        return 0;
}



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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N;
    ll sum = 0;
    vector<ll> B;
    cin >> N;
    B.resize(N);
    for(ll i = 0;i < N - 1;i++) cin >> B[i];
    sum += B[0];
    for(ll i = 1;i < N - 1;i++) sum += min(B[i], B[i - 1]);
    sum += B[N - 2];
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
N, X, Y = map(int, input().split())
cnt = [0]*N
for i in range(1, N):
    for j in range(i+1, N+1):
        d = min([abs(i-j), (abs(i-X) + 1 + abs(Y-j)), (abs(i-Y) + 1 + abs(X-j))])
        cnt[d] += 1
for i in range(1, N):
    print(cnt[i])

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
#define PB push_back
#define INF 1000000001
#define INFL 1000000000000000001
#define M 1000000007
int n,a[200005],ls[200005],rs[200005];
int main(void){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)ls[i]=max(ls[i-1],a[i]);
	for(int i=n;i>=0;i--)rs[i]=max(rs[i+1],a[i]);
	for(int i=1;i<=n;i++)printf("%d\n",max(ls[i-1],rs[i+1]));
}


Measured memory_bytes: 3968
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

//
LL n;
double p[3005];
double ans = 0.0;
double dp[3005][3005];

int main(){
	scanf("%lld",&n);
	for(LL i = 1;i <= n;i ++) scanf("%lf",&p[i]);
	dp[0][0] = 1.0;
	for(LL i = 1;i <= n;i ++){
		for(LL j = 0;j <= i;j ++){
			dp[i][j] = dp[i - 1][j] * (1.0 - p[i]);
			if(j) dp[i][j] += dp[i - 1][j - 1] * p[i];
		}
	}
	for(LL i = (n >> 1) + 1;i <= n;i ++) ans += dp[n][i];
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 68992
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<int> s(n);
   rep(i, 0, n) {
      int w;
      cin >> w;
      if (i == 0)
         s[0] = w;
      else
         s[i] = s[i - 1] + w;
   }
   int ans = INF;
   rep(i, 0, n - 1) {
      int s1 = s[i];
      int s2 = s[n - 1] - s[i];
      ans = min(ans, abs(s1 - s2));
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main(){
  int n,s;
  cin>>n>>s;
  int a[n+1];
  rep(i,n)cin>>a[i];
  a[n]=s;
  sort(a,a+n+1);
  int diff[n+1];
  rep(i,n)diff[i]=a[i+1]-a[i];
  diff[n]=diff[n-1];
  //for(auto i:diff)cout<<i<<" ";cout<<endl;
  int gcd=diff[n];
  rep(i,n){
    int p=diff[i];
    int r=gcd;
    while(true){
      if(p<r)swap(p,r);
      if(!r)break;
      if(p==r)break;
      p%=r;
    }
    gcd=p;
  }
  cout<<gcd<<endl;
  return 0;
}


Measured memory_bytes: 1152
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

def cal(bit,i):
    return bit*N + i


def dijkstra(lines,N,s):
    weight = [INF]*N
    weight[s] = 0
    def search(s,w_0,q,weight):
        for t,w in lines[s]:
            w += w_0
            if weight[t] > w:
                heapq.heappush(q,[w,t])
                weight[t] = w
    q = [[0,s]]
    heapq.heapify(q)
    while q:
        w,n = heapq.heappop(q)
        search(n,w,q,weight)
    return weight

while True:
    L,N,M,S,T = inpl()
    if N == 0 and M == 0:
        break
    tt = inpl()
    S -= 1
    T -= 1
    lines = defaultdict(set)
    for _ in range(M):
        x,y,z = inpl()
        x,y = x-1,y-1
        lines[x].add((y,z))
        lines[y].add((x,z))

    lines2 = defaultdict(set)
    for s in range(N):
        for bit in range(1<<L):
            val_s = cal(bit,s)
            for b in range(L):
                if bit&(1<<b): # b番目の馬券を持ってる
                    bbit = bit - (1<<b)
                    for t,c in lines[s]:
                        val_t = cal(bbit,t)
                        #print(bin(bit),s,'->',bin(bbit),t,'  ',c/tt[b])
                        lines2[val_s].add((val_t,c/tt[b]))

    weights = dijkstra(lines2,(1<<L)*N,cal((1<<L)-1,S))
    ans = INF
    for bit in range(1<<L):
        ans = min(ans,weights[cal(bit,T)])

    if ans == INF:
        print('Impossible')
    else:
        print(ans)



Measured memory_bytes: 174972
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    
    s.nextInt();
    String str = s.next();
    int totalLength = str.length();
    str = str.replaceAll("R", "");
    int blue = str.length();
    int red = totalLength - blue;
    System.out.println(red > blue ? "Yes" : "No");
  }
}


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

using namespace std;
using ll =long long;
using db = double;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
const int mod = 1e9 + 7;

//ここから書き始める
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX + 1];

int solve()
{
	int ans = 0;

	bool V[MAX];
	rep(i,n){
		B[i] = A[i];
		V[i] = false;
	}
	sort(B,B+n);
	rep(i,n)
		T[B[i]]= i ;
	rep(i,n){
		if (V[i]) continue;

		int cur = i ;
		int S = 0;
		int m = VMAX;
		int an = 0;
		while(1){
			V[cur] = true;
			an++;
			int v =A[cur];
			m = min(m,v);
			S += v;
			cur = T[v];
			if( V[cur] ) break;
		}
		ans += min(S + (an - 2 )*m, m + S+(an + 1 ) * s);
	}
	return ans;
}

int main ()
{
	cin >> n;
	s = VMAX;
	rep(i,n){
		cin >> A[i];
		s = min(s,A[i]);
	}
	int ans = solve();
	cout << ans << endl; 
}



Measured memory_bytes: 3152
#include <iostream>
#include <stdlib.h>
#include <regex>
using namespace std;

long long N;
long long *A;
long long *B;

void input(){
    cin >> N;
    A = (long long *)malloc(sizeof(long long)*N);
    B = (long long *)malloc(sizeof(long long)*N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++){
        cin >> B[i];
    }
}

long long max_index(long long arr[]){
    long long max = -1000000000000000;
    long long max_i = -1;
    for(int i=0;i<N;i++){
        if(arr[i] >= max){
            max = arr[i];
            max_i = i;
        }
    }
    return max_i;
}

long long solve(){
    long long ret = 0;
    long long D[N]; //A-B
    long long dept = 0;
    long long property = 0;
    for(int i=0;i<N;i++){
        D[i] = A[i] - B[i];
        if(D[i] < 0){
            dept -= D[i];
            ret++;
        }else{
            property += D[i];
        }
    }
    if(dept > property){
        return -1;
    }
    while(dept > 0){
        long long index = max_index(D);
        dept -= D[index];
        D[index] = 0;
        ret++;
    }
    
    return ret;
}

int main(void){
    // Your code here!
    input();
    long long ret = solve();
    cout << ret << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

bool fn_is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

bool isOK(int index, int key, vector<ll>& a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<ll>& a) {
    int ng = -1;
    int ok = a.size();

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key, a)) ok = mid;
        else ng = mid;
    }
    return ok;
}

struct UnionFind {
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main()
{
    ll x; cin >> x;
    ll ans = 0;
    ans += x/11 * 2;
    x %= 11;
    if (x <= 6)
        ans++;
    else
        ans += 2;
    if (x == 0) ans--;
    cout << ans << endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>       
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int a,b,c,d;cin>>a>>b>>c>>d;
    int f1=0;
    while(c>0&&a>0)
    {
        c=c-b;
        if(c<=0)
        {
            f1=1;
            break;
        }
        a=a-d;
        if(a<=0)
        {
            f1=2;
            break;
        }
    }
    if(f1==1)
    {
        cout<<"Yes";
    }
    if(f1==2)
    {
        cout<<"No";
    }
    
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

ll solve(int l, int r,mat &dv, mat &dvr, mat &dsum, mat &dsumr){
    ll res(r - l);
    int nowl(l), nowr(r), len(1);
    Rrep(i, 18){
        if(dv[i][nowl] <= r){
            res -= dsum[i][nowl];
            nowl = dv[i][nowl];
            len += 1<<i;
        }
        if(dvr[i][nowr] >= l){
            res += dsumr[i][nowr];
            nowr = dvr[i][nowr];
        }
    }
    return res + len;
}

int main() {
    cin>>N>>K;
    N += 2;
    vec x(N), x_rev(N);
    mat dbl(18, vec(N)), dbl_rev(18, vec(N)), dbl_sum(18, vec(N, 0)), dbl_rev_sum(18, vec(N, 0));
    reps(i, 1, N - 1) cin>>x[i];
    x[0] = -INF; x[N - 1] = INF;
    copy(x.rbegin(), x.rend(), x_rev.begin());
    rep(i, N) x_rev[i] = - x_rev[i];
    //reps(i, 1, N - 1) cout<<x_rev[i]<<" \n"[i == N - 2];
    rep(i, N) {
        dbl[0][i] = dbl_sum[0][i] = min(N - 1, (ll)(lower_bound(ALL(x), x[i] + K) - x.begin()));
        dbl_rev[0][i] = dbl_rev_sum[0][i] = N - 1 - min(N - 1, (ll)(lower_bound(ALL(x_rev), x_rev[N - 1 - i] + K) - x_rev.begin()));
        //cout<<dbl_rev[0][i]<<" \n"[i == N - 1];
    }
    reps(i, 1, 18) {
        rep(v, N) {
            dbl[i][v] = dbl[i-1][dbl[i-1][v]];
            dbl_rev[i][v] = dbl_rev[i-1][dbl_rev[i-1][v]];
            dbl_sum[i][v] = dbl_sum[i-1][v] + dbl_sum[i-1][dbl[i-1][v]];
            dbl_rev_sum[i][v] = dbl_rev_sum[i-1][v] + dbl_rev_sum[i-1][dbl_rev[i-1][v]];
        }
    }
    cin>>Q;
    rep(_, Q){
        int l, r; cin>>l>>r;
        cout<<solve(l, r, dbl, dbl_rev, dbl_sum, dbl_rev_sum)<<endl;
    }
}


Measured memory_bytes: 120464
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
using PII = pair<ll, ll>;
#define FOR(i,a,n) for(ll i=(ll)a; i<(ll)n; ++i)
#define REP(i,n) FOR(i,0,n)

struct Edge {
	int to, sttime, cost, index;
	Edge(const int t, const int s, const int c, const int i) {
		to = t, sttime = s, cost = c, index = i;
		return;
	}
	bool operator<(const Edge&e)const {
		return sttime < e.sttime;
	}
};

int main() {
	int N, M, S, G;
	cin >> N >> M >> S >> G;
	S--, G--;
	vector<vector<Edge>>edge(N);
	for (int i = 0; i < M; i++) {
		int l, r, s, t;
		cin >> l >> r >> s >> t;
		l--, r--;
		edge[l].push_back(Edge(r, s, t, i));
	}
//cout << "JHIJHI" << endl;
	for (int i = 0; i < N; i++)sort(edge[i].begin(), edge[i].end());
	vector<vector<pair<int, int>>>dis_edge(M + 1);
//	cout << "GUUG" << endl;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < (int)(edge[i].size()) - 1; j++) {
			dis_edge[edge[i][j].index].push_back({ edge[i][j + 1].index,edge[i][j + 1].sttime - edge[i][j].sttime });
		}
		vector<pair<int, int>>box;
		for (auto j : edge[i]) {
			if (j.to == G) {
				dis_edge[j.index].push_back({ M,0 });
				continue;
			}
			if (edge[j.to].empty())continue;
			int L = -1, R = edge[j.to].size();
			while (R - L > 1) {
				int mid = (R + L) / 2;
				if (edge[j.to][mid].sttime >= j.sttime + j.cost)R = mid;
				else L = mid;
			}
			if (R == edge[j.to].size())continue;
			dis_edge[j.index].push_back({ edge[j.to][R].index,edge[j.to][R].sttime - j.cost - j.sttime });
		}
	}
	//cout << "Ho" << endl;
	vector<int>dis(M+1, MOD);
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>PQ;
	for (auto i : edge[S]) {
		dis[i.index] = i.sttime;
		PQ.push({ i.sttime,i.index });
	}
	while (!PQ.empty()) {
		int cn = PQ.top().second;
		int c = PQ.top().first;
		PQ.pop();
		for (auto j : dis_edge[cn]) {
			if (dis[j.first] > c + j.second) {
				dis[j.first] = c + j.second;
				PQ.push({ dis[j.first],j.first });
			}
		}
	}
	cout << dis[M] << endl;
}



Measured memory_bytes: 21312
#include <bits/stdc++.h>
using namespace std;
typedef struct{
    int c;
    int s;
    int f;
} info;
int main(){
    int n;
    cin >> n;
    vector<info> parm(n-1);
    for(int i = 0; i < n-1; i++){
        cin >> parm[i].c >> parm[i].s >> parm[i].f;
    }
    for(int i = 0; i < n-1; i++){
        long dis=parm[i].s+parm[i].c;
        for(int j = i+1; j < n-1; j++){
            if(dis<parm[j].s){
                dis = parm[j].s;
            }
            else if(dis > parm[j].s){
                int t = 0;
                while(dis>(parm[j].s + t))
                    t += parm[j].f;
                dis += parm[j].s + t - dis;
            }
            dis += parm[j].c;
        } 
        cout << dis << endl;
    }
    cout << "0";
}

Measured memory_bytes: 256
while(True):
	N = int(input())
	if N ==0 :break
	V = input().split()
	vote = {}
	top = 0
	second = 0
	for i in range(N):
		if V[i] in vote:
			vote[V[i]] += 1
			if top < vote[V[i]]:
				top = vote[V[i]]
			elif second < vote[V[i]]:
				second = vote[V[i]]
		else:
			vote[V[i]] = 1
			if top < vote[V[i]]:
				top = vote[V[i]]
			elif second < vote[V[i]]:
				second = vote[V[i]]
		ans = i+1
		if (N-1-i) < top-second: break
	if top == second:
		print("TIE")
	else:
		print("{} {}".format(max(vote, key=vote.get), ans))
			




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

int main()
{
	int A, B, K;
	cin >> A >> B >> K;

	int i,count = 0;
	for (i = min(A,B); count < K; --i)
	{
		if (!(A % i) && !(B % i))
		{
			++count;
		}
	}

	cout << i + 1 << endl;

	return 0;
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();


    int x1, x2, y1, y2;

    cin>>  x1>> y1>> x2>> y2;

    int dx= x2-x1, dy= y1- y2;

    cout << x2+ dy <<' ' << y2 + dx<< ' ' << x1+ dy<< ' '<< y1+ dx;
    nl;

    return 0;
}



Measured memory_bytes: 3596
import java.util.*;

public class Main {
public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a=sc.nextInt();
		int b=sc.nextInt();
		int k=sc.nextInt();
		int q=0;
		int count=0;
		int answer=0;
		if(b>a){
			q=a;
			a=b;
			b=q;
		}

		for(int i=b;i>0;i--){
			if(a%i==0 && b%i==0){
				count++;
				if(count==k){
					answer=i;
					break;
				}
			}
		}

		System.out.println(answer);

	}
}


Measured memory_bytes: 23380
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    if n%2==0:
        ans=0
        i=0
        while 10*5**i<=n:
            ans+=n//(10*5**i)
            i+=1
        print(ans)
    else:print(0)

if __name__=='__main__':
    main()

Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;
const int INF = 1e9;
const double PI = acos(-1.0);

int main() {
	
	int n, k;
	cin >> n >> k;
	int p = n / k;
	int m = n % k;
	ll ans = 0;
	vector<int> modk(k, 0);
	for (int i = 0; i < k; i++) {
		if (i != 0 && m - i >= 0)modk[i]++;
		modk[i] += p;
	}

	for (int i = 0; i < k; i++) {
		if (i == 0) {
			ans += (ll)modk[0] * modk[0] * modk[0];
		}
		else {
			if (2 * i%k == 0)ans += (ll)modk[i] * modk[k - i] * modk[i];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

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

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

   if(a<=b && b<=c)
      printf("%d %d %d\n", a, b, c);

   else if(b<=c && c<=a)
      printf("%d %d %d\n", b, c, a);

   else if(c<=a && a<=b)
      printf("%d %d %d\n", c, a, b);

   else if(a<=c && c<=b)
      printf("%d %d %d\n", a, c, b);

   else if(b<=a && a<=c)
      printf("%d %d %d\n", b, a, c);

   else if(c<=b && b<=a)
      printf("%d %d %d\n", c, b, a);

   return 0;
}

Measured memory_bytes: 1796
#include<bits/stdc++.h>
using namespace std;
long long int k, i, j, l, ans;
int main()
{
    cin >> k;
    for(i=1;i<=k;i++)
    {
        for(j=1;j<=k;j++)
        {
            for(l=1;l<=k;l++)
            {
                ans += __gcd(i, __gcd(j,l));
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int n = 3;
	vector<vector<int>> c(n, vector<int>(n));
	for (auto& r : c) {
		for (auto& e : r) {
			cin >> e;
		}
	}
	for (int i = 0; i < n; i++) {
		int m = INT_MAX;
		for (int j = 0; j < n; j++) {
			m = min(m, c[i][j]);
		}
		for (int j = 0; j < n; j++) {
			c[i][j] -= m;
		}
	}
	bool r = true;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			r &= c[i][j] == c[0][j];
		}
	}
	cout << (r ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256