akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  int C[N], S[N], F[N];
  for(int i=0; i<N-1; ++i){
    int c, s, f;
    cin >> c >> s >> f;
    C[i] = c;
    S[i] = s;
    F[i] = f;
  }
  for(int i=0; i<N-1; ++i){
    int t = 0;
    for(int j=i; j<N-1; ++j){
      if(S[j] > t) t = S[j];
      else if(t%F[j] != 0) t += F[j] - t%F[j];
      t += C[j];
    }
    cout << t << "\n";
  }
  cout << 0 << "\n";
  return 0;  
}



Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N, K;
vector<int> V;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  V.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }

  int ans = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      int sum = 0;
      if (i + j > min(N, K)) {
        continue;
      }
      int r = min(i + j, K - i - j);

      priority_queue<int, vector<int>, greater<int>> pq;
      for (int k = 0; k < i; k++) {
        sum += V[k];
        pq.push(V[k]);
      }
      for (int k = 0; k < j; k++) {
        sum += V[N - k - 1];
        pq.push(V[N - k - 1]);
      }

      for (int k = 0; k < r; k++) {
        int n = pq.top();
        pq.pop();
        if (n < 0) {
          sum -= n;
        }
      }

      ans = max(ans, sum);
    }
  }

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

Measured memory_bytes: 256
n,a,b=map(int,input().split())

def digit_sum(s):
    s = str(s)
    return sum([int(s[i]) for i in range(len(s))])
  
cnt=0
for i in range(1,n+1):
    if a<=digit_sum(i)<=b: cnt+=i
print(cnt)

Measured memory_bytes: 42988
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
import queue
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Prim(g):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v.keys()))
    V = list(set(V))

    used = set([])
    q = []
    heapq.heappush(q, (0, V[0]))

    ret = 0
    while q:
        c, v = heapq.heappop(q)

        if v in used:
            continue
        used.add(v)
        ret += c
        for u in g[v]:
            heapq.heappush(q, (g[v][u], u))
    return ret


@mt
def slv(S):
    even = len(S) % 2 == 0
    hte = S[0] == S[-1]
    if even != hte:
        return 'Second'
    return 'First'


def main():
    S = read_str()

    print(slv(S))


if __name__ == '__main__':
    main()


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

