akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


class Combination:
    def __init__(self, n, mod):
        assert 0 < n
        self.mod = mod
        self.fact = [1] * (n + 1)
        self.inv = [1] * (n + 1)
        for i in range(1, len(self.fact)):
            self.fact[i] = (i * self.fact[i - 1]) % self.mod
            self.inv[i] = pow(self.fact[i], self.mod - 2, self.mod)

    def nCr(self, n, k):
        if n == 0 and k == 0:
            return 1
        assert 0 <= n < len(self.fact) and 0 <= k
        a = self.fact[n]
        b = (self.inv[k] * self.inv[n - k]) % self.mod
        return a * b % self.mod


def main():
    H, W, A, B = map(int, input().split())
    MOD = 10 ** 9 + 7

    comb = Combination(100000 * 2 + 10, MOD)

    ans = 0
    for i in range(B + 1, W + 1):
        h, w = H - A - 1, i - 1
        s = comb.nCr(h + w, w) % MOD

        h, w = A - 1, W - i
        t = comb.nCr(h + w, w) % MOD

        ans += (s * t) % MOD
        ans %= MOD
    print(ans)



if __name__ == '__main__':
    main()


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

int main() {
  int a,b ; cin >> a >> b;
  string s; 
  
  if(a <= b){
    for(int i=0; i < b; i++){
      s += '0' + a;
    }
    cout << s << endl;
  }
  else{
    for(int i=0; i < a; i++){
      s += '0' + b;
    }
    cout << s << endl;
  }
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL; // VL a(n);
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VL> VLL; // VII a(n,VI(m)) n * m
typedef pair<ll, ll> PL;
typedef map<ll, ll> MP; // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

bool check(string s, string t){
  int n = s.size(), m = t.size();
  for(int i=0; i+m<=n; i++){
    bool ok = true;
    rep(j,m){
      if(!(s[i+j]=='?' || s[i+j]==t[j]))
        ok = false;
    }
    if(ok) 
      return true;
  }
  return false;
}


int main() {
  ll n,k,m,x=0,y=0,z = 0,h=0,w=0,ans=0,sum = 1, Max = -1, Min = 3e9+1;
  string s,t;
  bool ok=true;
  cin >> s >> t;
  if(!check(s,t)){
    pri("UNRESTORABLE"); return 0;
  }
  n = s.size();
  rep(i,n){
    if(s[i]=='?'){
      for(char c = 'a'; ;c++){
        s[i] = c;
        if(check(s,t))
          break;
      }
    }
  }
  pri(s);
  return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt() * sc.nextInt();
        int b = sc.nextInt() * sc.nextInt();
        if (a > b) {
            System.out.println(a);
        } else {
            System.out.println(b);
        }
    }
}

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

int N;
int64_t K;
std::vector<int64_t> A, F;

bool able(int64_t);

int main()
{
	scanf("%d%lld", &N, &K);
	A.resize(N);
	F.resize(N);
	for (auto& e: A) scanf("%lld", &e);
	for (auto& e: F) scanf("%lld", &e);
	std::sort(A.rbegin(), A.rend());
	std::sort(F.begin(), F.end());
	int64_t ng{-1}, ok{1ll << 60};
	while (ok - ng > 1)
	{
		int64_t mid{(ok + ng) >> 1};
		if (able(mid)) ok = mid;
		else ng = mid;
	}
	printf("%lld\n", ok);

	return 0;
}

bool able(int64_t score)
{
	int64_t cost{};
	for (int i{}; i < N; i++)
		cost += std::max(0l, A[i] - score / F[i]);
	return cost <= K;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 n, a, b;
  cin >> n >> a >> b;
  if (n * a < b) cout << n * a << endl;
  else cout << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)
 
int main() {
  ll N, M;
  cin >> N >> M;
  
  cout << N*(N-1)/2 + M*(M-1)/2 << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);


