akhauriyash/Code-Regression huggingface dataset:
N = int(input())
x = []
y = []
for i in range(N):
    a,b = map(int, (input().split()))
    x.append(a)
    y.append(b)

aaa = 0
for i in range(N):
    for k in range(N):
        aaa += ((x[i] - x[k])**2+(y[i] - y[k])**2)**0.5
print(aaa/N)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
  long long sum=0;
  int n;
  cin >> n;
  for(int i=1;i<=n;i++){
    if(i%3 == 0 || i%5==0){
      continue; 
    }
    sum+=i;
  }
  cout << sum;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

string s;

// a = now b = next
int valid(int foot, int a, int b) {
    if (foot) {
        if (a == 1) return 0;
        else if (a == 2) {
            if (b != 1 ) return 0;
            else return 1;
        }
        else {
            if (b == 0) return 0;
            else return 1;
        }
    }
    else {
        if (a == 0) return 0;
        else if (a == 2) {
            if (b != 0) return 0;
            else return 1;
        }
        else {
            if (b == 1) return 0;
            else return 1;
        }
    }
}

int check(int f) {
    vector<int> dp(s.size()+1, 1e9);
    dp[0] = 0;
    
    for (int i = 1; i < s.size(); i++) {
        int now = (s[i-1]-'0') % 3;
        int next = (s[i]-'0') % 3;
        int foot;
        (i%2) == f ? foot = 1 : foot = 0;
        //printf("f=%d i=%d foot=%d    valid=%d now=%d next=%d\n",f,i,foot,valid(foot,now,next), now, next);
        int v = valid(foot,now,next);
        if (v) f = (f+1)%2;
        dp[i] = min(dp[i], dp[i-1] + v);
    }
    //printf("f=%d return=%d\n",f, dp[s.size()-1]);
    return dp[s.size()-1];
}

int main(void){
    while (cin>>s && s[0] != '#') {
        
        int ans = min(check(0), check(1));
        cout << ans << endl;
        //cout << "--------------------" << endl;
    }
}

Measured memory_bytes: 3308
#include <iostream>
using namespace std;
int main() {
 //   #ifndef ONLINE_JUDGE
	// freopen("input1.txt","r",stdin);
	// freopen("output1.txt","w",stdout);
	// #endif
	long long x;
	long long  count ;
	long long count1 ;
	cin>>x;
	
	
	
		count=x/500;
		

	
       count1=(x%500)/5;
       
	

  cout<<count*1000+count1*5;
	}


Measured memory_bytes: 888
x , y = map(int,input().split())
list1 = [1,3,5,7,8,10,12]
list2 = [4,6,9,11]
list3 = [2]

if x in list1 and y in list1:
	print('Yes')
elif x in list2 and y in list2:
	print('Yes')
elif x in list3 and y in list3:
	print('Yes')
else:
	print('No')
    

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll z, w;
    cin >> n >> z >> w;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = llabs(a[n-1] - w);
    if(n > 1) chmax(ans, llabs(a[n-2] - a[n-1]));
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n, m, l = 0, r = 10e5;
  cin >> n >> m;
  rep(i, m){
    int a, b;
    cin >> a >> b;
    l = max(l, a);
    r = min(r, b);
  }
  if(l > r) cout << 0 << endl;
  else cout << r-l+1 << endl;
  return 0;
}

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

using namespace std;

int const maxn = 3030;

double p[maxn];
double dp[maxn][maxn];

double solve(int i, int qtd) {
    if (qtd == 0) return 1.0;
    if (i == -1) return 0.0;
    
    double& d = dp[i][qtd];

    if (d != -1.0) return d;

    d = p[i]*solve(i-1, qtd-1) + (1.0 - p[i])*solve(i-1, qtd);

    return d;
}

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

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    for (int i = 0; i < n; i++) {
        fill(dp[i], dp[i]+maxn, -1.0);
    }

    double p = solve(n-1, n/2 + 1);

    cout << setprecision(9) << fixed;
    cout << p << "\n";
}

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

struct UnionFind {
    vector<ll> par;  // par[i]: parent of i
    vector<ll> siz;

    UnionFind(ll N) : par(N + 1), siz(N + 1, 1ll) {  // initialize by making every node a root node
        for (int i = 0; i <= N; i++) par[i] = i;
    }

    ll root(ll x) {  // find the root of a given node
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        return;
    }

