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

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

template<typename T>
struct LazySegmentTree {
private:
    int n;
    vector<T> node, lazy;
    
public:
    LazySegmentTree(vector<T> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.assign(2*n-1, 0);
        
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }   
    
    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r-l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }   
            lazy[k] = 0;
        }   
    }   
    
    void add(int a, int b, T x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }   
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }   
    }   
    
    T getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n; 
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        T vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        T vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }   
};

int main() {
    ll n, d, a; cin >> n >> d >> a;
    vector<pair<ll, ll>> temp(n);
    rep(i, n) cin >> temp[i].first >> temp[i].second;
    sort(temp.begin(), temp.end());
    vector<ll> x(n), h(n);
    rep(i, n) {
        x[i] = temp[i].first;
        h[i] = temp[i].second;
    }

    rep(i, n) {
        if (h[i] % a == 0) h[i] = h[i] / a;
        else h[i] = h[i] / a + 1LL;
    }

    vector<int> to(n);

    rep(i, n) {
        // x[i] + 2*d　を超える最大のx
        int idx = upper_bound(x.begin(), x.end(), x[i] + 2*d) - x.begin();
        idx--;
        to[i] = idx;
    }

    ll ans = 0;

    vector<ll> memo(n+1);
    LazySegmentTree<ll> seg(h);
    rep(i, n) {
        ll num = seg.getsum(i, i+1);
        if (num > 0) {
            ans += num;
            seg.add(i, to[i]+1, -num);
        }
    }

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


    


Measured memory_bytes: 18560
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<String, Integer> hm = new HashMap<>();
		String str;
		for (int i = 0; i < n; i++) {
			str = sc.next();
			if (hm.containsKey(str)) {
				hm.put(str, hm.get(str) + 1);
			} else {
				hm.put(str, 1);
			}
		}
		int m = sc.nextInt();
		for (int i = 0; i < m; i++) {
			str = sc.next();
			if (hm.containsKey(str)) {
				hm.put(str, hm.get(str) - 1);
			} else {
				hm.put(str, -1);
			}
		}
		int max = 0;
		for (String s : hm.keySet()) {
			max = Math.max(max, hm.get(s));
		}
		System.out.println(max);
	}
}


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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

#define MAX_LR 100000
int similars[MAX_LR+1];
int similars_sum[MAX_LR+2];
int prime[MAX_LR+1];

int main(){
    ios::sync_with_stdio(false);
    
    fill(prime, prime+MAX_LR+1, 1);
    prime[0] = 0;
    prime[1] = 0;
    int cur = 2;
    while(cur <= MAX_LR) {
        if (prime[cur]) {
            // cout << cur << endl;
            for(int i = cur*2; i <= MAX_LR; i+=cur) prime[i] = 0;
        }
        cur++;
    }
    
    FOR(i, 1, MAX_LR+1) {
        if (prime[i] && prime[(i+1)/2]) {
            similars[i] = 1;
        }
    }

    FOR(i, 0, MAX_LR+1) {
        similars_sum[i+1] = similars_sum[i] + similars[i];
    }
    
    int Q;
    cin >> Q;
    REP(i, Q) {
        int l, r;
        cin >> l >> r;
        cout << similars_sum[r+1] - similars_sum[l] << endl;
    }
    
    return 0;
}


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

#define pii pair<int, int>
#define x first
#define y second

int n, m;
int dp[11][110000];

int main() {
    scanf("%d %d", &n, &m);
    fill_n(dp[0], 11 * 110000, (int)1e9);
    dp[0][0] = 0;
    m /= 100;
    for(int i = 1; i <= n; ++i) {
        int a, b; scanf("%d %d", &a, &b);
        vector<pii> V;
        V.emplace_back(0, 0);
        for(int j = 1; j < a; ++j) V.emplace_back(j, j * i);
        V.emplace_back(a, a * i + (b / 100));
        for(pii x : V) for(int j = x.y; j < 110000; ++j) dp[i][j] = min(dp[i][j], dp[i-1][j-x.y] + x.x);
    }
    int ans = 1e9;
    for(int j = m; j < 110000; ++j) ans = min(ans, dp[n][j]);
    printf("%d\n", ans);
}


Measured memory_bytes: 4992
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(N):
  ans += B[A[i]-1]
  if i > 0 and A[i] == A[i-1] + 1:
    ans += C[A[i-1]-1]
print(ans)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll c[30],s[400][30];

