akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

struct Edge {
	int from, to;
	Edge(int f, int t) {
		from = f;
		to = t;
	}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

vector<int> kosaraju(const Graph& g) {
	int n = g.size(), sz = 0;
	Graph rg(n);
	vector<int>stk, cmp(n, -1), added(n), visited(n), ord(n);
	for (auto &es : g) {
		for (auto &e : es)rg[e.to].emplace_back(e.to, e.from);
		sz += es.size();
	}
	stk.resize(n + sz);
	sz = 0;
	for (int i = 0; i<n; ++i) {
		if (visited[i])continue;
		int s = 0;
		stk[s++] = i;
		while (s != 0) {
			int v = stk[s - 1];
			visited[v] = true;
			bool pushed = false;
			for (auto &e : g[v]) {
				int to = e.to;
				if (!visited[to]) {
					stk[s++] = to;
					pushed = true;
				}
			}
			if (pushed)continue;
			int t = stk[s - 1];
			if (!added[t]) {
				added[t] = true;
				ord[n - ++sz] = t;
			}
			--s;
		}
	}
	int k = 0;
	for (int &u : ord) {
		if (cmp[u] != -1)continue;
		int s = 0;
		stk[s++] = u;
		while (s != 0) {
			int v = stk[--s];
			cmp[v] = k;
			for (auto &e : rg[v]) {
				int t = e.to;
				if (cmp[t] == -1)stk[s++] = t;
			}
		}
		++k;
	}
	return cmp;
}

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(7);
	int N;
	while (cin >> N, N) {
		vector<double> p(N);
		Graph G(N), rG(N);
		Edges es;
		for (int i = 0, m; i < N; i++) {
			cin >> p[i];
			cin >> m;
			for (int j = 0, a; j < m; j++) {
				cin >> a; a--;
				G[i].emplace_back(i, a);
				rG[a].emplace_back(a, i);
				es.emplace_back(i, a);
			}
		}
		auto v = kosaraju(G);
		int V = 0;
		for (int i = 0; i < N; i++) {
			V = max(V, v[i] + 1);
		}
		Graph rDAG(V);
		vector<double> pri(V, 1.0);
		for (int i = 0; i < N; i++) {
			pri[v[i]] *= p[i];
		}
		for (auto e : es) {
			if (v[e.from] != v[e.to]) {
				rDAG[v[e.to]].emplace_back(v[e.to], v[e.from]);
			}
		}
		double res = 1.0;
		for (int i = 0; i < V; i++) {
			if (rDAG[i].empty()) {
				res *= 1.0 - pri[i];
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n;
  cin >> n;
  bool ok = true;
  map<string, int> mp;
  char last = ' ';
  REP(i, n){
    string w;
    cin >> w;
    if(last == ' '){
      last = w.back();
      mp[w]++;
      continue;
    }
    if(mp[w] != 0 || last != w[0]) ok = false;
    last = w.back();
    mp[w]++;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(){
    string S, T;
    cin >> S >> T;
    int N = S.size();
    if(T.substr(0,N) == S) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

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

//const ll mod = 1000000007;
const ll mod = 998244353;

template<int MOD> class Fp {
    ll val;
public:
    constexpr Fp(ll v = 0) noexcept : val(v % MOD) {
        if(val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator- () const noexcept { return val ? MOD - val : 0; }
    constexpr Fp operator+ (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator- (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator* (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator/ (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator+= (const Fp& r) noexcept {
        val += r.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator-= (const Fp& r) noexcept {
        val -= r.val;
        if(val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator*= (const Fp& r) noexcept {
        (val *= r.val) %= MOD;
        return *this;
    }
    constexpr Fp& operator/= (const Fp& r) noexcept {
        ll a = r.val, b = MOD, u = 1, v = 0;
        while(b){
            ll t = a/b;
            a -= t*b; swap(a, b);
            u -= t*v; swap(u, v);
        }
        (val *= u) %= MOD;
        if(val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator== (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator!= (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    constexpr bool operator> (const Fp& r) const noexcept {
        return this->val > r.val;
    }
    constexpr bool operator< (const Fp& r) const noexcept {
        return this->val < r.val;
    }
    friend constexpr ostream& operator<< (ostream &os, const Fp<MOD>& x){
        ll tmp = x.val;
        os << tmp;
        return os;
    }
    friend constexpr istream& operator>> (istream &is, const Fp<MOD>& x){
        ll tmp;
        is >> tmp;
        x = Fp<MOD>(tmp);
        return is;
    }
    constexpr Fp<MOD> modpow(ll n) noexcept {
        if(n == 0) return 1;
        auto t = modpow(n>>1);
        t *= t;
        if(n & 1) t *= *this;
        return t;
    }
};
using mint = Fp<mod>;

int main(){
    ll n, m = -1; cin >> n;
    vector<ll> a(100005, 0), b(n);
    rep(i, n){
        cin >> b[i];
        a[b[i]]++;
        m = max(m, b[i]);
    }
    rep(i, n){
        if(b[0] != 0 || (i != 0 && b[i] == 0)){
            cout << 0 << endl;
            return 0;
        }
    }
    mint sum(1);
    rep(i, m+1){
        if(i < 2) continue;
        sum *= mint(a[i-1]).modpow(a[i]);
        if(a[i] == 0) sum *= 0;
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 4844
package main

import (
  "fmt"
)

func main() {
  var x, n, tmp, min, max int
  fmt.Scanf("%d %d", &x, &n)
  target := make([]int, n)

  if n == 0 {
    fmt.Println(x)
  } else {

    for i := 0; i < n; i++ {
      fmt.Scanf("%d", &tmp)
      target[i] = tmp
    }

    for j := x; j >= 0; j--{
      isMin := true
      for _, v := range target {
        if j == v {
          isMin = false
          break
        }
      }

      if isMin {
        min = j
        break
      }
    }

    for k := x; k <= 101; k++ {

      isMax := true
      for _, v1 := range target {
        if k == v1 {
          isMax = false
          break
        }
      }

      if isMax {
        max = k
        break
      }
    }
    if x - min > max - x {
      fmt.Println(max)
    } else {
      fmt.Println(min)
    }
  }
}


Measured memory_bytes: 1824
#include <iostream>
#include <cassert>
//#define NDEBUG
int main(void){
	using namespace std;
	static const int MAX_NUM_OF_DATASETS = 10000;
	int case_cnt = 1;
	int input_num = 0;

    /* Output "Case x: input" */
	do{
		cin >> input_num;

		if(input_num == 0){
			break;
		}
		else{
			cout << "Case " << case_cnt << ": " << input_num << endl;
		}
		case_cnt++;
	}while(case_cnt <= MAX_NUM_OF_DATASETS);
	return 0;
}




Measured memory_bytes: 3076
const main = (inputs) => {
  const word = inputs[0];
  var flag = true;
  for (var i = 0; i < word.length; i++) {
    var count = 0;
    if (i % 2 === 0 && word[i] === 'h') {
      count = count + 1;
    }
    if (i % 2 === 1 && word[i] === 'i') {
      count = count + 1;
    }
    if (count === 0) {
      flag = false;
      break;
    }
  }
  if (flag && word.length % 2 === 0) {
    console.log('Yes');
  } else {
    console.log('No');
  }
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    string s;
    cin >> s;
    lint ans = 0;
    for(int i = 0 ; i < (1 << s.size()-1) ; i++){
        lint cnt = 0, tmp = 0;
        for(int j = 0 ; j < s.size()-1 ; j++){
            tmp *= 10;
            tmp += s[j] - '0';
            if(i >> j & 1){
                cnt += tmp;
                tmp = 0;
            }
        }
        tmp *= 10;
        tmp += s[s.size()-1] - '0';
        cnt += tmp;
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())

a = [0] * (m + 1)
b = [0] * (m + 1)
road = [[] for _ in range(n + 1)]

for i in range(m):
    a[i], b[i] = map(int, input().split())
    road[a[i]].append(b[i])
    road[b[i]].append(a[i])

ans = [-1] * (n + 1)
ans[0] = 0
ans[1] = 0

q = deque()
q.appendleft(1)

while len(q):
    i = q.pop()
    for j in road[i]:
        if ans[j] == -1:
            ans[j] = i
            q.appendleft(j)

if ans.count(-1) != 0:
    print("No")
    exit()
else:
    print("Yes")
    print(*ans[2:], sep="\n")



Measured memory_bytes: 101900
n = int(input())
l = list(map(int, input().split()))
count = 0
for i in range(n):
  for j in range(n):
    for k in range(n):
      if(i != j and i != k and j != k):
        if(l[i] != l[j] and l[i] != l[k] and l[j] != l[k]):
          t = [l[i], l[j], l[k]]
          t.sort()
          if(t[2] < t[1]+t[0]):
            count += 1
          
print(count//6)

Measured memory_bytes: 9208
N=input()
a=map(int, raw_input().split())
#print N
#print a

b=[]
for i in range(1,len(a)+1):
	#print i,a[i-1]
	if i==a[i-1]:
		b.append(a[i-1])
#print b
cnt=0
for j in range(len(b)):
	if b[j]==0:
		continue
	if j<len(b)-1:
		if b[j+1]-b[j]==1:
			cnt+=1
			b[j]=0
			b[j+1]=0
			#print b
			continue
	if b[j]!=0:
		cnt+=1
		b[j]=0
		#print b


print cnt

Measured memory_bytes: 11328
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int K;
  cin >> K;
  int cnt = 0;
  while(a>=b) {
    b *= 2;
    cnt++;
  }
  while(b>=c) {
    c *= 2;
    cnt++;
  }
  if(cnt<=K) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

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

  int p, q;
  while(cin >> p >> q){
    set<int> amari;
    vector<int> seq;
    map<int, int > amarinoketa;
    int f = -1, s = -1;
    int keta = 0;
    while(1){
      seq.push_back(p/q);
      int am = p%q;
      if(am == 0) break;
      if(amarinoketa.find(am) != amarinoketa.end()){
	f = amarinoketa[am];
	s = keta;
	break;
      }else{
	amarinoketa[am] = keta;
      }
      p = (p%q) * 10;
      keta++;
    }
    if(f == s && f == -1){
      for(size_t i = 1; i < seq.size(); i++){
	cout << seq[i];
      }
      cout << endl;
    }else{
      for(size_t i = 1; i < seq.size(); i++){
	cout << seq[i];
      }
      cout << endl;
      for(size_t i = 0; i < seq.size()-1; i++){
	if(i >= (size_t)f){
	  cout << '^';
	}else{
	  cout << ' ';
	}
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1228
# i番目に食べた料理はAi
# 料理iを食べると満足度Biを得る
# 料理iを食べた直後に料理(i+1)を食べると追加で満足度Ciを得る

N = int(input())
A = list(map(int, input().split()))  # A1~AN
B = list(map(int, input().split()))  # B1~BN
C = list(map(int, input().split()))  # C1~C(N-1)

satisf = sum(B)

for i in range(N-1):
    if A[i+1]-A[i] == 1:
        satisf += C[A[i]-1]

print(satisf)


Measured memory_bytes: 3060
def palindrome(sz):
    N = len(sz)
    sL = sz[:int((N-1)/2)]
    sR = sz[int(N+1)/2:]
    palin = (list(sL) == list(reversed(sR)))
    palinL = (list(sL) == list(reversed(sL)))
    palinR = (list(sR) == list(reversed(sR)))
    return (palin and palinL and palinR)

S = raw_input().rstrip("\r\n")
if palindrome(S):
    print("Yes\n")
else:
    print("No\n")


Measured memory_bytes: 2568
S = input()
T = input()
l = len(S)
s,t = [], []
for i in "abcdefghijklmnopqrstuvwxyz":
  tmps,tmpt = [], []
  for j in range(l):
    if S[j] == i:
      tmps.append(j)
    if T[j] == i:
      tmpt.append(j)
  s.append(tmps)
  t.append(tmpt)
s.sort()
t.sort()
if s == t:
 print("Yes")
else:
 print("No")

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

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;

    string before = S.substr(0,S.size()/2);
    // cout << before << "\n";
    string after = S.substr(S.size()/2);
    // cout << after << "\n";

    if (before == after) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}


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

int main()
{
    std::int64_t K;
    std::cin >> K;

    if(K % 2 == 0)
    {
        std::cout << "-1" << std::endl;
        return 0;
    }

    if(K % 7 == 0)
    {
        K /= 7;
    }

    if(K == 1)
    {
        std::cout << "1" << std::endl;
        return 0;
    }

    std::vector<std::optional<std::int64_t>> mods(K, std::nullopt);

    mods.at(1) = 1;
    std::int64_t curr_mod = 1;
    std::int64_t curr_p10 = 1;
    for(std::size_t i=2; i<=K; ++i)
    {
        const auto dif = curr_p10 * 10 % K;
        curr_p10 *= 10;
        curr_p10 %= K;

        curr_mod += dif;
        curr_mod %= K;

        if(mods.at(curr_mod))
        {
            break;
        }
        else
        {
            mods.at(curr_mod) = i;
        }
    }

    if(mods.at(0))
    {
        std::cout << *mods.at(0) << std::endl;
    }
    else
    {
        std::cout << "-1" << std::endl;
    }


    return 0;
}


Measured memory_bytes: 18780
#include <bits/stdc++.h>
using namespace std;
//ACGT AGC ACG GAC
int main()
{
	int64_t n, mod = 1000000007;
	cin >> n;

	int64_t dp[n + 1][4][4][4]{};
	for (int j = 0; j < 4; j++)
	{
		for (int k = 0; k < 4; k++)
		{
			for (int l = 0; l < 4; l++)
			{
				if (j == 0 && k == 2 && l == 1)
				{
					continue;
				}
				if (j == 0 && k == 1 && l == 2)
				{
					continue;
				}
				if (j == 2 && k == 0 && l == 1)
				{
					continue;
				}
				dp[3][j][k][l] = 1;
			}
		}
	}

	for (int i = 3; i < n; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			for (int k = 0; k < 4; k++)
			{
				for (int l = 0; l < 4; l++)
				{
					for (int m = 0; m < 4; m++)
					{

						if (k == 0 && l == 2 && m == 1)
						{
							continue;
						}
						if (k == 0 && l == 1 && m == 2)
						{
							continue;
						}
						if (k == 2 && l == 0 && m == 1)
						{
							continue;
						}
						if (j == 0 && l == 2 && m == 1)
						{
							continue;
						}
						if (j == 0 && k == 2 && m == 1)
						{
							continue;
						}
						(dp[i + 1][k][l][m] += dp[i][j][k][l]) %= mod;
					}
				}
			}
		}
	}

	int64_t ans = 0;
	for (int j = 0; j < 4; j++)
	{
		for (int k = 0; k < 4; k++)
		{
			for (int l = 0; l < 4; l++)
			{
				(ans += dp[n][j][k][l]) %= mod;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
<?php
    $s = fgets(STDIN);
    $ans = 0;
	$ans += min($s,9);
    if($s>99){
      $ans += min(900,$s-99);
    }
	if($s>9999){
      $ans += min(90000,$s-9999);
    }
	echo $ans;
?>

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

#define endl "\n"

typedef long long ll;
typedef pair <ll, ll> pii;
typedef long double ld;

const ll D = 100007;
const ll Inf = 1000000007;
ll n,m,k;
ll a,b,c;
ll v[D];
ll ans,ans2;
ll gs(ll a,ll b){
ll c=a,d=b;
while(c!=0&&d!=0){
    if(c>d)c%=d;else d%=c;
}

return (c+d);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>v[i];
    }
    ans=v[1];

    ll l=2;ll r=n;
    while(l!=r){
            a=gs(ans,v[l]);
            b=gs(ans,v[r]);
        if(a>b){ans=a;l++;}
        if(a<=b){ans=b;r--;}
       // if(a==b){ans=a;l++;r--;};
    }



    ans2=v[n];

    l=1;r=n-1;
    while(l!=r){
            a=gs(ans2,v[l]);
            b=gs(ans2,v[r]);
      //  cout<<a<<' '<<b<<endl;
        if(a>b){ans2=a;l++;}
        if(a<=b){ans2=b;r--;}
        //if(a==b){ans=a;l++;r--;};
    }
    cout<<max(ans,ans2);


    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan =new Scanner(System.in);
		String a=scan.next();
			if(a.charAt(2)==a.charAt(3)&&a.charAt(4)==a.charAt(5)) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}

Measured memory_bytes: 22996
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;
#define toInt(_char) _char - '0'

using namespace std;
//
// Created by karayuu on 2018-12-18.
//

int main() {
    string s;
    cin >> s;
    
    int count  = 0;
    FOR(i, 0, 3) {
        if (s[i] == '1') count++;
    }
    
    P(count);
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	int n;
  	cin >> n;
  	vll ans(n,0);
  	int c, s, f;
	rep(i,n-1){
      	cin >> c >> s >> f;
      	rep3(j,0,i){
      		if(ans[j]<s) ans[j] = s;
          	else if((ans[j]-s)%f != 0) ans[j] += f - ((ans[j]-s)%f);
      		ans[j] += c;
        }
    }
	rep(j,n) cout << ans[j] << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll n, t, a, h[1000];

int main(int argc, char **argv) {
	cin >> n >> t >> a;
	REP(i, n) cin >> h[i];
	ll d = INF, res = 0;
	REP(i, n) if (abs(t * 1000 - h[i] * 6 - a * 1000) < d) {
		d = abs(t * 1000 - h[i] * 6 - a * 1000);
		res = i;
	}
	cout << (res+1) << endl;
	return 0;
}


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

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

    if(s.size() <= k){
        cout << s << endl;
    }

    else{
        for(int i=0; i<k; i++){
            cout << s.at(i);
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

int N,H,W;
int X1[1000],X2[1000],Y1[1000],Y2[1000];
int fld[2002][2002],dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};

int compress(int *x1,int *x2,int w){
  vector<int>xs;

  for(int i=0;i<N;i++){
      int tx1=x1[i],tx2=x2[i];
      if(1<=tx1 && tx1<w)xs.push_back(tx1);
      if(1<=tx2 && tx2<w)xs.push_back(tx2);
  }
  xs.push_back(0);
  xs.push_back(w);
  sort(xs.begin(),xs.end());
  xs.erase(unique(xs.begin(),xs.end()),xs.end());
  for(int i=0;i<N;i++){
    x1[i]=find(xs.begin(),xs.end(),x1[i])-xs.begin();
    x2[i]=find(xs.begin(),xs.end(),x2[i])-xs.begin();
  }
  return xs.size()-1;
}

int bfs(void){

  int ans=0;

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(fld[i][j])continue;
      ans++;
      queue<pair<int,int> >que;
      que.push(make_pair(j,i));
      while(!que.empty()){
	int nx=que.front().first,ny=que.front().second;
	que.pop();

	for(int i=0;i<4;i++){
	  int tx=nx+dx[i],ty=ny+dy[i];
	  if(tx<0 || W<tx || ty<0 || H<ty || fld[ty][tx]>0)continue;
	  que.push(make_pair(tx,ty));
	  fld[ty][tx]=1;
	}
      }
    }
  }
  return ans;
}

int main(void){

  while(cin >> W >> H,W|H){
    cin >> N;
    for(int i=0;i<N;i++)
      cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
    
    fill(fld[0],fld[2002],0);
    
    W=compress(X1,X2,W);
    H=compress(Y1,Y2,H);
    
    for(int i=0;i<N;i++){
      fld[Y1[i]][X1[i]]++;
      fld[Y1[i]][X2[i]]--;
      fld[Y2[i]][X1[i]]--;
      fld[Y2[i]][X2[i]]++;
    }
    
    for(int i=0;i<H;i++){
      for(int j=1;j<W;j++){
	fld[i][j]+=fld[i][j-1];      
      }
    }
    
    for(int i=1;i<H;i++){
      for(int j=0;j<W;j++){
	fld[i][j]+=fld[i-1][j];
      }
    }
    cout << bfs() << endl;
  }
  return 0;
}

Measured memory_bytes: 16900
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int n;

	scanf("%d", &n);

	vector<int> arr;

	for (int i = 0; i < n; i++)
	{
		int input;

		scanf("%d", &input);

		arr.push_back(input);
	}

	int cnt = 0;

	for (int i = 0; i < n; i++)
	{
		if (arr[i] == cnt + 1)
		{
			cnt = arr[i];
		}
	}

	if (cnt == 0)
	{
		printf("%d\n", -1);
	}

	else
	{
		printf("%d\n", n - cnt);
	}

	return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main()
{
         long long c=0,i,n,f=0,b=0;
         cin>>n;
         for(i=1;i<=n;i++)
        {
           b+=i;
           if((i%3)==0 || (i%5)==0) {f+=i;
           }
         }

         cout<<b-f<<endl;
}


Measured memory_bytes: 3636
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,h[100005]={},cnt=0,ans=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> h[i];
  }
  for(int i=0; i<n-1; i++) {
    if(h[i]>=h[i+1]) {
      cnt++;
      ans=max(ans,cnt);
    }
    else {
      cnt=0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;


ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    x %= mod;
    return (x * powll(y,mod-2)) % mod;
}

int main() {
    ll n;
    cin >> n;
    VL a(n);
    REP(i,n) a[i] = lin();
    int m = 61;
    VL cnt(m);
    REP(i,n){
        REP(b,m){
            if ((a[i] >> b) & 1) cnt[b]++;
        }
    }
    ll ans = 0;
    REP(i,n){
        REP(b,m){
            ll x = (1LL << b) % mod;
            if ((a[i] >> b) & 1){
                ans = (ans + (n - cnt[b]) * x) % mod;
            }else{
                ans = (ans + cnt[b] * x) % mod;
            }
        }
    }
    ans = divll(ans, 2);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    vec A = {1, 3, 5, 7, 8, 10, 12};
    vec B = {4, 6, 9, 11};
    vec C = {2};
    map<ll, ll> G;
    for(auto a : A) G[a] = 1;
    for(auto b : B) G[b] = 2;
    for(auto c : C) G[c] = 3;

    ll x, y;
    cin >> x >> y;
    if(G[x] == G[y]) print("Yes");
    else print("No");

    return 0;
}

Measured memory_bytes: 256
def LI(): return list(map(int, input().split()))

n = int(input())
h = LI()

dp = [0] * n
dp[0], dp[1] = 0, abs(h[1] - h[0])
for i in range(2, n):
    dp[i] = min(
        dp[i-1] + abs(h[i] - h[i-1]),
        dp[i-2] + abs(h[i] - h[i-2])
    )

print(dp[-1])


Measured memory_bytes: 13928
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
void solve(){
  int n , m ;
  cin >> n >> m ;
  vector < pair < ll , ll > > a(n);
  for( int i = 0 ; i < n ; i++) cin >> a[i].ff >> a[i].ss ;
  sort(st(a));
  ll ans = 0 ;
  for( int i = 0 ; i < n ; i++){
        if(m>a[i].ss){
            m-=a[i].ss;
            ans+=a[i].ss*a[i].ff;
        }
        else{
            ans+=m*a[i].ff;
            break;
        }
  }
  cout << ans ;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


Measured memory_bytes: 1792
ashiba_num = gets.to_i
ashiba_cost = gets.split(' ').map(&:to_i)

dP = []
dP[0] = 0
dP[1] = (ashiba_cost[1] - ashiba_cost[0]).abs

range = 2..ashiba_num - 1 
range.each do |move|
    comp1 = dP[move - 1] + (ashiba_cost[move] - ashiba_cost[move - 1]).abs
    comp2 = dP[move - 2] + (ashiba_cost[move] - ashiba_cost[move - 2]).abs

    comp1 >= comp2 ? dP[move] = comp2 : dP[move] = comp1

end

p dP.last

Measured memory_bytes: 8908
def main():
    n = int(input())
    A = list(map(int, input().split()))

    res_list = [0] * 100001

    for num in A:
        res_list[num] += 1
        
        if num != 0:
            res_list[num-1] += 1
        if num != 10**5:
            res_list[num+1] += 1
    
    print(max(res_list))

if __name__ == '__main__':
    main()

Measured memory_bytes: 13964
/*   Abhijith  */
#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define	endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
     ios;
     lld n;
     cin>>n;
     vector<vector<lld> > v(n+1,vector<lld>(3)),dp(n+1,vector<lld>(3,0));
     rep(i,1,n)
     {
         cin>>v[i][0]>>v[i][1]>>v[i][2];
     }
     rep(i,1,n)
     {
         rep(j,0,2)
         {
             rep(k,0,2)
             {
                 if(j==k)
                    continue;
                 dp[i][j]=max(dp[i][j],dp[i-1][k]+v[i][j]);
             }
         }
     }
     cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
    return 0;
}


Measured memory_bytes: 11136
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        System.out.println(calc(N));
        sc.close();
        return;
    }

    static String calc(long N) {
        if (N == 0) {
            return "";
        }
        N--;
        return calc(N / 26) + _char((int) (N % 26));
    }

    static String _char(int N) {
        String moji = "";
        switch (N) {
            case 0:
                moji = "a";
                break;
            case 1:
                moji = "b";
                break;
            case 2:
                moji = "c";
                break;
            case 3:
                moji = "d";
                break;
            case 4:
                moji = "e";
                break;
            case 5:
                moji = "f";
                break;
            case 6:
                moji = "g";
                break;
            case 7:
                moji = "h";
                break;
            case 8:
                moji = "i";
                break;
            case 9:
                moji = "j";
                break;
            case 10:
                moji = "k";
                break;
            case 11:
                moji = "l";
                break;
            case 12:
                moji = "m";
                break;
            case 13:
                moji = "n";
                break;
            case 14:
                moji = "o";
                break;
            case 15:
                moji = "p";
                break;
            case 16:
                moji = "q";
                break;
            case 17:
                moji = "r";
                break;
            case 18:
                moji = "s";
                break;
            case 19:
                moji = "t";
                break;
            case 20:
                moji = "u";
                break;
            case 21:
                moji = "v";
                break;
            case 22:
                moji = "w";
                break;
            case 23:
                moji = "x";
                break;
            case 24:
                moji = "y";
                break;
            case 25:
                moji = "z";
                break;
        }
        return moji;
    }
}


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

using namespace std;

int main()
{
    int n,a,b;
    cin >> n  >> a >> b;
    int sum=(b-a)-1;
    if(sum%2)
        cout << "Alice" << endl;
    else
        cout << "Borys" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
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);
}


#define ARRAY_MAX 100005
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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




/******************************************************************************************/

ll sum[200005];


int main() {

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

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

	for (int i = 1; i <= n; i++)
	{
		sum[i] = sum[i - 1] + a[i - 1];
	}
	
	ll ans = 1LL << 60;


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

		int low = 0, high = i;
		while (high - low > 1) {
			int mid = (low + high) / 2;
			if (sum[mid] >= sum[i] - sum[mid]) high = mid;
			else low = mid;
		}
		ll P = sum[low];
		ll Q = sum[i] - sum[low];
		ll P2 = sum[high];
		ll Q2 = sum[i] - sum[high];
		ll left_min = min(P, Q);
		ll left_max = max(P, Q);
		if (abs(P2 - Q2) < abs(P - Q)) {
			left_min = min(P2, Q2), left_max = max(P2, Q2);
		}

		low = i, high = n;
		while (high - low > 1) {
			int mid = (low + high) / 2;
			if (sum[mid] - sum[i] >= sum[n] - sum[mid]) high = mid;
			else low = mid;
		}
		ll R = sum[low] - sum[i];
		ll S = sum[n] - sum[low];
		ll R2 = sum[high] - sum[i];
		ll S2 = sum[n] - sum[high];
		ll right_min = min(R, S);
		ll right_max = max(R, S);
		if (abs(R2 - S2) < abs(R - S)) {
			right_min = min(R2, S2), right_max = max(R2, S2);
		}

		ans = min(ans, max(left_max, right_max) - min(left_min, right_min));

	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 2560
//package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        int t=1;
        //t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            int k=scan.nextInt();
            int[] f=new int[n];
            for(int i=0;i<k;i++){
                int d=scan.nextInt();
                for(int j=0;j<d;j++){
                    int di=scan.nextInt();
                    f[di-1]++;
                }
            }
            int v=0;
            for(int i=0;i<n;i++){
                if(f[i]==0){
                    v++;
                }
            }
            out.println(v);
        }
        out.flush();
        out.close();
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


Measured memory_bytes: 33908
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL dp[51][51][2501];
int main()
{
	//freopen("In.txt" , "r" , stdin);
	int N , A;
	cin >> N >> A;
	vector<int> a(N);
	for(auto &x : a)
		cin >> x;
	dp[0][0][0] = 1;
	for(int i = 0; i < N; i++)
	{
		for(int picked = 0; picked <= i; picked++)
		{
			for(int sum = 0; sum <= i * 50; sum++)
			{
				dp[i + 1][picked + 1][sum + a[i]] +=
				dp[i][picked][sum];
				dp[i + 1][picked][sum] += dp[i][picked][sum];
			}
		}
	}
	LL ans = 0;
	for(int picked = 1; picked <= N; picked++)
		ans += dp[N][picked][picked * A];
	cout << ans;
	return 0;
}


Measured memory_bytes: 49024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int ans[5];

int main(){
  int n,m; cin >> n >> m;
  rep(i,n) ans[i]=-1;
  rep(i,m){
    int s; cin >> s; s--;
    int c; cin >> c;
    if(n!=1&&(s==0&&c==0)){
      cout << -1 << endl;
      return 0;
    }
    else if(ans[s]==-1||ans[s]==c) ans[s]=c;
    else{
      cout << -1 << endl;
      return 0;
    }
  }
  string s;
  rep(i,n){
    if(ans[i]!=-1) s+=to_string(ans[i]);
    else if(n!=1&&i==0) s+='1';
    else s+='0';
  }
  cout << s << endl;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int cnt1 = 0, cnt2 = 0;
    while (cin >> s){
        for (int i = 0; i < s.size(); i++) {
            if (s.substr(i, 3) == "JOI") { cnt1++; }
            else if (s.substr(i, 3) == "IOI") { cnt2++; }
        }
        cout << cnt1 << endl << cnt2 << endl;
        cnt1=0,cnt2=0;
    }
    return 0;
}


Measured memory_bytes: 3252
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] numMonsters = new int[N+1];
		int[] capasityHero = new int[N];		
		for(int i=0;i<N+1;i++) {
			numMonsters[i] = sc.nextInt();
		}		
		for(int i=0;i<N; i++) {
			capasityHero[i] = sc.nextInt();
		}
		
		long sum = 0;
		for(int i=0;i<N;i++) {
			sum += Math.min(numMonsters[i], capasityHero[i]);
			int extra = Math.max(0, capasityHero[i] - numMonsters[i]);
			sum += Math.min(numMonsters[i+1], extra);
			numMonsters[i+1] =  Math.max(0, numMonsters[i+1] - extra);
		}
		
		System.out.println(sum);
		
		sc.close();	
	}
 
}

Measured memory_bytes: 80744
X,K,D = [int(x) for x in input().split()]
X = abs(X)
a = X//D
if a >= K:
    print(X-K*D)
    exit()
else:
    K = K-a
if K % 2 == 0:
    print(X%D)
else:
    print(D-X%D)

Measured memory_bytes: 9176
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int a[200005];
 
int32_t main()
{
    fast;
    int n, sum = 0; cin >> n;
    Rep(i, 1, n) {
        cin >> a[i];
        sum += a[i];
    }

    int minx = sum, s = 0;
    Rep(i, 1, n) {
        s += a[i];
        minx = min(minx, abs(s - (sum - s)));
    }

    cout << minx << "\n";
    
    return 0;
}

Measured memory_bytes: 5184
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <set>

using namespace std;

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

int n;
bool exist[10];
int pos[10][2];
double total;
int path;

double get_dis(int u, int v) {
    double xd = pos[u][0] - pos[v][0];
    double yd = pos[u][1] - pos[v][1];
    return sqrt(xd * xd + yd * yd);
}

void dfs(int u, int depth, double dis) {
    if (depth == n) {
        total += dis;
        ++path;
        return;
    }

    for (int v = 0; v < n; ++v) {
        if (!exist[v]) {
            double len = u == -1 ? 0 : get_dis(u, v);
            exist[v] = true;
            dfs(v, depth + 1, dis + len);
            exist[v] = false;
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &pos[i][0], &pos[i][1]);
    }

    memset(exist, false, sizeof(exist));
    total = 0;
    path = 0;
    dfs(-1, 0, 0);
    printf("%.7lf\n", total / path);
    return 0;
}



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

int main() {
    int n, m, a, b;
    cin >> n >> m;
    vector<int> c_loads(n, 0);
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        c_loads.at(a-1) += 1;
        c_loads.at(b-1) += 1;
    }

    for (int i = 0; i < n; i++) {
        cout << c_loads.at(i) << endl;
    }
}


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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int n;
	
	cin >> n;
	
	int ans = 0;
	int l , r;
	
	while(n--) {
		cin >> l >> r;
		
		ans += r - l +1;
	}
	
	cout << ans;
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[200010];
    rep(i, N) cin >> a[i];
    rep(i, N) a[i]--;
    int b[200010];
    rep(i, N) b[a[i]] = i;
    multiset<int> st;
    st.insert(-1); st.insert(-1);
    st.insert(N); st.insert(N);
    int ans = 0;
    RREP(i, N - 1, 0) {
        int idx = b[i];
        auto itrL2 = (--(--st.lower_bound(idx)));
        auto itrL1 = --st.lower_bound(idx);
        auto itrR1 = st.lower_bound(idx);
        auto itrR2 = ++st.lower_bound(idx);
        //ans += (i + 1) * (*itr - idx) * (idx - *itr2);
        //cerr << idx << " " << *itr << " " << *itr2 << endl;
        ans += (i + 1) * (*itrL1 - *itrL2) * (*itrR1 - idx);
        ans += (i + 1) * (idx - *itrL1) * (*itrR2 - *itrR1);
        //cerr << *itrL2 << " " << *itrL1 << " " << idx << " " << *itrR1 << " " << *itrR2 << endl;
        st.insert(idx);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9812
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }

class BIT {
private:
	int size;
	vector<int> bit;
	
public:
	BIT(int n = 0):size(n), bit(n + 1, 0) {}
	
	void add(int i, int x) {
		while(i <= size) {
			bit[i] += x;
			i += i & -i;
		}
	}

	int sum(int i) const {
		int s = 0;
		while(i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
};

class BIT2D {
private:
	int size;
	vector<BIT> bit;
public:
	BIT2D(int w = 0, int h = 0):size(w), bit(w + 1, BIT(h)) {};

	void add(int x, int y, int v) {
		while(x <= size) {
			bit[x].add(y, v);
			x += x & -x;
		}
	}

	int sum(int x, int y) const {
		int s = 0;
		while(x > 0) {
			s += bit[x].sum(y);
			x -= x & -x;
		}
		return s;
	}
};

#define group first
#define r_power second
const int MAX = 33;

int h, w, s;
int lower;
pair<int, int> memo[MAX][MAX][MAX][MAX];
BIT2D bit;

inline int calc_sum(int sx, int sy, int tx, int ty) {
	return bit.sum(tx, ty) - bit.sum(sx, ty) - bit.sum(tx, sy) + bit.sum(sx, sy);
}

pair<int, int> dfs(int sx, int sy, int tx, int ty) {
	if(memo[sx][sy][tx][ty].group != 0)
		return memo[sx][sy][tx][ty];

	const int demand = calc_sum(sx, sy, tx, ty);
	if(demand < lower)
		return memo[sx][sy][tx][ty] = make_pair(-1, -1);

	pair<int, int> res = make_pair(1, demand - lower);

	for(int i = sx + 1; i < tx; ++i) {
		const pair<int, int> a = dfs(sx, sy, i, ty), b = dfs(i, sy, tx, ty);
		if(a.group == -1 || b. group == -1)
			continue;

		chmax(res, make_pair(a.group + b.group, min(a.r_power, b.r_power)));
	}

	for(int i = sy + 1; i < ty; ++i) {
		const pair<int, int> a = dfs(sx, sy, tx, i), b = dfs(sx, i, tx, ty);
		if(a.group == -1 || b. group == -1)
			continue;

		chmax(res, make_pair(a.group + b.group, min(a.r_power, b.r_power)));
	}

	return memo[sx][sy][tx][ty] = res;
}

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

	while(cin >> h >> w >> s, h) {
		bit = BIT2D(w, h);
		for(int i = 0; i < h; ++i) {
			for(int j = 0; j < w; ++j) {
				int u;
				cin >> u;
				bit.add(j + 1, i + 1, u);
			}
		}

		lower = bit.sum(w, h) - s;
		fill(memo[0][0][0], memo[0][0][0] + MAX*MAX*MAX*MAX, make_pair(0, 0));
		const pair<int, int> ans = dfs(0, 0, w, h);
		cout << ans.group << " " << ans.r_power << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 10524