akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ins insert
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=b;i>=a;i--)
#define boost ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL)
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;

const int N=6001;
const int MXN=1501;
const ll mod=1e9+7;
const ll inf=1e9;

ll dp[N];
int a[N],b[N];
pii c[N];
int d[N];

int main(){
  int n,t;
  cin>>n>>t;
  for(int i=1;i<=n;i++){
    cin>>c[i].x>>d[i];
    c[i].y=i;
  }
  sort(c+1,c+n+1);
  for(int i=1;i<=n;i++){
    a[i]=c[i].x;
    b[i]=d[c[i].y];
  }
  for(int i=0;i<N;i++){
    dp[i]=-inf;
  }
  dp[0]=0;
  int mx=0;
  for(int i=1;i<=n;i++){
    for(int j=t-1;j>=0;j--){
      if(dp[j+a[i]]<dp[j]+b[i]){
        dp[j+a[i]]=dp[j]+b[i];
        mx=max(mx,j+a[i]);
      }
    }
  }
  ll ans=-inf;
  for(int i=0;i<=mx;i++){
    ans=max(ans,dp[i]);
  }
  cout<<ans;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n, m, k; cin >> n >> m >> k;
    vector<int> A(n);
    vector<int> B(m);
    rep(i,n) cin >> A[i];
    rep(i,m) cin >> B[i];
    // 本棚Bにある本の読書分の合計を計算する
    ll t = 0;
    rep(i,m) t += B[i];

    int j = m;
    int ans = 0;
    // n+1は、0冊〜n冊の合計n+1通りを考えるため
    rep(i,n+1){
        // j=0となるときは、すでにB[0]が合計時間から減らされたあと
        while(j > 0 && t > k){
            --j;
            t -= B[j];
        }
        if(t > k) break;
        ans = max(ans, i+j);    // i:number of A, j:number of B
        if(i == n) break;
        t += A[i];
    }
    cout << ans << endl;

}

Measured memory_bytes: 4820
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

cnt = 0
for t in T:
    head = 0
    tail = n - 1
    while head <= tail:
        i = (head + tail) // 2
        if S[i] == t:
            cnt += 1
            break
        elif S[i] < t:
            head = i + 1
        else:
            tail = i - 1

print(cnt)


Measured memory_bytes: 16712
#include<bits/stdc++.h>
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define bug(x) do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define bugv(x) do{for(auto&e:x)cerr<<e<<" ";cerr<<x<<"\n";}while(0)

using namespace std;
using ll=long long;

