akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

using int64 = long long;

int64 gcd(int64 a, int64 b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

bool judge(int64 A, int64 B, int64 C, int64 D) {
    if (A < B) return false;
    if (D < B) return false;
    if (C >= B) return true;
    int64 g = gcd(B, D);
    // C < A - k * g < Bを満たすようなkが存在する時false
    int64 k = (A - C) / g;
    if (C >= A - k * g) k--;

    // cerr << "k: " << k << endl;
    return !(C < A - k * g and A - k * g < B);
}

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

    for (int i = 0; i < T; i++) {
        int64 A, B, C, D;
        cin >> A >> B >> C >> D;

        if (judge(A, B, C, D)) 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 pb push_back
#define fi first
#define se second
int main()
{
  ll n,m,i,j,a,b,ans=0;
  cin>>n>>m;
  map<ll,ll> mp;
  for(i=0;i<n;i++)
  {
   cin>>a;
   for(j=0;j<a;j++)
   {
     cin>>b;
     mp[b]++;
   }
  }
  for(auto l:mp) if(l.se==n) ans++;
  cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	bool cards[4][14];
	int n,number,colorn;
	char color;
	cin>>n;
	for(int i=0;i<4;i++){
		for(int j=0;j<14;j++){
			cards[i][j]=0;
			}
		}
		
	for(int i=0;i<n;i++){
		cin>>color>>number;
		if(color=='S') colorn=0;
		if(color=='H') colorn=1;
		if(color=='C') colorn=2;
		if(color=='D') colorn=3;
		
		cards[colorn][number]=1;
		}
	for(int i=0;i<4;i++){
		for(int j=1;j<14;j++){
			if(cards[i][j]==0) {
				if(i==0) color='S';
				if(i==1) color='H';
				if(i==2) color='C';
				if(i==3) color='D';
				cout<<color<<" "<<j<<"\n";
			}
		}
		}
	return 0;
}

Measured memory_bytes: 1160
import math
x, k, d = map(int, input().split())
p = math.floor(abs(x/d))
if x > 0:
    if p >= k: print(abs(x-k*d))
    elif (k-p)%2==1: print(abs(x-(p+1)*d))
    else: print(abs(x-p*d))
else:
    if p >= k: print(abs(x+k*d))
    elif (k-p)%2==1: print(abs(x+(p+1)*d))
    else: print(abs(x+p*d))


Measured memory_bytes: 9196
n, t = gets.chomp.split().map { |e| e.to_i }
shower  = gets.chomp.split().map { |e| e.to_i }
answer = t + shower.last

for i in 0 ... n - 1
    shower[i] += t
    answer -= [0, shower[i + 1] - shower[i]].max
end

puts answer


Measured memory_bytes: 21892
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}
ll powe(ll x, ll y,ll m)
{
    if(y==0)
        return 1;
    else
    {
        ll t = powe(x,y/2,m)%m;
        if(y%2==0)
            return (t*t)%m;
        else
            return (((t*t)%m)*x)%m;
    }
}
string itb(ll n)
{
    string s="";
    while(n>0)
    {
        ll d = n%2;
        s = (char)(d+48)+s;
        n=n/2;
    }
    return s;
}

bool parity(int a, int b)
{
    if(a%2==0 && b%2==0)
        return false;
    else if(a%2==1 && b%2==1)
        return false;
    else
        return true;
}
void build(int node,int start,int end,int tree[],int a[])
{
    if(start==end)
    {
        tree[node]=a[start];
    }
    else
    {
        int mid= (start+end)/2;
        build(2*node,start,mid,tree,a);
        build(2*node+1,mid+1,end,tree,a);
        tree[node] = min(tree[2*node+1],tree[2*node]);
    }
}
void update(int node,int start,int end,int idx,int val,int tree[],int a[])
{
    if(start==end)
    {
        a[idx]=val;
        tree[node]=val;
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx && idx <= mid)
        {
            update(2*node, start, mid, idx, val,tree,a);
        }
        else
        {
            update(2*node+1, mid+1, end, idx, val,tree,a);
        }
        tree[node] = min(tree[2*node+1],tree[2*node]);
    }
}
int query(int node, int start, int end, int l, int r,int tree[])
{
    if(r < start || end < l)
    {
        return 100005;
    }
    if(l <= start && end <= r)
    {
        return tree[node];
    }
    int mid = (start + end)/2;
    int p1 = query(2*node, start, mid, l, r,tree);
    int p2 = query(2*node+1, mid+1, end, l, r,tree);
    return min(p1,p2);
}
int bs_lower_bound(int a[], int n, int x) {
    int l = 0;
    int h = n;
    while (l < h) {
        int mid = (l + h) / 2;
        if (x <= a[mid]) {
            h = mid;
        } else {
            l = mid + 1;
        }
    }
    if(l>=n)
        l=-1;
    return l;
}
int main()
{
    fastio();
    
    ll r;
    cin>>r;
    cout<<r*r<<endl;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

//Union-Find Tree
class UnionFind{
    private:
        int N;
        vector<int> par;    //par[i]:iの親の番号
        vector<ll> size;

    public:
        UnionFind(int n) : N(n), par(n), size(n, 1){  //初期化時はすべて根とする
            for(int i=0; i<n; i++){
                par.at(i) = i;
            }
        }

        int root(int x){    //データxが属する木の根を再帰で得る
            if(par.at(x) == x){
                return x;
            }else{
                return par.at(x) = root(par.at(x)); //経路圧縮を同時に実行
            }
        }

        ll unite(int x, int y){   //xの属する木とyの属する木を併合
            int rx = root(x), ry = root(y);
            ll sx = size[rx], sy = size[ry];
            if(rx != ry){   //xとyの属する木が異なるとき
                par.at(rx) = ry;    //xの木の根をyの根につける
                size[ry] += size[rx];
                return size[ry]*(size[ry]-1)/2 - sx*(sx-1)/2 - sy*(sy-1)/2;
            }
            return 0;
        }

        bool same(int x, int y){    //x,yが同じ木に属するときtrue, そうでなければfalse
            return root(x) == root(y);
        }
};

int main(){
    ios();
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> v(m);
    for(auto& i : v){
        cin >> i.first >> i.second;
    }
    UnionFind tree(n);
    vector<ll> ans(m);
    ll cnt = (ll)n*(n-1)/2;
    RREP(i, m){
        ans[i] = cnt;
        cnt -= tree.unite(v[i].first - 1, v[i].second - 1);
    }
    for(auto i : ans){
        cout << i << '\n';
    }
    return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  for (int i = A; i <= B; ++i) {
    if (i % K == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < 3; ++i)
    {
        if(s[i] == s[i + 1])
        {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		bool l = false;
		int s = 0;
		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;
			if (a >= 2) l =true;
			if (a > 0) s++;
		}
		if (l) cout << s + 1 << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int N;
  cin >> N;
  ll mn = INF;
  REP(i, N) {
    ll tmp = 0;
    ll a;
    cin >> a;
    while (a % 2 == 0) {
      a /= 2;
      tmp++;
    }
    mn = min(mn, tmp);
  }
  cout << mn << endl;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.math, std.array, std.algorithm, std.string;

string show(int[] arr) {
  return arr.map!(to!(string)).join("");
}

void main() {
  double num;
  while(readf("%f\n", &num), num >= 0.0) {
    int integer;
    double dec;
    int[] dec_arr, integer_arr;

    dec = num - floor(num);
    integer = floor(num).to!(int);

    // 整数部の変換
    for(int i = 0; i < 8; i++) {
      integer_arr ~= (integer & 1);
      integer >>= 1;
    }

    // 小数部の変換
    for(int i = 0; i < 4; i++) {
      dec *= 2;
      dec_arr ~= dec.to!(int);
      dec = dec - floor(dec);
    }

    if (dec == 0 && integer == 0) {
      writeln(integer_arr.reverse.show, ".", dec_arr.show);
    }
    else {
      writeln("NA");
    }
  }
}

Measured memory_bytes: 1524
#include <cstdio>
using namespace std;

int main(){
    constexpr int ans[101] = {
        0,
        4,
        16,
        61,
        230,
        865,
        3247,
        12185,
        45719,
        171531,
        643550,
        2414454,
        9058467,
        33985227,
        127504505,
        478366600,
        794717734,
        733354121,
        261943303,
        776803305,
        580025381,
        51688048,
        44657419,
        737209731,
        604119499,
        159693437,
        858533109,
        639056669,
        549054109,
        996291083,
        531294469,
        23314687,
        783022045,
        855462856,
        649970414,
        68697295,
        409213624,
        604356692,
        88638656,
        978442997,
        534833116,
        763737161,
        785892908,
        123883652,
        639213333,
        181836645,
        998121103,
        124885216,
        501575626,
        39816123,
        113468411,
        799008836,
        775465589,
        256852905,
        664630886,
        971550783,
        751629411,
        51018086,
        702530485,
        725438992,
        696683714,
        792638194,
        221791721,
        149602322,
        414054379,
        986519078,
        981760191,
        305799096,
        515140586,
        406959393,
        975058685,
        245601370,
        324759692,
        673385295,
        191483611,
        570246669,
        427196161,
        781042769,
        569725155,
        842176273,
        25328739,
        847501730,
        206282374,
        353770801,
        323137024,
        371653459,
        940737264,
        123820509,
        915711339,
        847205021,
        252858375,
        718889563,
        866398347,
        738390145,
        133009077,
        333099663,
        170591295,
        329869205,
        616680192,
        597534442,
        388130742,
    };
    int n;
    scanf("%d", &n);
    printf("%d\n", ans[n]);
    
    return 0;
}

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

int main()
{
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    int dp[n+1][m+1];
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=m; j++)
        {
            if(i==0 || j==0) dp[i][j]=0;
            else if(s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int ans=dp[n][m];
    char a[ans+1]; a[ans]='\0';
    int i=n,j=m;
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
            a[--ans]=s[i-1];
            i--;j--;
        }
        else if(dp[i-1][j]>dp[i][j-1]) i--;
        else j--;
    }
    cout<<a<<endl;
    return 0;
}


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

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

    vector<int> a(n, 0);

    rep(i, k)
    {
        int d;
        cin >> d;
        rep(j, d)
        {
            int t;
            cin >> t;
            a.at(t-1)++;
        }
    }

    cout << count(a.begin(), a.end(), 0) << endl;
    return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  char a,b,c;
  cin>>a>>b>>c;
  cout<<a<<b<<c<<endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,K;
    cin >> N >> K;
    int R,S,P;
    cin >> R >> S >> P;
    string T;
    cin >> T;
    vector<bool> no(N, false);
    REP(i, N-K){
        if(no[i] == true) continue;
        if(T[i] == T[i+K]){
            no[i+K] = true;
        }
    }
    ll ans = 0;
    REP(i, N){
        if(no[i] == true) continue;
        if(T[i] == 's') ans += R;
        else if(T[i] == 'r') ans += P;
        else if(T[i] == 'p') ans += S;
    }

    pr(ans);
}

Measured memory_bytes: 512
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
cums = [0]
for a in A:
    cums.append(cums[-1] + a)
ctr = Counter(cums)

ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)

Measured memory_bytes: 41728
import java.lang.Math.pow
fun main(args: Array<String>) {
    var input = readLine()!!
    val n = input.split(" ")[0].toInt()
    val k = input.split(" ")[1].toInt()

    var si = 1.0
    var bo = n * pow(2.0 , cck(1, k))

    for (i in 2..n){
        si += bo / (n * pow(2.0, cck(i, k)))
    }
    print(si/bo)
}

fun cck(i: Int, k: Int): Double {
    var n = 0.0
    while (i.toDouble() * pow(2.0 , n) < k){
        n++
    }
    return n
}


Measured memory_bytes: 35984
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var NK = ReadLine().Split().Select(int.Parse).ToArray();
        int N = NK[0];
        int K = NK[1];
        var p = ReadLine().Split().Select(_=>double.Parse(_)/2 + 0.5).ToArray();
        var d = new double[N];
        for (int i = 0; i < K; i++)
        {
            d[0] += p[i];
        }
        for (int i = 1; i < N-K+1; i++)
        {
            d[i] = d[i - 1] - p[i - 1] + p[i + K - 1];
        }
        WriteLine(d.Max());
    }
}


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

