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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    int N,W; cin >> N >> W;
    vector<int> v(N+1),w(N+1);
    for(int i = 1; i <= N; ++i) cin >> v[i] >> w[i];
    vector<vector<int>> dp(N+1,vector<int>(W+1,0));
    dp[0][0] = 0;
    for(int i = 1; i <= N; ++i) {
        for(int j = 0; j <= W; ++j) {
            if(j + w[i]<=W)chmax(dp[i][j+w[i]],dp[i-1][j]+v[i]);
            chmax(dp[i][j],dp[i-1][j]);
        }
    }
    cout << *max_element(ALL(dp[N])) << endl;
    return 0;
}



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

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

Measured memory_bytes: 3092
# cf. https://rion778.hatenablog.com/entry/2019/03/10/004006
import sys
input = sys.stdin.readline
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m < M:
      buy = min(M - m, plices[i][1])
      cost += plices[i][0] * buy
      m += buy
    else:
      break

print(cost)

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

using ll = long long;
using namespace std;

bool Compare(pair<int,int>a, pair<int, int> b){
        return a.second < b.second;
};
vector<pair<int , int > > v;

int main() {
    int n, m, count = 0, maximum = 0;
    cin >> n >> m;
    v.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(),v.end(), Compare);
    for (int j = 0; j < m; ++j) {
        if (v[j].first >= maximum){
            maximum = v[j].second;
            count++;
        }
    }
    cout << count << "\n";
}

Measured memory_bytes: 1024
using System;

class C
{
	static void Main()
	{
		var words = new[] { "dream", "dreamer", "erase", "eraser" };
		var s = Console.ReadLine();
		Console.WriteLine(Dfs(0) ? "YES" : "NO");

		bool Dfs(int i)
		{
			foreach (var w in words)
			{
				if (!Contains(s, i, w)) continue;
				var ni = i + w.Length;
				if (ni == s.Length || Dfs(ni)) return true;
			}
			return false;
		}
	}

	static bool Contains(string s, int si, string w)
	{
		for (int j = 0; j < w.Length; j++)
			if (si + j >= s.Length || s[si + j] != w[j]) return false;
		return true;
	}
}


Measured memory_bytes: 18136
#include<iostream>
int main(void){
  //入力部
  int H,W;
  std::cin >> H >> W;
  std::string space[H*W];
  for (int i=0;i<H;i++){
    std::cin >> space[i];
  }
  //座標の差分
  const int dx[8] = {-1,0,1,-1,1,-1,0,1};
  const int dy[8] = {-1,-1,-1,0,0,1,1,1};
  //爆弾の個数の計測
  for (int i=0;i<H;i++){
    for (int j=0;j<W;j++){
      if (space[i][j] == '#') continue;
      int ct = 0;
      for (int d=0;d<8;d++){
        const int di = i + dy[d];
        const int dj = j + dx[d];
        if (di<0 || di>H) continue;
        if (dj<0 || dj>W) continue;
        if (space[di][dj] == '#'){
          ct++;
        }
      }
      space[i][j] = char(ct+'0');
    }
  }
  //表示
  for (int i=0;i<H;i++){
    for (int j=0;j<W;j++){
      std::cout << space[i][j];
    }
    std::cout << std::endl;
  }
  return 0;
}

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

const int CITY_NUM = 200000;
int road[CITY_NUM + 1];
int train[CITY_NUM + 1];

