akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

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 ** 18
MOD = 10 ** 9 + 7

def warshall_floyd(N: int, graph: list) -> list:
    """ ワーシャルフロイド(頂点数, 隣接行列(0-indexed)) """
    from copy import deepcopy

    res = deepcopy(graph)
    for i in range(N):
        # 始点 = 終点、は予め距離0にしておく
        res[i][i] = 0
    # 全頂点の最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])
    return res

N, M, L = MAP()
G = list2d(N, N, INF)
for i in range(M):
    a, b, c = MAP()
    a -= 1
    b -= 1
    G[a][b] = c
    G[b][a] = c

res = warshall_floyd(N, G)

G2 = list2d(N, N, INF)
for i in range(N):
    for j in range(i, N):
        # 最短距離がL以下の2点なら燃料1回で行ける
        if res[i][j] <= L:
            G2[i][j] = 1
            G2[j][i] = 1

# 燃料使用回数をコストとした最短経路
res2 = warshall_floyd(N, G2)

for i in range(INT()):
    a, b = MAP()
    a -= 1
    b -= 1
    ans = res2[a][b]
    if ans != INF:
        print(ans-1)
    else:
        print(-1)


Measured memory_bytes: 69852
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  int sum=0;
  cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  for(int i=0;i<n-1;i++){
    sum+=v[i];
  }
  if(sum<=v[n-1]){
    cout << "No";
  }else{
    cout << "Yes";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(i, vec.size()) cout << vec[i] << " "; print("");
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

void Main(){

	ll A, B, C;
	cin >> A >> B >> C;
	if(A + B >= C)  print("Yes");
	else print("No");
	
}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	Main();
    
	return 0;
	
}





Measured memory_bytes: 3604
#include<iostream>
using namespace std;
int main(void)
{
  int n;
  int x1, y1, z1, w1, x2, y2, z2, w2;

  while(cin >> n, n){
    for(int i = 0;i < n; i++){
      cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;

      cout << x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2
        << " " << x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2
          << " " << x1 * z2 - y1 * w2 + z1 * x2 + w1 * y2
            << " " << x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2
              << endl;
    }
  }
}


Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N; cin>>N;
  int ans = 0;
  if(N % 2 == 0) {
    ans	= N/2-1;
  } else {
    ans	= N/2;
  }
  cout << ans << endl;
  return 0;
}


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

namespace ABC139_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = AB[0];
            var B = AB[1];
            if (B == 1)
            {
                Console.WriteLine(0);
                return;
            }

            var ans = 1;
            var sum = A;
            while (true)
            {
                if (sum >= B)
                {
                    break;
                }
                ans++;
                sum += A - 1;
            }

            Console.WriteLine(ans);
        }
    }
}


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

int main() {
	int s=0;
	int a[200],b[200];
	while(scanf("%d %d", &a[s], &b[s]) != EOF) {
		s++;
	}

	int cnt;
	int keta[200];
	for(int i=0; i<200; i++) keta[i] = 0;

	for(int i=0; i<s; i++) {
		cnt = a[i] + b[i];
		while(cnt >= 10) {
			cnt/=10;
			keta[i] ++;
		}
		keta[i]++;
	}

	for(int i=0; i<s; i++) printf("%d\n", keta[i]);
	return 0;
}


Measured memory_bytes: 2620
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;