#define ll long long
#define endl "\n"
#define M 10000001

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    map<string, ll> ans;
    for(int i = 0; i < n; i++)
    {
        string s;
        cin>>s;
        ans[s]++;
    }
    cout<<"AC x "<<ans["AC"]<<endl;
    cout<<"WA x "<<ans["WA"]<<endl;
    cout<<"TLE x "<<ans["TLE"]<<endl;
    cout<<"RE x "<<ans["RE"]<<endl;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<string>

void max_heapify(int* A, int i, int H)
{
    int l = 2 * i, r = 2 * i + 1;
    if(l > H && r > H) return;
    int maxid = i, x;
    if(l <= H) maxid = (A[l] > A[maxid] ? l : maxid);
    if(r <= H) maxid = (A[r] > A[maxid] ? r : maxid);
    if(maxid == i) return;
    x = A[maxid]; A[maxid] = A[i]; A[i] = x;
    max_heapify(A, maxid, H);
}

int main()
{
    int A[2000001];
    int i, H, key;
    char cmd[8];
    scanf("%d", &H);
    for(i = 1; i <= H; i++) scanf("%d", &A[i]);
    H = 0;

    while(1){
        scanf("%s", cmd);  
        if(cmd[2] == 'd') break;  // end.
        if(cmd[2] == 't'){  // extract.
            if(H == 0) continue;
            printf("%d\n", A[1]);
            A[1] = A[H]; H--;
            if(H > 0) max_heapify(A, 1, H);
        }else{
            scanf("%d", &key); // H++;   // insert key.
            i = ++H;
            while(i > 1){
                if(A[i / 2] > key) break;
                A[i] = A[i / 2];
                i /= 2;
            };
            A[i] = key;
        }
    };
    return 0;
}

