akhauriyash/Code-Regression huggingface dataset:
N = int(input())
t = [0] + [int(x) for x in input().split()]
v = [0] + [int(x) for x in input().split()]

max_speed_from_left = [0] * (N+1) # index i = t[i],t[i+1]の間
max_speed_from_right = [0] * (N+1) # index i = t[i],t[i+1]の間

for i in range(1,N):
  start = max_speed_from_left[i-1]
  max_speed_from_left[i] = min(start + t[i], v[i], v[i+1])
  
for i in range(N-1,0,-1):
  start = max_speed_from_right[i+1]
  max_speed_from_right[i] = min(start + t[i+1], v[i], v[i+1])

speed = [min(x,y) for x,y in zip(max_speed_from_left,max_speed_from_right)]

def dist(left_speed,right_speed,t,v):
  x = (v - left_speed) + (v - right_speed)
  if x >= t:
    v = (left_speed + right_speed + t)/2
    x = t
  # 最高速度vに到達して、t-xあまる
  d = (left_speed + v) * (v-left_speed)/2
  d += v*(t-x)
  d += (right_speed + v) * (v-right_speed)/2
  return d

answer = 0
for i in range(1,N+1):
  answer += dist(speed[i-1],speed[i],t[i],v[i])
print(answer)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 9 * 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}

int main() {
    string S;
    cin >> S;
    vector<int> vec(S.size());
    for(int i = 0;i < S.size();i++) {
        vec.at(i) = S.at(i) - '0';
    }
    reverse(vec.begin(),vec.end());
    vector<int> Sum(S.size() + 1);
    for(int i = 0;i < S.size();i++) {
        Sum.at(i + 1) = (Sum.at(i) + vec.at(i) * RepeatSquaring(10,i,2019)) % 2019;
    }
    map<int,int> ma;
    for(int i = 0;i < Sum.size();i++) {
        ma[Sum.at(i)]++;
    }
    int ret = 0;
    for(auto x:ma) {
        ret += x.second * (x.second - 1) / 2;
    }
    cout << ret << endl;
}

Measured memory_bytes: 5128
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int a, b;
	cin >> a >> b;
	int val = b * 2;
	if (a>val)cout << a-val << endl;
	else cout << "0" << endl;
	return 0;
}


Measured memory_bytes: 256
while True:
    (n, x) =  [int(i) for i in input().split()]
    if n == x == 0:
        break

    count = 0
    for a in range(1, n+1):
        for b in range(a+1, n+1):
            for c in range(b+1, n+1):
                if (a + b + c) == x:
                    count += 1
                elif (a + b + c) > x:
                    break
    print(count)

Measured memory_bytes: 6724
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

struct ans_data{
	int id;
	int parent;
	int depth;
	int state;
	vector<int> chl;
};

void dfs(vector<vector<int>> &tree, vector<ans_data> &va, int now, int par, int dp){
	auto &na = va.at(now);
	na.id = now;
	na.parent = par;
	na.chl = tree.at(now);
	na.depth = dp;
	if(par == -1) na.state = -1;
	else if(na.chl.size() == 0) na.state = 1;
	else na.state = 0;
	for(int i : na.chl){
		dfs(tree, va, i, now, dp+1);
	}
}

int main(){
	int n;
	cin >> n;
	vector<vector<int>> tree(n);
	rep(i, n){
		int id, m;
		cin >> id >> m;
		rep(j, m){
			int add;
			cin >> add;
			tree.at(id).push_back(add);
		}
	}
	vector<bool> ck(n, false);
	rep(i, n){
		for(int j : tree.at(i)){
			ck.at(j) = true;
		}
	}
	int par;
	rep(i, n){
		if(ck.at(i) == false){
			par = i;
			break;
		}
	}
	vector<ans_data> va(n);
	dfs(tree, va, par, -1, 0);
	rep(i, n){
		auto now = va.at(i);
		cout << "node " << now.id << ": parent = " << now.parent << ", depth = " << now.depth << ", ";
		if(now.state == -1) cout << "root";
		else if(now.state == 0) cout << "internal node";
		else cout << "leaf";
		cout << ", [";
		for(int j = 0; j < now.chl.size(); j++){
			if(j != 0) cout << ", ";
			cout << now.chl.at(j);
		}
		cout << "]" << endl;
	}
	return 0;
}


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

using namespace std;

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

#define N 1000000
int arr[N];

void eratosthenes(){
	rep(i,N){
		arr[i]=1;
	}

	for(int i=2;i<sqrt(N);i++){
		if(arr[i]){
			for(int j=0;i*(j+2)<N;j++){
				arr[i*(j+2)]=0;
			}
		}
	}
}