    bool issame(ll x, ll y) {  // return true if x and y belong to the same tree
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

int main() {
	int n, m;
    cin >> n >> m;
    UnionFind uft(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uft.unite(a, b);
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans = max(ans, uft.size(i));
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 6380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
void solve() {
   int n,q;
   string s;
   set<int> st[26];
   cin >> n >> s >> q;
   rep(i,26)st[i].insert(n+1);
   rep(i,s.size())st[int(s[i]-'a')].insert(i+1);
   while(q--){
       int query; cin >> query;
       if (query==1){
           int idx;char c; cin >> idx >> c;
           char pre_c = s[idx-1];
           if (pre_c == c)continue;
           s[idx-1] = c;
           st[int(pre_c-'a')].erase(idx);
           st[int(c-'a')].insert(idx);
       }
       else {
           int l,r; cin >> l >> r;
           int ans = 0;
           rep(i,26)
               ans += ((*st[i].lower_bound(l)) <= r);
           cout << ans << endl;
       }
   }
   
}
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    solve();
}

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

using namespace std;
int main(){
	string a;
	string b;
	cin>>a;
	cin>>b;
	int n = a.length();
	int m = b.length();
	
	int dp[n+1][m+1];
	
	for(int i = 0 ; i <= n ; i++){
		for(int j= 0 ; j <= m ; j++){
			if(i==0||j==0) dp[i][j] = 0;
			else if(a[i-1]==b[j-1]) dp[i][j] = dp[i-1][j-1]+1;
			else{
				dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
			}
		}
	}
	string x;
	int len = dp[n][m];
	if(len==0) cout<<x;
	string res;
	int i = n;
	int j = m;
	
	while(i>0 && j>0){
		if(a[i-1]==b[j-1]){
			res.push_back(a[i-1]);
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1]){
			i--;
		}
		else{
			j--;
		}
	}
	string res1;
	for(int i = res.length()-1 ; i >= 0 ; i--){
		res1.push_back(res[i]);
	}
	cout<<res1;
	
	return 0;
}


Measured memory_bytes: 35456
<?php
list($n, $k, $q) = explode(' ', trim(fgets(STDIN)));

$a = [];
for ($i = 0; $i < $q; $i++) {
    $a[$i] = trim(fgets(STDIN));
    $a[$i]--;
}

$score = [];
for ($i = 0; $i < $n; $i++) {
    $score[$i] = $k;
}


$count = array_count_values($a);

for ($i = 0; $i < $n; $i++) {
    $score[$i] = $score[$i] - $q;
    if (isset($count[$i])) {
        $score[$i] += $count[$i];
    }
}

for ($i = 0; $i < $n; $i++) {
    if ($score[$i] > 0) {
        echo "Yes" . PHP_EOL;
    } else {
        echo "No" . PHP_EOL;
    }
}


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

int flag;
int main() {
  int N;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
   
    if (S == "Y") flag = true;
  }
    if (flag) 
      cout << "Four" << endl;
    else
     cout << "Three" << endl;
}

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

a_set = set(a)

if len(a_set) > 3:
    print("No")
elif len(a_set) == 3:
    x, y, z = a_set
    if a.count(x) == a.count(y) == a.count(z):
        if x ^ y ^ z == 0:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(a_set) == 2:
    x, y = sorted(a_set)
    if x == 0:
        if a.count(x) * 3 == N:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    if sum(a_set) == 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 14120
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;

int main(void) {
    ll n, i, tmp=0, ans=0;
    cin >> n;
    ll a[n];
    
    for(i=0; i<n; i++)
        cin >> a[i];
    sort(a, a+n);
    
    for(i=0; i<n; i++) {
        tmp=1;
        while(a[i]==a[i+1]) {
            tmp++;
            i++;
        }
        ans+=tmp%2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n;
    cin >> n;
    int cnt[9]={};
    rep(i,n){
        int tmp;cin>>tmp;
        cnt[min(tmp/400,8)]++;
    }
    int res=0;
    rep(i,8){res+=int(cnt[i]!=0);}
    cout << max(res,1) << " " << res+cnt[8] << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = inputI()
d = inputILs(N)

print(len(set(d)))

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <limits>
using namespace std;

int c=0;
void bubbleSort(int A[], int n);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, A[100];
    cin>>n;
    for(int i=0; i<n; i++) {
        cin>>A[i];
    }
    bubbleSort(A, n);
    for(int i=0; i<n-1; i++) {
        cout<<A[i]<<' ';
    }
    cout<<A[n-1]<<'\n'<<c<<'\n';
    return 0;
}

void bubbleSort(int A[], int n)
{
    bool flag=true;
    while(flag) {
        flag=false;
        for(int i=n-1; i>0; --i) {
            if(A[i]<A[i-1]) {
                swap(A[i], A[i-1]);
                ++c;
                flag=true;
            }
        }
    }
}

Measured memory_bytes: 1200
var b,bd,d,i,n,t,a,h:integer;

begin
  readln(n,t,a);
  b := 1;
  read(h);
  bd := abs((t - a) * 500 - h * 3);
  for i := 2 to n do begin
    read(h);
    d := abs((t - a) * 500 - h * 3);
    if bd > d then begin
      bd := d;
      b := i
    end
  end;
  writeln(b)
end.

Measured memory_bytes: 128
#include<stdio.h>

int main()
{
      int n,m,i,c=0,d=0;
      scanf("%d %d",&n,&m);
      int a[m];
      for(i=0;i<m;i++)
      {
            scanf("%d",&a[i]);
            c=c+a[i];

      }
      if(n>=c)
      {
            d=n-c;
            printf("%d",d);
      }

      else
            printf("-1");




}


Measured memory_bytes: 1764
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	void solve()
	{
		int r = ni(), D = ni(), x = ni();
		for(int i = 0; i < 10; i++) {
			x = r*x - D;
			out.println(x);
		}
	}
	
		
	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
	}
	
