akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, n;
    cin >> H >> W >> n;
    int sr, sc;
    cin >> sr >> sc;
    string s, t;
    cin >> s >> t;

    bool ans = true;
    for (char c : "LRUD") {
        if (c == 'L') {
            int c1 = 0, c2 = 0;
            for (int i = 0; i < n; i++) {
                c1 += (s[i] == c);
                if (sc + c2 - c1 <= 0) {
                    ans = false;
                    break;
                }
                if (t[i] == 'R' && sc + c2 + 1 - c1 <= W) {
                    c2++;
                }
            }
        } else if (c == 'R') {
            int c1 = 0, c2 = 0;
            for (int i = 0; i < n; i++) {
                c1 += (s[i] == c);
                if (sc + c1 - c2 > W) {
                    ans = false;
                    break;
                }
                if (t[i] == 'L' && sc + c1 - c2 - 1 > 0) {
                    c2++;
                }
            }
        } else if (c == 'U') {
            int c1 = 0, c2 = 0;
            for (int i = 0; i < n; i++) {
                c1 += (s[i] == c);
                if (sr + c2 - c1 <= 0) {
                    ans = false;
                    break;
                }
                if (t[i] == 'D' && sr + c2 + 1 - c1 <= H) {
                    c2++;
                }
            }
        } else {
            int c1 = 0, c2 = 0;
            for (int i = 0; i < n; i++) {
                c1 += (s[i] == c);
                if (sr + c1 - c2 > H) {
                    ans = false;
                    break;
                }
                if (t[i] == 'U' && sr + c1 - c2 - 1 > 0) {
                    c2++;
                }
            }
        }
    }

    cout << (ans ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 920
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	private static final String BR = System.getProperty("line.separator");
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			
			StringBuilder s = new StringBuilder();
			String[] strArray;	
			String line = br.readLine();
			
			while(line.equals("0 0") == false){	
				strArray = line.split("\\s");
				for (int i = 0; i < Integer.parseInt(strArray[0]); i++) {
					for (int j = 0; j <  Integer.parseInt(strArray[1]); j++) {
						if(i == 0 ||i == Integer.parseInt(strArray[0]) - 1 || j == 0 || j == Integer.parseInt(strArray[1]) - 1){
							s.append("#");	
						}else{
							s.append(".");
						}
					}
					s.append(BR);
				}
				System.out.println(s);
				s.delete(0, s.length());
				line = br.readLine();			
			}				
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	}
}

Measured memory_bytes: 21848
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long K, std::string S);

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
}

void solve(long long K, std::string S){
    if(S.length()<=K){
        cout << S << el;
        return;
    }
    S += "   ";
    S[K] = S[K+1] = S[K+2] = '.';
    S[K+3] = 0;
    S=S.substr(0, K+3);
    cout << S << el;
}



Measured memory_bytes: 3696
N, X = map(int, input().split())
L = list(map(int, input().split()))
ans = 0

for i in range(1, N):
    if i == 1:
        L[i] = L[i] + L[0]
    else:
        L[i] = L[i] + L[i-1]
L.append(0)
for i in L:
    if i <= X:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>
#define inf 1e18
using namespace std;
typedef long long ll;
inline ll rd()
{
	ll x=0,p=1;
	char a=getchar();
	while((a<48||a>57)&&a!='-')a=getchar();
	if(a=='-')p=-p,a=getchar();
	while(a>47&&a<58)
	{
		x=(x<<1)+(x<<3)+(a&15);
		a=getchar();
	}
	return x*p;
}
inline void swap(ll &x,ll &y){ll t=x;x=y;y=t;}
const int N=100002;
ll n,l,q,d[N][40],a[N],lgn;
inline int div(ll k)
{
	int l=1,r=n,mid,ans;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(a[mid]>k)r=mid-1;
		else l=mid+1;
	}
	return r;
}
int main()
{
	n=rd();lgn=log2(n);
	for(int i=1;i<=n;i++)a[i]=rd();
	l=rd();q=rd();
	for(int i=1;i<=n;i++)d[i][0]=div(a[i]+l);
	for(int j=1;j<=lgn;j++)
		for(int i=1;i<=n;i++)
			d[i][j]=d[d[i][j-1]][j-1];
	while(q--)
	{
		ll x,y,ans=0;
		x=rd();y=rd();
		if(x>y)swap(x,y);
		for(int j=lgn;j>=0;j--)
			if(d[x][j]<y)x=d[x][j],ans+=(1<<j);
		printf("%lld\n",ans+1);
	}
	return 0;
}

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