int main(){

	int a,b;
	while(1){
		cin>>a;
		if(a==0)break;
		b=a*2;

		eratosthenes();

		int count=0;

		arr[0]=0;
		arr[1]=0;

		// rep(i,a*2){
		// 	cout<<i<<" "<<arr[i]<<endl;
		// }

		repi(i,a+1,b+1){
			if(arr[i]==1)count++;
		}

		// cout<<"count:"<<count<<endl;
		cout<<count<<endl;

	}
}

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

int main()
{
	int N;
	cin >> N;
	vector<string> s(N);
	for (int i = 0; i < N; i++) {
		cin >> s.at(i);
	}

	int M;
	cin >> M;
	vector<string> t(M);
	for (int i = 0; i < M; i++) {
		cin >> t.at(i);
	}

	// 探索
	int k = 0;
	vector<int> a(N * 2, 1);
	for (int i = 0; i < N; i++) {
		if (s.at(i) == "")	continue;

		// 青カード
		for (int j = i + 1; j < N; j++) {
			if (s.at(i) == s.at(j)) {
				a.at(k)++;
				s.at(j) = "";
			}
		}
		k++;

		// 赤カード
		for (int j = 0; j < M; j++) {
			if (s.at(i) == t.at(j))	a.at(k)++;
		}
		k++;
	}

	// 計算
	int max = 0;
	for (int i = 0; i < k; i += 2) {
		int t_max = a.at(i) - (a.at(i + 1) - 1);
		if (t_max > max)	max = t_max;
	}

	cout << max << endl;
}

Measured memory_bytes: 256
x = int(input())
k = 0

def gcd(a,b):
    if b == 0:
        return a

    return gcd(b, a%b)

def lcm(a,b):
    return a*b /gcd(a,b)

saishoukoubai = lcm(360, x)
k = saishoukoubai / x

k = int(k)
print(k)


Measured memory_bytes: 9164
#include <iostream>

int main(){
    int i, j, ans;
    for(i=1; i<10; i++){
        for(j=1; j<10; j++){
            std::cout << i;
            std::cout << "x";
            std::cout << j;
            std::cout << "=";
            ans = i*j;
            std::cout << ans << std::endl;
        }
    }
}

Measured memory_bytes: 1116
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

void bfs(int st, vi& d, vector<vi>& g) {
	d[st] = 0;
	queue<int> que;
	que.push(st);
	while(!que.empty()) {
		int i = que.front();
		que.pop();
		for(auto j: g[i]) {
			if(d[j] != -1) continue;
			d[j] = d[i] + 1;
			que.push(j);
		}
	}
}

int main() {
//	cout << fixed << setprecision(15);
	int n, x, y;
	cin >> n >> x >> y;
	x--; y--;
	vector<vi> g(n);
	rep(i, n-1) {
		g[i].push_back(i+1);
		g[i+1].push_back(i);
	}
	g[x].push_back(y);
	g[y].push_back(x);
	vector<vi> d(n, vi(n, -1));
	rep(i, n) bfs(i, d[i], g);
	vi ans(n);
	for(int i = 0; i < n; i++) {
		for(int j = i+1; j < n; j++) {
			ans[d[i][j]]++;
		}
	}
	rep1(i, n-1) cout << ans[i] << endl;
}


Measured memory_bytes: 16128
import java.util.*;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        long n=sc.nextLong();
        long i;
        long ans=0;
        for(i=1;i*i<=n;i++){
            if(n%i==0)ans = i;
        }
        System.out.println(ans+n/ans-2);

    }

}



Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>


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; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

int parse(string& s, int &pos) {
	if ('0' <= s[pos] and s[pos] <= '2') {
		pos++;
		return s[pos - 1] - '0';
	}
	else if (s[pos] == '-') {
		pos++;
		int res = parse(s, pos);
		return 2 - res;
	}
	else {
		pos++;
		int p = parse(s, pos);
		char c = s[pos];
		pos++;
		int q = parse(s, pos);
		pos++;
		if (c == '+') return max(p, q);
		else return min(p, q);
	}
}