Measured memory_bytes: 6820
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

const int maxN = 2e5 + 10;

int n;
vector<int> adj[maxN];
int c[maxN], color[maxN], res[maxN], son[maxN];

void dfs(int u, int par)
{
    int cnt = c[color[u]];

    for(int v : adj[u])
    {
        if(v == par) continue;
        c[color[u]] = 0;
        dfs(v, u);
        son[u] += son[v];
        res[color[u]] += (son[v] - c[color[u]]) * (son[v] - c[color[u]] + 1) / 2;
    }
    c[color[u]] = cnt + son[u];
}

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

    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> color[i];
        son[i] = 1;
    }
    for(int i = 1; i <= n - 1; ++i)
    {
        int u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs(1, -1);

    for(int i = 1; i <= n; ++i){
        cout << n * (n + 1) / 2 - (n - c[i]) * (n - c[i] + 1) / 2 - res[i] << endl;
    }

}


Measured memory_bytes: 39536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		sc.close();
		int s;
		int k;
		s = X;
		X = Y;
		Y = s;
		k = X;
		X = Z;
		Z = k;
		System.out.println(X + " " + Y + " " + Z);
	}
}

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

int main(){
    
    string s;
    int k;
    cin >> s >> k;
    
    vector<string> subs;
    
    for(int i=0;i<s.size(); i++){
        for(int j=1;j<=k;j++){
            if(i+j<=s.size())   subs.push_back(s.substr(i,j));
        }
    }
    
    sort(subs.begin(),subs.end());
    unique(subs.begin(),subs.end());
    
    cout << subs.at(k-1) << endl;
    
    return 0;
    
}




Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


