akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;

// Modint
struct Mint {
	static const ll mod = 998244353;
	ll val;

	Mint() { val = 0; }
	Mint(ll a) { val = a; verify_value(); }

	void verify_value() {
		if (val >= mod) val %= mod;
		if (val < 0) val %= mod, val += mod;
	}

	Mint pow(ll p) const {
		Mint cur = Mint(val), ret = 1;
		while (p > 0) {
			if (p & 1) ret *= cur;
			cur *= cur;
			p >>= 1LL;
		}
		return ret;
	}
	Mint inv() const {
		if (val == 0) cerr << "CAUTION: inv() is called with 0." << endl;
		return pow(mod - 2);
	}

	Mint operator+() const { return *this; }
	Mint operator-() const { return Mint(mod - val); }

	Mint operator+=(const Mint &a) {
		val += a.val;
		if (val >= mod) val -= mod;
		return Mint(val);
	}
	Mint operator*=(const Mint &a) {
		val *= a.val;
		if (val >= mod) val %= mod;
		return Mint(val);
	}
	Mint operator-=(const Mint &a) { return *this += -a; }
	Mint operator/=(const Mint &a) { return *this *= a.inv(); }

	Mint operator++() { return *this += Mint(1); }
	Mint operator--() { return *this -= Mint(1); }
	Mint operator++(int) {
		Mint ret = *this;
		++(*this);
		return ret;
	}
	Mint operator--(int) {
		Mint ret = *this;
		--(*this);
		return ret;
	}

	operator ll() const { return val; }
};

Mint operator+(const Mint &a, const Mint &b) {
	ll ret = a.val + b.val;
	if (ret >= Mint::mod) ret -= Mint::mod;
	return Mint(ret);
}
Mint operator*(const Mint &a, const Mint &b) {
	ll ret = a.val * b.val;
	if (ret >= Mint::mod) ret %= Mint::mod;
	return Mint(ret);
}
Mint operator-(const Mint &a, const Mint &b) { return a + (-b); }
Mint operator/(const Mint &a, const Mint &b) { return a * b.inv(); }

ostream &operator<<(ostream &out, const Mint &a) { return out << a.val; }
istream &operator>>(istream &in, Mint &a) {
	in >> a.val;
	a.verify_value();
	return in;
}


