akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 100000
#define NIL -1

struct Node {int parent,left,right;};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u==NIL)return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left!=NIL)
    h1 = setHeight(T[u].left)+1;
  if(T[u].right!=NIL)
    h2 = setHeight(T[u].right)+1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].parent==NIL)return NIL;
  if(T[T[u].parent].left!=u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right!=u && T[T[u].parent].right!= NIL)
     return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent==NIL){
    printf("root\n");
  }else if (T[u].left== NIL && T[u].right ==NIL){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }
}
int main(){
  int i,v,l,r,root=0;
  scanf("%d",&n);

  for(i=0;i<n;i++)T[i].parent=NIL;

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL)T[l].parent=v;
    if(r!=NIL)T[r].parent=v;
  }

  for(i=0;i<n;i++)if(T[i].parent==NIL)root=i;

  setDepth(root,0);
  setHeight(root);

  for(i=0;i<n;i++)print(i);

  return 0;
}
    



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

using namespace std;

typedef long long ll;

int P = 998244353;

struct sg{
    vector<int> rangeMax;
    int n;
    sg(vector<int>& arr){
        n = arr.size();
        rangeMax.resize(4 * n);
        init(arr, 0, n-1, 1);
    }
    int init(vector<int>& arr, int arrLeft, int arrRight, int nodeIndex){
        if(arrLeft == arrRight){
            return rangeMax[nodeIndex] = arrLeft;
        }
        int mid = (arrLeft + arrRight) / 2;
        int left = init(arr, arrLeft, mid, nodeIndex * 2);
        int right = init(arr, mid+1, arrRight, nodeIndex * 2 + 1);
        return rangeMax[nodeIndex] = max(left, right);
    }

    int query(int arrLeft, int arrRight, int nodeLeft, int nodeRight, int nodeIndex){
        if(arrLeft <= nodeLeft && nodeRight <= arrRight){
            return rangeMax[nodeIndex];
        }
        if(arrLeft > nodeRight || arrRight < nodeLeft){
            return INT_MIN;
        }
        int mid = (nodeLeft + nodeRight) / 2;
        int left = query(arrLeft, arrRight, nodeLeft, mid, nodeIndex * 2);
        int right = query(arrLeft, arrRight, mid+1, nodeRight, nodeIndex * 2 + 1);
        return max(left, right);
    }

    int query(int arrLeft, int arrRight){
        return query(arrLeft, arrRight, 0, n-1, 1);
    }

    int update(int arrIndex, int val, int nodeLeft, int nodeRight, int nodeIndex){
        if(arrIndex < nodeLeft || arrIndex > nodeRight){
            return rangeMax[nodeIndex];
        }
        if(nodeLeft == nodeRight){
            return rangeMax[nodeIndex] = val;
        }
        int mid = (nodeLeft + nodeRight) / 2;
        int left = update(arrIndex, val, nodeLeft, mid, nodeIndex*2);
        int right = update(arrIndex, val, mid+1, nodeRight, nodeIndex*2+1);
        return rangeMax[nodeIndex] = max(left, right);
    }

    int update(int arrIndex, int val){
        return update(arrIndex, val, 0, n-1, 1);
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N;
    cin >> N;
    vector<pair<int,int>> robots(N);
    for(int i = 0 ; i < N; ++i){
        cin >> robots[i].first >> robots[i].second;
    }
    sort(robots.begin(), robots.end());
    vector<int> endList(N);
    for(int i = 0 ; i < N; ++i){
        pair<int,int> p = make_pair(robots[i].first + robots[i].second - 1, 2000000000);
        auto it = upper_bound(robots.begin(), robots.end(), p);
        int index = distance(robots.begin(), it);
        endList[i] = index - 1;
    }

    sg maxRobot(endList);
    for(int i = N-2 ; i >= 0 ; --i){
        int maxVal = maxRobot.query(i, endList[i]);
        maxRobot.update(i, maxVal);
        endList[i] = maxVal;
    }
    vector<int> dp(N+1);
    dp[N] = 1;
    dp[N-1] = 2;
    for(int i = N-2; i >= 0; --i){
        dp[i] = dp[endList[i] + 1] + dp[i+1];
        dp[i] %= P;
    }

    cout << dp[0] << endl;
    

    return 0;

}


Measured memory_bytes: 6528
object Main extends App {
  import Math.abs
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val A = Array.fill(n)(sc.nextInt)

  val max = A.max
  var diff = Int.MaxValue
  var ans = A(0)
  val half = max / 2