string s;

main(){
  cin>>s;

  vector<int> a(30);
  rep(i,4){
    a[s[i]-'A']++;
  }

  sort(all(a));
  reverse(all(a));

  if(a[0]==2&&a[1]==2){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if(C % B == 0 &&  A % D == 0) {
    
    if(C / B <= A / D) {
      cout << "Yes" << endl;
    }
    else {
       cout << "No" << endl;
    }
  }
  
    if(C % B != 0 &&  A % D == 0) {
    
    if(C / B < A / D) {
      cout << "Yes" << endl;
    }
    else {
       cout << "No" << endl;
    }
  }
  
    if(C % B == 0 &&  A % D != 0) {
    
    if(C / B <= A / D + 1) {
      cout << "Yes" << endl;
    }
    else {
       cout << "No" << endl;
    }
  }
  
   if(C % B != 0 &&  A % D != 0) {
    
    if(C / B <= A / D) {
      cout << "Yes" << endl;
    }
    else {
       cout << "No" << endl;
    }
  }
   
} 

Measured memory_bytes: 3640
#include <iostream>
#include <queue>

using namespace std;

priority_queue<int> Ai;

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

  for(int i=0; i<n; i++){
    int cost;
    cin >> cost;
    Ai.push( cost );
  }

  for(int i=0; i<m; i++){
    int val = Ai.top() / 2;
    Ai.pop();
    Ai.push(val);
  }

  long long ans = 0;
  while( !Ai.empty() ){
    ans += Ai.top();
    Ai.pop();
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

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

#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=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	string s;
	cin>>s;
	int n=s.size();
	int cnt=0;
	REP(i, s.size()){
		if(s[i]=='o'){
			++cnt;
		}
	}
	cout<<(cnt+15-n>=8 ? "YES" : "NO")<<'\n';
	return 0;
}


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

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

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
  int A[100];
  int N, i, j, minj, number=0, temp;

  scanf("%d", &N);
  if(N < 1 || 100 < N)
    exit(1);

  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
    if(A[i] < 0 || 100 < A[i])
      exit(2);
  }

  for(i = 0; i < N; i++){
    minj = i;
    for(j = i; j < N; j++){
      if(A[j] < A[minj])
	minj = j;
    }
    if(i != minj){
      temp = A[i];
      A[i] = A[minj];
      A[minj] = temp;
      number++;
    }
  }

  for(i = 0; i < N - 1; i++)
    printf("%d ", A[i]);
  printf("%d\n", A[i]);
  printf("%d\n", number);

  return 0;
}