int main() {
	int n; cin >> n;
	vector<int> d(n - 1);
	int a;  cin >> a;
	if (a != 0) {
		cout << 0 << endl;
		return 0;
	}
	Mint ans = 1;
	for (int i = 0; i < n - 1; i++) cin >> d[i];
	sort(d.begin(), d.end());
	if (d[0] == 0) {
		cout << 0 << endl;
		return 0;
	}
	vector<Mint> cnt(100003);
	for (int i = 0; i < n - 1; i++) {
		cnt[d[i]]++;
	}
	cnt[0]++;
	for (int i = 1; i <= d.back(); i++) {
		ans *= cnt[i - 1].pow(cnt[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
import java.util.*;

class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
      
        int kyori [] = new int[5];
        for(int i = 0;i<5;i++){
          kyori[i] = sc.nextInt();
        }
        int k = sc.nextInt();
        int max = kyori[4] - kyori[0];
  if(max<=k){System.out.println("Yay!");}
  else{System.out.println(":(");}
      

    }
}

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

bool f(string s){
    int j = s.size() - 1;
    for(int i = 0;i < s.size() / 2;i++){
        if(s[i] != s[j - i])return false;
    }
    return true;
}
int main(void){
    string s;
    cin >> s;
    
    string s1 = s.substr(0,s.size() / 2);
    string s2 = s.substr(s.size() / 2 + 1);
    if(f(s) && f(s1) && f(s2)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    // cout << s1 << endl;
    // cout << s2 << endl;
    
}


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

using namespace std;

int main(){
  int n,k,s;
  cin >> n >> k >> s;
  for(int i=0;i<k;i++){
	cout << s << "\n";
  }
  if(n>k){
	for(int j=0;j < n-k;j++){
	  cout << 394857235 << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define MAX_N 2005

using namespace std;

int n,z,w;
int a[MAX_N];

int main()
{
	scanf("%d%d%d",&n,&z,&w);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	printf("%d\n",n==1 ? abs(a[1]-w) : max(abs(a[n]-w),abs(a[n-1]-a[n])));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a+b > c+d)
    cout << "Left" << endl;
  else if (a+b < c+d)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
N=int(input())
list=list(map(int,input().split()))
while len(list) != 0and max(list) > len(list):
    list = [i for i in list if i < len(list)]
#list2 = [i for i in list if i < N]
set = set(list)
cnt=0
for i in set:
    c=list.count(i)
    if c > i:
        cnt +=c-i
    elif c < i:
        cnt +=c
print(N-len(list)+cnt)


Measured memory_bytes: 14244
#include <iostream>
#include <string>
#include <cctype>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map> // pair
#include <set>
#include <string>

#define MAXSIZE 200000
#define PI 3.141592653589
using namespace std;

template<typename T>
T add(T a,T b){
  return a+b;
}

namespace A
{
  int f(void){
    return 1;
  }
}

int main(){
  // int num[100000000];
  std::vector<int> v;
  int n;
  while (std::cin >> n) {
    int flag=0;
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0)flag=1;
      if(flag==1)break;
    }
    if(flag==0){
      vector< int >::iterator cIter = find( v.begin(),v.end() , n );

      if( cIter != v.end() ){
      }else{
        v.push_back(n);
      }
    }

  }

  std::cout << v.size() << '\n';

}


Measured memory_bytes: 3164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sandglass2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strInp =Console.ReadLine().Split(' ');

            int intX = int.Parse(strInp[0]);
            int intT = int.Parse(strInp[1]);

            int intParts = intX - intT;

            if (intParts > 0)
            {
                Console.WriteLine(intParts);
            }
            else
            {
                Console.WriteLine(0);
            }
           


            // for debug
            return;
        }
    }
}


Measured memory_bytes: 11092
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
const long long mod = 1000000007;
long long pw[200200] = { 1 };

signed main() {
  fastio;
	map<pair<int, int>, pair<int, int> > chk;

	for (int i = 1; i < 200200; i++) pw[i] = (pw[i - 1] * 2) % mod;

	int z = mod - 1;
	int n; cin >> n;
  while (n--){
	  int a, b; cin >> a >> b;
		if (a == 0 && b == 0){ z++; continue; }
    else if (a == 0) {
      chk[make_pair(0, 1)].first++;
    } 
    else if (b == 0) {
      chk[make_pair(0, 1)].second++;
    }
    else {
      int g = __gcd(abs(a), abs(b));
      a /= g; b /= g;
      if (a * b > 0) {
        chk[make_pair(abs(a),abs(b))].first++;
      } 
      else {
        chk[make_pair(abs(b),abs(a))].second++;
      }
    }
	}

	int r = 1;
	for (auto& p : chk) {
		r = r * (pw[p.second.first] + pw[p.second.second] - 1) % mod;
	}

	cout << (z + r) % mod << "\n";
  
  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


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

int main(){
  string s;
  cin >> s;
  int count = 0;
  int answer = 0;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T'){
      count++;
      if(i == s.size() - 1 && answer < count){
        answer = count;
      }
    }
    else{
      if(answer < count){
        answer = count;
        count = 0;
      }
      else{
        count = 0;
      }
    }

    
  } 
  cout << answer << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
vector<int> v[100001];
int P[100001];
int Y[100001];
int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    cin >> P[i] >> Y[i];
    v[P[i]].push_back(Y[i]);
  }
  for (int i=1; i<=N; i++) {
    sort(v[i].begin(), v[i].end());
  }
  for (int i=0; i<M; i++) {
    int d = lower_bound(v[P[i]].begin(), v[P[i]].end(), Y[i]) - v[P[i]].begin();
    printf("%06d%06d\n", P[i], d + 1);
  }
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    ll a,b,x;
    cin>>a>>b>>x;
    if(a%x==0) cout<<b/x-a/x+1<<endl;
    else cout<<b/x-a/x<<endl;
}



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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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



void func(long long K, long long S){

    lli ans = 0;
    for(lli x=0;x<=K;x++){
        for(lli y=0;y<=K;y++){
            lli z = S-(x+y);
            if(z>=0 && z<=K){
                ans++;
            }
        }
    }
    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long K;
    scanf("%lld",&K);
    long long S;
    scanf("%lld",&S);
    func(K, S);
    return 0;
}


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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    ll v[n][n-1];
    for(i=0;i<n;i++){
        for(j=0;j<n-1;j++){
            cin >> v[i][j];
        }
    }

    ll ret = 0;
    ll now[n]={};
    ll end=0;
    while(1){
        ret++;
        bool flag[n]={};
        bool ch=0;
        for(i=0;i<n;i++){
            if(flag[i]==0 && now[i]<n-1){
                ll op = v[i][now[i]];
                if(flag[op-1] == 0 && now[op-1] < n - 1 && i+1 == v[op-1][now[op - 1]]) {
                    now[i]++;
                    now[op-1]++;
                    flag[i]=flag[op-1]=true;
                    ch=1;
                    if(now[i]==n-1)end++;
                    if(now[op-1] == n - 1) end++;
                }
            }
        }
        if(ch==0){
            cout << -1 << endl;
            return 0;
        }
        if(end==n)break;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
void move(int,int);
int m[6];
int main(){
	int n,i,cnt=1;
	char p[10];
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		cnt=1;
		for(i=0;i<6;i++){
			m[i]=i+1;
		}
		for(i=0;i<n;i++){
			scanf("%s",p);
			if(p[0]=='N'){
				move(0,1);
			}
			else if(p[0]=='E'){
					move(0,3);
			}
			else if(p[0]=='W'){
				move(0,2);
			}
			else if(p[0]=='S'){
				move(0,4);
			}
			else if(p[0]=='R'){
				move(1,2);
			}
			else{
				move(1,3);
			}
			cnt+=m[0];
		}
		printf("%d\n",cnt);
	}
	return 0;
}
void move(int a,int b)
{
	int temp;
	temp=m[a];
	m[a]=m[b];
	m[b]=m[5-a];
	m[5-a]=m[5-b];
	m[5-b]=temp;
}

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

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

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

    multiset<int> maxes;
    for(auto a: A) {
        if (maxes.size() == 0) {
            maxes.insert(a);
        }
        else {
            if (a <= *maxes.begin()) {
                maxes.insert(a);
            }
            else {
                // auto it = lower_bound(maxes.begin(), maxes.end(), a);
                auto it = maxes.lower_bound(a);
                --it;
                maxes.erase(it);
                maxes.insert(a);
            }
        }
        // for(auto a: maxes) cout << a << ","; cout << endl;
    }
    cout << maxes.size() << endl;
}



