akhauriyash/Code-Regression huggingface dataset:
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll DIV = (ll)1e9+7;
// const ll MAXN = (ll)1e5+10;


int main(void) {
   int N;
   cin>>N;
   map<pair<ll,ll>,ll> Info;
   rep(i,0,N) {
      ll x,y,h;
      cin>>x>>y>>h;
      Info[make_pair(x,y)]=h;
   }
   ll h_est = (*Info.begin()).second;
   rep(cx,0,101) rep(cy,0,101) rep(h,h_est-220,h_est+220) {
      if (h<=0) continue;
      bool flag = true;
      for (auto in: Info) {
         if (in.second != max((ll)0,h-abs(cx-in.first.first)-abs(cy-in.first.second))) flag = false;
         if (!flag) break;
      }
      if (flag) {
         cout<<cx<<" "<<cy<<" "<<h<<endl;
         break;
      }
   }



   return 0;
}



Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int n;
ll w;
vl th[4];

int main() {
    fastio();

    cin >> n >> w;
    ll w1, v1;
    cin >> w1 >> v1;

    th[0].push_back(v1);

    forn(i, n - 1) {
        int w, v;
        cin >> w >> v;
        th[w - w1].push_back(v);
    }

    forn(i, 4) {
        th[i].push_back(0);
        sort(th[i].begin(), th[i].end(), greater<ll>());
    }

    ll ans = 0;
    ll a = 0;
    for (int i = 0; i < th[0].size(); i++) {
        ll b = 0;
        for (int j = 0; j < th[1].size(); j++) {
            ll c = 0;
            for (int k = 0; k < th[2].size(); k++) {
                ll d = 0;
                for (int l = 0; l < th[3].size(); l++) {
                    ll wtotal = 1LL * i * w1 + 1LL * j * (w1 + 1) + 1LL * k * (w1 + 2) + 1LL * l * (w1 + 3);

                    if (wtotal > w) continue;

                    chmax(ans, a + b + c + d);

                    d += th[3][l];
                }

                c += th[2][k];
            }

            b += th[1][j];
        }

        a += th[0][i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n, a;
  cin >> n >> a;
  cout << n * n - a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 200005;
const LL MOD = 998244353;

struct ST {
	LL maxv[4*MAXN];
	void set(int p, LL v, int l, int r, int idx) {
		if (p == l && p == r) {
			maxv[idx] = v;
			return;
		}
		int m = (l + r) >> 1;
		if (p <= m) this->set(p, v, l, m, idx << 1);
		else this->set(p, v, m + 1, r, idx << 1 | 1);
		maxv[idx] = max(maxv[idx << 1], maxv[idx << 1 | 1]);
	}
	LL query(int ql, int qr, int l, int r, int idx) {
		if (ql > r || qr < l) return 0;
		if (ql <= l && r <= qr) return maxv[idx];
		
		int m = (l + r) >> 1;
		LL q1 = query(ql, qr, l, m, idx << 1);
		LL q2 = query(ql, qr, m + 1, r, idx << 1 | 1);
		return max(q1, q2);
	}
} tree;

int N, h[MAXN], a[MAXN];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> h[i];
	for (int i = 1; i <= N; i++) cin >> a[i];
	
	for (int i = 1; i <= N; i++) {
		LL dp = tree.query(1, h[i], 1, N, 1);
		tree.set(h[i], dp + a[i], 1, N, 1);
	}
	
	cout << tree.query(1, N, 1, N, 1) << "\n";
}


Measured memory_bytes: 6400
#include <stdio.h>

int main(void){
   int m1, m2, m3, d, i;
   m1 = 0;
   m2 = 0;
   m3 = 0;
   for(i=0; i<10;i++){
      scanf("%d", &d);
      if(d>m1){
         m3 = m2;
         m2 = m1;
         m1 = d;
      }else if(d>m2){
         m3 = m2;
         m2 = d;
      }else if(d>m3){
         m3 = d;
      }
   }
   printf("%d\n%d\n%d\n", m1, m2, m3);
   return 0;
}

Measured memory_bytes: 600
import heapq
from collections import defaultdict
def main():
    N, M = map(int, input().split())
    work = defaultdict(list)
    for _ in range(N):
        A, B = map(int, input().split())
        work[M-A].append(B)
    
    ans = 0
    num_list = []
    heapq.heapify(num_list)
    for i in range(M-1,-1,-1):
        if work[i]:
            for j in work[i]:
                heapq.heappush(num_list,-j)
        if num_list:
            ans -= heapq.heappop(num_list)

    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 77656
import java.util.*;
import java.util.stream.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		String s = in.next();
		int ans = 700;
		for (int i=0; i<s.length(); i++) {
			if (s.charAt(i) == 'o') {
				ans += 100;
			}
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N,K;
  cin>>N>>K;
  
  
  int sum=1;
  
  for(int i=0;i<N;i++){
    sum=min(sum*2,sum+K);
  }
  
  cout<<sum<<endl;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

int main() {
    int N;
    cin >> N;
    int64_t ret = 0;
    int tmp;
    int64_t subret = 0;
    rep(i, N) {
        cin >> tmp;
        if(tmp > 0) {
            subret += tmp;
        } else {
            ret += subret / 2;
            subret = 0;
        }
    }
    ret += subret / 2;


    cout << ret << endl;


    return 0;
}



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

int main() {
  int N;
  cin >> N;
  
  vector<int> p(N);
  
  for (int i = 1; i < N + 1; i++){
    cin >> p.at(i-1);
  }
  
  int count = 0;
  
  for (int i = 1; i < N + 1; i++){
    if (p.at(i-1)==i){
      count++;
    }
  }
  
  if (count == N or count == N - 2){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  
  
}

Measured memory_bytes: 256
import java.io.*;

public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int[] arr = new int[5];
        int min=10; int idx = 0;
        for(int i=0;i<5;++i)
        {
            arr[i] = Integer.parseInt(br.readLine());
            if( ( arr[i]%10!=0) &&(arr[i]%10<min)) {idx=i; min=arr[i]%10;}
        }
        int sum =0;
        for(int i=0;i<5;++i)
        {
            if(i==idx)continue;
            sum+=arr[i];
            while(sum%10!=0) sum++;
        }
        sum+=arr[idx];
        bw.write(sum+"");
        bw.close();

    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define foreach(c,it) for (__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
using namespace std;
const int mod=1e9+7;
int n,m,i,j,s[200005],lst[3],f[200005];
string st;
int main(){
	cin>>st;
	n=st.size();st=" "+st;
	rep(i,n){
		if(st[i]-1!=((st[1]-1)^((i-1)&1))) break;
	}
	if(i>n){
		puts("1");
		return 0;
	}
	rep(i,n){
		s[i]=(s[i-1]+(st[i]&1)+1)%3;
	}
	f[0]=1;
	lst[0]=lst[1]=lst[2]=n+1;
	rep(i,n){
		if(s[i]) f[i]=1;
		for(j=0;j<3;j++)if(s[i]!=j){
			f[i]=(f[i]+f[lst[j]])%mod;
		}
		lst[s[i]]=i;
	}
	printf("%d\n",f[lst[s[n]]]);
	return 0;
}

Measured memory_bytes: 1276
#include <iostream>
using namespace std;
int main(void){
    int a;
    cin >> a;
    for(int i = 0;i < 10;i++){
        for(int j = 0; j < 10;j++){
            if(a == i*j){
                cout << "Yes"<<endl;
                return 0;
                
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, a) = (v[0], v[1]);
    let x = read_vec::<usize>();
    let x_max = x.iter().sum::<usize>();
    let mut dp = vec![vec![0i64; x_max + 1]; n + 1];
    dp[0][0] = 1;
    for i in 0..n {
        for used in (0..n).rev() {
            for j in (0..n * a).rev() {
                if j + x[i] > x_max {
                    continue;
                }
                dp[used + 1][j + x[i]] += dp[used][j];
            }
        }
    }
    let mut ans = 0;
    for j in 1..n + 1 {
        if j * a > x_max {
            break;
        }
        ans += dp[j][j * a];
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	int d;
	int n;
	int m;
	
	while (scanf("%d", &n) != EOF){
		m = 0;
		for (a = 0; a < 10; a++){
			for (b = 0; b < 10; b++){
				for (c = 0; c < 10; c++){
					for (d = 0; d < 10; d++){
						if (a + b + c + d == n){
							m++;
						}
					}
				}
			}
		}
	printf("%d\n", m);
	}
	return (0);
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
/*
int f(int a, int b, int c, int k) {
  if(k == 0) return a + b + c;
  if(k == 1) return max(2*a, max(2*b, 2*c));
  return max(f(2*a, ))
}
*/
int main() {
  //int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  int h, w;
  char ch[100][100];
  bool stat[100][100];
  scanf("%d %d", &h, &w);
  for(int i = 0; i < 100; ++i) {
    for(int j = 0; j < 100; ++j) {
      ch[i][j] = '.';
      stat[i][j] = false;
    }
  }
  for(int i = 1; i <= h; ++i) {
    getchar();
    for(int j = 1; j <= w; ++j) {
      scanf("%c", &ch[i][j]);
    }
  }
  /*
  for(int i = 1; i <= h; ++i) {
    for(int j = 1; j <= w; ++j) {
      printf("%c", ch[i][j]);
    }
    printf("\n");
  }
  */
  for(int i = 1; i <= h; ++i) {
    for(int j = 1; j <= w; ++j) {
      if(ch[i][j] == '#' && !stat[i][j]) {
        if(ch[i + 1][j] == '#') {stat[i + 1][j] = true; stat[i][j] = true;}
        else if(ch[i - 1][j] == '#') {stat[i - 1][j] = true; stat[i][j] = true;}
        else if(ch[i][j + 1] == '#') {stat[i][j + 1] = true; stat[i][j] = true;}
        else if(ch[i][j - 1] == '#') {stat[i][j - 1] = true; stat[i][j] = true;}
      }
    }
  }
  bool status = true;
  for(int i = 1; i <= h; ++i) {
    for(int j = 1; j <= w; ++j) {
      if(ch[i][j] == '#' && !stat[i][j]) {
        //cout << i << j << endl;
        status = false;
        break;
      }
    }
    if(!status) break;
  }
  if(status) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int solve(int i, int m);

int n,A[2000];

int main(){
  int i,q,m[2000];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&m[i]);

  for(i=0;i<q;i++){
    if(solve(0,m[i])) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int solve(int i, int m){ //i 番目以降の要素を使って m を作れる場合 true を返す
  int res;
  if(m==0) return 1;
  else if(i>=n) return 0;
  res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}

Measured memory_bytes: 588
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        int testCaseNum;
        int correctTestCaseNum;

        Scanner scanner = new Scanner(System.in);
        String inputData = scanner.nextLine();
        scanner.close();

        String[] editInputData = inputData.split(" ");

        testCaseNum = Integer.parseInt(editInputData[0]);
        correctTestCaseNum = Integer.parseInt(editInputData[1]);

        if (testCaseNum == correctTestCaseNum) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 21332
import math

class Dice:
    s = [0] * 6
    def __init__(self, s):
        self.s = s
    
    def move(self, s):
        if s == 'E':
            self.s[0], self.s[3], self.s[5], self.s[2] = self.s[3], self.s[5], self.s[2], self.s[0]
        if s == 'N':
            self.s[0], self.s[1], self.s[5], self.s[4] = self.s[1], self.s[5], self.s[4] ,self.s[0]
        if s == 'S':
            self.s[0], self.s[4], self.s[5], self.s[1] = self.s[4], self.s[5], self.s[1], self.s[0]
        if s == 'W':
            self.s[0], self.s[2], self.s[5], self.s[3] = self.s[2], self.s[5], self.s[3], self.s[0]

s = list(map(int, input().split()))
x = Dice(s)
m = input()

for i in m:
    x.move(i)
print(x.s[0])


Measured memory_bytes: 5668
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    if(H==1 || W==1) cout << 1 << endl;
    else cout << (H*W + 1)/2 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << x << endl;
#else 
    #define dbg(x)
#endif

#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 1000010;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
       
    int n, s;
    cin >> n >> s;
    for (int b = 2; b <= MX; ++b) {
        int cur = 0;
        int x = n;
        while (x) {
            cur += x % b;
            x /= b;
        }
        if (cur == s) {
            cout << b << '\n';
            exit(0);
        }
    }
    int mnb = BIG;
    if (n == s)
        mnb = n + 1;
    for (int x1 = 1; x1 <= min(MX, s); ++x1) {
        int x2 = s - x1;
        if (x2 <= n) {
            int b = (n - x2) / x1;
            if (n == b * x1 + x2 && b < mnb && b > max(x2, x1)) {
                mnb = b;
                dbg(x1);
                dbg(x2);
            }
        }
    }

    cout << (mnb == BIG ? -1 : mnb) << '\n';
}

Measured memory_bytes: 3652
def main():
  M,K=map(int,input().split())
  if K == 0:
    ans = []
    for i in range(2**M):
        ans.extend([i, i])
    print(*ans)
    return 0
  if 2**M <= K:
    print(-1)
    return 0
  if M==1:
    if K==1:
      print(-1)
      return 0

  ans=[str(x) for x in range(2**M) if x!=K]
  ans_b=[str(x) for x in range(2**M-1,-1,-1) if x!=K]
  print(str(K)+" "+" ".join(ans)+" "+str(K)+" "+" ".join(ans_b))
main()

Measured memory_bytes: 25092
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	int N, T, A;
	cin >> N >> T >> A;
	vector<int> H(N);
	for (auto &x : H) {
		cin >> x;
	}

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		double x = T - H[ans] * 0.006;
		double y = T - H[i] * 0.006;
		if (abs((double)A - y) < abs((double)A - x)) {
			ans = i;
		}
	}
	cout << ans + 1 << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    string s; cin >> s;
    if ((s[0] == s[1] and s[1] == s[2]) or (s[1] == s[2] and s[2] == s[3])) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

int main(void)
{
  string s;
  cin >> s;
  int i,l = 0, m = 0;
  for(i = 0; i < s.length(); i++) {
    switch(s[i]) {
    case 'A':
    case 'C':
    case 'G':
    case 'T':
      l++;
      m=max(m,l);
      break;
    default:
      l=0;
    }
  }
  cout << m << endl;
}
 


Measured memory_bytes: 256
#include <stdio.h>
//#include <string.h>

int c(char *p,int d){return ((26+*p-*(p+1))%26==d);}
int a(char *p){return((*p<'a')||(*p>'z'));}

char *decode (char *inbuf, int s) {
  int p = 0;
  while (inbuf[p] != 0) {
    //    if ((inbuf[p] >= 'a')&&(inbuf[p]<='z')) {
    if(!a(&inbuf[p])) {
      int t = inbuf[p] + s;

      if (t > 'z')      inbuf[p] = (char)(t - 26);
      else if (t < 'a') inbuf[p] = (char)(t + 26);
      else              inbuf[p] = (char)t;
    }
    p++;
  }
  return (inbuf);
}

int main(){
  char inbuf[82];
  while(fgets(inbuf,80,stdin)){
    int s;
    char *p=inbuf;
    while(*p){
      s = 0;
      if(c(p,12)){
	if(c(p+1,3)){
	  if(a(p+3)) {
	    s = 't' - *p;
	    p+=3;
	  }
	}
	/* that */
	else if(c(p+1,7)){
	  if(c(p+2,7))
	    if(a(p+4)) {
	      s = 't' - *p;
	      p+=4;
	    }
	}
	/* this */
	else if(c(p+1,25)){
	  if(c(p+2,16))
	    if(a(p+4)) {
	      s = 't' - *p;
	      p+=4;
	    }
	}
      }
      if (s) break;
      p++;
    }
    printf("%s",decode(inbuf, s));
  }
  return 0;
}

Measured memory_bytes: 524
import sys
import math

def divlist(n):
   sl=[]
   ll=[]
   for x in range(1,int(math.sqrt(n))+1):
       if n%x==0:
           sl.append(x)
           ll.append(n//x)
   ll.reverse()
   sl.extend(ll)
   return sl

def f(b,n):
    if n<b:
        return n
    else:
        return f(b,n//b)+(n%b)

def main(n,s):
    if n<s:
        return print(-1)
    elif n==s:
        return print(n+1)
    else:
        dl=divlist(n-s)
        for x in dl:
            if s==f(x+1,n):
                return print(x+1)
        return print(-1)

n=int(sys.stdin.readline().strip())
s=int(sys.stdin.readline().strip())

main(n,s)


Measured memory_bytes: 9300
import std.stdio;                                                       
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;


bool is_uruu(int n) {
	return n%400 == 0 || (n%100 != 0 && n%4 == 0);
}
void main() {
	bool f = false;
	while(true) {
		int a, b;
		auto s = readln().strip().split();
		a = to!int(s[0]);
		b = to!int(s[1]);
		if((a|b) == 0)
			break;
		if(f){
			writeln();
		}else{
			f = true;
		}

		int c;
		foreach(int n; a..b+1) {
			if(is_uruu(n)){
				writeln(n);
				++c;
			}
		}
		if(c == 0)
			writeln("NA");
	}
}

Measured memory_bytes: 1088
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int s,t,d;
  cin>>s>>t>>d;
  int w[d];
  for(int i=0;i<d;i++) cin>>w[i];
  int a[d+1];
  a[0]=0;
  for(int i=0;i<d;i++) a[i+1]=a[i]+w[i];
  int k=*min_element(a,a+d+1);
  if(s+k>t&&a[d]>=0){
    cout<<-1<<endl;
    return 0;
  }
  for(int i=0;i<=d;i++){
    if(s+a[i]<=t) {
      cout<<i<<endl;
      return 0;
    }
  }
  int l=0,r=1000000;
  while(l+1<r){
    int m=(l+r)/2;
    //cout<<m<<":"<<s+a[d]*m<<" "<<t<<endl;
    int x=0;
    for(int i=0;i<=d;i++){
      if(s+a[d]*m+a[i]<=t) {
	x=1;
	break;
      }
    }
    if(x) r=m;
    else l=m;
  }
  //cout<<r<<endl;
  int ans=r*d;
  for(int i=0;i<=d;i++){
    if(s+a[d]*r+a[i]<=t) break;
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 4660
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main(void) 
{

  int a,b,c,d,ans;
  int i = 111;
    if(scanf("%d", &a) == 1);
  
  	while(1){
  		if(i >= a){
      		printf("%d",i);
          	break;
    	}
      i += 111;
    }
    

    return 0;
}

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

int main(){
    using namespace std;
    string s;
    cin >> s;
    unsigned long N{s.size()};
    vector<unsigned long> l(N + 1), r(N + 1);
    for(unsigned long i = 0; i < N; ++i)l[i + 1] = s[i] == '<' ? l[i] + 1 : 0;
    for(unsigned long i = N; i--; )r[i] = s[i] == '>' ? r[i + 1] + 1 : 0;
    unsigned long ans{0};
    for(unsigned long i = 0; i <= N; ++i)ans += max(l[i], r[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8708
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
    char s[10000];
    scanf("%s", &s);
    int i, len = strlen(s);

    for(i=0; i<len; i++)
    {
        printf("%c", s[i]);
    }

    if(s[len-1]=='s')
        printf("es\n");
    else
        printf("s");

    return 0;
}


Measured memory_bytes: 3164
def root(x, root_ls):
  if root_ls[x] < 0:
    return x
  else:
    root_ls[x] = root(root_ls[x], root_ls)
    return root_ls[x]

def unite(a, b, root_ls):
  a = root(a, root_ls)
  b = root(b, root_ls)
  if a != b:
    root_ls[a] += root_ls[b]
    root_ls[b] = a
  
n, m = list(map(int, input().rstrip().split(" ")))
members = [-1 for i in range(n)]
max_idx = 0
for mm in range(m):
  a, b = list(map(int, input().rstrip().split(" ")))
  unite(a-1, b-1, members)
print(max([-m for m in members]))


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

int main ()
{
  string s; cin >> s;

  if (s[0] == 'S') cout << "Cloudy" << endl;
  else if (s[0] == 'C') cout << "Rainy" << endl;
  else cout << "Sunny" << endl;


  return 0;
}


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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

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

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

    sort(all(a));
    a.erase(unique(all(a)), end(a));

    // can skip n - 1 gaps
    vi b;
    for (int i = 1; i < a.size(); ++i) {
        b.push_back(a[i] - a[i - 1]);
    }
    sort(all(b));
    for (int i = 0; !b.empty() and i < n - 1; ++i)
        b.pop_back();
    ll ans = 0LL;
    for (int x : b)
        ans += x;

    cout << ans << '\n';

    
    return 0;
}


Measured memory_bytes: 1276
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef pair<long long, long long> pll;
typedef pair<long long, pll> plll;

const long long inf = 1ll << 60ll;

struct edge {long long cost, to;};

priority_queue<plll, vector<plll>, greater<plll> > p_que;
vector<struct edge> graph[105];
long long mcost[2][105];

void init(void);
void esearch(int pos, vector<long long> &e);

int main()
{
    int n, m;
    int a, b, c;

    while (cin >> n >> m, n != 0 && m != 0) {
        init();
        
        for (int i = 0; i < m; i++) {
            cin >> a >> b >> c;
            
            graph[a].push_back((struct edge){c, b});
            graph[b].push_back((struct edge){c, a});
        }
        
        vector<long long>e[105];
        for (int i = 1; i <= n; i++) {
            //グラフ春
            esearch(i, e[i]);
        }

        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < e[i].size(); j++) {
                graph[i].push_back((struct edge){0, e[i][j]});
            }
        }

        mcost[1][1] = 0;
        mcost[0][1] = 0;
        p_que.push(plll(0, pll(1, 0)));
        while (!p_que.empty()) {
            plll state = p_que.top(); p_que.pop();
            long long cost = state.first;
            long long pos = state.second.first;
            long long f = state.second.second;

            for (int i = 0; i < graph[pos].size(); i++) {
                long long npos = graph[pos][i].to;
                long long ncos = cost + graph[pos][i].cost;

                if (graph[pos][i].cost > 0) {
                    if (mcost[f][npos] > ncos) {
                        mcost[f][npos] = ncos;
                        p_que.push(plll(ncos, pll(npos, f)));
                    }
                }
                else {
                    if (f) continue;

                    if (mcost[1][npos] > ncos) {
                        mcost[1][npos] = ncos;
                        p_que.push(plll(ncos, pll(npos, 1)));
                    }
                }
            }
        }

        cout << min(mcost[0][n], mcost[1][n]) << endl;
    }

    return 0;
}

void init(void)
{
    for (int i = 0; i < 105; i++) {
        graph[i].clear();
    }

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 105; j++) {
            mcost[i][j] = inf;
        }
    }

    while(!p_que.empty()) p_que.pop();
}

void esearch(int pos, vector<long long> &e)
{
    for (int i = 0; i < graph[pos].size(); i++) {
        int npos = graph[pos][i].to;

        for (int j = 0; j < graph[npos].size(); j++) {
            e.push_back(graph[npos][j].to);
        }
    }

    sort(e.begin(), e.end());
    e.erase(unique(e.begin(), e.end()), e.end());

    return;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, p, q = INT_MAX;
	cin >> n;
	for(int i = 0; i < n; i++) {
		int arr;
		cin >> arr;
		p = 0;
		while(arr % 2 == 0) {
			arr /= 2;
			p++;
			if(q < p) break;
		}
		if(p < q) q = p;
	}
	cout << q << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>

int main()
{
    long a,b,c;
    std::cin >> a >> b >> c;
    if((c-a-b)*(c-a-b)-4*a*b>0 && (c-a-b)>0){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

b = sorted(a, reverse = True)

for j in range(n):
    if b[0] == b[1]:
        print(b[0])
    elif a[j] == b[0]:
        print(b[1])
    else:
        print(b[0])

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

counter = 0

for i in range(n):
    minj = i
    for j in range(i, n):
        if A[j] < A[minj]:
            minj = j
    if i != minj:
        A[i], A[minj] = A[minj], A[i]
        counter += 1

print(*A)
print(counter)



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    
    unordered_map<int, int> A;
    REP(i, 0, N) {
        int a; cin >> a;
        A[a]++;
    }

    bool ok = false;
    if (A.size() == 3) {
        int x = 0;
        bool cnt = true;
        for (auto a : A) {
            x ^= a.first;
            if (a.second != N / 3) {
                cnt = false;
                break;
            }
        }
        if (x == 0 && cnt) ok = true;
    } else if (A.size() == 2) {
        int z = -1, n = -1;
        for (auto a : A) {
            if (a.first == 0) z = a.second;
            else n = a.second;
        }
        if (z == N / 3 && n == N * 2 / 3) ok = true;
    } else if (A.size() == 1) {
        bool zero = false;
        for (auto a : A) {
            if (a.first == 0) zero = true;
        }
        if (zero) ok = true;
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

class Program
{

    static void Main(string[] args)
    {
        int N = GetInputInt();
        List<float> list = GetInputsFloatList();
        list.Sort();

        for (int i = 0; i < N-1; i++)
        {
            float f = list[0] + list[1];
            list.RemoveAt(1);
            list[0] = f/2;
        }

        Console.WriteLine(list[0]);
        Console.ReadKey();
    }

    public static int GetInputInt()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] GetInputsInt()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
    public static List<int> GetInputsIntList()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
    }
    public static List<float> GetInputsFloatList()
    {
        return Console.ReadLine().Split(' ').Select(float.Parse).ToList();
    }

    public static long GetInputLong()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] GetInputsLong()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }

}


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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int mx = 0, ans = 0, e, ee;

int main()
{
	IOS;
	for (int i = 0; i < 5; i++) {
		cin >> e;
		ee = (ceil(e * 1.0 / 10)) * 10;
		ans += ee;
		mx = max(mx, ee - e);
	}
	cout << ans - mx << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int k; cin >> k;
  string s; cin >> s;

  if (s.size() <= k) {
    COUT(s); return 0;
  }

  REP(i,k) {
    cout << s[i];
  }
  cout << "..." << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <set>
#include <functional>
#include <list>
#include <bitset>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>

#define INF 1e9
#define MOD 1000000007
#define ll long long
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
typedef unsigned long long ull;
typedef pair<int, int> pr;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<=s.size()-i;j++){
            if(s.substr(0,i)+s.substr(i+j)=="keyence"){
                cout<<"YES";
                return 0;
            }
        }
    }
    cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forN(i, n) for(int i = 0; i <n ; ++i)
#define endl "\n"
typedef long long ll;
using namespace  std;
const ll INF = 1e18;
const ll MOD = 1e6 + 3;
const int N = 1e5 +5;

int main() {
    fastIO;
    int n;
    cin>>n;
    if(n==0){
        cout<<1;
    }
    else cout<<0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int H, W;
    cin >> H >> W;
    string S[400];
    for(int i=0; i<H; i++) cin >> S[i];
 
    bitset<400> visited[400];
    const int dx[] = {-1, 1, 0, 0};
    const int dy[] = {0, 0, -1, 1};
 
    int64_t ans = 0;
 
 
    for(int i=0; i<H; i++) for(int j=0; j<W; j++){
        if(visited[i][j]) continue;
        visited[i][j] = true;
        vector<int64_t> num(2, 0);
        queue<pair<int, int>> que;
        que.push({i, j});
 
        while(que.size()){
            auto p = que.front(); que.pop();
            int x = p.first, y = p.second;
            num[S[x][y] == '#']++;
 
            for(int k=0; k<4; k++){
                int x2 = x + dx[k];
                int y2 = y + dy[k];
                if(x2 >= 0 && x2 < H && y2 >= 0 && y2 < W && !visited[x2][y2] && S[x][y] != S[x2][y2]){
                    que.push({x2, y2});
                    visited[x2][y2] = true;
                }
            }
        }
        ans += num[0] * num[1];
    }
    cout << ans << endl;
    return 0;
}


 

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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long )(1e18+1)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii >

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){ 
    in >> q.F >> q.S; return in;
}
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}
template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}
template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}

void solve() {
    int k, a, b, c;
    cin >> a >> b >> c >> k;
    int ans = min(k, a);
    k -= min(k, a);
    k -= min(k, b);
    ans -= min(k, c);
    k -= min(k, c);
    cout << ans << endl;

}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(20);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif
   
    //cin >> t;
    
    for(int i = 1; i <= t; ++i){
        //cout << "Case #" << i << ": "; 
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    
    int N;
    cin >> N;
    int H;
    cin >> H;
    H--;
    rep(i,N-1) {
        int x;
        cin >> x;
        if (H > x) {
            cout << "No" << endl;
            return 0;
        } else if (H == x) {
            H = x;
        } else {
            H = x - 1;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int h, w;
    cin >> h >> w;
    vector<string> vs;
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        vs.push_back(s);
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (vs[i][j] == '.') {
                vs[i][j] = '0';
            }
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (vs[i][j] == '#') {
                for (int a = -1; a <= 1; a++) {
                    for (int b = -1; b <= 1; b++) {
                        int x = i + a, y = j + b;
                        if (x < 0 || y < 0 || x >= h || y >= w || vs[x][y] == '#') continue;
                        vs[x][y]++;
                    }
                }
            }
        }
    }
    for (auto s : vs) {
        cout << s << endl;
    }
}




Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  // 標準入力高速化のおまじない
  // scanfとの同期を切る。以降紛らわしいのでscanf使用不可。
  ios::sync_with_stdio(false);
  // // cin前の自動flashをやめる
  cin.tie(nullptr);

  int X,A,B=1;
  cin >> X;

  // 探索範囲を調べる
  // ll range = 1;
  // while(true){
  //   if(pow(range,5)-pow(range-1,5)-pow(10,9)>0){
  //     cout << range << endl;
  //     return 0;
  //   }
  //   range++;
  // }
  int range = 120;

  for(int i=-range; i < range; i++){
    for(int j=-range; j < range; j++){
      if(pow(i,5)-pow(j,5)==X){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
long long n,m;
long long xx,yy;
long long ans;

int main()
{
    cin>>n>>m;
    ans+=n;
    xx=m; yy=n-m;
    if (xx<yy) swap(xx,yy);
    do
    {
        if (xx%yy!=0) ans+=xx/yy*2*yy;
        else ans+=(xx/yy*2-1)*yy;
        xx=xx%yy;
        swap(xx,yy);
    }
    while (yy!=0);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;

ll count(string s){
    ll ret=0;
    for(int i=0;i<s.size();i++){
        ret+=s[i]-'0';
    }
    return ret;
}


int main(){
    string s;
    cin>>s;
    ll mx=count(s);
    s[0]--;
    for(int i=1;i<s.size();i++){
        s[i]='9';
    }
    mx=max(mx,count(s));
    cout<<mx<<endl;
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S_arr = []

count_arr = []
for i in range(27):
    count_arr.append([])
    for j in range(N):
        count_arr[i].append(0)

for n in range(N):
    S = input()
    for c in S:
        count_arr[ord(c) - 97][n] += 1

min_count = []
for i in range(27):
    min_count.append(min(count_arr[i]))
# print(min_count)

ans = ''
for i in range(27):
    for _ in range(min_count[i]):
        ans += chr(i + 97)
print(ans)

Measured memory_bytes: 3064
'use strict'

function main(input) {
  const inputList = input.split('\n');
  const line1Array = inputList[0].split(' ')
  const h = Number(line1Array[0])
  const w = Number(line1Array[1])
  let s = inputList.slice(1)
  let tmp = new Array(h)

  for (let i=0; i<h; i++) {
    tmp[i] = new Array(w)
    tmp[i] = s[i].split('')
  }

  for (let i =0; i<h; i++) {
    for (let j=0; j<w; j++) {
      if (tmp[i][j] === '.') {
        tmp[i][j] = 0
        // console.log(String(isBomb(tmp, i, j)))
        if (isBomb(tmp, i-1, j-1)) tmp[i][j]++
        if (isBomb(tmp, i-1, j)) tmp[i][j]++
        if (isBomb(tmp, i-1, j+1)) tmp[i][j]++
        if (isBomb(tmp, i, j-1)) tmp[i][j]++
        if (isBomb(tmp, i, j+1)) tmp[i][j]++
        if (isBomb(tmp, i+1, j-1)) tmp[i][j]++
        if (isBomb(tmp, i+1, j)) tmp[i][j]++
        if (isBomb(tmp, i+1, j+1)) tmp[i][j]++
      }

 

    }
    s[i] = tmp[i].join('')
    console.log(s[i])
  }

}

function isBomb(array, i, j) {
  if (i < 0 || i >= array.length || j < 0 || j >= array[i].length) {
    return false 
  }

  if (array[i][j] === '#') {
    return true
  } else {
    return false
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8524
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(Math.max(0,c-(a-b)));
    }
}


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

int main(){
int N;
cin >> N;
int a[N];
for(int i = 0; i < N; i++){
cin >> a[i];
}

int b[N];
for(int i = 0; i < N; i++){
b[i] = a[N-1-i];
}

for(int i = 0; i < N-1; i++){
cout << b[i] << " ";
}
cout << b[N-1] << endl;

}


Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<deque>
using ll=long long;
using namespace std;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};




int main(){
	int p,q,r;
	cin>>p>>q>>r;
	cout<<min({p+q,p+r,q+r});

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;

string toString(int a, int b, int c, int d){
    return to_string(a + 1) + ' ' + to_string(b + 1) + ' ' + to_string(c + 1) + ' ' + to_string(d + 1);
}
int main(){
    int H, W;cin >> H >> W;
    int A[H][W];
    vector<string> ans;
    rep(i, H){
        rep(j, W){
            cin >> A[i][j];
        }
    }
    for(int h = 0;h < H;++h){
        string s;
        if(h % 2){
            for(int w = W - 1;w >= 0;--w){
                if(A[h][w] % 2){
                    A[h][w] -= 1;
                    if(w == 0 && h == H - 1)continue;
                    else if(w == 0){
                        A[h + 1][w] += 1;
                        s = toString(h, w, h + 1, w);
                        ans.push_back(s);
                    }
                    else{
                        A[h][w - 1] += 1;
                        s = toString(h, w, h, w - 1);
                        ans.push_back(s);
                    }
                }
            }
        }else{
            for(int w = 0;w < W;++w){
                if(A[h][w] % 2){
                    A[h][w] -= 1;
                    if(w == W - 1 && h == H - 1)continue;
                    else if(w == W - 1){
                        s = toString(h, w, h + 1, w);
                        ans.push_back(s);
                        A[h + 1][w] += 1;
                    }
                    else{
                        s = toString(h, w, h, w + 1);
                        ans.push_back(s);
                        A[h][w + 1] += 1;
                    }
                }
            }
        }
    }
    cout << ans.size() << endl;
    for(int i = 0;i < ans.size();++i)
        cout << ans[i] << endl;
}


Measured memory_bytes: 11892
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    temp = i
    count = 0
    while(True):
        if temp >= k:
            break
        count += 1
        temp = temp*2
    ans += (1/n)*((1/2)**count)
    
print(ans)

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

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	ll tot = 0;
	while (true) {
		auto ma = max_element(A.begin(), A.end());
		if (*ma < N) break;
		ll q = *ma / N;
		*ma -= q * (N+1);
		for (int i = 0; i < N; i++) {
			A[i] += q;
		}
		assert(0 <= *ma && *ma < N);
		tot += q;
	}
	cout << tot << '\n';

	return 0;
}


Measured memory_bytes: 256
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
for i, pi in enumerate(permutations(range(1, n+1))):
    if pi == p:
        a = i
    if pi == q:
        b = i
print(abs(a - b))


Measured memory_bytes: 3060
N=int(input())
a=[int(i) for i in input().split()]

ave=(sum(a)/N)

ave_a=[abs(i-ave) for i in a]

ans=101
thum=101
for i in range(N):
    if ave_a[i]<thum:
        thum=ave_a[i]
        ans=i

print(ans)

Measured memory_bytes: 3064