Measured memory_bytes: 600
#pragma GCC optimize(2)
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define sc(z) scanf("%d", &(z))
#define _ff(i, a, b) for (int i = (a); i <= (b); ++i)
#define _f(i, a, b) for (int i = (a); i < (b); ++i)
#define _rr(i, a, b) for (int i = (a); i >= (b); --i)
#define _r(i, a, b) for (int i = (a); i > (b); --i)
const int inf = 0x3f3f3f3f;
const int maxn = 105;
int a[maxn], b[maxn];
map<int, int> mp;

int main() {
    int n; cin >> n;
    _ff(i, 1, n) cin >> a[i];
    sort(a + 1, a + 1 + n);
    int cnt = 0;
    _ff(i, 1, n) {
        mp[a[i]] = 1;
        b[++cnt] = a[i];
        while (a[i+1] == a[i]) {
            mp[a[i]]++;
            ++i;
        }
    }
    int ans = 0;
    _ff(i, 1, cnt) {
        _ff(j, i + 1, cnt) {
            _ff(k, j + 1, cnt) {
                if (b[i] + b[j] > b[k] && abs(b[i] - b[j]) < b[k]) ans += mp[b[i]] * mp[b[j]] * mp[b[k]];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
n, q = map(int, readline().split())
ab = [list(map(int, readline().split())) for i in range(n - 1)]
px = [list(map(int, readline().split())) for j in range(q)]
graph = [[] for _ in range(n + 1)]

for a, b in ab:
  graph[a].append(b)
  graph[b].append(a)
memo = [0] * (n + 1)
for p, x in px:
  memo[p] += x
stack = [(1, 0)]

while stack:
  x, parent = stack.pop()
  memo[x] += memo[parent]
  for y in graph[x]:
    if y == parent:
      continue
    stack.append((y, x))
print(*memo[1:])

Measured memory_bytes: 132068
using System;

namespace AtCoder
{
    class MainClass
    {
        public static void Main()
        {
           

            string[] input1 = Console.ReadLine().Split(' ');
            int N= int.Parse(input1[0]);
            int M = int.Parse(input1[1]);

            string[] input2 = Console.ReadLine().Split(' ');

            int[] A = new int[N];

            int total = 0;

            for (int i=0;i<=N-1; i++)
            {
                A[i] = int.Parse(input2[i]);

                total += A[i];
            }

            float t = (float)total;

            float standard = t / (4 * M);

            int count = 0;

            for(int j = 0; j <= N - 1; j++)
            {
                if (A[j] >= standard) {
                    count++;
                }
                
            }

            if (count >=M)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            

           
        }
    }
}



Measured memory_bytes: 13140
N = int(input())
A = list(map(int, input().split()))

money = 1000
stock = 0

for i in range(N-1) :
  if A[i] > A[i+1] :
    money += stock * A[i]
    stock = 0
  elif A[i] < A[i+1] :
    temp = int(money / A[i])
    stock += temp
    money -= temp * A[i]
    
money += stock * A[N-1]
stock = 0
print(money)

Measured memory_bytes: 9012
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int A = int.Parse(Console.ReadLine());
        int B = int.Parse(Console.ReadLine());

        int O = Enumerable.Range(1, 3).Where(o => o != A && o != B).Single();
        Console.WriteLine(O);
    }
}

Measured memory_bytes: 11348
from math import ceil
n,h = map(int,input().split())
aa = [0]*n
bb = [0]*n
for i in range(n):
    a,b = map(int,input().split())
    aa[i] = a
    bb[i] = b
m = max(aa)
bb.sort(reverse=True)
ans = 0
dmg = 0

for i in range(n):
    if bb[i] < m or dmg >= h:
        break
    dmg += bb[i]
    ans += 1

if dmg < h:
    ans += ceil((h-dmg)/m)

print(ans)


Measured memory_bytes: 11312
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int x = in.nextInt();
		int y = in.nextInt();
		
		if(a+b<=c*2) {
			System.out.println(a*x+b*y);
		}else {
			if(x<y) {
				int ans = Math.min(2*c*x+b*(y-x), 2*c*y);
				System.out.println(ans);
			}else {
				int ans = Math.min(2*c*y+a*(x-y), 2*c*x);
				System.out.println(ans);
			}
		}
		
		in.close();

	}

}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(){
    string a;
    string  b;
    cin >> a >> b;
    int H_D;
    if(a == "H"){
        H_D = 0;
    }else{
        H_D = 1;
    }
    if(b == "H"){
        H_D += 0;
    }else{
        H_D += 1;
    }
    if(H_D % 2 == 0){
        cout << "H" << endl;
    }else{
        cout << "D" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split("");
			Arrays.sort(chr);

			 System.out.println(chr[0].equals(chr[1])
					 &&chr[2].equals(chr[3])
					 &&!(chr[0].equals(chr[2]))?"Yes":"No");
		}
	}
}