  A.foreach(x => {
    if (abs(half - x) < diff & x != max) {
      diff = abs(half - x)
      ans = x
    }
  })
  println(max + " " + ans)
}


Measured memory_bytes: 54100
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <utility>
using namespace std;
#define omajinai ios::sync_with_stdio(false);cin.tie(nullptr);

#pragma region typedef 
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> P;
#pragma endregion

#pragma region define
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#pragma endregion

#pragma region const
const ld PI = 3.141592653589793;
const ll INF18 = 1e18;
#pragma endregion

#pragma region function
template<class T>inline bool chmin(T& a,T b){
    if(a>b){a=b;return true;}return false;}
template<class T>inline bool chmax(T& a,T b){
    if(a<b){a=b;return true;}return false;}
#pragma endregion



int main() {
omajinai;

  int d, t, s;  cin >> d >> t >> s;

  t * s >= d ? cout << "Yes" :cout << "No" << endl;
return 0;
}

Measured memory_bytes: 3592
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 12 + 5;
const int M = 201;
const int Q = 2e5 + 5;
const int OO = 2e9;
const int mod = 998244353;

int n,m,x,c[N],a[N][N],sum[N],total,ans=OO;

void init() {
}

int main() {

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

    cin >> n >> m >> x;

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

    for (int mask = 0; mask < (1<<n); ++mask) {

        memset(sum, 0, sizeof sum);
        total = 0;

        for (int bit = 0; bit < n; ++bit) {

            if(mask&(1<<bit)) {

                total += c[bit];

                for (int i = 0; i < m; ++i) {
                    sum[i] += a[bit][i];
                }

            }
        }

        bool ok = 1;

        for (int i = 0; i < m; ++i) {
            if(sum[i]<x) ok = 0;
        }

        if(ok) ans = min(ans, total);

    }

    cout << (ans==OO ? -1 : ans) << '\n';

    return 0;
}

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

int n, m;
int edge[55][55];
int par[55][10];
pair<int, int> q[22];
int dept[55];
int hasquery[55];

void dfs(int now){
	rep(i, 7) par[now][i+1] = par[par[now][i]][i];
	rep(i, n){
		if(edge[now][i] >= 0 && i != par[now][0]){
			par[i][0] = now;
			dept[i] = dept[now] + 1;
			dfs(i);
		}
	}
}
int lca(int a, int b){
	if(dept[a] > dept[b]) swap(a, b);
	for(int i = 7; i >= 0; i--){
		if(dept[par[b][i]] >= dept[a]) b = par[b][i];
	}
	for(int i = 7; i >= 0; i--){
		if(par[a][i] != par[b][i]) a = par[a][i], b = par[b][i];
	}
	if(a != b) a = par[a][0], b = par[b][0];
	return a;
}

int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	memset(edge, -1, sizeof(edge));
	rep(i, n-1){
		int a, b;
		cin >> a >> b;
		a--, b--;
		edge[a][b] = edge[b][a] = i;
	}
	dfs(0);
	cin >> m;
	rep(i, m){
		cin >> q[i].first >> q[i].second;
		q[i].first--, q[i].second--;
		int now = q[i].first;
		while(now != lca(q[i].first, q[i].second)){
			hasquery[edge[now][par[now][0]]] |= (1 << i);
			now = par[now][0];
		}
		now = q[i].second;
		while(now != lca(q[i].first, q[i].second)){
			hasquery[edge[now][par[now][0]]] |= (1 << i);
			now = par[now][0];
		}
	}
	ll ans = 0;
	rep(mask, 1 << m){
		ll res = (__builtin_popcount(mask) % 2 == 0) ? 1 : -1;
		rep(i, n-1){
			if(!(hasquery[i] & mask)) res *= 2LL;
		}
		ans += res;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    int s[N], c[N];
    for (int i = 0; i < M; i++) cin >> s[i] >> c[i];

    int num[N];
    for (int i = 0; i < N; i++) num[i] = -1;
    for (int i = 0; i < M; i++) {
        if ((s[i] == 1) && (c[i] == 0) && (N > 1)) {
            cout << -1 << endl;
            return 0;
        }
        else if ((num[s[i] - 1] != -1) && (num[s[i] - 1] != c[i])) {
            cout << -1 << endl;
            return 0;
        }
        else {
            num[s[i] - 1] = c[i];
        }
    }
    string ans = "";
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            if (num[i] == -1 || num[i] == 0) {
                if (N == 1) ans += "0";
                else ans += "1";
            }
            else {
                ans += to_string(num[i]);
            }
        }
        else {
            if (num[i] == -1) {
                ans += "0";
            }
            else {
                ans += to_string(num[i]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int k,a,b; cin>>k>>a>>b;

    for (int i = a; i <= b; ++i) {
        if (i%k == 0) {
            cout << "OK" << '\n';
            return 0;
        }
    }

    cout << "NG" << '\n';
    return 0;
}

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

using namespace std;

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    vector<pair<long long int, long long int>> ab(n);
    for (int i = 0; i < n; i++)
    {
        scanf("%lld %lld", &(ab[i].first), &(ab[i].second));
    }

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

    long long int ans = 0;
    for (int i = 0; m > 0; i++)
    {
        if (m > ab[i].second)
        {
            ans += ab[i].first * ab[i].second;
            m -= ab[i].second;
        }
        else
        {
            ans += ab[i].first * m;
            break;
        }
    }

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

    return 0;
}


Measured memory_bytes: 1792
s = int(input())

def f(n):
  if n%2:
    return n*3+1
  else:
    return n//2

i = 1
hist = {s:i}
while 1:
  s = f(s)
  i+=1
  if s in hist:
    print(i)
    break
  else:
    hist[s]= i

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  string s;  
  cin>>s;
  if (s == string(3,'A') || s == string(3,'B')) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}



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

int main()
{
  long long N;

  cin >> N;
  vector<long long> a(N - 1);
  vector<long long> v(N, 0);

  for (long long  i = 0; i < N-1; i++)
  {
    cin >> a[i];
    v[a[i] - 1]++;
  }

  for (long long  i = 0; i < N; i++)
  {
    cout << v[i] << endl;
  }

  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    for (int i = 0; i < N; ++i) {
      cin >> A[i];
    }
    for (int i = 0; i < N; ++i) {
        A[i] *= -1;
    }
    multiset<int> se;
    for (int i = 0; i < N; ++i) {
        auto iter = se.upper_bound(A[i]);
        if(iter != se.end()) se.erase(iter);
        se.insert(A[i]);
    }
    cout << se.size();
    return 0;
}

Measured memory_bytes: 5376
n = int(input())
l = list(map(int, input().split()))

i = 0
ans = 0
while i < n:
    j = i
    while j < n-1 and l[j] >= l[j+1]:
        j += 1
    k = i
    while k < n-1 and l[k] <= l[k+1]:
        k += 1
    i = max(j, k) + 1
    ans += 1
    #print(j, k)

print(ans)

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

int main() {
  ll a;
  string s;
  cin >> a >> s;
  ll b = (s[0] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
  a *= b;
  a /= 100;
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 3624
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.IntStream;

public class Main{
	public static void main(String[]$) throws IOException{
		new Main().solve();
	}
	static FastScanner s=new FastScanner(System.in);
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static int gInt() throws IOException{return s.nextInt();}
	static long gLong() throws IOException{return s.nextLong();}
	static long gDouble() throws IOException{return s.nextLong();}

	private void solve() throws IOException{
		int n=gInt(),a[]=new int[n];
		for(int i=0;i<n;++i)
			a[i]=gInt();

		int odd=0,even=0;
		if(a[0]%2==0) {
			odd+=2;
			even+=1;
		}else{
			odd+=1;
			even+=2;
		}
		for(int i=1;i<n;++i) {
			if(a[i]%2==0) {
				even*=3;
				even+=odd;
				odd*=2;
			}else{
				even*=3;
				even+=odd*2;
			}
		}
		System.out.println(even);
	}

	static void yesno(boolean f) {
		yesno(f,"YES","NO");
	}
	static void yesno(boolean f,String yes,String no) {
		System.out.println(f?yes:no);
	}
}
class FastScanner{
	private final BufferedInputStream	in;
	private static final int			bufSize	=1<<16;
	private final byte					buf[]	=new byte[bufSize];
	private int							i		=bufSize;
	private int							k		=bufSize;
	private final StringBuilder			str		=new StringBuilder();

	FastScanner(InputStream in){
		this.in=new BufferedInputStream(in,bufSize);
	}
	int nextInt() throws IOException{
		return (int)nextLong();
	}
	long nextLong() throws IOException{
		int c;
		long x=0;
		boolean sign=true;
		while((c=nextChar())<=32)
			;
		if(c=='-'){
			sign=false;
			c=nextChar();
		}
		if(c=='+'){
			c=nextChar();
		}
		while(c>='0'){
			x=x*10+(c-'0');
			c=nextChar();
		}
		return sign?x:-x;
	}
	int nextChar() throws IOException{
		if(i==k){
			k=in.read(buf,0,bufSize);
			i=0;
		}
		return i>=k?-1:buf[i++];
	}
	String next() throws IOException{
		int c;
		str.setLength(0);
		while((c=nextChar())<=32&&c!=-1)
			;
		if(c==-1){
			return null;
		}
		while(c>32){
			str.append((char)c);
			c=nextChar();
		}
		return str.toString();
	}
	String nextLine() throws IOException{
		int c;
		str.setLength(0);
		while((c=nextChar())<=32&&c!=-1)
			;
		if(c==-1){
			return null;
		}
		while(c!='\n'){
			str.append((char)c);
			c=nextChar();
		}
		return str.toString();
	}
}

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

int main(){
    int a[101];
    int n;
    cin >> n;
    double ans=0.0;
    for (int i=0; i<n; i++){
        cin >> a[i];
        ans += 1.0/a[i];
    }
    ans = 1.0/ans;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

vector<pair<int, int> > a;

int main() {
	int n;
	cin >> n;
	FOR (i, n) {
		int b;
		cin >> b;
		a.pb(make_pair(b, i));
	}
	sort(all(a));
	int cnt = 0;
	FOR (i, a.sz)
		if ((i & 1) != (a[i].second & 1))
			cnt++;
	cnt >>= 1;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1400
def main():
    import sys

    input = sys.stdin.readline

    inf = (10 ** 5) * (10 ** 3)

    n, m = map(int, input().split())
    size = 1 << n

    dp = [inf] * size
    dp[0] = 0

    for _ in range(m):
        cost, _ = map(int, input().split())
        c = (int(x) - 1 for x in input().split())

        mask = 0
        for k in c:
            mask |= 1 << k

        for b in range(size - 1):
            if dp[b] == inf:
                continue
            nb = b | mask
            dp[nb] = min(dp[nb], dp[b] + cost)

    res = dp[size - 1]
    print(-1 if res == inf else res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41840
/* ITP1_11_B: Dice II */
/* 20181125 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define M 6
#define Q 24

enum Direction {top, front, right, left, back, bottom};

int main(void) {
	int Dice[M], answer[Q];
	int i, j, k, q, temp, inTop, inFront;

	for(i = 0; i < 6; i++) scanf("%d", Dice + i);
	scanf("%d", &q);

	k = 0;
	for(j = 0; j < q; j++) {
		scanf("%d %d", &inTop, &inFront);
		for(i = 0; Dice[top] != inTop && i < 3; i++) {
			temp = Dice[top];
			Dice[top] = Dice[left];
			Dice[left] = Dice[bottom]; 
			Dice[bottom] = Dice[right];
			Dice[right] = temp;
		}

		if(Dice[top] != inTop) {
			for(i = 0; Dice[top] != inTop; i++) {
				temp = Dice[top];
				Dice[top] = Dice[back];
				Dice[back] = Dice[bottom]; 
				Dice[bottom] = Dice[front];
				Dice[front] = temp;
			}
		}

		for(i = 0; Dice[front] != inFront; i++) {
			temp = Dice[back];
			Dice[back] = Dice[left];
			Dice[left] = Dice[front]; 
			Dice[front] = Dice[right];
			Dice[right] = temp;
		}

		answer[k++] = Dice[right];
	}

	for(i = 0; i <  q; i++) printf("%d\n", answer[i]);

	return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int k;
//   部分文字列pythonでいうところの[:k]
  string s;
  cin >> k >> s;
//   sizeで文字列の長さを図る　pythonでいうところのlenggth
  if (s.size() <= k) cout << s << endl;
  else {
    // c++だと何文字目からとしないといけない:kとできない
    string ans = s.substr(0,k);
    ans += "...";
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 100100100100100100
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

int main() 
{
    int a, b; cin >> a >> b;

    int ans = max(a,b);
    ans += max(ans-1,min(a,b)); 
    
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 256
n = int(input())
xyh = []
for i in range(n):
    xyh.append(list(map(int,input().split())))

for i in range(n):
    if xyh[i][2] != 0:
        x1,y1,h1 = xyh[i]
        break

for cx in range(101):
    for cy in range(101):
        ch = h1 + abs(x1 - cx) + abs(y1 - cy)
        
        a = 0
        for i in range(n):
            xi, yi, hi = xyh[i]
            if hi == max(ch - abs(xi - cx) - abs(yi - cy), 0):
                a += 1
            else:
                break
        
        if a == n:
            print(cx,cy,ch)

Measured memory_bytes: 3064
fn solve(n: usize) -> usize {
    if n == 1 {
        return 0;
    }

    let mut acc = 0;
    for i in 0..n {
        acc += i;
    }

    acc
}

#[test]
fn solve_test() {
    assert_eq!(solve(13), 78);
    assert_eq!(solve(2), 1);
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let n = parse_line!(usize);
    println!("{}", solve(n));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

ll a[50], b[50], c[50], d[50];

ll sq(ll x)
{
    return x * x;
}

ll d2(int i, int j)
{
    return abs(a[i] - c[j]) + abs(b[i] - d[j]);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> a[i] >> b[i];
    for (int i = 0; i < m; ++i)
        cin >> c[i] >> d[i];

    for (int i = 0; i < n; ++i)
    {
        int k = 0;
        for (int j = 1; j < m; ++j)
        {
            if (d2(i, j) < d2(i, k))
                k = j;
        }
        cout << k + 1 << '\n';
    }
}


Measured memory_bytes: 256
import sys
from collections import defaultdict as dd
import heapq
hpush = heapq.heappush
hpop = heapq.heappop
input = sys.stdin.readline
for _ in range(int(input())):
  N, A, B, C, D = map(int, input().split())
  h = [(0, N)]
  d = dd(lambda: float("inf"))
  d[N] = 0
  vis = set()
  while len(h):
    c, x = hpop(h)
    if x in vis: continue
    vis.add(x)
    if x == 0:
      print(c)
      break
    #print(h)
    if d[0] <= c: continue
    hpush(h, (c + x * D, 0))
    d[0] = min(d[0], c + x * D)
    if d[x // 2] > c + A + (x % 2) * D:
      hpush(h, (c + A + (x % 2) * D, x // 2))
      d[x // 2] = c + A + (x % 2) * D
    if d[-(-x // 2)] > c + A + (x % 2) * D:
      hpush(h, (c + A + (-x % 2) * D, -(-x // 2)))
      d[-(-x // 2)] = c + A + (-x % 2) * D

    if d[x // 3] > c + B + (x % 3) * D:
      hpush(h, (c + B + (x % 3) * D, x // 3))
      d[x // 3] = c + B + (x % 3) * D
    if d[-(x // 3)] > c + B + (-x % 3) * D:
      hpush(h, (c + B + (-x % 3) * D, -(-x // 3)))
      d[-(-x // 3)] = c + B + (-x % 3) * D

    if d[x // 5] > c + C + (x % 5) * D:
      hpush(h, (c + C + (x % 5) * D, x // 5))
      d[x // 5] = c + C + (x % 5) * D
    if d[x // 5] > c + C + (-x % 5) * D:
      hpush(h, (c + C + (-x % 5) * D, -(-x // 5)))
      d[-(-x // 5)] = c + C + (-x % 5) * D

Measured memory_bytes: 107928
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderF
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        long[] a = sc.LongArray();

        long[] memo = new long[n];
        long[] evenSum = new long[n];

        evenSum[0] = a[0];
        for (int i = 2; i < n; i += 2)
        {
            evenSum[i] = evenSum[i - 2] + a[i];
        }

        memo[0] = 0;
        memo[1] = Math.Max(a[0], a[1]);
        for (int i = 2; i < n; i++)
        {
            long tmpAnswer = 0;
            if (i % 2 == 1)
            {
                // 自分を選んだ場合
                long answer1 = a[i] + memo[i - 2];

                // 自分を選ばない場合
                long answer2 = evenSum[i - 1];

                tmpAnswer = Math.Max(answer1, answer2);
            }
            else
            {
                // 自分を選んだ場合
                long answer1 = a[i] + memo[i - 2];

                // 自分の1つ前を選んだ場合
                long answer2 = a[i - 1] + (i >= 3 ? memo[i - 3] : 0);

                // 自分、自分の1つ前、のどちらも選ばない場合
                long answer3 = evenSum[i - 2];

                tmpAnswer = Math.Max(answer1, Math.Max(answer2, answer3));
            }
            memo[i] = tmpAnswer;
        }

        long answer = memo[n - 1];

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 50824
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,c,x,ans;
int main()
{
	cin>>a>>b>>c>>x;
	if(!x)
	{
		cout<<"0"<<'\n';
		return 0;
	}
	for(int i=0;i<=a;++i)
	{
		for(int j=0;j<=b;++j)
		{
			for(int k=0;k<=c;++k)
			{
				if(i*500+j*100+k*50==x)
				  ans++;
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int a[n], sum=0, ave;
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum+=a[i];
    }
    int ans, diff_min=10000;
    for(int i=0; i<n; i++){
        if(abs(sum-a[i]*n)<diff_min){
            ans=i;
            diff_min=abs(sum-a[i]*n);
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n, w;
  cin >> n >> w;
  vector<int> a(n), b(n); // wi, vi
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  
  const int MAXV = 100010;

  vector<int> dp(MAXV, int(1e9) + 7);
  dp[0] = 0;

  for (int i = 0; i < n; i++) {
    for (int j = MAXV - 1; j >= b[i]; j--) {
      dp[j] = min(dp[j], dp[j - b[i]] + a[i]);
    }
  }

  for (int i = MAXV - 1; i >= 0; i--) {
    if (dp[i] <= w) {
      cout << i << '\n';
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 640
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

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



int main() {
	int a, b;
	cin >> a>> b;
	if (b / 10 >= 10) {
		a *= 1000;
	}
	else if (b / 10 >= 1) {
		a *= 100;
	}
	else if (b / 10 == 0) {
		a *= 10;
	}
	b += a;
	rep(i, 10001) {
		if (i * i == b) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

struct UnionFind {
  vector<int> par;
  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    p[i]--;
  }

  UnionFind UF(N);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    UF.unite(x, y);
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += UF.same(i, p[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
num_list = list(map(int, input().split()))
A, B, C = sorted(num_list)
ans = 0

if A % 2 == B % 2 == C % 2:
    ans += (C - B) // 2
    ans += (C - A) // 2
    print(ans)
elif A % 2 == B % 2 != C % 2:
    A += 1
    B += 1
    ans += 1
    ans += (C - B) // 2
    ans += (C - A) // 2
    print(ans) 
elif A % 2 == C % 2 != B % 2:
    ans += (C - A) // 2
    ans += (C - B) // 2 + 1
    ans += 1
    print(ans)
elif B % 2 == C % 2 != A % 2:
    ans += (C - B) // 2
    ans += (C - A) // 2 + 1
    ans += 1
    print(ans)
        


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

vector<int> ans;

void dfs(int num, int d){
    ans.push_back(num);
    if(ans.size() > 1000000) return;
    if(num > 3234566667) return;

    if(d != 0) dfs(num * 10 + d - 1, d - 1);
    if(d != 9) dfs(num * 10 + d + 1, d + 1);
    dfs(num * 10 + d, d);
}


signed main() {
    int k;
    cin >> k;

    for(int i = 1; i <= 9; i++){
        dfs(i,i);
    }
    sort(ans.begin(),ans.end());
    cout << ans[k - 1] << endl;
}
    



Measured memory_bytes: 6552
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
using namespace std;
int main(){
	int n;
	int c[1000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	sort(c, c + n);
	int a = 0;
	for (int j = n-1; j >= 0 ; j--) {
		if (j % 2 == (n - 1) % 2) {
			a += c[j];
		}
		else {
			a -= c[j];
		}
	}
	cout << a << endl;
	return 0;
}



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

int test()
{
    int a[7];
    
    for(int i=0;i<5;i++)
        a[i]=i*2;
    
	a[2]=2;
    a[5]=8;
    a[6]=10;
    
	cout<<upper_bound(a,a+7,12)-lower_bound(a,a+7,11)<<endl;
    return 0;
}
 
int main()
{
    int N,i,j,k;
    cin>>N;
    long long a[N],b[N];
    
    for(i=0;i<N;i++)
        cin>>a[i];
    for(i=0;i<N;i++)
        cin>>b[i];
 
    long long ans=0;
    
    for(k=0;k<30;k++)
	{
        long long a1[N],b1[N];
        long long T=pow(2,k);
        
        for(j=0;j<N;j++)
		{
            a1[j]=a[j]%(2 * T);
            b1[j]=b[j]%(2 * T);
        }
        
        sort(b1,b1+N);
        
        long long count=0;
        
        for(j=0;j<N;j++)
            count+=lower_bound(b1, b1+N,4*T-a1[j])-\
			lower_bound(b1,b1+N,3*T-a1[j])+lower_bound\
			(b1,b1+N,2*T-a1[j])-lower_bound(b1,b1+N,T-a1[j]);
		
        if(count%2==1)
            ans+=pow(2, k);
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 6528
ls = ["7","5","3"]
ws = set()
def rec(pre):
    if len(pre)==l:return
    for w in ls:
         s = pre+w
         ws.add(s)
         rec(s)
    return
n = int(input())
l = len(str(n))
rec("")
ans = 0
for w in ws:
    if w.count("7")*w.count("5")*w.count("3") !=0:
         if int(w)<=n:ans+=1
print(ans)


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int64 R, D, X;
  cin >> R >> D >> X;
  for(int i = 1; i <= 10; i++) {
    X = R * X - D;
    cout << X << endl;
  }
}




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

int main() {
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  bool can = false;
  for(char c='a'; c<='z'; c++) {
    for(int i=0; i<s.size(); i++) {
      if(s[i] == c) can = true;
    }
    if(!can) {
      cout<<c;
      return 0;
    }
    can = false;
  }
  cout<<"None";
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
#define sz(v) (ll)v.size()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,a,m;
	cin>>n>>m;
	priority_queue<ll,vector<ll> > mxhp;
	for(ll i=1;i<=n;i++)
	{
		cin>>a;
		mxhp.push(a);
	}
	while(m--)
	{
		ll ele=mxhp.top();
		mxhp.pop();
		mxhp.push(ele/2);
	}
	ll sum=0;
	while(!mxhp.empty())
	{
		sum+=mxhp.top();
		mxhp.pop();
	}
	cout<<sum<<"\n";
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;

int main(void) {

  string s;
  cin >> s;
  cout << ( s[0] == '9' || s[1] == '9' ? "Yes":"No" ) << endl;

  return 0;
}

// EOF


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    if (N <= 3) {
        write(*max_element(all(A)));
        return 0;
    }

    vv<ll> dp = vvec(N, 3, -LINF);
    dp[0][0] = A[0];
    dp[1][1] = A[1];
    dp[2][0] = A[0] + A[2];
    dp[2][2] = A[2];
    dp[3][1] = A[3] + max(A[0], A[1]);
    rep(i, 4, N) {
        //if (i % 2 == 0) {
        //    dp[i][0] = max(dp[i][0], dp[i - 2][0] + A[i]);
        //    dp[i][1] = max(dp[i][1], dp[i - 2][1] + A[i]);
        //    dp[i][1] = max(dp[i][1], dp[i - 3][0] + A[i]);
        //    dp[i][2] = max(dp[i][2], dp[i - 2][2] + A[i]);
        //    dp[i][2] = max(dp[i][2], dp[i - 3][1] + A[i]);
        //    dp[i][2] = max(dp[i][2], dp[i - 4][0] + A[i]);
        //}
        //else {
        //    dp[i][1] = max(dp[i][0], dp[i - 2][1] + A[i]);
        //    dp[i][1] = max(dp[i][0], dp[i - 3][0] + A[i]);
        //}

        dp[i][0] = max(dp[i][0], dp[i - 2][0] + A[i]);
        dp[i][1] = max(dp[i][1], dp[i - 2][1] + A[i]);
        dp[i][1] = max(dp[i][1], dp[i - 3][0] + A[i]);
        dp[i][2] = max(dp[i][2], dp[i - 2][2] + A[i]);
        dp[i][2] = max(dp[i][2], dp[i - 3][1] + A[i]);
        dp[i][2] = max(dp[i][2], dp[i - 4][0] + A[i]);
    }

    ll ans;
    if (N % 2 == 0) {
        ans = max(dp[N - 2][0], dp[N - 1][1]);
    }
    else {
        ans = max({ dp[N - 3][0], dp[N - 2][1], dp[N - 1][2] });
    }
    write(ans);
}

Measured memory_bytes: 15872
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

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

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	// エラトステネスのふるい
	int n = 100001;
	vector<int> isPrimeVec(n, 1);
	isPrimeVec[0] = 0;
	isPrimeVec[1] = 0;
	for (int i = 2; i < n; i++)
	{
		if (isPrimeVec[i])
		{
			int j = i + i;
			while (j < n)
			{
				isPrimeVec[j] = 0;
				j += i;
			}
		}
	}

	// 2017-likeかどうか
	vector<int> isLike2017(n, 0);
	for (int i = 0; i < n; i++)
	{
		if (isPrimeVec[i])
		{
			if (isPrimeVec[(i + 1) / 2])
			{
				isLike2017[i] = 1;
			}
			else
			{
				isLike2017[i] = 0;
			}
		}
	}

	// 累積和
	vector<int> s(n + 1);
	for (int i = 0; i < n; i++)
	{
		s[i + 1] = s[i] + isLike2017[i];
	}
	
	// クエリ処理
	int q;
	cin >> q;
	int ans = 0;
	for (int i = 0; i < q; i++)
	{
		int l, r;
		cin >> l >> r;
		cout << (s[r + 1] - s[l]) << endl;
	}
}

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

int main() {
	long long N, X, Y;
	vector<long long> P, Q;
	cin >> N;
	P.resize(N), Q.resize(N);
	for (int i = 0; i < N; i++) cin >> P[i];
	for (int i = 0; i < N; i++) cin >> Q[i];
	vector<long long> V(N);
	for (int i = 0; i < N; i++) V[i] = i + 1;
	//1~Nまでにする
	long long COUNT = 0;
	do {
		bool check1 = true, check2 = true;
		for (int i = 0; i < N; i++) {
			if (P[i] != V[i]) check1 = false;
			if (Q[i] != V[i]) check2 = false;
		}
		if (check1) X = COUNT;///ずっと一緒だったらtrueのまま
		if (check2) Y = COUNT;
		COUNT++;
	} while (next_permutation(V.begin(), V.end()));
	cout << abs(X - Y) << endl;
}


Measured memory_bytes: 256
use std::io;

fn main() {
    let mut buildngs = vec![vec![vec![0; 10]; 3]; 4];
    let n = input_number();
    let n = n[0];
    for _ in 0..n {
        let input = input_number();
        let b = input[0] as usize;
        let f = input[1] as usize;
        let r = input[2] as usize;
        let v = input[3] as usize;
       
        buildngs[b-1][f-1][r-1] += v;
    }
    for (index, build) in buildngs.iter().enumerate() {
        for floor in build {
            for house in floor {
                print!(" {}", house);
            }
            println!("");
        }
        if index != 3 {
            println!("####################");
        }
    }
}

#[allow(dead_code)]
fn input_number() -> Vec<i64> {
    let mut input = String::new();
    io::stdin().read_line(&mut input) .expect("Failed to read line");
    let vec: Vec<i64> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap_or(0))
        .collect();
    vec
}

#[allow(dead_code)]
fn input() -> (char, usize) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c:char = iter.next().unwrap().chars().nth(0).unwrap();
    let n:usize = iter.next().unwrap().parse().unwrap();
    (c, n)
}



Measured memory_bytes: 5024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
int main()
{
   ll q,h,s,d;
   ll n;
   while(scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n)!=EOF)
   {
       ll m1=min(q*4,h*2);
       m1=min(m1,s);
       ll m2=d;
       ll ans;
       if(2*m1<=m2)
       {
            ans=m1*n;
       }
       else if(2*m1>m2)
       {
            ans=n/2*m2;

           if(n%2==1)
           {
               ans+=m1;
           }
       }
       cout<<ans<<endl;
   }

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define maxn 1000000
using namespace std;
map <int, long long int> mp;  // h[i] dp[i]
long long int h[maxn],a[maxn];
int main()
{
	int N; cin >> N;
	mp[0]=0; 

	for(int i = 0; i < N; i++)
		cin >> h[i];

	for(int i = 0; i < N; i++)
		cin >> a[i];

	//mp[h[0]] = a[0];

	for(int i = 0; i < N; i++)
	{
		auto p = mp.upper_bound(h[i]);
		auto ps = prev(p);
		long long int tmp = a[i] + ps -> y;

		while(mp.end() != p && p->y <= tmp)
			mp.erase(p++);
		mp[h[i]] = tmp;
	}

	cout << prev(mp.end())->y <<endl;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto& i : v) cin >> i;

    sort(all(v));
    ll ans = 0;
    FOR(i, 0, n-2){
        FOR(j, i+1, n-1){
            int a = v[i], b = v[j];
            int d = max(b - a, a - b);
            auto ma = lower_bound(v.begin() + j + 1, v.end(), a + b);
            auto mi = upper_bound(v.begin() + j + 1, v.end(), d);
            ans += ma - mi;
        }
    }

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


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

int main()
{
    ll N;
    cin >> N;
    vector<ll> H(N);
    rep(i, N) cin >> H[i];

    ll mi = 0;
    int ans = 0;
    for (ll h : H)
    {
        if (mi <= h)
        {
            mi = h;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
int main()
{
  int n;
  scanf("%d", &n);
  int a[n], cnt = 0, num = 1;
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &a[i]);
    if (num != a[i])
      cnt++;
    else if (num == a[i])
      num++;
  }
  if (cnt == n)
    printf("-1");
  else
    printf("%d", cnt);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

const int m = 2019;

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

	string s;
	cin >> s;
	int n = s.size();
	reverse(all(s));
	int x = 1, tot = 0;
	vector<int> cnt(m);
	ll ans = 0;
	rep(i, n) {
		cnt[tot]++;
		tot += (s[i] - '0') * x;
		tot %= m;
		ans += cnt[tot];
		x = x * 10 % m;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3748
#include<cstdio>
#include<iostream>
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
int n,c[N],m=1,dp[N],num[N];
inline void Add(int &x,int y){x+=y;x-=x>=mod? mod:0;x+=x<0? mod:0;}
inline int MOD(int x,int y){x+=y;x-=x>=mod? mod:0;x+=x<0? mod:0;return x;}
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)scanf("%d",&c[i]);
	for(register int i=2;i<=n;i++)if(c[i]-c[i-1])c[++m]=c[i];
	dp[0]=1;
	for(register int i=1;i<=m;i++)
		dp[i]=MOD(dp[i-1],num[c[i]]),Add(num[c[i]],dp[i-1]);
	printf("%d\n",dp[m]);
	return 0;
}

Measured memory_bytes: 2560
function Main(input) {
    inputs = input.split(/\n/)
    const N = i(inputs[0])
    const K = i(inputs[1])
    const X = inputs[2].split(' ')
    const ans = X.reduce(function(sum, x, y){
        if(Math.abs(K - i(x)) < x){
            return sum + Math.abs(K - i(x)) * 2
        } else {
            return i(sum) + i(x) * 2
        }
    }, 0)
    console.log(ans)
}
function i(x){ return parseInt(x, 10)}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500