int main(){
    string s;
    cin >> s;
    
    ll ans = 0;
    for(ll i = 0;i < s.size();i++)ans += s[i]-'0';
    if(ans % 9 == 0)cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3752
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

int min(int a, int b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

int avd_i(int a, int b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

int main() {

	int N, l[1005], r[1005], ans = 0;

	cin >> N;
	for (int i = 0; i < N; i++) {

		cin >> l[i] >> r[i];

		ans += r[i] - l[i] + 1;

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramA
    {
        static void Main()
        {
            int p = NextInt, q = NextInt, r = NextInt;
            System.Console.WriteLine(Math.Min(Math.Min(p + q, q + r), r + p));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 13268
N= int(input())
ab = [list(map(int,input().split())) for i in range(N)]
cd = [list(map(int,input().split())) for i in range(N)]
alr = [False for i in range(N)]
ab.sort()
cd.sort()
count = 0
for c,d in cd:
    maxi = -1
    maxb = -1
    for i in range(N):
        if alr[i]:
            continue
        a,b = ab[i][0],ab[i][1]
        if a < c:
            if b < d:
                if maxb < b:
                    maxb = b
                    maxi = i
        else:
            break
    if maxi != -1:
        alr[maxi] = True
print(alr.count(True))

Measured memory_bytes: 3064
from collections import deque

s = input()
q = int(input())

queue = deque(list(s))
is_reverse = False

for _ in range(q):
    tfc = input()
    if tfc[0] == '1':
        is_reverse = not is_reverse
        continue
    else:
        if is_reverse == False and tfc[2] == '1':
            queue.appendleft(tfc[4])
        elif is_reverse == False and tfc[2] == '2':
            queue.append(tfc[4])
        elif is_reverse == True and tfc[2] == '1':
            queue.append(tfc[4])
        elif is_reverse == True and tfc[2] == '2':
            queue.appendleft(tfc[4])

if is_reverse:
    ans = list(queue)
    new_ans = ans[::-1]
    print(*new_ans, sep='')
else:
    ans = queue
    print(*ans, sep='')


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

int main() {
	int a,b;
	string operand;
	cin >> a >> b;
	if (a > b) operand = " > ";
	else if (a<b) operand = " < ";
	else operand = " == ";
	
	cout << "a" << operand << "b" << endl;
	return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

int main() {
	IN(int, n);
	vector<int> x(n);
	cin >> x;
	
	int ans = 1e9;
	inc1(p, 100) {
		int s = 0;
		inc(i, n) {
			s += (p - x[i]) * (p - x[i]);
		}
		setmin(ans, s);
	}
	OUT(ans);
}


Measured memory_bytes: 256
N = int(input())
A_list = list(map(int, input().split()))
two_list = [2 ** i for i in range(32)]

count = 0
items = {}
for a in A_list:
    if a in items.keys():
        items[a] += 1
    else:
        items[a] = 1
A_list.sort(reverse=True)
import bisect

for a in A_list:
    if items[a] >= 1:
        index = bisect.bisect_left(two_list, a)
        for t in two_list[index:]:
            m = t - a
            if m in items.keys():
                if m == a and items[a] >= 2:
                    count += 1
                    items[a] -= 2
                    break

                elif m != a and items[m] >= 1 and items[a] >= 1:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break
print(count)


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

int main(){
    int N;
    int64_t L, X[300000], T[300000];
    cin >> N >> L;
    for(int i=0; i<N; i++) cin >> X[i];
    for(int i=0; i<N; i++) cin >> T[i];

    int64_t C = N;
    bitset<300000> l, r;
    for(int i=0; i<N; i++){
        int64_t c = (T[i]-1) / (2*L);
        C += c;
        T[i] -= c * 2 * L;
        r[i] = (T[i] <= 2*(L-X[i]));
        l[i] = (T[i] <= 2*X[i]);
    }
    if(r[N-1] == 0) C++;

    int cl = 0, clr = 0;
    for(int i=0; i<N-1; i++){
        if(l[i] && r[i]){
            if(cl > 0){
                C--;
                cl--;
            }else{
                clr++;
            }
        }else if(l[i]){
            cl++;
        }else if(r[i]){
            if(cl > 0){
                C--;
                cl--;
            }else if(clr > 0){
                C--;
                clr--;
            }
        }
    }
    C -= clr/2;

    int64_t ans = C * 2 * L;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main (void){
  int H[100], W[100], i = 0, j, x, y;

  while(1){
    scanf("%d %d", &H[i], &W[i]);
    if(H[i] == 0 && W[i] == 0) break;
    i++;
  }



  for(j = 0; j < i; j++){
    for(y = 1; y < H[j] + 1; y++){
      for(x = 1; x < W[j] + 1; x++){
        if((x + y) % 2 == 0){
          printf("#");
        } else {
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 1788
let N = Int(readLine()!)!

var num: [Int: Int] = [:]
for a in readLine()!.split(separator: " ").map({Int($0)!}) {
    num[a] = (num[a] ?? 0) + 1
}

var res: Int = 0
for (a, aNum) in num {
    res += aNum < a ? aNum : aNum - a
}
print(res) // (๑•ૅㅁ•๑)

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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a'){
    cout << "vowel" << endl;
  }
  else if (c == 'i'){
    cout << "vowel" << endl;
  }
  else if (c == 'u'){
    cout << "vowel" << endl;
  }
  else if (c == 'e'){
    cout << "vowel" << endl;
  }
  else if (c == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1];}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const objvs =(a)=>{const b=[];for(const v in a){b.push(a[v])}return b};
const main=()=>{
  let o={}
  let n=tn()
  let na=tss(n)
  for(let i=0;i<n;i++)o[na[i]]=0
  let m=tn()
  let ma=tss(m)
  for(let i=0;i<m;i++)o[ma[i]]=0
  for(let i=0;i<n;i++)o[na[i]]+=1
  for(let i=0;i<m;i++)o[ma[i]]-=1
  to(max(...objvs(o))<0?0:max(...objvs(o)))
}
main()


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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int main(){
  string S;
  cin >> S;
  int N = S.size();
  int ans = 0;;
  int c = 0;
  REPR(i, N-1){
    int x = S[i] - '0';
    if((x+c) > 5){
      ans += 10 - (x+c);
      c = 1;
    }
    else if((x+c) == 5){
      if(i > 0 && S[i-1] >= '5'){
        ans += 10 -(x+c);
        c= 1;
      }
      else{
        ans += (x+c);
        c = 0;
      }
    }
    else{
      ans+= x+c;
      c = 0;
    }
  }
  ans += c;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1412
#pragma warning (disable :4996)
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-12;
#define For(i,n,m) for(int i=n;i<=m;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,l,r) for(int i=l;i>=r;--i)
#define clr(a,b) memset(a,b,sizeof(a))

ll n, cnt;
ll a[200100];
ll x[200100], y[200100];
map<ll, vector<int> > s;
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin >> n;
	rep(i, 1, n) {
		cin >> a[i];
		x[i] = a[i] + i;
		if (i - a[i] > 0)	s[i - a[i]].push_back(i);
	}
	rep(i, 1, n) {
		if (s[x[i]].size()) {
	//		cout << i << " " << x[i] << " " << s[x[i]].size() << "\n";
			cnt += s[x[i]].size();
		}
	}
	cout << cnt << "\n";
	
	
	return 0;
}

Measured memory_bytes: 25288
fn main() {
    let n = read::<u32>();
    println!("{}", n * (n + 1) / 2);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import os
from collections import Counter

import itertools
import math
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]

zero = 0
A = []
B = []
for a, b in AB:
    if a == b == 0:
        zero += 1
    elif a == 0:
        A.append(0)
        B.append(1)
    elif b == 0:
        A.append(1)
        B.append(0)
    else:
        if a < 0:
            a = -a
            b = -b
        g = math.gcd(a, b)
        A.append(a // g)
        B.append(b // g)

ab = [(a, b) for a, b in zip(A, B)]
ba = [(b, a) for a, b in zip(A, B)]

counts = Counter(ba)
ans = 1
nandemo = 0
seen = set()
for (a, b), cnt in Counter(ab).items():
    cc = counts[-a, b] + counts[a, -b]
    if cc == 0:
        nandemo += cnt
    else:
        if not ((a, -b) in seen or (-a, b) in seen):
            seen.add((b, a))
            seen.add((-b, -a))
            ans *= pow(2, cnt, MOD) + pow(2, cc, MOD) - 1
            ans %= MOD

ans *= pow(2, nandemo, MOD)
ans += zero
ans -= 1
ans %= MOD
print(ans)


def test():
    ans = 0
    for choices in itertools.product([True, False], repeat=N):
        iwasi = []
        for i, c in enumerate(choices):
            if c:
                iwasi.append(AB[i])
        ok = True
        for (a, b), (c, d) in itertools.combinations(iwasi, r=2):
            ok &= a * c + b * d != 0
        if ok:
            print(iwasi)
        ans += ok
    print(ans - 1)


# test()


Measured memory_bytes: 171436
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,a,b = LI()
    ans = 0
    for i in range(1,n+1):
        if a <= sum(map(int, str(i))) <= b:
            ans += i
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 41068
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int ans[N];
vector<pii> g[N];

void dfs(int n, int p, int color) {
    int c = 1;
    for (auto i : g[n]) {
        if (i.fi == p) continue;
        if (c == color) c++;
        ans[i.se] = c;
        dfs(i.fi, n, c);
        c++;
    }
}

signed main(){
    IOS;
    int n;
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        g[a].pb({b, i});
        g[b].pb({a, i});
    }
    dfs(1, -1, -1);
    cout << *max_element(ans + 1, ans + n) << endl;
    for (int i = 1; i < n; i++)
        cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 8704
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, m, X[1005], Y[1005], mx = 0, isodd = -1, d[35];
char dirs[35], dir;

signed main(){
	getint(N);
	for(register int i = 1; i <= N; i++){
		getint(X[i]), getint(Y[i]), mx = max(mx, abs(X[i]) + abs(Y[i]));
		if(isodd == -1) isodd = (X[i] ^ Y[i]) & 1;
		else if(isodd != ((X[i] ^ Y[i]) & 1)) return puts("-1"), 0;
	}
	for(m = d[1] = 1; (1LL << m) <= mx; m++) d[m + 1] = 1 << m;
	if(!isodd) d[++m] = 1;
	sort(d + 1, d + m + 1), dirs[m] = '\0', printf("%d\n", m);
	for(register int i = 1; i <= m; i++) printf("%d ", d[i]); puts("");
	for(register int k = 1; k <= N; k++){
		register ll x = 0, y = 0;
		for(register int i = m; i; i--){
			register ll mn = inf, cur, nx, ny;
			if((cur = llabs(x + d[i] - X[k]) + llabs(y - Y[k])) < mn) mn = cur, dir = 'R', nx = x + d[i], ny = y;
			if((cur = llabs(x - d[i] - X[k]) + llabs(y - Y[k])) < mn) mn = cur, dir = 'L', nx = x - d[i], ny = y;
			if((cur = llabs(x - X[k]) + llabs(y + d[i] - Y[k])) < mn) mn = cur, dir = 'U', nx = x, ny = y + d[i];
			if((cur = llabs(x - X[k]) + llabs(y - d[i] - Y[k])) < mn) mn = cur, dir = 'D', nx = x, ny = y - d[i];
			dirs[i - 1] = dir, x = nx, y = ny;
		}
		puts(dirs);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;

int main() {
  int n,m;cin>>n>>m;
  vector<string> a(n),b(m);
  rep(i,n) cin>>a[i];
  rep(i,m) cin>>b[i];

  bool ans = false;
  rep(i,n-m+1) rep(j,n-m+1) {
    bool all = true;
    rep(k,m) rep(l,m) {
      if (a[i+k][j+l] != b[k][l]) all = false;
    }
    if (all) ans = true;
  }
  cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
l = []
for i in range(M):
  p, y = list(map(int, input().split()))
  l.append([i+1, p, y, ""])
l = sorted(l, key=lambda x: x[2])

cnt = [1]*(N+1)
for i in range(M):
  l[i][3] = str(l[i][1]).zfill(6) + str(cnt[l[i][1]]).zfill(6)
  cnt[l[i][1]] += 1

l = sorted(l, key=lambda x: x[0])
for i in range(M):
  print(l[i][3])

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

int main(void) {
  int N;
  cin >> N;

  vector<long long> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  cout << accumulate(p.begin(), p.end(), 0) -
              (*max_element(p.begin(), p.end())) / 2
       << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    int n,m;
    cin>>n>>m;
    cout<<(n*(n-1)/2)+(m*(m-1)/2)<<endl;
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (ll i=0; i<n; i++)
#define	Rep1(i, n)	for (ll i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	ll M, K;
	cin >>M >>K;
	if (0==M) {
		if (0!=K) {
			cout <<-1 <<endl;
			return 0;
		}
		cout <<"0 0" <<endl;
		return 0;
	}
	if (1==M) {
		if (0!=K) {
			cout <<-1 <<endl;
			return 0;
		}
		cout <<"0 0 1 1" <<endl;
		return 0;
	}
	if (K>=(1<<M)) {
		cout <<-1 <<endl;
		return 0;
	}
	cout <<K;
	Rep0(i, 1<<M)
		if (i!=K)
			cout <<' ' <<i;
	cout <<' ' <<K;
	for (ll i=(1<<M)-1; i>=0; i--)
		if (i!=K)
			cout <<' ' <<i;
	cout <<endl;
	return 0;
}



Measured memory_bytes: 1792
N, K = list(map(int, input().split()))
d = []
A = []
for _ in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))

all_A = []

for _1 in A:
    for _2 in _1:
        all_A.append(_2)

all_A = set(all_A)
print(N - len(all_A))

Measured memory_bytes: 9184
MOD = 10**9 + 7
def ketadp3(a, b):
    L = len(a)

    dp = [[[0 for i in range(2)] for j in range(b)] for k in range(L + 1)]
    dp[0][0][0] = 1
    for i in range(L):
        D = int(a[i])
        for k in range(b):
            for j in range(2):
                for d in range(10 if j else D+1):
                    dp[i + 1][(k + d) % b][j or (d < D)] += dp[i][k][j]
                    dp[i + 1][(k + d) % b][j or (d < D)] %= MOD

    print((dp[L][0][0] + dp[L][0][1] - 1) % MOD)


def main():
    n = input()
    d = int(input())
    ketadp3(n, d)


if __name__ == '__main__':
    main()

Measured memory_bytes: 130140
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{

    class Program
    {
        private const long COMDIV = 1000000007;

        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            Console.WriteLine(x == 0 ? 1 : 0);
        }
    }
}

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

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

int main() {
	long long int n, k;
	cin >> n >> k;

	long long int caluvalue;
	caluvalue = n /k;
	long long int comA, comB;
	comA = abs(n - caluvalue*k);
	comB = abs(comA - k);

	long long int ans;
	ans = min(comA, comB);

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

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

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, M; in(N); in(M);

  pii BA[M];
  rep(i, M) {
    in(BA[i].second);
    in(BA[i].first);
  }
  sort(BA, BA+M);
  reverse(BA, BA+M);
  int left = 0, right = N;
  int ans = 1;
  rep(i, M) {
    if (BA[i].first <= left) {
      ++ans;
      left = BA[i].second;
      right = BA[i].first;
    } else {
      right = BA[i].first;
      left = max(left, BA[i].second);
    }
  }
  out(ans);

  return 0;
}


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

int main(){
   int h, r;
   cin>>h>>r;
   if( - h - r < 0 ) cout<<"1"<<endl;
   if( - h - r > 0 ) cout<<"-1"<<endl;
   if( h + r == 0 ) cout<<"0"<<endl;

   return 0;
}


Measured memory_bytes: 3100
from collections import Counter
n, p = map(int, input().split())
c = []
if p == 1:
    print(1)
    exit()
if n == 1:
    print(p)
    exit()
for i in range(2, int(p**0.5)+1):
    while p % i == 0:
        c.append(i)
        p /= i
c = Counter(c)
ans = 1
for key in c.keys():
    if c[key] >= n:
        ans *= int(key) ** (c[key]//n)
print(ans)

Measured memory_bytes: 3316
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

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

const int N = 100000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int n, m, a[N], b[N], fen[N];
vector<pii> P;

int minu(int a, int b){
	a -= b;
	if (a < 0) a += MOD;
	return a;
}

int add(int a, int b){
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

bool cmp(pii x, pii y){
	if (x.F == y.F) return x.S < y.S;
	return x.F > y.F;
}

void ADD(int id, int x){
	for (; id < N; id += id & (-id)) fen[id] = add(fen[id], x);
}

int Get(int id){
	int res = 0;
	for (; id > 0; id -= id & (-id))  res = add(res, fen[id]);
	return res;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= m; i++) cin >> b[i];
	vi tah;
	for (int i = 1; i <= n; i++){
		int x = lower_bound(b + 1, b + m + 1, a[i]) - b - 1;
		if (x == 0) continue;
		int y = upper_bound(b + 1, b + m + 1, a[i]) - b;
		if (y == m + 1) continue; 
		P.pb({a[i] - b[x], b[y] - a[i]});
		tah.pb(b[y] - a[i]);
	}
	sort(all(tah));
	tah.resize(unique(all(tah)) - tah.begin());
	for (int i = 0; i < P.size(); i++){
		pii u = P[i];
		int x = lower_bound(all(tah), u.S) - tah.begin() + 1;
		P[i].S = x;
	}
	ADD(N - 1, 1);
	sort(all(P));
	P.resize(unique(all(P)) - P.begin());
	sort(all(P), cmp);
	for (int i = 0; i < P.size(); i++){
		pii u = P[i];
		int x = minu(Get(N - 1), Get(u.S));
		ADD(u.S, x);
	}
	cout << Get(N - 1);





	return 0;
}


Measured memory_bytes: 2932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a7=1000000007;
ll inf=100000000000000000;

int main()
{
  ll n;cin>>n;
  bool flag=0;
  for(ll i=1;i<=9;i++){
    for(ll j=i;j<=9;j++){
      if(i*j==n){
        flag=1;break;
      }
    }
  }
  if(flag==0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int e;
  while(cin>>e,e){
    int m=INF;
    REP(y,1001){
      REP(z,101){
        if(e-y*y-z*z*z>=0){
          int x=e-y*y-z*z*z;
          m=min(m,x+y+z);
        }
      }
    }
    cout<<m<<endl;
  }
  return 0;
}



Measured memory_bytes: 3032
# ABC081C - Not so Diverse (ARC086C)
from collections import Counter


def main():
    N, K, *A = map(int, open(0).read().split())
    C = list(Counter(A).values())
    C.sort(reverse=1)
    ans = sum(C[K:])
    print(ans)


if __name__ == "__main__":
    main()

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

int main(){
    int n;
    cin >> n;
    vector<int> as(n);
    for (int i = 0; i < n; i++){
        cin >> as[i];
    }
    for (int i = 0; i < 31; i++){
        sort(as.begin(), as.end());
        for (int i = 0; i < n - 1; i++){
            as[i + 1] = as[i + 1] - as[i] * (as[i + 1] / as[i]);
            if (as[i + 1] == 0){
                as[i + 1] = as[i];
            } 
        }
    }
    cout << as[0] << endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }

    static Scanner cin;

    void calc()
    {
        int N = cin.nextInt();
        int[] A = cin.ArrayInt(N);

        int CountWrong = 0;

        for (int i = 0; i < N; i++)
        {
            if (A[i] != i + 1) CountWrong++;            
        }

        if(CountWrong == 0 || CountWrong == 2)
        {
            Console.WriteLine("YES");
        }
        else Console.WriteLine("NO");
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include<unordered_map>
/*
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*    ▀▀       ▀▀▀▀▀▀    ▀     ▀▀▀▀▀▀      ▀    ▀
*   ▀  ▀      ▀         ▀     ▀            ▀  ▀
*  ▀    ▀     ▀ ▀ ▀     ▀     ▀ ▀ ▀         ▀
* ▀ ▀▀▀▀ ▀    ▀         ▀     ▀             ▀
*▀        ▀   ▀         ▀     ▀             ▀
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*/
using namespace std;
void afify()
{
	ios::sync_with_stdio(0);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
#define ll long long
#define ld long double
#define mk make_pair
#define loop(i,intial,n)  for(int i=int(intial);i<n;i++)
#define loopn(j,n) for(int j=int(n-1);j>=0;j--)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(v) v.begin(),v.end()
///////////////////////////////////////
#define SCD(a) scanf("%d",&a)
#define SCD2(a,b) scanf("%d %d",&a,&b)
#define SCLL(a) scanf("%lld",&a)
#define SCLL2(a,b) scanf("%lld %lld",&a,&b)
#define PRD(a) printf("%d\n",a)
#define PRLL(a) printf("%lld\n",a)
///////////////////////////////////////
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vi> vvi;
typedef vector <vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;
typedef stringstream ss;
const ll oo = (ll) 10e9 + 7;
const double EPS = 1e-4;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//ifstream ifs("input.txt");
//ofstream ofs("output.txt");
int main()
{
	afify();
	int n;
	string s;
	cin >> n>> s;
	int res = 0;
	int l = 0, r = 0;
	loopn(i, n) {
		if (s[i] == '(' && l == 0) {
			r++;
		}
		if (s[i] == '(' && l > 0) {
			l--;
		}
		if (s[i] == ')') {
			l++;
		}
	}
	loop(i, 0, l) {
		s.insert(s.begin(), '(');
	}
	loop(i, 0, r) {
		s.push_back(')');
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include "boost/multiprecision/cpp_int.hpp"
using ll = long long;
using ull = unsigned long long;
namespace mp = boost::multiprecision;

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);

	int H, W; std::cin >> H >> W;

	std::vector<std::string> table(H);

	for (auto& s : table) {
		std::cin >> s;
	}

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

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {

			if (table[i][j] == '#')continue;

			int num = 0;

			for (int k = 0; k < 8; k++) {
				int tmpx = j + dx[k];
				int tmpy = i + dy[k];
				if (tmpx < 0 || tmpx >= W)continue;
				if (tmpy < 0 || tmpy >= H)continue;
				if (table[tmpy][tmpx] == '#')num++;
			}

			table[i][j] = char(num + '0');

		}

		std::cout << table[i] << std::endl;
	}

	return 0;

}

Measured memory_bytes: 256
x = int(input())
if x <= 599:
  print(8)
elif x <= 799:
  print(7)
elif x <= 999:
  print(6)
elif x <= 1199:
  print(5)
elif x <= 1399:
  print(4)
elif x <= 1599:
  print(3)
elif x <= 1799:
  print(2)
else:
  print(1)


Measured memory_bytes: 9168
#if __has_include("noamoa_atcoder_lib.h")
#include "noamoa_atcoder_lib.h"
#else
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) (x).begin(),(x).end()
namespace atcoder {
	using namespace std;
	using ll = long long;
	using intv = vector<int>;
	using charv = vector<char>;
	using boolv = vector<bool>;
	using floatv = vector<float>;
	using doublev = vector<double>;
	using stringv = vector<string>;

	constexpr ll MOD  = 1000000007;
	constexpr ll MOD9 = 1000000009;

	template<typename T>
	void sort(vector<T>& v){
		sort(all(v));
	}
	template<typename T>
	void sortInv(vector<T>& v){
		sort(all(v), greater<T>());
	}

	template<typename T>
	T sum(const vector<T>& v){
		T ret = 0;
		for(const auto& e : v) ret += e;
		return ret;
	}

	template<typename T>
	inline vector<T>& operator+=(vector<T>& v, const T& e){
		v.push_back(e);
		return v;
	}

	template<typename T>
	void in(vector<T>& v){
		for(auto& e : v) cin >> e;
	}

	template<typename T>
	istream& operator>>(istream &stream, vector<T>& v){
		for(auto& e : v) stream >> e;
		return stream;
	}

	template<typename T>
	void out(const vector<T>& v){
		for(const auto& e : v) cout << e << ' ';
		cout << endl;
	}

	template<typename T>
	void outln(const vector<T>& v){
		for(const auto& e : v) cout << e << endl;
	}

	void init(){
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}
using namespace atcoder;
#endif

int main(){
	init();
	string s;
	cin>>s;
	cout <<((s[0]=='7'|s[1]=='7'||s[2]=='7')?"Yes":"No");
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <map>
using namespace std;

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;
}

int main() {
	int n, x; cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	vector<int> res(n);
	for (int i = 0; i < n; i++) {
		res.at(i) = a.at(i);
	}
	if (a.at(0) > x) {
		res.at(0) = x;
	}
	for (int i = 0; i < n - 1; i++) {
		if (res.at(i) + a.at(i + 1) > x) {
			res.at(i + 1) = x - res.at(i);
		}
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += a.at(i) - res.at(i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,x,y;
  cin >> N;
  vector<int> card(N);
  for (int i=0; i<N; i++) {
    cin >> card[i];
  }
  sort (card.begin(),card.end());
  for (int i=0; i<N; i+=2) {
    if (N % 2 == 0) {
    x += card[i+1];
    y += card[i];
    }
    else {
      x += card[i];
      y += card[i+1];
    }
  }
  cout << x-y << endl;
}

Measured memory_bytes: 256
N,D = map(int,input().split())
b = [input().split() for l in range(N)]
count = 0
for i in range(N):
    y = b[0]
    del b[0]
    for j in range(len(b)):
        x = 0
        for k in range(D):
            x += (int(y[k]) - int(b[j][k]))**2
        if (x**.5)%1 == 0:
            count+=1
print(count)

Measured memory_bytes: 3188
#include <iostream>
using namespace std;
 
int main()
{
  while(true)
  {
    int h, w;
    cin >> h >> w;
    if ( h == 0 && w == 0) return 0;
    for (int i=0; i<h; i++)
    {
      for (int j=0; j<w; j++)
      {
        cout << ((i+j)%2 == 0 ? '#' : '.') << flush;
      }
      cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int c = s.nextInt();
        for(int i = 0; i < c; ++i) {
            ArrayList<Integer> p = new ArrayList<Integer>();
            for(int j = 0; j < 3; ++j) {
                p.add(s.nextInt());
            }
            Collections.sort(p);
            System.out.println(((Math.pow(p.get(0), 2) + Math.pow(p.get(1), 2)) == Math.pow(p.get(2), 2))?"YES":"NO");
        }
    }
}

Measured memory_bytes: 23364
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
template<typename T>
class Fenwick {
private:
  int n;
  vector<T> bit;
public:
  Fenwick() : n(-1) {}
  Fenwick(int n_, T d = T()) : n(n_), bit(n + 1, d) {}

  inline void add(int i, T val) {
    if (i == 0) return;
    for (int x = i; x <= n; x += (x & -x)) bit[x] += val;
  }

  // [1, i);
  inline T get(int i) {
    T res = T();
    for (int x = i; x > 0; x -= (x & - x)) res += bit[x];
    return res;
  }

  // return [i, j);
  inline T get(int i, int j) {
    return get(j - 1) - get(i - 1);
  }

  inline int lower_bound(int val) {
    if (val <= 0) return 0;
    int x = 0, r = 1;
    while (r < n) r <<= 1;
    for (int k = r; k > 0; k >>= 1) {
      if (x + k <= n && bit[x + k] < val) {
        val -= bit[x + k];
        val += k;
      }
    }
    return x + 1;
  }

  const T& operator[](const int &i) const {
    return bit[i];
  }
};
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //c
  int n;
  cin >> n;
  Fenwick<int> bit(n + 10);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (bit.get(a) == 0) ans++;
    bit.add(a, 1);
  }
  cout << ans << '\n';
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  ll a, b;
  cin >> a >> b;
  auto f = [](ll n)
  {
    bool ret = true;
    string s = to_string(n);
    ret &= (s[0] == s[4]);
    ret &= (s[1] == s[3]);
    return ret;
  };
  int ans = 0;
  for(ll i = a; i <= b; ++i)
  {
    if(f(i))ans++;
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3784
//たてなが

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
const int inf = 2147483647;

int main (){
    int h,w;cin>>h>>w;
    rep(i,0,h){
        string s;cin>>s;
        cout << s << endl;
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;

int main()
{   int n;
    cin>>n;
    if(n<1200)  cout<<"ABC";
	else if(n>=1200 && n<2800)  cout<<"ARC";
	else cout<<"AGC"; 
	return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input, marker::Chars};

#[fastout]
fn main() {
    input! {
        mut s: Chars,
    }

    if *s.last().unwrap() == 's' {
        s.push('e');
    }
    s.push('s');

    let ans = s.into_iter().collect::<String>();
    
    println!("{}", ans);
}


Measured memory_bytes: 2188
#include<bits/stdc++.h>
using namespace std;
#define LL long long

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	int a[n];
	int b[1000001] = {};
	int count = 0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		b[a[i]]++;
	}
	int c = 1;
	// keisan
	int ans = 1;
	for(int i=2;i<=1000000;i++){
		int tmp = 0;
		for(int j=1;i*j<=1000000;j++){
			tmp += b[i*j];
		}
		if(tmp > 1){
			c = 0;
		}
		ans = max(ans,tmp);
	}
	if(c){
		cout << "pairwise coprime" << endl;
	}else if(ans == n){
		cout << "not coprime" << endl;
	}else{
		cout << "setwise coprime" << endl;
	}
	// syutsuryoku
}

Measured memory_bytes: 11412
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 12:11:12 2020

@author: shinba
"""

n = int(input())

a = map(int,input().split())

two = 0
four = 0

b = []

for i in a:
    if i % 2 == 0:
        b.append(i//2)

for i in b:
    if i % 2 == 0:
        four += 1
    else:
        two += 1

if two == 0:
    if n <= 2*four +1:
        print("Yes")
    else:
        print("No")
else:
    if n - two <= 2*four:
        print("Yes")
    else:
        print("No")

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

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

using namespace std;

int main(){
	int n,L; cin>>n>>L;
	int a[100000];
	rep(i,n) cin>>a[i];

	rep(i,n-1) if(a[i]+a[i+1]>=L) {
		cout<<"Possible"<<endl;
		rep(j,i) cout<<j+1<<endl;
		for(int j=n-2;j>=i;j--) cout<<j+1<<endl;
		return 0;
	}
	cout<<"Impossible"<<endl;

	return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>

int multi(int n){
	int max=0,x,tmp;
	x=10;
	while(x<=n){
		tmp=(n/x)*(n%x);
		if(tmp>max){
			max=tmp;
		}
		x*=10;
	}
	return max;
}

int main(void){
	int q,i,r,tmp,cnt;
	scanf("%d",&q);
	for(i=0;i<q;i++){
		cnt=0;
		scanf("%d",&r);
		while(r>=10){
			tmp=multi(r);
			if(tmp==r){
				printf("-1\n");
				break;
			}
			r=tmp;
			cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int x, a, b;

int main() {
	cin >> x >> a >> b;
	if (a-b>=0) cout << "delicious" << ln;
	else if (b-a<=x) cout << "safe" << ln;
	else cout << "dangerous" << ln;
}

Measured memory_bytes: 256