akhauriyash/Code-Regression huggingface dataset:
n = int(input())
ans = 10000000000

for i in range(n//2):
    x = i+1
    y = str(n-x)
    x = str(x)
    z = 0

    for c in x:
        z += int(c)
    for c in y:
        z += int(c)
    
    if z < ans:
        ans = z

print(ans)

Measured memory_bytes: 3188
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

const D: usize = 1_000_000_007;

fn main() {
    input! {
        n: usize,
        m: usize,
        a: [usize; m],
    }
    let mut count = vec![0; n + 1];
    let broken = {
        let mut v = vec![false; n + 1];
        for a in a {
            v[a] = true;
        }
        v
    };
    for i in 0..n + 1 {
        if i == 0 {
            count[i] = 1;
        } else if i == 1 {
            count[i] = 1;
        } else {
            count[i] = (count[i - 1] + count[i - 2]) % D;
        }
        if broken[i] {
            count[i] = 0;
        }
    }
    println!("{}", count[n]);
}


Measured memory_bytes: 6396
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
#include <random>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<bool> vbool;
typedef vector<string> vstr;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
template <typename _Ty> _Ty ipow(_Ty x, _Ty n) { _Ty ret = _Ty(1); for (_Ty i = _Ty(0); i < n; i++) ret *= x; return ret; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false


bool is_prime(int n)
{
	int i;
	if (n < 2) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;

	for (i = 3; i * i <= n; i += 2) {
		if (n % i == 0)	return false;
	}
	return true;
}

int main()
{
	//clock_t start, end;
	//start = clock();

	int n;
	cin >> n;

	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		ans += (is_prime(x) ? 1 : 0);
	}
	cout << ans << endl;

	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}



Measured memory_bytes: 3088
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n = readint;
    bool[int] d;
    for (int i = 0; i < n; i++) {
        int x = readint;
        d[x] = true;
    }

    writeln(d.keys.length);
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

//const int INF = 1001001001;
const ll INF = 1e18;

struct root {
	int to;
	int cost;
	ll time;
};

struct change {
	ll cost;
	ll time;
};

struct Data {
	int v, cost;
	ll time;
	Data(int v, int s, ll x) :v(v), cost(s), time(x) {};
	bool operator<(const Data a) const{
		return a.time < time;
	}
};


int main() {
	int n, m;
	ll s;
	cin >> n >> m >> s;
	vector<vector<root>>path(n);
	vector<change>c(n);
	int a_max = 0;
	for (int i = 0; i < m; i++) {
		int u, v, a;
		ll b;
		cin >> u >> v >> a >> b;
		u--; v--;
		root x = { v,a,b };
		root y = { u,a,b };
		path[u].push_back(x);
		path[v].push_back(y);
		if (a > a_max)a_max = a;
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i].cost >> c[i].time;
	}
	vector<vector<ll>>dp(n, vector<ll>(a_max*(n - 1) + 1, INF));
	int sb = min((ll)a_max*(n - 1), s);
	priority_queue<Data>q;
	auto push = [&](int v, int s, ll x) {
		if (s < 0)return;
		if (dp[v][s] <= x)return;
		dp[v][s] = x;
		q.emplace(v, s, x);
	};
	push(0, sb, 0);
	while (q.empty() != 1) {
		Data hoge = q.top();
		q.pop();
		int v = hoge.v;
		int co = hoge.cost;
		ll x = hoge.time;
		//if (v == 2)cout << co <<" "<< x << endl;
		if (dp[v][co] < x)continue;
		{
			int ns = min(co + (int)c[v].cost, a_max*(n - 1));
			push(v, ns, x + c[v].time);//両替
		}
		for (root p : path[v]) {
			push(p.to, co - p.cost, x + p.time);
		}
	}
	for (int i = 1; i < n; i++) {
		ll ans = INF;
		for (int j = 0; j < a_max*(n - 1) + 1; j++) {
			ans = min(ans, dp[i][j]);
			//cout << dp[i][j] << " ";
		}
		//cout << endl;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 6272
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a, b, c;
	cin >> a >> b >> c;

	if (a == b)
	{
		cout << c;
	}
	else if (a == c)
	{
		cout << b;
	}
	else
	{
		cout << a;
	}
	cout << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

def cur(p):
    for x in neighbor[p]:
        if x==par[p]: continue
        else:
            par[x]=p
            descend[p]+=cur(x)
    neighbor[p].remove(par[p])
    return descend[p]

n=int(input())
neighbor=[[]  for _ in range(n+1)]
descend=[1]*(n+1)
par=[0]*(n+1)

for _ in range(n-1):
    a,b=map(int,input().split())
    neighbor[a].append(b)
    neighbor[b].append(a)
neighbor[1].append(0)
cur(1)


x=[descend[n]-1]
t=n
while t!=1:
    t,pret=par[t],t
    x.append(descend[t]-descend[pret]-1)

l=len(x)
p,q=sum(x[:l//2]),sum(x[l//2:])
if l%2==0: print("Fennec" if p<q else "Snuke")
else: print("Fennec" if p<=q else "Snuke")

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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007

//container-use 

typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< ll,ll > pll;
typedef vector<pair<ll,ll > > vpl;
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,a,b) for (int i = a; i <= b; i++)

//main function here

ll n,k;
ll a[200000+5],f[200000+5];
bool check(ll m)
{
    ll sum=0;          // count of a[i]'s needed to be wwasted by k
    for(ll i=0;i<n;i++)
                sum+=max(0ll,a[i]-m/f[i]);
    return sum>k;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    for(ll i=0;i<n;i++)
        cin>>f[i];
    sort(a,a+n);
    sort(f,f+n,greater<ll>());
    ll l=0,r=(ll)(1e18),mid,d;
    while(l<=r)
    {
        mid=(l+r)/2;
        if(check(mid))
            l=mid+1;
        else
        {
            d=mid,r=mid-1;
        }
    }
    cout<<d<<"\n";
  return 0;
 }

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(string, s);
    CoutYn( !( (Contains(s, 'N') ^ Contains(s, 'S')) || (Contains(s, 'E') ^ Contains(s, 'W')) ) );
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    
    scanf("%d",&N);
    
    int ang = 0, count = 0;
    while(ang != 0 || count == 0)
    {
        ang = (ang+N >= 360)? ang+N-360:ang+N;
        count++;
    }
    printf("%d\n",count);
}


Measured memory_bytes: 3812
from copy import *
from sys import *
from math import *
import queue
from collections import defaultdict,Counter,deque

setrecursionlimit(1000000)

#location: w,hで記載
def main():
	n,m,x = map(int,input().split())
	a = list(map(int,input().split()))
	ans = 0
	sna = 0
	for i in a:
		if(i<x):
			ans+=1
		if(i>x):
			sna+=1
	print(min(ans,sna))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	#競プロ用のQueue
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)

class Stack():
	#怯プロ用のStack
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)