	public static void main(String[] args) throws Exception { new Main().run(); }
	
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	
	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }
	
	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

vi v[100010];
int main()
{
	int n,m;
	cin >> n >> m;
	vi a(m),b(m);
	rep(i,m){
		cin >> a[i] >> b[i];
		v[a[i]].emplace_back(b[i]);
	}
	int ans = 0;
	for(int i = 0; i < n; i++) sort(all(v[i]));
	for(int i = 0; i < 100010; i++){
		if(!v[i].size()) continue;
		int mi = v[i].front();
		for(int j = i; j < v[i].front(); j++){
			if(v[j].size()) mi = min(mi,v[j].front());
		}
		i = mi-1;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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


public class Test
{	
    public static void Main()
	{
        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        int h = int.Parse(Console.ReadLine());
        
        Console.WriteLine((a+b)*h / 2);
	
	 
	}
}

Measured memory_bytes: 11092
#include<stdio.h>
int main()
{
	int x, a, b, dis1, dis2;
	scanf("%d%d%d", &x, &a, &b);
	dis1=a-x;
	dis2=b-x;
	if(dis1<0)
		dis1=dis1*(-1);
	if(dis2<0)
		dis2=dis2*(-1);
	if(dis1<dis2)
		printf("A\n");
	else if(dis2<dis1)
		printf("B\n");
	return 0;
}

Measured memory_bytes: 1656
#include<stdio.h>
#define MAX 26

struct Node { int v, a, b; };
struct Node G[MAX];
int N,i,l,r,p;
char S[4][100]={"Preorder","Inorder","Postorder"};
void pre(int n)
{
    if(n==-1)return;
    printf(" %d",n);
    pre(G[n].a);
    pre(G[n].b);
    return;
}
 
void ino(int n)
{
    if(n==-1)return;
    ino(G[n].a);
    printf(" %d",n);
    ino(G[n].b);
    return;
}
 
void pos(int n)
{
    if(n==-1)return;
    pos(G[n].a);
    pos(G[n].b);
    printf(" %d",n);
    return;
}
 
 
 
int main()
{
    void (*funcs[])(int)={pre,ino,pos};
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d%d%d",&p,&l,&r);
        G[l].v=G[r].v=1;
        G[p].a=l;
        G[p].b=r;
    }
    for(i=0;i<N;i++)if(!G[i].v)p=i;
    for(i=0;i<3;i++)
    {
        puts(S[i]);
        (*(funcs[i]))(p);
        puts("");
    }
    return 0;
}

Measured memory_bytes: 612
#include <stdio.h>
int main(){
  int n;
  char p, newline;
  int input;
  int trump[4][13];
  int i, j;

  //trump initiallize
  for(i=0; i<4; i++){
    for(j=0; j<13; j++){
      trump[i][j]=0;
    }
  }

  //input trump cards
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%c", &newline);
    scanf("%c %d", &p, &input);
    switch(p){
      case 'S':
        trump[0][input-1]=1;
        break;
      case 'H':
        trump[1][input-1]=1;
        break;
      case 'C':
        trump[2][input-1]=1;
        break;
      case 'D':
        trump[3][input-1]=1;
        break;
    }
  }

  //output trump cards
  for(i=0; i<4; i++){
    for(j=0; j<13; j++){
      if(trump[i][j]==0){
        switch(i){
          case 0:
            printf("S %d\n", j+1);
            break;
          case 1:
            printf("H %d\n", j+1);
            break;
          case 2:
            printf("C %d\n", j+1);
            break;
          case 3:
            printf("D %d\n", j+1);
            break;
        }
      }
    }
  }
  return 0;
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  if (a == 5 && b == 5 && c == 7)
    cout << "YES" << endl;
  else if (a == 5 && b == 7 && c == 5)
    cout << "YES" << endl;
  else if (a == 7 && b == 5 && c == 5)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!
    //val sn = n.chunked(1).map { it.toInt() }.sum()
    var sn = 0
    (0 until n.length).forEach {
        sn += n[it].toString().toInt()
    }

    if (n.toInt() % sn == 0) {
        print("Yes")
    } else {
        print("No")
    }
}


