akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct tree{
    size_t n,r,m,md;
    vector<vector<int>> e;
    vector<int> pa,d,im,s;
    vector<vector<int>> lc;
    explicit tree(int n_){
        n=n_;
        e.resize(n);
        im.resize(n);
        s.resize(n);
    }
    void add(int a,int b){
        e[a].emplace_back(b);
    }
    void r_dfs(int i,int p=-1,int D=0){
        pa[i]=p;d[i]=D;md=max(md,(size_t)D);++D;
        for(auto j:e[i]) if(j!=p) r_dfs(j,i,D);
    }
    void r_i(int r_){
        pa.resize(n);d.resize(n);r=r_;md=0;
        r_dfs(r);
    }
    void dfs(int i,int p=-1){
        for(auto j:e[i]) if(j!=p) im[j]+=im[i],dfs(j,i);
    }
    void b_lca(int r_){
        r_i(r_);
        m=1;int c=1;
        while(c<=md) ++m,c*=2;
        lc.resize(n,vector<int>(m,-1));
        fr(i,n) lc[i][0]=pa[i];
        fr(i,n) fr(j,m-1) if(lc[i][j]!=-1) lc[i][j+1]=lc[lc[i][j]][j];
    }
    int lca(int a,int b){
        if(a==b) return a;
        if(d[a]>d[b]) swap(a,b);
        if(d[a]!=d[b]) ifr(i,m) if((lc[b][i]!=-1)&&(d[a]<d[lc[b][i]])) b=lc[b][i];
        if(d[a]!=d[b]) b=pa[b];
        if(a==b) return a;
        ifr(i,m) if(lc[a][i]!=lc[b][i]) a=lc[a][i],b=lc[b][i];
        if(a!=b) a=pa[a];
        return a;
    }
};

class DKi {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,q,a,b;
        in>>n>>q;
        tree t(n);
        fr(i,n-1){
            in>>a>>b;
            --a,--b;
            t.add(a,b);
            t.add(b,a);
        }
        t.r_i(0);
        fr(i,q){
            in>>a>>b;
            t.im[a-1]+=b;
        }
        t.dfs(0);
        fr(i,n) out<<t.im[i]<<" ";
        out<<endl;
    }
};

int main() {
    DKi solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 22784
s=int(input())
a=s//100
b=s%100
if a>0 and a<=12:
  if b>0 and b<=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if b>0 and b<=12:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 9036
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int ans = 0;
		for(int i = a; i <= b; i++) {
			if(c % i == 0) {
				ans++;
			}
		}
		System.out.println(ans);
		sc.close();
	}
}



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

int main(void)
{
    int N;
    scanf("%d", &N);
    for (int i = N; i > 0; i--) {
        double value = sqrt((double)i);
        if (ceil(value) - floor(value) == 0) {
            printf("%d\n", i);
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 128
from math import sqrt

def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x

def calc(a,b):
    x = gcd(a,b)
    res = 0
    if (x % 2 == 0):
        res += 1

        # Print the number of 2s that divide x
        while (x % 2 == 0):
            x = x / 2

    # x must be odd at this point. So we
    # can skip one element (Note i = i +2)
    k = int(sqrt(x)) + 1
    for i in range(3, k, 2):
        if (x % i == 0):

            # While i divides x, print i
            # and divide x
            res += 1
            while (x % i == 0):
                x = x / i

                # This condition is to handle the
    # case when x is a prime number
    # greater than 2
    if (x > 2):
        res += 1
    return res



# Driver code
if __name__ == '__main__':
    a,b = [int(i) for i in input().split()]
    print(calc(a, b)+1)

# This code is contributed by
# Surendra_Gangwar

Measured memory_bytes: 38640
a = list(map(int, input().split()))
for i in range(1,len(a)):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v

print("{} {} {}".format(a[0],a[1],a[2]))


Measured memory_bytes: 5592
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))


typedef long long lint;

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

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



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

	lint a, b; cin >> a >> b;
	co((a + b) % 24);
	gc();
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n + 1];

		for (int i = 0; i < n; i++) {
			a[sc.nextInt()] = i + 1;
		}

		for (int i = 0; i < n; i++) {
			System.out.print(a[i + 1] + " ");
		}

	}
}

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