Measured memory_bytes: 5376
# -*- coding: utf-8 -*-

n = int(input())
A = [int(i) for i in input().split()]
d = {}

As = set(A)

for a in A:
    if a in d:
        d.update({a: d.get(a) + 1})
    else:
        d.update({a: 1})

summ = 0
for x in As:
    y = d.get(x)
    summ += y*(y-1) // 2

for a0 in A:
    print(summ - (d.get(a0)-1))

Measured memory_bytes: 94032
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int n,m;
	int[][] map;
	int cost;
	int expense;
	void run() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m= sc.nextInt();
		map = new int[n][n];
		for(int i=0;i<n;i++) {
			fill(map[i], INF);
		}
		for(int i=0;i<m;i++) {
			String[] str = sc.next().split(",");
			int a = Integer.parseInt(str[0])-1;
			int b = Integer.parseInt(str[1])-1;
			int c = Integer.parseInt(str[2]);
			int d = Integer.parseInt(str[3]);
			map[a][b] = c;
			map[b][a] = d;
		}
		wf();
		String[] str = sc.next().split(",");
		int f = Integer.parseInt(str[0])-1;
		int t = Integer.parseInt(str[1])-1;
		cost = Integer.parseInt(str[2]);
		expense = Integer.parseInt(str[3]);
		
		System.out.println(cost - expense - map[f][t] - map[t][f]);
	}
	
	void wf() {
		for(int i=0;i<n;i++) for(int j=0;j<n;j++) for(int k=0;k<n;k++){
			map[i][k] = min(map[i][k], map[i][j] + map[j][k]);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e6 + 7;
const int N = 3e3 + 7;
const int M = 20;
const int mod = 998244353;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
    ll n,a,b;
    cin >> n >> a >> b;
    ll l = 0 , r = n / (a + b) + 10;
    while( l < r ){
        ll m = (l + r) / 2 + 1;
        if( m * a + m * b <= n )l = m;
        else r = m - 1;
    }
    ll ans = l * a;
    n -= ans;
    n -= l * b;
    ans += min( n , a );
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

seki = 1

a.sort()
if a[0] == 0:
	print(0)
	exit()
else:
	for i in range(N):
		seki = seki * a[i]
		if seki > 1e18:
			print(-1) 
			exit()
print(seki)

Measured memory_bytes: 21660
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

	int ans = 0;
	int c = 0;
	for (int i = 0; i + 1 < N; ++i) {
		if (H[i] >= H[i + 1]) {
			++c;
			ans = max(ans, c);
		}
		else {
			c = 0;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

// LCSセット
const int S_LEN_MAX = 3333;
ll dp[S_LEN_MAX][S_LEN_MAX];
ll LCS(string s, string t){
    ll n = s.size();
    ll m = t.size();
    for (int i=0; i<n; ++i) {
        for (int j=0; j<m; ++j) {
            if (s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
            }
            else {
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }
    }
    return dp[n][m];
}

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

    // input
    string s, t;
    cin >> s >> t;

    ll lcs = LCS(s, t);
    if(lcs==0){
      cout << endl;
      return 0;
    }

    // 復元
    ll i = s.size();
    ll j = t.size();
    stringstream ss;
    // 現在と同じLCSを保ったまま左上に進む
    while(true){
      while(true){
        bool go_left = false;
        bool go_up = false;
        if(i>0 && dp[i-1][j]==lcs){
          i--;
          go_left = true;
        }
        if(j>0 && dp[i][j-1]==lcs){
          j--;
          go_up = true;
        }
        if(!go_left && !go_up){
          // 左上に来た
          lcs--;
          break;
        }
      }
      i--;
      j--;
      ss << s[i];
      if(lcs==0) break;
    }
    
    string ans = ss.str();
    reverse(ALL(ans));
    p(ans);
    
    return 0;
}

Measured memory_bytes: 80128
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        x: usize,
        m: usize,
    }

    let mut ans = x;
    let mut sum = 0;
    let mut cnt = 0;
    let mut init = 0;
    let mut ok: bool = true;
    let mut dp: Vec<usize> = Vec::new();
    for i in 0..m {
        dp.push(ans);
        ans = (ans*ans)%m;
        for j in 0..dp.len() {
            if ans==dp[j] {
                cnt = dp.len() - j;
                init = j;
                ok = false;
                break;
            }
        }
        if ok==false {
            break;
        }
    }
    let mut init_sum = 0;
    for i in 0..init {
        init_sum += dp[i];
    }

    for i in init..dp.len() {
        sum += dp[i];
    }

    let d = (n-init) / cnt;
    let r = (n-init) % cnt;
    sum *= d;
    sum += init_sum;
    for i in 0..r {
        sum += ans;
        ans = (ans*ans)%m;
    }
    println!("{}", sum);
}


Measured memory_bytes: 2504
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std; 
int main(){
 
   char g;
    cin >> g;
if(g=='A') cout <<"T";
  else if(g=='T') cout <<"A";
  else 
    if(g=='G') cout <<"C";
  else 
    if(g=='C') cout <<"G";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rItr(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define Itr(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define setp(n) fixed << setprecision(n)
#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define All(a) (a.begin()),(a.end())
#define rAll(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string str; cin>>str;
	if (str<="2019/04/30"){
		cout<<"Heisei\n";
	}else{
		cout<<"TBD\n";
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int min_count = 1000000;
  
  for(int i=0; i<N; i++)
  {
    int x;
    cin >> x;
    bool flag = true;
    
    int count = 0;
    
    while(flag)
    {
      if(x%2 == 0)
      {
        x /= 2;
        count++;
      }else
      {
        flag = false;
//        cout << count << endl;
        if(min_count > count) min_count = count;
      }
    }
    
  }
  
  cout << min_count << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int n, m, x[30][30] = { {} }, ans=0;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int a;
            cin >> a;
            x[i][a-1]++;
        }
    }
    for (int i = 0; i < m; i++) {
        int y = 0;
        for (int j = 0; j < n; j++) {
            if (x[j][i] == 0) y++;
        }
        
        if (y == 0) ans++;
    }
    cout << ans << endl;
}
    

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n, x; cin >> n >> x;
    vector<int> v(n);
    rep(i, 0, n) cin >> v[i];
    sort(all(v));
    int ans = 0;
    rep(i, 0, n) {
        if (x >= v[i] && i != n - 1) x -= v[i], ans++;
        if (x == v[i] && i == n - 1) x -= v[i], ans++;
    }
    cout << ans << endl;
}

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

int main()
{
    int n,i;
    cin >> n;
    vector<pair<int,int>> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i).first;
        a.at(i).second = i;
    }
    sort(a.begin(),a.end());
    for(i = 0;i < n;++i){
        if(i != a.at(n-1).second){
            cout << a.at(n-1).first << endl;
        }else{
            cout << a.at(n-2).first << endl;
        }
    }
    return 0;
}

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