int main(){
	ll a, b, n;

	cin >> a >> b >> n;

	ll max;
	if(n < b){
		max = a*n/b;
	}else{
		max = a*(b-1)/b;
	}

	cout << max;
}


Measured memory_bytes: 3632
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var Sa = ReadLine();
            var Sb = ReadLine();
            var Sc = ReadLine();
            var mem = new string[] { Sa, Sb, Sc };
            var turn = 0L;
            while (true)
            {
                if (mem[turn].Length == 0)
                {
                    WriteLine((char)('A' + turn));
                    return;
                }
                var next = mem[turn][0] - 'a';
                mem[turn] = mem[turn].Remove(0, 1);
                turn = next;
            }
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<string>
using namespace std;
#define MAX 2000000
#define INF (1<<30)

int H=0;
int* h= new int[MAX+1];

void insert(int k){
    h[++H]=-INF;
    if(k<h[H]) return;
    h[H]=k;
    int i=H;
    while(i>1&&h[i]>h[i/2]){
        swap(h[i],h[i/2]);
        i=i/2;
    }
}

void maxHeapify(int i){
    int largest=i;
    if(i*2<=H&&h[i*2]>h[largest]) largest=i*2;
    if(i*2+1<=H&&h[i*2+1]>h[largest]) largest=i*2+1;
    if(i!=largest){
        swap(h[i],h[largest]);
        maxHeapify(largest);
    }
}

void extract(){
    if(H<1) return;
    int maxv=h[1];
    h[1]=h[H--];
    maxHeapify(1);
    cout<<maxv<<endl;
}

int main(){
    int k;
    string com;
    cin>>com;
    while(com!="end"){
        if(com=="insert"){
            cin>>k;
            insert(k);
        }
        if(com=="extract"){
            extract();
        }
        cin>>com;
    }
}


Measured memory_bytes: 6956
using System;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //string[] str = Console.ReadLine().Split(' ');
            //int n = int.Parse(Console.ReadLine());

            string s = Console.ReadLine();
            if(s=="hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi")
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }


            //ここまで
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second  
#define endl '\n'
#define pb push_back
#define t_case ll tt; cin>>tt; while (tt--)
#define all(v) v.begin(),v.end()
#define ub(a,x) upper_bound(all(a),x)-a.begin()
#define lb(a,x) lower_bound(all(a),x)-a.begin()
#define fr(a,b,c) for (ll a=b;a<c;a++)
#define take(xx,n) for (int i=0;i<n;i++) cin>>xx[i];
#define take1(xx,n) for (int i=1;i<=n;i++) cin>>xx[i];
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

int main() 
{
	fastio
	//t_case
	{
		int n,m,q,ans=0,f=1,d,k,x,y,sum=0,h,w,black=0 ;cin>>h>>w>>k   ; 
		string s[6]; take(s,h);
		fr(m1,0,1<<h)
			fr(m2,0,1<<w){
				int cnt=0;
				fr(i,0,h) fr(j,0,w)
					    if (s[i][j]=='#'&& !((m1>>i)&1) && !((m2>>j)&1)) 
							cnt++;
				if(cnt==k) ans++;
			}
	    cout<<ans;
	}
	
	return 0;
}

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

int main() {
	int n,i,j;
	cin>>n;
	int a=n;
	vector<int> d(n);
	for(i=0;i<n;i++)cin>>d.at(i);
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(d.at(i)==d.at(j)){a--;break;}
		}
	}
	cout<<a;
	// your code goes here
	return 0;
}

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

Measured memory_bytes: 600
import numpy as np

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

if N >= M:
    c = 0
else:
    X = np.array(sorted(X))
    dist = np.sort(X[1:] - X[:-1])
    c = np.sum(dist[:M-N])

print(c)

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
#define pqasc priority_queue<long long, vector<long long>, greater<long long>>

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; cin>>n;
  vi a(n+1);
  reps(i,n) cin>>a[i];
  
  vi b(n+1);
  
  rreps(i,n){
    int other=0;
    for(int x=i*2; x<=n; x+=i) if(b[x]) other++;
    if(other%2!=a[i]) b[i]=1;
  }
  
  vi ans;
  reps(i,n) if(b[i]) ans.push_back(i);
  
  cout<<ans.size()<<endl;
  for(auto d: ans) cout<<d<<endl;
}


Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

string s;

