akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
vector<int> v;
int main() {
  string ins;
  cin >> ins;
  bool w, e, n, s;
  w = e = n = s = false;
  for (char c : ins) {
    if (c == 'W') {
      w = true;
    } else if (c == 'E') {
      e = true;
    } else if (c == 'N') {
      n = true;
    } else if (c == 'S') {
      s = true;
    }
  }
  if (w == e && n == s) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define inf 0x3f3f3f3f
#define N 100010
#define int long long
#define mod 1000000007
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
vector <int> e[N];
int n,k,ans=1;

void dfs(int x,int fa,int a)
{
    for(int i=0;i<e[x].size()-(int)(x!=1);i++)
    {
        ans=ans*(a-i)%mod;
    }
    vector <int>:: iterator it;
    for(it=e[x].begin();it!=e[x].end();it++)
    {
        if(*it==fa)
            continue;
        dfs(*it,x,k-2);
    }
}

signed main(){
    scanf("%lld%lld",&n,&k);
    for(int i=2;i<=n;i++)
    {
        int u,v;
        scanf("%lld%lld",&u,&v);
        e[u].push_back(v);
        e[v].push_back(u);
    }
    ans=k;
    dfs(1,0,k-1);
    printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 12172
#define ll long long
#define lld long double
#define cn(n)  ll n;cin >> n;
#define tes(t) ll t;cin>>t;while(t--) 
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define al(v) v.begin(), v.end()
#define oset(X) tree<X, null_type, less<X>, rb_tree_tag, tree_order_statistics_node_update>
#define roset(X) tree<X, null_type, greater<X>, rb_tree_tag, tree_order_statistics_node_update>
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const ll MOD2 = 998244353;
const long double PI = 3.141592653589793;
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <functional>
// using namespace __gnu_pbds;
using namespace std;
ll power(ll x, ll y, ll p){ll res = 1;x %= p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}
ll po(ll base, ll powerRaised){if (powerRaised != 0)return (base * po(base, powerRaised - 1));else return 1;}
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
ll lcm(ll a, ll b){return (a * b) / gcd(a, b);}
int main()
{
//   ios_base::sync_with_stdio(false);
//   cin.tie(NULL);
//   cout.tie(NULL);
// #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif //*
  // tes(t)
  // {
  // }
  ll ans;
  rep(i,0,4)
  {
    ll x;
    cin>>x;
    if(x==0)
    ans=i+1;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3520
#!/usr/bin/env python3
# coding: utf-8
import collections
import math
def debug(arg):
    if __debug__:
        pass
    else:
        import sys
        print(arg, file=sys.stderr)

N, *A = map(int, open(0).read().split())
a = dict(enumerate(A, 1))
# dp = collections.defaultdict(int)
dp = collections.defaultdict(lambda: -float("inf"))
dp[0, 0] = 0 
dp[1, 0] = 0 
dp[1, 1] = a[1]
for i in range(2, N + 1):
    jj = range(max(math.floor(i // 2 - 1), 1), math.ceil((i + 1) // 2) + 1)
    debug(jj)
    for j in jj:
        x = dp[i - 2, j - 1] + a[i]
        y = dp[i - 1, j]

        dp[i, j] = max(x, y)
        debug([i - 2, j - 1])
        debug([i - 1, j])
        debug([i, j])
        debug(dp[i, j])
print(dp[N, N // 2])

Measured memory_bytes: 155504
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

        try {
            int lim = Integer.parseInt(in.readLine());

            for (int i = 0; i < lim; i++) {
                String[] values = in.readLine().split(" ");
                int a = Integer.parseInt(values[0]);
                int b = Integer.parseInt(values[1]);
                int c = Integer.parseInt(values[2]);

                int x = a * a;
                int y = b * b;
                int z = c * c;
                if (((x + y) == z) || ((y + z) == x) || ((z + x) == y)) System.out.println("YES");
                else System.out.println("NO");
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2097162
#define inf 1e9
#define MOD 1000000007

int main()
{

    ll n, m;
    cin >> n >> m;
    vector<ll > v(n+5, 1);
    for(ll i  =0; i < m; i++)
    {

        ll x;
        cin >> x;
        v[x]=0;
    }
    ll dp[n+5];
    mset(dp,0);
    dp[0]=1;
    dp[1]=v[1];
    for(ll i = 2; i <= n; i++)
    {

        if(v[i]) dp[i]=((dp[i-1]%MOD)+dp[i-2]%MOD)%MOD;
    }
    cout << dp[n];
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
string b[a];
bool ans = true;
for(int i = 0;i < a;i++){
cin >> b[i];
if(i!=0){
  if(b[i-1].at(b[i-1].size()-1) == b[i].at(0)){

  }
  else{
    ans = false;
    //cout << i <<endl;
    break;
  }
}

for(int j = 0;j < i;j++){
  if(b[j] == b[i]){
    ans = false;
    // cout << i <<endl;
    break;
  }
}
}
 if(ans == false){
  cout << "No" <<endl;
   }
   else{
    cout << "Yes" <<endl;
   }
}



Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] stu = new int[n][2];
        for(int i = 0; i < stu.length; i++){
            stu[i][0] = sc.nextInt();
            stu[i][1] = sc.nextInt();
        }
        
        int[][] cp = new int[m][2];
        for(int i = 0; i < cp.length; i++){
            cp[i][0] = sc.nextInt();
            cp[i][1] = sc.nextInt();
        }
        
        for(int i = 0; i < stu.length; i++){
            int min = -1;
            int d = 1000000000;
            for (int j = 0; j < cp.length; j++) {
                int temp = Math.abs(stu[i][0] - cp[j][0]) + Math.abs(stu[i][1] - cp[j][1]);
                if(d > temp){
                    min = j;
                    d = temp;
                }
            }
            System.out.println(min + 1);
        }
    }
}

Measured memory_bytes: 23764
hT, sT, hA, sA = map(int, input().split())
win = ''
while True:
    hA = hA-sT
    if hA <= 0:
        win = 'Yes'
        break
    hT = hT - sA
    if hT <= 0:
        win = 'No'
        break
print(win)

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int h,a;
    cin>>h>>a;
    cout<<(h+a-1)/a<<endl;
    return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b,c,d=parseMap(split(readline()))
    for i in 1:1000000
        c-=b
        if c<=0
            println("Yes")
            break
        end
        a-=d
        if a<=0
            println("No")
            break
        end
    end
end
main()

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

vector<int> dx = { -1,0,0,1 };
vector<int> dy = { 0,-1,1,0 };

int main() {
	ll h, w;
	cin >> h >> w;
	vector<string> v;
	string tmp(w + 2, '#');
	v.push_back(tmp);
	ll ans = 0;
	for (ll i = 0; i < h; ++i) {
		string s;
		cin >> s;
		v.push_back("#" + s + "#");
	}
	v.push_back(tmp);
	for (ll i = 1; i <= h; ++i) {
		for (ll j = 1; j <= w; ++j) {
			if (v[i][j] == '#')continue;
			vector<vector<bool>> visited(h + 2, vector<bool>(w + 2, false));
			queue<pair<pair<ll, ll>, ll>> q;
			q.push({ {i,j},0 });
			while (!q.empty()) {
				auto p = q.front();
				q.pop();
				if (visited[p.first.first][p.first.second])continue;
				ans = max(ans, p.second);
				visited[p.first.first][p.first.second] = true;
				for (ll k = 0; k < 4; ++k) {
					if (v[p.first.first + dx[k]][p.first.second + dy[k]] == '.') {
						q.push({ {p.first.first + dx[k],p.first.second + dy[k]},p.second + 1 });
					}
				}
			}
			
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))
from functools import reduce;gcd=lambda*x:reduce(math.gcd,x);lcm=lambda*x:reduce(lambda x,y:(x*y)//gcd(x,y),x,1)
from collections import deque
Yes=lambda b:print("Yes"if b else"No");YES=lambda b:print("YES"if b else"NO")
is_even=lambda x:True if x%2==0 else False

def is_palindrome(s):
  n=len(s);b=True
  for i in range(int(0.5*n)):
    if s[i]!=s[n-i-1]:b=False
  return b

def main():
  k,x=ints()
  Yes(k*500>=x)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**7) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
# h,w = li()
# ss = [ns() for _ in range(h)]

ls = [2222,1111,999,888,777,666,555,444,333,222,111]

X = int(input())
ans = 111
for s in ls:
    if X <= s:
        ans = s

print(ans)


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var lim = (int) (Math.Pow(n, 1.0 / 5.0) * 2);

            var array = new long[lim + 1];
            for (var i = 0; i <= lim; i++)
            {
                array[i] = (long) Math.Pow(i, 5.0);
            }

            var result = new int[2];
            for (var i = 0; i <= lim; i++)
            {
                for (var j = i + 1; j <= lim; j++)
                {
                    var a = array[i];
                    var b = array[j];
                    if (b > n)
                    {
                        if (b - a == n)
                        {
                            result[0] = j;
                            result[1] = i;
                            break;
                        }
                    }
                    else
                    {
                        if (b + a == n)
                        {
                            result[0] = j;
                            result[1] = -i;
                            break;
                        }
                    }
                }
            }

            Console.WriteLine($"{result[0]} {result[1]}");
        }
    }
}

Measured memory_bytes: 27860
#include<stdio.h>
#define INFINITY 1000000001
#define N 500000

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int cnt = 0;

int main(){
  int s[N];
  int n;
  int i;

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

  mergeSort(s, 0, n);

  for(i=0;i<n;i++){
    if(i == n-1) printf("%d\n", s[i]);
    else printf("%d ", s[i]);
  }

  printf("%d\n", cnt);
  
  return 0;
}

void merge(int *s, int left, int mid, int right){
  int n1, n2;
  int i, j, k;
  
  n1 = mid - left;
  n2 = right - mid;
  int l[n1+1], r[n2+1];

  for(i=0;i<n1;i++){
    l[i] = s[left + i];
  }
  for(i=0;i<n2;i++){
    r[i] = s[mid + i];
  }
  l[n1] = INFINITY;
  r[n2] = INFINITY;

  i = 0;
  j = 0;
  for(k=left;k<right;k++){
    if(l[i] <= r[j]){
      s[k] = l[i];
      i++;
      cnt++;
    }
    else{
      s[k] = r[j];
      j++;
      cnt++;
    }
  }
}

void mergeSort(int *s, int left, int right){
  int mid;
  
  if(left+1 < right){
    mid = (left + right) / 2;
    mergeSort(s, left, mid);
    mergeSort(s, mid, right);
    merge(s, left, mid, right);
  }
}



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

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define L 8

map<string, int> state;
int mv[4] = {1, -1, 4, -4};

//int bfs(string start, string goal)
void bfs(string start)
{
	int res = 0;
	int i, j;

	queue<string> q;
	q.push(start);

	while (q.size()) {
		
		string t = q.front();
		q.pop();

/*
		if (t == goal) {
			res = state[t];

cout << "Found goal:" << t << '\n';

			break;	
		}
*/

		int zPos = t.find("0");

		for (i=0; i<4; i++) {
			int nmv = zPos + mv[i];
			if (0<=nmv && nmv<L && !(zPos == 4 && nmv == 3) && !(zPos == 3 && nmv == 4)) {
				string u = t;
				swap(u[zPos], u[nmv]);

				if (!state.count(u)) {
					q.push(u);
					state[u] = state[t] + 1;
//cout << "pushed:" << u << ", count:" << state[u] << '\n';
				}
			}
		}
	}
}


int main()
{

	int i, j;
	string start = "01234567";
	string goal;
	state[start] = 0;

	bfs(start);

	while (1) {
//cout << "-----------------------------" << '\n';
		//input
		char c;
		if (scanf("%c ", &c) == EOF) break;
		goal = c;
		for (i=1; i<L; i++) {
			scanf("%c ", &c);
			goal += c;
		}
	
		//bfs & output
		//printf("%d\n", bfs(start, goal));
		printf("%d\n", state[goal]);
	}	

	return 0;
}

Measured memory_bytes: 3464
use proconio::input;
use std::cmp;

fn main() {
    input! {
        n: usize,
        w: usize,
        items: [(usize, usize); n],
    }

    let inf = 10usize.pow(10);
    let max_v = 100001;
    let mut dp = vec![vec![inf; max_v]; n + 1];
    dp[0][0] = 0;

    for i in 1..=n {
        for j in 0..max_v {
            dp[i][j] = dp[i - 1][j];
            if j >= items[i - 1].1 {
                dp[i][j] = cmp::min(dp[i][j], dp[i - 1][j - items[i - 1].1] + items[i - 1].0);
            }
        }
    }

    let mut ans = 0;
    for i in 0..max_v {
        if dp[n][i] <= w {
            ans = i;
        }
    }
    println!("{}", ans);
}


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

using namespace std;

#define max(a,b) (a > b ? a: b)
//#define max3(a,b,c) a > max(b,c) ? a : max(b,c)

int main()
{
    int n;
    scanf("%d",&n);
    int* a= new int[n];
    int* b= new int[n];
    int* c= new int[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        scanf("%d",&b[i]);
        scanf("%d",&c[i]);
    }
    
    int** dp= new int* [3];
    for(int i=0;i<3;++i)
    dp[i]= new int [n];
    
    dp[0][0]=a[0];
    dp[1][0]=b[0];
    dp[2][0]=c[0];
    for(int i=1;i<n;i++)
    {
        
        dp[0][i]= max(dp[1][i-1],dp[2][i-1])+a[i];
        dp[1][i]= max(dp[0][i-1],dp[2][i-1])+b[i];
        dp[2][i]= max(dp[1][i-1],dp[0][i-1])+c[i];
        
    }
    cout<<(dp[0][n-1] > max(dp[1][n-1],dp[2][n-1]) ? dp[0][n-1] : max(dp[1][n-1],dp[2][n-1]))<<endl;
    return 0;
    
}

Measured memory_bytes: 2560
N,M=map(int,input().split())
A=[int(x) for x in input().split()]
CB=[]
for i in range(M):
  B,C = map(int,input().split())
  CB +=[[C,B]]

for j in range(N):
  CB +=[[A[j],1]]

CB=sorted(CB,reverse = True)
count = 0
result =0

i=0
while count<N:
  count +=CB[i][1]
  result +=CB[i][0]*CB[i][1]
  i +=1

result -= (count-N)*(CB[i-1][0])
print(result)

Measured memory_bytes: 36072
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
LL D;
int main(){
	scanf ("%d%lld", &n, &D);
	
	int ans = 0;
	LL x, y;
	for (int i = 1; i <= n; i++) {
		scanf ("%lld%lld", &x, &y);
		if (x * x + y * y <= D * D) ans++;
	}
	printf ("%d\n", ans);
  return 0;
}

Measured memory_bytes: 3820
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int x, a, b;
  cin >> x >> a >> b;
  int da = abs(a - x);
  int db = abs(b - x);
  if (da < db) {
    cout << "A" << endl;
  } else {
    cout << "B" << endl;
  }
}


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

static const long long int INF = ((1ll<<60)-1);

int main()
{
	long long int a, b, m;
	cin >> a >> b >> m;
	long long int A[100001], B[100001];
	long long int mir = INF, mid = INF;
	for (long long int i = 1; i <= a; ++i)
	{
		cin >> A[i];
		mir = min(mir, A[i]);
	}
	for (long long int i = 1; i <= b; ++i)
	{
		cin >> B[i];
		mid = min(mid, B[i]);
	}
	long long int x, y, c;
	long long int ans = INF;
	for (long long int i = 0; i < m; ++i)
	{
		cin >> x >> y >> c;
		ans = min(ans, A[x] + B[y] - c);
	}
	cout << min(mir + mid, ans) << endl;
	return 0;
}

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

int main()
{
  string s; cin >> s;
  int n = s.size();

  string ans = "";
  rep(i, n) {
    if (s[i] == 'B') {
      if (!ans.empty()) ans.pop_back();
    } else {
      ans.push_back(s[i]);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
s = str(input())  #
n = len(s) -1 # 
for i in range(1<<n):#0-2**nまで
    equ = s[0]
    for j in range(n):
        if i & (1<<j):#iの2進数展開のj+1桁目が０でない
            equ = equ + '+' + s[j+1]
        else:
            equ = equ + '-' + s[j+1]
    if (eval(equ) == 7):
        print(equ + '=7')
        break

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007


void solve()
{
	string s;
	cin>>s;
	ll n=s.size();
	ll c=0,ans=0;
	for(ll i=0;i<n;i++)
	{
		ans+=s[i]-'0';
		ans%=9;
	}
	if(ans%9==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No";
	return;
}

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

Measured memory_bytes: 3744
import sys
import math
input = sys.stdin.readline


def main():
    A, B = map(int, input().split())
    assert A <= 100
    assert B <= 100
    for i in range(1000):
        if math.floor((i+1) * 0.08) == A and math.floor((i+1) * 0.1) == B:
            print(i+1)
            exit()
    print("-1")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int N = 1e5+10;
int n,m;
int dis[N];
bool vis[N];
vector<pair<int,int> >E[N];
bool dfs(int u){
    vis[u] = 1;
    vector<pair<int,int> >::iterator it;
    for(it = E[u].begin(); it != E[u].end(); it++){
        int v = (*it).first;
        int d = (*it).second;
        if(!vis[v]){
            dis[v] = dis[u] + d;
            if(!dfs(v))
                return false;
        }
        else if(dis[u]+d!=dis[v])
            return false;
    }
    return true;
}
int main(){
    cin >> n >> m;
    int u,v,w;
    int i;
    for(i = 1; i <= m; i++){
        cin >> u >> v >> w;
        E[u].push_back(make_pair(v,w));
        E[v].push_back(make_pair(u,-w));
    }
    for(i = 1; i <= n; i++){
        if(!vis[i]){
            if(!dfs(i)){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 11136
program tax_rate
  implicit none
  integer :: n, x, t
  read(*,*) n
  do x = 0, n
    t = int(x*1.08d0)
    if (t == n) then
      write(*,'(i0)') x
      stop
    end if
  end do
  write(*,'(a)') ":("
end program tax_rate

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N;
	cin >> N;

	vector<int> A(N+1);
	vector<int> B(N);
	for (int i = 0; i < N+1; i++)
		cin >> A[i];
	for (int i = 0; i < N; i++)
		cin >> B[i];

	ll ans = 0;
	int yusya = 0;
	for (int i = 0; i < N; i++)
	{
		yusya += B[i];
		if (yusya < A[i])
		{
			ans += yusya;
			yusya = 0;
		}
		else
		{
			ans += A[i];
			if (yusya - B[i] >= A[i])
				yusya = B[i];
			else
				yusya -= A[i];
		}
	}
	ans += min(yusya, A[N]);
	cout << ans << endl;
}



Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
 
public class Hello{
    static public int mod = 1000000007;
    public static void Main(){
        string a = "1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51";
        string[] b = a.Split(',');
        int i = rint();
        WriteLine(b[i-1]);
        
        
        
        
    

        
        
        
        
    }
    static int ncr(int n,int r){r = Min(r,n-r);long nn = 1;for(int i=n-r+1;i<=n;i++){nn = nn*i%mod;}long rr = 1;for(int i=1;i<=r;i++){rr = rr*i%mod;}rr = square((int)rr,mod-2);nn = nn * rr %mod;return (int)nn;}
    // a^b mod
    static int square(int a,int b){string binary = Convert.ToString(b,2);int bileng = binary.Length;long a_power = a;long value = 1;for(int i=bileng-1;i>=0;i--){if(binary[i] == '1'){value = value*a_power%mod;}a_power = a_power*a_power%mod;}return (int)value;}
    //static int square2(long a,long b,long m){var list = new List<int>();int temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > 0){if(temp <= b){b -= temp;ret = ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;}
    //各種読取
    static string rstr(){ return ReadLine(); }
    static int rint(){ return int.Parse(ReadLine()); }
    static long rlong(){ return long.Parse(ReadLine()); }
    static string[] stra(){ return ReadLine().Split(' '); }
    static int[] inta(){ string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for(int countup_i=0;countup_i<read_str_array.Length;countup_i++){ return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static int[,] inta2(int num_array,int in_array){ int[,] int_array2 = new int[num_array,in_array]; for(int i=0;i<num_array;i++){ int[] temp_array = inta(); for(int j=0;j<in_array;j++){ int_array2[i,j] = temp_array[j]; } } return int_array2; }
    static long[] longa(){ string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){ return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea(){ string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){ return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; }
    // -----------------------------
    static long divideup(long divided,long divid){ long temp_divide = divided/divid; if(divided % divid > 0){ temp_divide++; } return temp_divide; }
    static long GCD(long a,long b){ if(a < b){ long temp = a; a = b; b = temp; } if(a % b == 0){ return b; } else{ long temp = b; b = a%b; a = temp; return GCD(a,b); } }
    static long LCM(long a,long b){ return a * b / GCD(a,b); }
}

Measured memory_bytes: 13140
import fractions

n = int(input())
a = [int(_) for _ in input().split()]

a = sorted(a)
aa = [i % a[0] for i in a][1:]
aaa = []

for i in aa:
    if i != 0:
        aaa.append(fractions.gcd(i, a[0]))

if len(aaa) == 0:
    print(a[0])
else:
    print(min(aaa))


Measured memory_bytes: 16276
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

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

object Problem {
    fun pow(a: Int, p: Int): Long = pow(a.toLong(), p)
    fun pow(a: Long, p: Int): Long = when {
        p == 0 -> 1L
        p % 2 == 1 -> a * pow(a, p - 1)
        else -> {
            val half = pow(a, p / 2)
            half * half
        }
    }

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val M = sc.next().toInt()
        val X = sc.next().toInt()
        val C = IntArray(N)
        val A = Array(N) { IntArray(M) }
        repeat(N) { i ->
            C[i] = sc.next().toInt()
            A[i] = IntArray(M) { sc.next().toInt() }
        }
        var ans = Int.MAX_VALUE
        for (i in 0 until pow(2, N).toInt()) {
            var c = 0
            val s = IntArray(M)
            for (b in 0 until N) {
                if ((i shr b) and 1 == 1) {
                    c += C[b]
                    repeat(M) {
                        s[it] += A[b][it]
                    }
                }
            }
            if (s.all { it >= X }) {
                if (ans > c) {
                    ans = c
                }
            }
        }
        if (ans == Int.MAX_VALUE) ans = -1
        pw.println(ans)
    }
}


Measured memory_bytes: 35660
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

typedef struct node *Node;
struct node{
  int key;
  Node Right;
  Node Left;
  Node Parent;
};

Node root;
Node Find[500001];
int i,j=0;

void insert(int k)
{
 Node y = NIL;
 Node x = root;
 Node z;

 z = malloc(sizeof(struct node));

 z->key = k;
 z->Left = NIL;
 z->Right = NIL;
 
  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->Left;
    else
      x = x->Right;
  }

  z->Parent = y;

  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->Left = z;
  else
    y->Right = z;
}

Node find(Node r,int k){
  while(r != NIL){
    if(k == r->key)
      return r;
    else if(k > r->key)
      r = r->Right;
    else
      r = r->Left;
  }
  return NIL;
}

void inorder(Node r){
  if(r == NIL) return;
  inorder(r->Left);
  printf(" %d",r->key);
  inorder(r->Right);
}

void preorder(Node r){
  if(r == NIL) return;
  printf(" %d",r->key);
  preorder(r->Left);
  preorder(r->Right);
}
void print()
{
  /*for(i=0; i<j; i++){
    if(Find[i] != NIL)
      printf("yes\n");
    else
      printf("no\n");
      } */
  inorder(root);
  printf("\n");
  preorder(root);
  printf("\n");
}

int main()
{
  int m,k;
  char s[6];
  scanf("%d",&m);

  for(i=0; i<m; i++){
    scanf("%s%d",s,&k);
    if(s[0] == 'i')
      insert(k);
    else if(s[0] == 'f'){
      if(find(root,k)!=NIL)
	printf("yes\n");
      else printf("no\n");
    }
    else
      print();
  }
  return 0;
}



Measured memory_bytes: 20436
#include <bits/stdc++.h>
#define mxn 200005

using namespace std;
typedef long long ll;

int N;
string cad;
map<int,int> M ;
ll sol;

const int mod = 2019;
int pot10[mxn];

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

    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    cin >> cad;
    N = cad.size();
    pot10[0] =1;
    for (int i = 0; i <= N; i++)
        pot10[i+1] = (pot10[i]*10)%mod;

    int mu=0;
    M[0]++;
    for (int i = N-1; i >= 0; i--){
        mu = ((cad[i]-'0')* pot10[N-i-1] + mu)%mod;
        M[mu]++;
    }

    for (auto &v: M)
        sol += (ll(v.second) * ll(v.second-1)) / 2LL;
    
    cout << sol << "\n";
    return 0;
}

Measured memory_bytes: 4492
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

typedef pair<int,int> pii;
int n,m;
int s,t;
pii ps[101];
// »ê¼êÌÀW©çêÔß¢RrjÖÌ£
int dists[101][101];
const int INF=1000000000;
pii cand[101];
bool used[101][101];
bool noSet[101][101];

const int dy[2][6]={{-1,-1,0,1,1,0},{-1,-1,0,1,1,0}};
const int dx[2][6]={{-1,0,1,0,-1,-1},{0,1,1,1,0,-1}};

int calcDist(pii &p1,pii &p2){

    return 0;
}

int updateMinDist(int sx,int sy,bool isSearch=true){
    memset(used,0,sizeof(used));
    queue<pii> q[2];
    int cur=0;
    int nxt=1;
    int cnt=0;
    pii sp=pii(sy,sx);
    used[sy][sx]=true;
    dists[sy][sx]=0;
    int res=1;
    q[cur].push(sp);
    while(q[cur].size()){
        while(q[cur].size()){
            pii p=q[cur].front();q[cur].pop();
            for(int i=0;i<6;i++){
                int ny=dy[p.first%2][i]+p.first;
                int nx=dx[p.first%2][i]+p.second;
                if(ny>=0&&nx>=0&&ny<n&&nx<m&&!used[ny][nx]){
                    used[ny][nx]=true;
                    q[nxt].push(pii(ny,nx));
                    if(isSearch)
                        dists[ny][nx]=min(dists[ny][nx],cnt+1);
                    else{
                        if(dists[ny][nx]>cnt+1){
                            res++;
                        }
                    }
                }
            }
        }
        cnt++;
        swap(cur,nxt);
    }
    return res;
}

int main(){
    while(cin>>m>>n&&(m|n)){
        memset(noSet,0,sizeof(noSet));
        cin>>s;
        for(int i=0;i<101;i++)for(int j=0;j<101;j++)dists[i][j]=INF;
        for(int i=0;i<s;i++){
            cin>>ps[i].second>>ps[i].first;
            ps[i].second--;
            ps[i].first--;
            noSet[ps[i].first][ps[i].second]=true;
        }
        for(int k=0;k<s;k++)updateMinDist(ps[k].second,ps[k].first);
        cin>>t;
        for(int i=0;i<t;i++){
            cin>>cand[i].second>>cand[i].first;
            cand[i].second--;
            cand[i].first--;
        }
        int res=0;
        for(int i=0;i<t;i++){
            int cnt=0;
            //if(used[cand[i].first][cand[i].second])continue;
            // ¡Ìê©çe_ÜÅÌ£ðvZµAß¢àÌÌÝÌp
            cnt=updateMinDist(cand[i].second,cand[i].first,false);
            res=max(res,cnt);
        }
        cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    bool o=true;
    if(n<=81){
        int t=n/10;
        for(int i=t+1;i<=9;i++){
            if(n%i==0) {o=false; cout<<"Yes";break;}
        }
    }
    if(o) cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//---------------------------------------------------------------
#define fastio std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
//--------------------------------------------------------------

int main(int argc,char** argv){ fastio; myio;
  ll n;
  cin>>n;
  if(n==0){cout<<0; return 0;}
  string ans;
  while(n!=0){
    ll a = n%2;
    if(a==-1) a=1;
    ans+=(a? '1':'0');
    n = (n-a)/(-2);
  }
  reverse(rng(ans));
  cout<<ans<<endl;
}


Measured memory_bytes: 256
from heapq import heappop, heappush
from math import ceil, floor


def p_d():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    H = []

    for a in A:
        heappush(H, a * -1)

    for _ in range(M):
        x = heappop(H)

        heappush(H, ceil(x / 2))

    ans = 0

    for a in H:
        ans -= a

    print(ans)


if __name__ == '__main__':
    p_d()


Measured memory_bytes: 93208
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int n,a,b,c,d,x;
  long long la,lb,lc,lx;
  double da,db,dc;
  string s,ss,sss;
  
  double ans = 0;
  string anss = "";
  
  cin >> n;
  vector<double> va(n);
  //vector<int> vb(n);
  //vector<int> vc(n-1);
  rep(i,0,n) cin >> va.at(i);
  //rep(i,0,n) cin >> vb.at(i);
  //rep(i,0,n-1) cin >> vc.at(i);
  //int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  //int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  rep(i,0,n){
    ans += 1.0/va.at(i);
  }
ans = 1.0 / ans;
  //cout << ans << endl;
  cout << fixed << setprecision(5) << ans << endl;

}

Measured memory_bytes: 256
import sys
n, k = map(int, raw_input().split())
c = 0
if k == 0:
    print n**2
    sys.exit()
for x in xrange(k+1, n+1):
    c += len(xrange(k, x))
    c += ((n-x)/x)*(x-k)
    if (n-x)%x-k+1 > 0:
        c += (n-x)%x-k+1
print c


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

#define _ << " " <<
#define tr(x) cout << #x _ x << endl
#define fi first
#define se second

#ifdef _WIN32
#define LD "%I64d"
#else
#define LD "%ld"
#endif

using namespace std;

typedef long long ll;

const int maxn = 100005;

int n, k;
char s[maxn];

int read() {
    if (scanf("%s", s) < 1) {
        return 0;
    }
    n = strlen(s);
    scanf("%d", &k);
    return 1;
}

void solve() {
    for (int i = 0; i < n; i++) {
        if (s[i] == 'a') continue;
        int steps2a = 'z' - s[i] + 1;
        if (k >= steps2a) {
            k -= steps2a;
            s[i] = 'a';
        }
    }
    while (k--) {
        if (s[n - 1] == 'z') 
            s[n - 1] = 'a';
        else 
            s[n - 1]++;
    }
    /*s[n - 1] += k;
    if (s[n - 1] > 'z') {
        s[n - 1] = 'a' + s[n - 1] - 'z' - 1;
    }*/
    printf("%s\n", s);
}

int main(int argc, char *argv[]) {
    while (read()) {
        solve();
    }
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

int main(){
  bool flag=true;
  int c[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>c[i][j];
    }
  }
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      if(c[(i+1)%3][j]-c[i][j]!=c[(i+1)%3][(j+1)%3]-c[i][(j+1)%3]) flag=false;
      if(c[j][(i+1)%3]-c[j][i]!=c[(j+1)%3][(i+1)%3]-c[(j+1)%3][i]) flag=false;
    }
  }
  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

int main(){
  int n; cin >>n;
  vector<int>a(n+1); vector<int>b(n); ll sum=0;
  for(int i=0; i<=n; i++) cin >>a[i];
  for(int i=0; i<n; i++) cin >>b[i];
  for(int i=0; i<n; i++){
    if(b[i]>=a[i]){
      sum+=a[i]; b[i]-=a[i];
      if(b[i]>=a[i+1]){sum+=a[i+1]; a[i+1]=0;}
      else{sum+=b[i]; a[i+1]-=b[i];}
    }
    else sum+=b[i];
  }
  cout <<sum;
return 0;}

Measured memory_bytes: 3996
n=int(input())
root=[[] for i in range(n)]
for i in range(n):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        root[i].append((x-1,y))
k=2**n
h=[0]*n
idx=0
for i in range(k):
    buf=i
    flag=True
    #print(h)
    for j in range(n):
        h[j]=buf%2
        buf=buf//2
    for j in range(n):
        if h[j]==1:
            for x,y in root[j]:
                if h[x]!=y:
                    flag=False
                    break
        if flag==False:
            break
    if flag==True:
        idx=max(idx,sum(h))

print(idx)

Measured memory_bytes: 43888
x1,x2,x3,x4,x5 = map(int,input().split())


if x1 ==0:
    print(1)

if x2 ==0:
    print(2)

if x3 ==0:
    print(3)

if x4 ==0:
    print(4)

if x5 ==0:
    print(5)

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

using namespace std;

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;
}

int64_t Count(int64_t n, int64_t a, int64_t b) {
  int64_t div_a = n / a;
  int64_t div_b = n / b;
  int64_t div_ab = n / lcm(a, b);
  return n - div_a - div_b + div_ab;
}

int main() {
  int64_t A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << Count(B, C, D) - Count(A - 1, C, D) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 12

void paint( char map[ N ][ N ], int x, int y ) {
  if( x < 0 || y < 0 || N <= x || N <= y )
    return ;
  if( map[ x ][ y ] != '1' )
    return ;

  map[ x ][ y ] = '0';

  paint( map, x + 1, y );
  paint( map, x - 1, y );
  paint( map, x, y + 1 );
  paint( map, x, y - 1 );
}

int main( void ) {

  while( 1 ) {
    int i, j;
    char map[ N ][ N ], hoge;
    int count;

    for( i = 0; i < N; i++ ) {
      for( j = 0; j < N; j++ )
        scanf( "%c", &map[ i ][ j ] ); // マップ読み取り
      scanf( "%c", &hoge ); // 改行飛ばし
    }
    if( scanf( "%c", &hoge ) != 1 ) // 空白の一行飛ばし
      break;

    count = 0;
    for( i = 0; i < N; i++ )
      for( j = 0; j < N; j++ )
        if( map[ i ][ j ] == '1' ) {
          count++;
          paint( map, i, j );
        }

    printf( "%d\n", count );
  } 

  return ( 0 );
}

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

int main() {
    long long n;
    cin >> n;
    string s = to_string(n);
    int d = s.size();
    long long a = 0, o = 1;
    for (int i = 0; i < d; i++) {
        a += 9*o;
        if (i != d-1) o *= 10;
    }
    while (a > n) a -= o;
    string t = to_string(a);
    int ans = 0;
    for (int i = 0; i < t.size(); i++) {
        ans += t[i] - '0';
    }
    cout << ans << endl;
}

Measured memory_bytes: 3708
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [i64; n]
    }
    if n == 2 {
        println!("{}", max(v[0], v[1]));
        return;
    }
    let mut dp = vec![[i64::min_value(); 3]; n];
    dp[0][0] = v[0];
    dp[1][1] = v[1];
    dp[2][2] = v[2];
    for i in 2..n {
        for j in 0..3 {
            if dp[i - 2][j] != i64::min_value() {
                dp[i][j] = max(dp[i - 2][j] + v[i], dp[i][j]);
            }
        }
        if i >= 3 && dp[i - 3][0] != i64::min_value() {
            dp[i][1] = max(dp[i - 3][0] + v[i], dp[i][1]);
        }
        if i >= 3 && dp[i - 3][1] != i64::min_value() {
            dp[i][2] = max(dp[i - 3][1] + v[i], dp[i][2]);
        }
        if i >= 4 && dp[i - 4][0] != i64::min_value() {
            dp[i][2] = max(dp[i - 4][0] + v[i], dp[i][2]);
        }
    }
    if n % 2 == 1 {
        println!("{}", max(dp[n - 1][2], max(dp[n - 2][1], dp[n - 3][0])));
    } else {
        println!("{}", max(dp[n - 1][1], dp[n - 2][0]));
    }
}


Measured memory_bytes: 8396
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); ++i)
//std::cout<<std::fixed<<std::setprecision(10)
using namespace std;


int main()
{
  	int N;
	cin >> N;
	int A[N];
	double b, answer;
	rep (i,N){
		cin >> A[i];
	}
	rep (i,N){
		b += 1.0/A[i];
	}
	answer = 1.0/b;
	cout << std::setprecision(10) << answer << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int result=0;
  for(int i=1;i<=n;i++){
    int digit=0;
    while(std::pow(10,digit)<=i){
      digit++;
    }
    if(digit%2==1)result++;
  }
  cout<<result<<endl;

  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
struct node{
  int key;
  struct node *r,*l,*p;
};
struct node *rt;
void insert(int);
void in(struct node *);
void pre(struct node *);
struct node *find(struct node *,int);
int main(){
  int n,i,x;
  struct node *y;
  char c[7];
  scanf("%d",&n);
  i=0;
  while(i<n){
    scanf("%s",c);
    if(c[0]=='i'){
       scanf("%d",&x);
       insert(x);
    }
    else if(c[0]=='p'){
      in(rt);
      printf("\n");
      pre(rt);
      printf("\n");
    }
    else if(c[0]=='f'){
       scanf("%d",&x);
       y=find(rt,x);
       if(y!=NULL)printf("yes\n");
       else printf("no\n");
    }
    i++;
  }
  return 0;
}

void insert(int k){
  
  struct node *x=rt,*y=NULL,*z;

  z=(struct node *)malloc(sizeof(struct node));
  z->key=k; z->l=NULL; z->r=NULL;
  while(x!=NULL){
    y=x;
    if(z->key < x->key)x=x->l;
    else x=x->r;
  }
    z->p=y;
    
    if(y==NULL)rt=z;
    else {
      if(z->key < y->key) y->l=z;
      else y->r=z;
    
  }
}


void pre(struct node *p){

  if(p==NULL) return 0;
  printf(" %d",p->key);
  pre(p->l);
  pre(p->r);
}

void in(struct node *p){
  
  if(p==NULL) return 0;
   in(p->l);
   printf(" %d",p->key);
   in(p->r);
}

struct node *find(struct node *p,int k){
 
  while(p!=NULL&&k!=p->key){
    if(k < p->key)p=p->l;
    else p=p->r;
  }
  return p;
  
}



Measured memory_bytes: 20500