Measured memory_bytes: 25552
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a, b, c, x = 0;
	cin >> a >> b >> c;
	x = a + b;
	if (x >= b + c) {
		x = b + c;
	}
	if (x >= a + c) {
		x = a + c;
	}
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <deque>

using namespace std;

void A_Station_and_Bus(void) {

	string S;

	cin >> S;

	cout << ((S[0] == S[1] && S[0] == S[2]) ? "No" : "Yes");

	return;
}

void B_Count_Balls(void) {

	long n;
	//int a, b;
	long a, b;
	
	//long count = 0;

	cin >> n >> a >> b;

	//count = (n - (n % (a + b))) / (a + b);
	long count = long(n / (a + b));

	/*
	if (n % (a + b) <= a) {

		cout << n % (a + b) + count * a;
	}
	else {

		cout << a + count * a;
	}
	*/
	cout << ((n % (a + b) <= a) ? count * a + n % (a + b) : a * (count + 1));

	return;
}

void C_Tax_Increase(void) {

	int a, b;
	/*
	int pa[1000] = { -1 };
	int pb[1000] = { -1 };

	int flag = 0;
	int re = 0;
	*/
	cin >> a >> b;

	/*
	for (int loop = 1; loop < 1400; loop++) {

		if ((int)(loop * 0.08) == a && flag < 1000) {
			pa[flag] = loop;
			flag++;
		}
	}

	flag = 0;
	for (int loop = 1; loop < 1400; loop++) {

		if ((int)(loop * 0.1) == b && flag < 1000) {
			pb[flag] = loop;
			flag++;
		}
	}

	for (int xloop = 0; xloop < 1000; xloop++) {

		for (int yloop = 0; yloop < 1000; yloop++) {

			if (pa[xloop] != -1 && pa[xloop] == pb[yloop]) {

				re = pa[xloop];
			}
		}
	}

	for (int xloop = 0; xloop < 1000; xloop++) {

		for (int yloop = 0; yloop < 1000; yloop++) {

			if (pa[yloop] != -1 && pa[yloop] == pb[xloop]) {

				if (re > pa[yloop]) re = pa[yloop];
			}
		}
	}

	if (re > 0) {

		cout << re << flush;
	}
	else {

		cout << -1 << flush;
	}
	*/

	for (int loop = 0; loop < 1400; loop++) {

		if (int(loop * 0.08) == a && int(loop * 0.10) == b) {
			
			cout << loop << flush;
			return;
		}
	}

	cout << -1 << flush;
	return;
}

void D_String_Formation(void) {

	string S1;
	deque<char> S2;
	int Q;

	cin >> S1;
	cin >> Q;

	for (int loop = 0; loop < (int)S1.size(); loop++) {

		S2.push_back(S1[loop]);
	}

	int T;
	int F;
	char C;

	int max = 0;
	char sBuff;

	//
	bool order = true;

	int loop1 = 0;
	int loop2 = 0;

	for (loop1 = 0; loop1 < Q; loop1++) {

		cin >> T;

		if (T == 1) {
			/*
			max = (int)(S.size() * 0.5);

			for (loop2 = 0; loop2 < max; loop2++) {

				sBuff = S[loop2];
				S[loop2] = S[S.size() - loop2 - 1];
				S[S.size() - loop2 - 1] = sBuff;
			}
			*/
			order = !order;
		}
		else {

			cin >> F >> C;

			if (order && F == 1 || !order && F == 2) {

				//S = C + S;
				S2.push_front(C);
			}
			else {

				//S = S + C;
				S2.push_back(C);
			}
		}
	}

	if (!order) {

		max = (int)(S2.size() * 0.5);

		for (loop2 = 0; loop2 < max; loop2++) {

			sBuff = S2[loop2];
			S2[loop2] = S2[S2.size() - loop2 - 1];
			S2[S2.size() - loop2 - 1] = sBuff;
		}
	}

	S1 = "";

	for (int loop = 0; loop < (int)S2.size(); loop++) {

		S1 += S2[loop];
	}

	cout << S1;

	return;
}