Measured memory_bytes: 33812
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,count;
  cin >> a >> b >> c;
  count = 0;
  if (a==c) 
    count++;
  if (a==b)
    count++;
  if(b==c && count <= 1)
    count++;
  cout << 3-count <<endl;
}

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

int main() {
  int N;
  cin >> N;
  int n = N;
  int d = 0;
  while (n > 0) {
    d += n % 10;
    n /= 10;
  }
  if (N % d == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  cout << min(n%(a+b),a)+(n/(a+b))*a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int X,Y,Z;
  cin>>X>>Y>>Z;
  cout<<(X-Z)/(Y+Z)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back

# define inOut(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
# define RESET(a) memset(a,0,sizeof(a))
# define MEMO(a) memset(a,-1,sizeof(a))
# define DEBUG puts("Debug-Has-Come-Until-Here")


typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	cin.tie(NULL);
	
	char str[24];
	int i;
	scanf("%s",str);
	for (i=strlen(str)-1; i>=0; i--){
		printf("%c",str[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 3088
N = int(input())
b = list(map(int, input().split()))
flag = True
ans = []
for i in range(N):
    for j in range(len(b)-1, -1, -1):
        if b[j] == j + 1:
            ans.append(b.pop(j))
            break
    else:
        flag = False
        break
if flag:
    for i in range(N-1, -1, -1):
        print(ans[i])
else:
    print(-1)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>

const double EPS = 1e-5;

double q;

int main()
{
	while( std::cin >> q, q != -1 )
	{
		double prv = q / 2.0, crt;

		do
		{
			crt = prv - ( pow( prv, 3.0 ) - q ) / ( 3 * pow( prv, 2.0 ) );
			prv = crt;
		}while( fabs( pow( crt, 3.0 ) - q ) >= EPS * q );

		std::cout.setf( std::ios::fixed, std::ios::floatfield );
		std::cout << std::setprecision( 6 ) << crt << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1352
#include<bits/stdc++.h>
#define int long long
#define PI 3.14159265
int mod = 1000000009;
#define fi(i,start,end) for(int i=0; i<n; i++)
#define pb(x) push_back(x)
#define int long long
#define PI 3.14159265
#define all(v) v.begin(), v.end()
#define endl cout<<"\n" 
#define ll long long
#define dbg(x) cout<<#x<<" "<<x;endl;
#define bye endl;return
using namespace std;
template<typename T>



void debug(vector<T> x){
    for(auto e:x){
        cout<<e<<" ";
    }
    cout<<"\n";
}
/*
1
8 6
1 2 4 1 2 4 1 2

*/


void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    set<int> s;
    for(int i=0; i<n; i++){
        cin>>v[i];
        // s.insert(v[i]);
    }
    // v.clear();
    // for(auto x:s){
    //     v.push_back(x);
    // }
    sort(all(v));
    // n = v.size();
    int ans = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            for(int k = j+1; k<n; k++){
                if(v[i]!=v[j] && v[j]!=v[k] && v[i]+v[j] > v[k] && v[j]+v[k] > v[i] && v[i]+v[k] > v[j])
                    ans++;
                
            }
        }
    }
    cout<<ans;bye;
}

signed main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1;;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;
class Main{
  public static void main (String[] args){
    Scanner stdIn = new Scanner(System.in);
    
    int K = stdIn.nextInt();
    int a = stdIn.nextInt();
    int b = stdIn.nextInt();
    
    int t = 0;
    for(int i = a;i <= b;i++){
		 if(i % K == 0)
           t++;
    }
    if(t > 0)
      System.out.println("OK");
    else
      System.out.println("NG");
  }
}


Measured memory_bytes: 35780
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<int> c(n+1, 0);
    for (int i = 0; i < m; i++) {
        int l, r; cin >> l >> r;
        c[l-1]++; c[r]--; 
    }
    for (int i = 0; i < n; i++) {
        c[i+1] += c[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (c[i] == m) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
h = [0] + list(map(int, input().split()))
ab = [(list(map(int, input().split())))for _ in range(m)]

l = [set({}) for _ in range(n + 1)]
for a, b in ab:
    l[a].add(b)
    l[b].add(a)

cnt = -1
for i, v in enumerate(l):
    if len(v) != 0:
        if h[i] > max([h[j] for j in v]):
            cnt += 1
    else:
        cnt += 1
print(cnt)

Measured memory_bytes: 57228
fn divisors(n: u64) -> Vec<u64> {
    let mut ds = Vec::<u64>::new();
    for i in 1..n {
        if i * i > n {
            break;
        }
        if n % i == 0 {
            let j = n / i;
            ds.push(i);
            if j > i {
                ds.push(j);
            }
        }
    }
    ds
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin = my::io::InputReader::new(stdin.lock());

    let N: u64 = stdin.read();
    let ds = divisors(N);
    let result: u64 = ds.iter().map(|d| d - 1).filter(|&m| m > 0 && N / m == N % m).sum();
    println!("{}", result);
}

mod my {
    pub mod io {
        use std::io::{BufRead, ErrorKind, Result};
        use std::str::{FromStr, from_utf8};
        use std::fmt::Debug;

        pub fn read_word<R: BufRead>(r: &mut R, buf: &mut Vec<u8>)
                                              -> Result<usize> {
            let mut read = 0;
            loop {
                let (done, used) = {
                    let available = match r.fill_buf() {
                        Ok(n) => n,
                        Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
                        Err(e) => return Err(e)
                    };
                    match available.iter().position(|&x| x == b'\n' || x == b' ') {
                        Some(i) => {
                            buf.extend_from_slice(&available[..i]);
                            (true, i + 1)
                        }
                        None => {
                            buf.extend_from_slice(available);
                            (false, available.len())
                        }
                    }
                };
                r.consume(used);
                read += used;
                if done || used == 0 {
                    return Ok(read);
                }
            }
        }

        pub struct InputReader<R: BufRead> {
            reader: R,
            buf: Vec<u8>,
        }

        impl<R: BufRead> InputReader<R> {
            pub fn new(reader: R) -> InputReader<R> {
                InputReader {
                    reader: reader,
                    buf: Vec::<u8>::new(),
                }
            }

            pub fn read_word(&mut self) {
                read_word(&mut self.reader, &mut self.buf);
            }
            
            pub fn read<T>(&mut self) -> T
                where T: FromStr,
                      T::Err: Debug
            {
                self.buf.clear();
                self.read_word();
                from_utf8(&self.buf).unwrap().trim().parse().unwrap()
            }
        }
    }
}

Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {
	static class Range {
		int start, end;

		Range(int start, int end) {
			this.start = start;
			this.end = end;
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);

		String s = convert(in.readLine());
		Deque<Character> deque = new ArrayDeque<>();
		for (int i = 0; i < s.length(); ++i) {
			deque.addLast(s.charAt(i));
		}

		long result = count(deque);

		System.out.println(result);

		in.close();
	}

	static long count(Deque<Character> deque) {
		long result = 0;
		int aCount = 0;
		while (!deque.isEmpty()) {
			Character c = deque.pollFirst();
			if (c == 'A') {
				++aCount;
			} else if (c == 'B' || c == 'C') {
				aCount = 0;
			} else {
				result += aCount;
			}
		}
		return result;
	}

	static int swap(char[] chars, int dIndex) {
		int result = 0;
		for (int i = dIndex - 1; i >= 0; --i) {
			if (chars[i] == 'A') {
				++result;
			} else {
				if (result == 0) {
					// 何もしない
				} else {
					chars[i + 1] = 'D';
					chars[dIndex] = 'A';
				}
				break;
			}
		}
		return result;
	}

	static String convert(String s) {
		return s.replaceAll("BC", "D");
	}

}

Measured memory_bytes: 36304
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    String str = Integer.toString(N);
    int sum = 0;
    
    for (int i = 0; i < str.length(); i++) {
      char ch = str.charAt(i);
      int c = Integer.parseInt(String.valueOf(ch));
      sum = sum + c;
    }

    if (N % sum == 0) {
      System.out.println("Yes");
      return;
    }
    
    System.out.println("No");
  }
}


Measured memory_bytes: 35792
#include <stdio.h>

#define INF 10000000

int main()
{
  int n,p[101],m[101][101],i,l,j,k,q;
  scanf("%d",&n);

  for(i = 1;i <= n;i++)
    {
      scanf("%d %d",&p[i - 1],&p[i]);
    }

  
  for(i = 1;i <= n;i++)
    {
      m[i][i] = 0;
    }
  for(l = 2;l <= n;l++)
    {
      for(i = 1;i <= n-l+1;i++)
	{
	  j = i+l-1;
	  m[i][j] = INF;
	  for(k = i;k <= j - 1;k++)
	    {
	      q = m[i][k] + m[k + 1][j] + p[i - 1]*p[k]*p[j];
	      if(m[i][j] <= q )
		{
		  m[i][j] = m[i][j];
		}
	      else
		{
		  m[i][j] = q;
		}
	    }
	}
    }
  printf("%d\n",m[1][n]);

  return 0;
}



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

int main(){
  int n,c;

  while(cin >> n ,n){
    int total = 0;
    for(int i = 0 ; i < n*(n-1)/2 ; i++){
      cin >> c;
      total += c;
    }
    cout << total / (n-1) << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<algorithm>
#define MOD 1000000007
using namespace std;
int n,s[205],x;
long long saigo=1,dp[205][100005],ans,pre[205];
long long poww(int a,int b) {
	long long rt=1;
	while(b) {
		if(b&1) rt=rt*(long long)a%MOD;
		a=(long long)a*(long long)a%MOD;
		b>>=1;
	}
	return rt;
}
int main()
{
	for(int i=1;i<=200;++i) pre[i]=poww(i,MOD-2);
	scanf("%d%d",&n,&x);for(int i=1;i<=n;++i) scanf("%d",&s[i]);dp[n+1][x]=1;
	for(int i=2;i<=n;++i) saigo=(saigo*(long long)i)%MOD;
	sort(s+1,s+1+n);
	for(int i=n;i;--i) {
		for(int j=s[i];j<=x;++j) {
			dp[i][j%s[i]]=(dp[i][j%s[i]]+dp[i+1][j]*pre[i])%MOD;
			dp[i][j]=(dp[i][j]+dp[i+1][j]*(long long)(i-1)%MOD*pre[i])%MOD;
		}
		for(int j=0;j<s[i];++j) {
			dp[i][j]=(dp[i][j]+dp[i+1][j])%MOD;
		}
	}
	for(int i=0;i<=x;++i) ans=(ans+dp[1][i]*saigo%MOD*(long long)i)%MOD;
	printf("%lld",ans);
	return 0;
}

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

int main(){
    int n; cin >> n;
    int cnt = 0;
    bool ok = false;
    for(int i=0; i<n; i++){
        int k,j; cin >> k >> j;
        if(k == j) cnt++;
        else cnt = 0;

        if(cnt >= 3) ok = true;
    }

    if(ok) cout << "Yes";
    else cout << "No";
    cout << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define Whitebeard ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int main()
{
    Whitebeard;
    ll n,c,k,a;
    deque<ll>dod;
    cin>>n>>c>>k;
    while(n--)
    {
        cin>>a;
        dod.push_back(a);

    }

    sort(dod.begin(),dod.end());
    ll sum=0,h=dod[0]+k,e=c,q=dod.size();
    while(q)
    {

        if(dod[0]<=h && c!=0)
        {
            q--;
            dod.pop_front();
            c--;
            continue;
        }
        sum++;
        h=dod[0]+k;
        c=e;
        continue;

    }
    cout<<sum+1
        ;
    return 0;
}


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

using namespace std;

int main(void){
    
    int s, w;
    cin >> s >> w;
    
    if (w >= s){
        cout << "unsafe" << endl;
        return 0;
    }
    else{
        cout << "safe" << endl;
        return 0;
    }
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <list>
#include <set>
#include <map>
#define F first
#define S second
#define pb push_back
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vLL vector<LL>
#define vpint vector<pair<int, int>>
#define vpLL vector<pair<LL, LL>>
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fr(n) \
    for (int i = 0; i < n; i++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned long long LU;
const LL mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i, j, n, x, y;
    cin >> n >> x >> y;
    int a[n + 1][n + 1], dis[n + 1] = {0};
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= n; j++)
        {
            a[i][j] = abs(i - j);
        }
    }
    a[x][y] = a[y][x] = 1;
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= n; j++)
        {
            if (a[i][x] + a[x][j] < a[i][j])
            {
                a[i][j] = a[i][x] + a[x][j];
            }
        }
    }
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= n; j++)
        {
            if (a[i][y] + a[y][j] < a[i][j])
            {
                a[i][j] = a[i][y] + a[y][j];
            }
        }
    }
    // for (i = 1; i <= n; i++)
    // {
    //     for (j = 1; j <= n; j++)
    //     {
    //         if (a[i][x] + a[x][j] < a[i][j])
    //         {
    //             a[i][j] = a[i][x] + a[x][j];
    //         }
    //     }
    // }
    // for (i = 1; i <= n; i++)
    // {
    //     for (j = 1; j <= n; j++)
    //     {
    //         if (a[i][y] + a[y][j] < a[i][j])
    //         {
    //             a[i][j] = a[i][y] + a[y][j];
    //         }
    //     }
    // }
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= n; j++)
        {
            if (i > j)
            {
                dis[a[i][j]]++;
            }
        }
    }
    for (i = 1; i < n; i++)
    {
        cout << dis[i] << "\n";
    }
    return 0;
}

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