void solve() {
	string s; cin >> s; if (s == ".") exit(0);
	int res = 0;
	for (char P = '0'; P < '3'; P++) {
		for (char Q = '0'; Q < '3'; Q++) {
			for (char R = '0'; R < '3'; R++) {
				string t = s;
				for (int i = 0; i < t.size(); i++) {
					if (t[i] == 'P') t[i] = P;
					if (t[i] == 'Q') t[i] = Q;
					if (t[i] == 'R') t[i] = R;
				}
				int pos = 0;
				if (parse(t, pos) == 2) res++;
			}
		}
	}
	printf("%d\n", res);
}
int main()
{
	
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
	int kkt = 89;
	while (kkt) {
		solve();
	}
    return 0;
}


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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    cin >> n;
    vector<bool> sunukes(n, false);

    int k;
    cin >> k;
    rep(i, k) {
        int d;
        cin >> d;

        rep(j, d) {
            int a;
            cin >> a;
            a--;
            sunukes[a] = true;
        }

    }

    cout << count(sunukes.begin(), sunukes.end(), false) << endl;

}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int DigitsSum(int num){
	int digits;
	int sum = 0;
	while (num) {
		digits = num % 10;
		sum += digits;
		num /= 10;
	}
	return sum;
}

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

	char N;
	cin >> N;
	N++;
	
	cout << N;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int main() {
	ll i, j, n, x, s, ans=0;
	scanf("%lld%lld", &n, &x);
	vll a(2*n);
	for(i=0; i<n; i++) {
		scanf("%lld", &a[i]);
		a[i+n]=a[i];
		ans+=a[i];
	}
	vll b(a);
	for(i=1; i<n; i++) {
		s=0;
		for(j=0; j<n; j++) {
			b[j]=min(b[j], a[j+i]);
			s+=b[j];
		}
		ans=min(ans, s+i*x);
	}
	printf("%lld\n", ans);
   	return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  rep(i,s.size()){
    if(s[i]=='9'){
      cout<<"Yes"<<endl;
      return ;
    }
  }

  cout<<"No"<<endl;
  
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < (int) n; ++i)
#define ford(i, n) for (int i = ((int) n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#define FILE_NAME "a"

const int MAXN = 1e5 + 10;

int x, y;

bool read() {
	if  (scanf("%d%d", &x, &y) < 2) {
		return 0;
	}
	return 1;
}

int solve() {
	assert(x != y);
	if  (x >= 0) {
		if  (y >= x) {
			return y - x;
		}
		if  (y > 0) {
			return 2 + (x - y);
		}
		if  (y == 0) {
			return 1 + x;
		}
		assert(y < 0);
		if  (y >= -x) {
			return 1 + (y - -x);
		}
		assert(y < -x);
		return (-y - x) + 1;
	}
	assert(x < 0);
	if  (y <= 0) {
		if  (y >= x) {
			return y - x;
		}
		if  (y < x) {
			return 2 + (x - y);
		}
	}
	assert(y > 0);
	if  (y <= -x) {
		return 1 + (-x - y);
	}
	if  (y > -x) {
		return 1 + (y - -x);
	}
	assert(0);
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		printf("%d\n", solve());
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


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

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int D;
ll dp[10010][100];

// k % D = d (0 <= k <= K)
ll rec(const string& K, int d) {
    if (K.empty()) return d == 0;

    ll ret = 0;

    int t = K.front() - '0';

    // [t00~000, K]
    ret = rec(K.substr(1), (d + D - t) % D);

    for (int k = 0; k < t; ++k) {
        // [k00~000, k99~999]
        ret += dp[K.size() - 1][(d + D - k) % D];
    }

    return ret % MOD;
}

int main() {
    string K;
    cin >> K >> D;

    dp[0][0] = 1;
    for (int n = 1; n <= 10000; ++n) {
        for (int d = 0; d < D; ++d) {
            for (int k = 0; k < 10; ++k) {
                dp[n][(k + d) % D] += dp[n - 1][d];
                dp[n][(k + d) % D] %= MOD;
            }
        }
    }

    cout << (rec(K, 0) + MOD - 1) % MOD << endl;
    return 0;
}


Measured memory_bytes: 72064
ab = input()
ablist = ab.rsplit(" ")

abadd = int(ablist[0]) + int(ablist[1])

abminus = int(ablist[0]) - int(ablist[1])

abmultiply = int(ablist[0]) * int(ablist[1])

if abadd > abminus:
 if abadd > abmultiply:
  print(abadd)
 else:
  print(abmultiply)
else:
 if abminus > abmultiply:
  print(abminus)
 else:
  print(abmultiply)



Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] rc = new int [r+1][c+1];
		//r???c?????????????????????
		for(int i=0; i<r; i++){
			for(int j=0; j<c; j++){
				rc[i][j] = scan.nextInt();
			}
		}
		//???+1???????????????
		for(int i=0; i<c; i++){
			rc[r][i] = 0;
			for(int j=0; j<r; j++){
				rc[r][i] += rc[j][i];
			}
		}
		// c+1???????????????
		for(int i=0; i<r+1; i++){
			rc[i][c] = 0;
			for(int j=0; j<c; j++){
				rc[i][c] += rc[i][j];
			}
		}
		for(int i=0; i<r+1; i++){
			for(int j=0; j<c; j++){
				System.out.print(rc[i][j] + " ");
			}
			System.out.println(rc[i][c]);
		}
	}
}

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

