akhauriyash/Code-Regression huggingface dataset:
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Sat Jan  5 15:54:59 2019
//
package main

import (
	"fmt"
)

func max(slice ...int) int {
	val := slice[0]
	for _, s := range slice {
		if val < s {
			val = s
		}
	}
	return val
}

func min(slice ...int) int {
	val := slice[0]

	for _, s := range slice {
		if s < val {
			val = s
		}
	}
	return val
}

func find(slice []int, val int) int {
	for i := range slice {
		if slice[i] == val {
			return i
		}
	}
	return len(slice)
}

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

func main() {
	var N int
	fmt.Scan(&N)
	arr := make([]int, N)

	for i := range arr {
		fmt.Scan(&arr[i])
	}
	minVal := min(arr...)
	maxVal := max(arr...)

	fmt.Println(2*N - 1)
	if abs(minVal) < abs(maxVal) {
		index := find(arr, maxVal)

		for i := 0; i < N; i++ {
			fmt.Println(index+1, i+1)
		}

		for i := 1; i <= N; i++ {
			if i+1 <= N {
				fmt.Println(i, i+1)
			}
		}
	} else {
		index := find(arr, minVal)

		for i := 0; i < N; i++ {
			fmt.Println(index+1, i+1)
		}

		for i := N; i >= 1; i-- {
			if i-1 >= 1 {
				fmt.Println(i, i-1)
			}
		}
	}
}


Measured memory_bytes: 512
import sys
n = int(input())
if n == 1:
  print(1)
  sys.exit()
min_max = 1000
for div in range(1, int(n**(0.5) + 1)):
  if n % div == 0:
    a = div
    b = n // div
    fx = max(len(str(a)), len(str(b)))
    min_max = min(min_max, fx)
print(min_max)

Measured memory_bytes: 39860
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,maxsize=1,size=1;
    cin>>n;
    int p[n],pt[n+1];
    for(int i=0;i<n;i++){
        cin>>p[i];
        pt[p[i]]=i;
    }
    for(int i=2;i<=n;i++){
        if(pt[i-1]<pt[i])size++;
        else{
            if(maxsize<size)maxsize=size;
            size=1;
        }
    }
    if(maxsize<size)maxsize=size;
    cout<<(n-maxsize)<<endl;
    return 0;
}

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

int yakusuu(int num) {
    int sum = 0;
    int ans = 0;
    for (int i = 1; i <= num; i++) {
        if (i & 1) {
            for (int j = 1; j <= i; j++) {
                if (i%j == 0) sum++;
                if (sum > 8) break;
            }
        }
        if (sum == 8) ans++;
        sum = 0;
    }
    return ans;
}

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

    cout << yakusuu(n) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int main() {
char x,y;
int a,b;   
   cin >> x >>y;
   if(x<y) cout<<"<"<<endl;
   else if(x>y) cout<<">"<<endl;
   else if(x==y)cout << "=" << endl;
   }
   


Measured memory_bytes: 256
N, T = (int(i) for i in input().split())
c_min = 114514

for i in range(N):
	c, t = (int(i) for i in input().split())
	if t <= T:
		c_min = min(c_min, c)
if c_min == 114514:
	print("TLE")
else:
	print(c_min)

Measured memory_bytes: 3060
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

int N, K;
vector<int> A;
vector<int> F;

// スコアをx以下にできるか
bool f(int x) {
    int cost = 0;

    for (int i = 0; i < N; i++) {
        int k = (int)(ceil(1.0 * A[i] - 1.0 * x / F[i]));
        if (k >= 1) cost += k;
    }

    return cost <= K;
}

signed main() {
    cin >> N >> K;
    A.resize(N);
    F.resize(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> F[i];
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<>());

    int lb = -1;
    int ub = INF;
    while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if (f(mid)) {
            ub = mid;
        } else {
            lb = mid;
        }
    }

    cout << ub << endl;
    return 0;
}

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