int main(){
    cin >> s;

    string f = "FESTIVAL";
    int n = f.size();
    cout << s.substr(0,s.size()-n) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    cin >> __VA_ARGS__;
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

template <class T>
inline istream &operator,(istream &is, T &rhs) {
    return is >> rhs;
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

struct UnionFind {  // {{{
    vector<int> u;
    explicit UnionFind(int n) : u(n + 5, -1) {}
    int size(int x) { return -u[root(x)]; }
    int root(int x) { return (u[x] < 0) ? x : (u[x] = root(u[x])); }
    bool same(int x, int y) { return (root(x) == root(y)); }
    bool unite(int x, int y) { return (x = root(x)) == (y = root(y)) ? false : (u[x] += u[y], u[y] = x, true); }
};  // }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, N, K);
    UnionFind uf(N);

    rep(i, 0, K) {
        var(int, a, b);
        --a, --b;
        uf.unite(a, b);
    }

    map<int, int> cnt;
    rep(i, 0, N) {
        cnt[uf.root(i)] += 1;
    }

    int ans = 0;
    for (const auto [root, num] : cnt) {
        chmax(ans, num);
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 13456
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>

using namespace std;


int main(int argc, char *argv[]) {
	int h, w, kk;
	cin >> h >> w >> kk;
	int res = h * w;
	vector<vector<int>> data;
	for (int i = 0; i < h; i++) {
		vector<int> row_data;
		string s;
		cin >> s;
		for (int j = 0; j < w; j++)
			row_data.push_back(s[j] - '0');
		data.push_back(row_data);
	}

	for (int i = 0; i < pow(2, h - 1); i++) {
		vector<int> v;
		int t = i;
		int c = 0;
		for (int j = 0; j < h - 1; j++) {
			c += t % 2;
			v.push_back(t % 2);
			t /= 2;
		}
		vector<vector<int>> index_set;
		vector<int> index(1, 0);
		for (int j = 0; j < h - 1; j++) {
			if (v[j] == 1) {
				index_set.push_back(index);
				index.clear();
			}
			index.push_back(j + 1);
		}
		index_set.push_back(index);

		vector<int> sum(index_set.size(), 0);
		bool flag = true;
		for (int j = 0; j < w; j++) {
			vector<int> sum_next(index_set.size(), 0);
			for (int k = 0; k < index_set.size(); k++) {
				for (auto node : index_set[k]) {
					sum_next[k] += data[node][j];
				}
				if (sum_next[k] > kk) {
					flag = false;
					break;
				}
			}
			if (!flag) break;
			bool cut = false;
			for (int k = 0; k < index_set.size(); k++) {
				if (sum_next[k] + sum[k] > kk) {
					cut = true;
					break;
				} else {
					sum[k] += sum_next[k];
				}
			}
			if (cut) {
				c++;
				sum = sum_next;
			}
		}
		if (flag) {
			res = min(res, c);
		}
	}
	cout << res << endl;
}









Measured memory_bytes: 256
import sys
import numpy as np
from numba import njit
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


@njit("i4(i4,i4[:])", cache=True)
def proc(N, P):
    ans = 0
    Removed = np.zeros((500, 500), dtype=np.int8)
    Mat = np.zeros((500, 500), dtype=np.int16)
    Dy, Dx = np.array([1,0,-1,0]), np.array([0,1,0,-1])

    for y in range(N):
        for x in range(N):
            Mat[y, x] = min(y, N-1-y, x, N-1-x)
    #print(Mat)
    Buf = [(0, 0) for _ in range(1<<17)]
    Buf_idx = 0
    for i in range(N*N):
        p = P[i]
        y, x = divmod(p, N)
        ans += Mat[y,x]
        Removed[y,x] = 1
        Buf[Buf_idx] = (y, x)
        Buf_idx += 1
        while Buf_idx:
            Buf_idx -= 1
            vy, vx = Buf[Buf_idx]
            vr = Removed[vy,vx]
            val = Mat[vy,vx]
            #for dy, dx in zip(Dy, Dx):
            for j in range(4):
                uy, ux = vy + Dy[j], vx + Dx[j]
                if not (0<=uy<N and 0<=ux<N):
                    continue
                ur = Removed[uy,ux]
                if vr:
                    if Mat[uy,ux] >= val+1:
                        Mat[uy,ux] = val
                        Buf[Buf_idx] = (uy, ux)
                        Buf_idx += 1
                else:
                    if Mat[uy,ux] >= val+2:
                        Mat[uy,ux] = val+1
                        Buf[Buf_idx] = (uy, ux)
                        Buf_idx += 1
    return ans

N = int(readline())
P = np.array(read().split(), np.int32)-1
 
print(proc(N, P))

Measured memory_bytes: 123328
from collections import deque
# from math import factorial
import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)
n, m = list(map(int, input().split()))
room = [[] for i in range(n)]
for i in range(m):
    a, b = list(map(int, input().split()))
    room[a-1].append(b-1)
    room[b-1].append(a-1)

ans = [-1]*n


def bfs(i):
    q = deque()
    q.append(i)
    while q:
        x = q.popleft()
        for i in range(len(room[x])):
            if ans[room[x][i]] == -1:
                q.append(room[x][i])
                ans[room[x][i]] = x
    return


bfs(0)
print("Yes")
for i in range(1, n):
    print(ans[i]+1)



Measured memory_bytes: 33812
main :: IO ()
main = do
    [n, m, k] <- map read . words <$> getLine
    putStrLn $ if solve n m k then "Yes" else "No"

solve :: Int -> Int -> Int -> Bool
solve n m k = 
    k `elem` [ i * (m - j) + (n - i) * j | i <- [0 .. n], j <- [0 .. m] ]

Measured memory_bytes: 1020
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int N, K;
	cin >> N >> K;

	if (N % K != 0)
	{
		cout << 1;
	}
	else
	{
		cout << 0;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define bufsize 1<<22
char ibuf[bufsize];
char *ptr=ibuf;

void readint(int *i)
{
    *i=0;
    while(*ptr>='0')
    {
        *i=*i*10+*ptr-'0';
        ++ptr;
    }
    ++ptr;
}


main()
{
    fread(ibuf,1,bufsize,stdin);

    int h,w,k,sx,sy,tx,ty;
    readint(&h);
    readint(&w);
    readint(&k);
    readint(&sx);
    readint(&sy);
    readint(&tx);
    readint(&ty);
    sx--,sy--,tx--,ty--;
    const int dst=tx*w+ty;

    struct po {int x,y;};
    struct po qu[1<<20];
    struct po *beg=qu,*end=qu+1;
    beg->x=sx,beg->y=sy;
    unsigned int dist[1<<20];
    memset(dist,-1,sizeof(dist));
    dist[sx*w+sy]=0;
    while(beg!=end)
    {
        int x=beg->x,y=beg->y;
        unsigned int d=dist[x*w+y];
        ++beg;
        char *pt=ptr+x*(w+1)+y;
        char *const pcp=pt;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            a++,z+=w;
            pt+=w+1;
            if(a==h||*pt=='@'||dist[z]<=d) break;
            if(z==dst)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        pt=pcp;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            b++,z++;
            pt++;
            if(b==w||*pt=='@'||dist[z]<=d) break;
            if(z==dst)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        pt=pcp;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            a--,z-=w;
            pt-=w+1;
            if(a<0||*pt=='@'||dist[z]<=d) break;
            if(z==dst)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        pt=pcp;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            b--,z--;
            pt--;
            if(b<0||*pt=='@'||dist[z]<=d) break;
            if(z==dst)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
    }
    puts("-1");
}


Measured memory_bytes: 11268
#include<iostream>
using namespace std;
int main(){
	int n,x;
	cin>>n>>x;
	int d[n+1],k[n+1];
	for(int i=1;i<=n;++i)
		cin>>k[i];
	d[0]=0;
	for(int i=1;i<=n;++i)
		d[i]=d[i-1]+k[i];
	int sum=0;
	for(int i=1;i<=n;++i)	
		sum+=(d[i]<=x);
	cout<<sum+1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <complex>
#include <algorithm>

using namespace std;
using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using i32 = int_fast32_t;
using u32 = uint_fast32_t;

#define int i64

template<class T>
inline bool chmin(T &a, T b) { if(a > b) {a = b; return true;} return false; }
template <class T>
inline bool chmax(T &a, T b) { if(a < b) {a = b; return true;} return false; }
const int INF = 1LL << 60;

signed main() {
	int n;
	cin >> n;
	vector<int> a(n, 0), b(n, 0), c(n, 0);
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];

	vector<vector<int>> dp(n, vector<int>(3, 0));
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for(int i = 1; i < n; i++) {
		chmax(dp[i][0], dp[i - 1][1] + a[i]);
		chmax(dp[i][0], dp[i - 1][2] + a[i]);
		chmax(dp[i][1], dp[i - 1][0] + b[i]);
		chmax(dp[i][1], dp[i - 1][2] + b[i]);
		chmax(dp[i][2], dp[i - 1][0] + c[i]);
		chmax(dp[i][2], dp[i - 1][1] + c[i]);
	}

	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
	
	return 0;
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n, m;
	cin >> n >> m;

	cout << (n-1) * (m-1) << endl;
	
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
s = input()
s_list=list(s)
s_len=len(s_list)
s_first=int(s_list[0]+s_list[1])
s_second=int(s_list[2]+s_list[3])
if s_first<13 and s_first>0: #MMYY case
    if s_second<13 and s_second>0:
        print('AMBIGUOUS')
    else:
        print('MMYY')

else: #YYMM case
    if s_second<13 and s_second>0:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    vector<int> A(3, 0); cin >> A[0] >> A[1] >> A[2];
    sort(A.begin(), A.end());
    printf("%d\n", (A[0] * A[1]) / 2); 
}

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

def bs(a, n):
  cnt=0
  f = True
  while f:
    f = False
    for i in range(n-1):
      v = a[i]
      if v>a[i+1]:
        a[i] = a[i+1]
        a[i+1] = v
        cnt+=1
        f = True
  return a,cnt

b,c = bs(a, n)

for i in range(n):
    if i==n-1:
      print(b[i], end='')
    else:
      print(b[i], end=' ')

print()
print(c)


Measured memory_bytes: 5616
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int train = n * a;
        int taxi = b;
        System.out.println(Math.min(train, taxi));
    }
}


Measured memory_bytes: 24276
S=input()

for i in range(100000):
    if S=="":
        print("YES")
        break
    elif S[-5:-1]=='drea':
        S=S[0:len(S)-5]
    elif S[-7:-1]=='dreame':
        S=S[0:len(S)-7]
    elif S[-5:-1]=='eras':
        S=S[0:len(S)-5]
    elif S[-6:-1]=='erase':
        S=S[0:len(S)-6]
        
if S!="":
    print("NO")


Measured memory_bytes: 3188
n,m = map(int,input().split())
list1 = list(input())

first,last = 0,0 #しゃくとり法の、firstとlast
count = 0
flag = 1 #2変更毎にスワップしてく為
#操作１、変更できる部分についてのループ
#時間削減のため、わざわざリストを操作しない。どこまでしゃくとれたかで考える
for i in range(m+1): #変更可能回数+1だけループ(理由：変更したあとの、次の変わり目でループを止めたい)
	if first == n:
		break
	while True:
		if first == n:
			break
		if list1[first] != list1[last]:
			if flag:
				last = first
				first += 1
				flag = 0
				break
			else:
				flag = 1
				last = first
				if i == m:
					first += 1
					break #フラグ分ループ回数が多くなるから。本来は"理由："の為に止めたい
				
				
		first += 1

if first == n: #全ての要素が同一になったなら
	print(n-1)
	exit()

#操作２、変更でどれだけカウントが増えたのか計上。
#整理：lastは現在変わり目地点(変わったあと)にいる。
count += last -1 +1 #カウントは人数-1,なお、インデックスの概念が存在するので+1

#操作3、変更できない部分について地道にしゃくとりでカウント。
#なお、first,lastは引き継ぐことができる。
while True:
	if first == n:
		break
	while True:
		if first == n:
			count += first - last -1 #firstがnを超えてるので、一個戻す。
			break
		if list1[first] != list1[last]:
			count += first - last -1
			last = first
			first += 1
			break
		first += 1

print(count)


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"

void Main() {
    int a, p;
    cin >> a >> p;
    int ans = (a * 3 + p) / 2;
    cout << ans << "\n";
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

#define ll long long

int N, A[105], ans = 0;

int main(){
    cin >> N;

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

    for(int i = 0; i < N-1; i++){
        for(int j = i+1; j < N; j++) ans = max(ans, abs(A[i] - A[j]));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R') r++;
    }    
    if(n/2 < r) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]
    exchange_count = 0


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

    print(" ".join(map(str, nums)))
    print(exchange_count)

if __name__ == '__main__' :
    main()

Measured memory_bytes: 7788
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    h = list(map(int, input().split()))
    h[0] -= 1
    for i in range(n-1):
        if h[i]==h[i+1]:
            continue
        if h[i] > h[i+1]:
            print('No')
            exit()
        else:
            h[i+1] -= 1
    print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 59632
#include <stdio.h>

int main(void)
{
    int n;
    double w;
    double h;

    while (scanf("%d,%lf,%lf", &n, &w, &h) != EOF){
        if (w / h / h >= 25){
            printf("%d\n", n);
        }
    }

    return (0);
}

Measured memory_bytes: 624
#include <bits/stdc++.h>
using namespace std;
#define int ll
typedef long long ll ;
const int MAX=1e3+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
int dir[21][2]={{2,0},{0,2},{-2,0},{0,-2},{2,2},{-2,2},{2,-2},{-2,-2},
                {1,2},{1,-2},{-1,2},{-1,-2},{2,1},{2,-1},{-2,1},{-2,-1},
                {1,1},{1,-1},{-1,1},{-1,-1}};
int dir1[4][2]={{1,0},{-1,0},{0,1},{0,-1}};

struct Node{
    int a,b;
    int ci;

    Node(int aa,int bb,int cc){
        a=aa;
        b=bb;
        ci=cc;
    }
    bool operator<(const Node &no)const {
        return ci>no.ci;
    }
};

char a[MAX][MAX];
bool biao[MAX][MAX];
int h,w;
bool check(int x,int y){
    if(x>=1&&x<=h&&y>=1&&y<=w){
        return true;
    }
    return false;
}
queue<Node>q;
queue<Node>q2;
void solve(){
    cin>>h>>w;
    int ch,cw,dh,dw;
    cin>>ch>>cw>>dh>>dw;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>a[i][j];
        }
    }

    q.push(Node(ch,cw,0));
    biao[ch][cw]=1;
    bool is=true;
    ll ans=-1;
    while(is&&(!q.empty()||!q2.empty())) {
        while (!q.empty()) {
            Node begin = q.front();
            q.pop();
            if (begin.a == dh && begin.b == dw) {
                ans = begin.ci;
                is = false;
                break;
            }
            for (int i = 0; i < 4; i++) {
                Node next = Node(begin.a + dir1[i][0], begin.b + dir1[i][1], begin.ci);
                if (a[next.a][next.b] == '#') {
                    q2.push(begin);
                }
                if (check(next.a, next.b) && biao[next.a][next.b] == 0 && a[next.a][next.b] == '.') {
                    biao[next.a][next.b] = 1;
                    q.push(next);
                }
            }
        }
        while (!q2.empty()) {
            Node begin = q2.front();
            q2.pop();
            if (begin.a == dh && begin.b == dw) {
                ans = begin.ci;
                is = false;
                break;
            }
            for (int i =0; i <20; i++) {
                    Node next2 = Node(begin.a + dir[i][0], begin.b + dir[i][1], begin.ci + 1);
                    if (check(next2.a, next2.b) && biao[next2.a][next2.b] == 0 && a[next2.a][next2.b] == '.') {
                        biao[next2.a][next2.b] = 1;
                        q.push(next2);
                    }
            }
        }
    }
    if(is){
        cout<<-1;
    }else{
        cout<<ans;
    }

}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int _=1;
    //cin>>_;
    while(_--){
        solve();
    }
    return 0;
}


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