using namespace std;

#define rep(i, a, b)  for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define sq(x) ((x) * (x))
#define bit(x) bitset<32>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<llint>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


template<typename Tn> Tn __lcm(Tn a, Tn b)
{
    return a / __gcd(a, b) * b;
}

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

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

    if(k == 1) co << 0 << en;
    else co << n - k << en;
  
    return 0;
}


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

using namespace std;

int dfs(int v, int max_len, int p, vector<vector<int> > &g) {
    if (max_len == 0) {
        return 0;
    }
    int res = 1;
    for (int to : g[v]) {
        if (to == p) {
            continue;
        }
        res += dfs(to, max_len - 1, v, g);
    }
    return res;
}

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    vector<vector<int> > g(n);
    for (int i = 0; i + 1 < n; i++) {
        int fr, to;
        scanf("%d %d", &fr, &to);
        fr--;
        to--;
        g[fr].push_back(to);
        g[to].push_back(fr);
    }
    int res = 0;
    for (int root = 0; root < n; root++) {
        int dp0 = 1, dp1 = 1;
        for (int to : g[root]) {
            int not_use = dfs(to, k / 2, root, g);
            int use = dfs(to, k / 2 + 1, root, g);
            int nextDP1 = max(dp1 + not_use, dp0 + use);
            dp0 += not_use;
            dp1 = nextDP1;
        }
        if (k % 2 == 1) {
            dp0 = dp1;
        }
        res = max(res, dp0);
    }
    printf("%d\n", n - res);
    return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rs64() {
	int64_t n;
	scanf("%" SCNd64, &n);
	return n;
}
#define MOD 1000000007
template<int mod>
struct ModInt{
	int x;
	ModInt():x(0){}
	ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=mod-p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1LL*x*p.x%mod);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inverse();
		return *this;
	}
	ModInt &operator^=(long long p){
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	ModInt operator-()const{return ModInt(-x);}
	ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
	ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
	ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
	ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
	ModInt operator^(long long p)const{return ModInt(*this)^=p;}
	bool operator==(const ModInt &p)const{return x==p.x;}
	bool operator!=(const ModInt &p)const{return x!=p.x;}
	explicit operator int() const { return x; }						   // added by QCFium
	ModInt operator=(const int p) {x = p; return ModInt(*this);} // added by QCFium
	ModInt inverse()const{
		int a=x,b=mod,u=1,v=0,t;
		while(b>0){
			t=a/b;
			a-=t*b;
			std::swap(a,b);
			u-=t*v;
			std::swap(u,v);
		}
		return ModInt(u);
	}
	friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
		return os<<p.x;
	}
	friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
		long long x;
		is>>x;
		a=ModInt<mod>(x);
		return (is);
	}
};
typedef ModInt<MOD> mint;

struct MComb {
	std::vector<mint> fact;
	std::vector<mint> inversed;
	MComb(int n) { // O(n+log(mod))
		fact = std::vector<mint>(n+1,1);
		for (int i = 1; i <= n; i++) fact[i] = fact[i-1]*mint(i);
		inversed = std::vector<mint>(n+1);
		inversed[n] = fact[n] ^ (MOD-2);
		for (int i = n - 1; i >= 0; i--) inversed[i]=inversed[i+1]*mint(i+1);
	}
	mint ncr(int n, int r) {
		return (fact[n] * inversed[r] * inversed[n-r]);
	}
	mint npr(int n, int r) {
		return (fact[n] * inversed[n-r]);
	}
	mint nhr(int n, int r) {
		assert(n+r-1 < (int)fact.size());
		return ncr(n+r-1, r);
	}
};