int main()
{
	int D;
	cin >> D;
	rep(i,26)
	{
		cin >> c[i];
	}
	rep(i,365)
	{
		rep(j,26)
		{
			cin >>s[i][j];
		}
	}
	rep(i,365)
	{
		cout << (i%26+1) << endl;
	}
	return 0;
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
     cin>>a>>b;
    int c=0;
    for(int i=0;i<=a;i++)
    {
        c=a-i;
        if(4*i+2*c==b)
        {
            cout<<"Yes"<<endl;
            exit(0);
    }
    }
    cout<<"No"<<endl;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i <n; i++)
    {
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    int ans = h.at(h.size() - 1);
    for(int i = 0; i <= n - k; i++)
    {
        if (ans > (h.at(i + k - 1) - h.at(i))) {
            ans = h.at(i + k - 1) - h.at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
s=input()
dp = [[0 for _ in range(4)] for _ in range(len(s)+1)]
dp[0][0] = 1
for i in range(len(s)):
    for j in range(4):
        dp[i][j] %= 10**9+7
        if s[i]=="?":
            dp[i+1][j] += (3*dp[i][j])
        else:
            dp[i+1][j] += dp[i][j]

    if s[i] == "A" or s[i] == "?":
        dp[i+1][1] += dp[i][0]
    if s[i] == "B" or s[i] == "?":
        dp[i+1][2] += dp[i][1]
    if s[i] == "C" or s[i] == "?":
        dp[i+1][3] += dp[i][2]

print(dp[-1][-1] % (10**9+7))

Measured memory_bytes: 56028
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

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

    int N=S.length();

    if(N==1){
        if(S[0]=='3'){
            cout<<"bon"<<endl;
        }else if(S[0]=='0'||S[0]=='1'||S[0]=='6'||S[0]=='8'){
            cout<<"pon"<<endl;
        }else{
            cout<<"hon"<<endl;
        }

    }else if(N==2){
        if(S[1]=='3'){
            cout<<"bon"<<endl;

        }else if(S[1]=='0'||S[1]=='1'||S[1]=='6'||S[1]=='8'){
            cout<<"pon"<<endl;

        }else{
            cout<<"hon"<<endl;

        }

    }else if(N==3){
        if(S[2]=='3'){
            cout<<"bon"<<endl;

        }else if(S[2]=='0'||S[2]=='1'||S[2]=='6'||S[2]=='8'){
            cout<<"pon"<<endl;
        }else{
            cout<<"hon"<<endl;

        }

    }

}


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

using namespace std;

typedef long long swl;

swl sum(swl n) {
  return n*(n+1)/2;
}

int main(void) {
  int n; cin >> n;
  
  string str[n];
  map<string, int> ang;

  for (int i = 0; i < n; i++) {
    cin >> str[i];
    sort(str[i].begin(), str[i].end());

    if (ang.count(str[i]) > 0) {
      ang[str[i]]++;
    } else {
      ang.insert(make_pair(str[i], 1));
    }
  }
  
  swl ans = 0;
  for (auto it = begin(ang); it != end(ang); it++) {
    ans += sum((swl)it->second - 1);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 18176
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string X = Console.ReadLine();
		int ct = 0;
		int[]A = new int[N];
		for(var i=0;i<X.Length;i++){
			int s = int.Parse(X.Substring(i,1));
			if(s==1){
				A[i] = 1;
				ct++;
			}
		}
		int[,]B = new int[N,4];
		int t = 1;
		int a = 0;
		for(var j=N-1;j>=0;j--){
			if(A[j]==1){
				a = (a + t) % (ct+1);
            }
			B[j,0] = a;
			t = (t * 2) % (ct+1);
		}
		t = 1;
		a = 0;
		for(var j=N-1;j>=0;j--){
          	if(ct>1){
				if(A[j]==1){
					a = (a + t) % (ct-1);
				}
				B[j,1] = a;
				t = (t * 2) % (ct-1);
            } else {
				B[j,1] = 0;
            }
		}
		t = 1;
		for(var j=N-1;j>=0;j--){
			B[j,2] = t;
          	t = (t * 2) % (ct+1);
		}
		t = 1;
		for(var j=N-1;j>=0;j--){
			if(ct>1){
				B[j,3] = t;
				t = (t * 2) % (ct-1);
			} else {
				B[j,3] = 0;
			}
		}
		int[]C = new int[200002];
		for(var i=1;i<=200001;i++){
			int at = i;
			int c = 1;
			int ca = 0;
			while(true){
				if(at/c%2==1){
					ca++;
				}
				c *= 2;
				if(c>at){
					break;
				}
			}
			int d = at % ca;
			C[at] = C[d]+1;
		}
		for(var i=0;i<N;i++){
			if(A[i]==0){
              	int a3 = B[0,0]+B[i,2];
				Console.WriteLine(C[a3%(ct+1)]+1);
			} else {
				if(ct==1){
                  	Console.WriteLine(0);
                } else {
					int a3 = (B[0,1]-B[i,3]+(ct-1))%(ct-1);
					Console.WriteLine(C[a3%(ct-1)]+1);
                }
			}
		}
	}
}

Measured memory_bytes: 26588
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - XYZ Triplets
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 10000;

/* typedef */

/* global variables */

int fs[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int x = 1, x2; (x2 = x * x) < n; x++)
    for (int y = 1, y2; x2 + (y2 = y * y) < n; y++)
      for (int z = 1, z2; x2 + y2 + (z2 = z * z) < n; z++) {
	int m = x2 + y2 + z2 + x * y + y * z + z * x;
	if (m <= n) fs[m]++;
	else break;
      }

  for (int i = 1; i <= n; i++) printf("%d\n", fs[i]);
  return 0;
}


Measured memory_bytes: 3228
(function (input) {
    var inputs = input.replace(/\r/g, '').split("\n"),
        index = 0,
        salesData = [],
        exist;

    while(inputs[index] !== '0') {

        salesData = [];
        exist = false;
        n = parseInt(inputs[index++]);

        for(i = index; i < n + index; i++) {

            datas = inputs[i].split(' ');
            num = parseInt(datas[0]);
            sales = parseInt(datas[1]) * parseInt(datas[2]);

            for ( var j = 0, len = salesData.length; j < len; j++ ) {
                // 既に入力されている社員の場合
                if ( salesData[j].num === num ) {
                    salesData[j].sales += sales;
                    break;
                }
            }
            // 入力されていなかった場合、入力値をその社員の初期値とする
            if ( j >= len ) {
                salesData.push({
                    num: num,
                    sales: sales
                });
            }
        }

        salesData.forEach(function(employee) {
            if(employee.sales >= 1000000) {
                console.log(employee.num);
                exist = true;
            }
        });

        if(!exist) {
            console.log('NA');
        }

        index += n;
    }
})(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 10692
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
int main(void){
 long long int a, b, k;
 cin >> a >> b >> k;
 if(a < k){
     b = b - (k - a);
     if(b < 0) b = 0;
     a = 0;
 }else if(a == k){
     a = 0;
 }else{
     a = a - k;
 }
 cout << a << " " << b << endl;
}


Measured memory_bytes: 256
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

from decimal import Decimal, getcontext
getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()
import math
# slist = "abcdefghijklmnopqrstuvwxyz"
A,B = input().split()
# A = int(A)
# B = float(B)*10000

# B = round(B,-2)
# ans = A*B//10000

A = Decimal(A)
B = Decimal(B)

ans = A*B

# print(A,B,ans)
print(int(ans))
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){
    return (a % b+b) % b;
}
ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}
void Yes(){
    cout << "Yes" << endl;
}
void No(){
    cout << "No" << endl;
}
void Judge(bool b){
    b ? Yes() : No();
}
void YES(){
    cout << "YES" << endl;
}
void NO(){
    cout << "NO" << endl;
}
void JUDGE(bool b){
    b ? YES() : NO();
}
ll powmod(ll b, ll e){
    ll r = 1;
    while (e > 0) {if (e & 1) r = (r % MOD) * (b % MOD) % MOD; b = (b % MOD) * (b % MOD) % MOD; e >>= 1;} return r;
}
double distance(ll x1, ll y1, ll x2, ll y2){
    return sqrt((x1-x2) * (x1-x2)+(y1-y2) * (y1-y2));
}