int main()
{
    int xmin=0,ymin=0,xmax,ymax,n;
    cin>>xmax>>ymax>>n;
    for(int i=0;i<n;i++)
    {
        int a,x,y;
        cin>>x>>y>>a;
        if(a==1)    xmin=max(x,xmin);
        if(a==2)    xmax=min(x,xmax);
        if(a==3)    ymin=max(y,ymin);
        if(a==4)    ymax=min(ymax,y);

    }
    if(xmin<xmax && ymin<ymax)
        cout<<(xmax-xmin)*(ymax-ymin);
    else
        cout<<0;
    return 0;
}



Measured memory_bytes: 3636
import sys,collections,math,random,fractions,bisect;sys.setrecursionlimit(10**7)
sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n")
def I(i=0): t = [int(x)-i for x in sr().split()];return t
def S(): t = sr().split(); return t if len(t) > 1 else t[0]
L1,L2,L3,L4, = [],[],[],[]
 
a, = I()
print(math.ceil(a/2))

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

int main() {
  int N,M;
  cin >> N;
  vector<string> s(N);
  
  for(int i = 0; i < s.size(); i++){
    cin >> s.at(i);
  }
  
  cin >> M;
  vector<string> t(M);
  for(int i = 0; i < t.size(); i++){
    cin >> t.at(i);
  }
  
  // 同じ文字列が何個あるか数えて、配列に格納
  vector<int> cnt(N);
  for(int i = 0; i < s.size(); i++){
    for(int j = 0; j < s.size(); j++){      
      if(s.at(i) == s.at(j)){
        cnt.at(i)++;
      }
    }
    
    for(int j = 0; j < t.size(); j++){
      if(s.at(i) == t.at(j)){
        cnt.at(i)--;
      }
    }
  }
  
  // 
  int ans = 0;
  for(int i = 0; i < cnt.size(); i++){
    if(ans < cnt.at(i)){
      ans = cnt.at(i);
    }
  }
    cout << ans << endl;
}