int main() {



	vector<int> a;
	a.resize(3);
	int answer = 0;
	
	cin >> a[0] >>a[1] >>a[2];

	sort(a.begin(), a.end());
	while (!((a[0] == a[1]) && (a[1] == a[2]))) {
		if ((a[0] == a[1]) 
			&& (a[2] - a[1]) == 1) {
			a[0]++;
			a[1]++;
			answer++;
		}
		else if (a[1] == a[2]
				&& (a[1] - a[0] == 2)) {
			a[0] += 2;
			answer++;
		}
		else {
			a[0] += 2;
			answer++;
		
		}


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

	}

	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#define mp make_pair
#define pb push_back
using namespace std;

namespace Header_Template {
  typedef long long li;
  template<class T>inline void read(T &x) {
    x = 0;
    T tmp = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') tmp = -1, c = getchar();
    while (c >= '0' && c <= '9')
      x = (x << 1) + (x << 3) + c - '0', c = getchar();
    x *= tmp;
  }
  template<class T>inline void Max(T &x, T y) { if (y > x) x = y; }
  template<class T>inline void Min(T &x, T y) { if (y < x) x = y; }
}
using namespace Header_Template;

const int N = 61;
int n, m, l;
vector<pair<int, int> > g[N];

int main(void) {
  read(l);
  m = 0;
  n = 1;
  int T = 60;
  while (l > 1) {
    if (l & 1) {
      g[n].pb(mp(T, l - 1));
      ++m;
    }
    g[n].pb(mp(n + 1, 0));
    g[n].pb(mp(n + 1, l >> 1));
    m += 2;
    ++n;
    l >>= 1;
  }
  printf("%d %d\n", n, m);
  for (int i = 1; i < n; ++i)
    for (pair<int, int> now : g[i])
      printf("%d %d %d\n", i, now.first == T ? n : now.first, now.second);

  return 0;
}


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

L = 0 # Nの桁数
t = N
while t:
    L += 1
    t = t // 10

ans = 0
for i in range(1, L, 2):
    ans += 10**i - 10**(i-1) 

#print("==", ans)
if L % 2 == 1:
    ans += N - 10**(L-1) + 1

print(ans)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for(int x = 0; x <= K; x++) {
    for(int y = 0; y <= K; y++) {
      int z = S - x - y;
      if(0 <= z && z <= K) { ans++; }
    }
  }

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

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


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

	vector<long long int> X1(N), Y1(N), D1(N), X2(N), Y2(N), D2(N);
	vector<long long int> xs, ys, ds;

	for(int i = 0; i < N; i++) {
		cin >> X1[i] >> Y1[i] >> D1[i] >> X2[i] >> Y2[i] >> D2[i];
		xs.push_back(X1[i]); xs.push_back(X2[i]);
		ys.push_back(Y1[i]); ys.push_back(Y2[i]);
		ds.push_back(D1[i]); ds.push_back(D2[i]);
	}

	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());
	sort(ds.begin(), ds.end());

	long long int volume = 0;

	for(int x = 0; x < xs.size()-1; x++) {
		for(int y = 0; y < ys.size()-1; y++) {
			for(int d = 0; d < ds.size()-1; d++) {
				int k = 0;

				for(int n = 0; n < N; n++) {
					k += (xs[x] >= X1[n] && X2[n] >= xs[x+1]) &&
					     (ys[y] >= Y1[n] && Y2[n] >= ys[y+1]) &&
					     (ds[d] >= D1[n] && D2[n] >= ds[d+1]);
				}

				if(K <= k) {
					volume += (xs[x+1] - xs[x]) * (ys[y+1] - ys[y]) * (ds[d+1] - ds[d]);
				}
			}
		}
	}

	cout << volume << endl;
}

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

int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] -= i + 1;
  }
  sort(A, A + N);
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += abs(A[i] - A[N/2]);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 4420
class SegmentTree():
  def __init__(self, n, mapping, id):
    self.n = n
    self.id = id
    self.log = (n - 1).bit_length()
    self.size = 1 << self.log
    self.data = [self.id] * (2 * self.size)
    self.mapping = mapping
  
  def get(self, p):
    #assert 0 <= p < self.n
    res = self.id
    p += self.size
    for _ in range(self.log+1):
      res = self.mapping(res, self.data[p])
      p >>= 1
    return res

  def set(self, p, x):
    #assert 0 <= p < self.n
    p += self.size
    self.data[p] = x

  def range_set(self, l, r, x):
    #assert 0 <= l <= r <= self.n
    l += self.size
    r += self.size
    while l < r:
      if l & 1:
        self.data[l] = self.mapping(self.data[l], x)
        l += 1
      if r & 1:
        r -= 1
        self.data[r] = self.mapping(self.data[r], x)
      l >>= 1
      r >>= 1

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
id = 10**18
lst = SegmentTree(N,min,id)
lst.set(0,0)
A = [list(map(int, input().split())) for _ in range(M)]
A.sort(key=lambda x:(x[0],x[1]))
for l,r,c in A:
  lst.range_set(l-1,r,lst.get(l-1)+c)
ans = lst.get(N-1)
print(ans if ans<id else -1)

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

