akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static ArrayList<ArrayList<Integer>> g = new ArrayList<>();

	public static void main(String[] args) {
		int N = sc.nextInt();
		for (int i = 0; i < N; i++) {
			g.add(new ArrayList<>());
		}
		for (int i = 0; i < N - 1; i++) {
			int u = Integer.parseInt(sc.next()) - 1;
			int v = Integer.parseInt(sc.next()) - 1;
			g.get(u).add(v);
			g.get(v).add(u);
		}
		int[] parent = new int[N];
		Arrays.fill(parent, -1);
		ArrayList<Integer> q = new ArrayList<>();
		q.add(0);
		for (int i = 0; i < N; i++) {
			int cur = q.get(i);
			for (int adj : g.get(cur)) {
				if (adj == parent[cur]) continue;
				parent[adj] = cur;
				q.add(adj);
			}
		}
		int maxInvalid = 0;
		int[] len = new int[N];
		int[] lenDown = new int[N];
		for (int i = N - 1; i >= 0; i--) {
			int cur = q.get(i);
			for (int adj : g.get(cur)) {
				if (adj == parent[cur]) continue;
				len[cur] = Math.max(len[cur], len[adj]);
			}
			len[cur] += 1;
		}
		for (int i = 0; i < N; i++) {
			int cur = q.get(i);
			int[] maxLeft = new int[g.get(cur).size() + 1];
			maxLeft[0] = lenDown[cur];
			for (int j = 0; j < g.get(cur).size(); j++) {
				int adj = g.get(cur).get(j);
				maxLeft[j + 1] = Math.max(maxLeft[j], adj == parent[cur] ? 0 : len[adj]);
			}
			int maxRight = 0;
			for (int j = g.get(cur).size() - 1; j >= 0; j--) {
				int adj = g.get(cur).get(j);
				if (adj == parent[cur]) continue;
				lenDown[adj] = Math.max(maxLeft[j], maxRight) + 1;
				maxRight = Math.max(maxRight, len[adj]);
			}
			if (g.get(cur).size() >= 3) {
				ArrayList<Integer> lens = new ArrayList<>();
				lens.add(lenDown[cur]);
				for (int adj : g.get(cur)) {
					if (adj == parent[cur]) continue;
					lens.add(len[adj]);
				}
				Collections.sort(lens);
				int len0 = lens.get(lens.size() - 1);
				int len1 = lens.get(lens.size() - 2);
				int len2 = lens.get(lens.size() - 3);
				maxInvalid = Math.max(maxInvalid, len0);
				if (len0 == len2) {
					maxInvalid = Math.max(maxInvalid, len0 + len2 - 1);
				} else {
					maxInvalid = Math.max(maxInvalid, len0 + len2);
				}
			}
		}
		char[] ans = new char[N];
		Arrays.fill(ans, '1');
		for (int i = 3; i <= maxInvalid; i++) {
			ans[i - 1] = '0';
		}
		System.out.println(String.valueOf(ans));
	}

}



Measured memory_bytes: 91920
let () =
  Scanf.scanf "%d\n" @@ fun n -> 
  Array.init n (fun _ -> Scanf.scanf "%d " (fun x -> x))
  |> Array.to_list
  |> List.sort Pervasives.compare
  |> List.rev
  |> List.fold_left (fun (x, k) y -> (x + k * y, -k)) (0, 1)
  |> fst
  |> Printf.printf "%d\n"

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

int main(){
	double x,h;
	while(1){
	cin>>x>>h;
	if(x==0)break;
	double s=0.0;
	s+=x*x;
	s+=2*x*sqrt(x*x/4+h*h);
	printf("%0.8lf\n",s);
	}

	return 0;
}



Measured memory_bytes: 3188
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
const int MAX=1000001;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=min(b,d)-max(a,c);
    if(ans>=0) cout<<ans<<endl;
    else cout<<0<<endl;
}    

Measured memory_bytes: 256
import collections
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if len(list(set(a))) <= k:
  ans = 0
else:
  m = len(list(set(a))) - k
  c = collections.Counter(a)
  c = dict(c)
  c = sorted(c.items(), key=lambda x:x[1])
  for i in range(m):
    ans += c[i][1]
print(ans)

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