template<class T>bool chmax(T &a, const T &b) {
    if (a < b) { a = b; return 1; } return 0;
}
template<class T>bool chmin(T &a, const T &b) {
    if (b < a) { a = b; return 1; } return 0;
}
template<typename T>
void ppp(T n){
    cout << n << endl;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa {
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15);
    };
} fastio;

int main(){

    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];

    sort(d.begin(), d.end());
	ppp(d[n/2]-d[n/2-1]);

    return 0;
}


Measured memory_bytes: 640
<?php
list($k,$n)=explode(" ",trim(fgets(STDIN)));
$a=explode(" ",trim(fgets(STDIN)));
$ans=$a[$n-1]-$a[0];
$i=1;
while($i<$n){
  if($ans>$a[$i-1]+$k-$a[$i]){
    $ans=$a[$i-1]+$k-$a[$i];
  }
  ++$i;
}
echo $ans;

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

int main(){
	
	string sim ;
	int n;
	int base=0 , point=0 , count=0 ;
	
	cin >> n ;
	
	for( int i=0 ; i<n ;){
		cin >> sim ;
		
		if( sim == "HIT" ){
			base++;
			if( base == 4 ){
				base=3;
				point++;
			}
		}
		else if( sim == "HOMERUN" ){
			point += base+1 ;
			base=0;
		}
		else if( sim == "OUT" ){
			count++;
			if( count%3 == 0 ){
				cout << point << endl ;
				i++;
				base=0;
				point=0;
			}
		}
	}
	
return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define mem(dp,a) memset(dp,a,sizeof dp);
#define all(a) a.begin(),a.end()
#define sall(a) sort(all(a))
#define X first
#define Y second
typedef long long int ll;
typedef pair<ll,ll> pp;

#define debug(x) cout << #x << " :: "<< x <<"\n";
#define debug2(x,y) cout << #x << " :: "<< x << "\t" << #y << " :: " << y << "\n";
#define debug3(x,y,z) cout << #x << " :: "<< x << "\t" << #y << " :: " << y << "\t" << #z << " :: " << z << "\n";
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree< pp , null_type,less< pp >, rb_tree_tag,tree_order_statistics_node_update>

ll power(ll b, ll exp){
    ll res = 1;
    while(exp > 0){
        if(exp % 2){
            res = 1LL * res * b % mod;
        }
        b = 1LL * b * b % mod;
        exp /= 2;
    }
    return res;
}

int main()
{
    boost
    ll n,m,k;
    cin >> n >> m >> k;
    char a[n][m];
    ll cnt=0,ans=0;
    for(ll i=0;i<n;i++) {
        for(ll j=0;j<m;j++) {
            cin >> a[i][j];
            if( a[i][j]=='#' )
                cnt++;
        }
    }
    for(ll i=0;i<(1LL<<n);i++)    {
        for(ll j=0;j<(1LL<<m);j++)    {
            ll temp=cnt;
            for(ll r=0;r<n;r++) {
                for(ll c=0;c<m;c++) {
                    if( ( ((1LL<<r)&i) || ((1LL<<c)&j) ) && a[r][c]=='#' ) {
                        temp--;
                    }
                }
            }
            if( temp==k )   {
                ans++;
            }
        }
    }
    cout << ans ;
    return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int i = 0, j = n - 1;
  int res = false;
  int cnt = 0;
  while (cnt < n) {
    if (s == t) {
      res = true;
      break;
    }
    char last = s[n - 1];
    s.erase(n - 1, 1);
    s = last + s;
    cnt++;
  }
  if (res) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll n;
  cin>>n;
  ll a[n+1]={};
  ll sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }

  ll c=n*(n+1)/2;
  ll times=sum/c;
  if(sum%c!=0){
    cout<<"NO"<<endl;
    return 0;
  }

  ll d[n+1]={};
  for(int i=1;i<n;i++){
    d[i]=a[i]-a[i-1];
    d[i]-=times;
  }
  d[0]=a[0]-a[n-1]-times;

  int flag=0;
  int cnt=0;
  for(int i=0;i<n;i++){
    if(d[i]>0) break;
    if(d[i]%n!=0) break;
    cnt+=-d[i]/n;
    if(cnt>times) break;
    if(i==n-1&&times==cnt) flag=1;
  }
  if(flag) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}


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