int main()
{
    int n;
    cin  >> n;
    int a[n];
    ll sum = 0,ans = INT_MAX;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        a[i] = x;
        sum += x;
    }
    ll k = 0;
    for(int i = 0; i < n-1; i++){
        k += a[i];
        ans = min(ans,abs(sum-2 * k));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

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

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	//n := r.nextInt()
	r.Scan(true)
	a := r.nextStringArray().toInts()
	r.Scan(true)
	b := r.nextStringArray().toInts()

	var kai func(v int) int
	kai = func(v int) int {
		if v <= 1 {
			return 1
		}
		return v * kai(v-1)

	}
	var bef func(v []int, i int) int
	bef = func(v []int, i int) int {
		n := len(v)
		if i >= n {
			return 0
		}
		cnt := 0
		for j := i + 1; j < n; j++ {
			if v[j] < v[i] {
				cnt++
			}
		}

		return cnt*kai(n-i-1) + bef(v, i+1)
	}
	fmt.Fprintln(stdout, abs(bef(a, 0)-bef(b, 0)))
}


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

int main(){
    string s;
    cin >> s;
    vector<int> d(s.size()+1);
    int ten = 1;
    for (int i = s.size()-1; i >= 0; --i) {
        int a = (s[i] - '0') * ten % 2019;
        d[i] = (d[i+1]+a) % 2019;
        ten *= 10; ten %= 2019;
    }
    vector<int> cnt(2019);
    long long int ans = 0;
    for(int i = s.size(); i >= 0; --i) {
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4432
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
/* -- template -- */

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

int main() {
    int K; cin >> K;
    ll sum = 0;
    for(int i = 1;i <= K; ++i) {
        for(int j = 1;j <= K;++j) {
            for(int k = 1;k <= K;++k) {
                sum += gcd(gcd(i, j), k);
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3624
#include <iostream>

using namespace std;

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

    int cnt = 1;
    for (int i = 0, d = 0; i < n; i++) {
        int l;
        cin >> l;
        d += l;

        if (d <= x) {
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
    int n;
    cin >> n;
    if(n%2==0)
        cout << n/2 << endl;
    else
        cout << n/2 + 1 << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}

signed main()
{
   int N, A, B;
   cin >> N >> A >> B;
   if ((A - B) % 2 == 0) {
      cout << "Alice" << endl;
   } else {
      cout << "Borys" << endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

ll merge_cnt(vector<ll> &a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin()+n/2);
    vector<ll> c(a.begin()+n/2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    // merge の処理
    while (ai < n) {
        if ( bi < b.size() && (ci == c.size() || b[bi] >= c[ci]) ) {
            a[ai++] = b[bi++];
        } else {
            cnt += n/2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

bool judge(vector<ll> &a, ll x) {
    ll n = a.size();
    ll sum_v = 0;
    vector<ll> s = {0};

    for (auto &e: a) {
        int t = (e <= x) ? 1 : -1;
        sum_v += t;
        s.push_back( sum_v );
    }

    return merge_cnt(s) > n*(n+1)/2/2;
}

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

    vector<ll> a(n);

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

    ll high = 1e18, low = 0;

    while (low < high) {
        ll mid = ( high + low ) / 2;

        if ( judge(a, mid) ) {
            high = mid;
        } else {
            low = mid+1;
        }
    }

    cout << high << endl;

    return 0;
}

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

// だめだったけど、まだ諦めない
// 一旦バグ取りしたけど、これだとTLEになるから次で改善する
int main() {
    int N, M;
    long long K;
    cin >> N >> M >> K;

    int aCount = 0;
    map<int, long long> A, B;
    long long sum = 0;
    bool isMax = false;
    long long num;
    for (int i = 0; i < N; i++) {
        cin >> num;
        if (!isMax) {
            sum += num;
            if (sum >= K) {
                isMax = true;
            }
            if (sum <= K) {
                if (sum > K) break;
                A[i] = K - sum;
                aCount++;
            }
        }
    }
    sum = 0;
    isMax = false;
    int maxReadCount = aCount;
    int aLastNo = aCount;
    for (int i = 0; i < M; i++) {
        cin >> num;
        if (isMax) {
            continue;
        }
        sum += num;
        if (sum >= K) {
            isMax = true;
        }
        if (sum <= K) {
            if (sum > K) break;
            int a;
            for (int j = aLastNo; j >= 0; j--) {
                if (j == 0) {
                    a = K;
                } else {
                    a = A[j - 1];
                }
                if (sum > a) continue;
                // cout << "i:" << i << ", j:" << j;  // debug
                // cout << ", a:" << a << ", sum:" << sum << endl;  // debug
                maxReadCount = max((i + 1) + j, maxReadCount);
                aLastNo = j;
                break;
            }
        }
    }

    cout << maxReadCount;
}
/*
3 5 20
5 5 5
10 1 1 7 1
*/

Measured memory_bytes: 16052
#include<bits/stdc++.h>
using namespace std;
#define what_is(x) cerr<<#x <<" is "<<x<<endl;
#define ll long long 
#define gcd(a,b) __gcd(a,b)
#define pi 2*acos(0.0)
//use emplace_back() instead of push_back()
template<typename T>
void print(T t)
{
	for(const auto& e:t)cout<<e<<" ";
	cout<<endl;
}
ll nod(ll n) 
{ 
    return floor(log10(n) + 1); 
} 
ll power(ll a,ll n,ll m)
{
	ll ans=1;
	a=a%m;
	if(a==0)return 0;
	while(n)
	{
		if(n%2)
		ans*=a;
		else
		{
			a=a*a;
			n=n/2;
		}
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll ans=0,cnt=0,n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			for(ll k=j+1;k<n;k++)
			{
					if(a[i]==a[j] || a[j]==a[k] || a[i]==a[k])continue;
					if(a[i]+a[j]>a[k])ans++;
				}
			}
		}
		cout<<ans<<endl;
	return 0;
}


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

int main()
{
	int a, b;

	cin >> a >> b;
	
	if (a < b) {
		cout << "a < b" << endl;
	}
	else if (a > b) {
		cout << "a > b" << endl;
	}
	else {
		cout << "a == b" << endl;
	}
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I n;
  cin >> n;
  V h(n);
  VIN(h);
  I t=0,c=0;
  REP(i,n){
    if (i==0) continue;
    if (h.at(i) <= h.at(i-1)){
      c++;
    }else{
      c=0;
    }
    if (t < c) t = c;
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 1152
#include <cstdio>
#include <iostream>
#include <queue>

using namespace std;

int main()
{
	int buf;
	priority_queue<int> qu;

	for ( int i = 0; i < 10; i++ )
	{
		cin >> buf;
		qu.push( buf );
	}

	for ( int i = 0; i < 3; i++ )
	{
		printf("%d\n", qu.top() );
		qu.pop();
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){
    string str;
    cin>>str;
    
    vector<bool> b(26, false);
    bool bb=true;
    for(int i=0; i<str.size(); i++){
        if(b[str[i]-'a']){
            bb=false;
            break;
        }else{
            b[str[i]-'a']=true;
        }
    }
    
    if(bb){
        cout<<"yes"<<endl;
    }else{
        cout<<"no"<<endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
 
using namespace std;
 
#define pai 3.14159265359
#define mod 1000000007

long long int n, a;
int x[51];

long long int num[60][60][2510];

long long int solve(int restsum, int restcardnum, int selectcardnum)
{   
    if(restcardnum == 0 && restsum == 0){
        num[selectcardnum][restcardnum][restsum] = 1;
        return 1;
    }
    if(num[selectcardnum][restcardnum][restsum] != -1) return num[selectcardnum][restcardnum][restsum];
    long long int result = 0;
    for(int i = selectcardnum; i <= n; i++){
        if(restcardnum > 0 && restsum >= x[i]) result += solve(restsum - x[i], restcardnum - 1, i + 1);
    }
    num[selectcardnum][restcardnum][restsum] = result;
    // cout << restsum << " " << restcardnum << " " << selectcardnum << " " << result << endl;
    return result;
}

int main()
{
    cin >> n >> a;
    long long int xsum = 0;
    for(int i = 1; i <= n; i++){
        cin >> x[i];
        xsum += x[i];
    }
    for(int i = 0; i < 51; i++){
        for(int j = 0; j < 51; j++){
            for(int k = 0; k < 2501; k++){
                num[i][j][k] = -1;
            }
        }
    }
    long long int ans = 0;
    long long int nownum = a;
    long long int nowcardnum = 1;
    while(nowcardnum <= n && nownum <= xsum){
        ans += solve(nownum, nowcardnum, 1);
        nownum += a;
        nowcardnum++;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}

int main(){
	startTime=clock();
	int q=1e5+1;
	bool isprime[q];
	FOR(i,q) isprime[i]=true;
	for(int i=2;i<q;i++){
		if(isprime[i]){
			for(int j=2;j*i <q;j++) isprime[j*i]=false;
		}
	}
	isprime[1]=false;
	isprime[0]=false;
	bool is2017[q];
	FOR(i,q) is2017[i]=isprime[i] && isprime[(i+1)/2] && i%2;
	int sum[q]={};
	sum[0]=0;
	sum[1]=0;
	for(int i=2;i<q;i++){
		sum[i]=is2017[i]+sum[i-1];
	}

	int n,l,r;
	cin >> n;
	FOR(i,n){
		cin >> l >> r;
		if(is2017[l]) cout << 1+sum[r]-sum[l];
		else cout << sum[r]-sum[l];
		cout <<"\n";
	}
	return 0;
}

Measured memory_bytes: 4144
#include<bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e17;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin>>n;
    vii cnt(26, infi);
    rep(xx,n){
        string s;
        cin >> s;
        vii cnti(26, 0);
        rep(i,s.size()){
            cnti[s[i] - 'a']++;
        }
        rep(i,26){
            cnt[i] = min(cnt[i], cnti[i]);
        }
    }
    string ans;
    rep(i,26){
        rep(j,cnt[i]){
            ans += (char)('a' + i);
        }
    }
    cout << ans << ENDL;
}

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

int n;
char s[310][310], t[310][310];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", s[i]);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        bool flag = 1;
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                t[j][k] = s[j][(k + i) % n];
            }
        }
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                flag &= t[j][k] == t[k][j];
            }
        }
        if (flag) ans += n;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 384
open List
let rec($)l=function[]->l|[e]->e::l|((a,b),s)as x::((((c,d),t)::z)as y)->if a<c&&b>d then l$(((a,b),s+t)::z)else(x::l)$y
let a=[]$(fold_left(fun(i,q,w)x->match x with|'_'->i+1,q,w|'\\'->i+1,i::q,w|_->(match q with[]->i+1,q,w|j::o->i+1,o,((j,i),i-j)::w))(0,[],[])(let s=read_line()in let a=ref[]in for i=String.length s-1downto 0do a:=s.[i]::!a done;!a)|>fun(_,_,t)->t)and g=Printf.printf;;g"%d
"(fold_left(fun z(_,n)->z+n)0 a);g"%d"(length a);iter(fun(_,n)->g" %d"n)a;g"
"

Measured memory_bytes: 5136
#include<stdio.h>
#define LEN 1000000
typedef struct{
  char name[20];
  int time;
}Que;
Que que[LEN],Q;
int main()
{
  int N,i,q,head=0, tail=0,times=0;
  scanf("%d%d",&N,&q);
  for(i=0; i<N; i++){
      scanf("%s%d",Q.name,&Q.time);
      que[head]=Q;
      head++;
  }
  while(1){
      tail++;
      Q= que[tail-1];
      if(Q.time<=q){
	     times+=Q.time;
	     printf("%s %d\n", Q.name, times);
      }else{
    	  Q.time-=q;
    	  times+=q;
    	  que[head]=Q;
          head++;
      }
      if( head-tail==0)break;
  }
  return 0;
}


Measured memory_bytes: 6164
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new TEST().doIt();
    }
    class TEST{
        void doIt(){
        	int n = sc.nextInt();
        	int a[] = new int [n];
        	for(int i = 0;i < n;i++)a[i] = sc.nextInt();
        	for(int i = n-1;i > 0;i--)System.out.print(a[i]+" ");
        	System.out.println(a[0]);
        }
    }
}

Measured memory_bytes: 26044
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
  return list(map(int,input().split()))
def m(): #複数文字
  return map(int,input().split())
def onem(): #Nとかの取得
  return int(input())
def s(x): #圧縮
  a = []
  if len(x) == 0:
    return []
  aa = x[0]
  su = 1
  for i in range(len(x)-1):
    if aa != x[i+1]:
      a.append([aa,su])
      aa = x[i+1]
      su = 1
    else:
      su += 1
  a.append([aa,su])
  return a
def jo(x): #listをスペースごとに分ける
  return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
  return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
  ll = 0
  rr = r
  while True:
    mid = (ll+rr)//2

  if rr == mid:
    return ll
  if (ここに評価入れる):
    rr = mid
  else:
    ll = mid+1
"""

n,k = m()

if n == 0:
  if k == 0:
    print("0 0")
  else:
    print(-1)

elif n == 1:
  if k == 0:
    print("0 0 1 1")
  else:
    print(-1)
else:
  if 2<<(n-1) > k:
    po = []

    op = []

    for i in range((2<<(n-1))):
      if i == k:
        continue
      else:
        if po == "":
          po.append(i)
          op.append(i)
        else:
          po.append(i)
          op.append(i)
    op.reverse()
    print("{0} {1} {2} {3}".format(jo(po),k,jo(op),k))
  else:
    print(-1)




Measured memory_bytes: 103808
from sys import stdin
 
a=stdin.readline().split()
A=int(a[0]) #1
B=int(a[1]) #0
C=int(a[2]) #-1
K=int(a[3])
 
if K<=A:
  print(K)
elif K<A<=A+B:
  print(A)
else:
  print(2*A+B-K)

Measured memory_bytes: 9192
while 1:
    n, q = map(int, input().split())
    if n==0: break
    a = []
    for _ in range(n):
        a = a + list(map(int, input().split()))[1:]
    max = 0
    d = 0
    for i in range(1, 101):
        if a.count(i) >= q and max < a.count(i):
            max = a.count(i)
            d = i
    print(d)


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
const ll mn=1e5+4;
ll a[mn];
vector<ll> g[mn];
ll n,k;
ll final=0;
ll dfs(ll x) {
	ll depth=0;
	for (auto &y:g[x]) {
		chkmax(depth, dfs(y));
	}
	if (depth==k-1) {
		if (a[x]!=1) final++;
		return 0;
	}
	else return depth+1;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin>>n>>k;
	for (ll x=1;x<=n;x++) cin>>a[x];
	if (a[1]!=1) {final++;a[1]=1;}
	for (ll x=1;x<=n;x++) {
		if(a[x]!=x) g[a[x]].PB(x);
	}
	dfs(1);
	cout<<final<<endl;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n;
    cin >> n;
    vi p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    vi a(n);
    rep(i, n) a[i] = i + 1;
    map<vi, int> mp;
    do {
        mp[a] = mp.size();
    } while (next_permutation(all(a)));
    cout << abs(mp[p]-mp[q]) << endl;
    return 0;
}


Measured memory_bytes: 5248
var
 n,m,i,j:longint;
 a:array[0..101,0..101] of char;
begin
 readln(n,m);
 for i:=1 to n do
  begin
   for j:=1 to m do
    read(a[i,j]);
   readln;
  end;
 for i:=1 to 2*n do
  begin
   for j:=1 to m do
    write(a[(i+1) div 2,j]);
   writeln;
  end;
end.

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
//#define sort(v,n) sort(v,v+n)
#define ll long long
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
ll n,a,b;
ll c[100001];
bool taosu(ll t) {
	ll cont = 0;
	ll d = a - b;
	for (int i = 0; i < n; i++) {
		ll h = c[i] - t*b;
		if (h > 0) {
			cont += (h + d - 1) /d;
		}
	}
	/*if (cont <= t) {
		cout << "cont<=t" << endl;
	}
	else {
		cout << "else" << endl;
	}*/
	return cont <= t;
}

int main() {
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	ll l = 0, r = 10000000000;
	while (l+1 < r) {
		ll mid = (r + l)/2;
		if (taosu(mid)) {
			r = mid;
			//cout <<"r="<< r << endl;
		}
		else {
			l = mid;
			//cout << "l=" << l << endl;
		}
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<math.h>
#include<algorithm>
#include<iostream>

using namespace std;

int main(){
	int size[3];
	int n,r;
	int i;
	
	while(1){
	 for(i=0;i<3;i++){cin>>size[i];}
	 if(!(size[0]||size[1]||size[2])){break;}
	 sort(size,size+3);
	 
	 cin>>n;
	 for(i=0;i<n;i++){
	  cin>>r;
	  if(pow(size[0],2)+pow(size[1],2)<4*pow(r,2)){cout<<"OK\n";}else{cout<<"NA\n";}
	 }
	}
	
	return 0;
}

Measured memory_bytes: 1136
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <string>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	string s;
	cin >> s;

	int k;
	cin >> k;

	int sz = s.size();

	set<string> subs;
	for (int i = 0; i < sz; ++i) {
		string curr = "";
		for (int j = i; j < min(i + 5, sz); ++j) {
			curr.push_back(s[j]);
			subs.insert(curr);
		}
	}

	int i = 1;
	for (auto it = subs.begin(); it != subs.end(); ++it) {
		if (i == k) {
			cout << *it << "\n";
			return 0;
		}

		++i;
	}

	return 0;

}

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

i = 1
# j = 0

if 1 in set(a):
    # while j < N and i in set(a[j:]):
    #     j = a[j:].index(i) + j
    #     # print(i, j)
    #     i += 1
    for a_i in a:
        if a_i == i:
            i += 1
    print(N - i + 1)
else:
    print(-1)

Measured memory_bytes: 26268
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <string>
#include <cstring>
#include <cctype>
#include <climits>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <sstream>
#include <queue>
#include <stack>
using namespace std;

int main(){
	int n,val,ans=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&val);
		ans+=val-1;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
package main
 
import (
	"fmt"
)

func SumOfDigits(n int) int {
		sum := 0
		for n > 0 {
				sum += n % 10
				n /= 10
		}
		return sum
}
 
func main() {
		var N,A,B int
		fmt.Scan(&N,&A,&B)

		ans := 0
		for i := 1; i <= N; i++ {
				sum := SumOfDigits(i)
				if sum >= A && sum <= B {
					ans += i
				}
		}
		fmt.Println(ans)
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    s[k-1] = tolower(s[k-1]);
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    map<int,int> mp;
    for(int i=0;i<n;i++){
        cin >>a[i];
        if(a[i]>3200)a[i]=3200;
        mp[(a[i]/400)]++;
    }
    int ans=0;
    for(int i=0;i<8;i++)ans+=(mp[i] > 0);
    cout << max(ans,1) << " " << ans + mp[8];
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define ld                 long double
#define ff                 first
#define ss                 second
#define P                 pair<int,int>
#define pb                 push_back
#define mod             1000000007
#define inf             1e18
#define endl            '\n'
const int N = 100005;//change it when needed
int n;
int a[N];
int dp[N];
int go(int i) {
    if (i < 2) {
        return abs(a[i] - a[0]);
    }
    int &ans = dp[i];
    if (ans != -1)return ans;
    ans = inf;
    int op1, op2;
    op1 = abs(a[i] - a[i - 1]) + go(i - 1);
    if (i > 1)
        op2 = abs(a[i] - a[i - 2]) + go(i - 2);
    ans = min(op1, op2);
    return ans;
}
void solve() {
    int  m, ans = 0, cnt = 0, sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        dp[i] = -1;
    }
    cout << go(n - 1) << endl;
}

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t; cin >> t; while (t--)
    solve();
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
 
#define 	FOR(i,a,b)			for(i = a ; i < b ; i++)
#define 	RFOR(i,a,b)			for(i = a ; i >= b ;i--)
#define 	FORSW(i,a,b,sw)		for(i = a ; i < b && sw ; i++)
#define 	RFORSW(i,a,b,sw)	for(i = a ; i >= b && sw ; i--)
#define 	fast 				ios::sync_with_stdio(false),cin.tie(),cout.tie();
#define 	to_int(x) 			atoi(x.data())
#define 	to_long(x) 			atoll(x.data())
#define 	ALL(x) 				x.begin(),x.end()
#define 	RALL(x) 			x.rbegin(),x.rend()
typedef 	long long 			ll;
typedef 	pair<int,int> 		pi;
typedef 	pair<ll,ll> 		pl;
const		int 				modN = 1e9+7;
const		double 				PI = 3.1415926535897932384626433832795028841;
//---------------------------------------------------------------------------------------------
 
int n,m;
char grid[1002][1002];
int memo[1002][1002];
 
int dp(int i, int j){
	if(i==n-1 && j==m-1) {memo[i][j]=0;return 1;}
	if(grid[i][j]=='#') return memo[i][j]=0;
	if(memo[i][j]!=-1) return memo[i][j];
	if(i==n-1) return memo[i][j]=dp(i,j+1);
	if(j==m-1) return memo[i][j]=dp(i+1,j);
	return memo[i][j]=((dp(i+1,j)%modN+dp(i,j+1)%modN)%modN); 
}
 
int main(){
	char c;
	int i,j;
	while(cin >>n >>m){
		memset(memo,-1,sizeof memo);
		FOR(i,0,n) FOR(j,0,m) cin >> grid[i][j];
		cout << dp(0,0)<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 8648
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int main() {
	int  a, b, k;
	cin >> a >> b >> k;
	VI ok;
	FOR(i, 1, min(a, b) + 1) {
		if ((a%i == 0) & (b%i == 0)) {
			ok.PB(i);
		}
	}
	reverse(ALL(ok));
	cout << ok[k - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
// #include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h> 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
 
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}
	 
 //using namespace __gnu_pbds;
 //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
// mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); for randomized solutions

typedef int ftype;
typedef complex<ftype> point;
#define x real
#define y imag

vector<point> hull, vecs;
ftype dot(point a, point b) {
    return (conj(a) * b).x();
}

ftype cross(point a, point b) {
    return (conj(a) * b).y();
}


void add_line(ftype k, ftype b) {
    point nw = {k, b};
     point iota = {0,1};
    while(!vecs.empty() && dot(vecs.back(), nw - hull.back()) < 0) {
        hull.pop_back();
        vecs.pop_back();
    }
    if(!hull.empty()) {
        vecs.push_back(iota * (nw - hull.back()));
    }
    hull.push_back(nw);
}
int get(ftype x) {
    point query = {x, 1};
    auto it = lower_bound(vecs.begin(), vecs.end(), query, [](point a, point b) {
        return cross(a, b) > 0;
    });
    return dot(query, hull[it - vecs.begin()]);
}
int32_t main()
{
    IOS

    
	int n,c;
	cin>>n>>c;
	int h[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
	}
	int dp[n+1];
	add_line(h[1],h[1]*h[1]);
	for(int i=2;i<=n;i++)
	{
		dp[i]=get(-2*h[i])+c+h[i]*h[i];
		add_line(h[i],h[i]*h[i]+dp[i]);
	}
	cout<<dp[n]<<endl;


}       

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

int main() {
	// your code goes here
	long long N = 0;
	cin>>N;
	if(N % 10 == 0)
	{
	    cout<<"10";
	}
	
	else
	{
	   long n = N;
	   long m = 0;
	   long sum = 0;
	   while(n != 0)
	   {
	       m = n % 10;
	       n = n / 10;
    	   sum = sum + m;
	   }
	   cout << sum;
	}
	return 0;
}


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

typedef long long int ll;
typedef pair <ll, ll> pll;

const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const ll Inf = 1LL << 62;

int main() {
	ll x;
	cin >> x;
	ll tot = 360;
	while(1) {
		if(tot % x == 0) {
			cout << tot / x << endl;
			return 0;
		}
		tot += 360;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define Rep1(i,k,n) for(int i=k ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

double inverse(int x){
    return (1.0)/x;
}

bool isPrime(int x){
    if(x == 1) return false;

    for(int i=2;i*i <= x; i++){
        if(x%i == 0) return false;
    }

    return true;
}


int main(){
    int n; cin >> n;
    vi l(n),r(n);

    rep(i,n){
        cin >> l[i] >> r[i];
    }

    vi s(100010);

    for(int i=3;i<=100000;i++){
        bool f1 = isPrime(i);
        bool f2 = isPrime((i+1)/2);

        if(f1 and f2) s[i] = s[i-1] + 1;
        else s[i] += s[i-1];
    }

    rep(i,n){
        cout << s[r[i]] - s[l[i]-1] << endl;
    }


}


Measured memory_bytes: 1792
#include <iostream>
#include <math.h>

using namespace std;


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

	long long ans = 0;
	long long max = 0, min = 0;
	long long mod = pow(10, 9) + 7;

	// Initialize max, min values
	for (int i = 0; i < K; ++i)
	{
		max += N - i;
		min += i;
	}

	// Calculate ans
	for (int i = K; i <= N; ++i)
	{
		ans += (max - min + 1) % mod;
		ans %= mod;
		// Update max, min values
		max += N - i;
		min += i;
	}
	ans += 1;
	ans %= mod;

	cout << ans;
}

Measured memory_bytes: 3628
from collections import deque

N = int(input())
tree = [dict() for _ in range(N+1)]
color = [0]*(N+1)
parent = [0]*(N+1)
for _ in range(N-1):
    u, v, w = map(int, input().split())
    w %= 2
    tree[u][v] = w
    tree[v][u] = w

que = deque([1])
while len(que) != 0:
    u = que.pop()
    Rel, c, p = tree[u], color[u], parent[u]
    for v in Rel.keys():
        if v == p:
            continue
        elif Rel[v] == 0:
            color[v] = c
        else:
            color[v] = c^1
        parent[v] = u
        que.append(v)

for c in color[1:]:
    print(c)

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

using namespace std;

#define NAX 1e9+5

int main()
{
    int n;
    scanf("%d",&n);
    vector<int> a(n),b(n),c(n);

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

    vector<vector<int> > dp(n,vector<int>(3,NAX));

    dp[0][0]=a[0],dp[0][1]=b[0],dp[0][2]=c[0];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
    }
    printf("%d",max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}));
}


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

int main(){
  int j,i,ans=0,N,K,d,temp;
  bool A[101]={0};
  cin>>N>>K;
  for(i=0;i<K;i++){
    cin>>d;
    for(j=0;j<d;j++){
      cin>>temp;
      A[temp-1]=1;
    }
  }
  for(i=0;i<N;i++) ans+=A[i];
  cout<<N-ans<<endl;
}

Measured memory_bytes: 3644
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int X,t; cin >> X >> t;
    cout << max(0,X - t) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include<cfenv>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include<numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
vector<llong> AllDivisors(llong N) {
	vector<llong> ANS;
	for (llong i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ANS.push_back(i);
			if (N / i != i)ANS.push_back(N / i);
		}
	}
	sort(ANS.begin(), ANS.end());
	return ANS;
}
bool IsPrime(llong N) {
	for (llong i = 2; i * i <= N; i++) {
		if (N % i == 0) return false;
	}
	return true;
}
//ここまで共通
llong X;
int main() {
	cin >> X;
	llong A = 100;
	llong ANS = 0;
	while (A < X) {
		ANS++;
		llong tmp = A / 100;
		A += tmp;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 3632
# Problem C - management

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

# initialization
ue_list = [0]*N

# ue loop
for i in range(N-1):
    a = a_list[i]
    ue_list[a-1] += 1

# output
for u in ue_list:
    print(u)


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

int main(){
  string s;
  cin>>s;
  set<char> st;
  for(int i =0; i < s.length(); i++){
    st.insert(s[i]);
  }
  if(st.size() >= 2){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}

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

remark_list = [[] for _ in range(n)] # -1:言及なし, 0:不親切, 1：親切
for i in range(n):
    a = int(input())
    for j in range(a):
        remark_list[i].append(list(map(int, input().split())))

ans = 0
for i in range(2**n):
    state = [-1]*n
    is_ok = True
    ok_num = 0
    for j in range(n):
        if ((i >> j) & 1):
            if state[j] != 0:
                state[j] = 1
            else:
                is_ok = False
            remark = remark_list[j]
            ok_num += 1
            for r in remark:
                if state[r[0]-1] == -1:
                    state[r[0]-1] = r[1]
                elif state[r[0]-1] != r[1]:
                    is_ok = False
                    break
        else:
            if state[j] != 1:
                state[j] = 0
            else:
                is_ok = False
    if is_ok:
        ans = max(ans, ok_num)
print(ans)


Measured memory_bytes: 74212