using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	long long int n;
	cin >> n;
	vector<long long int>v;
	for (int i = 0; i < n; i++) {
		long long int a;
		cin >> a;
		v.push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < v.size(); i++) {
		for (int j = i + 1; j < v.size(); j++) {
			for (int k = j + 1; k < v.size(); k++) {
				if (v[i] + v[j] > v[k] && v[i] < v[j] + v[k] && v[i] + v[k] > v[j]) {
					if (v[i] != v[j] && v[j] != v[k] && v[k] != v[i]) {
						ans++;
					}
				}
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <utility>
#include <queue>
#include <string>
using namespace std;

const int INF = 100000;
char grid[50][51];
int d[50][50];
int main(){
  int H,W; cin >> H >> W;

  for(int i = 0;i < H;i++)scanf("%s",grid[i]);


  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      d[i][j] = INF;
    }
  }

  int num_of_black = 0;
  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      if(grid[i][j] == '#')num_of_black++;
    }
  }

  queue<pair<int,int>> que;
  que.push(make_pair(0,0));

  d[0][0] = 1;


  while(que.size()){
    pair<int,int> now = que.front();
    que.pop();

    int now_y = now.first;
    int now_x = now.second;

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

    for(int i = 0;i < 4;i++){
      int ny = now_y + dy[i];
      int nx = now_x + dx[i];
      if(0 <= nx && nx < W && 0 <= ny && ny < H && d[ny][nx] == INF && grid[ny][nx] != '#'){
        d[ny][nx] = d[now_y][now_x] + 1;
        que.push(make_pair(ny,nx));
      }
    }
  }

  int ans = H * W - num_of_black - d[H-1][W-1];

  if(d[H-1][W-1] != INF)cout << ans << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i <= int(n); i++)
#define mod 1000000007
 