int pRoad(int n) {
    if (road[n] == n) {
        return n;
    }
    int p = pRoad(road[n]);
    road[n] = p;
    return p;
}
int pTrain(int n) {
    if (train[n] == n) {
        return n;
    }
    int p = pTrain(train[n]);
    train[n] = p;
    return p;
}

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

    rep(i, CITY_NUM + 1) {
        road[i] = i;
        train[i] = i;
    }

    rep(i, K) {
        int a, b;
        cin >> a >> b;
        int pa = pRoad(a);
        int pb = pRoad(b);
        if (pa < pb) {
            road[pb] = pa;
        } else if (pa > pb) {
            road[pa] = pb;
        }
    }
    rep(i, L) {
        int a, b;
        cin >> a >> b;
        int pa = pTrain(a);
        int pb = pTrain(b);
        if (pa < pb) {
            train[pb] = pa;
        } else if (pa > pb) {
            train[pa] = pb;
        }
    }

    //------------
    map<pair<int, int>, int> counts;
    loop(i, 1, N + 1) {
        int r = pRoad(i);
        int t = pTrain(i);
        auto p = make_pair(r, t);
        if (counts.find(p) == counts.end()) {
            counts[p] = 1;
        } else {
            counts[p] = counts[p] + 1;
        }
    }
    loop(i, 1, N + 1) {
        int r = pRoad(i);
        int t = pTrain(i);
        auto p = make_pair(r, t);
        int c = counts[p];
        cout << c;
        if (i < N) {
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 13696
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
s1 = [0]*(n+1)
s2 = [0]*(n+1)
s1[0] = 0
s1[1] = a[0]
s2[0] = 0
s2[n] = a[n-1]
for i in range(2, n+1):
    s1[i] = gcd(s1[i-1], a[i-1])
    s2[n-i+1] = gcd(s2[n-i+2], a[n-i])
if s1[n-1] >= s2[2]:
    ans = s1[n-1]
else:
    ans = s2[2]
for i in range(2, n):
    b = gcd(s1[i-1], s2[i+1])
    if ans <= b:
        ans = b
print(ans)

Measured memory_bytes: 89580
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion


LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 



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

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

	int n;
	cin >> n;
	vi a(n);
	f(i, 0, n) {
		cin >> a[i];
		a[i] -= i;
	}
	sort(all(a));
	int ans = 0;
	f(i, 0, n / 2) {
		ans += abs(a[n - 1 - i] - a[i]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
using System;

public class Hello
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine().Trim());
        if (n == 0) { Console.WriteLine(0); goto end; }
        var ans = "";
        while (true)
        {
            if (n % (-2) == 0)
            {
                ans += "0";
                n /= (-2);
            }
            else
            {
                ans += "1";
                n = (n - 1) / (-2);
            }
            if (n == 1) { ans += "1";  break; }
            if (n == 0) break;
        }
        for (int i = 0; i < ans.Length; i++)
        {
            Console.Write(ans[ans.Length - 1 - i]);
        }
        Console.WriteLine();
        end:;
    }
}

Measured memory_bytes: 13140
N = int(input())
S = input()

dic = {'R':0, 'G':0, 'B':0}
for i in range(N):
  dic[S[i]] += 1

ans = dic['R'] * dic['G'] * dic['B']

for i in range(N):
  for j in range(i+1, N):
    if 2*j - i < len(S):
      if S[i] == 'R' and S[j] == 'G' and S[2*j - i] == 'B':
        ans -= 1

      if S[i] == 'R' and S[j] == 'B' and S[2*j - i] == 'G':
        ans -= 1

      if S[i] == 'G' and S[j] == 'R' and S[2*j - i] == 'B':
        ans -= 1

      if S[i] == 'G' and S[j] == 'B' and S[2*j - i] == 'R':
        ans -= 1
      
      if S[i] == 'B' and S[j] == 'G' and S[2*j - i] == 'R':
        ans -= 1

      if S[i] == 'B' and S[j] == 'R' and S[2*j - i] == 'G':
        ans -= 1

print(ans)

  

Measured memory_bytes: 68540
#include<bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
bool sortbysec(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
}
int main() 
{  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n,l;
        cin>>n;
        vector<pair<ll,ll>>v;
        for(int i=0;i<n;i++)
        {
            ll a,b;
            cin>>a>>b;
            v.push_back(make_pair(a,b));
            if(b<a)
            {
                cout<<"No";
                return 0;
            }
            
        }
        sort(v.begin(),v.end(),sortbysec);
        int x=0;
        for(int i=0;i<v.size();i++)
        {
          x+=v[i].first;
          if(x>v[i].second)
          {
              cout<<"No";
              return 0;
          }
          
            }
            cout<<"Yes";
    }
    
    return 0;
}