Measured memory_bytes: 256
s = gets.chomp
len = s.length
n = len / 2
if len.odd?
  ans1 = ('10' * n + '1').split('')
  ans2 = ('01' * n + '0').split('')
else
  ans1 = ('10' * n + '1').split('')
  ans2 = ('01' * n + '0').split('')
end

a1 = 0
s.split('').each_with_index do |e, i|
  a1 += 1unless ans1[i] == e
end

a2 = 0
s.split('').each_with_index do |e, i|
  a2 += 1unless ans2[i] == e
end

if a1 > a2
  puts a2
else
  puts a1
end

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

using namespace std;
using ll = long long;

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

  string s, t;
  cin >> s >> t;

  int ans = s.size();
  for (int i = 0; i <= s.size() - t.size(); i++) {
    string u = s.substr(i, t.size());
    int sum = 0;
    for (int j = 0; j < t.size(); j++) {
      if (u[j] != t[j])
        sum++;
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <tuple>
using namespace std;

int main(){

    int n, a, b;
    cin >> n >> a >> b;

    cout << min(n*a, b) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int A,B;

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

	cin >> A >> B;

	REP(i,2){
		if(A>B){
			ans += A;
			A--;
		}else{
			ans += B;
			B--;
		}
	}

	cout << ans << endl;


}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long X = Long.parseLong(sc.next());
		sc.close();

		long sum = 100;
		int count = 0;
		do {
			sum = (long) (sum * 1.01);
			count++;

		} while (sum < X);

		System.out.println(count);

	}

}