int main()
{
	int X,Y,Z;
	cin >> X >> Y >> Z;
	cout<< (X-Z) / (Y+Z) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <complex>

bool check(std::string str)
{
	int i = 0, j = str.length() - 1, n = str.length();
	
	while (i < n && j >= 0)
	{
		while (str[i] == 'x' && i < n)
			++i;
		
		while (str[j] == 'x' && j >= 0)
			--j;
		
		if (i < n && j >= 0)
		{
			if (str[i] != str[j])
				return 0;
			
			++i;
			--j;
		}
		else
		{
			break;
		}
	}
	
	return 1;
}

int solve(std::string str)
{
	int i = 0, j = str.length() - 1, n = str.length(), xLeft = 0, xRight = 0, ans = 0;
	
	while (i < n && j >= 0)
	{
		while (str[i] == 'x' && i < n)
		{
			++i;
			++xLeft;
		}
		
		while (str[j] == 'x' && j >= 0)
		{
			--j;
			++xRight;
		}
		
		if (i < n && j >= 0 && i <= j)
		{
			ans += abs(xLeft - xRight);
			++i;
			--j;
			xLeft = 0;
			xRight = 0;
		}
		else
		{
			break;
		}
	}
	
	return ans;
}

int main()
{
	std::string str;
	std::getline(std::cin, str);
	
	if (check(str))
	{
		std::cout << solve(str);
	}
	else
	{
		std::cout << -1;
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

bool check(const vl& L,const ll& N){
	FOR(i,0,N-1)if(L[i+1] < L[i])return 0;
	return 1;
}

vl Sort(vl L,ll N){
	random_device rnd;
	while(!check(L,N)){
		ll a = rnd()%N;
		ll b = rnd()%N;
		if(a-b)swap(L[a],L[b]);
	}
	return L;
}

signed main(){
	ll N;
	cin >> N;
	vl L(N);
	FOR(i,0,N)cin >> L[i];
	vl ans = Sort(L,N);
	ll SUM = 0;
	DEBUG(ans)
	FOR(i,0,N)SUM += ans[i];
	Yes(SUM-ans[N-1] > ans[N-1]);
}

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

#include<cstdio>

int main(){
  int a, b, d, r;
  double f;

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

  d = a/b;
  r = a%b;
  f = (double)a/b;

  printf("%d %d %f\n",d,r,f);

  return 0;
}

Measured memory_bytes: 2732
#include<iostream>
#include<string>
#include<cstring>

using namespace std;

int main()
{
    char ch[1000],cc[200],ca[100];
    cin >> ch >> cc;
    strcpy(ca,ch);
    strcat(ch,ca);
    if(strstr(ch,cc) == NULL) {
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}



Measured memory_bytes: 3120
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

int N;
int p[100];

void solve()
{
    int n = 0;
    REP(i, N){
        if(i+1 != p[i]) n++;
    }
    cout << (n <= 2 ? "YES" : "NO") << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) cin >> p[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b, c := intScanner(), intScanner(), intScanner()
	fmt.Println(smaller(b/a, c))
}


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


public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		int num=Integer.parseInt(arrayString[0]);
		int q=Integer.parseInt(arrayString[1]);
		
		ArrayList<Process> que=new ArrayList<Process>();
		ArrayList<Process> finlist=new ArrayList<Process>();
		
		String list;
		while((list=bf.readLine())!=null){
			String[] str=list.split(" ");
			Process process=new Process(str[0],Integer.parseInt(str[1]));
			que.add(process);
		}
		
		int time=0;
		while(que.size()!=0){
			Process process = que.get(0);
			if(process.getTime()<=q){
				time+=process.getTime();
				process.setFinishtime(time);
				finlist.add(process);
				que.remove(0);
			}
			else{
				time+=q;
				process.reduceTime(q);
				que.add(process);
				que.remove(0);
			}
		}
		
		for(Process pro:finlist){
			System.out.println(pro.getName() + " " + pro.getFinishtime());
		}
	}
}

class Process{
	private String name;
	private int time;
	private int finishtime;
	
	public Process(String name,int time){
		this.setName(name);
		this.setTime(time);
	}

	public void reduceTime(int q) {
		this.time-=q;

		
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getFinishtime() {
		return finishtime;
	}

	public void setFinishtime(int finishtime) {
		this.finishtime = finishtime;
	}
}

Measured memory_bytes: 65700
N,D,A=map(int,input().split())
D*=2 # 爆発の長さ
X=[None]*N
for i in range(N):
  X[i]=list(map(int,input().split()))

X=sorted(X,key=lambda x:x[0])
lastX=X[-1][0] # 最後のモンスターの場所
from collections import defaultdict
damage=defaultdict(int)
ans=0
for i in range(len(X)):
  x=X[i][0]
  if X[i][1]>0:
    dele=set()
    for d in damage.items():
      if d[0]<x:
        dele.add(d[0])
      else:
        X[i][1]-=d[1]
    for p in dele:
      del damage[p]
  if X[i][1]>0:
    turn=(X[i][1]+A-1)//A
    if x+D>lastX:
      damage[lastX]+=turn*A
    else:
      damage[x+D]=turn*A
    ans+=turn
print(ans)


Measured memory_bytes: 56784
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

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

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


int main(){
    ll N,A,B; cin >> N >> A >> B;
    ll d = B-A;
    if(d % 2 == 0){
        cout << d/2 << endl;
    }
    else{
        ll k = B-A;
        ll l = A+(N-B+1);
        cout << min(A+(k-1)/2,N-B+1+(N-l)/2) << endl;
    }
}
    



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
int main() {
  int n;
  std::cin >> n;
  std::vector<int> a;
  a.resize(n);
  for (auto &ai: a) std::cin >> ai;
  int num_negatives = 0;
  for (auto ai: a) if (ai < 0) num_negatives++;
  for (auto &ai: a) ai = std::abs(ai);
  if (num_negatives % 2 == 1) {
    auto i =  std::min_element(a.begin(), a.end());
    *i = -*i;
  }
  std::cout << std::accumulate(a.begin(), a.end(), 0LL);
}

Measured memory_bytes: 640
# Problem C - Peaks

# input
N, M = map(int, input().split())
h_list = list(map(int, input().split()))

# initialization
score_list = [0]*N
for i in range(M):
    a, b = map(int, input().split())
    if h_list[a-1]<h_list[b-1]:
        if h_list[b-1]>=0:
            score_list[b-1] += 1
        else:
            score_list[b-1] = -1 * float("INF")
        score_list[a-1] = -1 * float("INF")
    elif h_list[a-1]>h_list[b-1]:
        if h_list[a-1]>=0:
            score_list[a-1] += 1
        else:
            score_list[a-1] = -1 * float("INF")
        score_list[b-1] =  -1 * float("INF")
    else:
        score_list[a-1] = -1 * float("INF")
        score_list[b-1] = -1 * float("INF")

# output
ans = 0
for s in score_list:
    if s>=0:
        ans += 1
print(ans)


Measured memory_bytes: 20164
#include<bits/stdc++.h>
#define maxi 200000

using namespace std;

typedef struct alp
{
    int s;
    int f;

}nd;

bool cmp(nd x,nd y)
{
    if(x.f<y.f)return true;
    else if(x.f==y.f){

        if(x.s<y.f)return true;

    }
    else return false;

}


int main()
{
    int n,i,j,x,l,c=1,mem;
    cin>>n;
    nd ar[maxi];
    for(i=0;i<n;++i){

        cin>>x>>l;
        ar[i].s = x-l;
        ar[i].f = x+l;

    }
    sort(ar,ar+n,cmp);
    mem=ar[0].f;
    for(i=1;i<n;++i){

        if(ar[i].s>=mem){

            ++c;
            mem=ar[i].f;

        }

    }
    cout<<c<<endl;
    return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;

int main(void)
{
	int N; cin >> N;
	vector<int> x(N), y(N); rep(i, 0, N)cin >> x[i] >> y[i];
	vector<int> v(N); rep(i, 0, N)v[i] = i;
	double sum = 0.;
	do {
		rep(i, 0, N - 1) {
			sum += sqrt(pow(x[v[i]] - x[v[i + 1]], 2) + pow(y[v[i]] - y[v[i + 1]], 2));
		}
	} while (next_permutation(v.begin(), v.end()));

	int f = 1; rep(i, 2, N + 1)f *= i;
	double ans = sum / f;
	printf("%.7lf\n", ans);

	return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    N = int(input())
    D = [input() for i in range(N)]    
    
    for i in range(2,N):
        if (D[i][0] == D[i][-1]) \
            and (D[i-1][0] == D[i-1][-1]) \
            and (D[i-2][0] == D[i-2][-1]):
                print('Yes')
                break
        if i == N-1:
            print('No')

Measured memory_bytes: 9184
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    --A[i];
  }
  vector<ll> dist(N, -1);
  dist[0] = 0;
  ll cur = 0;
  ll x, y;
  while (true) {
    ll next = A[cur];
    if (dist[next] == -1) {
      dist[next] = dist[cur] + 1;
      cur = next;
    } else {
      x = dist[next];
      y = dist[cur] - dist[next] + 1;
      break;
    }
  }

  if (K <= x) {
    ll pos = 0;
    while (K > 0) {
      pos = A[pos];
      --K;
    }
    cout << pos + 1 << endl;
  } else {
    ll pos = 0;
    while (x > 0) {
      pos = A[pos];
      --x;
      --K;
    }
    K = K % y;
    while (K > 0) {
      pos = A[pos];
      --K;
    }
    cout << pos + 1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 6008
#include<stdio.h>

int main()
{
	int n, taro_p = 0, hana_p = 0;
	char taro[105], hana[105];
	
	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%s", taro);
		scanf("%s", hana);

		for (int j = 0;; j++)
		{
			if (taro[j] < hana[j])
			{
				hana_p += 3;
				break;
			}
			else if (taro[j] > hana[j])
			{
				taro_p += 3;
				break;
			}
			else if (taro[j] + hana[j] == 0)
			{
				taro_p++;
				hana_p++;
				break;
			}
		}
	}

	printf("%d %d\n", taro_p, hana_p);

	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  ll a, b;

  cin >> a >> b;
  if(a <= 5) {
    cout << 0 << endl;
  } else if(a <= 12) {
    cout << b/2 << endl;
  } else {
    cout << b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy
from collections import Counter, deque
import heapq
from functools import reduce
sys.setrecursionlimit(200000)
# local only
# if not __debug__:
#     fin = open('in_1.txt', 'r')
#     sys.stdin = fin
# local only
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    N = ii()
    A = lmi()
    a = 0
    for i in range(N):
        a = a ^ A[i]
    if a != 0:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 16208
#a,b = map(int,input().split())
#A = list(map(int,input().split()))
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
for i in range(N-1):
    if(A[i]+1==A[i+1]):
        ans+=C[A[i]-1]
print(ans+ sum(B))

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

void solve() {
    int a,b; cin >> a >> b;
    if(to_string(a).size() == 1 && to_string(b).size() == 1)
        cout << a * b << endl;
    else
        cout << -1 << endl;
}

int main() {
    solve();
}



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

#define endl '\n'
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

typedef long long llong;
typedef pair<int, int> pii;

void solve() {

	int n;
	cin >> n;

	string a, b;
	cin >> a >> b;

	int ans = a.size();

	while (!b.empty()) {

		size_t pos = a.find(b);

		if(pos != string::npos) break;
		else ans++;

		b.pop_back();

	}

	cout << ans;
	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif

	solve();

	return 0;

}

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String c = in.readLine();
    String alphabet = "abcdefghijklmnopqrstuvwxyz";
    int index = alphabet.indexOf(c);
    System.out.println(alphabet.charAt(index+1));
  }
}

Measured memory_bytes: 21076
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	char str[2][3];
	for(int i=0;i<2;i++)
		scanf("%s",str[i]);
	int vis=1;
	for(int i=0,j=2;i<3,j>=0;i++,j--)
	{
		if(str[0][i]!=str[1][j])
		{
			vis=0;
			break;	
		}
	}
	if(vis)
	   printf("YES\n");
	else
	   printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
   int A, B ; 
   cin >> A >> B; 
   int m, n, p, q; 
   m = (A-1) / 50; 
   n = (A-1) % 50; 
   p = (B-1) / 50; 
   q = (B-1) % 50; 
   char s[60][100]; 
cout << 60 << " " << 100 << endl; 
for(int i = 0; i < 30; ++i){
  for(int j = 0; j < 100; ++j)
  if(i % 2 == 1 && j % 2 == 1 
     && (i < m * 2 || (i == m * 2 + 1 && j < n * 2)))
    s[i][j] = '.'; 
  else s[i][j] = '#';  
  }
for(int i = 30; i < 60; ++i){
  for(int j = 0; j < 100; ++j)
  if(i % 2 == 1 && j % 2 == 1 
     && (i-30 < p * 2 || (i-30 == p * 2 + 1 && j < q * 2)))
    s[i][j] = '#'; 
  else s[i][j] = '.';  
  }
 for(int i = 0; i < 60; ++i){
  for(int j = 0; j < 100; ++j){
    cout << s[i][j]; 
   }
   cout << endl; 
 }
}

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

amaps = { i + 1: int(input()) for i in range(N) }

if 2 not in amaps.values():
    print(-1)
    exit()

current = amaps[1]
switches = 1
max_switches = len(amaps)

while switches <= max_switches:
    if current == 2:
        print(switches)
        exit()

    if current not in amaps:
        break
    current = amaps[current]
    switches+=1

print(-1)

Measured memory_bytes: 17892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
int main()
{
    ll x;
    cin >> x;
    ll sum = 0;
    ll cnt = x/500;
    sum = cnt*1000;
    x -= (cnt * 500);
    cnt = x/5;
    sum += cnt*5;
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

long long gcd(long long a, long long b)
{
	long long temp;

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

		temp = a;
		a = b;
		b = temp;
	}

	return a;
}

int main()
{
	long long a, b;
	vector<long long> prime;
	long long i, j;
	bool isprime;
	long long temp;
	long long cnt = 1;
	long long ub;

	scanf("%lld %lld", &a, &b);

	prime.push_back(2);

	temp = gcd(a, b);

	ub = (long long)sqrt(double(temp));

	for (i = 3; i <= ub; i += 2)
	{
		isprime = true;

		for (j = 0; j < prime.size() && prime[j] * prime[j] <= i; j++)
		{
			if (!(i%prime[j]))
			{
				isprime = false;

				break;
			}
		}

		if (isprime)
		{
			prime.push_back(i);
		}
	}

	for (i = 0; i < prime.size(); i++)
	{
		if (temp == 1 || prime[i] * prime[i] > temp)
		{
			break;
		}

		if (!(temp%prime[i]))
		{
			cnt++;

			while (!(temp%prime[i]))
			{
				temp /= prime[i];
			}
		}

		if (temp == 1 || prime[i] * prime[i] > temp)
		{
			break;
		}
	}

	if (temp != 1)
	{
		cnt++;
	}

	printf("%lld\n", cnt);

	return 0;
}

Measured memory_bytes: 1400
def gcd(n,m):
    a = max(n,m)
    b = min(n,m)
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

n,x = map(int,input().split())
lx = list(map(int,input().split()))

ans = 0
for i in range(len(lx)):
    ans = gcd(abs(lx[i]-x),ans)
print(ans)

Measured memory_bytes: 62576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
    static int matrixChainMultiplication(int n, int[] p) {
        int[][] m = new int[n + 1][n + 1];

        for (int l = 2; l <= n; l++) {
            for (int i = 1; i <= n - l + 1; i++) {
                int j = i + l - 1;
                m[i][j] = Integer.MAX_VALUE;
                for (int k = i; k <= j - 1; k++) {
                    m[i][j] = Math.min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
                }
            }
        }

//        for (int i = 0; i <= n; i++) {
//            System.out.println(Arrays.toString(m[i]));
//        }

        return m[1][n];
    }

    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
             PrintWriter out = new PrintWriter(System.out)) {

            int n = Integer.parseInt(in.readLine());
            int[] p = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                String[] line = in.readLine().split(" ");
                p[i - 1] = Integer.parseInt(line[0]);
                p[i] = Integer.parseInt(line[1]);
            }

            out.println(matrixChainMultiplication(n, p));
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 24456
// ###### Sat Mar 28 14:19:29 IST 2020
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long    
#define MOD                998244353
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"  
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             (x).begin(),(x).end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5+7;
int tests(){ 
  string  s ;
  cin >> s ;
  bool ok = true ;
  ok &= (s[2] == s[3]);
  ok &= (s[4] == s[5]);
  cout << (ok?"Yes" : "No");
  cout << '\n' ;

  return 0 ;
} 
int main(){
    I__O ;            
    int cases = 1 ; 
    // cin >> cases ;  
    while(cases--){   
    // cout << "Case #" << cases << ": ";
      tests(); 
    }
    return 0 ; 
}

// -Wall -Wextra -O2
// -pedantic -std=c++11
// -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll d, c[26], s[365][26], t[365], ans = 0, m, x, y, v, old[2];
  set<ll> se[26];
  srand(time(NULL));
  cin >> d;
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
    se[i].insert(0);
  }
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < d; i++) {
    x = -10000000000000;
    y = -1;
    for (int j = 0; j < 26; j++) {
      if (x < s[i][j] + (i + 1 - *se[j].rbegin()) * c[j]) {
        y = j;
        x = s[i][j] + (i + 1 - *se[j].rbegin()) * c[j];
      }
    }
    t[i] = y;
    se[t[i]].insert(i + 1);
    ans += s[i][t[i]];
    for (int j = 0; j < 26; j++) {
      ans -= (i + 1 - *se[j].rbegin()) * c[j];
    }
  }
  for (int i = 0; i < 26; i++) {
    se[i].insert(d + 1);
  }
  for (int i = 0; i < 4000000; i++) {
    y = (floor(20 / (log(rand() % 100000 + 20) / log(20)))) - 4;
    x = rand() % (d - y) + 1;
    y += x;
    v = 0LL;
    v += s[x - 1][t[y - 1]] - s[x - 1][t[x - 1]] + s[y - 1][t[x - 1]] -
         s[y - 1][t[y - 1]];
    set<ll>::iterator it = se[t[x - 1]].find(x);
    it--;
    ll z = *se[t[x - 1]].upper_bound(x);
    v -= c[t[x - 1]] * (z - x) * (x - *it);
    se[t[x - 1]].erase(x);
    it = se[t[y - 1]].find(y);
    it--;
    z = *se[t[y - 1]].upper_bound(y);
    v -= c[t[y - 1]] * (z - y) * (y - *it);
    se[t[y - 1]].erase(y);
    it = se[t[y - 1]].lower_bound(x);
    it--;
    v += c[t[y - 1]] * (*se[t[y - 1]].lower_bound(x) - x) * (x - *it);
    it = se[t[x - 1]].lower_bound(y);
    it--;
    v += c[t[x - 1]] * (*se[t[x - 1]].lower_bound(y) - y) * (y - *it);
    if (v > 0LL) {
      ans += v;
      se[t[x - 1]].insert(y);
      se[t[y - 1]].insert(x);
      ll temp = t[x - 1];
      t[x - 1] = t[y - 1];
      t[y - 1] = temp;
    } else {
      se[t[x - 1]].insert(x);
      se[t[y - 1]].insert(y);
    }
  }
  for (int i = 0; i < d; i++) {
    cout << t[i] + 1 << endl;
  }
}