main()

Measured memory_bytes: 40172
package main

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

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
)

func main() {
	scanner.Split(bufio.ScanWords)
	n := scanInt()
	fmt.Println((n * (n - 1)) / 2)
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanText(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func scanTexts(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanText()
	}
	return s
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

// greatest common divisor(最大公約数)
func gcd(a, b int) int {
	for {
		mod := a % b
		if mod == 0 {
			return b
		}
		a, b = b, mod
	}
}

// latest common multiple(最小公倍数)
func lcm(a, b int) int {
	return (a / gcd(a, b)) * b
}


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

using namespace std;

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

template <typename T>
int sz(T &x) {
  return (int)(x.size());
}

int ban[51];
int dp[51][51];

int can(int x, int y) {
  if (x < y) {
    return 0;
  }
  if (x == y) {
    return 1;
  }
  if (~dp[x][y]) {
    return dp[x][y];
  }
  int &ans = dp[x][y];
  ans = 0;
  for (int i = x; i >=  1; --i) {
    if (!ban[i]) {
      ans |= can(x % i, y);
    }
  }
  return ans;
}

int ok(vector<int> &a, vector<int> &b) {
  for (int i = 0; i <= 50; ++i) {
    for (int j = 0; j <= 50; ++j) {
      dp[i][j] = -1;
    }
  }
  for (int i = 0; i < sz(a); ++i) {
    if (!can(a[i], b[i])) {
      return 0;
    }
  }
  return 1;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  if (!ok(a, b)) {
    cout << "-1\n";
    return 0;
  }
  ll ans = 0;
  for (int i = 50; i >= 1; --i) {
    ban[i] = 1;
    if (!ok(a, b)) {
      ban[i] = 0;
      ans += (1LL << i);
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
import itertools
import math

def CalcDistance(x1, y1, x2, y2):
	return ((x1-x2)**2 + (y1-y2)**2)**(1/2)

N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
	x[i], y[i] = map(int, input().split())

distance = 0
Town = range(N)
for Route in itertools.permutations(Town,N):
	for TownNum in range(N-1):
		distance += CalcDistance(x[Route[TownNum]], y[Route[TownNum]], x[Route[TownNum+1]], y[Route[TownNum+1]])

print(distance/math.factorial(N))

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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for(auto& e : h) cin >> e;
    h.emplace_back(1e9 + 7);
    int res = 0;
    for(int i = 0, l = 0;i < n;i++){
        if(h[i+1] <= h[i]) continue;
        res = max(res, i - l);
        l = i + 1;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
Y,Z=0,0
V,W=0,0
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  Y,Z=-1,-10**20
  for j in range(26):
    if Y==-1:
      V,W=Y,Z
      Y,Z=0,X[0]+S[i][0]
    if Z<X[j]+S[i][j]:
      V,W=Y,Z
      Y,Z=j,X[j]+S[i][j]
    elif W<X[j]+S[i][j]:
      V,W=j,X[j]+S[i][j]
  XX[Y]-=X[Y]
  X[Y]=0
  P.append((Y,V))
SCORE=0
X=[0]*26
for i in range(D):
  SCORE+=S[i][P[i][0]]
  for j in range(26):
    X[j]+=C[j]
  X[P[i][0]]=0
  SCORE-=sum(X)
SCORE2=0
YY=[]
for i in range(D):
  d,q=i,P[i][1]
  SCORE2=SCORE
  YY=XX[:]
  SCORE2-=S[d][P[d][0]]
  SCORE2+=S[d][q]
  for j in range(26):
    X[j]=0
  YY[P[d][0]],YY[q]=0,0
  for j in range(D):
    if j==d:
      Z=q
    else:
      Z=P[j][0]
    X[P[d][0]]+=C[P[d][0]]
    X[q]+=C[q]
    X[Z]=0
    YY[P[d][0]]+=X[P[d][0]]
    YY[q]+=X[q]
  if SCORE2-sum(YY)>SCORE-sum(XX):
    P[i]=(P[i][1],P[i][0])
    XX=YY[:]
    SCORE=SCORE2
for i in range(D):
  print(P[i][0]+1)

Measured memory_bytes: 69540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int n,d;
	cin >> n >> d;

	int ans=0;
	while(n>0){
		ans++;
		n -= 2*d+1;
	}
	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void start(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("input.txt","r")){
        freopen ("input.txt" , "r" , stdin);
        freopen ("output.txt" , "w" , stdout);
    }
    #endif
}
signed main(){
    start();

    string s;
    int k;
    cin>>k>>s;
    if(s.length()<=k) cout<<s;
    else{
        cout<<s.substr(0,k)+"...";
    }

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
const int MAX_N = 100005;

int graph[7][MAX_N], child[4][MAX_N];
string s;

int move(int i, int p, int cnt)
{
    if (cnt == 0) return i;
    return move(graph[p][i], p, --cnt);
}

int main()
{
    cin >> s;

    rep(i, 0, s.size())
        graph[0][i] = (s[i] == 'R')? i + 1: i - 1;

    rep(p, 1, 7)
    rep(i, 0, s.size())
        graph[p][i] = move(i, p - 1, 10);

    rep(i, 0, s.size())
        child[0][i] = 1;
    rep(j, 0, s.size())
        child[1][graph[6][j]] += child[0][j];
    rep(j, 0, s.size())
        child[2][graph[5][j]] += child[1][j];
    rep(j, 0, s.size())
        child[3][graph[2][j]] += child[2][j];

    rep(i, 0, s.size())
        printf("%d ", child[3][i]);
    cout << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  int a, b;
  cin >> a >> b;
  if ((a + b) % 2 == 0) {
    cout << (a + b) / 2 << endl;
    return 0;
  } else {
    cout << (a + b) / 2 + 1 << endl;
  }
  return 0;
}

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

int main()
{
  string s;
  cin >> s;
  string t = "CODEFESTIVAL2016";
  int i, ans;
  ans = 0;
  for(i = 0; i < 16; i++)
  {
    if(s.at(i) != t.at(i))
    {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K,H,W,L,R,l,r,mi1,mi2,sum,Q;
LL ans;
LL no;
bool b,bb[100001];
string s,t;

int main() {
	cin >> N;
	vector<LL>x(N), y(N);
	double sum = 0.0;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
	}

	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			sum += pow((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]),0.5);
		}
	}
	sum = sum*2 / N;
		cout << fixed << setprecision(10) << sum<< endl;

	return 0;
}



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

int N;
const int MAX_N = 200005;
int vs[MAX_N];
int vals[MAX_N];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", vs + i + 1);
  }
  int num = 0;
  for (int i = N; i >= 1; --i) {
    int sum = 0;
    int k = i;
    while (k <= N) {
      sum += vals[k];
      k += i;
    }
    if (sum % 2 != vs[i]) {
      vals[i] = 1;
      num++;
    }
  }
  printf("%d\n", num);
  for (int i = 1; i <= N; ++i) {
    if (vals[i]) printf("%d\n", i);
  }
}


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


int main () {
    string s ; cin >> s ;
    for (int i = 1 ; i < s.size() ; i++) {
        if (s[i-1] == 'A' and s[i] == 'C') {
            cout << "Yes" ;
            return  0 ;
        }
    }
    cout << "No" << endl ;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		long sum = 1;
		long c = 1000000007;
		long[] soinsu = new long[1000];
		
		for(int i = 1; i <= N; i++) {
			loop:
			for(int j = 2; j <= N; j++) {
				if(j % 2 == 0 && j > 2) {
					continue;
				}
				for(int k = 2; k <= j - 1; k++) {
					if(j % k == 0) {
						continue loop;
					}
				}
				int a = i;
				while(a % j == 0 && j > 1) {
					soinsu[j]++;
					a /= j;
				}
			}
		}
		for(int i = 0; i < soinsu.length; i++) {
			if(soinsu[i] > 0) {
				sum = sum % c * (soinsu[i] + 1) % c;
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 22484
n = int(input())
card = [[False for i in range(13)] for j in range(4)]

for i in range(n) :
    mark, suit = input().split()
    if mark == "S" :
        mark_num = 0
    elif mark == "H" :
        mark_num = 1
    elif mark == "C" :
        mark_num = 2
    elif mark == "D" :
        mark_num = 3
    card[mark_num][int(suit)-1] = True

for j in range(4) :
    for i in range(13) :
        if card[j][i] == False :
            if j == 0 :
                print("S", i+1)
            elif j == 1 :
                print("H", i+1)
            elif j == 2 :
                print("C", i+1)
            elif j == 3 :
                print("D", i+1)



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

void solve(){
	string s;
	int i, n;
	cin>>s;
	n=s.length();
	for(i=0;i<n;i++){
		if(s[i]=='?'){
			cout<<'D';
		}else{
			cout<<s[i];
		}
	}cout<<endl;


	/*
	int dp[n+1];
	vector<int> s1(n);
	dp[0]=0;
	dp[1]=s[0]!='P';
	s1[0]=s[0]=='P';
	for(i=2; i<=n;i++){
		if(s[i-1]=='D'){
			if(s[i-2]=='P'){
				dp[i]=2+dp[i-2];
			}else if(s[i-2]=='D'){
				dp[i]=1+dp[i-1];
			}else{
				dp[i]=2+dp[i-2];
				s1[i-2]=1;
			}
			s1[i-1]=0;
		}else if(s[i-1]=='P'){
			dp[i]=dp[i-1];
			s1[i-1]=1;
		}else{
			int a=dp[i-1]; // replacing ? by P
			int b=1;
			int p=0, q=0, y=0, z=0;
			// Now, cases of replacing ? by D and checking for previous char to be ? or P
			if(s[i-2]=='?'){
				if((2+dp[i-2])>(1+dp[i-1])){
					p=1;
				}
				else{
					q=1;
				}
				b= max(2+dp[i-2], 1+dp[i-1]);
			}else if(s[i-2]=='P'){
				b=2+dp[i-2];
				y=1;
			}else{
				b=1+dp[i-1];
				z=1;
			}
			if(a>b){
				s1[i-1]=1;
			}else{
				s1[i-1]=0;
				if(p==1){
					s1[i-2]=1;
				}else{
					s1[i-2]=0;
				}
			}
			dp[i]=max(a, b);
		}
	}
	//cout<<dp[n]<<endl;
	for(i=0;i<n;i++){
		cout<<((s1[i]==1)?'P':'D');
	}cout<<endl;
	*/
}
int main() 
{ 
   ios_base::sync_with_stdio(false);
   cin.tie(NULL); 
   #ifndef ONLINE_JUDGE 
   freopen("../input.txt", "r", stdin);
   freopen("../output.txt", "w", stdout); 
   #endif
   solve();
   return 0; 
}

Measured memory_bytes: 3752
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#define _USE_MATH_DEFINES
using namespace std;
double H,M,temp;
int h,m;
int main()
{
	cin>>H>>M>>h>>m;
	temp=M_PI/30.0*(h*60.0+m)-M_PI/360.0*(h*60.0+m);
	printf("%.20lf", sqrt(H*H+M*M-2*H*M*cos(temp)));
	return 0;
 } 

Measured memory_bytes: 4228
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    x=parseMap(split(readline()))
    ans=1000000000
    for i in 1:100
        res=0
        for j in x
            res+=(j-i)^2
        end
        ans=min(ans,res)
    end
    println(ans)
end
main()

Measured memory_bytes: 113652
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int cl = 0;
		int fcl = 0;
		String s = sc.next();
		for(int i = 0; i < s.length(); i ++){
			switch(s.charAt(i)){
			case 'a':
				if(cl < a + b){
					System.out.println("Yes");
					cl++;
				}else{
					System.out.println("No");
				}
				break;
			case 'b':
				if(cl < a + b && fcl < b){
					System.out.println("Yes");
					cl++;
					fcl ++;
				}else{
					System.out.println("No");
				}
				break;
			default:
				System.out.println("No");
				break;
			}
		}
	}
}




Measured memory_bytes: 52976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

ll modpow(ll a , ll b, ll m){
  if (b == 0) return 1;
  ll ret;
  if (b%2 == 0){
    ll  t = modpow(a, b/2, m)%m;
    ret = t*t %m;
  }else{
    ll t = modpow(a, (b-1)/2,m)%m;
    ret = a*t %m * t % m;
  }
  ret %= m;
  return ret;
}
const ll MOD = 1e9+7;

int main() {
  ll n;
  cin >> n;
  vector<ll> c(n);
  REP(i,n){
    cin >> c[i];
  }
  sort(ALL(c));
  reverse(ALL(c));
  ll ans = 0;
  FOR(k,1,n+1){
    ans += (k+1)*c[k-1] % MOD;
    ans %= MOD;
  }
  ans *= modpow(4,n-1,MOD);
  ans %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int N = NextInt();
        Dictionary<int, int> d = new Dictionary<int, int>();
        for (int i = 0; i < N; i++)
        {
            int a = NextInt();
            if (!d.ContainsKey(a)) d[a] = 0;
            d[a]++;
        }
        if (d.ContainsKey(0))
        {
            if (d[0] == N) Console.WriteLine("Yes");
            else if (N % 3 == 0 && d[0] == (N / 3) && d.Count() == 2)
            {
                Console.WriteLine("Yes");
            }
            else Console.WriteLine("No");
        }
        else if (N % 3 == 0 && d.Count() == 3)
        {
            int xor = 0;
            foreach (var v in d)
            {
                xor ^= v.Key;
                if (v.Value != (N / 3)) { Console.WriteLine("No"); return; }
            }
            if (xor == 0) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
        else Console.WriteLine("No");
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}
public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


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

int main() {
 	string s, t;
 	cin >> s >> t;
 	int x = s.size(), y = t.size();
 	int ans = 0;
 	for(int i = 0; i < x - y + 1; i++) {
        int lol = 0;
        for(int j = 0; j < y; j++) {
            if(s[i + j] == t[j]) {
                lol++;
            }
        }
        ans = max(ans, lol);
 	}
 	cout << y - ans << endl;
}


Measured memory_bytes: 3640
import numpy as np
import math

n = int(input())
A = list(map(int, input().split()))
A = np.asarray(A)
A = np.sort(A)
while(A.size != 1):
    minimum = A[0]
    m = A.size
    B = np.asarray([minimum]*m)
    A = A%B
    A[0] = minimum
    A = A[A > 0]
    A = np.sort(A)
print(minimum)


Measured memory_bytes: 23088
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {
  constexpr auto Mod = 1000000007;
  int N;
  scanf("%d", &N);
  auto mask = (1 << N) - 1;
  static int F[22][1 << 21];
  F[0][0] = 1;
  for (auto i = 0; i < N; ++i) {
    for (auto j = 0; j < N; ++j) {
      int x;
      scanf("%d", &x);
      if (x) {
        x <<= j;
        auto s = mask ^ x;
        for (auto t = s; t; t = s & (t - 1))
          F[i + 1][t | x] = (F[i + 1][t | x] + F[i][t]) % Mod;
        F[i + 1][x] = (F[i + 1][x] + F[i][0]) % Mod;
      }
    }
  }
  printf("%d\n", F[N][mask]);
  return 0;
}


Measured memory_bytes: 172288
#!/usr/bin/env python3
#F

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
edges = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = LI()
    edges[u-1].append(v-1)
    edges[v-1].append(u-1)

dp = [inf]*n
ans = [None]*n
ans[0] = 1
dp[0] = a[0]
def dfs(s, p, dp, num):
    for u in edges[s]:
        flag = False
        if u == p:
            continue
        r = bl(dp, a[u])
        tmp = dp[r]
        if dp[r] == inf:
            num += 1
            flag = True
        ans[u] = num
        dp[r] = min(dp[r], a[u])
        dfs(u, s, dp, num)
        dp[r] = tmp
        if flag:
            num -= 1
    return
dfs(0, -1, dp, 1)

for i in ans:
    print(i)
        

Measured memory_bytes: 548112
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main()
{
    // 入力の受け取り
    int n, m;
    cin >> n >> m;

    vector<int> vecPrice(n);
    for(int i=0; i<n; i++)
        cin >> vecPrice.at(i);

    priority_queue<int> pqPrice;
    for(int i=0; i<n; i++)
        pqPrice.push(vecPrice[i]);

    // 一番値段が大きいものに割引券使用
    for(int i=0; i<m; i++){
        int max = pqPrice.top();
        pqPrice.pop();
        pqPrice.push(0.5*max);
    }

    // 結果
    long long res = 0;
    while(!pqPrice.empty()){
        res += pqPrice.top();
        pqPrice.pop();
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1404
n=int(input())
a=[int(input())for _ in[0]*n]
for i in range(4):
 for j in range(n-1,i,-1):
  if a[i]>a[j]:a[i],a[j]=a[j],a[i]
p=[]
for i in range(3):
 for d in a[i+1:4]:
  c=a[i]
  p+=[int(f'{c}{d}'),int(f'{d}{c}')]
print(sorted(p)[2])


Measured memory_bytes: 5992
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pranay2516
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            int sum = 0;
            for (int i = 0; i < m; ++i) {
                sum += in.nextInt();
            }
            out.println(sum > n ? -1 : n - sum);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 32976
import java.util.*;
public class Main {
	private static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		byte a = sc.nextByte();
		for (int l=0; l<a; l++){
			byte gx=sc.nextByte();
			byte gy=sc.nextByte();
			byte No [][] = new byte [gx+1][gy+1];
			byte b = sc.nextByte();
			for (int k=0; k<b; k++){
				byte x1=sc.nextByte();
				byte y1=sc.nextByte();
				byte x2=sc.nextByte();
				byte y2=sc.nextByte();
				
				if (x1 == x2) {
					No [x1][(Math.max(y1, y2))]+=1;
				}
				else {No[(Math.max(x1,x2))][y1]+=2;}			
			}
			int Total[][] = new int [gx+1][gy+1];
			Total[0][0] = 1;
			for (int i=0; i<=gx; i++){
				for (int j=0; j<=gy; j++){
					if (No[i][j] == 0){
						if (i>0 & j>0){
							Total[i][j]=Total[i-1][j]+Total[i][j-1];
						}
						else if (j>0){
							Total[i][j]=Total[i][j-1];
						}
						else if (i>0){
							Total[i][j]=Total[i-1][j];
						}
						else;
					}
					else if(No[i][j] == 1){
						if (i>0){
							Total[i][j]=Total[i-1][j];
							}
						else Total[i][j]=0;
					}
					else if(No[i][j] == 2){
						if (j==0){
							Total[i][j]=0;
						}
						else Total[i][j]=Total[i][j-1];
					}
					else {
						Total[i][j]=0;
					}
				}
			}
			if (Total[gx][gy]==0){
				System.out.println("Miserable Hokusai!");
			}
			else {System.out.println(Total[gx][gy]);
			}
		}
	}
}

Measured memory_bytes: 32940
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 500005;
const int mod = 1000000007;

struct P {
  int x,y;
  int idx;
  P(){}
  bool operator<(const P&a)const {
    return y<a.y;
  }
}q[maxn];
int a[maxn];

int c[maxn];
void add(int x,int y){
  while(x<maxn){
    c[x]+=y;
    x += (x&-x);
  }
}
int query(int x){
  int ret = 0;
  while(x){
    ret+=c[x];
    x-=(x&-x);
  }
  return ret;
}

int ans[maxn];
int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++)cin>>a[i];
  for(int i=0;i<m;i++){
    cin>>q[i].x>>q[i].y;
    q[i].idx = i;
  }
  sort(q,q+m);
  unordered_map<int,int>mp;
  int cur = 1;
  for(int i=0;i<m;i++){
    while(cur<=q[i].y){
      int x = a[cur];
      if(mp.find(x)!=mp.end()){
        int tt = mp[x];
        add(tt, -1);
      }
      mp[x] = cur;
      add(cur, 1);
      cur++;
    }
    int tt = query(q[i].y) - query(q[i].x-1);
    ans[q[i].idx] = tt;
  }
  for(int i=0;i<m;i++)cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 35212
#include <iostream>
#include <string>

using namespace std;
int main(){
  string s;
  cin >> s;
  int num1 = 0;
  int num2 = 0;
  char s2;
  
  for(int i = 0; i < 4; i++){
    if(s[i] == s[0]){
    num1++;
    }
    else {
    s2 = s[i];
    }
  }
  
  for (int i = 0; i < 4; i++){
  if(s[i] == s2){
    num2++;  
   }
  }
  
  if (num1 == num2 && num1 == 2){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  
  
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    cout << (n+1) /2 << endl;
    return 0;
}

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


struct Node {
    int id;
    int parentId;
    int leftChildId;
    int rightSiblingId;
};


class RootedTree {
public:
    static const int NIL_ID = -1;

    Node *nodes;
    int size;

    RootedTree(int n) {
        nodes = (Node *)malloc(sizeof(Node) * n);
        size = n;
        for (int i = 0; i < size; i++)
        {
            nodes[i] = Node{i, NIL_ID, NIL_ID, NIL_ID};
        }
    }

    ~RootedTree() {
        delete nodes;
    }

    void push_values(int id, int childCnt, int childIds[]) {
        int prevChildId = NIL_ID;
        for (int i = 0; i < childCnt; i++)
        {
            int childId = childIds[i];
            if (i == 0)
            {
                nodes[id].leftChildId = childId;
            } else {
                nodes[prevChildId].rightSiblingId = childId;
            }
            prevChildId = childId;
            nodes[childId].parentId = id;
        }
    }

    int getDepth(int id) {
        int d = 0;
        int curId = id;
        while (nodes[curId].parentId != NIL_ID)
        {
            curId = nodes[curId].parentId;
            d++;
        }
        return d;
    }

    void printNode(int id) {
        cout << "node " << id << ": parent = " << nodes[id].parentId << ", depth = ";
        int depth = getDepth(id);
        cout << depth << ", " << getNodeType(id, depth) << ", [";
        for (int i = 0, childId = nodes[id].leftChildId; childId != NIL_ID; childId = nodes[childId].rightSiblingId, i++)
        {
            if (i > 0)
                cout << ", ";
            cout << childId;
        }
        cout << "]";
    }

private:
    string getNodeType(int id, int depth) {
        if (depth == 0) {
            return "root";
        } else if (depth > 0 && nodes[id].leftChildId == NIL_ID) {
            return "leaf";
        } else if (depth > 0 && nodes[id].leftChildId != NIL_ID) {
            return "internal node";
        } else {
            throw "there is something wrong on input";
        }
    }
};


int main() {
    int N;
    int i, j, id, deg;

    cin >> N;

    RootedTree tree = RootedTree(N);

    for (i = 0; i < N; i++) {
        cin >> id >> deg;
        int childIds[deg];
        for (j = 0; j < deg; j++)
            cin >> childIds[j];
        tree.push_values(id, deg, childIds);
    }

    for (i = 0; i < N; i++) {
        tree.printNode(i);
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 4532
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = sum(B)

now = A[0]
for i in range(1, len(A)):
    if now+1 == A[i]:
        ans += C[now-1]
    now = A[i]

print(ans)


Measured memory_bytes: 3060
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long maxNum = nums.Max();
    long minNum = nums.Min();
    long minCount = 0;//小さい数の猫の数
    long maxCount = 0;

    for(long i = 0; i < n; i++)
    {
      if(nums[i] == minNum) minCount++;
    }
    maxCount = n - minCount;

    if(maxNum - minNum >= 2) Console.WriteLine("No");
    else if(maxNum - minNum == 0)
    {
      if(maxNum <= n/2 || maxNum == n-1) Console.WriteLine("Yes");
      else Console.WriteLine("No");
    }else if(maxNum - minNum == 1)
    {
      if(maxCount == 1) Console.WriteLine("No");
      else if(minCount+1 <= maxNum && maxNum <= minCount + (maxCount/2)) Console.WriteLine("Yes");
      else Console.WriteLine("No");
    }

	}
}

Measured memory_bytes: 19296
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

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

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

int main(int argc, const char * argv[]) {
    
    int X;
    cin >> X;
    
    if(X>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(ll i= (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int N; cin >> N;
    vector<ll> L(N); REP(i, N) cin >> L[i];
    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());
    ll ans = 0;
    REP(i, N - 2) {
        FOR(j, i + 1, N - 1) {
            if (L[i] == L[j]) {
                continue;
            }
            FOR(k, j + 1, N) {
                if (L[j] == L[k]) {
                    continue;
                }
                if (L[i] >= L[j] + L[k]) {
                    continue;
                }
                ans++;
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3652