typedef long long ll;
typedef vector < int > vi;
typedef pair <int , int > pi;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fr(i,a,b) for(int i=a;i<b;i++)

ll fact(ll n) {
   if ((n==0)||(n==1))
   return 1;
   else
   return n*fact(n-1);
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
    cin>>s>>t;
    int ans=0;
    int k = s.length();
    for(int i=0;i<k;i++)
    {
        if(s[i]!=t[i])
        {
            ans++;
        }
    }
    cout<<ans;
    
    return 0;
}


Measured memory_bytes: 3796
/***
**     Author: Khairul Anam Mubin
**     Bangladesh University of Business and Technology,
**     Dept. of CSE.
***/

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <string>
#include <sstream>
#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>

#define pb       push_back
#define Sqr(n)   (n*n)
#define Sort(v)  sort(v.begin(),v.end())
#define Mxe(v)   *max_element(v.begin(),v.end())
#define Mne(v)   *min_element(v.begin(),v.end())
#define Fill0(a) memset(a,0,sizeof(a))
#define Fin      freopen("input.txt","r",stdin)
#define Fout     freopen("output.txt","w",stdout)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
const double pi = acos(-1.0);

template <typename T> T Abs(T a) {if(a<0)return -a;else return a;}
template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T Pow(T B,T P){ if(P==0) return 1; if(P&1) return B*Pow(B,P-1);  else return Sqr(Pow(B,P/2));}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template <typename T> T exgcd(T a,T b,T &x,T &y) {if(a<0){T d=exgcd(-a,b,x,y);x=-x;return d;}   if(b<0){T d=exgcd(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=exgcd(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}

char uplowch(char ch){if(ch >= 'A' &&  ch <= 'Z') ch += 32; return ch;}
char lowupch(char ch){if(ch >= 'a' &&  ch <= 'z') ch -= 32; return ch;}
bool isalpha(char ch){if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) return true; return false;}
int strtoint(string str){stringstream ss(str);int x = 0;ss >> x ;return x ;}
string intostr(int x){stringstream ss; ss << x; string str = ss.str(); return str;}
vector<string> linetostr(string str){string s; vector <string> v ;istringstream is(str); while(is >> s)v.pb(s);return v;}

#define MOD 1000000007
#define MAX -1000000007
#define MIN 1e9 + 7

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

//Code starts from here......
int main() {
    int n , k ;
    cin >> n >> k;
    int ar[n+10];
    for(int i = 0 ; i < n; i++){
        cin >> ar[i];
    }
    //sort(ar,ar+n);
    int cnt = 0;
    for(int i = 0 ; i < n ; i += k){
        cnt++;
        if(i)
        i--;
    }
    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 640
import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)

n,m,k=map(int, input().split())  
friend=[[] for _ in range(n)]

for i in range(m):
    a,b=map(int, input().split()) 
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)

par=[None]*n
frmember=defaultdict(int)

def dfs(v):
    if par[i]==None:
        par[v]=v
        frmember[par[v]]+=1
    for f in friend[v]:
        if par[f]==None:
            par[f]=par[v]
            frmember[par[v]]+=1
            dfs(f)

for i in range(n):
    if par[i]==None:
        dfs(i)

ans=[0]*n
for i in range(n):
    ans[i]+=frmember[par[i]]-len(friend[i])-1

for i in range(k):
    a,b=map(int, input().split()) 
    if par[a-1]==par[b-1]:
        ans[a-1]-=1
        ans[b-1]-=1

print(*ans)

Measured memory_bytes: 45276
#include<bits/stdc++.h>
#include<sstream>
using namespace std;
#define ll long long
#define ld long double
 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>=b;i--)
 