Measured memory_bytes: 4064
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 100010;
static const ll INFTY = 1e12;
static const int NUMMAX = 300;


int main(){

  int N;
  int ans = 0;

  cin >> N;

  for( int i = 1; i <= 9; i++ ){
    for(int j = 1; j <= 9; j++){
      if( i * j == N ){
        ans = 1;
      }
    }
  }

  if(ans == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&a==c)
        cout<<"Yes";
    else
        cout<<"No";

} 



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b="CF";
int al,bl;
int main(){
    getline(cin,a);
    al=a.length();
    for(int i=0;i<al;i++)
        if(a[i]==b[bl]){ 
            bl++;
            if(bl==2)   
                break;
        }
    if(bl==2) cout<<"Yes"; 
    else cout<<"No";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
s = int(input())
MOD = 10**9+7

U = s
fact = [0]*(U+1)
fact[0] = 1
for i in range(1, U+1):
    fact[i] = fact[i-1]*i % MOD


invfact = [0]*(U+1)
invfact[U] = pow(fact[U], MOD-2, MOD)
for i in reversed(range(U)):
    invfact[i] = invfact[i+1]*(i+1) % MOD


def nCr(n, r):
    if r < 0 or n < r:
        return 0
    return fact[n]*invfact[r]*invfact[n-r]


ans = 0
for i in range(1, s):
    left = s-i*3
    if left < 0:
        break
    ans += nCr(left+i-1, i-1)
    ans %= MOD
print(ans)


Measured memory_bytes: 9240
import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();

        int ans = 0;

        for(int n=0; n<N-2; n++) if(S.substring(n, n+3).equals("ABC")) ans++;
        System.out.println(ans);
    }

}


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