Measured memory_bytes: 35700
def paku(N, A, mid):
    if mid == 0:
        return False

    size = sum(A[:mid])

    for i in range(mid, N):
        if A[i] <= 2*size:
            size += A[i]
        else:
            return False

    return True


N = int(input())
A = [int(i) for i in input().split()]
A.sort()

top = N
btm = 0

while top - btm > 1:
    mid = (top + btm) // 2

    if paku(N, A, mid):
        top = mid
    else:
        btm = mid

ans = N - top + 1

print(ans)

Measured memory_bytes: 14252
#include<cstdio>
#include<cstring>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 100010
#define INF 0x3FFFFFFF
using namespace std;
typedef long long ll;
int n;
int a[MAXN];
bool flag[MAXN];
char s[20];
ll pre[MAXN];
ll sum,ans=-INF;
int main(){
	SF("%d",&n);
	flag[1]=0;
	SF("%d",&a[1]);
	for(int i=2;i<=n;i++){
		SF("%s",s);
		if(s[0]=='-')
			flag[i]=1;
		SF("%d",&a[i]);
	}
	for(int i=n;i>=1;i--)
		pre[i]=pre[i+1]+a[i];
	int las=1;
	while(flag[las]==0&&las<=n){
		sum+=a[las];
		las++;
	}
	while(las<=n){
		int las1=las+1;
		ll sum1=0;
		while(flag[las1]==0&&las1<=n){
			sum1+=a[las1];
			las1++;
		}
		if(las1<=n){
			ans=max(ans,sum-sum1-a[las]+pre[las1]);
		}
		sum-=a[las];
		las=las1;
		sum+=sum1;
	}
	ans=max(ans,sum);
	PF("%lld",ans);
}	

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;

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