int a[10000], s[10000];
signed main(){
  int n;cin >> n;
  rrep(i,n)cin >> a[i];
  rrep(i,n)s[i] = s[i-1] + a[i];
  int ans = INF;
  rrep(i,n-1){
    int s1 = s[i] - s[0];
    int s2 = s[n] - s[i];
    ans = min(ans, abs(s1-s2));
  }
  cout << ans << endl;
  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.Arrays;
import java.util.Scanner;

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

    static class CStringTransformation {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int[] index = new int[26];
            Arrays.fill(index, -1);
            String s = in.next(), t = in.next();
            for (int i = 0; i < s.length(); i++) {
                int c = t.charAt(i) - 'a';
                if (index[c] >= 0 && s.charAt(index[c]) != s.charAt(i)) {
                    out.println("No");
                    return;
                }
                index[c] = i;
            }
            Arrays.fill(index, -1);
            for (int i = 0; i < s.length(); i++) {
                int c = s.charAt(i) - 'a';
                if (index[c] >= 0 && t.charAt(index[c]) != t.charAt(i)) {
                    out.println("No");
                    return;
                }
                index[c] = i;
            }
            out.println("Yes");
        }

    }
}



Measured memory_bytes: 27488
#include<stdio.h>
int main(){
  long int n,x,t,s,u,i;
  scanf("%ld%ld%ld",&n,&x,&s);
  u=x<s?s-x:0;
  s=x<s?x:s;
  for(i=1;i<n;i++){
    scanf("%ld",&t);
    u+=s+t>x?s+t-x:0;
    s=s+t>x?x-s:t;
  }
  printf("%ld",u);
}


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

using namespace std;

long long mod=1e9+7;

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

    long long total = 1;
    for(int i=0;i<N;i++){
        total = total * (i+1) % mod;  
    }
    cout << total << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	vector<int> vec;
	int a;
	for(int i=0; i<3; ++i){
		cin >> a;
		vec.emplace_back(a);
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	cout << vec.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};
int p[200000],q[200000];
signed main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,n){
		scanf("%d",&p[i]);p[i]--;
		q[p[i]]=i;
	}
	UnionFind uf(n);
	rep(i,m){
		int x,y;scanf("%d%d",&x,&y);x--;y--;
		uf.unite(x,y);
	}
	int ans=0;
	rep(i,n){
		if(uf.same(i,q[i]))ans++;
	}
	cout<<ans<<endl;
}

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

//2辺固定して残り１辺を二分探索