void main_()
{
    int N;
    cin >> N;
    vector<int> as;
    copy_n(istream_iterator<int>(cin), N, back_inserter(as));

    auto ans = accumulate(begin(as), end(as), 0LL) - N;
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var n, mochi int
  fmt.Scan(&n)
  m := make(map[int]int)
  
  for i := 0; i < n; i++ {
    fmt.Scan(&mochi)
    m[mochi]++
  }
  
  fmt.Println(len(m))
}

Measured memory_bytes: 512
n,k = list(map(int, input().split()))
s = input()

# print(n, k, s)

prevcCt = 0 # 前に連続逆立ちの数
nextCnt = 0 # 後ろに連続逆立ちの数

# "00010" ⇒ [-3, 1, -1]のような配列に変換

val = 0
vals = []
for i in range(len(s)):
	if s[i] == "0":
		val -= 1
	else:
		val += 1

	#print(i, val, s[i], s[i+1])
	# print(i,len(s))
	if i == len(s) - 1 or s[i] != s[i+1]:
		vals.append(val)
		val = 0

#print(vals)

#操作しやすいようにマイナス要素が偶数になるように先頭に0を追加
if vals[0] < 0:
	vals.insert(0,0)

vals.append(0)
vals.append(0)

#print(vals)

vals = list(map(abs, vals))
#print(vals)