using namespace std;

int main() {
    set<int> st = {1, 7, 9, 4};
    for (int i = 0; i < 4; ++i) {
        int a;
        cin >> a;
        if (st.find(a) != st.end()) st.erase(a);
    }

    if (st.empty()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  map<char, vi> mps, mpt;
  for(int i = 0; i <= s.size(); i++) {
    mps[s[i]].push_back(i);
    mpt[t[i]].push_back(i);
  }
  set<vi> sts, stt;
  for(auto v : mps) sts.insert(v.second);
  for(auto v : mpt) stt.insert(v.second);
  cout << (sts == stt ? "Yes" : "No") << endl;
}


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

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


int main() {
	long long k, n, a,tempa,firsta;
	long long k_sum = 0;
	long long k_max = 0;

	cin >> k >> n;

	cin >> a;
	firsta = a;
	rep(i, n - 1) {
		tempa = a;
		cin >> a;
		k_sum += a - tempa;
		k_max = max(a - tempa, k_max);
	}
	k_sum += k - a + firsta;
	k_max = max(k - a + firsta, k_max);
	cout << k_sum - k_max << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define cast static_cast
#define vi vector<int>
#define v vector
#define p pair
#define push_back pb
#define mkae_pair mk
typedef long long int ll;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int n;
	cin>>n;
	int ah=0;
	int wh=0;
	int th=0;
	int rh=0;
	string inp;
	for(int i=0;i<n;i++){
		cin>>inp;
		if(inp=="AC"){
			ah++;
		}
		else if(inp=="WA"){
			wh++;
		}
		else if(inp=="TLE"){
			th++;
		}
		else{
			rh++;
		}
	}
	cout<<"AC x "<<ah<<"\n";
	cout<<"WA x "<<wh<<"\n";
	cout<<"TLE x "<<th<<"\n";
	cout<<"RE x "<<rh<<"\n";
}	

int main(){
	boost_io;
	solve();
	return 0;
}


Measured memory_bytes: 3652
k = int(input())
num = 1
anss=[i for i in range(1,10)]
ans=[i for i in range(0,10)]
j=1
while(len(anss)<100001):
  j*=10
  ans_=[]
  for i in ans:
    i_=i//(j//10)
    if i_==9:
      ans_.append(i_*j+i)
      ans_.append((i_-1)*j+i)
    elif i_==0:
      ans_.append(i_*j+i)      
      ans_.append((i_+1)*j+i)
    else:
      ans_.append(i_*j+i)
      ans_.append((i_+1)*j+i)
      ans_.append((i_-1)*j+i)
  anss.extend(ans_)
  anss=list(set(anss))
  ans=[x for x in ans_]
anss.sort()
print(anss[k])
  

Measured memory_bytes: 30664
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define INF (1LL << 61)

#define MAXN (400410)

ll t[MAXN];

ll getmin(int v, int tl, int tr, int l, int r) {
	if (l > r) {
		return INF;
	}
	if ((l == tl) && (r == tr)) {
		return t[v];
	}
	int tm = (tl + tr) / 2;
	ll m1 = getmin(2 * v, tl, tm, l, min(r, tm));
	ll m2 = getmin(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
	return min(m1, m2);
}

void update(int v, int tl, int tr, int pos, ll new_val) {
	if (tl == tr) {
		t[v] = new_val;
	} else {
		int tm = (tl + tr) / 2;
		if (pos <= tm) {
			update(2 * v, tl, tm, pos, new_val);
		} else {
			update(2 * v + 1, tm + 1, tr, pos, new_val);
		}
		t[v] = min(t[2 * v], t[2 * v + 1]);
	}
}

struct edge {
	int l, r, c;

	edge(int tl = 0, int tr = 0, int tc = 0) {
		l = tl;
		r = tr;
		c = tc;
	}

	void read() {
		cin >> l >> r >> c;
		l--;
		r--;
	}

	bool operator<(const edge & e) const {
		return (l < e.l);
	}

	void print() {
		cerr << l << " " << r << " " << c << endl;
	}
};

int n, m;

edge a[MAXN];
ll ans[MAXN];

ll quickmin(int l, int r) {
	return getmin(1, 0, n - 1, l, r);
}

void quickup(int pos, ll new_val) {
	//cerr << pos << " " << new_val << endl;
	update(1, 0, n - 1, pos, new_val);
}

int main() {
	for (int i = 0; i < MAXN; i++) {
		t[i] = INF;
		ans[i] = INF;
	}
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		a[i].read();	
	}
	sort(a, a + m);
	ans[0] = 0;
	quickup(0, 0);
	//cerr << "here" << endl;
	int curedge = 0;
	for (int i = 0; i < n; i++) {
		ll & curdist = ans[i];
		curdist = quickmin(i, n - 1);
		
		if ((curedge >= m) || (a[curedge].l > i)) {
			continue;
		}
	
		while ((curedge < m) && (a[curedge].l == i)) {
	//		a[curedge].print();
			ll old = quickmin(a[curedge].r, a[curedge].r); 
			ll nnext = curdist + a[curedge].c;
			if (old > nnext) {
				quickup(a[curedge].r, nnext);	
			}
			curedge++;
		}
	}
	ll ret = ans[n - 1];
	if (ret == INF) {
		cout << -1 << endl;
	} else {
		cout << ret << endl;
	}

	return 0;
}


Measured memory_bytes: 14572
n,m=map(int,input().split())
par=[i for i in range(n+1)]
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x] = y
for i in range(m):
    a,b=map(int,input().split())
    unite(a,b)