int main(){
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    int countA = sa.size();
    int countB = sb.size();
    int countC = sc.size();
    char round;
    char ans;
    round = sa.at(sa.size() - countA);
    countA--;
    while(true){
        if(round == 'a'){
            if(countA == 0){
                ans = 'A';
                break;
            }
            round = sa.at(sa.size() - countA);
            countA--;
        }
        else if(round == 'b'){
            if(countB == 0){
                ans = 'B';
                break;
            }
            round = sb.at(sb.size() - countB);
            countB--;
       }
       else if(round == 'c'){
            if(countC == 0){
                ans = 'C';
                break;
            }
           round = sc.at(sc.size() - countC);
           countC--;
       }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main(){
	int n,i;
	double x1, y1, x2, y2, x3, y3;
	double det, s, t, px, py, r;

	// データセット数の入力
	cin >> n;

	// 処理
	for(i=0;i<n;i++){
		// 3点の座標の入力
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		// det の計算
		det = ((y3 - y2) * (x3 - x1)) - ((y1 - y3) * (x2 - x3));
		// det ≠ 0 かどうかチェック
		if(det == 0){
			cerr << "逆行列が存在しません" << endl;
			i--;
			break;
		}
		// 予備計算
		s = ((x3 - x1) * (x1 - x2)) + ((y3 - y1) * (y1 - y2));
		t = ((x3 - x2) * (x1 - x2)) + ((y3 - y2) * (y1 - y2));
		s /= (det * 2);
		t /= (det * 2);
		// 中心座標の計算
		px = ((x2 + x3) / 2) + s * (y3 - y2);
		py = ((y2 + y3) / 2) + s * (x2 - x3);
		// 距離の計算
		r = sqrt(((px - x1) * (px - x1)) + ((py - y1) * (py - y1)));
		// 出力
		printf("%.3f %.3f %.3f\n", px, py, r);
	}

	return 0;
}

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

int main() {
  int k, a, b;
  cin >> k;
  cin >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      cout << "OK";
      return 0;
    }
  }
  cout << "NG";
  return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char a;
  cin >> a;
  if (a=='A'){
    cout << 'T' << endl;
  }
  else if (a=='T'){
    cout << 'A' << endl;
  }
  else if (a=='C'){
    cout << 'G' << endl;
  }
  else {
    cout << 'C' << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
  char ha[1<<21],k[256];
int main(int argc,char *argv[]){
  int flg;
  int val,s,t;
  char c;
  k['T'] = 1;
  k['G'] = 2;
  k['C'] = 3;
  k['A'] = 4;
   
  scanf("%d", &val);
  getchar();
  while (val--) {
    s = 0;
    t = 1;
    flg = ( c = getchar() ) == 'i';
    while ( ( c = getchar() ) != ' ' );
    while ( ( c = k[getchar()] ) != 0 ) {
      s += c * t;
      t *= 4;
    }
    if (flg) ha[s] = 1; else puts( ha[s] ? "yes" : "no" );
  }
  return 0;
}

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


int main () {
	string s;

	lli a,z;
	cin >> s;

	a = s.size();
	z = 0;

	for(lli i=0;i<s.size();i++){
		if(s[i]=='A'){
			a=min(a,i);
			break;
		}
		
	}

	for(lli i=s.size()-1;i>-1;i--){
		if(s[i]=='Z'){
			z=max(z,i);
			break;
		}
	}

	cout << z-a+1 << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T> ostream& operator<<(ostream &os, const vector<T> &v){os << "{";ITR(i,v){if(i!=v.begin())os << ","; os << *i;}os << "}"; return os;}
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}

template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}

template <typename A, typename B, typename C>
ostream& operator<<(ostream& os, const tuple<A,B,C> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}

LLI dp[1100][21000];

using tlll = tuple<LLI,LLI,LLI>;

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

  int N; cin >> N;
  vector<tlll> a(N);
  REP(i,N) cin >> get<0>(a[i]) >> get<1>(a[i]) >> get<2>(a[i]);

  sort(ALL(a), [](tlll &a, tlll &b){return get<1>(a)+get<0>(a) < get<1>(b)+get<0>(b);});
  
  vector<LLI> w(N),s(N),v(N);
  REP(i,N){
    tie(w[i],s[i],v[i]) = a[i];
  }

  REP(i,N){
    REPE(j,20000){
      chmax(dp[i+1][j], dp[i][j]);
      if(s[i] >= j) chmax(dp[i+1][j+w[i]], dp[i][j]+v[i]);
    }
  }

  LLI ans = 0;
  REPE(i,20000) chmax(ans, dp[N][i]);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 166016
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>

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

using namespace std;

const int INF = 100000001;

int main(){
  int a,b,c,d,e,k;
  cin >> a >> b >> c>> d >> e >>k;

  if (e - a > k) {
    cout << ":(" << endl;
    return 0;
  }

  cout << "Yay!" << endl;

  return 0;
}

Measured memory_bytes: 256
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Feb  2 10:55:11 2020
//
package main

import "fmt"

var N, M int

func main() {
	fmt.Scan(&N, &M)
	if N == M {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

string S;

int main(){
    cin>>S;
    bool flag;
    for(char c='a';c<='z';c++){
        flag=true;
        rep(i,S.length()){
            if(S[i]==c){
                flag=false;
                break;
            }
        }
        if(flag){
            out(c);
            return 0;
        }
    }
    out("None");
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static bool Solve(int N)
        {
            for (int i = 0; i <= 25; ++i)
            {
                for (int j = 0; j <= 14; ++j)
                {
                    if (i * 4 + j * 7 == N) { return true; }
                }
            }
            return false;
        }
        static void Main(string[] args)
        {
            Console.WriteLine(Solve(ReadInt()) ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13140
def solve(n, aaa):
    if n == 0:
        if aaa[0] == 1:
            return 1
        else:
            return -1
    if aaa[0] != 0:
        return -1

    hi = 1
    hi_enable = [1]
    for a in aaa[1:]:
        if hi * 2 < a:
            return -1
        hi = hi * 2 - a
        hi_enable.append(hi)
    # print(hi_enable)
    vn = aaa[n]
    ans = vn
    for i in range(n - 1, -1, -1):
        hi = hi_enable[i]
        a = aaa[i]
        vn = min(vn, hi) + a
        ans += vn
        # print(vn, ans)
    return ans


n = int(input())
aaa = list(map(int, input().split()))
print(solve(n, aaa))


Measured memory_bytes: 669508
// AtCoder Beginner Contest 130
// https://atcoder.jp/contests/hitachi2020
import * as fs from "fs";

const stdin = fs.readFileSync("/dev/stdin", "utf8");
const split = stdin.split("\n");
Main(split);

function Main(inputLines: string[]) {
  const input = inputLines[0];
  const tmp = input.replace(/hi/g, "");
  if (tmp.length < 1) {
    console.log("Yes");
    return;
  }
  console.log("No");
}


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;
const int p = 2019;
const int p1 = 3;
const int p2 = 673;

int main(){
    ll l,r;
    cin >> l >> r;
    // int a = 2017;
    // int b = 2018;
    // bool ok_3 = false;
    // bool ok_6 = false;
    ll ans = -1*INF;
    for(ll i = l; i<r; ++i){
        for(ll j = i+1; j<=r;++j){
            ans = min(ans, i*j%p);
            if(ans == 0){
                cout << ans << endl;
                return 0;
            }
        }
    }
    //     int ii = i % p;
    //     if(i%p1==0)ok_3 = true;
    //     if(i%p2==0)ok_6 = true;
    //     if(ok_3&&ok_6){
    //         cout << 0 << endl;
    //         return 0;
    //     }
    //     if(ii<=a){
    //         b = a;
    //         a = i;
    //     }
    //     else if(a<ii && ii<=b){
    //         b = i;
    //     }
    //     else continue;
    cout << ans << endl;
    return 0;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;
#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

int h,w;
vvi g;

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

int const inf=1<<28;

inline bool in(int x, int y){
    return 0<=x && 0<=y && x<w && y<h;
}

int ans=inf;

void rec(int x,int y, int depth){
    if(depth>=11) return;
    rep(d,4){
        int cx=x, cy=y;
        if(!in(cx+dx[d],cy+dy[d]) || g[cy+dy[d]][cx+dx[d]]==1) continue;
        while(1){
            int nx=cx+dx[d];
            int ny=cy+dy[d];
            if(!in(nx,ny)) goto next;
            if(g[cy][cx]==0){
                if(g[ny][nx]==0){
                    cx=nx, cy=ny;
                    continue;
                }
                if(g[ny][nx]==1){
                    g[ny][nx]=0;
                    rec(cx,cy,depth+1);
                    g[ny][nx]=1;
                    break;
                }
                if(g[ny][nx]==3){
                    ans=min(ans,depth+1);
                    break;
                }
            }
            if(g[cy][cx]==3){
                ans=min(ans,depth);
            }
        }
    next:;
    }
}

void solve(){
    rep(i,h)rep(j,w)if(g[i][j]==2){
        g[i][j]=0;
        rec(j,i,0);
    }
}

int main(){
    while(cin >> w>>h && w){
        ans=inf;
        g.assign(h,vi(w));
        rep(i,h)rep(j,w) cin >>g[i][j];
        solve();
        cout << (ans>10?-1:ans) << endl;
    }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=55;
ll ncr[55][55];
void init(){
    for(ll i=0;i<N;i++){
        for(ll j=0;j<=i;j++){
            if(j==0 || j==i)ncr[i][j]=1;
            else ncr[i][j] = ncr[i-1][j-1] + ncr[i-1][j];
        }
    }
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    init();
    ll n,A,B;cin>>n>>A>>B;
    ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
    sort(a,a+n,greater<ll>());
    long double avg=0;for(ll i=0;i<A;i++)avg+=a[i];
    avg/=(A*1.0);
    ll tot=0,req=0;
    for(ll i=0;i<n;i++){
        if(a[i]!=a[A-1])continue;
        tot++;
        if(i<A)req++;
    }
    ll cnt=0;
    if(req==A)for(ll take=A;take<=B;take++)cnt+=ncr[tot][take];
    else cnt=ncr[tot][req];
    cout<<fixed<<setprecision(18)<<avg<<"\n";
    cout<<cnt;
}


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

typedef struct{
  int parent;
  int child;
  int sibiling;
}Node;

int main(){
  Node T[MAX];
  int id,i,k,j=0,l=0,n,c;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent=T[i].child=T[i].sibiling=-1;
  }
  for(i=0;i!=n;i++){
    scanf("%d%d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&c);
      if(T[id].child==-1){
      T[id].child=c;
      }else {
	T[l].sibiling=c;
      }
      T[c].parent=id;
      l=c;
    }
  }
  for(i=0;i<n;i++){
    j=i;
    c=0;
    while(T[j].parent!=-1){
      c++;
      j=T[j].parent;
    }
    printf("node %d: parent = %d, depth = %d, ",i,T[i].parent,c);
    if(T[i].parent==-1)printf("root, [");
    else if(T[i].child!=-1)printf("internal node, [");
    else if(T[i].child==-1)printf("leaf, [");
    if(T[i].child!=-1){
      j=T[i].child;
      printf("%d",T[i].child);
      while(T[j].sibiling!=-1){
	printf(", %d",T[j].sibiling);
	j=T[j].sibiling;
      }
     
    }
     printf("]\n");
  }
  return 0;
}
    



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

int main() {
	int a,b,c;
	int ar[15]={0};
	cin>>a>>b>>c;
	ar[a]++;
	ar[b]++;
	ar[c]++;
	if(ar[5]==2&&ar[7]==1)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] T = new int[N];
		int[] A = new int[N];
		for(int i = 0 ; i < N ; i++) {
			T[i] = sc.nextInt();
			A[i] = sc.nextInt();
		}
		//得点:x,y  何倍:n
		long x = 1, y = 1, n;
		for(int i = 0 ; i < N ; i++) {
			if(x % T[i] != 0) {
				x = (x / T[i] + 1) * T[i];
			}
			if(y % A[i] != 0) {
				y = (y / A[i] + 1) * A[i];
			}
			n = Math.max(x / T[i], y / A[i]);
			x = n * T[i];
			y = n * A[i];
		}
		System.out.println(x + y);
	}
}


Measured memory_bytes: 25832
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Process
{
    public string name;
    public int time;
    public Process(string n, int t)
    {
        name = n;
        time = t;
    }
}

class Program
{
    public static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int n = int.Parse(s[0]);
        int q = int.Parse(s[1]);
        Queue<Process> queue = new Queue<Process>();
        for (int i = 0; i < n; i++)
        {
            s = Console.ReadLine().Split(' ');
            string name = s[0];
            int time = int.Parse(s[1]);
            queue.Enqueue(new Process(name, time));
        }
        int now = 0;
        while (queue.Count > 0)
        {
            Process proc = queue.Dequeue();
            int time = Math.Min(proc.time, q);
            now += time;
            proc.time -= time;
            if (proc.time == 0)
            {
                Console.WriteLine("{0} {1}", proc.name, now);
            }
            else
            {
                queue.Enqueue(proc);
            }
        }
    }
}


Measured memory_bytes: 24480
import math
a, b, c = map(int, input().split())

h = b*math.sin(math.radians(c))
s = h*a/2
l = a+b+(a**2+b**2-2*a*b*math.cos(math.radians(c)))**0.5
print("{:.8f}".format(s))
print("{:.8f}".format(l))
print("{:.8f}".format(h))


Measured memory_bytes: 5728
#include<stdio.h>
int max(int x,int y,int z){
	if(x>=y&&x>=z)
	return x;
	if(y>=x&&y>=z)
	return y;
	if(z>=x&&z>=y)
	return z;
	
	}
int main(){
	int m,n,i,j,w,e;
	while(~scanf("%d%d%d%d",&m,&n,&i,&j)){
		w=max(m,n,i);
		e=m+n+i-w;
		for(int q=0;q<j;q++){
			w=w*2;
		}
		e=e+w;
		printf("%d\n",e);
	}
}

Measured memory_bytes: 128
//2018年  3月 22日 木曜日 22:06:42 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int H, W, D;
int Q;
vector<int> S[MAX_N];
int B[310][310];

pi at[MAX_N];

void solve() {
	cin >> H >> W >> D;
	rep(i, 0, H) {
		rep(j, 0, W) {
			cin >> B[i][j]; B[i][j]--;
			at[B[i][j]] = pi(i, j);
		}
	}
	rep(i, 0, D) {
		pi prev = at[i];
		int cost = 0;
		S[i].pb(0);
		for(int j = i + D; j < H * W; j += D) {
			pi now = at[j];
			cost += abs(now.fst - prev.fst) + abs(now.sec - prev.sec);
			prev = now;
			S[i].pb(cost);
		}
	}
	// rep(i, 0, D) debug(S[i]);
	cin >> Q;
	rep(i, 0, Q) {
		int a, b;
		cin >> a >> b; a--; b--;
		int m = a % D;
		int ad = a / D, bd = b / D;
		// debug(m, ad, bd);
		cout << S[m][bd] - S[m][ad] << "\n";
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 9088
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
int n, a[100010],b[100010];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(a, a + n);
	rep(i, n) {
		if (b[i] == a[0]) {
			cout << i + 1 << endl;
			return 0;
		}
	}
}



Measured memory_bytes: 4676
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define M 1000000007
#define eb emplace_back

using namespace std;
const int N = 1e6;

int32_t main(){
  boost;
  int t = 1; //cin >> t;
  while(t--)
  {
    int a, b;
    cin >> a >> b;
    if(a < b)
    {
      for(int i=1; i<=b; i++)
        cout <<a;
    }
    else
    {
      for(int i=1; i<=a; i++)
        cout<<b;
    }
  }
}



Measured memory_bytes: 256
//Count Balls

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main (){
    ll N,A,B;cin >> N >> A >> B;
    cout << (N/(A+B))*A+(N%(A+B)>=A ? A : N%(A+B)) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools

def main():
  n,m,x = map(int, input().split())
  books = []
  [books.append(list(map(int, input().split()))) for _ in range(n)]

  canMoney = []
  for i in range(n):
    for book_comb in itertools.combinations(books, i+1):
      sum = [0 for _ in range(m+1)]
      for book in book_comb:
        for j in range(m+1):
          sum[j] += book[j]
      
      enough = True
      for s in range(len(sum)-1):
        if sum[s+1] < x:
          enough = False
          break
      if enough:
        canMoney.append(sum[0])

  if len(canMoney) == 0:
    print('-1')
  else:
    canMoney.sort()
    print(canMoney[0])


if __name__ == '__main__':
  main()

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

int main(){
  string s;
  cin>>s;
  int a=0;
  if(s.at(0)!=s.at(1)){
    a++;
  }
  if(s.at(2)!=s.at(1)){
    a++;
  }
  if(a==0){
    cout<<"No"<<endl;
  }
  
  if(a!=0){
    cout<<"Yes"<<endl;
  }
}
  

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	int tmp;
	int h, w , k;
	cin >> h >> w >> k;
	vector<string> c(h);
	REP(i, h) cin >> c[i];
	int numh = 1 << h, numw = 1 << w;
	REP(i, numh){
		REP(j, numw){
			tmp = 0;
			REP(x, h){
				REP(y, w){
					if(i & (1<<x) && j & (1<<y) && c[x][y]=='#') tmp++;
				}
			}
			if(tmp == k) ans ++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define rpt(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main()
{
    IO;

    ll K; cin >> K;

    ll a = 7, b = 7, jj = 1;

    rep(i, K) {
        if (b % K == 0) {
            break;
        }
        a = a * 10 % K;
        b = (b + a) % K;
        ++jj;
    }

    if (jj == K + 1) {
        cout << -1 << endl;
    }
    else if (jj < K + 1) {
        cout << jj << endl;
    }
}

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

int main()
{       
        int total=0;
        int a;
        for(int i = 0; i<3; i++)
        {
                
                cin >> a;
                total += a;
        }
        if(total <=21)
        {
                cout << "win" << endl;
        }
        else if(total >= 22)
        {
                cout << "bust" << endl;
        }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    n = II()
    p = LI()

    counter = 0
    for i in range(1,n-1):  # i=2-(n-1)
        if (p[i-1] <= p[i] <= p[i+1]) or (p[i+1] <= p[i] <= p[i-1]):
            counter += 1

    print(counter)


main()

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
//#include <string>
using namespace std;
int main(){
   

    
    int in[4][13];
    int n;
    cin>>n;
    for(int i=0;i<4;i++){
        for(int j=0;j<14;j++){
            in[i][j]=0;
        }
    }
    
    for(int i=0;i<n;i++){
        char tora;
        int num;
        cin>>tora>>num;
        if (tora=='S') {
            in[0][num-1]=1;
        }
        else if(tora=='H'){
            in[1][num-1]=1;
        }
        else if(tora=='C'){
            in[2][num-1]=1;
        }
        else if(tora=='D'){
            in[3][num-1]=1;
        }
    }
    
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            
            
            if(in[i][j]==0){
                if(i==0){
                    cout<<'S'<<' '<<j+1<<endl;
                }else if(i==1){
                    cout<<'H'<<' '<<j+1<<endl;
                    
                }else if(i==2){
                    cout<<'C'<<' '<<j+1<<endl;
                    
                }else if(i==3){
                    cout<<'D'<<' '<<j+1<<endl;
                    
                }
                
            }
            
            
            
            
        }
    }
    return 0;

}



Measured memory_bytes: 3088
import java.util.*;


/**
 * Created by Seiya on 2016/10/16.
 */

public class Main {

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

        int W = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();

        int ans = Math.max(b - (a + W), a  - (b + W));

        System.out.println(ans < 0 ? 0 : ans);


    } // mainMethod


} // MainClass


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int a[2000];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ma = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 0;
    int i, j, k;
    for (i = 0; i < n; i++) {
        for (j = i + 1; j < n; j++) {
            int su = a[i] + a[j];
            for (k = j + 1; k < n; k++) {
                if (a[k] < su) {
                    ans++;
                }
            }
        }
    }
    cout << ans << "\n";
}

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

typedef long long ll;

#define rep(var,n) for(int var=0;var<(n);++var)

int main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int r; cin >> r;

  cout << 3*r*r << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;

/* [💭] [💡] [🎈] */

int pa[200000];

void dfs(int u, int p, const vector<vector<int>> &tree) {
    pa[u] = p;
    for (int v : tree[u]) {
        if (v == p) continue;
        dfs(v, u, tree);
    }
}

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

    int n;
    cin >> n;
    vector<vector<int>> tree(n);
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        tree[u].emplace_back(v);
        tree[v].emplace_back(u);
    }

    pa[0] = -1;
    dfs(0, -1, tree);

    ll s = 0;
    for (int x = 0; x < n; x++) {
        int a = pa[x];
        if (x > a) {
            s += (ll) (x - a) * (n - x);
        } else {
            s += (ll) (a - x) * (x + 1);
        }
    }
    cout << s;

    return 0;
}

Measured memory_bytes: 24104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

//素因数分解
std::vector<long long> prime_factorization(long long N){
    /*
    Copyright (c) 2020 0214sh7
    https://github.com/0214sh7/library/
    */
  std::vector<long long> R;
  if(N<2)return R;
  for(long long i=2;i*i<=N;i++){
      while(N%i==0){
          R.push_back(i);
          N/=i;
      }
  }
  if(N!=1){
        R.push_back(N);
  }
  return R;
}

int main(void){
    ll N,a;
    vector<ll> A;
    cin >> N;
    REP(i,N){
        cin >> a;
        A.push_back(a);
    }
    
    ll g=A[0];
    REP(i,N){
        g=gcd(g,A[i]);
    }
    
    if(g!=1){
        cout << "not coprime" << endl;
        return 0;
    }
    
    vector<bool> visited(1000000,false);
    bool ok = true;
    
    vector<ll> Pri;
    REP(i,N){
        Pri = prime_factorization(A[i]);
        REP(j,Pri.size()){
            if(j!=0 && Pri[j]==Pri[j-1])continue;
            if(!visited[Pri[j]]){
                visited[Pri[j]]=true;
            }else{
                ok = false;
                break;
            }
        }
        if(!ok)break;
    }
    
    if(ok){
        cout << "pairwise coprime" << endl;
    }else{
        cout << "setwise coprime" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 11600
n=int(input())
b=list(map(int,input().split()))
num=[]
for i in range(n):
    num.append([b[i],0]) #0はまだ残ってる　１は取り除いた
flag=True
ans=[]
remove=0 #取り除いた数。
remove_sum=[0]*n
while flag and remove<=n-1:
    remove_ind=-1
    for i in range(n):
        if num[i][1]==0:
            if i-remove_sum[i]==num[i][0]-1:
                remove_ind=i
    if remove_ind!=-1:
        num[remove_ind][1]=1
        remove+=1
        ans.append(num[remove_ind][0])
        for j in range(remove_ind+1,n):
            remove_sum[j]+=1
    else: #取り除くものがなかった
        flag=False
if flag:
    ans=ans[::-1]
    for i in range(n):
        print(ans[i])
else:
    print(-1)

Measured memory_bytes: 39152
#include <iostream>
using namespace std;
#define ll long long
int main()
{
	ll a,b,c;
	cin>>a>>b>>c;
	
	if(a+b==c||b+c==a||a+c==b)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
} 

Measured memory_bytes: 888
#include <stdio.h>
int main(){
    int x,y,z;
    scanf("%d %d",&x,&y);
    if(y%2 != 0){
        z = 1;
    }else if(2*x <= y && 4*x >= y){
        z = 0;
    }else {
        z = 1;
    }

    if(z == 0){
        printf("Yes");
    }else if(z == 1) {
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<LL> a(n);
    REP(i, n) cin >> a[i];

    vector<LL> ruiseki(n);
    ruiseki[0] = a[0];
    REP(i, n-1) ruiseki[i+1] = ruiseki[i] + a[i+1];
    
    LL ans = INFL;
    REP(i, n-1){
        ans = min(ans, abs(ruiseki[i] - (ruiseki[n-1] - ruiseki[i])));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3456
K = int(input())
S = input()
list_s =list(S)
T = len(list_s)
if T > K:
    for i in range(K,T):
        del list_s[K]
    S =""
    for i in range(K):
        S += list_s[i]
    S += '...'
print(S)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_156() {
	ll n, p;
	ll ans = 0;

	cin >> n;

	vector<ll> x(n);
	float sum = 0;
	rep(i,n){
		cin >> x[i];
		sum += x[i];
	}

	sum /= n;

	p = (ll)(sum + 0.5f);

	rep(i, n){
		ans += (p - x[i]) * (p - x[i]);
	}

	cout << ans << "\n";
}

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

	solve_156();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    string s;
    int k, n;
    cin>>s>>k;
    n=s.size();
    map<string,int> mp;
    for(int i=n; i>0; --i){
        if(n-i>=6) break;
        rep(j,i){
            mp[s.substr(j,(n-i+1))]++;
        }
    }
    int cnt=0;
    string ans;
    for(auto &v: mp){
        ans=v.first;
        cnt++;
        if(cnt==k) break;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int N, a, b, c, d;
    cin >> N;
    a = N % 10;
    N /= 10;
    b = N % 10;
    N /= 10;
    c = N % 10;
    N /= 10;
    d = N % 10;
    if ((b == c) and ((a == b) or (c == d))){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int now = sc.nextInt();
		int count =0;
		int max =0;
		for (int i=1;i<N;i++) {
			int temp = sc.nextInt();
			if (temp<=now) {
				count++;
				if (count>max) {
					max = count;
				}
			} else {
				count =0;
			}
			now = temp;
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 58844
import heapq
N,M = map(int,input().split())
A = [(-1)*int(i) for i in input().split()]
heapq.heapify(A)
for i in range(M):
    tmp = heapq.heappop(A)
    tmp = (-1)*((-1*tmp)//2)
    heapq.heappush(A,tmp)
    

print(-sum(A))


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

int main(){
	
	map<int,int>bef;
	map<int,int>aft;
	
	int cnt=0;
	char c;
	int name=0;
	int seco=0;
	while(scanf("%c",&c)!=EOF){
		if(c=='\n'){
			name=0;
			if(cnt)seco=1;
			else cnt=1;
		}
		else{
			cnt=0;
			if(c==','){
				if(seco){
					aft[name]++;
				}else{
					bef[name]++;
				}
			}else{
				name*=10;
				name+=(c-'0');
			}
		}
	}
	
	map<int, int>::iterator it = bef.begin();
	while( it != bef.end() ){
		if(aft[(*it).first]){
			cout << (*it).first << " " << (*it).second+aft[(*it).first] << endl;
		}
		++it;
	}
	
	
	
	return 0;
}


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

int main()
{

    int n, a;
    cin >> n;
    multimap<int, int> m;
    for (int i = 1; i <= n; i++) {
        cin >> a;
        m.insert(make_pair(a, i));
    }
    for (auto i = m.begin(); i != m.end(); i++) {
        cout << i->second << " ";
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 5504