int main() {
    ll n; 
    cin >> n;
    ll  x[n], y[n], h[n];
    rep(i,0,n-1) cin >> x[i] >> y[i]>>h[i];

    rep(cx,0,100) rep(cy,0,100) {
        ll H=0;
        rep(i,0,n-1) if (h[i]>0) H = h[i]+abs(x[i]-cx) + abs(y[i]-cy);
        int c=0;
        rep(i,0,n-1) if (max(0LL,H-abs(x[i]-cx) - abs(y[i]-cy))==h[i]) c++;

        if (c==n) { cout<<cx << " " << cy << " " << H<<endl; return 0; }
    }


    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AFiveAntennas solver = new AFiveAntennas();
        solver.solve(1, in, out);
        out.close();
    }

    static class AFiveAntennas {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            in.nextInt();
            in.nextInt();
            in.nextInt();
            int e = in.nextInt();
            int k = in.nextInt();
            if (e - a <= k) out.println("Yay!");
            else out.println(":(");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23508
#include <algorithm>
#include <iostream>
#include <stdio.h>

#define MAX_N 200
#define INF 1'000'000'001

using namespace std;

int main() {
  int N;
  cin >> N;
  int n = INF;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    if (a % 2 != 0) {
      printf("0\n");
      return 0;
    }
    int cnt = 1;
    while ((a = a >> 1) % 2 == 0) {
      ++cnt;
    }
    n = min(n, cnt);
  }
  printf("%d\n", n);
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

const int MAX_N = 2e5 + 5;
vint dpa(2019), dpb(2019);

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

    ll ans = 0;
    rep(i, n)
    {
        int now = s[i] - '0';

        rep(j, 2019)
        {
            int here = (j * 10) + now;
            here %= 2019;
            dpa[here] += dpb[j];
        }
        ans += dpa[0];

        dpa[now]++;
        dpb = dpa;
        dpa = vint(2019);
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
  int a,b,c,d;
  int i;
  cin>>i;
  a=i/1000;
  b=(i%1000)/100;
  c=(i%100)/10;
  d=i%10;
  bool t=false;
  for (int x:{1,-1}){
    for (int y:{1,-1}){
      for (int z:{1,-1}){
        if (a+b*x+c*y+d*z==7){
          vector<char> op(3);
          int l=0;
          for (int w:{x,y,z}){
            if (w==1) op.at(l)='+';
            else op.at(l)='-';
            l++;
          }
          cout<<a<<op.at(0)<<b<<op.at(1)<<c<<op.at(2)<<d<<"=7"<<endl;
          t=true;
          break;
        }
      }
    if (t) break;
    }
  if (t) break;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
  string s, t; cin >> s >> t;
  map <char, ll> score_s, score_t;
  vector <ll> res_s(s.size()), res_t(t.size());
  rep(i, s.size()) {
    if (!score_s.count(s.at(i))) score_s[s.at(i)] = score_s.size();
    res_s.at(i) = score_s.at(s.at(i));
    if (!score_t.count(t.at(i))) score_t[t.at(i)] = score_t.size();
    res_t.at(i) = score_t.at(t.at(i));
  }
  if (res_s == res_t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 7032
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 02:42:27 2020

@author: liang
"""

N, M = map(int, input().split())
drinks = list()

for i in range(N):
    a, b = map(int,input().split())
    drinks.append((a,b))

drinks.sort(key = lambda x: x[0])
#print(drinks)
ans = 0
while M > 0:
    a, b = drinks.pop(0)
    if M <= b:
        ans += a*M
        M = 0
    else:
        ans += a*b
        M -= b
    #print(ans,M)
print(ans)

Measured memory_bytes: 23908
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
using Point = complex<ld>;
const ld eps = 1e-9;

vector<ld>quad_equa(ld a, ld b, ld c) {
	ld root = b*b - 4 * a*c;
	if (abs(root) < eps) {
		ld ans = -b / (2 * a);
		return vector<ld>(2, ans);
	}
	else if (root > 0) {
		ld ans = -b / (2 * a);
		vector<ld>anss(2);
		anss[0] = ans + sqrt(root) / (2 * a);
		anss[1] = ans - sqrt(root) / (2 * a);
		if (anss[0] > anss[1])swap(anss[0], anss[1]);
		return anss;
	}
	else {
		return vector<ld>();
	}
}

pair<ld, Point> getway(Point dp,const ld dv, Point fp, Point fv) {
	fp -= dp;
	auto ts= quad_equa(norm(fv)-dv*dv, 2 * fv.real()*fp.real() + 2 * fv.imag()*fp.imag(), norm(fp));
	if (ts.empty()) {
		return make_pair(1e18, Point(0.l, 0.l));
	}
	else {
		ld t;
		if (ts[0] < -eps) {
			if (ts.size()>1) {

				t = ts[1];
			}
			else {
				t = ts[0];
			}
		}
		else t = ts[0];
		if (t < -eps)return make_pair(1e18, Point(0.l, 0.l));
		Point catp = fp + fv*t;
		return make_pair(t, catp / ld(t));
	}
}

int main() {
	while (1) {
		int N; cin >> N;
		int M; cin >> M;
		if (!N)break;
		vector<Point>dps;
		vector<ld>dvs;
		vector<int>nums(N);
		for (int i = 0; i < N; ++i) {
			ld dx, dy, v; cin >> dx >> dy >> v;
			dps.push_back(Point(dx, dy));
			dvs.push_back(v);
		}
		for (int i = 0; i < M; ++i) {
			vector<pair<ld, Point>>ways(N);
			ld fpx, fpy, fvx, fvy; cin >> fpx >> fpy >> fvx >> fvy;
			Point fp(fpx, fpy);
			Point fv(fvx, fvy);
			ld mint = 1e19;
			int minid = -1;
			for (int j = 0; j < N; ++j) {
				ways[j] = getway(dps[j], dvs[j], fp, fv);
				if (mint > ways[j].first) {
					mint = ways[j].first;
					minid = j;
				}
			}
			nums[minid]++;
			for (int j = 0; j < N; ++j) {
				dps[j] += ways[j].second*mint;
			}
		}
		for (int i = 0; i < N; ++i) {
			cout << nums[i];
			if (i == N - 1)cout << endl;
			else cout << " ";
		}
	}
	
	return 0;
}

Measured memory_bytes: 3152
from sys import stdin, setrecursionlimit


def main():
    MOD = 998244353
    input = stdin.buffer.readline
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [0] * (s + 1)
    dp[0] = 1

    for i in range(n):
        tmp = [0] * (s + 1)
        for j in range(s + 1):
            tmp[j] += 2 * dp[j]
            tmp[j] %= MOD
            if j + a[i] <= s:
                tmp[j + a[i]] += dp[j]
                tmp[j + a[i]] %= MOD

        dp = tmp

    print(dp[-1] % MOD)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 68616
import collections 
n = int(input())
d = collections.Counter(input())
for _ in range(n-1):
    s = input()
    cnt = collections.Counter(s)
    for k,v in cnt.items():
        de = d.get(k,False)
        if de:
            d[k] = min(de,cnt[k])
    for k,v in d.items():
        if not cnt.get(k,False):
            d[k] = 0

ans = ''
for k,v in sorted(d.items()):
    ans += k*v
print(ans)


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

int main(){
  int N;
  cin >> N;
  vector<int> S;
  int ans=0;
  for(int i=0; i<N; i++){
    int s; cin >> s;
    ans+=s;
    S.push_back(s);
  }
  sort(S.begin(), S.end());
  if(ans%10!=0){
    cout << ans << endl;
    return 0;
  }
  for(int i=0; i<S.size(); i++){
    if((ans-S[i])%10!=0){
      cout << ans-S[i] << endl;
      return 0;
    }
  }
  cout << "0" << endl;
  return 0;
}

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

int yakusuu(int x){
  int yakusuu=0;
  for(int i=1;i<=x;i++){
    if(x%i==0) yakusuu++;
  }
  return yakusuu;
}
int main(){
  int n;
  cin>>n;
  int count=0;
  for(int i=1;i<=n;i+=2){
    int a=yakusuu(i);
    if(a==8) count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
#define pb push_back
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define ff first
#define oo 1000000000000000005
#define ss second
#define el "\n"
#define maxS 200005
#define MOD 998244353
using namespace std;
typedef long long ll;

ll fact[maxS], inv_fact[maxS];

ll mul(ll a, ll b)
{
    return (a*b)%MOD;
}

ll add(ll a, ll b)
{
    return (a+b)%MOD;
}

ll fastpow(ll b, ll e)
{
    ll res = 1;
    while(e)
    {
        if(e&1)
            res = mul(res, b);
        e >>= 1;
        b = mul(b, b);
    }
    return res;
}

ll INV(ll x)
{
    return fastpow(x, MOD-2);
}

void pre()
{
    fact[0] = 1;
    inv_fact[0] = 1;
    for(ll i=1 ; i<maxS ; i++)
    {
        fact[i] = mul(fact[i-1], i);
        inv_fact[i] = INV(fact[i]);
    }
}

ll nCr(ll n, ll r)
{
    ll res = mul(fact[n], inv_fact[r]);
    res = mul(res, inv_fact[n-r]);
    return res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    // ll t;cin>>t;while(t--)
    {
        pre();
        ll n, m, k, ans = 0;
        cin>>n>>m>>k;
        
        for(ll p=n-k ; p<=n ; p++)
        {
            ll tmp = fastpow(m-1, p-1);
            tmp = mul(m, tmp);
            ll tmp2 = nCr(n-1, p-1);
            ans = add(ans, mul(tmp, tmp2));
        }
        
        cout<<ans<<el;
    }
    
    return 0;
}

Measured memory_bytes: 6776
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        int[] out = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
            out[a[i] - 1] = i + 1;
        }
        for(int i = 0; i < n; i++) System.out.print(out[i] + " ");
    }
}

Measured memory_bytes: 62868
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, D): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    fn iceil(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    let ans = iceil(N, (2 * D + 1));

    println!("{}", ans);
}


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  rep(i,h) cin >> grid[i];
  int cnt = 0;
  rep(i,h){
    rep(j,w){
      if(grid[i][j] == '#'){
        cnt++;
      }
    }
  }
  cout << (cnt == h + w - 1? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 256
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=mp()
a=lmp()
for i in range(k,n):
    if a[i]>a[i-k]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 97492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b,c;
    int ans=1;
    cin>>a>>b>>c;
    if(a!=b) ans++;
    if(c!=a&&c!=b) ans++;
    cout<<ans<<endl;

}


Measured memory_bytes: 256
while True:
    n, x = map(int, raw_input().split(" "))
    if n==x==0:
        break
    ans = 0
    for a in range(1, n-1):
        for b in range(a+1, n):
            for c in range(b+1, n+1):
                if a+b+c == x:
                    ans += 1
                    break
    print ans

Measured memory_bytes: 6356
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll n; cin >> n;
  ll ans = 0;
  rep(i, n) ans += ll(i+1)*(n-i);
  rep(i, n-1) {
    ll a, b; cin >> a >> b;
    --a; --b;
    if (a > b) swap(a, b);
    ans -= (a+1)*(n-b);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;
using ll = long long;

int main() {
	int x[5];
	for (int i = 0;i < 5;i++) {
		cin >> x[i];
	}
	for (int i = 0;i < 5;i++) {
		if (x[i] == 0) {
			cout << i + 1 << endl;
		}
	}
}

Measured memory_bytes: 3628
S = input()

first = int(S[0:2])
last = int(S[2:4])

if (0 < first < 13):
	if (0 < last < 13):
		print("AMBIGUOUS")
	else:
		print("MMYY")
else:
	if (0 < last < 13):
		print("YYMM")
	else:
		print("NA")

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

int main(void){
	char str[10],temp;
	int n,i,j,k,max,min;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",str);
		for(j=0;j<8-1;j++){
			for(k=j+1;k<8;k++){
				if(str[j]<str[k]){
					temp=str[j];
					str[j]=str[k];
					str[k]=temp;
				}
			}
		}
		max=atoi(str);
		for(j=0;j<8-1;j++){
			for(k=j+1;k<8;k++){
				if(str[j]>str[k]){
					temp=str[j];
					str[j]=str[k];
					str[k]=temp;
				}
			}
		}
		min=atoi(str);
		printf("%d\n",max-min);
	}
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

char C;
int main()
{
	cin >> C;
	cout << char(C+1) << endl;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793


   
int main(){
 int x,y;
 cin >> x >> y;
 set<int> num;
  num.insert(4);
  num.insert(6);
  num.insert(9);
  num.insert(11);
  if(x==2 || y==2)cout << "No" << endl;
  else if(num.count(x)){
     if(num.count(y))cout << "Yes" << endl;
     else cout << "No" << endl;
  }
  else if(num.count(y))cout << "No" << endl;
  else cout << "Yes" << endl;
}
    

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll INF = 1LL << 60;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

vector<i_i> edges[1005][1005];
int memo[1005][1005];
bool visited[1005][1005];

int dfs(int i, int j) {
  if (memo[i][j] >= 0) return memo[i][j];
  visited[i][j] = true;

  int ret = 1;
  for (i_i p : edges[i][j]) {
    if (visited[p.first][p.second] && memo[p.first][p.second] < 0) return memo[i][j] = 999999999;
    chmax(ret, dfs(p.first, p.second) + 1);
  }

  return memo[i][j] = ret;
}

int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  rep(i, 0, n) {
    i_i prev{-1, -1};
    rep(j, 0, n - 1) {
      int to;
      cin >> to;
      to--;

      if (prev.first != -1) {
        edges[prev.first][prev.second].pb({min(i, to), max(i, to)});
      }
      prev.first = min(i, to);
      prev.second = max(i, to);
    }
  }

  int ans = 0;
  Fill(memo, int(-1));
  rep(i, 0, n) rep(j, 0, n) {
    if (i >= j) continue;
    chmax(ans, dfs(i, j));
  }

  cout << (ans >= 999999999 ? -1 : ans) << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 44544
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long int ll;
const int MOD=1000000007;
int main(){
  	int a[10];
	int flag = 1;
	for (int i=0; i<5; i++){
      cin >> a[i];
      if (a[i]==0){
        cout << flag << endl;
        return 0;
      } else {
        flag = a[i] + 1;
      }
    }
    return 0;
}

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

int main() {
  int N, A;
  cin >> N >> A;
  int x = N%500;
   
  if ( x > A) {
    cout << "No" << endl;
  }
  if ( x <= A)  {
    cout << "Yes" << endl;
}
}
    

Measured memory_bytes: 3632
def main():
    from sys import stdin
    input = stdin.readline
    n = int(input())
    g = [[] for _ in [0]*n]
    for _ in range(n-1):
        a, b = map(int, input().split())
        g[a-1].append(b-1)
        g[b-1].append(a-1)

    mod = 10**9+7
    fact = [1, 1]
    inv = [1]*(n+1)
    for i in range(2, n+1):
        fact.append(fact[-1]*i % mod)
    temp = pow(fact[-1], mod-2, mod)
    for i in range(n, 0, -1):
        inv[i] = temp*fact[i-1] % mod
        temp = temp*i % mod

    class rerooting():
        # addは頂点iに頂点jを根とする部分木（DPの値：x）をくっつけるときの補正
        def __init__(self, tree, ini):
            # merge:頂点aにbをマージするときのモノイド
            # adj_bu:ボトムアップ時の調整（a:値,i:頂点）
            # adj_td:トップダウン時の調整（a:値,i:頂点,p:親）
            # adj_fin:最終調整（a:値,i:頂点）
            def merge(a, b): return a * b % mod
            def adj_bu(a, i): return a * inv[size[i]] % mod
            def adj_td(a, i, p): return a * inv[n-size[i]] % mod
            def adj_fin(a, i): return a * fact[n-1] % mod

            # トポロジカルソートをする
            # T:木の隣接グラフ表現をset化
            # P:親
            # q:キュー
            # order:トポソしたもの
            T = g
            P = [-1]*n
            q = [0]
            order = []
            while q:
                i = q.pop()
                order.append(i)
                for a in T[i]:
                    if a != P[i]:
                        P[a] = i
                        T[a].remove(i)
                        q.append(a)

            # サイズの処理を先に行う
            # size[i]:0を根とする根付き木における、iを根とする部分木の大きさ
            size = [1]*n
            for i in order[1:][::-1]:
                size[P[i]] += size[i]

            # ボトムアップ処理をする
            # ME:マージした値を一時保存
            # DP:DP値、MEを調整したもの
            ME = [ini]*n
            DP = [0]*n
            for i in order[1:][::-1]:
                DP[i] = adj_bu(ME[i], i)
                p = P[i]
                ME[p] = merge(ME[p], DP[i])
            DP[order[0]] = adj_fin(ME[order[0]], order[0])
            TD = [ini]*n

            # トップダウン処理をする
            for i in order:
                # 左からDP（結果はTDに入れている）
                ac = TD[i]
                for j in T[i]:
                    TD[j] = ac
                    ac = merge(ac, DP[j])
                # 右からDP（結果はacに入れている、一度しか使わないのでacで問題ない）
                ac = ini
                for j in T[i][::-1]:
                    TD[j] = adj_td(merge(TD[j], ac), j, i)
                    ac = merge(ac, DP[j])
                    DP[j] = adj_fin(merge(ME[j], TD[j]), j)
            for i in DP:
                print(i)

    rerooting(g, 1)


main()


Measured memory_bytes: 109048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    int sum = 1;
    if (b == 1) {
        cout << 0 << endl;
        return 0;
    }
    while (1) {
        sum += a - 1;
        ans++;
        if (sum >= b) break;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	char s;
	for(int i=0; i<n; i++){
		cin >> s;
		if(s == 'Y') {
			cout << "Four";
			return 0;
		}
	}
	cout << "Three";
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  ll W,H,x,y;
  cin >> W >> H >> x >> y;
  int a=0;
  if(W==2*x && H==2*y) a=1;
  printf("%lf %d\n", W*H/2.0,a);
}


Measured memory_bytes: 3244
n = int(input())

k = int(input())

keta = len(str(n))

dp = [[[0 for j in range(keta+2)] for _ in range(2)]  for i in range(keta)]

s = str(n)

#dp[何桁目か][未満フラグ 0 = 未満][ゼロ以外のの個数]

x = int(s[0])
if x == 1:
    dp[0][1][0] = 1
else:
    dp[0][1][0] += 1
    dp[0][0][0] += x - 1


for index, c in enumerate(s[1:]):
    i = index + 1
    x = int(c)
    dp[i][0][0] += 9
    for j in range(k+1):
        dp[i][0][j] += dp[i - 1][0][j]
        if x == 0:
            dp[i][1][j] += dp[i - 1][1][j]
            dp[i][0][j + 1] += dp[i - 1][0][j] * 9
        elif x:
            dp[i][1][j + 1] += dp[i - 1][1][j]
            dp[i][0][j]     += dp[i - 1][1][j]
            dp[i][0][j + 1] += dp[i - 1][0][j] * 9
            dp[i][0][j + 1] += dp[i - 1][1][j] * (x - 1)
    # print(sum(dp[i][0]) + sum(dp[i][1]))
    # print(s[:index + 2])
    # print(dp)




print(dp[-1][0][k-1] + dp[-1][1][k-1])


Measured memory_bytes: 38384
// Problem C

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

#define MAXN 1000
#define pb push_back
#define mp make_pair

using namespace std;

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

ll A;
char b[10];
ll B;

int main() {
  cin >> A;
  cin >> b;
  if (strlen(b) == 4)
    B = (b[0]-'0')*100 + (b[2]-'0')*10 + b[3]-'0';
  else
    B = 1000;
  
  cout << A*B/100 << endl;
  
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <queue>

using namespace std;

long long gcd(long long a, long long b){
    if(b == 0) return a;

    return(gcd(b, a%b));
}

int main(){
    long long a, b, g, ans;
    cin >> a >> b;
    g = gcd(a, b);
    map<int, int> mp;
    for(long long i = 2; i*i<=g; i++){
        if(g == 1) break;
        while(g % i == 0){
            g = g/i;
            mp[i]++;
        }
    }
    if(g != 1) mp[g]++;
    ans = mp.size() + 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	int a1=a+b,a2=a-b,a3=a*b;
	if(a1>a2) a2=a1;
	if(a2>a3) a3=a2;
	cout<<a3;
	return 0;
}

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] key = new int[N];
        int[] L = new int[M];
        int[] R = new int[M];

        for (int i = 0; i < M; i++) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        Arrays.sort(R);
        Arrays.sort(L);

        if (R[0] - L[M - 1] + 1 > 0) {
            System.out.println(R[0] - L[M - 1] + 1);
        } else {
            System.out.println("0");
        }

        sc.close();

    }
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  string s;
  cin >> s;
  int a = -1,z = -1;
  REP(i,s.size()){
    s[i] == 'A' ? a != -1 ? a : a = i : a;
    s[i] == 'Z' ? z = i : z;
  }
  cout << z - a + 1 << endl;



  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>                                                   //---------------------------------------------------------------
                                                                    
# define ll long long   
# define ld long double                                               
# define mod 1000000007                                                   
# define MAX 100005
# define pi 3.141592653589793238                                                                                  //shortcut keys
                                                                                
# define pb push_back                                                                     
# define mp make_pair 
# define all(x) x.begin(),x.end()                                                      
                                                                  
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------                                       
using namespace std;
int main()
{
	int n;
	cin>>n;
	int x=n%10;
	if(x==2||x==4||x==5||x==7||x==9)
	cout<<"hon"<<'\n';
	else if(x==0||x==1||x==6||x==8)
	cout<<"pon"<<'\n';
	else
	cout<<"bon"<<'\n';
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const int MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    int mod13[10][6];
    rep(i,10){
        rep(j,6){
            if(j==0){
                mod13[i][j] = i;
            }else{
                mod13[i][j] = (mod13[i][j-1]*10) % 13;
            }
        }
    }

    ll ans = 0;

    int n = s.size();
    int dp[n+10][13];
    rep(i,13){
        rep(j,n+10){
            dp[j][i] = 0;
        }
    }

    rep(i,n){
        int x = n-1-i;
        if(s[x]=='?'){
            if(i==0){
                rep(j,10){
                    dp[i][j] = 1;
                }
            }else{
                rep(j,10){
                    rep(k,13){
                        dp[i][(k+mod13[j][i%6])%13] += dp[i-1][k];
                        dp[i][(k+mod13[j][i%6])%13] %= MOD;
                    }
                }
            }
        }else{
            int y = (int)s[x] - 48;
            if(i==0){
                dp[i][y] = 1;
            }else{
                rep(k,13){
                    dp[i][(k+mod13[y][i%6])%13] += dp[i-1][k];
                    dp[i][(k+mod13[y][i%6])%13] %= MOD;
                }
            }
        }
    }

    cout << dp[n-1][5] << endl;
    return 0;
}
 
 


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int A, B;
    cin >> A >> B;
    if(A%3 == 0 || B%3 == 0 || (A+B)%3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >>s;
  if(s[0]=='a' && s[1]=='b' && s[2]=='c') cout << "Yes" << endl;
  else if(s[0]=='a' && s[1]=='c' && s[2]=='b') cout << "Yes" << endl;
  else if(s[0]=='b' && s[1]=='a' && s[2]=='c') cout << "Yes" << endl;
  else if(s[0]=='b' && s[1]=='c' && s[2]=='a') cout << "Yes" << endl;
  else if(s[0]=='c' && s[1]=='b' && s[2]=='a') cout << "Yes" << endl;
  else if(s[0]=='c' && s[1]=='a' && s[2]=='b') cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main() {
  int H;
  cin >> H;
  vector<int> A(H + 1);
  for (int i = 1; i <= H; ++i)
    cin >> A[i];

  for (int i = 1; i <= H; ++i) {
    cout << "node " << i << ": key = " << A[i] << ", ";
    if (i != 1)
      cout << "parent key = " << A[i / 2] << ", ";
    if (2 * i <= H)
      cout << "left key = " << A[2 * i] << ", ";
    if (2 * i + 1 <= H)
      cout << "right key = " << A[2 * i + 1] << ", ";
    cout << endl;
  }
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, s;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	ll m = n;
	while (m) {
		s += m % 10ll;
		m /= 10ll;
	}
	cout << ((n % s == 0ll) ? "Yes" : "No") << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <math.h>

using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll k = s.length();
    ll ans=0;
    REP(i, k/2){
        if(s[i]!=s[k-i-1])ans++;
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long a[3][3],ans=0;
    f(i,0,3){
        f(j,0,3){
            cin>>a[i][j];
            ans+=a[i][j];
        }
    }
    if(ans%3!=0){
        cout<<"No"<<endl;
        return 0;
    }
    long long d[6];
    d[0]=a[0][0]+a[1][1]+a[2][2];
    d[1]=a[0][0]+a[1][2]+a[2][1];
    d[2]=a[0][1]+a[1][0]+a[2][2];
    d[3]=a[0][1]+a[1][2]+a[2][0];
    d[4]=a[0][2]+a[1][0]+a[2][1];
    d[5]=a[0][2]+a[1][1]+a[2][0];
    f(i,0,6){
        if(d[i]!=ans/3){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int n,m,A[200001];
    cin>>n>>m;
    rep(i,n) cin>>A[i];
    int sum=0;
    rep(i,n) sum+=A[i];
    int ans=0;
    rep(i,n) if(A[i]*4*m>=sum) ans++;
    if(ans>=m) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  while(1){
    long long a,b[70000],c[70000],d=0,e,f,g,h=0,i,j,k;
    cin >>a;
    if(a==0) break;
    for(int n=0;n<a;n++){
      cin >>b[n];
      d+=b[n];
    }
    e=d*a,f=a;
    for(int n=0;n<a-1;n++){
      cin >>c[n];
    }
    sort(c,c+a-1,greater<long long>());
    while(1){
      g=e/f+c[h],f--,h++;
      if(g*f>e) e=g*f;
      else break;
    }
    cout <<e<<'\n';
  }
  return (0);
}



Measured memory_bytes: 4088
l=sorted(map(int,input().split()))
d1=l[2]-l[0]
d2=l[2]-l[1]
if d1%2==0 and d2%2==0:
    print(d1//2 + d2//2)
elif d1%2==0 or d2%2==0:
    print(d1//2 + d2//2 + 2)
else:
    print(d1//2 + d2//2 + 1)

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

using namespace std;

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

    int ans = 0;
    for (int bit = 0; bit < (1 << 3); bit++) {
        string ans;
        int res = s[0] - '0';
        ans = s[0];
        for (int i = 0; i < 3; i++) {
            if (bit & (1 << i)) {
                res += s[i + 1] - '0';
                ans.push_back('+');
                ans.push_back(s[i + 1]);
            } else {
                res -= s[i + 1] - '0';
                ans.push_back('-');
                ans.push_back(s[i + 1]);
            }
        }
        if (res == 7) {
            ans.append("=7");
            cout << ans << endl;
            return 0;
        } 
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpi = vector<pii>;

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

    int k;
    cin >> k;
    string s = "";
    while (k--) s += "ACL";
    cout << s << "\n";

	return 0;
}


Measured memory_bytes: 3544
let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let len = String.length (string_of_int n) in
  let rec sum n i len =
    if i > len then 0 else (n / (int_of_float (10. ** float_of_int (i-1)))) mod 10 + sum n (i+1) len in
  Printf.printf "%s\n" (if n mod (sum n 1 len) = 0 then "Yes" else "No")

Measured memory_bytes: 4180
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef unsigned long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

const int sz = 500005;
char s[sz];
int st[sz+sz][26];

int N;
void build() {
	for (int i = 0; i < N; ++i) {
		st[i + N][s[i]-'a'] = 1;
	}
	for (int i = N-1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) {
			st[i][j] = st[i << 1][j] + st[i << 1 | 1][j];
		}
	}
}

int update(int pos, char cc) {
	--pos;
	st[pos + N][s[pos]-'a'] = 0;
	for (int i = pos + N; i > 0; i >>= 1) {
		st[i >> 1][s[pos]-'a'] = st[i][s[pos]-'a'] + st[i^1][s[pos]-'a'];
	}
	s[pos] = cc;
	st[pos + N][s[pos]-'a'] = 1;
	for (int i = pos + N; i > 0; i >>= 1) {
		st[i >> 1][s[pos]-'a'] = st[i][s[pos]-'a'] + st[i^1][s[pos]-'a'];
	}
}

int query(int L, int R) {
	--L;
	bool exist[26];
	RESET(exist);
	for (L += N, R += N; L < R; L >>= 1, R >>= 1) {
		if (L & 1) {
			for (int j = 0; j < 26; ++j) {
				exist[j] |= (st[L][j] > 0);
			}
			++L;
		}
		if (R & 1) {
			--R;
			for (int j = 0; j < 26; ++j) {
				exist[j] |= (st[R][j] > 0);
			}
		}
	}
	int tot = 0;
	for (int i = 0; i < 26; ++i) {
		tot	+= exist[i];
	}
	return tot;
}

int main() {
	sci(N);
	scanf("%s", s);
	build();
	int Q;
	sci(Q);
	while (Q--) {
		int type;
		sci(type);
		if (type == 1) {
			int i; char cc;
			cin >> i >> cc;
			update(i, cc);
		} else {
			int L, R;
			sci(L), sci(R);
			printf("%d\n", query(L,R));
		}
	}
	return 0;
}

Measured memory_bytes: 102400
H, W = map(int, input().split())
S = ['/'*(W+2)]
for i in range(H):
    S.append('/' + input().strip() + '/')
S += ['/'*(W+2)]

ans = []

for i in range(1, H+1):
    s = ''
    for j, x in enumerate(S[i][1:-1]):
        if x == '.':
            num = 0
            for n in range(3):
                for m in range(3):
                    if S[i+n-1][j+1+m-1] == '#':
                        num += 1
            s += str(num)
        else:
            s += x
    ans.append(s)
print(*ans, sep='\n')

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a[4], b[4];
	fill(a, a + 4, 0);
	fill(b, b + 4, 0);
	double c, d;
	while (cin >> c >> d) {
		if (c >= 1.1)
			a[0]++;
		else if (c >= 0.6)
			a[1]++;
		else if (c >= 0.2)
			a[2]++;
		else
			a[3]++;
		if (d >= 1.1)
			b[0]++;
		else if (d >= 0.6)
			b[1]++;
		else if (d >= 0.2)
			b[2]++;
		else
			b[3]++;
	}
	for (int i = 0; i < 4; i++) {
		cout << a[i] << " " << b[i] << endl;
	}
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}
Int tmp = 0;
double tmpd = 0.0;


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

    Int n, m, l, r;
    Int ll, rr;
    cin >> n >> m;

    Int cnt = 0;
    for(Int i=0; i<m; i++){
        cin >> ll >> rr;
        if(i==0){
            l = ll, r=rr;
            cnt = r-l+1;
            continue;
        }
        if(l <= ll && rr <= r){
            cnt = rr-ll+1;
            r = rr, l = ll;
            continue;
        }
        if(rr < l || r < ll){
            cnt = 0;
            break;
        }
        if(rr <= r){
            cnt = rr-l+1;
            r = rr;
        }
        if(l <= ll){
            cnt = r-ll+1;
            l = ll;
        }
    }   
    cout << cnt << endl;
    return 0;
}

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

int main() {
  int a[10];
  for (int i = 0; i < 10; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a, a + 10);
  printf("%d\n%d\n%d\n", a[9], a[8], a[7]);
}


Measured memory_bytes: 2708
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector< vector<int> > VVI;
typedef vector< vector<int> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VI A(N);
  rep(i,N) cin>>A[i];
  set<int> S;
  rep(i,N) S.insert(A[i]);
  int ans=0;
  sort(all(A));
  auto X=S.begin();
  rep(i,S.size()){
    int Y=ub(all(A),*X)-lb(all(A),*X);
    if(*X>Y) ans+=Y;
    else ans+=Y-*X;
    X++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5120
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

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

const int kMaxN = 2000;

int N, K, Q;
int A[kMaxN];
int ans = 1000000000;

signed main() {
  cin >> N >> K >> Q;
  REP(i, N) { cin >> A[i]; }

  REP(i, N) {
    int Y = A[i];

    vector<int> v;
    int j = 0;
    while (j < N) {
      vector<int> v2;
      while (j < N && A[j] >= Y) { v2.push_back(A[j]); ++j; }
      sort(v2.begin(), v2.end());
      REP(k, (int)v2.size() - K + 1) { v.push_back(v2[k]); }
      ++j;
    }

    sort(v.begin(), v.end());
    if (v.size() >= Q) { ans = min(ans, v[Q-1]-Y); }
  }

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


Measured memory_bytes: 384
#include <stdio.h>
int f(int r, int n){
	int s=0,i;
	if(r<0)return 0;
	if(!n)return!r;
	for(i=0;i<=9;i++)s+=f(r-i,n-1);
	return s;
}
int main( void ){
	int n;
	for(;~scanf("%d",&n);printf("%d\n",f(n,4)));
	return 0;
}

Measured memory_bytes: 0
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# 
# s = input()

a, b, c, k = list(map(int, input().split()))
ans = 0
if k > 0:
    ans += min(a, k)
    k -= a
    
if k > 0:
    k -= b

if k > 0:
    ans -= min(c, k)
    
print(ans)


Measured memory_bytes: 8912