int main() {

    int X ;

    cin >> X ;

    int sat = 0 ;

    if ( X % 500 == 0) cout << X / 500 *1000 << endl ;

    else if ( X % 5 != 0){

        for( int i = 0 ; i < 2000001 ; i++){

           if (X - i * 500 < 500 ){

               sat += i * 1000 ;

               break ;
           }

        }

        for ( int k = 0 ;  k < 100 ; k++){

            if( (X - sat/2) - k * 5 < 5){

                sat += k * 5 ;

                break ;

            }

        }

        cout << sat << endl ;

    }

}


Measured memory_bytes: 256
// A - Something on It
// https://beta.atcoder.jp/contests/abc095/tasks/abc095_a
//
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;


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

    int ans = 700;
    string S;
    cin >> S;
    ans += count(S.begin(), S.end(), 'o') * 100;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, a, A[2][100];
    cin >> N;
  	for (int j = 0; j < 2; j++){
		for (int i = 0; i < N; i++){
			cin >> a;
          	A[j][i] = a;
        }
    }
    for (int j = 1; j < N; j++){
        A[0][j] += A[0][j-1];
    }
  	A[1][0] += A[0][0];
	for (int i = 1; i < N; i++){
		A[1][i] += max(A[0][i], A[1][i-1]);
    }

    cout << A[1][N-1] << endl;
  return 0;
}

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

public class Program{
    public static void Main(){
        
        int[] dishes = new int[5];
        
        for(var i = 0; i < 5; i++){
            dishes[i] = int.Parse(Console.ReadLine());
        }
        
        var min = 0;
        
        for(var i = 1; i < 5; i++){
            
            if(dishes[i] % 10 != 0 && dishes[min] % 10 > dishes[i] % 10){
                min = i;
            }else if(dishes[min] % 10 == 0){
                min = i;
            }
        }
        for(var i = 0; i < 5; i++){
            if(i != min){
                dishes[i] = (int)Math.Ceiling((double)dishes[i] / 10) * 10;
            }
        }
        
        Console.WriteLine("{0}", dishes.Sum());
    }
}

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

