akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
 
 
def main():

    # mapは引数1の関数を引数2へ当てはめる 
    num_candy = list(map(int,input().split(' ')))
    max_candy = max(num_candy)
 
    if sum(num_candy) / 2 == max_candy:
        print("Yes")
    else:
      print("No")
 
    return 0
 
 
if __name__ == '__main__':
    main()

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

int main() {
    
    int n;
    cin >> n;
    int result = 0;
    
    for (int i = 1; i < n; i++) {
        for (int j = 1; i*j < n; j++) {
            result++;
            // if (i == j) {
            //     result++;
            // } else {
            //     result += 2;
            // }
        }
    }

    cout << result << endl;

    return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=1e9+7;
const int N=1e9+5;

int main(){
    int N, K; cin >> N >> K;
    vi A(N);
    for(auto &x: A) cin >> x;
    while(K--){
        bool ok=true;
        vi cnt(N+1, 0);
        for(int i=0; i<N; i++){
            cnt[max(0, i-A[i])]++;
            cnt[min(N, i+A[i]+1)]--;
        }
        for(int i=1; i<=N; i++){
            cnt[i]+=cnt[i-1];
        }
        for(int i=0; i<N; i++){
            A[i]=cnt[i];
            if(A[i] != N) ok=false;
        }
        if(ok) break;
    }
    for(int i=0; i<N; i++){
        if(i != 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4848
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
//#include<cmath>
using namespace std;
int main() {
	int A[10000];
	int n, i;
	long long s = 0;
	cin >> n;
	for (i = 0; i < n; i++) cin >> A[i],s+=A[i];
	sort(A, A + n);
	cout << A[0] <<" "<< A[n - 1] <<" "<< s << endl;
	return 0;
}

Measured memory_bytes: 3132
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {		
		Scanner scanner = new Scanner(System.in);
		String date = scanner.next();
		
		int year = Integer.parseInt(date.substring(0, 4));
		int month = Integer.parseInt(date.substring(5, 7));
		int day = Integer.parseInt(date.substring(8, 10));
		
		if(year <= 2019 && month <= 04) {
			System.out.println("Heisei");
		} else {
			System.out.println("TBD");
		}
		
	}
}

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

const int MAX = 300;
int main() {
	int N;
	string S[MAX], tmp;
	cin >> N;
	for (int i = 0;i < N;i ++) cin >> S[i];
	
	int correct = 0;
	for (int i = 0;i < N;i ++) { // Aに当たる
		bool isCorrect = true;
		for (int j = 0;j < N;j ++) {
			for (int k = 0;k < N;k ++) {
				if (S[j][k] != S[k][j]) isCorrect = false;
			}
		}
		if (isCorrect) correct ++;
		tmp = S[0];
		for (int j = 1;j < N;j ++) {
			S[j - 1] = S[j];
		}
		S[N - 1] = tmp;
	}
	cout << correct * N;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

今、あるA,Bにおいての盤面をS(A, B)としておくよ
この時、S(A+1, B+1)の盤面とS(A, B)の盤面におけるペアは等しくなることが実験すると分かるよ
なので、調べるパターンはN^2じゃなくN通りで良い
O(N^3)は通るので、つまりN通りの盤面全てで実際に調べてしまえば解けるね
*/

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

int main(int argv, char *argc[]){
    
    int *determinant, *vector;
    int row, line, rcounter, lcounter, result;
    
    scanf("%d %d\n", &row, &line);
    
    determinant = (int *)calloc(row*line, sizeof(int));
    vector = (int *)calloc(line, sizeof(int));

    for(rcounter=0; row>rcounter; rcounter++){
        for(lcounter=0; line>lcounter; lcounter++){
            scanf("%d", &determinant[(rcounter*line) + lcounter]);
            if(line-1 >lcounter) scanf(" ");
            else scanf("\n");
        }
    }
    
    for(lcounter=0; line>lcounter; lcounter++){
        scanf("%d\n", &vector[lcounter]);
    }
    
    for(rcounter=0; row>rcounter; rcounter++){
        for(lcounter=0; line>lcounter; lcounter++){
             result += vector[lcounter] * determinant[(rcounter*line) + lcounter];
        }
        printf("%d\n", result);
        result = 0;
    }
    
    free(determinant);
    free(vector);
    
    return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main() {
	lli N, K;
	cin >> N >> K;
	lli res = 0;

	//bの値に対してaとしてありうる個数を計算
	//ただしa=0のケースも足す
	for (lli b = K + 1;b <= N;b++) {
		//Nをbで割ったあまりK未満かK以上かで場合分け
		if (N%b < K) res +=(N / b)*(b - K);
		else res += (b - K)*(N / b) + N % b - K + 1;
	}
	//a=0のケースを引く.これはK=0の場合に対応
	if (K == 0) res -= N;
	cout << res;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int X,Y,Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y << endl;
}

Measured memory_bytes: 256
import copy
N = int(input())
A = [int(input()) for i in range(N)]
B = copy.copy(A)
Max_1 = max(A)
B.remove(Max_1)
Max_2 = max(B)

for i in A:
    if i == Max_1:
        print(Max_2)
    else:
        print(Max_1)

Measured memory_bytes: 14560
INF = float("inf")

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_ints_list = lambda:list(input_ints())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,input_func:[input_func() for _ in range(n)]

import importlib
import_module = lambda module_name:importlib.import_module(module_name)

init_array_1dim = lambda value,n:[value]*n # 1次元配列を生成
init_array_2dim = lambda value,n,m:[init_array_1dim(value,n) for _ in range(m)] # 2次元配列を生成

gcd_base = lambda value1,value2:import_module('fractions').gcd(value1,value2) # 最大公約数（2値)
gcd = lambda lst:import_module('functools').reduce(gcd_base,lst) # 最大公約数（リスト）
lcm_base = lambda value1,value2:(value1*value2)//gcd_base(value1,value2) # 最小公倍数(2値)
lcm = lambda lst:import_module('functools').reduce(lcm_base,lst,1) # 最小公倍数(リスト)

permutations = lambda lst,n:import_module('itertools').permutations(lst,n) # 順列
combinations = lambda lst,n:import_module('itertools').combinations(lst,n) # 組み合わせ
product = lambda lst1,lst2:import_module('itertools').product(lst1,lst2) # 二つのリストの直積

round = lambda value:round(value) # 四捨五入
ceil = lambda value:import_module('math').ceil(value) # 切り上げ
floor = lambda value:import_module('math').floor(value) # 切り捨て

# キュー
init_q = lambda lst: import_module('collections').deque(lst)
q_pop = lambda q: q.popleft() # 先頭から取り出し
q_push = lambda q,value:q.appendleft(value) # 先頭に追加（値）
q_pushlist = lambda q,lst:q.extendleft(lst) # 先頭に追加（リスト）
q_append = lambda q,value:q.append(value) # 末尾に追加（値）
q_appendlist = lambda q,lst:q.extend(lst) # 末尾に追加（リスト）

# プライオリティキュー
init_heap = lambda a:import_module('heapq').heapify(a)
heap_push = lambda a,v:import_module('heapq').heappush(a,v)
heap_pop = lambda a:import_module('heapq').heappop(a) # 最小値を取り出す

def solution():
    # ここに実装
    N = input_int()
    abc = input_lines(N,input_ints_list)

    dp = init_array_2dim(-1,3,N)
    for i in range(N):
        if i == 0:
            dp[i][0] = abc[0][0]
            dp[i][1] = abc[0][1]
            dp[i][2] = abc[0][2]
        else:
            dp[i][0] = abc[i][0] + max(dp[i-1][1],dp[i-1][2])
            dp[i][1] = abc[i][1] + max(dp[i-1][0],dp[i-1][2])
            dp[i][2] = abc[i][2] + max(dp[i-1][0],dp[i-1][1])
    print(max(dp[N-1]))
    
if __name__ == '__main__':
    solution()

Measured memory_bytes: 70236
INF = 10 ** 10
n, m = gets.split.map(&:to_i)
edges = []
m.times { edges << gets.split.map(&:to_i) }
graph = Array.new(n + 1) { Array.new }
# 重み付き有向グラフ
edges.each do |f, t, w|
  graph[f] << [f, t, w]
  graph[t] << [t, f, -w]
end

# 全ての頂点 pos を仮に定める
# グラフが非連結な場合があるため、BFS を繰り返す
pos = Array.new(n + 1, INF)
(1..n).each do |node|
  if pos[node] == INF
    queue = [[node, node, 0]]
    until queue.empty?
      from, to, weight = queue.shift
      # 既に pos が仮決めされている場合は飛ばす
      next if pos[to] != INF
      pos[to] = weight
      graph[to].each do |f, t, w|
        # 逆流しないようにする（両方のグラフに入れているので必ず1つ該当する）
        next if t == from
        queue << [f, t, w + weight]
      end
    end
  end
end

# 仮決めした頂点 pos が全て正しいかどうかを確認する
puts edges.all? { |f, t, w| pos[f] + w == pos[t] } ? "Yes" : "No"


Measured memory_bytes: 57340
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100

int pop(void);
void push(int);
int stack[N],top=0;

int main(){
  int n,m,i;
  char c[N];

  while(scanf("%s",c)!=EOF){
    if (c[0]=='+'){
      m=pop();
      n=pop();
      push(n+m);
    } else if (c[0]=='-'){
      m=pop();
      n=pop();
      push(n-m);
    } else if (c[0]=='*'){
      m=pop();
      n=pop();
      push(n*m);
    } else {
      n=atoi(c);
      push(n);
    }
  }
  printf("%d\n",stack[1]);
  return 0;
}

int pop(void){
  top--;
  return stack[top+1];
}

void push(int i)
{ 
  top++;
  stack[top]=i;
}

Measured memory_bytes: 548
#include <stdio.h>
#include <math.h>

typedef struct {
  double x;
  double y;
}xy;

void kock(int,xy,xy);

int main(){
  xy p1 = {0.0, 0.0},p2 = {100.0, 0.0};
  int n;
  
  scanf("%d",&n);
  if(n < 0 || n > 6)return 0;
  
  printf("%.8lf %.8lf\n",p1.x,p1.y);
  
  kock(n,p1,p2);
  
  printf("%.8lf %.8lf\n",p2.x,p2.y);
    
  return 0;
}

void kock(int n,xy p1,xy p2){
    xy s,t,u;
  
  if(n == 0)return;
  
  s.x = (2*p1.x + p2.x)/3;
  s.y = (2*p1.y + p2.y)/3;
  t.x = (p1.x + 2*p2.x)/3;
  t.y = (p1.y + 2*p2.y)/3;
  u.x = (t.x - s.x)*cos(M_PI / 3) - (t.y -s.y)*sin(M_PI / 3) + s.x;
  u.y = (t.x - s.x)*sin(M_PI / 3) + (t.y -s.y)*cos(M_PI / 3) + s.y;

  kock(n-1,p1,s);
  printf("%.8lf %.8lf\n",s.x,s.y);
  kock(n-1,s,u);
  printf("%.8lf %.8lf\n",u.x,u.y);
  kock(n-1,u,t);
  printf("%.8lf %.8lf\n",t.x,t.y);
  kock(n-1,t,p2);
}



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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
ll mod , n , a[100005];
string s;

ll solve()
{
    ll tn=1 , cur=0 , ans=0;
    for(int i=n; i>0; i--)
    {
        cur = tn*(s[i]-'0') + cur;
        cur %= mod;
        tn *= 10;
        tn %= mod;
        ans += a[cur];
        if (cur==0) ans++;

        a[cur]++;
    }
    return ans;
}

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

    cin >> n >> mod >> s;
    s = ' '+s;

    if (mod != 2 && mod != 5)
    {
        ll ans = solve();
        cout << ans << '\n';
    }
    else
    {
        ll ans = 0;
        for(ll i=1; i<=n; i++)
        {
            int x = s[i]-'0';
            if (x%mod==0) ans += i;
        }
        cout << ans << '\n';
    }

    return 0;
}

Measured memory_bytes: 788
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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

Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

x, y = MAP()

for i in range(x+1):
    j = x - i
    if i*2 + j*4 == y:
        Yes()
        exit()
No()


Measured memory_bytes: 9268
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using usize = std::size_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

template <class T> void chmin(T &a, const T &b) {
  if (b < a)
    a = b;
}

using graph = std::vector<std::vector<usize>>;

std::map<std::vector<usize>, usize> hash_base;

usize hash(const graph &g, const usize root, const usize parent) {
  std::vector<usize> hs;
  for (const auto e : g[root]) {
    if (e == parent) {
      continue;
    }
    hs.push_back(hash(g, e, root));
  }
  std::sort(hs.begin(), hs.end());
  auto &node = hash_base[hs];
  if (node == 0) {
    node = hash_base.size();
  }
  return node;
}

std::vector<usize> far(const graph &g, const usize v, const usize p) {
  std::vector<usize> ret;
  for (const auto e : g[v]) {
    if (e == p) {
      continue;
    }
    auto f = far(g, e, v);
    if (f.size() > ret.size()) {
      std::swap(ret, f);
    }
  }
  ret.push_back(v);
  return ret;
}

std::vector<usize> tree_hash(const graph &g, usize v) {
  const usize n = g.size();
  v = far(g, v, n).front();
  const auto diam = far(g, v, n);
  std::vector<usize> ret;
  const usize m = diam.size();
  if (m % 2 == 0) {
    ret.push_back(hash(g, diam[m / 2], n));
    ret.push_back(hash(g, diam[m / 2 - 1], n));
    std::sort(ret.begin(), ret.end());
  } else {
    ret.push_back(hash(g, diam[m / 2], n));
  }
  return ret;
}

struct union_find {
  std::vector<usize> c;

  union_find(usize n) : c(n) { std::iota(c.begin(), c.end(), 0); }

  usize find(const usize x) { return x == c[x] ? x : c[x] = find(c[x]); }

  void unite(usize x, usize y) {
    x = find(x);
    y = find(y);
    c[y] = x;
  }
};

int main() {

  usize n1, m;
  std::cin >> n1 >> m;

  graph g1(n1);
  union_find uf(n1);
  for (usize i = 0; i != m; ++i) {
    usize u, v;
    std::cin >> u >> v;
    --u;
    --v;
    g1[u].push_back(v);
    g1[v].push_back(u);
    uf.unite(u, v);
  }

  usize n2;
  std::cin >> n2;
  graph g2(n2);
  for (usize i = 0; i != n2 - 1; ++i) {
    usize u, v;
    std::cin >> u >> v;
    --u;
    --v;
    g2[u].push_back(v);
    g2[v].push_back(u);
  }

  usize ans = 0;

  const auto g2_hash = tree_hash(g2, 0);

  for (usize i = 0; i != n1; ++i) {
    if (uf.find(i) == i) {
      if (g2_hash == tree_hash(g1, i)) {
        ans += 1;
      }
    }
  }

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

  return 0;
}



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

#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++)

using namespace std;

long long MOD = 1000000000 + 7;

long long modPow(int n, int num) {
	if (num == 0) return 1;
	long long res = modPow(n, num / 2);
	if (num % 2 == 0) res = (res * res) % MOD;
	else res = (((res * res) % MOD) * n) % MOD;
	return res;
}

long long modNck(int n, int k) {
	long long res = 1;
	for (int i = 0; i < k; i++) {
		res = (res * ((long long)n - i) % MOD * modPow(i + 1, MOD - 2)) % MOD;
	}
	return res;
}

int main() {
	long long X, Y;
	cin >> X >> Y;

	long long a, b;
	if ((2 * Y - X) % 3 == 0) {
		a = (2 * Y - X) / 3;
	}
	else {
		cout << 0;
		return 0;
	}
	b = Y - 2 * a;
	if (a < 0 || b < 0) {
		cout << 0;
		return 0;
	}

	long long ans = modNck(a + b, min(a, b)) % MOD;
	cout << ans;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>

using namespace std;

/**
 * main
 */
int main () {
  // if (N >= 10) then I = R
  // else R = I - 100 * (10 - N)

  int N, R;
  cin >> N >> R;
  cout << ((N >= 10) ? R : (R + 100 * (10 - N))) << '\n';
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
p = [list(map(int, input().split())) for i in range(m)]
cand = sorted(a)
ps =  sorted(p, key = lambda x : x[1], reverse = True)
i = 0
ans = 0
def calc():
    global i
    for b, c in ps:
        for d in range(b):
            if i + d == len(cand):
                return sum(cand)
            if cand[i + d] < c:
                cand[i + d] = c
            else:
                return sum(cand)
        i += b
    return sum(cand)
print(calc())


Measured memory_bytes: 36216
#include <iostream>

using namespace std;

int main() {
	int n, i, x;
	cin >> n;
	for (i = 1; i <= n; i++) {
		x = i;
		if (x % 3 == 0) {
			cout << " " << i;
		}
		else {
			while (1) {
				
				if (x%10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
				if (x == 0) {
					break;
				}
			}
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3096
n, x, y = map(int, input().split())
ans = [0] * n
for i in range(n - 1):
    for j in range(i + 1, n):
        d = min(j - i, abs(x - 1 - i) + abs(y - 1 - j) + 1)
        ans[d] += 1

for a in ans[1:]:
    print(a)

Measured memory_bytes: 46172
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(void){
  int n,ai,i,j,t=0,k=1;
  cin >> n;
  vector<P> ab;
  for (i=0;i<n;i++){
    cin >> ai;
    for (j=t-1;j>=0;j--) if (ab.at(j).first==ai) break;
    if (j>=0) ab.at(j).second++;
    else{
      t++;
      ab.push_back(P(ai,1));
    }
    if (t>3){
      cout << "No" << endl;
      return 0;
    }
  }
  if (ab.at(0)==P(0,n)){
    cout << "Yes" << endl;
    return 0;
  }
  sort(ab.begin(),ab.end());
  if (t==2 && ab.at(0)==P(0,n/3)){
    cout << "Yes" << endl;
    return 0;
  }
  if (t!=3){
    cout << "No" << endl;
    return 0;
  }
  int a,b,c;
  vector<int> m;
  for (i=0;i<3;i++){
    if (ab.at(i).second*3!=n){
      cout << "No" << endl;
      return 0;
    }
    m.push_back(ab.at(i).first);
  }
  for (i=0;i<31;i++){
    a=(m.at(0) & k);
    b=(m.at(1) & k);
    c=(m.at(2) & k);
    if (a+b+c!=2*k && a+b+c!=0) break;
    k*=2;
  }
  if (i==31) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define INF 100000
  
int main(){
  int i,j,l,x[N+1][N+1],n,p[N+1],k,r;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1], &p[i]);
  }
  
  for(i=1;i<=n;i++){
    x[i][i] = 0;
  }
  
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      x[i][j] = INF;
      for(k=i;k<j;k++){
    r = x[i][k] + x[k+1][j] + p[i-1] * p[k] * p[j];
    if(x[i][j] > r) x[i][j] = r; 
      }
    }
  }
  printf("%d\n",x[i-1][j]);
  return 0;
}


Measured memory_bytes: 2104
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] f = new int[n][10];
        int[][] p = new int[n][11];
        for(int i = 0; i < n; i++)
            for(int j = 0; j < 10; j++)
                f[i][j] = sc.nextInt();
        for(int i = 0; i < n; i++)
            for(int j = 0; j < 11; j++)
                p[i][j] = sc.nextInt();
        int ans = Integer.MIN_VALUE;
        for(int i = 1; i < Math.pow(2, 10); i++){
            int tmp = 0;
            String s = pow2(i);
            for(int j = 0; j < n; j++){
                tmp += p[j][cover(s, f[j])];
            }
            ans = Math.max(ans, tmp);
        }
        System.out.println(ans);
    }
    static String pow2(int n){
        String res = "";
        for(int i = 1; i <= 10; i++){
            int t = n % 2;
            res += t;
            n /= 2;
        }
        return res;
    }
    static int cover(String s, int[] f){
        int res = 0;
        for(int i  = 0; i < 10; i++){
            String x = Character.toString(s.charAt(i));
            String y = Integer.toString(f[i]);
            if(x.compareTo(y) == 0 && x.compareTo("1") == 0){
                res++;
            }
        }
        return res;
    }
}

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

int main() {
  int N,Q;
  cin >> N >> Q;
  vector<int> S(N),T(N),X(N);
  vector<int> D(Q);
  rep(i,N) cin >> S.at(i) >> T.at(i) >> X.at(i);
  rep(i,Q) cin >> D.at(i);

  set<P> s;
  vector<tuple<int,int,int>> a(N);
  vector<int> ans(Q,-1);

  rep(i,Q) s.insert(P(D.at(i),i));
  rep(i,N) a.at(i) = tie(X.at(i),S.at(i),T.at(i));
  sort(a.begin(),a.end());//位置でソート

  rep(i,N){//工事止めに対して
    int x,l,r;tie(x,l,r)=a.at(i);
    auto it=s.lower_bound(P(l-x,-1));
    while(it!=s.end()){
      if(it->first + x >= r) break;
      else{
        ans.at(it->second)=x;
        s.erase(it++);
      }
    }
    /*auto it=s.lower_bound(P(l,-1));//l以降のものを探す
    while(it!=s.end()){
      if(it->first>=r) break;//工事の影響がない
      ans.at(it->second)=x;//工事の影響でストップ
      s.erase(it++);//要素を消し，itをインクリメント
    }*/
  }
  rep(i,Q) cout << ans.at(i) << endl;
  return 0;
}

Measured memory_bytes: 17536
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  10005

ll dp[N][100][2];
ll n,d;
vi v;
ll tim=0;
ll dps(ll ind,ll mod,ll flg)
{
    if(ind==n)
    {
        if(mod==0)
        return 1;
        return 0;
    }
    if(dp[ind][mod][flg]!=-1)
        return dp[ind][mod][flg];
    ll x=0;
    if(flg==1)
    rep(i,0,10)
    {
        if(i<v[ind])
        {
            x=(x+dps(ind+1,(mod+i)%d,0))%hell;
        }
        else if(i==v[ind])
        {
            x=(x+dps(ind+1,(mod+i)%d,1))%hell;       
        }
    }
    else
    rep(i,0,10)
    {
        x=(x+dps(ind+1,(mod+i)%d,0))%hell;  
    }   
    return dp[ind][mod][flg]=x;
}
void solve()
{
    string s;
    cin>>s;
    n=sz(s);
    cin>>d;
    for(auto u:s)
        v.pb(u-'0');
    // cout<<n<<endl;
    memset(dp,-1,sizeof(dp));
    cout<<(dps(0,0,1)-1+hell)%hell<<endl;
    // rep(i,0,n+1)
    // {
    //     rep(j,0,d)
    //     {
    //         cout<<dp[i][j][0]<<" ";
    //     }
    //     cout<<endl;
    // }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 20200
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int a=s.nextInt();
		int b=s.nextInt();
		int c=s.nextInt();
		int kind=3;
		
		if(a==b)kind--;
		if(b==c)kind--;
		if(a==c)kind--;
		if(kind==0)kind++;
		
		System.out.print(kind);

	}

}


Measured memory_bytes: 20820
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
typedef long long ll;

int main()
{
	int n,k;
	scanf("%d%d", &n,&k);
	int d[k+1];
	int a[k+1][n+1];
	int i = 1;
	int j;
	int nlog[n+1];
	while (i <= n)
	{
		nlog[i] = i;
		i++;
	}
	i = 1;
	while (i <= k)
	{
		scanf("%d",&d[i]);
		j = 1;
		while (j <= d[i])
		{	
			scanf("%d",&a[i][j]);
			nlog[a[i][j]] = 0;
			j++;
		}
		i++;
	}
	i = 1;
	int cnt = 0;
	while (i <= n)
	{
		if (nlog[i] != 0)
			cnt++;
		i++;
	}
	printf("%d\n", cnt);
	return (0);
}


Measured memory_bytes: 2156
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string>
#include<cmath>
using namespace std;
using ll =long long int ; 

int main(){
    int N,K;
    cin >> N >> K;
    vector<ll> H(N,0);
    for(int i=0;i<N;i++) cin>>H[i];
    sort(H.begin(),H.end());
    if(K >= N) cout << "0" << endl;
    else{
        ll total = accumulate(H.begin(),H.begin()+N-K,0LL);
        cout << total << endl;
    }
}

Measured memory_bytes: 1792
from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
a.sort()

def comb(n, k):
    ans = 1
    for i in range(k):
        ans = ans * (n - i) // (i + 1)
    return ans


i = bisect_left(a, a[-1]/2)
if i > 0:
    if abs(a[-1]/2 - a[i]) < abs(a[-1]/2 - a[i-1]):
        print(a[-1], a[i])
    else:
        print(a[-1], a[i-1])
else:
    print(a[-1], a[i])


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
string S;
cin >> S;
int K;
cin >> K;

set<string>C;
REP(i, S.size()){
    string now ="";
    for(int j = 1; j <= K; j++) {
        now = S.substr(i,j);
        C.insert(now);
    }
}

    int cnt = 0;
    for (auto i : C) {
        cnt++;
        if (cnt == K) cout << i << endl;
    }
}

Measured memory_bytes: 1664
#ifdef lolipop
    #define _GLIBCXX_DEBUG
#endif

/*
    This ain't a milly rock
    This a money dance
    And my D' ain't hard
    That's a '30 in my pants
*/

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <bitset>
#include <deque>
#include <utility>

using namespace std;

#define int long long
#define all(x) x.begin(), x.end()
#define ld long double

inline void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

void solve() {
    ld r;
    cin >> r;
    cout << fixed << setprecision(20) << 2 * 3.141592 * r << '/n';
}

signed main() {
#ifdef lolipop
    freopen("input.txt", "r", stdin);
#else
    fastio();
#endif
    int T = 1;
//    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3232
import java.util.Scanner;

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

		String s = sc.nextLine();

		boolean a = false;
		boolean b = false;
		boolean c = false;

		if (s.contains("a")) {
			a = true;
		}
		if (s.contains("b")) {
			b = true;
		}
		if (s.contains("c")) {
			c = true;
		}

		if (a && b && c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();

	}
}


Measured memory_bytes: 22228
n = int(input())
s = input()

imemo = [0]*10
memo = [0]*100
counter = 0

for i in range(n):
    if imemo[int(s[i])] == 0:
        imemo[int(s[i])] = 1
    else:
        continue
        
    for j in range(i+1,n):
        if memo[int(s[i])*10+int(s[j])] == 0:
                memo[int(s[i])*10+int(s[j])] = 1
                counter += len(set(s[j+1:]))
print(counter)


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 998244353;

int n;
int d[125252];

int cnt[125252];

int main(){
    scanf("%d",&n);
    REP(i,n)scanf("%d",d+i);
    if(d[0]!=0){
        puts("0");
        return 0;
    }
    if(count(d,d+n,0)!=1){
        puts("0");
        return 0;
    }
    REP(i,n)cnt[d[i]]++;
    ll ans = 1;
    FOR(i,1,n){
        ans = ans * cnt[d[i]-1] % MOD;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string.h>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <stack>
#include <iomanip>
#include <functional>
#include <limits.h>
using namespace std;
#define ll long long int
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,n) for(ll i=1;i<=n;i++)
#define N 1000
#define kr 1000000007
ll binarys(ll low,ll high,ll a[],ll x)
{
    while (high-low>1) {
        ll mid=low+(high-low)/2;
        if(a[mid]>x)
            high=mid;
        else
            low=mid;
    }
    if(a[high]<=x)
        return high;
    else if(a[low]<=x)
        return low;
    else
        return -1;
}
int main()
{
    ios_base::sync_with_stdio(0);
    ll a,b;
    cin>>a>>b;
    if(a+b<10)
        cout<<a+b;
    else
        cout<<"error";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int> > PQG;
#define REP(i, a, n) for(ll i = (ll) a;i < (ll) n;i++)
#define fi first
#define se second
#define pb push_back
#define INF 1000000009
#define MOD 1000000007
#define MAXN 40
#define MAXC 100000000000014
#define MAXV 1000000009

string s, t;

void solve1(int n, int m, int rec, int ii, int jj){
    int k = 0;
    REP(i, 0, n){
        if(i >= ii - jj && i < ii + (m - jj)){
            cout << t[k++];
        }
        else if(s[i] == '?'){
            cout << 'a';
        }
        else{
            cout << s[i];
        }
    }
    cout << endl;
}
void solve2(int n, int m, int ii){
    REP(i, 0, n){
        if(i >= ii){
            cout << t[i - ii];
        }
        else if(s[i] == '?'){
            cout << 'a';
        }
        else{
            cout << s[i];
        }
    }
    cout << endl;
}

int main()
{
    cin >> s >> t;
    int n = s.size(), m = t.size(), w = 0, res = 0;
    for(int i = n - 1; i >= 0; i--){
        REP(j, 0, m){
            if(s[i] == t[j]){
                int rec = 0;
                if(i + m - j - 1 < n){
                    REP(k, i - j, i + (m - j)){
                        if(s[k] == t[rec] || s[k] == '?'){
                            rec++;
                            //printf("i = %d j = %d i - j = %d\n", i, j, i - j);
                        }
                    }
                }
                if(rec == m){
                    solve1(n, m, rec, i, j);
                    return 0;
                }
            }
        }
        if(s[i] == '?'){
            w++;
            if(w == m){
                solve2(n, m, i);
                return 0;
            }
        }
        else{
            w = 0;
        }
    }
    printf("UNRESTORABLE\n");


    return 0;
}
/*
5 8
0 1 3
1 2 5
2 3 5
3 4 3
4 0 7
0 3 4
2 0 4
4 1 6
*/















Measured memory_bytes: 384
from math import sqrt
def intersection(cx, cy, r, P1, P2):
    x1, y1 = P1; x2, y2 = P2

    xd = x2 - x1; yd = y2 - y1
    X = x1 - cx; Y = y1 - cy
    a = xd**2 + yd**2
    b = xd * X + yd * Y
    c = X**2 + Y**2 - r**2

    f0 = c; f1 = a+2*b+c
    if (f0 >= 0 and f1 <= 0) or (f0 <= 0 and f1 >= 0):
        return True
    return -a <= b <= 0 and b**2 - a*c >= 0 and (f0 >= 0 or f1 >= 0)

def solve():
    N = int(input())
    if N == 0:
        return False
    C = []
    for i in range(N):
        x, y, r = map(int, input().split())
        C.append((x, y, r))
    M = int(input())
    for i in range(M):
        tx, ty, sx, sy = map(int, input().split())
        for j in range(N):
            cx, cy, r = C[j]
            if intersection(cx, cy, r, (tx, ty), (sx, sy)):
                print("Safe")
                break
        else:
            print("Danger")
    return True
while solve():
    ...


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

bool isApproved(vector<int> &A) {
    for (int i = 0; i < A.size(); i++) {
        if (A.at(i) % 2 == 0) {
            if ((A.at(i) % 3 != 0) && (A.at(i) % 5 != 0)) {
                return false;
            }
        }
    }

    return true;
}

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A.at(i);
    }

    cout << (isApproved(A) ? "APPROVED" : "DENIED") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const int maxN = 53;
const int maxSz = 50 * 50 * 50;
const ll inf = 1LL << 60;

struct item {
    ll cost, val, limit;

    bool operator<(const item& who)const {
        return val * who.cost > who.val * cost;
    }
};

int n, i, x;
int cnt[maxN];
ll X, D;
ll m[maxN];
vector<int> list[maxN];
vector<item> data;

ll dp[maxN * maxN * maxN];
deque< pair<ll, ll> > Q;

void dfs(int node) {
    cnt[node] = 1;

    for (auto to : list[node]) {
        dfs(to);
        cnt[node] += cnt[to];
        m[node] += m[to];
    }

    if (node == 1)
        data.pb({m[node], cnt[node], inf});
    else
        data.pb({m[node], cnt[node], D});
}

ll greedy(ll sz, const vector<item>& bag) {
    ll ans = 0;
    ll aux;

    for (auto act : bag) {
        aux = min(act.limit, sz / act.cost);
        ans += aux * act.val;
        sz -= aux * act.cost;
    }

    return ans;
}

ll small_knapsack( vector<item>& small_bag,  vector<item>& big_bag) {
    ll maxi = 0;
    ll i, j, bg;

    dp[0] = 0;
    for (i = 1; i <= maxSz; i++) dp[i] = inf;

    /*reverse(small_bag.begin(), small_bag.end());
    while (small_bag.size() > 1) small_bag.pop_back();

    swap(big_bag[0], big_bag[2]);*/

    for (auto act : small_bag) {
        maxi += act.val * act.limit;

        for (bg = 0; bg < act.val; bg++) {
            while (!Q.empty()) Q.pop_back();

            for (i = bg; i <= maxi; i += act.val) {

                while (!Q.empty()) {
                    if (Q.back().first <= dp[i] - act.cost * (i / act.val)) break;
                    Q.pop_back();
                }
                Q.push_back(mp(dp[i] - act.cost * (i / act.val), i));

                if (i - Q.front().second > act.limit * act.val) Q.pop_front();

                dp[i] = Q.front().first + act.cost * (i / act.val);
            }

        }
    }

    ll ans = 0;
    for (i = 0; i <= maxi; i++) {
        if (dp[i] <= X)
            ans = max(ans, i + greedy(X - dp[i], big_bag));
    }

    return ans;
}

ll knapsack(vector<item> base, int max_sz) {
    vector<item> small_bag, big_bag;

    small_bag = big_bag = {};
    for (auto e : base) {
        if (e.limit <= max_sz) {
            small_bag.pb(e);
        } else {
            small_bag.pb({e.cost, e.val, max_sz});
            big_bag.pb({e.cost, e.val, e.limit - max_sz});
        }
    }

    sort(big_bag.begin(), big_bag.end());
    return small_knapsack(small_bag, big_bag);
}

int main()
{
  //  freopen("test.in","r",stdin);

    scanf("%d%lld%lld", &n, &X, &D);
    scanf("%lld", &m[1]);
    for (i = 2; i <= n; i++) {
        scanf("%lld%d", &m[i], &x);
        list[x].pb(i);
    }

    dfs(1);
    ll ans = knapsack(data, 50);

    printf("%lld", ans);

    return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if (a < 6) {
        cout << 0 << endl;
    } else if (a > 12) {
        cout << b << endl;
    } else {
        cout << b / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N; cin >> N; int A[N+10],B[N+10],sum=0;
    rep(i,N) cin >> A[i]; 
    rep(i,N){
        if(i==0) sum+=abs(A[i]-0);
        else sum+=abs(A[i]-A[i-1]);
        if(i==0 || i==N-1){
            B[i]=abs(A[i]-A[(i==0 ? i+1 : i-1)])+abs(A[i]-0)-abs(A[(i==0 ? i+1 : i-1)]-0);
        }
        else B[i]=abs(A[i]-A[i-1])+abs(A[i]-A[i+1])-abs(A[i-1]-A[i+1]);
    }
    sum+=abs(A[N-1]-0);
    rep(i,N){
        cout << sum-B[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 2816
#include <iostream>

using namespace std;

int main()
{
        int x, a, b;
        cin >> x >> a >> b;
        int xtoa = x - a;
        int xtob = x - b;
        if (xtoa < 0) {
                xtoa = -1 * xtoa;
        }
        if (xtob < 0) {
                xtob = -1 * xtob;
        }
        if (xtoa > xtob) {
                cout << "B" << endl;
        } else {
                cout << "A" << endl;
        }

        return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

int main(){
  int N; cin >> N;
  ll A[N], sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i]; sum += A[i];
  }
  sort(A, A + N);
  cout << A[0] << " " << A[N - 1] << " " << sum << endl;
  return 0;
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

bool f(string S) {
  for(int i=0; i<S.size()/2; ++i) {
    if(S[i] != S[S.size()-1-i]) return false;
  }
  return true;
}

int main() {
  string S; cin >> S;
  int N = S.size();
  string S_a = S.substr(0, (N-1)/2);
  string S_b = S.substr((N+3)/2-1, N-((N+3)/2-1));
  if(f(S) && f(S_a) && f(S_b)) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 3604
import java.io.PrintWriter
import java.util.TreeSet
val pw = PrintWriter(System.out)
fun main(args: Array<String>) {
    func()
    pw.flush()
}
fun println(value: Any) { pw.println(value) }

private data class Work(val start: Int, val end: Int, val dist: Int)
private data class Position(val pos: Int, val index: Int)

fun func() {
    val (n, q) = listOfInt()
    var workList = mutableListOf<Work>()

    for (n in 0 until n) {
        val (S, T, X) = listOfInt()
        var start = Math.ceil(S - 0.5 - X).toInt()
        var end = Math.floor(T - 0.5 - X).toInt()
        workList.add(Work(start, end, X))
    }
    workList.sortBy { it.dist }
    var posSet = TreeSet<Position> { a, b -> a.pos - b.pos }
    for (n in 0 until q) {
        posSet.add(Position(nextInt(), n))
    }
    val ans = IntArray(q) { -1 }
    for (work in workList) {
        val comp = Position(work.start,-1)
        var iter = posSet.tailSet(comp).iterator()
        while (iter.hasNext()) {
            val position = iter.next()
            if (position.pos > work.end) break
            iter.remove()
            ans[position.index] = work.dist
        }
    }
    println(ans.joinToString("\n"))
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) } //{ it.toInt() }


Measured memory_bytes: 135560
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e5 + 7;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    ans += min(k, a);
    k -= a;
    if (k > 0) {
        k -= b;
    }
    if (k > 0) {
        ans -= min(k, c);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3504
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var number = Console.ReadLine();
            var value = Console.ReadLine().Split();
            var cost = Console.ReadLine().Split();
            var sum = 0;
            for (int i = 0; i < int.Parse(number); i++)
            {
                var costParformance = int.Parse(value[i]) - int.Parse(cost[i]);
                if (costParformance > 0)
                {
                    sum += costParformance;
                }
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  string S,T,U;
  cin>>S>>T>>U;
  int A=S.size();
  int B=T.size();
  string X="NO";
  if(S[A-1]==T[0]&&T[B-1]==U[0]) X="YES";
  cout<<X;
return 0;}

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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug1(x) cout<<#x<<" : "<<x<<endl
#define debug2(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl

typedef long long ll;
typedef pair<ll,ll> pii;
const ll modd=1e9+7;

ll poww(ll a,ll b){
  ll ans=1;
  while(b>0){
    if(b%2==1) ans=(ans*a);
    a=(a*a);
    b=b/2;
  }
  return ans;
}

/*-----------------------------------------------------------------------*/

ll seg[800001],n;
ll dp[200001];
vector <ll> h(200001);
vector <ll> a(200001);

void update(ll node,ll l,ll r,ll index,ll val){
	if(l==r){
		seg[node]=val;
		dp[l]=val;
	}
	else{
		ll mid=(l+r)/2;
		if(index<=mid)
			update(2*node,l,mid,index,val);
		else
			update(2*node+1,mid+1,r,index,val);
		seg[node]=max(seg[2*node],seg[2*node+1]);
	}
}

ll query(ll node,ll l,ll r,ll p,ll q){
	if(p<=l&&r<=q)
		return seg[node];
	else{
		ll mid=(l+r)/2;
		ll max1=0,max2=0;
		if(p<=mid)
			max1=query(2*node,l,mid,p,q);
		if(q>mid)
			max2=query(2*node+1,mid+1,r,p,q);
		return max(max1,max2);
	}
}

int main(){
   fastt;

   cin>>n;

   for(ll i=1;i<=n;i++)
   	  cin>>h[i];

   for(ll i=1;i<=n;i++)
   	  cin>>a[i];

   ll ans=0;

   for(ll i=n;i>=1;i--){
   	   if(i==n)
   	   	  dp[h[i]]=a[i];
   	   else
   	   	  dp[h[i]]=a[i]+query(1,1,n,h[i]+1,n);
   	   update(1,1,n,h[i],dp[h[i]]);
   }

   for(ll i=1;i<=n;i++)
       ans=max(ans,dp[i]);

   cout<<ans<<endl;

   return 0;
}


Measured memory_bytes: 9600
object Main extends App {
  val sc = new FastScanner(System.in)
  val n = sc.nextInt()
  var m = Map[Int, Int]().withDefaultValue(0)
  var sum = 0L
  for (_ <- 0 until n) {
    val a = sc.nextInt()
    m += a -> (m(a) + 1)
    sum += a
  }
  val q = sc.nextInt()
  val bc = List.fill(q)((sc.nextInt(), sc.nextInt()))


  val pw = new java.io.PrintWriter(Console.out)
  for ((b, c) <- bc) {
    val k = m(b)
    sum += k * (c - b)
    m += b -> 0
    m += c -> (m(c) + k)
    pw.println(sum)
  }

  pw.flush()
}

class FastScanner(source: java.io.InputStream) {
  val buf = new Array[Byte](1024)
  var now, end = 0

  def isPrintable(b: Byte): Boolean = 33 <= b && b <= 126
  def isNum(b: Byte): Boolean = 48 <= b && b <= 57

  def hasNextByte: Boolean = {
    if (now < end) {
      true
    } else {
      now = 0
      end = source.read(buf)
      end > 0
    }
  }

  def nextByte(): Byte = {
    if (hasNextByte) {
      val b = buf(now)
      now += 1
      b
    } else {
      -1
    }
  }

  def hasNext: Boolean = {
    while (hasNextByte && !isPrintable(buf(now))) {
      now += 1
    }
    hasNextByte
  }

  def next(): String = {
    if (hasNext) {
      val sb = new StringBuilder()
      var b = nextByte()
      while (isPrintable(b)) {
        sb += b.toChar
        b = nextByte()
      }
      sb.toString
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextInt(): Int = {
    nextLong().toInt
  }

  def nextLong(): Long = {
    if (hasNext) {
      var b = nextByte()
      var sign = 1
      var n = 0L
      if (b == '-') {
        sign = -1
        b = nextByte()
      }
      while (isNum(b)) {
        n = n * 10 + (b - 48)
        b = nextByte()
      }
      sign * n
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 78868
S = input()
T = input()

flg = 0
ans = ""
temp = ""
for i in range(len(S)):
    flg = 0
    if len(S[i:]) < len(T):
        break
    for j in range(len(T)):
        if S[i:][j] != T[j] and S[i:][j] != "?":
            flg = 1
    if flg == 0:
        temp = (S[0:i]+T+S[i+len(T):]).replace("?", "a")
        if temp < ans or ans == "":
            ans = temp
    
print(ans if ans != "" else "UNRESTORABLE")

Measured memory_bytes: 3064