#define mp make_pair
#define pb push_back
 
#define ft first
#define sd second
 
 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V> 
 
const ll N = 100005;
const ll M = 1000000007;
 
int main(){
 ll h,a;
 cin>>h>>a;
 if(h%a==0){
 	cout<<h/a;
 }
 else{
 	cout<<(h/a)+1;
 }
}

Measured memory_bytes: 256
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n, m;cin>>n>>m;
  vector<bool> ball(n, false);
  vector<int> count(n, 1);
  ball[0] = true;
  rep(i, m){
    int x, y;cin>>x>>y;
    x--;y--;
    if(ball[x] && count[x]<=1){
      ball[x] = false;
      ball[y] = true;
    }else if(ball[x] && count[x]>1){
      ball[y] = true;
    }
    count[x]--;
    count[y]++;
  }
  int ans = 0;
  rep(i, n)if(ball[i])ans++;
  cout<<ans<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    char c;
    set<char> st;
    rep(i, N){
        cin >> c;
        st.insert(c);
    }
    if(st.size() == 3) cout << "Three" << endl;
    else cout << "Four" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
class Tree():
    def __init__(self):
        self.root = None
    def insert(self, key):
        z = Node(key)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z
    def find(self, key):
        x = self.root
        while x and x.key != key:
            if x.key < key:
                x = x.right
            else:
                x = x.left
        return x
    def delete(self, key):
        z = self.find(key)
        y = self.successor(z) if z.left and z.right else z
        x = y.left if y.left else y.right

        if x:
            x.parent = y.parent
        if y.parent == None:
            self.root = x 
        elif y == y.parent.left:
            y.parent.left = x
        else:
            y.parent.right = x
        if y != z:
            z.key = y.key
    def successor(self, x):
        if x.right:
            return self.minimum(x.right)
        y = x.parent
        while y and x == y.right:
            x = y
            y = y.parent
        return y

    def minimum(self, x):
        while x.left:
            x = x.left
        return x
    
    def print(self):
        print('',' '.join(map(str, self.root.inwalk())))
        print('',' '.join(map(str, self.root.prewalk())))
    
class Node():
    def __init__(self, key):
        self.key = key
        self.parent = self.left = self.right = None
    def prewalk(self):
        ret = [self.key]
        if self.left:
            ret += self.left.prewalk()
        if self.right:
            ret += self.right.prewalk()
        return ret
    def inwalk(self):
        ret = []
        if self.left:
            ret += self.left.inwalk()
        ret += [self.key]
        if self.right:
            ret += self.right.inwalk()
        return ret