int main() {
	int n = ri();
	int k = ri();
	int res = 0;
	while (n) n /= k, res++;
	printf("%d\n", res);
	return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef long double LD;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()

LL MOD=1000000007;

int main()
{
    int n;
    cin>>n;
    vector<LL> a(n);
    REP(i,n)
        cin>>a[i];

    sort(ALL(a));

    LL sum =0;
    int ans=0;
    REP(i,n-1)
    {
        sum+=a[i];
        if(a[i+1]<=sum*2)
            ans++;
        else
            ans=0;
    }
    ans++;
    cout<<ans<<endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N;
	string S;
	cin >> N >> S;
	vector<int> R(N, -1);
	vector<int> G(N, -1);
	vector<int> B(N, -1);
	int r = 0, g = 0, b = 0;
	for (int i = 0; S[i]; i++)
	{
		if (S[i] == 'R')
			R[r++] = i;
		else if (S[i] == 'G')
			G[g++] = i;
		else
			B[b++] = i;
	}
	ll all = (ll)r*g*b;
	ll sub = 0;
	for (int i = 0; i < N-1; i++)
	{
		for (int j = i+1; j < N; j++)
		{
			if (S[i] == S[j])
				continue ;
			int k = j+j-i;
			if (k >= N || S[k] == S[i] || S[k] == S[j])
				continue ;
			sub++;
		}
	}
	cout << all - sub << endl;
}



Measured memory_bytes: 3660
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ll n,a,b;
	cin >> n >> a >> b;
	int x[n];
	for (int i=0;i<n;i++) cin >> x[i];
	ll c=0;
	for (int i=0;i<n-1;i++) {
		if ((x[i+1]-x[i])*a>b) c+=b;
		else c+=a*(x[i+1]-x[i]);
	}
	cout << c;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){

  int N,M;
  cin >> N;
  string a[100], b[100];
  int count[100]={-1};
  for(int i=0; i<N; i++) cin >> a[i];
  cin >> M;
  for(int i=0; i<M; i++) cin >> b[i];
  
  
  if(N>=M){
  for(int i=0; i<N; i++){
  	for(int j=0; j<N; j++){
    	if(a[i]==a[j]) count[i]++;
        if(a[i]==b[j]) count[i]--;
    }
  }
  }
  
  else if(N<M){
  for(int i=0; i<M; i++){
  	for(int j=0; j<M; j++){
    	if(a[i]==a[j] && a[i]!=" ") count[i]++;
        if(a[i]==b[j] && a[i]!=" ") count[i]--;
    }
  }
  }
  
  int ans=0;
  for(int i=0; i<N; i++){
  	if(count[i]>ans) ans=count[i];
  }
cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,a,b,c;
    scanf("%d",&n);
    if(n>=100 && n<=999){
    a = n%10;
    n = n/10;
    b = n%10;
    c = n/10;
    if(a==7 || b==7 || c==7 )printf("Yes\n");
    else printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 1660
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		Comp comp = new Comp();
		while(true){
			int n = in.nextInt();
			if(n == 0) break;
			Queue<Integer> moving = new PriorityQueue<Integer>();
			int[][] car = new int[n][2];
			for(int i=0; i<n; i++){
				String[] time1 = in.next().split(":");
				String[] time2 = in.next().split(":");
				int t1 = 0;
				int t2 = 0;
				int base = 3600;
				for(int j=0; j<3; j++){
					t1 += Integer.parseInt(time1[j])*base;
					t2 += Integer.parseInt(time2[j])*base;
					base /= 60;
				}
				car[i][0] = t1;
				car[i][1] = t2;
			}
			Arrays.sort(car, comp);
			int res = 0;
			int stop = 0;
			for(int i=0; i<n; i++){
				while(!moving.isEmpty() && moving.peek()<=car[i][0]){
					moving.poll();
					stop++;
				}
				if(stop>0){
					stop--;
				}else{
					res++;
				}
				moving.add(car[i][1]);
			}
			System.out.println(res);
		}
	}
}

class Comp implements Comparator<int[]>{
	@Override
	public int compare(int[] o1, int[] o2) {
		return o1[0]-o2[0];
	}
}

Measured memory_bytes: 102868
#include<stdio.h>
#include<string.h>

typedef struct{
    int n,r,l,d,p,dep,h,sub,deg;
}Tree;

Tree tree[30];
int i,j,N,r,l,n;

int dfs(int,int);

int main(){
    memset(tree,-1,sizeof(tree));
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d%d%d",&n,&l,&r);
        tree[n].l=l;
        tree[n].r=r;
        tree[n].deg=(r!=-1)+(l!=-1);
        tree[l].sub=r;
        tree[r].sub=l;
        if(l!=-1) tree[l].p=n;
        if(r!=-1) tree[r].p=n;
    }
    for(i=0;i<N;i++) if(tree[i].p==-1) dfs(i,0);

    for(i=0;i<N;i++) printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",i,tree[i].p,tree[i].sub,tree[i].deg,tree[i].dep,tree[i].h,tree[i].p==-1?"root":tree[i].l==-1&&tree[i].r==-1?"leaf":"internal node");
    return 0;
}