const int maxn = 1e9 + 10, mod = 1e9 + 7;
const int maxa = 2e5 + 25;

int n,a,b;
int fact[maxa];

int power(int a, int b){
	int ret = 1;
	while(b){
		if(b & 1)
			ret = 1ll * ret * a % mod;
		b >>= 1;
		a = 1ll * a * a % mod;
	}
	return ret;
}

int main(){
	
	cin >> n >> a >> b;
	
	int ans = power(2, n);
	
	fact[0] = 1;
	int mul1 = 1, mul2 = 1;
	for(int i = 1; i <= b; i++){
		fact[i] = 1ll * fact[i-1] * i % mod;
		if(i <= a)
			mul1 = 1ll * mul1 * (n-i+1) % mod;
		mul2 = 1ll * mul2 * (n-i+1) % mod;
	}
	
	int sub = 1ll * mul1 * power(fact[a], mod - 2) % mod;
	sub += 1ll * mul2 * power(fact[b], mod - 2) % mod;
	sub++;
	sub %= mod;
	
	ans -= sub;
	if(ans < 0) ans += mod;
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

int main(void) {
  	int num, old=-1, counter=0;
 	std::cin >> num;
  
  	for(int i = 0; i < 4; i++) {
      int new_degree = num % 10;
      if(old == new_degree)
        counter++;
      else
        counter = 0;
      if(2 <= counter){
        std::cout << "Yes";
        return 0;
      }
      old = new_degree;
      num = (num - new_degree)/10;
    }
  	std::cout << "No";

	return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

n,m=map(int,input().split())
e=[]
ans=0

for i in range(m):
    a,b=map(int,input().split())
    e.append((a-1,b-1))
    
for i in range(m):
    uf = UnionFind(n)
    for a,b in e[:i]+e[i+1:]:
        uf.union(a,b)
    if uf.size(0) < n:
        ans+=1
print(ans)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{
    vi A(3);
    in(3,A);
    sort(all(A));
    
    int ans = 0;
    while(true){
        if(A[0] == A[1] && A[1] == A[2]){
            out(ans);
            return 0;
        }
        sort(all(A));
        if(A[2] > A[1]){
            A[0]++,A[1]++;
            ans++;
        }else{
            A[0]+=2;
            ans++;
        }
    }
    
    
    


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    ll ans=0;
    int i=h-a+1,j=b;
    while(i<=h&&1<=j){
        ans=(ans+COM(i+j-2,i-1)*COM(h-i+w-j,h-i))%MOD;
        i++,j--;
    }
    ans=(MOD+COM(h+w-2,h-1)-ans)%MOD;
    cout<<ans<<endl;
}


Measured memory_bytes: 12160
MAXINT = 100010    # 十分に大きな数（回数）

# 引き出す金額を入力
N = int(input())

# 動的計画法のテーブル
dp = [MAXINT] * (N + 1)

# 初期値を設定
dp[0] = 0

# １円からN円に向かって探索　貰うDP
for i in range(1, N + 1):
    dp[i] = min(dp[i - 1] + 1, dp[i])
    
    j = 0
    while (i - 6 ** j) >= 0:
        dp[i] = min(dp[i - 6 ** j] + 1, dp[i])
        j += 1
        
    j = 0
    while (i - 9 ** j) >= 0:
        dp[i] = min(dp[i - 9 ** j] + 1, dp[i])
        j += 1

print(dp[N])


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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int A, B, C;
	
	cin>>A>>B>>C;
	
	cout<<min(min(A+B, B+C), C+A)<<endl;
	
	
	return 0;
}

Measured memory_bytes: 888
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  int ans = 0;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      for(int k=0;k<10;k++){
        int l=0;
        vector<int> f = {i,j,k};
        int p = 0;
        while(l<n && p<3){
          if(f[p] == s[l]-'0'){
            p += 1;
          }
          l += 1;
        }
        if(p == 3) ans += 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using ll = long long;

using namespace std;

int main() {
    int n;
    ll m;
    cin >> n >> m;
    ll a[n];
    for (auto &ai:a) cin >> ai;
    sort(a, a+n, greater<ll>());
    ll l = 2 * a[n-1], r = 2 * a[0] + 1;
    int nums[n];
    while (r - l > 1) {
        ll mid = (l + r) / 2,
           sum = 0;
        for (int i=0; i<n; i++) {
            auto itr = partition_point(a, a+n, [&](ll x) {
                return x >= mid - a[i];
            });
            nums[i] = itr - a;
            sum += nums[i];
        }
        if (sum >= m) l = mid;
        else r = mid;
    }
    ll rui[n+1];
    rui[0] = 0;
    for (int i=0; i<n; i++) rui[i+1] = rui[i] + a[i];
    ll ans = 0,
       cnt = 0;
    for (int i=0; i<n; i++) {
        auto itr = partition_point(a, a+n, [&](ll x) {
            return x >= l - a[i];
        });
        ll k = itr - a;
        cnt += k;
        ans += rui[k] + a[i] * k;
    }
    cout << ans - (cnt - m) * l << '\n';
    return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

// 約数列挙
vector< ll > divisor(ll n) {
	vector< ll > ret;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(all(ret));
	return (ret);
}

int main() {
	ll A, B;
	cin >> A >> B;

	ll N = 1e6 + 1;
	vi as;
	vi bs;
	as.pb(1);
	bs.pb(1);

	repa(i, 2, N) {
		if (A % i == 0) {
			as.pb(i);
			while (A % i == 0) {
				A /= i;
			}
		}

		if (B % i == 0) {
			bs.pb(i);
			while (B % i == 0) {
				B /= i;
			}
		}
	}
	if (A != 1) {
		as.pb(A);
	}
	if (B != 1) {
		bs.pb(B);
	}


	ll ans = 0;
	ll bi = 0;
	ll bn = bs.size();

	for (auto a : as) {
		while (bi < bn && bs[bi] <= a) {
			if (bs[bi] == a) {
				ans++;
			}
			bi++;
		}
	}
	

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

Measured memory_bytes: 256