tree = Tree()
n = sys.stdin.readline()
for line in sys.stdin:
    if line[0] == 'i':
        tree.insert(int(line.split()[1]))
    elif line[0] == 'f':
        print('yes' if tree.find(int(line.split()[1])) else 'no')
    elif line[0] == 'd':
        tree.delete(int(line.split()[1]))            
    else:
        tree.print()



Measured memory_bytes: 117256
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define mp make_pair
#define SIZE 105
#define eps 1e-9
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int h, w, cnt, id;
int main() {
	io(); cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; i++) cin >> s[i];
	vector<vector<int> > dp(h, vector<int>(w));
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (!i && !j) dp[0][0] = (s[0][0] == '#');
			else {
				dp[i][j] = INT_MAX;
				if (i > 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + (s[i - 1][j] == '.' && s[i][j] == '#'));
				if (j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + (s[i][j - 1] == '.' && s[i][j] == '#'));
			}
		}
	}
	cout << dp[h - 1][w - 1];
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#define inf (int)(2e9)

signed compare(const void *a, const void *b){
	int sub = *(int *)a - *(int *)b;
	if(sub < 0){
		return -1;
	}
	else if(sub == 0){
		return 0;
	}
	else{
		return 1;
	}
}

int max(int a, int b){
	return a >= b ? a : b;
}

int min(int a, int b){
	return a <= b ? a : b;
}

int sub1(int N, int *a, int K){
	int i, ans = 0;
	for(i = 0; i < K; i++){
		ans = max(ans, a[i] + a[2 * K - 1 - i]);
	}
	return ans;
}

int sub2(int N, int *a, int L){
	int i, ans = inf;
	for(i = 0; i < L; i++){
		ans = min(ans, a[2 * N - 1 - i] + a[2 * N - 2 * L + i]);
	}
	return ans;
}

int sub3(int N, int *a, int L){
	int i, ans = 0;
	for(i = 0; i < L; i++){
		ans = max(ans, a[2 * N - 1 - i] + a[2 * N - 2 * L + i]);
	}
	return ans;
}

int can_achieve(int N, int M, int *a, int x){
//	printf("x = %d\n", x);
	int l, h, r;
	int v1, v2, v3;

	l = -1;
	r = N + 1;
	while(r - l > 1){
		h = (l + r) / 2;
		if(sub1(N, a, h) > x){
			r = h;
		}
		else{
			l = h;
		}
	}
	v1 = l;

	l = -1;
	r = N + 1;
	while(r - l > 1){
		h = (l + r) / 2;
		if(sub2(N, a, h) >= M){
			l = h;
		}
		else{
			r = h;
		}
	}
	v2 = l;

	l = 0;
	r = N + 1;
	while(r - l > 1){
		h = (l + r) / 2;
		if(sub3(N, a, h) > M + x){
			l = h;
		}
		else{
			r = h;
		}
	}
	v3 = r;
//	printf("(v1, v2, v3) = (%d, %d, %d)\n", v1, v2, v3);

	if(max(N - v1, v3) <= v2 || v1 == N){
		return 1;
	}
	else{
		return 0;
	}
}

int main(){
	int N, M, i;
	scanf("%d%d", &N, &M);
	int *a = (int *)malloc(sizeof(int) * (2 * N));
	for(i = 0; i < 2 * N; i++){
		scanf("%d", &a[i]);
	}
	qsort(a, 2 * N, sizeof(int), compare);
	int l = -1, h, r = M;
	while(r - l > 1){
		h = (l + r) / 2;
		if(can_achieve(N, M, a, h) == 1){
//			printf("can_achieve(%d) = 1\n", h);
			r = h;
		}
		else{
//			printf("can_achieve(%d) = 0\n", h);
			l = h;
		}
	}
	printf("%d\n", r);
	return 0;
}

Measured memory_bytes: 1788
#include<stdio.h>