int dfs(int p,int d){
    int a,b;
    if(p==-1) return -1;
    tree[p].dep=d;
    a=dfs(tree[p].r,d+1);
    b=dfs(tree[p].l,d+1);
    if(a==-1&&b==-1) tree[p].h=0;
    else tree[p].h=(a>b?a:b)+1;
    return tree[p].h;
}


Measured memory_bytes: 2052
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
//void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }



//---------- 1000000007 ----------
const int MOD = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% MOD + MOD) % MOD) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(MOD - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

mint m_comb(mint n, mint r)
{
	int i;
	mint p = 1;
	for (i = 1; i <= r.x; i++)
	{
		p *= n - i + 1;
		p /= i;
	}
	return p;
}
mint m_comb_with_rep(mint n, mint r)
{
	return m_comb(n + r - 1, r);
}
mint m_perm(mint n, mint r)
{
	mint a = 1;
	for (int i = n.x; i > n.x - r.x; i--)
	{
		a *= i;
	}
	return a;
}



int N, K;
mint calc(int a)
{
	int b = K;
	int r = N - K;

	int bb = b - a;
	int rr = r - (a - 1);

	if (bb < 0 || rr < 0)
	{
		return 0;
	}

	mint ba = a;
	mint ra = a + 1;

	mint bc = m_comb_with_rep(ba, bb);
	mint rc = m_comb_with_rep(ra, rr);

	return bc * rc;
}

signed main()
{
	cin >> N >> K;

	int ans = 0;
	for (int i = 1; i <= K; i++)
	{
		mint c = calc(i);
		cout << c << endl;
	}
}



Measured memory_bytes: 3576
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import Counter
def resolve():
    K = ir()
    def GCD(a, b):
        if b == 0:
            return a
        else:
            return GCD(b, a % b)
    ab = []
    for i in range(1, K+1):
        for j in range(1, K+1):
            ab.append(GCD(i, j))
    A = Counter(ab)
    ans = 0
    for k in A.keys():
        for i in range(1, K+1):
            abc = GCD(k, i)
            ans += abc*A[k]
    print(ans)
resolve()

Measured memory_bytes: 73796
import heapq

K, T = map(int, input().split())
a = [int(i) for i in input().split()]
b = [[0 for j in range(2)] for i in range(T)]
for i in range(T):
	b[i][0] = a[i] * -1
	b[i][1] = i
heapq.heapify(b)
ans, c = 0, -1
while len(b):
	d = heapq.heappop(b)
	if c == d[1]:
		if not len(b):
			ans += 1
			c = d[1]
			d[0] += 1
			if d[0]:
				heapq.heappush(b, d)
		else:
			e = heapq.heappop(b)
			c = e[1]
			e[0] += 1
			heapq.heappush(b, d)
			if e[0]:
				heapq.heappush(b, e)
	else:
		c = d[1]
		d[0] += 1
		if d[0]:
			heapq.heappush(b, d)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int X, A; cin >> X >> A;
    if (X < A) {
    	cout << 0 << endl;
    } else {
    	cout << 10 << endl;
    }
    
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 892
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())-1
b=list(map(int,input().split()))
a=b[0]
for i in range(1,N,1):
    if b[i] >= b[i-1]:
        a+=b[i-1]
    else: a+=b[i]
a+=b[N-1]
print(a)

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> a(n);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	int r = 0;
	int l = 0;
	for (int i = 0; i < m; i++) {
		if (a[i] > x) {
			r++;
		}
		else {
			l++;
		}
	}
	cout << min(r, l);

}

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

template<typename T> struct BIT {
    int max_n;
    vector<T> data;
    const T unit;
    BIT<T>(int n, T u = T(0)) : max_n(n), unit(u) {
        data.assign(max_n + 1, u);
    }
    void add(int i, T x) {
        while ( i <= max_n ) {
            data[i] += x;
            i += i & -i;
        }
    }
    T sum(int i) {
        T s = unit;
        while ( i > 0 ) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }
};