ans=[find(i) for i in range(1,n+1)]
ans=set(ans)
print(len(ans)-1)

Measured memory_bytes: 21872
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

LL f(LL X,vector<LL>& A){
	int size = A.size();
	for(int i=0;i<size;++i){
		//X = (X/A[i])*A[i];//AC
		X -= X%A[i];
	}
	return X;
}
void solve(){
	int K;
	cin >> K;
	vector<LL> A(K);
	for(int i=0;i<K;++i){
		cin >> A[i];
	}
	//////
	//最後に2人以上残る最小値を探す
	LL NG,OK;
	NG = 0;
	OK = LINF;
	LL f_OK = f(OK,A);
	if( f_OK < 2 ){
		cout << -1 << endl;
		return;
	}
	while(OK-NG>1){
		LL mid = (NG+OK)/2;
		LL f_mid = f(mid,A);
		if( f_mid >= 2 ){
			OK = mid;
		}else{
			NG = mid;
		}
	}
	f_OK = f(OK,A);
	LL f_NG = f(NG,A);
	if( f_OK != 2 ){
		cout << -1 << endl;
		return;
	}
	LL ansMin = OK;
	//2人残る最小値が存在したので、
	//最大値は、最小値以上の値で存在する。

	//最後に2人以下残る最大値を探す
	LL L,R;
	L = ansMin;//最後に0人残る
	R = LINF;
	while(R-L>1){
		LL mid = (L+R)/2;
		LL f_mid = f(mid,A);
		if( f_mid <= 2 ){
			L = mid;
		}else{
			R = mid;
		}
	}
	LL ansMax = L;
	cout << ansMin << " " << ansMax << endl;
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] d = new int[N];
            for (int i = 0; i < N; i++) {
                d[i] = in.nextInt();
            }

            Arrays.sort(d);

            int d1 = d[N / 2 - 1];
            int d2 = d[N / 2];

            System.out.println(d2 - d1);
        }
    }
}