int main(void) {

	//A_Station_and_Bus();
	//B_Count_Balls();
	//C_Tax_Increase();
	D_String_Formation();

	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,n) for(int i = (a); i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define debug_v(v,N) for(int i=0;i<N;i++) { cout << v[i] << " "; } cout << endl;
#define debug_vv(v,H,W) for(int i=0;i<H;i++) { for(int j=0;j<W;j++) { cout << v[i][j] << " "; } cout << endl; }

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int N, M; cin >> N >> M;
	vector<ll> A(N);
	priority_queue<ll> que;
	rep(i, N) {
		cin >> A[i];
		que.push(A[i]);
	}
	rep(i,M) {
		ll v = que.top();
		que.pop();
		que.push(v / 2);
	}
	ll result = 0;
	while (!que.empty())
	{
		result += que.top();
		que.pop();
	}
	cout << result << endl;
}

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


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

int main(){
  ll n;
  cin >> n;
  string s;
  while(n){
    n--;
    s.push_back('a'+n % 26);
    n /= 26;
  }
  reverse(begin(s),end(s));
  cout << s << endl;
  return 0;

}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  char a;
  cin >> a;
  if (a >= 'a' && a <= 'z') cout << "a";
  else cout << "A";
}


Measured memory_bytes: 3592
import java.util.Scanner;

class Problem {
    private int N;
    private int M;
    private int C;
    private int[] B;
    private int[][] A;

    Problem() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        C = sc.nextInt();

        B = new int[M];
        for (int i = 0; i < M; i++) {
            B[i] = sc.nextInt();
        }
        A = new int[N][M];
        for (int n = 0; n < N; n++) {
            for (int i = 0; i < M; i++) {
                A[n][i] = sc.nextInt();
            }
        }
    }

    int solve() {
        int ans = 0;
        for (int n = 0; n < N; n++) {
            int sum = C;
            for (int i = 0; i < M; i++) {
                sum += A[n][i] * B[i];
            }
            if (sum > 0) {
                ans++;
            }
        }
        return ans;
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println(new Problem().solve());
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll MOD = 1000000007;
const int MAX = 100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }


int main(){
    int N; cin >> N;
    ll cnt=0;
    int d=1;
    int x[10][10] = {0};
    for(int i=1;i<=N;i++){
        if(i%(10*d)==0) d*=10;
        int a=i/d; //先頭の桁
        int b=i%10; //末尾の桁
        x[a][b]++;
    }
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            cerr << x[i][j] << " ";
            cnt += x[i][j]*x[j][i];
        }
        cerr << "\n";
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const ll p = 1e9 + 7;
const ll MAXK = 10009;
const ll MAXD = 109;
 
ll memo[MAXK][MAXD][2];
 
int main() {
  string K; cin >> K;
  int D; cin >> D;
  memset(memo, -1, sizeof(memo));
  function<ll(int, int, int)> dp = [&](int i, int rem, int tight) {
    if (i == K.size()) return ll(rem == 0);
    else if (memo[i][rem][tight] != -1) return memo[i][rem][tight];
    else {
      int upperbound = tight ? (K[i] - '0') : 9;
      ll ret = 0;
      for (int d = 0; d <= upperbound; d++) {
        ret = (ret + dp(i + 1, (rem + d) % D, tight && (d == upperbound))) % p;
      }
      return memo[i][rem][tight] = ret;
    }
  };
  cout << ((dp(0, 0, 1) - 1) % p + p) % p << endl;
  return 0;
}

Measured memory_bytes: 18560
#include <stdio.h>
#include <math.h>

int main(void)
{
	int n, d, ans = 0;
	int x[10][10];
	int i, j, k;
	double cal;
	
	scanf("%d %d", &n, &d);
	
	for (i = 0; i < n; i++) {
		for (j = 0; j < d; j++) {
			scanf("%d", &x[i][j]);
		}
	}
	
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (i == j) continue;
			cal = 0;
			for (k = 0; k < d; k++) {
				cal += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			cal = sqrt(cal);
			if (cal == (int)cal) {
				ans++;
			}
		}
	}
	
	printf("%d\n", ans / 2);
	
	return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define pi 3.141592653589793