ll solve() {
    ll N;
    cin >> N;
    ll c = 0;
    for ( int i = 1; i <= N; i++ ) {
        if ( to_string(i).size() % 2 == 1) c++;
    }
    return c;    
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

  string s; cin >> s;

  map<char, int> mp;
  for(int i=0;i<SZ(s);++i) {
    mp[s[i]]++;
  }

  bool ok = true;
  for(const auto &e: mp) {
    if(e.second % 2) {
      ok = false;
      break;
    }
  }

  cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 999999999999
#define F first
#define S second
#define eb emplace_back
#define mp make_pair
#define P(x) cout<<__LINE__ <<": "<<#x<<' '<<(x)<<'\n'
#define dbg cout<<__LINE__ <<": 0manush\n"
#define read(x) freopen("input.txt","r",stdin)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pi 2*acos(0.0)
#define ee exp(1)
#define mx 200009
#define mod 1000000007
using namespace std;

int main(){//read(x);
fast;
ll r,g,h,i,j,x,t,y,z=0,e,f;

double a,b,c,d,l;
cin>>a>>b>>c;
d=a/c;
if(d>b)cout<<"No\n";
else cout<<"Yes\n";


}























Measured memory_bytes: 3740
#include <iostream>

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define mod 1000000007
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} //log(a+b) complexity
int help(string s){
	int ans=0;
	for(int i=0;i<s.size();i++){
		ans+=s[i]-'0';
	}
	return ans;
}
void testcase(){
string s;
cin>>s;
bool ok=false;
int sum=help(s);
if(sum%9==0){
	ok=true;
}
cout<<(ok?"Yes":"No")<<endl;

return;
}
int32_t main(){
ios_base::sync_with_stdio(false); 
   cin.tie(NULL);
 cout.tie(NULL); 
int t=1,k=1;
//cin>>t;
do{
//cout<<"Case #"<<k<<":"<<" ";
testcase();
k++;
t--;
}while(t>0);

return 0;
}


Measured memory_bytes: 3736
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long 
using namespace std;