ll solve() {
    ll N, M;
    cin >> N >> M;
    vector<ll> L(N), R(N);
    vector<pair<ll, int>> D;
    for ( int i = 0; i < N; i++ ) {
        cin >> L[i] >> R[i];
        D.emplace_back(R[i]-L[i]+1, i);
    }
    sort(D.begin(), D.end());
    vector<ll> ans(M+1);
    BIT<ll> sl(M+2), sh(M+2);

    int p = N-1;
    for ( int d = M; d >= 1; d-- ) {
        while ( p >= 0 && D[p].first >= d ) {
            sl.add(1, 1);
            sl.add(D[p].first + 1, -1);
            p--;
        }
        ans[d] += sl.sum(d);

        // for ( int m = 0; m <= M; m++ ) {
        //     cout << sl.sum(m) << " ";
        // }
        // cout << "\n";
    }

    p = 0;
    for ( int d = 1; d <= M; d++ ) {
        while ( p < N && D[p].first < d ) {
            int i = D[p].second;
            sh.add(L[i], 1);
            sh.add(R[i]+1, -1);
            p++;
        }
        for ( int j = 0; j <= M; j+=d ) {
            ans[d] += sh.sum(j);
        }

        // for ( int m = 0; m <= M; m++ ) {
        //     cout << sh.sum(m) << " ";
        // }
        // cout << "\n";
    }

    for ( int i = 1; i <= M; i++ ) {
        cout << ans[i] << "\n";
    }
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 15212
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]-=(i+1);
    }
    sort(ALL(a));
    ll k=a[n/2];
    ll ans=0;
    rep(i,n){
        ans+=abs(a[i]-k);
    }
    cout << ans << endl;
}


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

bool coffee(string s)
{
    int n = s.length();
    for (int i = 0; i <= n; i++)
        if (s[2]==s[3] && s[4]==s[5])
            return true;

    return false;
}

int main()
{
    string s;

    cin>>s;

    if (coffee(s))
        cout <<"Yes";
    else
        cout << "No";

    return 0;
}


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

int main() {
    string S, T; cin >> S >> T;
    bool canMatch = false;
    for (int i = 0; i < S.size(); i++) {
        if (S == T) {
            canMatch = true;
        }
        S = S[S.size() - 1] + S.substr(0, S.size() - 1);
    }
    if (canMatch) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int n;
    cin>>n;
    int res = 0;
    for (int i=1; i<=n; i++) {
	int x = n-i;
	if (i<x) {
	    res++;
	}
    }
    cout<<res<<endl;    
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, pii> plp;
typedef complex<double> xy_t;
typedef vector<lint> poly;

const lint mod = 1e9 + 7;
const lint INF = mod * mod;

int main(){
    lint n;
    scanf("%lld", &n);
    lint ans = INF;
    for(lint i=1; i*i<=n; ++i){
        if(n % i == 0){
            ans = min(ans, i+n/i-2);
        }
    }
    printf("%lld\n", ans);
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int count = 0;
  while(a * count - (count - 1) < b) count++;
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int H,N;
  cin>>H>>N;
  vector<int>attack(N);
  for(int i=0;i<N;i++){
  cin>>attack.at(i);
  }
  int hp;
    for(int i=0;i<N;i++){
  H-=attack.at(i);
  }
  if(H<=0){
  cout<<"Yes";
  }
  else{
  cout<<"No";
  }
}


Measured memory_bytes: 3760
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long li;

const int maxn = 1e5;
int n, a[maxn], b[maxn];

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", a + i, b + i);
  }
  li ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    li cur = a[i] + ans;
    li tar = (cur + b[i] - 1) / b[i] * b[i];
    ans += tar - cur;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 896
#include<stdio.h>
int main(void)
{
	int a,b,c,d,s,z,zz;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	s=a+b+c+d;
	z=s/60;
	zz=s%60;
	printf("%d\n",z);
	printf("%d\n",zz);
	return 0;
}

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

using namespace std;

long long inf=1000000007;

long long modpow(long long n,long long p,long long mod);

int main(){
	long long n,w;
	cin>>n>>w;
	vector<long long> val(n),wei(n);
	for(long long i=0;i<n;i++) cin>>val.at(i)>>wei.at(i);

	vector<long long> dp(w+1,-1);
	dp.at(0)=0;

	for(long long i=1;i<=w;i++){
		dp.at(i)=dp.at(i-1);
		for(long long j=0;j<n;j++){
			if(i-wei.at(j)>=0){
				dp.at(i)=max(dp.at(i),dp.at(i-wei.at(j))+val.at(j));
			}
		}
	}

	cout<<dp.at(w)<<endl;

	return 0;
}