Measured memory_bytes: 50160
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    char c;
    cin >> c;
    char ans;
    if(c == 'A') ans = 'T';
    if(c == 'T') ans = 'A';
    if(c == 'G') ans = 'C';
    if(c == 'C') ans = 'G';
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;
 
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

vector<int> x;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    rep(i, n) {
        int v; cin >> v;
        x.pb(v);
    }
    int bes = 0x3f3f3f3f;
    rep1(bx, 100) {
        int ans = 0;
        for(int& v:x) ans += (v-bx)*(v-bx);
        bes = min(bes, ans);
    }
    cout << bes << endl;
}



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

int main() {
  int N, M=0, S=0, p;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> p;
    S+=p;
    M=max(M, p);
  }
  cout << S-M/2 << endl;
}



Measured memory_bytes: 3520
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main()
{
  ll a, b;
  cin >> a >> b;
  if (abs(a) == abs(b))
  {
    cout << 1 << "\n";
  }
  else
  if (abs(a) < abs(b))
  {
    cout << abs(b) - abs(a) + (a < 0) + (b < 0) << "\n";
  }
  else
  {
    cout << abs(a) - abs(b) + (a > 0) + (b > 0) << "\n";
  }
}

Measured memory_bytes: 256
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

n, x = map(int, input().split(' '))
lst = list(int(x) for x in input().split(' '))
ans = abs(x - lst[0])
for i in range(1, n):
    ans = gcd(ans, abs(x-lst[i]))
print(ans)


Measured memory_bytes: 14252