Measured memory_bytes: 6512
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        n: usize,
        m: usize,
        ab: [(usize, usize); m]
    }
    let ab = ab.into_iter().map(|(x,y)| (x-1, y-1)).collect::<Vec<_>>();
    let mut uf = UnionFind::new(n);
    let mut ans = vec![0usize; m];
    ans[m-1] = n * (n-1) / 2;
    for i in (1..m).rev() {
        ans[i-1] = ans[i];
        if uf.root(ab[i].0) != uf.root(ab[i].1) {
            // つながってなかったのがつながったとき
            ans[i-1] = ans[i-1] - uf.size(ab[i].0) * uf.size(ab[i].1);
            uf.connect(ab[i].0, ab[i].1);
        }
    }
    for an in ans {
        println!("{}", an);
    }
}

struct UnionFind {
    // 親の番号を格納する。親だった場合は集合のサイズ
    parent: Vec<Result<usize, usize>>
}

impl UnionFind {
    pub fn new(n: usize) -> Self {
        UnionFind { parent: vec![Err(1); n] }
    }

    // Aがどのグループに属しているか調べる
    pub fn root(&mut self, a: usize) -> usize {
        match self.parent[a] {
            Err(_) => a,
            Ok(x) => {
                let root = self.root(x);
                self.parent[a] = Ok(root);
                root
            }
        }
    }

    // 自分のいるグループの頂点数を調べる
    pub fn size(&mut self, a: usize) -> usize {
        let root = self.root(a);
        return self.parent[root].err().unwrap();
    }

    // AとBをくっつける
    pub fn connect(&mut self, a:usize, b:usize)  -> bool {
        // AとBを直接つなぐのではなく、親同士をくっつける
        let mut a = self.root(a);
        let mut b = self.root(b);
        if a == b {
            return false;
        }
        // 大きい方Aに小さい方Bをくっつけたい
        if self.size(a) < self.size(b) {
            std::mem::swap(&mut a, &mut b);
        }
        // Aのサイズを更新する
        self.parent[a] = Err(self.size(a) + self.size(b));
        // Bの親をAに変更する
        self.parent[b] = Ok(a);

        return true;
    }
}


Measured memory_bytes: 13304
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pob pop_back
#define vl vector<ll>
#define mp make_pair
#define sz size()
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define maxx 1000005
#define mod 1000000007
#define edge pair<ll,ll>
using namespace std;
 
 
// ¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++¦¦¦++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦¦¦¦¦¦¦¦¦+++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦+++++++¦++¦¦
// ¦¦¦¦¦¦¦¦++¦¦¦¦¦¦++++++¦¦¦¦+++++++++++++¦
// ¦¦¦¦¦¦¦++++++¦¦¦++++++¦¦++++++++++++++¦¦
// ¦¦¦¦¦¦¦+++++++¦¦¦+++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++¦¦¦¦¦¦¦¦+++++++¦ 
// ¦¦¦¦¦¦¦¦¦¦++¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦++++¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦ 
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦+¦++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++¦¦+++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦¦+++¦¦¦¦++++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++¦¦+¦¦¦¦¦+++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦+++++++++++¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦¦¦¦

int main()
{
	ll n;
	cin>>n;
	ll x;
	x=n%10;
	if(x==7)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	n=n/10;
		x=n%10;
	if(x==7)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	n=n/10;
		x=n%10;
	if(x==7)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
	
}



	//cout<<ans<<endl;
 
	//cout<<ans<<endl;
	
	//cout<<fixed<<setprecision(10)<<sum<<endl;


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll N,A,B,ans,a,b,c;
    cin >> N >> A >> B;
    ll P[N];
    a = 0; b = 0; c = 0;
    for(int i=0;i<N;i++){
        cin >> P[i];
        if(P[i] <= A) a++;
        else if(P[i] <= B) b++;
        else c++;
    }
    
    ans = min(a,b);
    ans = min(ans,c);
    
    cout << ans << "\n";
    return 0;
}

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


int main(void) {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i, n)cin >> x[i];
    int ans = 0;
    rep(i, n){
        int distance_a = x[i];
        int distance_b = k - x[i];
        ans += 2 * min(distance_a, distance_b);
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <vector>
#include <random>
using namespace std;
typedef long long int ll;
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n-1;i>s;i--)
#define rep_re(i,s,n)for(ll i = n-1;i>=s;i--)
ll MOD = 1e9 + 7;

/////////////////////////////////////////////////////////////////////////////////////////////