# K回操作できるということは連続した2k+1個の要素の最大値を求めればよい
max = 0

loopCnt = len(vals) - k
if  loopCnt < 1:
	loopCnt = 1


# 最初の要素をベースとする
sumVal = sum(vals[0:2*k + 1])
max = sumVal

# print(vals)
# print(max)

for i in range(loopCnt):
	#print(i, len(vals), k)
	# 偶数の時だけ判定
	if i%2 == 0 and i>0:
		# 外れた要素の合計値
		outVal = sum(vals[i-2:i])
		# 新たに加わった要素の合計値
		inVal = sum(vals[i + 2*k -1:i + 2*k + 1])
	
		sumVal = sumVal - outVal + inVal

		#print(i, vals[i-2:i], outVal, vals[i + 2*k -1:i + 2*k + 1], inVal, sumVal)
		# print(vals[i:i + 2*k + 1])

		#sumVal = sum(vals[i:i + 2*k + 1])
		# for e in vals[i:i + 2*k + 1]:
		# 	sumVal += abs(e)
		if sumVal > max:
			max = sumVal

print(max)

Measured memory_bytes: 4860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s,t;
	ll n;
	cin>>n>>s;
	t=s;
	bool ch=true;;
	while(ch){
		ch=false;
		for(int i=0;i<ll(t.size()-1);i++){
			if(t[i]=='('&&t[i+1]==')'){
				ch=true;
				t.erase(t.begin()+i);
				t.erase(t.begin()+i);
			}
		}

	}

	for(int i=0;i<t.size();i++){
		if(t[i]=='('){
			s.push_back( ')');
		}
		else{
			s='('+s;
		}
	}
	cout <<s;
	// your code goes here
	return 0;
}

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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#endif