signed main() {
	int N,D;
	cin >> N >> D;
	if(N % (1 + D * 2) == 0) {
      	cout << N / (1 + D * 2) << endl;
    }
  	else {
      	cout << N / (1 + D * 2) + 1 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
const long long INF = 1LL << 60;
// map<int,int> mp;

int main() {
  ll a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
}

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

int main() {
    int a,b;
    cin >> a >> b;

    if(a >= 13){
        cout << b << endl;
    }else if(a >= 6){
        cout << b / 2 << endl;
    }else{
        cout << 0 << endl;
    }
}


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

int main ()
{
	long long int n;
	cin>>n;
	int flag1=1;
	long long int i=n;
	
	if (n%2!=0)
	{
	  cout<<n*2;	
	}
	
	else 
	{
		while (flag1)
	{
		if (i%n==0 && i%2==0)
		{
			
				cout<<i;
				flag1=0;
				break;
			
		
		}
		else 
		{
			i++;
			continue;
			
		}
		
	}
	
	}
	
		
	
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define endl '\n'
//#define for(a,b) for(int i=a;i<b;i++)
vector<int> adj[100005];
long long int ans=0;
void fxn(int n)
{	
	adj[n][0]+= max(adj[n+1][1],adj[n+1][2]);
	adj[n][1]+= max(adj[n+1][0],adj[n+1][2]);
	adj[n][2]+= max(adj[n+1][0],adj[n+1][1]);
	
	if(n==0) return ;
	fxn(n-1);
	
}
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	int n,a,b,c;
	cin>>n;
	for(int i=0;i<n;i++) adj[i].clear();
	for(int i=0;i<n;i++){
	    cin>>a>>b>>c;
		adj[i].pb(a); adj[i].pb(b); adj[i].pb(c);
	}
	if(n==1) cout<<max(adj[0][2],(max(adj[0][0],adj[0][1])));
	else
	{fxn(n-2);
	cout<<max(adj[0][2],(max(adj[0][0],adj[0][1])))<<endl; }
	return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;

int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n;
        cin >> n;
        int a[n+1],b[n+1],c[n+1];
        for(int i=0; i<n; i++){
            cin >> a[i] >> b[i] >> c[i];
        }
        int dp[n+1][3];
        dp[0][0]=a[0];
        dp[0][1]=b[0];
        dp[0][2]=c[0];
        for(int i=1; i<n; i++){
            dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
            dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
            dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
        }
        cout <<max3(dp[n-1][0],dp[n-1][1],dp[n-1][2]) << '\n';
}

Measured memory_bytes: 4992
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func countingSort(as []int, bs []int, k int) {
	cs := make([]int, k+1)
	for _, x := range as {
		cs[x] = cs[x] + 1
	}
	for i := 1; i < k+1; i++ {
		cs[i] = cs[i] + cs[i-1]
	}
	for i := (len(as) - 1); i >= 0; i-- {
		bs[cs[as[i]]-1] = as[i]
		cs[as[i]] = cs[as[i]] - 1
	}
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func printArray(xs []int) {
	fmt.Println(strings.Trim(fmt.Sprint(xs), "[]"))
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	as := make([]int, n)
	k := 0
	for i := 0; i < n; i++ {
		x := nextInt(sc)
		as[i] = x
		if x > k {
			k = x
		}
	}
	bs := make([]int, n)
	countingSort(as, bs, k)
	printArray(bs)
}



Measured memory_bytes: 73852
n = gets.to_i
s = gets.chomp
a = Array.new(n,0)
n.times do |i|
  if s[i] == "E"
    a[i] += 1
  else
    a[0] += 1
    a[i] -= 1
  end
end
for i in 1..n-1
  a[i] += a[i-1]
end
max = a.index(a.max)
ans = 0
for i in 0..n-1
  if (i < max && s[i] =="W") || (i > max && s[i] == "E")
    ans += 1
  end
end
puts ans

Measured memory_bytes: 4868
#include<stdio.h>

#define QUEUE_SIZE 1000000  /* ?????????????????\????????????????????§??° */
#define SUCCESS     1       /* ?????? */
#define FAILURE     0       /* ??±??? */

typedef struct{
	char name[10];
	int  time;
}PROCESS;

typedef PROCESS data_t;	/* ???????????? */

data_t queue_data[QUEUE_SIZE]; /* ???????????????????????¬??? */
int queue_head;                /* ??????????????? */
int queue_num;                 /* ??????????????° */

int enqueue(data_t enq_data)
{
    if (queue_num < QUEUE_SIZE) {
        queue_data[(queue_head + queue_num) % QUEUE_SIZE] = enq_data;
        queue_num ++;
        return SUCCESS;
    } else {
        return FAILURE;
    }
}

int dequeue(data_t *deq_data)
{
    if (queue_num > 0) {
        *deq_data = queue_data[queue_head];
        queue_head = (queue_head + 1) % QUEUE_SIZE;
        queue_num --;
        return SUCCESS;
    } else {
        return FAILURE;
    }
}

int main(void){
	int n, q, i;
	int t = 0;	//????????????
	queue_head = 0;
	queue_num = 0;
	data_t process;
	
	scanf("%d %d", &n, &q);
	
	//???????????????n??????????´?
	for(i = 0; i < n; i++){
		scanf("%s %d", process.name, &process.time);
		enqueue(process);
	}
	
	while(queue_num){
		dequeue(&process);
		process.time -= q;
		if(process.time <= 0){
			t += q + process.time;
			printf("%s %d\n", process.name, t);
		}else{
			t += q;
			enqueue(process);
		}
	}
	
	return 0;
}

Measured memory_bytes: 4692
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main(void){
  long long int  n, a[200000], b;
  long long int  i, c, f, sum = 0;

  cin >> n;
  for(i = 0; i < n + 1; i++){
    cin >> a[i];
  }
  for(i = 0; i < n; i++){
    cin >> b;
    c = a[i] + a[i + 1];
    f = c - b;
    if(f <= 0){
      sum += a[i] + a[i + 1];
      a[i + 1] = 0;
    }
    else if(a[i] >= b){
      sum += b;
    }
    else{
      sum += b;
      a[i + 1] = f;
    }
  }
  cout << sum << endl; 
  return 0;
}

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

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;

int main() {
  int n, tt;
  scanf("%d%d ", &n, &tt);
  int INF = 1000000;
  int c = INF, t;
  REP(i,n) {
    int x;
    scanf("%d%d ", &x, &t);
    if (t <= tt) c = min(c, x);
  }
  if (c == INF)
    puts("TLE");
  else
    printf("%d\n", c);
  return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
		input = input.split(" ");
	
	//文字列から10進数に変換するときはparseIntを使います
	    var A = parseInt(input[0], 10);
    var B = parseInt(input[1], 10);
  var c = 0;
  var c =(A +B)%2;
 // console.log(c);
  if (c== 0){console.log((A+B)/2);
            }else{console.log("IMPOSSIBLE");
                 }
  
  
  	   }    //    1    
     
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


Measured memory_bytes: 21064
import bisect
n=int(input())
x=[int(s)-1 for s in input().split()]
l=int(input())
q=int(input())
p=[[0]*17 for _ in range(n)]
for i in range(n):
    p[i][0]=bisect.bisect_right(x,x[i]+l)-1
for i in range(1,17):
    for j in range(n):
        p[j][i]=p[p[j][i-1]][i-1]
for _ in range(q):
    a,b=sorted(int(s)-1 for s in input().split())
    r=0
    for i in reversed(range(17)):
        if p[a][i]<b:
            a=p[a][i]
            r+=1<<i
    print(r+1)

Measured memory_bytes: 88120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str + sep);
    string buffer;
    while( getline(ss,buffer,sep ) ) v.pb(buffer);
    return v;
}

int Na,Nt,Ng,Nc;
int m;

const int N = 52;
const ll mod = 1e9+7;

vector<string> x;
int X;

ll dp[N][N][N][N];
ll dfs(int a, int t, int g, int c){
    if(a>Na || t>Nt || g>Ng || c>Nc) return 0;

    int idx = a+t+g+c;
    if(idx == X){
        return (a==Na && t==Nt && g==Ng && c==Nc);
    }

    if(dp[a][t][g][c]>=0) return dp[a][t][g][c];

    string f = x[idx];
    ll ret = 0;
    rep(i,f.size()){
        if(f[i]=='A') ret += dfs(a+1,t,g,c);
        else if(f[i]=='T') ret += dfs(a,t+1,g,c);
        else if(f[i]=='G') ret += dfs(a,t,g+1,c);
        else if(f[i]=='C') ret += dfs(a,t,g,c+1);
        ret %= mod;
    }
    return dp[a][t][g][c] = ret;
}

int main(){
    cin >>Na >>Nt >>Ng >>Nc >>m;
    cin.ignore();

    map<string,int> t2id;
    vector<vector<string>> v(m);
    rep(i,m){
        string s;
        getline(cin,s);
        vector<string> vs = split(s, ' ');

        string t = vs[0];
        t = t.substr(0,t.size()-1);
        t2id[t] = i;

        for(int j=1; j<vs.size(); ++j) v[i].pb(vs[j]);
    }

    // precalc for length
    vector<ll> L(m);
    for(int i=m-1; i>=0; --i){
        rep(j,v[i].size()){
            if(v[i][j][0]=='[') ++L[i];
            else{
                int idx = t2id[v[i][j]];
                L[i] += L[idx];
            }
        }
    }

    // Over Length
    if(L[0] > Na+Nt+Ng+Nc){
        cout << 0 << endl;
        return 0;
    }

    // calc DP
    for(int i=m-1; i>=0; --i){
        vector<string> new_v;
        rep(j,v[i].size()){
            if(v[i][j][0]=='[') new_v.pb(v[i][j].substr());
            else{
                int idx = t2id[v[i][j]];
                for(string a:v[idx]) new_v.pb(a);
            }
        }
        v[i] = new_v;
    }

    x = v[0];
    X = x.size();
    memset(dp,-1,sizeof(dp));
    cout << dfs(0,0,0,0) << endl;
    return 0;
}



Measured memory_bytes: 60360
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
#define inI(x) scanf("%d",&x)
#define inI2(x,y) scanf("%d %d",&x,&y)
#define inI3(x,y,z) scanf("%d %d %d",&x,&y,&z)
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
char c[200005];
int len;
vector<int>v[30];
int main()
{
    scanf("%s",c+1);
    len=strlen(c+1);
    for(int i=1;i<=len;i++)
    {
        v[c[i]-'a'].push_back(i);
    }
    for(int i=0;i<26;i++)
    {
        for(int j=1;j<v[i].size();j++)
        {
            if(v[i][j]-v[i][j-1]<3)
            {
                printf("%d %d",v[i][j-1],v[i][j]);
                return 0;
            }
        }
    }
    printf("-1 -1");
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=3e5+10;
int main()
{
    FASTINOUT;
    int x,y,z;
    cin>>x>>y>>z;
    int m=x*100+y*10+z;
    if (m%4==0)
        cout<<"YES\n";
    else
        cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <unordered_map>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)

using namespace std;

int main(void){
	string S;
	int i,j;
	long num=0,num2,ans;
	cin >> S;
	long dp2[2019]={};
	myfor(i,S.size()){	
		long dp[2019]= {};	
		myfor(j,2019){
			num2 = (j*10 + long(S[i] - '0'))%2019;
			dp[num2] += dp2[j];
		}	
		num = long(S[i] - '0')%2019;
		dp[num]++;
		ans+=dp[0];
		memcpy(dp2,dp,sizeof(dp));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3332
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;

int main(){
    long long a,b;
    cin >> a >> b;

    long long i=max(a,b);
    long long j=i;
    while(1){
        if(j%a==0 && j%b==0){
            cout << j << endl;
            return 0;
        }
        j += i;
    }
    
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 2000000
#define K 10010

int A[MAX], B[MAX];

void CountingSort(int A[], int N, int B[]) {
	int C[K] = { 0 };
	for (int i = 0; i < N; i++) {
		C[A[i]]++;
	}
	for (int i = 1; i < K; i++) {
		C[i] += C[i - 1];
	}
	for (int i = N - 1; i >= 0; i--) {
		C[A[i]]--;
		B[C[A[i]]] = A[i];
	}

}

int main() {
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	CountingSort(A, N, B);
	for (int i = 0; i < N; i++) {
		if (i)printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 17456
#include<bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define inlld(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define inlld2(x, y) scanf("%lld%lld", &x, &y)
#define inlld3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define ind2(x, y) scanf("%d%d", &x, &y)
#define ind3(x, y, z) scanf("%d%d%d", &x, &y, &z)

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

typedef long long ll;
typedef long double ld;

using namespace std;

struct line
{
    ll sl, cn;
    line(ll s, ll c)
    {
        sl=s;
        cn=c;
    }
};

//VERY IMPORTANT, CHANGE IF NEEDED:
//GETTING LINES IN DECREASING ORDER OF SLOPE
//CHANGE CHECK CONDITION FOR THE REVERSE
struct CHT
{
    vector<line>lines;
    int pointer;

    void set_pointer()
    {
        pointer=0;
    }

    bool check()
    {
        int x=lines.size();
        line lt=lines[x-3], rt=lines[x-1], mid=lines[x-2];
        //CHANGE FOLLOWING CONDITION IF NEEDED
        return (rt.cn-lt.cn)*(lt.sl-mid.sl)<(mid.cn-lt.cn)*(lt.sl-rt.sl);
    }

    void add(line x)
    {
        lines.pb(x);
        while(lines.size()>=3 && check())
            lines.erase(lines.end()-2);
    }

    ll query(ll x)
    {
        if(pointer>=lines.size())
            pointer=lines.size()-1;
        //CHANGE FOLLOWING CONDITION IF NEEDED
        while(pointer<lines.size()-1 &&
            lines[pointer+1].sl*x+lines[pointer+1].cn<
                lines[pointer].sl*x+lines[pointer].cn)
            pointer++;
        return lines[pointer].sl*x+lines[pointer].cn;
    }
};

CHT cht;
ll dp[N], h[N], C, n;

int main()
{
    inlld2(n, C);
    for(ll a=1; a<=n; a++)
    {
        dp[a]=1e18;
        inlld(h[a]);
    }
    dp[1]=0;
    cht.add(line(-2*h[1], dp[1]+h[1]*h[1]));
    for(ll a=2; a<=n; a++)
    {
        dp[a]=min(dp[a], cht.query(h[a])+h[a]*h[a]+C);
        cht.add(line(-2*h[a], h[a]*h[a]+dp[a]));
    }
    printf("%lld\n", dp[n]);
    return 0;
}

Measured memory_bytes: 9456
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back

int main() {
  ll n;
  cin >> n;

  ll t = n, cnt = 0;
  int digit = 0, tmp = 0;
  while (t > 0) {
    if (t / 10 == 0) digit = t % 10;
    tmp += t % 10;
    t /= 10, cnt++;
  }
  int res = digit + (cnt-1) * 9;
  if (tmp != res) res--;

  cout << res << endl;
}


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

#define Pair pair<int,int>
#define Opl pair<Pair,Pair>

int H, W;

bool a[501][501];


void print_ans(vector<Opl> v){
	cout << v.size() << endl;
	for(int i=0;i<v.size();i++){
		Pair o_1 = v[i].first;
		Pair o_2 = v[i].second;
 
		cout << o_1.first << " " << o_1.second;
		cout << " ";
		cout << o_2.first << " " << o_2.second;
		cout << endl;
	}
}






void solve(){
	vector<Opl> ans;
	Pair prev;

	int right=1; int flag=0;

	for(int i=1;i<=H;i++){
		if(right){
			for(int j=1;j<=W;j++){
				if(flag){
					ans.push_back({prev,{i,j}});
				}
				if(a[i][j]) flag^=1;
				prev = {i,j};
			}
		}else{
			for(int j=W;1<=j;j--){
				if(flag){
					ans.push_back({prev,{i,j}});
				}
				if(a[i][j]) flag^=1;
				prev = {i,j};
			}
		}
		right^=1;
	}
	print_ans(ans);

}


int main(){
	cin >> H >> W;

	int A;

	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			cin >> A;
			if(A%2==1) a[i][j]=true;
		}
	}

	solve();

	return 0;
}

Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>d(n);
  int sum=0;
  for (int i=0; i<n; i++) cin>>d[i];
  for (int i=0; i<n; i++){
    for (int j=i+1; j<n; j++){
      sum += d[i]*d[j];
    }
  }
  cout<<sum;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define SIZE 200010
using namespace std;
const long long MOD = 998244353;

long long fac[SIZE], inv[SIZE]; // fac 存储阶乘  inv 存储阶乘逆元

long long qpow(long long a, long long b, long long mod) { // 快速幂 a ^ b % mod
	long long ans = 1;
	while (b) {
		if (b & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ans;
}
long long getInv(long long n, long long p) { // 求 n mod p 意义下的逆元
	return qpow(n, p - 2, p);
}

void getFacInv(int n, long long p) { // 阶乘逆元
	fac[0] = 1;
	for (long long i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % p;
	inv[n] = getInv(fac[n], p);
	for (long long i = n - 1; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % p;
}

long long C(long long n, long long m) {
	if (m < 0 || m > n) return 0;
	return fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	getFacInv(200000, MOD);
	long long N, M, K, ans = 0;
	cin >> N >> M >> K;
	
	for (long long i = 0; i <= K; ++i) {
		ans += M * C(N - 1, i) % MOD * qpow(M - 1, N - i - 1, MOD) % MOD;
		ans %= MOD;
	}

	cout << (ans % MOD + MOD) % MOD;
}

Measured memory_bytes: 6832
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=int(b); i++)
#define loop(k,a) for (int k=(a); ~k; k=link[k])
using namespace std;
 
const int maxn = 1009, maxm = 1000009, INF = 1e9;
struct edge { int u, v, f, c; };
struct ISAP {
    int n, m, s, t, head[maxn], link[maxm];
    int d[maxn], p[maxn], cur[maxn], num[maxn];
    edge e[maxm];
    void init(int _n) {
        n = _n; m = 0;
        memset(head, -1, sizeof head);
        memset(cur, -1, sizeof cur);
    }
    void addEdge(int u, int v, int w) {
        e[m].u = u; e[m].v = v; e[m].f = 0; e[m].c = w;
        link[m] = head[u]; cur[u] = head[u] = m++;
        e[m].u = v; e[m].v = u; e[m].f = 0; e[m].c = 0;
        link[m] = head[v]; cur[v] = head[v] = m++;
    }
    int augment() {
        int mn = INF, u = t;
        while (u != s) {
            mn = min(mn, e[p[u]].c - e[p[u]].f);
            u = e[p[u]].u;
        }
        u = t;
        while (u != s) {
            e[p[u]].f += mn; e[p[u]^1].f -= mn;
            u = e[p[u]].u;
        }
        return mn;
    }
    int Maxflow(int _s, int _t) {
        int res = 0, u = _s, flag;
        memset(d, 0, sizeof d);
        memset(num, 0, sizeof num);
        s = _s; t = _t; num[0] = n;
        while (d[s] < n) {
            if (u == t) { res += augment(); u = s; }
            flag = 0;
            loop (k, cur[u])
                if (e[k].f < e[k].c && d[u] == d[e[k].v] + 1) {
                    p[e[k].v] = cur[u] = k;
                    u = e[k].v; flag = 1;
                    break;
                }
            if (flag) continue;
            int mn = n;
            loop (k, head[u])
                if (e[k].f < e[k].c)
                    mn = min(mn, d[e[k].v] + 1);
            if (--num[d[u]] == 0) return res;
            num[d[u] = mn]++; cur[u] = head[u];
            if (u != s) u = e[p[u]].u;
        }
        return res;
    }
} G;
int n, a[maxn], b[maxn], c[maxn], d[maxn], S, T;

int main() {
	scanf("%d", &n);
	S = n * 2 + 1; T = S + 1; G.init(T);
	rep (i, 1, n) {
		scanf("%d%d", &a[i], &b[i]);
		G.addEdge(S, i, 1);
	}
	rep (i, 1, n) {
		scanf("%d%d", &c[i], &d[i]);
		G.addEdge(n+i, T, 1);
	}
	rep (i, 1, n) rep (j, 1, n)
		if (a[i] < c[j] && b[i] < d[j]) 
			G.addEdge(i, n+j, 1);
	printf("%d\n", G.Maxflow(S, T));
	return 0;
}

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

  vector<int> a(n);

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

  sort(a.begin(), a.end());

  cout << a[n-1] - a[0] << endl;

}

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


void solve(long long a, long long b, long long c){
    set<ll> ans;
    ans.insert(a);
    if(!ans.count(b)) ans.insert(b);
    if(!ans.count(c)) ans.insert(c);

    cout << ans.size() << endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    solve(a, b, c);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int m,n;
bool ch(int x){while (x!=1){if (x%2)return 0;x/=2;}return 1;}
void sc(int x,int y){cout<<x<<' '<<y<<'\n';}
int lo(int x){return x&(-x);}
int main(){
	cin>>n;
	if (ch(n))puts("No");
	else{
		puts("Yes");
		sc(1,2);sc(2,3);sc(3,n+1);sc(n+1,n+2);sc(n+2,n+3);
		for (int i=4;i<=n;i+=2){
			if (i<n)sc(i,1),sc(i+1,1),sc(i+n,i+1),sc(i+n+1,i);
			else sc(i,i-lo(i)+1),sc(i+n,lo(i));
		}
	}
	return 0;
}

Measured memory_bytes: 2304
import math

n, m = map(int, input().split())
ansTimes = [10**6]*(n+1)
ans = [0]*(n+1)
ansTimes[1] = 0
routeList = [[] for j in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    routeList[a].append(b)
    routeList[b].append(a)

checkedList = [0]*(n+1)
tugiChecks = [1]
while tugiChecks != []:
    i = tugiChecks.pop(0)
    for target in routeList[i]:
        if ansTimes[i]+1 < ansTimes[target]:
            ansTimes[target] = ansTimes[i]+1
            ans[target] = i
        if checkedList[target] == 0:
            tugiChecks.append(target)
            checkedList[target] = 1


if 10**6 in ansTimes[1:]:
    print("No")
else:
    print("Yes")
    for i in range(2, n+1):
        print(ans[i])


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

int main() {
    int e, y;
    cin >> e >> y;
    if (e == 0)
    {
        if (y <= 1911) cout << "M" << y - 1867;
        else if (y <= 1925) cout << "T" << y - 1911;
        else if (y <= 1988) cout << "S" << y - 1925;
        else cout << "H" << y - 1988;
    }
    else
    {
        int offset[] = { 1867, 1911, 1925, 1988 };
        cout << offset[e - 1] + y;
    }
    cout << endl;
}



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

int main() {
  int A , B , K;
  cin >> A >> B >> K;
  vector<int> vec(100);
 /* for(int k=0 ; k<100 ; k++){
    vec.at(k)=1000;
  }*/
  for(int i=0 ; i<100 ; i++){
    if(A%(i+1)==0 && B%(i+1)==0){
      vec.at(i)=i+1;
    }
  }
  sort(vec.begin() , vec.end());
  reverse(vec.begin() , vec.end());
  cout << vec.at(K-1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
#include <math.h>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    return x*y/(T)GCD(x,y);
}
int main(){
    int n,q; cin >> n;
    int s; 
    map<int,int> mp;
    for(int i = 0; i < n; i++){
        cin >> s;
        mp[s]++;
    }
    cin >> q;
    int ans = 0;
    for(int i = 0; i < q; i++){
        cin >> s;
        if (mp[s]){
            ans++;
        }
    }
    cout << ans << endl;
}
  




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

int main() {
    int x, a, b;
    cin >> x >> a >> b;

    if (abs(x - a) < abs(x - b)) {
        cout << 'A' << endl;
    } else {
        cout << 'B' << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;

long long MOD = 1e9 + 7;

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

    int a, b;

    cin >> a >> b;

    int max = a + b;
    max = std::max(max, a - b);
    max = std::max(max, a * b);

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256