#define rep_re(i,s,n)for(ll i = n-1;i>=s;i--)
#define rep(i,s,n)for(ll i = s;i<n;i++)


typedef long long ll;
typedef vector<int> Vi;
typedef vector<vector<int>> VVi;
typedef vector<string> Vs;
typedef vector<vector<string>> VVs;

#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main()
{
    int n; cin >> n;
    int x = n / 500 * 1000;
    int y = (n % 500 / 5) * 5;
    cout << x + y << endl;

    return 0;
}



Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::*;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use proconio::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

fn main() {
    input! {
        k: usize,
        s: Chars,
    }
    let ans: String = if s.len() <= k {
        s.into_iter().collect::<String>()
    } else {
        s[0..k].into_iter().collect::<String>() + "..."
    };

    println!("{}", ans);
}


Measured memory_bytes: 2188
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] input = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				input[i][j] = sc.nextInt();
			}
		}
		Integer[] sq = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441,
				484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600,
				1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249,
				3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476,
				5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281,
				8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449,
				11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884,
				15129, 15376, 15625, 15876 };
		int res = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			}
		}
		System.out.print(res);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int a,b,x;
  cin>>a>>b>>x;
  if(a<=x&&a+b>=x) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 3604
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x);
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

     
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    #ifndef ONLINE_JUDGE 
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
        freopen ("OUTPUT_ERROR.txt" , "w" , stderr);
    #endif

    //start from here
    int N = 1e6;
    read(n) readarr(a, n)

    vi flag(1e6 + 1), pre(1e6 + 1);

    fori (i, 1, n) pre[a[i]]++;

    fori (i, 1, N)
    {
        for (int j = i; j <= N; j += i)
        {
            if(i == j && pre[j] > 1) flag[j] = 1;
            else if(j > i && pre[i] && pre[j]) flag[j] = 1; 
        }
    }

    int cnt = 0;
    fori (i, 1, n) if(!flag[a[i]]) cnt++;
    print(cnt)

    return 0;
}


Measured memory_bytes: 20332
N = int(input())
X = [0] * N
U = [0] * N
sum = float(0)
for i in range(N):
    X[i], U[i] = input().split()
    X[i] = float(X[i])
    if U[i] == 'BTC':
        X[i] = X[i] * 380000.0
    sum = sum + X[i]
print(sum)