class LazySegTree {
public:
    int n;
    vector<int> nodes;
    
    LazySegTree(int _n) {
        n = 1 << (int)ceil(log2(_n));
        nodes.resize(n*2-1, INT_MAX);
    }

    void update(int l, int r, int val) {
        _update(0, 0, n, l, r, val);
    }

    void _update(int k, int kl, int kr, int l, int r, int val) {
        if (kr <= l || r <= kl) return;
        if (l <= kl && kr <= r) {
            nodes[k] = min(nodes[k], val);
            return;
        }
        _update(k*2+1, kl, (kl+kr)/2, l, r, val);
        _update(k*2+2, (kl+kr)/2, kr, l, r, val);
    }

    int get(int k) {
        int res = INT_MAX;
        int i = 0, l = 0, r = n;
        while (i != n-1+k) {
            res = min(res, nodes[i]);
            if (k < (l+r)/2) {
                i = i*2+1;
                r = (l+r)/2;
            } else {
                i = i*2+2;
                l = (l+r)/2;
            }
        }
        return min(res, nodes[n-1+k]);
    }
};

vector<int> co;
int z(int x) {
    int res = lower_bound(co.begin(), co.end(), x) - co.begin();
    return res;
}

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

    int N, Q;
    cin >> N >> Q;

    vector<int> S(N), T(N), X(N);
    for (int i=0; i<N; ++i) {
        cin >> S[i] >> T[i] >> X[i];
        co.push_back(S[i]-X[i]);
        co.push_back(T[i]-X[i]);
    }

    vector<int> D(Q);
    for (int i=0; i<Q; ++i) {
        cin >> D[i];
        co.push_back(D[i]);
    }
    sort(co.begin(), co.end());
    co.erase(unique(co.begin(), co.end()), co.end());

    LazySegTree segt((int)co.size());

    for (int i=0; i<N; ++i) {
        segt.update(z(S[i]-X[i]), z(T[i]-X[i]), X[i]);
    }

    for (int i=0; i<Q; ++i) {
        int di = segt.get(z(D[i]));
        cout << (di == INT_MAX ? -1 : di) << endl;
    }

    return 0;
}

Measured memory_bytes: 15980
x,n=map(int,input().split())

if n==0:
	print(x)
	exit()
	
p=list(map(int,input().split()))
p.sort()
#print(p)

exact=x
ansmin=x-1
ansmax=x+1

for i in range(n):
	if p[i]==exact:
		exact=200