int main() {
  int n, c, m, s, t, a[4], b[4];
  while (1) {
    scanf("%d", &n);
    if (!n) break;
    a[0] = a[1] = INT_MAX;
    a[2] = a[3] = -INT_MAX;
    b[0] = b[1] = b[2] = b[3] = -1;
    for (int i=0; i<n; i++) {
      scanf("%d", &c);
      t = 0.;
      for (int j=0; j<4; j++) {
        scanf("%d %d", &m, &s);
        t += 60 * m + s;
      }
      if (t < a[0]) {
        a[1] = a[0];
        a[0] = t;
        b[1] = b[0];
        b[0] = c;
      } else if (t < a[1]) {
        a[1] = t;
        b[1] = c;
      }
      if (t > a[3]) {
        a[2] = a[3];
        a[3] = t;
        b[2] = b[3];
        b[3] = c;
      } else if (t > a[2]) {
        a[2] = t;
        b[2] = c;
      }
    }
    for (int i=0; i<3; i++) {
      printf("%d\n", b[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 1028
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = [0] * M
X = [0] * M
for i in range(M):
	P[i], X[i] = map(int, input().split())

for i in range(M):
	sum = 0
	for j in range(N):
		if j == (P[i] - 1):
			sum = sum + X[i]
		else:
			sum = sum + T[j]
	print(sum)


Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  int N;
  while (cin >> N) {
    int v[2 * N];
    for (int i : range(2 * N)) cin >> v[i];
    sort(v, v + 2 * N);
    int x = 0;
    for (int i : range(N)) x += v[2 * i];
    cout << x << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

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

const ll INF = 100100100100100100;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }


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

    ll sum = 0;
    rep(i, n) sum += a[i];

    vector<ll> s(n + 1, 0);
    rep(i, n) s[i + 1] = s[i] + a[i];

    ll ans = INF;
    for (int i=1;i<n;++i) {
        ll a = s[i];
        ll b = sum - s[i];
        ans = min(ans, abs(a - b));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

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


//////////////////////////////////////////////////////////////////////////////////////b,cl

int main(){
    long long k;
    
    while(cin >> k){
        priority_queue<long long,vector<long long>,greater<long long>> que;
        for (int i = 1;i <= 9;i++) que.push(i);

        for (int i = 0;i < k - 1;i++){
            long long p = que.top();
            que.pop();
            for (int j = -1;j <= 1;j++){
                long long add = (p % 10) + j;
                if(add >= 0 and add <= 9) que.push(p * 10 + add);
            }
        } 
         cout << que.top() << endl;   
    }
}

Measured memory_bytes: 2420
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int n,m,h,K;
int score[1005];
int ti[1005];
vector<pair<int,bool> >s[1005][1005];
int main(){
    while(1){
    for(int i=0;i<1005;i++){
        for(int j=0;j<1005;j++){
            s[i][j].resize(0);
        }
    }
    vector<P>tate2[1005];
    scanf("%d %d %d %d",&n,&m,&h,&K);
    if(!n) break;
    for(int i=1;i<=n;i++){
        scanf("%d",&score[i]);
    }
    for(int i=1;i<=m;i++){
        int r,p; 
        scanf("%d %d",&r,&p);
        tate2[r].pb(mp(p,r+1));
        tate2[r+1].pb(mp(p,r));
    }
    for(int i=1;i<=n;i++){
        sort(tate2[i].begin(),tate2[i].end());
    }
    for(int i=1;i<=n;i++){
        int now=i;
        for(int k=1;k<=h;k++){
            for(int op=0;op<tate2[now].size();op++){
                if(tate2[now][op]==mp(k,now-1)){
                    s[now-1][k].pb(mp(i,false));
                    now--;
                    break;
                }else if(tate2[now][op]==mp(k,now+1)){
                    s[now][k].pb(mp(i,true));
                    now++;
                    break;
                }
            }
        }
        ti[i]=score[now];
    }
    int maxi=0;
    for(int i=0;i<1005;i++){
        for(int j=0;j<1005;j++){
            int z;
            z=(int)s[i][j].size();
            if(!z) continue;
            int ax=0,bx=0;
            for(int k=0;k<z;k++){
               if(s[i][j][k].second){
                  ax=ti[s[i][j][k].first];
               }else{
                  bx=ti[s[i][j][k].first];
               }
               if(ax && bx) break;
            }
            int dif=0;
            int rp;
            for(int ww=0;ww<s[i][j].size();ww++){
                if(s[i][j][ww].first<=K && s[i][j][ww].second){
                    dif+=(ax-bx);
                }else if(s[i][j][ww].first<=K){
                    dif+=(bx-ax);
                }
            }
            maxi=max(maxi,dif);
        }
    }
    int ans=0;
    for(int i=1;i<=K;i++){
        ans+=ti[i];
    }
    ans-=maxi;
    printf("%d\n",ans);
    }
}

Measured memory_bytes: 30364
#include <iostream>

using namespace std;

int main()
{
    long long l,r;;
    cin >> l >> r;
        /*long long num1,num2;
        num1=l/2019;
        num2=r/2019;
        if(num1==num2)
        {
            cout << min((r%2019*(r-1)%2019)%2019,(l%2019*(l+1)%2019)%2019) << endl;
        }
        else
            cout << 0 << endl;*/
        if(r-l>=2019)
            cout << 0 << endl;
        else
        {
            long long ans=999999999;
            for(long long i=l;i<=r;i++)
            {
                for(long long j=i+1;j<=r;j++)
                {
                    ans=min(i*j%2019,ans);
                }
            }
            cout << ans << endl;
        }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var x1 = sc.ReadInt();
        var y1 = sc.ReadInt();
        var x2 = sc.ReadInt();
        var y2 = sc.ReadInt();
        var dx = x1 - x2;
        var dy = y1 - y2;
        int x3 = 0, y3 = 0, x4 = 0, y4 = 0;
        x3 = x2 + dy;
        y3 = y2 - dx;
        x4 = x3 + dx;
        y4 = y3 + dy;
        Console.WriteLine(x3 + " " + y3 + " " + x4 + " " + y4);
    }

    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


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

int main(void){
    ll num=0,m=0;
    string S;
    cin >> S;
    for(int i=0; i<S.size(); i++){
        for(int j=i; j<S.size(); j++){
            if(S.at(j)=='A' || S.at(j)=='C' || S.at(j)=='G' || S.at(j)=='T'){
                num++;
            }
            else{
                break;
            }
        }
        m = max(num,m);
        num = 0;
    }
    cout << m << endl;
}

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

using namespace std;

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    char P[N];
    for(int i=0; i<N; i++){cin >> P[i];}

    int candidates = 0;
    int rank_in_f = 0;
     
    for(int i=0; i<N; i++){
        char s = P[i];
        if (s=='a'){
            if(candidates < A+B){
                cout << "Yes" << endl;
                candidates += 1;
            }else{
                cout << "No" << endl;
            }
        } else if (s == 'b') {
            rank_in_f += 1;
            if((candidates < A+B) && (rank_in_f <= B) ){
                cout << "Yes" << endl;
                candidates += 1;
            }else{
                cout << "No" << endl;
            }
        }else{
            cout << "No" << endl;
        }
    }


}

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

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if (s == u) --a;
  else --b;
  printf("%d %d\n", a, b);
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto& e : v) cin >> e;
  for (int i = n - 1; i > 0; i--) {
    cout << v[i] << " ";
  }
  cout << v[0] << endl;
  return 0;
}


Measured memory_bytes: 3084
#include<stdio.h>
int main(){
  int a[100],n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=n-1;i>=0;i--){
    if(i==n-1)printf("%d",a[i]);
    else printf(" %d",a[i]);
    
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
import sys

#入力行から整数として受け取る
def ReadLineInt():
    return [int(x) for x in sys.stdin.readline().split()]

n, c = ReadLineInt()

#働いているレコーダーは、その録画の終わる時間が記録される
recorders = [-1] * (c+1)

#ソートすることで、レコーダーのリストで録画されているものは全て自分よりも前から動いている。
programs = sorted([ReadLineInt() for _ in range(n)])

#プログラムの始まる時間よりもレコーダーの稼働が終わる時間が遅いときは、そのレコーダーは使えない
for start, end, channel in programs:
    for i in range(c):
        if recorders[i] < start:
            recorders[i] = end
            break

ans = 0

#最終的に終わる時間が記録されているレコーダーは使ったということで、何台のレコーダーが同時に使われたかを答えとして返す。
for i in range(c+1):
    if recorders[i] < 0:
        ans = i
        break

print(ans)

Measured memory_bytes: 22516
#include <atcoder/convolution>
#include <atcoder/modint>
#include <cstdio>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<mint> a(n), b(m);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        a[i] = x;
    }
    for (int i = 0; i < m; i++) {
        int x;
        scanf("%d", &x);
        b[i] = x;
    }

    auto c = convolution(a, b);

    for (int i = 0; i < n + m - 1; i++) {
        printf("%d ", c[i].val());
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 19052
// https://atcoder.jp/contests/abc068/tasks/abc068_c
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    bitset<200010> memo;
    bool flag = false;
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        if (a == 1) {
            if (memo[b]) {
                flag = true;
            }
            memo[b] = true;
        }
        if (b == n) {
            if (memo[a]) {
                flag = true;
            }
            memo[a] = true;
        }
    }
    cout << (flag ? "POSSIBLE\n" : "IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = Add.num;
        var ar = Add.arL;
        Array.Sort(ar);
        var sum = new long[num + 1];
        for (var i = 1; i <= num; i++)
            sum[i] = sum[i - 1] + ar[i - 1];
        var res = num;
        for (var i = 1; i < num; i++)
        {
            if (2 * sum[i] < ar[i])
                res = num - i;
        }
        WriteLine(res);
    }
}

public class Add
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 26460
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;

int MOD=1000000007;

int main()
{
  ll N,R,ans=0;
  cin >> N >> R;
  if(N<10) ans=R+(100*(10-N));
  else ans= R;
  cout << ans << endl;
}

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

typedef struct prime{
    unsigned long n;
    struct prime* next;
}prime;

unsigned long func(unsigned long h, unsigned long l){
    unsigned long a = h%l;
    while(a != 0){
        h = l;
        l = a;
        a = h%l;
    }
    return l;
}

unsigned long sub_func(unsigned long x){
    unsigned long c = 0;
    prime target;
    target.n = 2;
    target.next = NULL;
    if(x % 2 == 0){
        c++;
        while(x%2 == 0){
            x = x/2;
        }
    }
    prime* s = &target;
    prime* l = &target;
    for(unsigned long i=3; i*i<=x; i += 2){
        int flag = 1;
        s = &target;
        while(s != NULL){
            if(i % s->n == 0){
                flag = 0;
                break;
            }
            s = s->next;
        }
        if(flag == 0){
            continue;
        }
        if(x%i == 0){
            c++;
            l->next = (prime*)malloc(sizeof(prime));
            l = l->next;
            l->n = i;
            l->next = NULL;
            while(x%i == 0){
                x = x/i;
            }
        }
    }
    if(x>1){
        c++;
    }

    return c;
}

int main(){
    unsigned long a, b;
    scanf("%lu%lu", &a, &b);
    unsigned long h, l, g;
    if(a>b){
        h = a;
        l = b;
    }else{
        h = b;
        l = a;
    }
    g = func(h, l);
    printf("%lu", sub_func(g) + 1);

    return 0;
}

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

n.sort()

c = 0

c += n[2] - n[1]
# print(c)
if c > 0:
    n[0] += c
    n[1] += c
# print(n)
if (n[1] - n[0]) % 2 == 0:
    c += (n[1] - n[0]) // 2
else:
    c += (n[1] - n[0]) // 2 + 2
print(c)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  if(n%1000==0)
  {
    cout<<"0"<<endl;
  }else
  {
    int x=ceil(double(n/1000.00));
    x=x*1000;
    x=x-n;
    cout<<x<<endl;
  }
}

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

int main() {
    int n, m;
    while(cin >> n >> m, n){
        vector< vector<int> > g(n);
        for(int i=0;i<m;i++){
            int a, b;
            cin >> a >> b;
            a--; b--;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        // bfs
        vector<bool> invited(n, false);
        vector<int> d(n, 0);
        queue<int> que;
        que.push(0);
        invited[0] = true;
        while(!que.empty()){
            int now = que.front();
            que.pop();
            if(d[now] >= 2) continue;
            for(auto nxt : g[now]){
                if(!invited[nxt]){
                    invited[nxt] = true;
                    d[nxt] = d[now]+1;
                    que.push(nxt);
                }
            }
        }
        int cnt = 0;
        for(int i=1;i<n;i++){
            if(invited[i]) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}



Measured memory_bytes: 3160
/*
  AOJ 0281
  Title:Formation
  @kankichi573
*/
#include <stdio.h>
#define min(x,y) ((x)>(y)?(y):(x))

int Q;

int solve(int c,int a,int n)
{
        int ret,w;

        //printf("CAN=%d %d %d\n",c,a,n);

        if(c+a+n < 3 ||c==0)
                ret=0;
        else if(a==0)
                ret=c/3;
        else if(n==0)
        {
                if(2*a <= c)
                        ret=a+solve(c-2*a,0,0);
                else
                        ret=c/2;
        }
        else
        {
                w=min(c,min(a,n));
                ret=w+solve(c-w,a-w,n-w);
        }
        return(ret);
}
main()
{
        int c,a,n,ret;
        int i;

        scanf("%d",&Q);
        for(i=0;i<Q;i++)
        {
                scanf("%d %d %d",&c,&a,&n);
                ret=solve(c,a,n);
                printf("%d\n",ret);
        }
        return(0);
}

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

const long MAXN=110;
long a;

int main() {
	long n;
	cin>>n;
	register long i;
	for(i=1;i<=n;++i) {
		cin>>a;
		if(a%2==0) {
			if(a%3!=0 && a%5!=0) {
				cout<<"DENIED"<<endl;
				return 0;
			}
		}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}

Measured memory_bytes: 256
// AtCoder Beginner Contest 064
// C - Colorful Leaderboard

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long int ll;

const int R = 8;
const int R_STEP = 400;

int N;
int counts[R + 1];

int main() {

    int a;
    int rates;

    scanf("%d", &N);
    memset(counts, 0, sizeof(counts));
    for (int i = 0; i < N; i++) {
        scanf("%d", &a);
        if (a >= R * R_STEP) {
            counts[R]++;
        } else {
            for (int j = 0; j < R; j++) {
                if (a < (j + 1) * R_STEP) {
                    counts[j]++;
                    break;
                }
            }
        }
    }

    rates = 0;
    for (int j = 0; j < R; j++) {
        if (counts[j] > 0) {
            rates++;
        }
    }
    printf("%d %d\n", max(rates, 1), rates + counts[R]);

    return 0;

}





Measured memory_bytes: 128
n,m=map(int, input().split())
a=sorted(map(int, input().split()))
b=[]
for i in range(1,m):
    b.append(a[i]-a[i-1])
b.sort()
if n>=m:print(0)
elif n==1:print(a[-1]-a[0])
else:print(sum(b[:-n+1]))

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> path(N);
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        A--, B--;
        path[A].push_back(B);
        path[B].push_back(A);
    }

    vector<bool> visited(N, false);
    vector<int> ans(N, -1);
    queue<int> q;
    q.push(0);
    visited[0] = true;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto nv: path[v]) {
            if (visited[nv]) continue;
            visited[nv] = true;
            ans[nv] = v;
            q.push(nv);
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < ans.size(); i++) cout << ans[i] + 1 << endl;
}


Measured memory_bytes: 10032
def f(i,j):
    cnt = 0
    if j<W-1 and A[i][j+1]=="#":
        cnt += 1
    if j<W-1 and i>=1 and A[i-1][j+1]=="#":
        cnt += 1
    if i>=1 and A[i-1][j]=="#":
        cnt += 1
    if i>=1 and j>=1 and A[i-1][j-1]=="#":
        cnt += 1
    if j>=1 and A[i][j-1]=="#":
        cnt += 1
    if i<H-1 and j>=1 and A[i+1][j-1]=="#":
        cnt += 1
    if i<H-1 and A[i+1][j]=="#":
        cnt += 1
    if i<H-1 and j<W-1 and A[i+1][j+1]=="#":
        cnt += 1
    A[i][j] = str(cnt)
H,W = map(int,input().split())
A = [list(input().strip()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j]==".":
            f(i,j)
for i in range(H):
    print("".join(A[i]))

Measured memory_bytes: 40172
n,m=map(int,input().split())
A=[list(map(int,input().split())) for i in range(m)]
water=[1]*(n+1)
red=[0]*(n+1)
red[1]=1
for x,y in A:
    water[y] +=1
    water[x] -=1
    if red[x]==1:red[y]=1
    if water[x]==0:red[x]=0

cnt=0
for i in range(1,n+1):
    if water[i]>0 and red[i]==1:
        cnt +=1

print(cnt)

Measured memory_bytes: 28836
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

struct UnionFind {
    vector< int > data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return false;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int find(int k) {
        if(data[k] < 0) return k;
        return (data[k] = find(data[k]));
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int k) {
        return -data[find(k)];
    }
};

int main() {
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind road(n), rail(n);
    rep(i, k) {
        int p, q;
        cin >> p >> q;
        p--, q--;
        road.unite(p, q);
    }
    rep(i, l) {
        int r, s;
        cin >> r >> s;
        r--, s--;
        rail.unite(r, s);
    }
    map<pair<int, int>, int> mp;
    rep(i, n) mp[{road.find(i), rail.find(i)}]++;
    rep(i, n) cout << mp[{road.find(i), rail.find(i)}] << endl;
}

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

using namespace std;

long long a,b,c,d,ans;
int main()
{
    cin>>a>>b>>c>>d;
    ans=max(max(a*c, a*d), max(b*c, b*d));
    if(a<=0 && b>=0)
        ans=max(ans, (long long)0);
    if(c<=0 && d>=0)
        ans=max(ans, (long long)0);

    cout<<ans;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a,b,s="";
	int i,j,n,m,k;
	cin>>a>>b;
	n=a.size();
	m=b.size();
	int t[n+1][m+1];
	for(i=0;i<=n;i++)
	{
	    for(j=0;j<=m;j++)
	    {
	        if(i==0||j==0)
	        t[i][j]=0;
	        else if(a[i-1]==b[j-1])
	        t[i][j]=1+t[i-1][j-1];
	        else
	        t[i][j]=max(t[i-1][j],t[i][j-1]);
	    }
	}
	i=n,j=m;
	while(i>0&&j>0)
	{
	    if(a[i-1]==b[j-1])
	    {
	        s+=a[i-1];
	        i=i-1;
	        j=j-1;
	    }
	    else if(t[i-1][j]>=t[i][j-1])
	    {
	        i=i-1;
	    }
	    else
	    j=j-1;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

const ll mod=1000000007;

int main() {
    int N;
    cin>>N;
    vi p(N);
    rep(i,N) cin>>p[i];
    int ans=0;
    rep(i,N) {
        if(p[i]==i+1) {
            ans++;
            if(i!=N-1&&p[i+1]==i+2) i++;
        } 
    }
    cout<<ans<<endl;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

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

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

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

int H, W, D;
Pi convD(Pi p) {
	return Pi(p.second - p.first + H, p.first + p.second);
}

char convmas[1111][1111];
void Main() {
	cin >> H >> W >> D;
	for (int i = 0; i < 1111; i++) {
		for (int j = 0; j < 1111; j++) {
			int by = (i/D)&1, bx = (j/D)&1;
			if (by == 0 && bx == 0) convmas[i][j] = 'R';
			if (by == 0 && bx == 1) convmas[i][j] = 'B';
			if (by == 1 && bx == 0) convmas[i][j] = 'Y';
			if (by == 1 && bx == 1) convmas[i][j] = 'G';
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			Pi base = Pi(i, j);
			Pi ret = convD(base);
			int y, x;
			tie(y, x) = ret;
			assert(y >= 0 && x >= 0);
			cout << convmas[y][x];
		}
		cout << el;
	}
}

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


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> line(h);
  
  for (int i = 0; i < h; i++) {
  	cin >> line.at(i);
  }
  
  string sharp = "#";
  for (int i = 0; i < w; i++) {
  	sharp += "#";
  }
  sharp += "#";
  cout << sharp << endl;
  
  for (int i = 0; i < h; i++) {
  	cout << "#" + line.at(i) + "#" << endl;
  }
  
  cout << sharp << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,n,f[6],pi,zx,xc;
char pa[100009];
deque <int> de[6];
string s;
pair <int, int> p[100009];
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	a=n;
	cin>>f[1]>>f[2]>>f[3];
	for(i=1; i<=n; i++){
		cin>>s;
		if(s[0]=='A') c=1;
		if(s[0]=='B') c=2;
		if(s[0]=='C') c=3;
		if(s[1]=='A') d=1;
		if(s[1]=='B') d=2;
		if(s[1]=='C') d=3;
		p[i].first=c;p[i].second=d;
	}
	for(i=1; i<=a; i++){
		c=p[i].first;d=p[i].second;
		de[c].push_back(d);
		de[d].push_back(c);
	}
	for(i=1; i<=a; i++){
		c=p[i].first;d=p[i].second;
		if(f[c]==0&&f[d]==0){
			cout<<"No";
			return 0;
		}
		if(f[c]==0){
			f[c]++;f[d]--;
			pi++;pa[pi]=c+'A'-1;
			de[c].pop_front();
		de[d].pop_front();
			continue;
		}
		if(f[d]==0){
			f[d]++;f[c]--;
			pi++;pa[pi]=d+'A'-1;
			de[c].pop_front();
		de[d].pop_front();
			continue;
		}
		for(e=1; e<=3; e++){
			if(e!=c&&e!=d){
				break;
			}
		}
		zx=de[e].front();
		if(zx==c){
			f[c]++;f[d]--;
			pi++;pa[pi]=c+'A'-1;
		}else{
			f[d]++;f[c]--;
			pi++;pa[pi]=d+'A'-1;
		}
		//
		de[c].pop_front();
		de[d].pop_front();
	}
	cout<<"Yes"<<endl;
	for(i=1; i<=pi; i++) cout<<pa[i]<<endl;
	return 0;
}

Measured memory_bytes: 5124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC135C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] Ainput = Console.ReadLine().Split(' ');
            string[] Binput = Console.ReadLine().Split(' ');
            int[] A = new int[N + 1];
            int[] B = new int[N];
            for(int i = 0; i < N + 1; i++)
            {
                A[i] = int.Parse(Ainput[i]);
            }
            for(int i = 0; i < N; i++)
            {
                B[i] = int.Parse(Binput[i]);
            }
            long ans = 0;
            for(int i = 0; i < N; i++)
            {
                if (A[i] >= B[i])
                {
                    ans += B[i];
                }
                else
                {
                    ans += A[i];
                    B[i] -= A[i];
                    B[i] = Math.Min(B[i], A[i + 1]);
                    ans += B[i];
                    A[i + 1] -= B[i];
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 47308
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long M, std::vector<long long> d, std::vector<long long> c){
  ll ans = 0;
  rep(i,M) ans += c[i];
  ans--;
  ll temp = 0;
  rep(i,M){
    temp += d[i] * c[i]; // temp <= 1e16
  }
  cout << ans + (temp-1)/9LL << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> d(M);
  std::vector<long long> c(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&d[i]);
    scanf("%lld",&c[i]);
  }
  solve(M, std::move(d), std::move(c));
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define bug(x) cerr << (#x) << " = " << (x) << endl;
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define X first
#define Y second

using namespace std;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<double, double> dd;
typedef pair<float, float> ff;
const int Nmax = 101;
const int Wmax = 100001;
int n, w;
ll current[Wmax], Next[Wmax];
ii item[Nmax];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	scanf("%d %d", &n, &w);
	REP1(i, n) {
		scanf("%d %d", &item[i].X, &item[i].Y);
		REP0(j, w + 1) {
			Next[j] = current[j];
			if (item[i].X <= j) Next[j] = max(Next[j], current[j - item[i].X] + item[i].Y);
		}
		REP0(j, w + 1) current[j] = Next[j];
	}
	cout << Next[w];
	return 0;
}

Measured memory_bytes: 1792
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
int roundup(int a,int b){return	(a-1)/b+1;}

signed main(){
	int n;cin>>n;
	vi a(n);
	rep(i,n) cin>>a[i];
	int q=-1;
	int ans=0;
	rep(i,n-1) if(a[i]==a[i+1]){
		a[i+1]=q;
		q--;
		ans++;
	}
	cout<<ans<<endl;
}


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

typedef pair<int,int> P;
template<typename T>
using vec = vector<T>;

int N;

void solve() {
    vec<P> p(N);
    for (auto &i : p) cin >> i.first >> i.second;
    sort(p.begin(), p.end());
    int sum = 0;
    for (int i = 0; i < N - 1; i++) sum += p[i].first;
    int sub = 0;
    if (sum < p[N-1].first) sub = p[N-1].first - sum;

    vector<map<int,bool> > dp(N);
    dp[0][0] = true;
    int m = 0;
    for (int i = 0; i < N; i++) {
        for (auto x : dp[i]) {
            if (x.first > sub) break;
            m = max(x.first, m);
            if (i == N - 1) continue;
            dp[i+1][x.first] = true;
            if (x.first + p[i].second <= sub) dp[i+1][x.first + p[i].second] = true;
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) ans += p[i].first + p[i].second;

    cout << ans + sub - m << endl;
}

int main() {
    while (cin >> N, N) solve();
    return 0;
}

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

class union_find {
public:
    union_find(int n): par(vector<int>(n, -1)), components(n) {}

    bool unite(int x, int y) {
        if((x = find(x)) == (y = find(y))) {
            return false;
        } else {
            if(par[x] < par[y]) swap(x, y);
            par[y] += par[x];
            par[x] = y;
            --components;
            return true;
        }
    }

    int find(int x) {
        if(par[x] < 0) return x;
        else return par[x] = find(par[x]);
    }

    int size(int x) {
        return -par[find(x)];
    }

    int cnt() {
        return components;
    }

private:
    vector<int> par;
    int components;
};


int main() {
    int N; cin >> N;
    unordered_map<string, int> index;
    vector<int> x(N);
    for(int i=0; i<N; ++i) {
        string a; cin >> a >> x[i];
        index[a] = i;
    }

    union_find uf(N);
    int M; cin >> M;
    while(M--) {
        string s, t; cin >> s >> t;
        uf.unite(index[s], index[t]);
    }

    unordered_map<int, int> minx;
    for(int i=0; i<N; ++i) {
        int p = uf.find(i);
        if(minx.count(p)) minx[p] = min(minx[p], x[i]);
        else minx[p] = x[i];
    }
    int res = 0;
    for(auto p : minx) res += uf.size(p.first) * p.second;
    cout << res << endl;
}


Measured memory_bytes: 3996