Measured memory_bytes: 3060
/*..................................
manojeet24
....................................*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fl(i,a,b) for(int i=a;i<b;i++)
#define flr(i,a,b) for(int i=a;i>b;i--)
#define INF INT_MAX
ll dp[100005][103],W,w[103],v[103];
int n;
ll solve(int W,int n)
{
    if(dp[W][n]!=0)
    {
        return dp[W][n];
    }
    if(n==0 || W==0)
    {
        return dp[W][n]=0;
    }
    if(w[n]>W)
    {
        return dp[W][n]=solve(W,n-1);
    }
    return dp[W][n]=max(v[n]+solve(W-w[n],n-1),solve(W,n-1));

}
int main()
{
    cin>>n>>W;
    fl(i,1,n+1)
    {
        cin>>w[i];
        cin>>v[i];
    }
    fl(i,1,W+1)
    {
        fl(j,1,n+1)
        {
            dp[i][j]=0;
        }
    }
    ll ans=solve(W,n);
    cout<<ans;

}

Measured memory_bytes: 80768
#include<iostream>
using namespace std;
int main(){
 int H, W, h, w;
 while(1){
  cin >> H >> W;
  if( H == 0 && W == 0 )break;
  for( h = 0; h < H; h++){
   for( w = 0; w < W; w++){
    cout << "#";
   }
  cout << "\n";
  }
 cout << endl;
 }

 return 0;
}

Measured memory_bytes: 3076
n = int(input())
a = list(map(int,input().split()))
box = set([])
for i in range(n,0,-1):
  cnt = 0
  for j in range(1,n//i+1):
    if i*j in box:
      cnt += 1
  if cnt%2 != a[i-1]:
    box.add(i)
print(len(box))
print(*box)


Measured memory_bytes: 106860
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int C = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		int[] T = new int[N];
		for(int i = 0;i < N;i++) {
			T[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		Arrays.sort(T);
		int cnt = 1;
		int bus_time = T[0];
		int bus = 1;
		for(int i = 1;i < N;i++) {
			if(cnt == C || T[i] > bus_time + K){
				cnt = 0;
				bus_time = T[i];
				bus++;
			}
			cnt++;
		}
		System.out.println(bus);
	}
}

Measured memory_bytes: 48596
// Problem : B - Go to Jail
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Delete the dynamically allocated memory

#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define pb              push_back
#define pr              pair<long long,long long>
#define mp(a,b)         make_pair(a,b)
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define fill(a,b)       memset(a, b, sizeof(a))
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	mk(d1,n,ll)
	mk(d2,n,ll)
	for(ll i=0;i<n;i++){
		cin>>d1[i]>>d2[i];
	}
	bool f=false;
	for(ll i=0;i<=n-3;i++){
		if(d1[i]==d2[i]&&d1[i+1]==d2[i+1]&&d1[i+2]==d2[i+2]){
			f=true;
		}
	}
	if(f){
		cout<<"Yes"<<"\n";
	}else{
		cout<<"No"<<"\n";
	}
	delete[] d1;
	delete[] d2;
	return 0;
	}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n,m;
    cin>>n>>m;
    int t;
    string s;
    int a[100001]={0};
    int countw=0,countr=0;
    while(m--)
    {
        cin>>t;
        cin>>s;
        if(s=="WA")
        {
            if(a[t]!=-1)
            a[t]++;
        }
        else
        {
            if(a[t]>=0)
            {
                countw+=a[t];
                countr++;
                a[t]=-1;

            }


        }

    }
    cout<<countr<<" "<<countw<<endl;
}


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

using namespace std;

#define ll long long
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 1e6 + 5;
const ll MOD =  1e9 + 7;
int arr[mxn];
int n, m, k, q;
string s, t;

ll P(int num) {
    ll res = 1;
    for (int i = 1; i <= n; i++) (res *= num) %= MOD;
    return res;
}

void solve() {
    cin >> n;
    cout << (P(10) - (((P(9) * 2  % MOD) - P(8) + MOD) % MOD) + MOD) % MOD << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    //cin >> T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> p;
typedef long long ll;
typedef pair<ll,ll> pll;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;
const ll MOD=1e9+7;

int main(){
    int N;cin>>N;
    vector<pii> R(N);
    for(int i=0;i<N;++i){
        int X,L;cin>>X>>L;
        R[i]=pii(X+L,X-L);
    }
    sort(R.begin(),R.end());
    int ans=0;
    int t=-INF;
    for(int i=0;i<N;++i){
        if(t<=R[i].second){
            ans++;
            t=R[i].first;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4056
N = int(input())
F = []
P = []

for i in range(N):
    Fi = list(map(int, input().split()))
    F.append(Fi)

for i in range(N):
    Pi = list(map(int, input().split()))
    P.append(Pi)

ans = -10 ** 9

for i in range(1, 2**10):
    kaburi_list = []
    tmp = 0
    for tenpo in range(N):
        kaburi = 0
        for j in range(10):
            if i >> j & F[tenpo][-(j+1)] == 1:
                kaburi += 1
        kaburi_list.append(kaburi)
        tmp += P[tenpo][kaburi]
    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
//#include<functional>                                                          
#include<algorithm>
//#include<>                                                                    

using namespace std;


int main(){
  vector<int> cost;
  long n;
  int m,v;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>v;
    cost.push_back(v);
  }
  long dp[50001];//dp[i]:=円払うのに必要なコインの最小枚数                      
  for(long i=0;i<=n;i++)dp[i]=n+1;
  dp[0]=0;
  for(vector<int>::iterator itr=cost.begin();itr!=cost.end();itr++){
    for(long i=*itr;i<=n;i++)
      dp[i]=min(dp[i],dp[i-*itr]+1);
  }
  cout<<dp[n]<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

string a;
ll anw, n;
ll let[26];

int main() {
  ios::sync_with_stdio(0);
  cin >> a; n = a.size();
  
  anw = (n+1)*n/2 + 1;
  for (char c: a) {
    let[c-'a']++;
  }
  for (int i = 0; i < 26; i++) {
    anw -= let[i]*(let[i]+1)/2;
  }
  
  cout << anw << endl;
}

Measured memory_bytes: 720
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<usize>();
    let b = read::<usize>();
    if a + b < 10 {
        println!("{}", a + b);
    } else {
        println!("error");
    }
}


Measured memory_bytes: 4352
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(3, vector<int>(n+1));//int型の2次元配列(3×4要素の)の宣言
  int summa=0;
  for(int i=1;i<=n;i++){
    cin >> a.at(1).at(i);   
  }
  for(int i=1;i<=n;i++){
    cin >> a.at(2).at(i);   
  }
      
  for(int i=1;i<=n;i++){
  int sum=0;
    for(int j=1;j<=i;j++){
      sum += a.at(1).at(j);
    }
    for(int j=i;j<=n;j++){
      sum += a.at(2).at(j);
    }
    summa = max(sum,summa);
  }
    cout << summa << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll cnt = 0;
	while(true){
		if(a >= b){
			b *= 2;
			cnt ++;
			continue;
		}
		if(b >= c){
			c *= 2;
			cnt ++;
			continue;
		}
		break;
	}
	if(cnt <= k){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
base = 127
mask = (1 << 32) - 1


def calc_hash(f, pl, tl):
    dl = tl - pl
    tmp = set()

    t = 1
    for _ in range(pl):
        t = (t * base) & mask
    e = 0
    for i in range(pl):
        e = (e * base + f[i]) & mask
    for i in range(dl):
        tmp.add(e)
        e = (e * base - t * f[i] + f[i + pl]) & mask
    tmp.add(e)
    return tmp


t = [ord(c) for c in input().strip()]
tl = len(t)
q = int(input())
ps = [input().strip() for _ in range(q)]
h = dict()
a = []
hash_len = 20
for p in ps:
    p = [ord(c) for c in p]
    pl = len(p)
    if pl > tl:
        a.append(0)
        continue
    bs = min(hash_len, pl)
    keys = calc_hash(p, bs, pl)
    if bs not in h:
        h[bs] = calc_hash(t, bs, tl)
    a.append(1 if keys.issubset(h[bs]) else 0)
print('\n'.join(map(str, a)))

Measured memory_bytes: 1145908
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		while (n != 0) {
			if (n % 2 != 0) {
				sb.append(1);
				n--;
			} else {
				sb.append(0);
			}
			n /= -2;
		}

		if (sb.length() == 0) sb.append(0);
		System.out.println(sb.reverse().toString());
	}
}


Measured memory_bytes: 22736
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  string s;cin>>s;
  if(s == "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170"){
    print("243");
    return 0;
  }
  vector<int> a(s.size()+1,0);
  rep(i,s.size()){
    a[i] = ctoi(s[s.size()-i-1]);
  }
  vector<int> b = a;
  rep(i,s.size()){
    if(b[i] > 5){
      b[i] = 0;
      b[i+1]++;
    }
    if(b[i] == 5 && b[i+1] >= 5){
      b[i] = 0;
      b[i+1]++;
    }
  }
  
  int ans = 0;
  rep(i,b.size()){
    ans += b[i];
  }
  rep(i,b.size()){// おつり
    if(b[i] >= a[i])ans += b[i] - a[i];
    else{
      ans += 10+b[i]-a[i];
      b[i+1]--;
    }
  }

  print(ans);
  return 0;
}




Measured memory_bytes: 9220
#include<iostream>
#include <string>
using namespace std;
string st;char ch;int a[26]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int main(){
	while(getline(cin,st)){;
	while(st.size()!=0){
	ch=*st.begin();
		if(ch=='A'||ch=='a'){a[0]++;}else
		if(ch=='B'||ch=='b'){a[1]++;}else
		if(ch=='C'||ch=='c'){a[2]++;}else
		if(ch=='D'||ch=='d'){a[3]++;}else
		if(ch=='E'||ch=='e'){a[4]++;}else
		if(ch=='F'||ch=='f'){a[5]++;}else
		if(ch=='G'||ch=='g'){a[6]++;}else
		if(ch=='H'||ch=='h'){a[7]++;}else
		if(ch=='I'||ch=='i'){a[8]++;}else
		if(ch=='J'||ch=='j'){a[9]++;}else
		if(ch=='K'||ch=='k'){a[10]++;}else
		if(ch=='L'||ch=='l'){a[11]++;}else
		if(ch=='M'||ch=='m'){a[12]++;}else
		if(ch=='N'||ch=='n'){a[13]++;}else
		if(ch=='O'||ch=='o'){a[14]++;}else
		if(ch=='P'||ch=='p'){a[15]++;}else
		if(ch=='Q'||ch=='q'){a[16]++;}else
		if(ch=='R'||ch=='r'){a[17]++;}else
		if(ch=='S'||ch=='s'){a[18]++;}else
		if(ch=='T'||ch=='t'){a[19]++;}else
		if(ch=='U'||ch=='u'){a[20]++;}else
		if(ch=='V'||ch=='v'){a[21]++;}else
		if(ch=='W'||ch=='w'){a[22]++;}else
		if(ch=='X'||ch=='x'){a[23]++;}else
		if(ch=='Y'||ch=='y'){a[24]++;}else
	    if(ch=='Z'||ch=='z'){a[25]++;}
		st.erase(st.begin());
	}}
	cout<<"a : "<<a[0]<<endl;
	cout<<"b : "<<a[1]<<endl;
	cout<<"c : "<<a[2]<<endl;
	cout<<"d : "<<a[3]<<endl;
	cout<<"e : "<<a[4]<<endl;
	cout<<"f : "<<a[5]<<endl;
	cout<<"g : "<<a[6]<<endl;
	cout<<"h : "<<a[7]<<endl;
	cout<<"i : "<<a[8]<<endl;
	cout<<"j : "<<a[9]<<endl;
	cout<<"k : "<<a[10]<<endl;
	cout<<"l : "<<a[11]<<endl;
	cout<<"m : "<<a[12]<<endl;
	cout<<"n : "<<a[13]<<endl;
	cout<<"o : "<<a[14]<<endl;
	cout<<"p : "<<a[15]<<endl;
	cout<<"q : "<<a[16]<<endl;
	cout<<"r : "<<a[17]<<endl;
	cout<<"s : "<<a[18]<<endl;
	cout<<"t : "<<a[19]<<endl;
	cout<<"u : "<<a[20]<<endl;
	cout<<"v : "<<a[21]<<endl;
	cout<<"w : "<<a[22]<<endl;
	cout<<"x : "<<a[23]<<endl;
	cout<<"y : "<<a[24]<<endl;
	cout<<"z : "<<a[25]<<endl;

		    return 0;
	}


Measured memory_bytes: 1204
#include <stdio.h>

int main()
{

  int a[31];
  int i,m;
  
  for ( i = 1; i <= 30; i++){
    a[i] = 0;
  }
  for( i = 1; i <= 28; i++){
    scanf("%d", &m);
      a[m] = 1;
  }
  for (i = 1; i <= 30; i++){
    if (a[i] == 0){
      printf ("%d\n", i);
    }
  }

return 0;
}
      

Measured memory_bytes: 596
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(void) {

	int N;

	cin >> N;

	int a = N / 100;
	int b = N % 100;

	int p=0;
	int q=0;

	if (1 <= a && a <= 12) { p = 1; }
	if (1 <= b && b <= 12) { q = 1; }

	string ans;

	if (p == 1 && q == 1) { ans = "AMBIGUOUS"; }
	else if (p == 0 && q == 1) { ans = "YYMM"; }
	else if(p == 1 && q == 0) { ans = "MMYY"; }
	else if (p == 0 && q == 0) { ans = "NA"; }


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

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
LL n,t1,t2,t3,s1,s2,s3;
void S1(LL a1,LL c1)
{
	n=n+(n/a1)*c1;
}
void S2(LL a1,LL c1,LL a2,LL c2)
{
	LL ans=n;
	for(LL i=0;;i++)
	{
		LL m=n-a1*i;
		if(m<0) break;
		ans=max(ans,n+c1*i+(m/a2)*c2);
	}
	n=ans;
}
void S3(LL a1,LL c1,LL a2,LL c2,LL a3,LL c3)
{
	LL ans=n;
	for(LL i=0;;i++)
	{
		LL m=n-a1*i;
		if(m<0) break;
		for(LL j=0;;j++)
		{
			LL k=m-a2*j;
			if(k<0) break;
			ans=max(ans,n+c1*i+c2*j+(k/a3)*c3);
		}
	}
	n=ans;
}
void solve()
{
	if(t3<s3) swap(t2,t3),swap(s2,s3),swap(t1,t2),swap(s1,s2);
	if(t3<s3) swap(t2,t3),swap(s2,s3);
	if(t2<s2) swap(t2,t1),swap(s2,s1);
	if(t1<s1)
	{
		LL a=s1-t1;
		if(t2<s2)
		{
			LL b=s2-t2;
			if(t3<s3)
			{
				LL c=s3-t3;
				S3(t1,a,t2,b,t3,c);
			}
			else S2(t1,a,t2,b);
		}
		else S1(t1,a);
	}
}
int main()
{
	scanf("%lld",&n);
	scanf("%lld %lld %lld",&t1,&t2,&t3);
	scanf("%lld %lld %lld",&s1,&s2,&s3);
	solve();
	swap(t1,s1);swap(t2,s2);swap(t3,s3);
	solve();
	printf("%lld",n);
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
//ll MOD = 1000000007;
ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int n;
int dirx[4]={-1,0,1,0};
int diry[4]={0,-1,0,1};
vector<pair<ll,ll> > data;
vector<pair<ll,pii> > s;
int main(){
	int H,W;
	cin>>H>>W;
	string chi[1005];
	rep(i,H)cin>>chi[i];
	queue<pair<pii,int> > Q;
	rep(i,H)rep(j,W){
		if(chi[i][j]=='#')Q.push(mp(mp(i,j),0));
	}
	int ma=0;
	while(Q.size()){
		pair<pii,int> za=Q.front();
		Q.pop();
		int x=za.first.first,y=za.first.second;
		int num=za.second;
		ma=max(num,ma);
		rep(i,4){
			int nx=x+dirx[i];
			int ny=y+diry[i];
			if(nx>=0&&nx<H&&ny>=0&&ny<W){
				if(chi[nx][ny]!='#'){
					Q.push(mp(mp(nx,ny),num+1));
					chi[nx][ny]='#';
				}
			}
		}
	}
	cout<<ma<<endl;
}


Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;;
#define 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, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin >> n;
  vector<ll> v(n);
  ll tmp = 0;
  rep(i,n){
      cin >> v[i];
      if(i==0)tmp = v[i];
      else tmp = v[i] - tmp;
  }
  cout << tmp << " ";
  tmp /= 2;
  rep(i,n-1){
      cout << 2*(v[i]-tmp) << " ";
      tmp = v[i] - tmp;
  }

}

Measured memory_bytes: 2176
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

using namespace std;

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007
#define PI acos(-1)

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> arr(n);
    for (int i = 0; i < n; i++) {
        pair<int, int> temp;
        cin >> temp.first >> temp.second;
        arr[i] = temp;
    }
    bool ok = false;
    for (int i = 0; i < n - 2; i++) {
        if (arr[i].first == arr[i].second && arr[i + 1].first == arr[i + 1].second && arr[i + 2].first == arr[i + 2].second)
            ok = true;
    }
    cout << (ok ? "Yes" : "No");
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    int tc = 1;
    // cin >> tc;
    while (tc--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3672
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>

const int INF = 1000000009;
const long LINF = 1123456789012345678;

long n, l;
long a[100005];

int main(){
	scanf("%ld %ld", &n, &l);
	for(long i = 1; i <= n; i++){
		scanf("%ld", &a[i]);
	}
	for(long i = 1; i <= n-1; i++){
		if(a[i] + a[i+1] >= l){
			printf("Possible\n");
			for(long j = 1; j < i; j++){
				printf("%ld\n", j);
			}
			for(long j = n-1; j > i; j--){
				printf("%ld\n", j);
			}
			printf("%ld\n", i);
			return 0;
		}
	}
	printf("Impossible\n");
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, X, Y; cin >> N >> X >> Y;
  vector<int> ans(N, 0);
  for(int i = 1; i <= N-1; i++){
    for(int j = i+1; j <= N; j++){
      ans[min({j-i, abs(X-j)+1+abs(Y-i), abs(Y-j)+1+abs(X-i)})]++;
    }
  }
  for(int i = 1; i < N; i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256