#	if p[i]==ansmin:
#		ansmin-=1
	if p[i]==ansmax:
		ansmax+=1
		
p.sort(reverse=True)
#for i in range(n-1,0,-1):
for i in range(n):
	if p[i]==ansmin:
		ansmin-=1
	
#print(ansmin,exact,ansmax)
	
if exact==x:
	print(exact)
elif abs(ansmax-x)<abs(ansmin-x):
	print(ansmax)
else:
	print(ansmin)

Measured memory_bytes: 9244
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s)
    a--;
    else
    {
        b--;
    }
    cout<<a<<" "<<b<<endl;

    

}

Measured memory_bytes: 3608
x, n = map(int, input().split())
p = list(map(int, input().split()))

cnt = 0
while True:
    if x+cnt not in p:
        print(x+cnt)
        break
    cnt *= -1
    if x+cnt not in p:
        print(x+cnt)
        break
    cnt *= -1
    cnt -= 1

Measured memory_bytes: 61848
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func nextIntSlice(size int) []int {
	re := make([]int, size)
	for i := 0; i < size; i++ {
		re[i] = nextInt()
	}
	return re
}

func rsort(a []int, n int) {
	for i := 0; i < n; i++ {
		for j := n - 1; j >= i+1; j-- {
			if a[j-1] < a[j] {
				a[j-1], a[j] = a[j], a[j-1]
			}
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	l := nextIntSlice(n)

	rsort(l, n)
	ans := 0
	for i := 0; i < k; i++ {
		ans += l[i]
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
int main() {
	int n, k[15], ma = 0, ans = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
		ma = max(ma, k[i]);
	}
	ans += ma / 2;
	sort(k, k + n);
	for (int i = 0; i < n - 1; ++i) {
		ans += k[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a,b,c,x,ans = 0;
    cin >> a >> b >> c >> x;

    for(int i = 0;i <= a;i++)
        for(int j = 0;j <= b;j++)
            for(int k = 0;k <= c;k++)
                if(i*500+j*100+50*k == x)ans++;
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = input()
m = input()

n = sorted(n)
m = sorted(m, reverse = True)

flag = True

if len(n) < len(m):
    for i in range(len(n)):
        if n[i] == m[i]:
            continue
        else:
            for j in "abcdefghijklmnopqrstuvwxyz":
                if n[i] == j:
                    flag = True
                    break
                if m[i] == j:
                    flag = False
                    break
            break
    else:
        flag = True
elif len(n) == len(m):
    for i in range(len(n)):
        if n[i] == m[i]:
            continue
        else:
            for j in "abcdefghijklmnopqrstuvwxyz":
                if n[i] == j:
                    flag = True
                    break
                if m[i] == j:
                    flag = False
                    break
            break
    else:
        flag = False
else:
    for i in range(len(m)):
        if n[i] == m[i]:
            continue
        else:
            for j in "abcdefghijklmnopqrstuvwxyz":
                if n[i] == j:
                    flag = True
                    break
                if m[i] == j:
                    flag = False
                    break
            break
    else:
        flag = False
        

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
  int n, s, t;

  while(cin>>n && n){
    s = 0;

    for(int i = 0; i < 54; i++){
      for(int j = 0; j < 96; j++){
	t = i*i*i + j*(j+1)*(j+2)/6;
	if(t > s && t <= n){
	  s = t;
	}
      }
    }

    cout << s << endl;
  }

  return 0;
}

Measured memory_bytes: 864
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
const int N=1e4+7;
int a[N],n,x,ans=0;
int main(){
	scanf("%d%d",&n,&x);
	rep(i,1,n)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	rep(i,1,n-1)if(x>=a[i]){
		ans++;x-=a[i];
	}
	if(x==a[n])ans++;
	printf("%d\n",ans);
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int x;
	cin >> x;
	if (x >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3632
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
typedef pair<int , pair<int , int> > piii;
int a , b , c , cnt5 , cnt7;
int32_t main()
{
        cin >> a >> b >> c;
        if(a == 5)
                cnt5 ++;
        if(b == 5)
                cnt5 ++;
        if(c == 5)
                cnt5 ++;
        if(a == 7)
                cnt7 ++;
        if(b == 7)
                cnt7 ++;
        if(c == 7)
                cnt7 ++;
        if(cnt5 == 2 and cnt7 == 1)
                return cout << "YES" << endl , 0;
        return cout << "NO" << endl , 0;
}
                                                                                                                                                                                                          


Measured memory_bytes: 256
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

inline int input() { int x; scanf("%d", &x); return x; }

int main() {
	int a = input(), b = input();
	printf("%d\n", std::max(std::max(a + b, a - b), a * b));
}


Measured memory_bytes: 128