#define mod 1000000007
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	ll n;
	cin >> n;
	vl a(n + 1);
	for (ll i = 1;i <= n;i++)
		cin >> a[i];
	vl dp(n + 1);
	vl odd(n + 1);
	dp[1] = max(a[1], 0LL);
	dp[2] = max(a[1], a[2]);
	odd[1] = a[1];
	for (int i = 3;i <= n;i++) {
		if (i & 1) {
			odd[i] = odd[i - 2] + a[i];
			dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
		}
		else {
			dp[i] = max(dp[i - 2] + a[i], odd[i - 1]);
		}
	}
	cout << dp[n] << '\n';
}


Measured memory_bytes: 7948
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	ll m;
  cin>>m; m;
  vector<ll> ds(m);
  vector<ll> cs(m);
  rep(i,m){
    cin>>ds[i];
    cin>>cs[i];
  }
	ll sum=0;
	rep(i,m) sum+=ds[i]*cs[i];
	cout<<accumulate(all(cs),-1ll)+max(0ll,sum-1)/9 NL;
	// int x=ds[0];
	// --cs[0];
	// if(!cs[0]){
	// 	ds.erase(ds.begin());
	// 	cs.erase(cs.begin());
	// }
	// rep(i,m){
	// 	int d=ds[i];
	// 	int c=cs[i];
	// 	if(x+d>=0){
	// 		++re;
	// 		x+=d;
	// 		x=x/10
	// 	}
	// }
	return 0;
}




Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  vector<int> s(N);
  int sum = 0;
  rep(i, N) {
    cin >> s[i];
    sum += s[i];
  }
  
  sort(all(s));
  
  if(sum%10 != 0) {
    cout << sum << endl;
    return 0;
  }
  
  rep(i, N) {
    if((sum-s[i])%10 != 0) {
      cout << sum-s[i] << endl;
      return 0;
    }
  }
  
  cout << 0 << endl;

}

Measured memory_bytes: 256
input_n = int(input())
input_a = list(map(int, input().split()))

def calc_divtwo(n):
    return n / 2

count = 0

while (all([x%2 == 0 for x in input_a]))&(all([x != 0 for x in input_a])):
    count +=1
    input_a = list(map(calc_divtwo, input_a))
print(count)

Measured memory_bytes: 39152
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <algorithm>
using namespace std;
const int INF = 100000000;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n;
	while (cin >> n && n){
		//dp[n]はn段目に行く登り方の種類
		int dp[31];
		dp[0] = 1; dp[1] = 1; dp[2] = 2;
		for (int i = 3; i <= n; i++){
			dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
		}
		int cnt = dp[n];
		if (cnt % 10){
			cnt = cnt / 10 + 1;
		}
		else{
			cnt = cnt / 10;
		}
		if (cnt % 365){
			cnt = cnt / 365 + 1;
		}
		else{
			cnt = cnt / 10;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}


int main() {

  long n, w, h, a, b, d;
  // string s;
  vector<pair<long,long>> ft(3);
  // vector<long> b(3);

  vector<long> count(4,0);

  for(int i=0;i<3;i++){
    cin >> a >> b ;
    // ft[i] = make_pair(a, b);
    count[a-1]++;
    count[b-1]++;
  }



  bool ans = true;


  for(int i=0;i<4;i++){
    if (count[i]>=3)ans=false;
  }


  





  if (ans){
    cout << "YES" <<endl;
  }else{
    cout << "NO" <<endl;
  }


}




















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

int main() {
  int n,m;
  while(cin >> n >> m && (n||m)) {
    P a[n];
    rep(i,n) cin >> a[i].S >> a[i].F;
    sort(a,a+n,greater<P>());
    for(int i=0; i<n; i++) {
      int x=min(m,a[i].S);
      a[i].S-=x;
      m-=x;
    }
    int ans=0;
    rep(i,n) ans+=a[i].F*a[i].S;
    pr(ans);
  }
  return 0;
}


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

int n, k, ans = 0;
vector<int> l;

int main() {
  cin >> n >> k;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    l.push_back(x);
  }
  sort(l.begin(), l.end(), greater<int>());
  for(int i = 0; i < k; ++i) ans += l[i];
  cout << ans << endl;
  return 0;
}

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

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

string yn(bool x){
    return x ? "Yes" : "No";
}


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

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

    Sort(p);

    int sum = 0;
    rep(i,n){
        sum += (i != n-1 ? p[i] : p[i]/2);
    }

    cout << sum << endl;
}


Measured memory_bytes: 256