long long modpow(long long n,long long p,long long mod){
	if(p==0) return 1;
	if(p%2==0) return (modpow(n,p/2,mod)*modpow(n,p/2,mod))%mod;
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int X, N;
    cin >> X >> N;
    int mn = 1<<30;
    int ans = 0;

    set<int> st;
    REP(i, N){
        int p;
        cin >> p;
        st.insert(p);
    }
    for(int i=0; i<=101; i++){
        if(st.find(i)!=st.end()) continue;
        int diff = abs(X-i);
        if(diff < mn){
            mn = diff;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

#define NIL -1
#define MAX 25

typedef struct {
  int parent;
  int le;
  int ri;
}Node;


Node t[MAX];
int h,max;
void calc(int);
 
int main() {

  int i,j,n,id,left,right;
  int depth[MAX],height[MAX],sibling[MAX],degree[MAX];
 
  scanf("%d",&n);

  for(i=0; i<n; i++) {
    t[i].parent=t[i].le=t[i].ri=sibling[i]=NIL;
    degree[i]=0;
  }    

  for(i=0; i<n; i++) {
    scanf("%d%d%d",&id,&left,&right);
    if(left!=NIL) {
      t[left].parent=id;
      degree[id]++;
    }
    if(right!=NIL){
      t[right].parent=id;
      degree[id]++;
    }
    t[id].le = left;
    t[id].ri = right;
    sibling[left]=right;
    sibling[right]=left;
  }
 
  for(i=0; i<n; i++) {
    depth[i]=height[i]=0;
    j=i;
    while(t[j].parent!=NIL) {
      j=t[j].parent;
      depth[i]++;
    }
    max=h=0;
    calc(i);
    height[i] = max;
  }
  for(i=0; i<n; i++) {
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,t[i].parent,sibling[i],degree[i],depth[i],height[i]);
    if(t[i].parent==-1) printf("root");
    else if(t[i].le!=-1 || t[i].ri!=-1) printf("internal node");
    else printf("leaf");
    printf("\n");
  }
  return 0;
}
 
 
void calc(int n)
{
  if(t[n].le==NIL || t[n].ri==NIL)  max = h>max ? h:max;
  if(t[n].le!=NIL) {
    h++;
    calc(t[n].le);
  }
  if(t[n].ri!=NIL) {
    h++;
    calc(t[n].ri);
  }
  h-=1;
}



Measured memory_bytes: 2088
R, G, B, N = map(int, input().split())

ans = 0
for r in range(0, N+1, 1):
    for g in range(0, N+1 - R*r, 1):
        if N - R*r - G*g < 0:
            continue
        elif (N - R*r - G*g) % B == 0:
            ans += 1
print(ans)

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

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

	int n;
	cin >> n;
	vector<ll> a(n);
	for (auto &i : a) cin >> i;

	const ll mod = 1e9+7;
	ll ans = 0;
	for (int j = 0; j < 60; ++j)
	{
		vector<ll> z(2);
		for (auto i : a)
		{
			ans += (1LL<<j) % mod * z[~i>>j&1];
			ans %= mod;
			++z[i>>j&1];
		}
	}
	cout << ans << "\n";

	return 0;
}


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

int main(){
    int W,N;
    int C = 0;
    while(cin >> W >> N && W){
        int dp[1010] = {};
        for(int i=0;i<N;i++){
            int a,b;
            char c;
            cin >> a >> c >> b;
            for(int j=W;j>=b;j--) dp[j] = max(dp[j], dp[j-b]+a);
        }
        int x = 0, y = 0;
        for(int i=0;i<=W;i++) if(x < dp[i]) x = dp[i], y = i;
        cout << "Case " << ++C << ":\n" << x << "\n" << y << "\n";
    }
}

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

#define ll long long
#define endl "\n";
#define mod 1000000007
#define pii pair<int,int>
#define vii vector<pii>
#define mp make_pair
#define all(a) a.begin(), a.end()
#define mk(arr,n,type) type *arr=new type[n];

void fastio() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main() {
    fastio();
    int n, k, p;
    cin >> n >> k;
    priority_queue<int, vector<int>, greater<int>> pq;
    for (int i = 0; i < n; i++) {
        cin >> p;
        pq.push(p);
    }

    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3660
#include<stdio.h>
int main(void){
    int a,b,i,c;
    while(1){
        if(scanf("%d %d",&a,&b)==EOF)
        break;
    c=a+b;
    i=1;
    while(1){
        if((c/10)<1)
        break;
        else{
          i++;
          c/=10;
        }
    }
    printf("%d\n",i);
    }

        return 0;
}



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

int main()
{
	long long int X, ans = 0;

	cin >> X;

	ans = X / 11 * 2;

	if (X % 11) {
		ans++;
		if (X % 11 > 6)ans++;
	}

	cout << ans;

	return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll H, W;
    cin >> H >> W;
    ll ans;
    if (H == 1 || W == 1) 
    {
        ans = 1;
    }
    else
    {
        if (H % 2 == 0)
        {
            ans = W * (H / 2);
        }
        else
        {
            ans = W * (H / 2) + (W + 1) / 2;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256