int main(void){
	
	int n,v,j;
	
	scanf("%d", &n);
	int a[n];
	
	
	for(int i = 0;i < n;i++)
	{
		scanf("%d",&a[i]);
		printf("%d", a[i]);
		if(i!=n-1)printf(" ");
	}
		printf("\n");
	
	
	for(int i = 1;i < n;i++){
		v = a[i];
		j = i-1;
	while(j >= 0 && a[j] > v){
		a[j+1] = a[j];
		j--;
		a[j+1] = v;
	}
		for(int i = 0;i < n;i++){
			printf("%d", a[i]);
			if(i!=n-1)printf(" ");
		}
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 2084
#!/usr/bin/env python3
import sys
# Maze by warshall_floyd
# ワーシャルフロイド法


def solve(H, W, a):
    # print(a)
    inf = H*W**2
    d = [[inf]*(H*W) for _ in range(H*W)]
    for h in range(H):
        for w in range(W):
            if (a[h][w] == "0"):
                d[h*W+w][h*W+w] = 0
                if (w+1<W)and(a[h][w+1] == "0"):
                    d[h*W+w][h*W+w+1] = 1
                if (h+1<H)and(a[h+1][w] == "0"):
                    d[h*W+w][(h+1)*W+w] = 1
                if (w-1>=0)and(a[h][w-1] == "0"):
                    d[h*W+w][h*W+w-1] = 1
                if (h-1>=0)and(a[h-1][w] == "0"):
                    d[h*W+w][(h-1)*W+w] = 1
                
    # print(*d, sep='\n')

    for k in range(H*W):  # via k [k//W][k% W]
        for st in range(H*W):  # start from st
            for ed in range(H*W):  # go to ed
                d[st][ed] = min(d[st][ed], d[st][k]+d[k][ed])

    # print(*d, sep="\n")

    print(max(*map(lambda x: max([_ if _ != inf else -1 for _ in x ]), d)))
    return

if __name__ == '__main__':
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int

    a = [[_ for _ in next(tokens).replace(".","0").replace("#","1")] for _ in range(H)]  # type: "List[int]"
    solve(H, W, a)


Measured memory_bytes: 41328
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;
    x = x % p;
    if (x == 0)
    return 0; // In case x is divisible by p; 
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
bool sortinrev(const pair<vector<int>,int>&a,const pair<vector<int>,int>&b)
{
    if(a.fi==b.fi)
    return b.se>a.se;
    return a.fi>b.fi;
}
// make adjustment;
// void BFS()
// {
//     level[1]=1;
//     q.push(1);vis[1]=true;
//     while(!q.empty())
//     {
//         int p = q.front();
//         q.pop();
//         for(int i=0;i<adj[p].size();i++)
//         {
//             if(vis[adj[p][i]]==false)
//             {
//                 level[adj[p][i]] = level[p]+1;
//                 q.push(adj[p][i]);
//                 vis[adj[p][i]]=true;
//             }
//         }
//     }
// }
void DFS(vector<int>adj[],vector<bool>&visited,int u,int n,vector<int>&vi)
{
    visited[u]=true;
    vi.pb(u);
    for(int i=0;i<adj[u].size();i++)
    {
        if(visited[adj[u][i]]==false)
        {
            (DFS(adj,visited,adj[u][i],n,vi));
        }
    }
}
void run(vector<int>v)
{
    for(int i=0;i<v.size();i++)
    cout<<v[i]<<" ";
    cout<<endl;
}
ll fact(ll n)
{
    ll f=1;
    for(int i=1;i<=n;i++)
    {
        f*=i;
    }
    return f;
}
int main() 
{ 
    FIO;
    int s,w;
    cin>>s>>w;
    if(w>=s)
    {
        cout<<"unsafe\n";
    }
    else
    {
        cout<<"safe\n";
    }
   return 0; 
} 

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
vector<int> dfs(int u, vector<vector<int>> &ff, vector<int> &box, vector<int> &seen, vector<int> &ffnum, vector<vector<int>> &ffsize) {
  ffnum.at(u) = ffsize.size();
  seen.at(u) = 1;
  box.push_back(u);
  for(int i = 0; i < ff.at(u).size(); i++) {
    int v = ff.at(u).at(i);
    if(seen.at(v) == 1) continue;
    dfs(v, ff, box, seen, ffnum, ffsize);
  }
  return box;
}

int main() {
  int N, M, K; cin >> N >> M >> K;
  vector<int> seen(N, 0);
  vector<int> ffnum(N);
  vector<vector<int>> ffsize(0, vector<int> (0));
  vector<vector<int>> ff(N, vector<int> (0));
  for(int i = 0; i < M; i++) {
    int a, b; cin >> a >> b; a--; b--;
    ff.at(a).push_back(b);
    ff.at(b).push_back(a);
  }
  for(int i = 0; i < N; i++) {
    if(seen.at(i) == 1) continue;
    vector<int> box(0);
    ffsize.push_back(dfs(i, ff, box, seen, ffnum, ffsize));
  }
  vector<int> fpost(N, 0);
  for(int i = 0; i < N; i++) {
    int x = ffsize.at(ffnum.at(i)).size(), y = ff.at(i).size();
    //cout << x << " " << y << endl;
    fpost.at(i) = x - y - 1;
  }
  for(int i = 0; i < K; i++) {
    int c, d; cin >> c >> d; c--; d--;
    if(ffnum.at(c) == ffnum.at(d)) {
      fpost.at(c)--;
      fpost.at(d)--;
    }
  }
  for(int i = 0; i < N; i++) {
    cout << fpost.at(i) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 11960
local n=io.read("n")
local a={}
for i=1,n do
    a[i]=io.read("n")
end

local dp={}
local flag={}
for i=1,n do
    dp[i]={}
    flag[i]={}
    for j=1,n do
        dp[i][j]=0
    end
end

local function solve(i,j)
    if flag[i][j] then
        return dp[i][j]
    end
    flag[i][j]=true
    if i==j then
        dp[i][j]=a[i]
        return dp[i][j]
    end
    dp[i][j]=math.max(a[i]-solve(i+1,j),a[j]-solve(i,j-1))
    return dp[i][j]
end

print(solve(1,n))

Measured memory_bytes: 180332
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
num = gets.chomp.to_i

ans = num.to_s.split(//).map(&:to_i).inject(&:+)
1.upto(num.to_s.size-1).each do |i|
  num = num - num%(10**i) - 1
  # p num
  sum = num.to_s.split(//).map(&:to_i).inject(&:+)
  ans = sum if ans < sum
end

puts ans


Measured memory_bytes: 2684
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long C = sc.nextLong();
		long K = sc.nextLong();
		long[] T = new long[N];
		for(int i = 0; i < N; i++) {
			T[i] = sc.nextLong();
		}
		sc.close();
		Arrays.sort(T);
		int cnt = 1;
		long c = 1;
		long t = T[0] + K;
		for(int i = 1; i < N; i++) {
			if(c < C) {
				if(T[i] <= t) {
					c++;
				}else {
					cnt++;
					c = 1;
					t = T[i] + K;
				}
			}else {
				cnt++;
				c = 1;
				t = T[i] + K;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 50404
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    map<int,int> mp;
    rep(i,N) mp[a[i]]++;
    ll ans = 0;
    for(auto u : mp){
        if(u.first > u.second) ans += u.second;
        else ans += u.second-u.first;
    }
    cout << ans << endl;
}



Measured memory_bytes: 5120
// The moment you think of giving up you have already lost the battle
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define M   1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }

    }
}
int main()
{
   ll D,S,T;
   cin>>D>>T>>S;
   if(S*T>=D)
    cout<<"Yes";
   else
    cout<<"No";
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int n,ans=0;
    cin >> n;
    vector<int> v(n);
    for(int i=0;i < n;i++)
    {
        int x;
        cin >> x;
        ans += x-1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
s = sum(a)

cnt = [0]*(10**5)
for i in a:
    cnt[i-1] += 1

q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    s += (c-b)*cnt[b-1]
    cnt[c-1]+=cnt[b-1]
    cnt[b-1]=0
    print(s)

Measured memory_bytes: 20860
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <cstring>
#include <queue>
#include <sys/time.h>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rev(i,n) for(int i=(int)n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ( (a)/__gcd((a),(b))*(b) )

template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}

double naive(long long n,vector<long long> v){
	long long ans = 0 , cnt = 0;
	for(int i = 1 ; i <= n ; i++){
		bool flag = true;
		for(int j = 0 ; j < v.size() ; j++)
			flag &= (i%v[j]) != 0;
		if(flag) ans += i , cnt++;
	}
	return 1.0 * ans / cnt;
}
int main(){
	long long n;
	int m;
	while(cin >> n >> m && n){// 11 7 5 1 
		long long ans = n*(n+1) / 2.0;
		vector<long long> v(m);
		rep(i,m)cin >> v[i];
		long long counter = 0;
		long long calc = 0;
		for(int i = 1 ; i < (1<<m); i++){
			long double chk = 0;
			long long g = 1;
			rep(j,m) if(i>>j&1)g = lcm(g,v[j]);
			assert(g>0);
			counter += (bitcount(i)%2?1:-1) * (n/g);
			calc += (bitcount(i)%2?1:-1) * (n/g)*(n/g+1)/2 * g;
		}
		//cout << ans << " " << calc << endl;
		counter  = n - counter ;
		printf("%.6f\n",counter?(double)(ans-calc)/counter:0);
		//printf("%.10f\n",naive(n,v));
	}
}

Measured memory_bytes: 964
#include "bits/stdc++.h"

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
//#define int ll
int INF = 1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
typedef pair<int, int> Vec2;
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template<class T> inline void chmax(T& a, T b) { if (a < b) a = b; }
template<class T> inline void chmin(T& a, T b) { if (a > b)  a = b; }

const int NMX = 110000;
int dp[NMX];

signed main() {
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	rep(i, NMX) dp[i] = INF;
	dp[0] = 0;
	for (int i = 1; i <= N; i++) {
		int power = 1;
		while (power <= i) {
			dp[i] = min(dp[i], dp[i - power] + 1);
			power *= 6;
		}
		power = 1;
		while (power <= i) {
			dp[i] = min(dp[i], dp[i - power] + 1);
			power *= 9;
		}
	}
	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    vector<ll> A(3);
    rep(i, 3) cin >> A[i];
    int K;
    cin >> K;
    sort(all(A));
    A[2] <<= K;
    ll ans = 0;
    rep(i, 3) ans += A[i];
    output(ans);
    
    
    return 0;
}


Measured memory_bytes: 256