int main()
{
    int N;
    cin >> N;
    vector<long long> L(N);
    for (int i = 0; i < N; i++)
        cin >> L[i];
    sort(L.begin(), L.end());

    long long cnt = 0;

    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            int k = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();

            cnt += max(k - (j + 1), 0);
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N;
  cin>>N;
  vector<ll>A(N);
  for(ll i=0;i<N;i++)cin>>A[i];
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  ll ans=A[0];
  ll cnt=1;
  ll i=1;
  while(true){
    if(cnt==A.size()-1)break;
    for(ll j=0;j<2;j++){
      if(cnt==A.size()-1)break;
      ans+=A[i];
      cnt++;
      //cout<<i<<endl;
    }
    i++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    string s;
    cin >> s;
    mint ret  = 1;
    lint open = 0;
    for (int i = 0; i < 2 * n; ++i) {
        if (s[i] == 'B' && open % 2 == 0) {
            open++;
        } else if (s[i] == 'B' && open % 2 == 1) {
            ret *= open;
            open--;
        } else if (s[i] == 'W' && open % 2 == 0) {
            ret *= open;
            open--;
        } else if (s[i] == 'W' && open % 2 == 1) {
            open++;
        }
        if (open < 0 || open > n) {
            cout << 0 << "\n";
            return 0;
        }
    }
    if (open != 0) {
        cout << 0 << "\n";
        return 0;
    }
    for (int i = 1; i <= n; ++i) {
        ret *= i;
    }
    cout << ret << "\n";
    return 0;
}

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

#define fi first
#define se second

const int N = 200200;
const long long mod = 1e9 + 7;

using namespace std;

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        int n;
        cin >> n;
        vector < int > a(2 * n);
        for(int i = 0; i < 2 * n; i++){
                char c;
                cin >> c;
                a[i] = (c == 'B' ? 1 : 0);
                if(i % 2){
                        a[i] ^= 1;
                }
                if(a[i] == 0){
                        a[i] = -1;
                }
        }
        long long res = 1, bal = 0;
        for(int i = 0; i < 2 * n; i++){
                if(a[i] == -1){
                        res = res * bal % mod;
                }
                bal += a[i];
                if(bal < 0){
                        cout << 0 << "\n";
                        return 0;
                }
        }
        if(bal){
                cout << 0 << "\n";
                return 0;
        }
        for(int i = 1; i <= n; i++){
                res = res * i % mod;
        }
        cout << res << "\n";
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string,getline
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline
#include <cmath>	//ceil,M_PI

using namespace std;

int main() {

	int N, M;
	cin >> N >> M;

	if (N == M) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;

}

Measured memory_bytes: 3592
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

from collections import Counter

dp = Counter()
dp[0] = 0
for w, v in WV:
  ndp = Counter()
  for k in dp:
   	ndp[k] = max(dp[k], ndp[k])
   	if k+w <= W:
   	 	ndp[k+w] = max(dp[k] + v, ndp[k+w])
  dp = ndp
print(dp.most_common()[0][1])

Measured memory_bytes: 132792
#include<stdio.h>
int main()
{
    int a,b,c,x,y=0;
    scanf("%d%d%d",&a,&b,&c);
    for(x=a;x<=b;x++)
    {
        if(c%x==0)
            y++;
    }
    printf("%d\n",y);
    return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<string>
#include<algorithm> 
using namespace std;
int main(){
  int n,d[105]={0},max=0,sum=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>d[i];
  }
  sort(d,d+105);
  for(int i=1;i<=104;i++){
    if(d[i]>max){
      sum++;
      max=d[i];  
    }
  } 
  cout<<sum<<endl;
  return 0;
}

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

int main()
{
    int h, w;
    cin >> h;
    cin >> w;
    vector<string> a(h);
    for (int i = 0; i < h; i++)
    {
        cin >> a[i];
    }
    vector<bool> row(h, false);
    vector<bool> col(w, false);
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (a[i][j] == '#')
            {
                row[i] = true;
                col[j] = true;
            }
        }
    }

    for (int i = 0; i < h; i++)
    {
        if (row[i])
        {
            for (int j = 0; j < w; j++)
            {
                if (col[j])
                {
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
distance=[9999999999999999]*n
distance[0]=0
for i in range(n-1):
  for j in range(m):
    if distance[l[j][1]-1]>distance[l[j][0]-1]-l[j][2]:
      distance[l[j][1]-1]=distance[l[j][0]-1]-l[j][2]
f=[0]*n
for i in range(n):
  for j in range(m):
    if distance[l[j][1]-1]>distance[l[j][0]-1]-l[j][2]:
      distance[l[j][1]-1]=distance[l[j][0]-1]-l[j][2]
      f[l[j][1]-1]=1
    if f[l[j][0]-1]==1:
      f[l[j][1]-1]=1
if f[n-1]==0:
  print(-distance[n-1])
else:
  print('inf')

Measured memory_bytes: 47724
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
sAB = sorted(AB, key=lambda x: x[0])

ans = 0
cnt = 0
last_cnt = 0
for a, b in sAB:
    cnt += b
    if cnt < M:
        ans += a*b
        last_cnt = cnt
    else:
        ans += a*(M-last_cnt)
        break

print(ans)



Measured memory_bytes: 24388
#include<stdio.h>
int main()
{
	int a,b,sum=0;
	a>=1;
	b<=9;
	scanf("%d%d",&a,&b);
	sum=a+b;
	{
		if(sum>=10)
		printf("error\n");
		else
		printf("%d\n",sum);
	}
}

Measured memory_bytes: 128
/**
 * Created by hiramekun at 21:12 on 2020-04-02.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    vl a(n);
    cin >> a;
    map<ll, ll> mp;
    rep(i, n) mp[a[i]]++;
    ll ans = mp.size();
    ll tmp = 0;
    each(e, mp) {
        if (e.S % 2 == 0) tmp++;
    }
    ans -= tmp % 2;
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 7296
N, K, S = map(int, input().split())

ans = [0]*N
cnt = 0
for i in range(N):
  if cnt < K:
    ans[i] = str(S)
    cnt += 1
  else:
    ans[i] = str(min(S+1,10**9-1))
    
print(" ".join(ans))

Measured memory_bytes: 13300
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

string S;
int sums = 0;

void func( int n, int now, int sum ) {
  if( n == S.size() ) sums += now + sum;
  else {
    func( n + 1, S[n] - '0', sum + now );
    func( n + 1, now * 10 + S[n] - '0', sum );
  }
}

main()
{
  cin >> S;
  func( 0, 0, 0 );
  cout << sums / 2 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n,i,j,stage=1;
    scanf("%d",&n);

    int d[n];
    for(i=0;i<n;i++){
        scanf("%d",&d[i]);
        if(i>0) for(j=0;j<i;j++){
            if(d[i]==d[j]) break;
            if((j+1)==i) stage++;
        }
    }
    printf("%d\n", stage);
    return 0;
}

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

using namespace std;


char s[20];
int ask(int x) {
  printf("%d\n", x);
  fflush(stdout);
  scanf("%s", s);
  if (s[0] == 'V')
    return 0;
  else if (s[0] == 'M')
    return 1;
  else
    return -1;
}

int main() {
  int n;
  scanf("%d", &n);
  int res = ask(0);
  if (!res) return 0;
  int le = 1, ri = n-1;
  while (le < ri) {
    int mid = (le + ri) >> 1;
    int val = ask(mid % n);
    if (!val) return 0;
    if ((mid - le) & 1) {
      if (val == res)
        le = mid+1;
      else
        ri = mid-1;
    }
    else {
      if (val == res)
        ri = mid-1;
      else
        le = mid+1, res = val;
    }
  }
  assert(ask(le % n) == 0);
  return 0;
}

Measured memory_bytes: 852
/* AOJ 0118 Property Distribution */

#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef pair<int, int> pii;

const int MAX_H = 100;
const int MAX_W = 100;

char garden[MAX_W][MAX_H];
int h, w;
vector<pii> dir;

int count_partitions();
void dfs(int x, int y, char fruit);
void set_dir();

int
main()
{
    set_dir();

    for (;;) {
        cin >> h >> w;
        cin.ignore();

        if (h == 0 && w == 0) break;

        cout << count_partitions() << endl;
    }

    return 0;
}

int
count_partitions()
{
    int n_partitions = 0;
    int i, j;

    for (j = 0; j < h; j++) {
        string s;

        getline(cin, s);
        for (i = 0; i < w; i++)
            garden[i][j] = s[i];
    }

    for (i = 0; i < w; i++) {
        for (j = 0; j < h; j++) {
            switch (garden[i][j]) {
            case '@': // リンゴ
            case '#': // カキ
            case '*': // ミカン
                n_partitions++;
                dfs(i, j, garden[i][j]);
            }
        }
    }

    return n_partitions;
}

// 深さ優先探索
void
dfs(int x, int y, char fruit)
{
    vector<pii>::iterator it;

    // 探索済みを表す文字に書き換える
    garden[x][y] = '!';

    for (it = dir.begin(); it != dir.end(); ++it) {
        int x_new = x + it->first, y_new = y + it->second;

        if (0 <= x_new && x_new < w && 0 <= y_new && y_new < h &&
                garden[x_new][y_new] == fruit) {
            // 新しい座標が果樹園内で、同じ果物の場合、そこを起点に
            // さらに探索する
            dfs(x_new, y_new, fruit);
        }
    }
}

void
set_dir()
{
    dir.push_back(pii(1, 0)); // 右
    dir.push_back(pii(0, 1)); // 下
    dir.push_back(pii(-1, 0)); // 左
    dir.push_back(pii(0, -1)); // 上
}

Measured memory_bytes: 1688
#include <bits/stdc++.h>
using namespace std;
__int128 a[100005]={0};
inline __int128 read(){
    __int128 x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){                                        // 有快读和快速输出
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}

inline void print(__int128 x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}

int main(void){
    __int128 n= read();
    __int128 t=1,t1=0;
    __int128 m=1e18;
   
    for(int i=1;i<=n;i++){
    	  a[i]= read();
	}
	sort(a+1,a+n+1);
	if(a[1]==0){
		 cout<<0<<endl;
		 return 0;
	}
	for(int i=1;i<=n;i++){
		t=t*a[i];
		if(t>m){
			t1=1;
			break;
		}
		 
	}
	if(t1==1){
		cout<<-1<<endl;
		return 0;
	}
	else{
		print(t);
	}

    return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;

    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

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

    int ans = 1e9;
    for (int i = 0; i + k - 1 < n; i++) {
        ans = min(ans, h[i + k - 1] - h[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>Set;
typedef tree<int,int,less<int>,rb_tree_tag,tree_order_statistics_node_update> Map;

#define ipow(a,b)+0.5 (int)pow(a,b)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fi first
#define se second
#define pll pair<ll,ll>
#define ook order_of_key
#define findby find_by_order
#define pii pair<int,int>

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

template<typename X> inline X abs(const X& a) { return (a < 0 ? -a : a); }
template<typename X> inline X sqr(const X& a) { return (a * a); }

const ld EPS = ld(1e-9);
const ld PI = ld(3.141592653589);
ll n;
vector<pii>a;
set<int>check;
class Task
{
public:
    void solve(istream& in,ostream& out)
    {
          in>>n;
          factors();
          cnt();

          out<<*check.begin()<<endl;
    }

    void factors()
    {
          for(ll i=1;i<=(ll)sqrt(n);i++)
          {
               if(n%i==0)
               {
                    a.pb(mp(i,n/i));
               }
          }
    }

    void cnt()
    {
          rep(i,a.size())
          {
               ll b=a[i].fi;
               ll c=a[i].se;

               string B=to_string(b);
               string C=to_string(c);

               check.insert(max(B.length(),C.length()));
          }
    }
};


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	Task solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in,out);
	out.flush();

    return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	vector<ll> vec(n+1,0);
	for(ll i=1;i<=n;i++){
		cin>>vec[i];
	}
	
	ll ans=INT_MAX;
	for(ll i=1;i<=100;i++){
		ll p=0;
		for(ll j=1;j<=n;j++){
			ll u=vec[j]-i;
			p+=(u*u);
		}
		ans=min(ans,p);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import math

n, d = map(int, input().split())
x=[0]*n
y=[0]*n

for i in range(n):
  x_temp, y_temp = map(int, input().split())
  x[i] = x_temp
  y[i] = y_temp

ans = 0
for i in range(n):
  dis = math.sqrt(x[i]**2 + y[i]**2 )
  if dis <= d:
    ans +=1

print(ans)

Measured memory_bytes: 24696
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var A = one[0];
	var B = one[1];
	if(A % 2 != B % 2){
		myout("IMPOSSIBLE");
	}else{
		var tmp = (Math.max(A,B) - Math.min(A,B)) / 2;
		myout(Math.max(A,B) - tmp);
	}
}


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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int a[3][3];

bool check() {
  rep(i ,3) {
    if (a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) return true;
    if (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) return true;
  }
  if (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) return true;
  if (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0) return true;
  return false;
}

void f(int b) {
  rep(i, 3) rep(j, 3) {
    if (a[i][j] == b) {
      a[i][j] = 0;
    }
  }
}

int main() {
  rep(i, 3) rep(j, 3) cin >> a[i][j];
  int n;
  cin >> n;
  rep(i, n) {
    int b;
    cin >> b;
    f(b);
  }

  bool ans = check();
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<ll> a(n+1), b(n);
    rep(i, n+1) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll ans = 0;
    vector<ll> aa = a;
    rep(i, n) {
        if (a[i] > b[i]) {
            //cout << "test1" << endl;
            ans += b[i];
            a[i] -= b[i];
        }
        else {
            //cout << "test2" << endl;
            ans += a[i];
            ans += min(a[i+1], (b[i] - a[i]));
            //cout << b[i] - a[i] << endl;
            a[i+1] = max(0LL, a[i+1] - b[i] + a[i]);
            a[i] = 0;
        }
        //cout << ans << endl;
    }
    reverse(aa.begin(), aa.end());
    reverse(b.begin(), b.end());
    ll cnt = 0;
    rep(i, n) {
        if (aa[i] > b[i]) {
            //cout << "test1" << endl;
            cnt += b[i];
            aa[i] -= b[i];
        }
        else {
            //cout << "test2" << endl;
            cnt += aa[i];
            cnt += min(aa[i+1], (b[i] - aa[i]));
            //cout << b[i] - aa[i] << endl;
            aa[i+1] = max(0LL, aa[i+1] - b[i] + aa[i]);
            aa[i] = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5548
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;
typedef long long ll;

const int MOD = 1e9+7;
const int INF = 1e9;
string S;
int N;
ll solve(){
    ll res = 0;
    int cnt = 1;
    rep(i,N-1){
        if(S[i] == S[i+1]){
            cnt++;
        }
        else{
            if(cnt>1){
                res+= cnt/2;
            }
            cnt = 1;
        }
    }
    res += cnt/2;
    cerr<<res<<endl;

    return res;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K;
    cin>>S>>K;
    N = S.size();
    bool AllSame = true;
    rep(i,N-1){
        if(S[i]==S[i+1])continue;
        else AllSame = false;
    }
    if(AllSame){
        ll ans = (ll)N * K / 2;
        cout<<ans<<endl;
        return 0;
    }
    if(S[0] == S[N-1]){
        int cnt0 = 1;
        int cntN = 1;
        rep(i,N){
            if(S[i] == S[i+1])cnt0++;
            else break;
        }
        for (int i = N-1; i >= 0; --i){
            if(S[i-1] == S[i])cntN++;
            else break;
        }
        cerr<<cnt0<<" "<<cntN<<endl;
        ll ans = solve();

        if((cnt0 + cntN) % 2 == 0){
            ans = ans * K + K-1;
        }
        else ans *= K;
        cout<<ans<<endl;
        return 0;
    }
    else{
        ll ans = solve() * K;
        cout<<ans<<endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())


// a,bの最小公倍数
ll LCM(ll a, ll b){ll lcm = a * b; ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return lcm /= b;}
// a,bの最大公約数
ll GCD(ll a, ll b){ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return b;}


const int MOD = 1000000007;
const int INF = INT_MAX;



int main(){

    int n;
    cin >> n;
    ll x;
    cin >> x;
    ll c[n];
    rep(i,n) cin >> c[i];

    ll mx = MOD;
    rep(i,n) mx = min(mx, max(c[i] - x, x - c[i]));


    ll ans = mx;
    rep(i,n) {
        if ( (c[i] - x) % mx == 0) ;
        else {
            ans = GCD(ans, max(c[i] - x, x - c[i]));
        }
    }


    cout << ans << endl;

    
    
}





//              g++ -std=c++1z


Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair
#define MOD (LL)(1e9+7)

string S;
int dp[200000][2] ={};
int solve(int now, int bef){
	if(now == S.size()) return 0;
	if(now > S.size()) return -1000000;
	if(dp[now][bef] != 0) return dp[now][bef];
	int ret = -1000000;
	if(bef == 0){
		ret = max(ret, solve(now+2, 1));
		if(now == 0 || S[now-1] != S[now]) ret = max(ret, solve(now+1, 0));
	}
	else{
		ret = max(ret, solve(now+1, 0));
		if(now <= 1 || (S[now-2] != S[now] || S[now-1] != S[now+1])) ret = max(ret, solve(now+2, 1));
	}
	return dp[now][bef] = ret + 1;
}

int main(){
	cin >> S;
	cout << solve(0, 0) << endl;
}

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

int howmany(int x){
    int counter = 1;
    while(x/10 > 0){
        x /= 10;
        counter++;
    }
    return counter;
}

int f(int a, int b){
    return max(howmany(a), howmany(b));
}

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

    int a, b;
    for (int i = int(sqrt(n)); i>0; i--){
        if (n%i == 0){
            a = i;
            b = n/i;
            break;
        }
    }

    cout << f(a, b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin>>a>>b;
    int t =0;
    for(int i=0;i<a.size();i++){
        if(a[i] != b[i]){
            t++;
        }
    }
    cout<<abs(t);
    return 0;
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int n;
vector<string>ans;
void dfs(int now,int p,string x){
  if(now>n){
    ans.pb(x);
    return ;
  }
  for(int i=0;i<=p;i++){
    dfs(now+1,p,x+(char)(i+'a'));
  }
  dfs(now+1,p+1,x+(char)(p+1+'a'));
}
int main() {
  ios::sync_with_stdio(false);
  cin>>n;
  dfs(2,0,"a");
  sort(ans.begin(),ans.end());
  for(auto k:ans){
    cout<<k<<'\n';
  }
  return 0;
}


Measured memory_bytes: 7796
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll n;
    cin >> n;
    str s;
    vs s2(n);

    REP(i, n){
        cin >> s;
        sort(s.begin(), s.end());
        s2[i] = s;
    }
    sort(s2.begin(),s2.end());
    ll c = 1;
    ll ans = 0;
    FOR(i, 1, n-1){
        if(s2[i]==s2[i-1]){
            c++;
        }else{
            ans += c*(c-1)/2;
            c = 1;
        }
    }
    ans += c*(c-1)/2;

    cout << ans << endl;
}

Measured memory_bytes: 7808
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    long long N, A, B;

    cin >> N >> A >> B;

    if((B-A)%2==0) cout << "Alice" << endl;
    else cout << "Borys" << endl;

    return 0;
}

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

int main(){

  int a, b;

  cin >> a >> b;
  int tmp = a+b;

  if(a % 3 == 0){
    cout << "Possible" << endl;
  }else if(b % 3 == 0){
    cout << "Possible" << endl;
  }else if(tmp % 3 == 0){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, D;
string K;
ll dp[10010][110][2]; //0: equal, 1: smaller

void solve() {
	cin >> K;
	N = sz(K);
	cin >> D;
	dp[0][0][0] = 1;
	rep(i, 0, N) {
		rep(j, 0, D) {
			int a = K[i] - '0';
			//k == 0
			ADD(dp[i + 1][(j + a) % D][0], dp[i][j][0]);
			for(int k = 0; k < a; k++) {
				ADD(dp[i + 1][(j + k) % D][1], dp[i][j][0]);
			}

			//k == 1
			for(int k = 0; k < 10; k++) {
				ADD(dp[i + 1][(j + k) % D][1], dp[i][j][1]);
			}
		}
	}
	cout << (dp[N][0][0] + dp[N][0][1] - 1 + mod) % mod << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000001;
int cnt[maxn],num[maxn],ans,n,q,a[maxn];
int main()
{
    scanf("%d%d",&n,&q);
    for(int i=1; i<=n; i++) {scanf("%d",&a[i]); cnt[a[i]]++;}
    for(int i=1; i<=n; i++)
    {
        for(int j=max(i-cnt[i]+1,0); j<=i; j++) num[j]++;
    }
    for(int i=1; i<=n; i++) if(num[i]==0) ans++;
    for(int i=1; i<=q; i++)
    {
        int x,y;
		cin>>x>>y;
        cnt[a[x]]--; if(a[x]-cnt[a[x]]>0) {num[a[x]-cnt[a[x]]]--; if(num[a[x]-cnt[a[x]]]==0) ans++;}
        a[x] = y;
        if(y-cnt[y]>0) {if(num[y-cnt[y]]==0) ans--; num[y-cnt[y]]++;} cnt[y]++;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 6124
#include <cstdio> 
int maxn, minn=0x3f3f3f3f;
int main() {
	int n;
	scanf("%d", &n);
	for(int i=1, x;i<=n;i++) {
		scanf("%d", &x);
		if(maxn < x) maxn = x;
		if(minn > x) minn = x;
	}
	printf("%d\n", maxn - minn);
}

Measured memory_bytes: 128
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

M,K = map(int,input().split())

if K == 0:
    print(*[i//2 for i in range(2**(M+1))])
elif M == 1:
    print(-1)
elif K < 2**M:
    X = [i for i in range(2**M) if i != K]
    print(*(X+[K]+X[::-1]+[K]))
else:
    print(-1)

Measured memory_bytes: 69488
from itertools import product
n, *A = map(int, input().split())
L = [int(input()) for _ in range(n)]
m_ = sum(abs(A[i]-L[i]) for i in range(3))
for P in product(range(4), repeat = n):
    C = [[] for _ in range(4)]
    m = 0
    for i in range(n):
        C[P[i]].append(L[i])
    C = C[1:]
    if [] in C: continue
    for i in range(3):
        m += (len(C[i])-1)*10+abs(sum(C[i])-A[i])
    m_ = min(m_, m)
print(m_)

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

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0; i<(n); ++i)
#define TWO(x) (1ULL << x)

template<class T>
class seg_tree{
public:
	static const T invalid = TWO(31) - 1;

private:
	vector<T> dat;	ll n;

	T query(ll a, ll b, ll k, ll l, ll r){
		if (r <= a || b <= l) return invalid;
		if (a <= l && r <= b) return dat[k];

		ll mid = (l + r) / 2;
		T lval = query(a, b, k * 2 + 1, l, mid);
		T rval = query(a, b, k * 2 + 2, mid, r);
		return min(lval, rval);
	}
	
	void propagate(ll i){ dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]); }

public:
	seg_tree(ll size){
		n = 1; while(n < size) n <<= 1;
		dat = vector<T>(2 * n - 1, invalid);
	}

	seg_tree(const vector<T> & v){
		n = 1; while(n < v.size()) n <<= 1;
		dat = vector<T>(2 * n - 1, invalid);
		
		REP(i, v.size()) dat[n - 1 + i] = v[i];
		REP(i, n-2) propagate((n-2) - i);
	}
	
	void update(ll k, T val){
		k += n - 1;
		dat[k] = val;
		while(k > 0) propagate(k = (k-1)/2);
	}
	T query(ll a, ll b) { return query(a, b, 0, 0, n); }
};



int main(){
	while (true) {
		ll r,c,q;
		cin >> r >> c >> q;
		if (q == 0) break;

		bool is_reverse = r > c;
		vector<seg_tree<ll>> segs(min(r,c), seg_tree<ll>(max(r,c)));
		REP(i, r) REP(j, c) {
			ll x = i, y = j;
			if (is_reverse) swap(x, y);
			ll grid; cin >> grid;
			segs[x].update(y, grid);
		}

		REP(i, q) {
			ll minimum = seg_tree<ll>::invalid;
			ll x_1, y_1, x_2, y_2;
			cin >> x_1 >> y_1 >> x_2 >> y_2;
			if (is_reverse) swap(x_1, y_1), swap(x_2, y_2);
			REP(i, x_2 + 1 - x_1) minimum = min(minimum, segs[x_1 + i].query(y_1, y_2 + 1));
			cout << minimum << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 33836
def add(N):
    n = N % 10
    ret = N * 10
    if n == 0:
        return [ret, ret + 1]
    elif n == 9:
        return [ret + 9,ret + 8]
    else:
        return [ret + n - 1, ret + n, ret + n + 1]

X = int(input())
l = [1,2,3,4,5,6,7,8,9]
lists = list()
lists.append(l)
n = 9
while n < X:
    list_ = lists[-1]
    templist = list()
    for l_ in list_:
        vals = add(l_)
        n += len(vals)
        templist.extend(vals)
    lists.append(templist)

R = list()
for list_ in lists:
    R.extend(list_)
R.sort()
print(R[X-1]) 

Measured memory_bytes: 13280
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long n, a, b = 0, e;
	 cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a;
		while (a % 2 == 0) {
			a = a / 2;
			b++;
		}
	}
	cout << b << endl;
	cin >> e;
}

Measured memory_bytes: 256