akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  ll k;
  cin >> k;
  vector<int> A(n+1);
  for (int i = 1; i <= n; ++i) {
    int a;
    cin >> a;
    A[i] = a;
  }
  if (k > n) {
    int tort = A[1], hare = A[A[1]];
    while (tort != hare) {
      tort = A[tort];
      hare = A[A[hare]];
    }
    tort = 1;
    int start = 1;
    while (tort != hare) {
      tort = A[tort];
      hare = A[hare];
      start++;
    }
    int next = A[tort];
    int len = 1;
    while (tort != next) {
      len++;
      next = A[next];
    }

    int ret = 1;
    for(int i = 1; i < start; i++) {
      ret = A[ret];
    }
    for(int i = 1; i <= ((k-start+1) % len); i++) {
      ret = A[ret];
    }
    cout << ret << endl;

  } else {
    int ret = 1;
    for(int i = 1; i <= k; i++) {
      ret = A[ret];
    }
    cout << ret << endl;
  }
  return 0;
}


Measured memory_bytes: 4068
N, K = map(int, input().split())
R, S, P = map(int, input().split())
d = [[] for _ in range(K)]

for i, s in enumerate(input()):
    d[i%K].append(s)

ans = 0
score = {}
score["s"] = R
score["p"] = S
score["r"] = P

for l in d:
    prev_hand = "a"
    for s in l:
        if s!=prev_hand:
            ans += score[s]
            prev_hand = s
        else:
            prev_hand = "a"
print(ans)

Measured memory_bytes: 13488
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
struct Matrix{ 
	int a[2][2] = {{0,0},{0,0}};
	Matrix operator *(const Matrix& other){
		Matrix product;
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
						product.a[i][k] =product.a[i][k] + (ll)a[i][j]*other.a[j][k];
				}
			}
		}
		return product;
	}
};
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
vector<int> parent;
vector<int> s;
void make_set(int v)
{
	parent[v] = v;
	s[v] = 1;
}
int find_set(int v)
{
	if(v==parent[v])
	{
		return v;
	}
	return find_set(parent[v]);
}
void union_set(int a,int b)
{
	a = find_set(a);
	b = find_set(b);
	//cout<<a<<" "<<b<<'\n';
	if(a!=b)
	{
		if(s[a]<s[b])
		swap(a,b);
		
		parent[b] = a;
		s[a] +=s[b];
	}
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 int n;
	 cin>>n;
	 parent.resize(n+1);
	 s.resize(n+1);
	 for(int i=1;i<=n;i++)
	 {
		 make_set(i);
	 }
	 //for(int x:parent)
	 //cout<<x<<" ";
	 //cout<<'\n';
	 int m;
	 cin>>m;
	 for(int i=0;i<m;i++)
	 {
		 int a,b;
		 cin>>a>>b;
		 union_set(a,b);
	 }
	 int ans = -1;
	 for(int i=1;i<=n;i++)
	 {
		 ans = max(ans,s[i]);
	 }
	 cout<<ans<<'\n';
	 return 0;
}


Measured memory_bytes: 4692
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto x = readln.chomp.split.to!(int[]);
  auto a = max(x[0], x[2]);
  auto b = min(x[1], x[3]);
  writeln(max(b-a, 0));
}


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

int w,h;
int field[51][51];

// »Ýn(x,y)
void dfs(int x, int y){
	// ¡¢éÆ±ëð-1Éu«·¦é
	field[y][x] = -1;

	// Ú®·é8ûüð[v
	for(int dx = -1 ; dx <= 1 ; dx++ ){
		for(int dy = -1 ; dy <= 1 ; dy++ ){
			// xûüÉdx, yûüÉdy, Ú®µ½êð(mx,my)Æ·é
			int mx = x + dx;
			int my = y + dy;
			// ÍÍOÉo½Æ«ÍÌÖ
			if( mx < 0 || my < 0 || mx >= w || my >= h ) continue;
			// ¤n¾Á½çÄAÄÑoµ
			if( field[my][mx] == 1 ){
				dfs( mx , my );
			}
		}
	}
}

int main(){
	while( cin >> w >> h , w||h ){
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				cin >> field[y][x];
			}
		}

		int ans = 0;
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				if( field[y][x] == 1 ){
					dfs( x , y );
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;

int main(void){
	int N,K;cin>>N>>K;
	int num = 1;
	for(int i = 0;i < N;i++){
		if(num + K >= num * 2)num *= 2;
		else num += K;
	}
	cout<<num;
}


Measured memory_bytes: 256
D = int(input())
c = list(input().split())
Contestday = []

#
# def CalcDownSatisfied(num, day):
#
#
#
#
# def Last(day, i):
#     count = 1
#     last = 0
#     for k in Contestday:
#         if k == i:
#             last = day - count
#         count += 1
#     return last


for i in range(D):
    Satisfied = list(map(int, input().split()))
    print(Satisfied.index(max(Satisfied)) + 1)

Measured memory_bytes: 9192
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
using namespace std;


int main(){
  int a, b, t;
  int ans;
  cin >> a >> b >> t;

  ans = t / a * b;

  cout << ans << endl;

}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair

#define NEWLINE         cerr << "\n";
#define HOISE           cerr << "hoise " << __LINE__ << "\n"
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << "\n"
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)

typedef long long ll;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 23;
const ll INFL = 2e18 + 23;

int32_t main()
{
    FASTIO;

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int sum = 0;
    for(int i= 0; i < k; i++)
        sum += a[i];

    cout << sum;

    return 0;
}

Measured memory_bytes: 3660
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    # 1/c=(4ab-na-nb)/nab
    from itertools import product
    for a,b in product(range(1,3501),repeat=2):
        if(4*a*b-n*a-n*b<=0): continue
        if(n*a*b%(4*a*b-n*a-n*b)==0):
            c=n*a*b//(4*a*b-n*a-n*b)
            print(a,b,c)
            return
resolve()

Measured memory_bytes: 39152
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <complex>

using namespace std;

#define mod 1000000007

int v;
int graph[101][101] = {};
int residual[101][101] = {};

pair<vector<int>, int> bfs()
{
	vector<int> next(101, -1);
	queue<int> qu;
	qu.push(v - 1);
	while(!qu.empty()){
		int now = qu.front();
		qu.pop();
		for(int i = 0; i < v - 1; i++){
			if(residual[i][now] > 0 && next[i] == -1){
				next[i] = now;
				qu.push(i);
			}
		}
	}
	int minc = mod;
	vector<int> ans;
	int now = 0;
	if(next[now] == -1) return make_pair(ans, minc);
	while(now != v - 1){
		minc = min(minc, residual[now][next[now]]);
		ans.push_back(now);
		now = next[now];
	}
	ans.push_back(v - 1);
	return make_pair(ans, minc);
}

int main()
{
	int e;
	cin >> v >> e;
	for(int i = 0; i < e; i++){
		int u, v, c;
		cin >> u >> v >> c;
		// graph[u][v] = c;
		residual[u][v] = c;
	}
	auto tmp = bfs();
	vector<int> tmpv = tmp.first;
	int c = tmp.second;
	while(!tmpv.empty()){
		for(int i = 0; i < tmpv.size() - 1; i++){
			int f = tmpv[i];
			int t = tmpv[i + 1];
			// cout << f << " ";
			graph[f][t] += c;
			residual[f][t] -= c;
			residual[t][f] += c;
		}
		// cout << tmpv[tmpv.size() - 1] << " " << c << endl;
		// for(int i = 0; i < v; i++){
		// 	for(int j = 0; j < v; j++){
		// 		cout << graph[i][j] << " ";
		// 	}
		// 	cout << endl;
		// }
		// cout << endl;
		tmp = bfs();
		tmpv = tmp.first;
		c = tmp.second;
	}
	int ans = 0;
	for(int i = 0; i < v - 1; i++){
		ans += graph[i][v - 1];
	}
	cout << ans << endl;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#include <math.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9

using namespace std;
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
const db pi = acos(-1);
const int N = 1e5 + 10;
int n, nxt, x;
ll ans;

int main()
{
	nxt = 0;
	n = read();
	x = read();
	rep(i, 1, n)
	{
		int now = read();
		nxt += now;
		if(nxt > x) now -= (nxt - x), ans += (ll)(nxt - x);
		nxt = now;
	}
	cout << ans;
    return 0;
}


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

int main(void){
	int N, K;
	cin >> N >> K;
	vector<long long>h(N, 0);
	for(int cnt = 0; cnt < N; cnt++){
		cin >> h[cnt];
	}
	sort(h.begin(), h.end());
	long long max = 1000000000;
	K--;
	for(int cnt = 0; cnt < N - K; cnt++){
		if(max > h[cnt + K] - h[cnt]){
			max = h[cnt + K] - h[cnt];
		}
	}
	cout << max << endl;
	return 0;
}



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

using namespace std;



int main(){
	
	int n;
	
	string s;
	bool flag = true;
	cin>>n>>s;
	
	if(n%2){
		cout<<"No\n";
		return 0;
	}
	for(int i = 0; i < n/2; i++){
		if(s[i] != s[n/2 + i]) flag = false;
	}
	
	if(flag) cout<<"Yes\n";
	else cout<<"No\n";
	
}


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

using namespace std;

//  # of a+b less than t
long long count(vector<int> &a, vector<int> &b, int t)
{
    int N = (int)a.size();
    int bi = N-1;
    long long ans = 0;
    for (int ai=0; ai<N; ai++)
    {
        while (bi>=0 && a[ai]+b[bi]>=t)
            bi--;
        ans += bi+1;
    }
    return ans;
}

//long long count(vector<int> &a, vector<int> &b, int t)
//{
//    int ans = 0;
//    for (int at: a)
//        for (int bt: b)
//            if (at+bt<t)
//                ans++;
//    return ans;
//}

int main()
{
    int N;
    cin>>N;
    vector<int> a(N), b(N), at(N), bt(N);
    for (int &t: a)
        cin>>t;
    for (int &t: b)
        cin>>t;

    int ans = 0;
    for (int d=0; d<=28; d++)
    {
        for (int i=0; i<N; i++)
            at[i] = a[i] & ((1<<(d+1))-1),
            bt[i] = b[i] & ((1<<(d+1))-1);
        sort(at.begin(), at.end());
        sort(bt.begin(), bt.end());

        //cout<<d<<endl;
        //for (int x: at)
        //    cout<<" "<<x;
        //cout<<endl;
        //for (int x: bt)
        //    cout<<" "<<x;
        //cout<<endl;
        //cout<<d<<" "<<count(at, bt, 1<<(d+1))<<" "<<count(at, bt, 1<<d)<<endl;
        //int cc = 0;
        //for (int aa: at)
        //    for (int bb: bt)
        //        if ((aa+bb) & 1<<d)
        //            cc++;
        //cout<<cc<<endl;
        long long c = N*N - count(at, bt, 3<<d)
                    + count(at, bt, 2<<d) - count(at, bt, 1<<d);            
        //cout<<c<<endl;
        ans |= (c&1)<<d;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
#include <iostream>
using namespace std;
 
int main()
{
      int n,flag=0;
      cin>>n;
      int a,b,c;
      if(n%10==7){
      cout<<"Yes"<<endl;
      flag=1;}
      n=n/10;
      if(n%10==7&&flag!=1){
      cout<<"Yes"<<endl;
      flag=1;}
      n=n/10;
      if(n%10==7&&flag!=1){
      cout<<"Yes"<<endl;
      flag=1;}
      if(flag==0)
      cout<<"No"<<endl;
 
      
 
 
    return 0;
}

Measured memory_bytes: 3624
N = int(input())
P = list(map(int, input().split()))

minP = 0
ans = 0
for i in range(N):
    if i == 0:
        ans += 1
        minP = P[0]
        continue
    if minP >= P[i]:
        ans += 1
        minP = P[i]
print(ans)


Measured memory_bytes: 32240
(function() {
  'use strict';
  var lines = [];
  require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
  }).on('line', function(line) {
    lines.push(line);
  });
  process.stdin.on('end', function() {
      console.log(lines[0].substring(0, 4) + ' ' + lines[0].substring(4));
  });
})();


Measured memory_bytes: 6904
def segfunc(x,y):return max(x,y)
ide_ele=0
class segtree():
  def __init__(self,init_val,segfunc=segfunc,ide_ele=ide_ele):
    n=len(init_val)
    self.segfunc=segfunc
    self.ide_ele=ide_ele
    self.num=1<<(n-1).bit_length()
    self.tree=[ide_ele]*2*self.num
    for i in range(n):
      self.tree[self.num+i]=init_val[i]
    for i in range(self.num-1,0,-1):
      self.tree[i]=self.segfunc(self.tree[2*i], self.tree[2*i+1])
  def update(self,k,x):
    k+=self.num
    self.tree[k]=x
    while k>1:
      self.tree[k>>1]=self.segfunc(self.tree[k],self.tree[k^1])
      k>>=1
  def query(self,l,r):
    res=self.ide_ele
    l+=self.num
    r+=self.num+1
    while l<r:
      if l&1:
        res=self.segfunc(res,self.tree[l])
        l+=1
      if r&1:
        res=self.segfunc(res,self.tree[r-1])
      l>>=1
      r>>=1
    return res
def isok(mid,key):
  return st.query(x-1,mid-1)>=key
def b_search(x,key):
  ng=x-1
  ok=n+1
  while abs(ng-ok)>1:
    mid=(ng+ok)//2
    if isok(mid,key):ok=mid
    else:ng=mid
  return ok
n,q=map(int,input().split())
a=list(map(int,input().split()))
st=segtree(a)
ans=[]
for _ in range(q):
  c,x,y=map(int,input().split())
  if c==1:st.update(x-1,y)
  elif c==2:ans+=[st.query(x-1,y-1)]
  else:ans+=[b_search(x,y)]
print(*ans,sep='\n')

Measured memory_bytes: 110268
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const ll LINF = (int)1e18;
const double EPS = 1e-9;

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

  int a,b;
  cin>>a>>b;
  cout << a*b-(a+b-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N, i;
	long long locus[87];
	scanf("%d", &N);
	locus[0] = 2; locus[1] = 1;
	for (i = 2; i <= N; i++){
		locus[i] = locus[i - 1] + locus[i - 2];
	}
	printf("%lld\n", locus[N]);
	return 0;
}

Measured memory_bytes: 128
N, M = list(map(int, input().split()))
KS = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))

answer = 0
from itertools import product

for sw in product([0, 1], repeat=N):
    for p, ks in zip(P, KS):
        K = ks[0]
        S = ks[1:]
        if sum([sw[s - 1] for s in S]) % 2 != p % 2:
            break
    else:
        answer += 1

print(answer)


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

int n,dp[lim];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    fill(dp,dp+lim,1e9);
    int m;
    cin>>n>>m;
    for(int i=0;i<m;i++) {
    	int cost,ones,mask=0;
    	cin>>cost>>ones;
    	for(int j=0;j<ones;j++) {
    		int x;
    		cin>>x;
    		mask |= (1<<(x-1));
    	}

    	for(int j=0;j<lim;j++)
    		if((mask|j)==mask)
    			dp[j] = min(dp[j],cost);
    }

    for(int i=1;i<lim;i++)
    	for(int j=i-1;j>=0;j--)
    		if(dp[i]!=1e9 && dp[j]!=1e9)
    			dp[i|j] = min(dp[i|j],dp[i]+dp[j]);
    
    if(dp[(1<<n)-1]==1e9)
    	cout<<-1;
    else
    	cout<<dp[(1<<n)-1];
    
    return 0;
}

Measured memory_bytes: 256
a = []
for i in range(3):
  a.append(list(map(int,input().split())))
for i in range(int(input())):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k] == b:
        a[j][k] = 0
def bingo():
  for i in range(3):
    if sum(a[i]) == 0 or a[0][i] + a[1][i] + a[2][i] == 0:
      return 'Yes'
  if a[0][0] + a[1][1] + a[2][2] == 0 or a[0][2] + a[1][1] + a[2][0] == 0:
    return 'Yes'
  return 'No'
print(bingo())

Measured memory_bytes: 38256
from collections import deque, defaultdict
import copy
import bisect
#sys.setrecursionlimit(10 ** 9)
import math
import heapq


import sys
def input():
	return sys.stdin.readline().strip()


X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

kouho = []
all_set = set()
heapq.heappush(kouho, [-(A[0] + B[0] + C[0]), 0, 0, 0])
all_set.add(0)
for i in range(K):
	comb = heapq.heappop(kouho)
	print(-comb[0])
	if comb[1] < X - 1 and not (comb[1] + 1)*Y*Z + comb[2]*Z + comb[3] in all_set:
		heapq.heappush(kouho,  [-(A[comb[1] + 1] + B[comb[2]] + C[comb[3]]), comb[1] + 1, comb[2], comb[3]])
		all_set.add((comb[1] + 1)*Y*Z + comb[2]*Z + comb[3])
	if comb[2] < Y - 1 and not comb[1]*Y*Z + (comb[2] + 1)*Z + comb[3] in all_set:
		heapq.heappush(kouho,  [-(A[comb[1]] + B[comb[2] + 1] + C[comb[3]]), comb[1], comb[2] + 1, comb[3]])
		all_set.add(comb[1]*Y*Z + (comb[2] + 1)*Z + comb[3])
	if comb[3] < Z - 1 and not comb[1]*Y*Z + comb[2]*Z + comb[3] + 1 in all_set:
		heapq.heappush(kouho,  [-(A[comb[1]] + B[comb[2]] + C[comb[3] + 1]), comb[1], comb[2], comb[3] + 1])
		all_set.add(comb[1]*Y*Z + comb[2]*Z + comb[3] + 1)


Measured memory_bytes: 56280
fun main(args: Array<String>){

    val n = readLine()!!.toInt()
    val heights = readLine()!!.split(" ").map { it.toInt() }
    var count = 0L


    val minus = IntArray(n)
    val dict = HashMap<Long, Long>()


    for(i in 0 until n){
        minus[i] = i - heights[i]
        val t = (i + heights[i]).toLong()
        if(dict.containsKey(t)){
            dict[t] = dict[t]!! + 1L
        } else {
            dict[t] = 1
        }
    }


    for(i in 0 until n){
        if(dict.containsKey(minus[i].toLong())){
            count += dict[minus[i].toLong()]!!
        }
    }
    println(count)

}



Measured memory_bytes: 81692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1e9+7
//xをn乗してmodで割ったあまりを返す
ll mod_pow(ll x, ll n, ll mod){
    if(n == 0)return 1;
    ll res = mod_pow(x*x%mod,n/2,mod);
    if(n&1) res = res * x % mod;
    return res;
}

int main(){
    ll m, n; cin >> m >> n;
    ll ans = mod_pow(m,n,MOD);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>

int main(int argc, const char * argv[]) {
    int a,b;
    std::cin>>a>>b;
    if(b<=1)std::cout<<0<<std::endl;
    else if((b-1)%(a-1)==0){
      std::cout<<(b-1)/(a-1)<<std::endl;
    }else{
        std::cout<<(b-1)/(a-1)+1<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[20][60];
int ans[20];
int t[20];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	int last=0;
	int ret=0;
	for(int i=0;i<a;i++){
		int p,q,r,s;
		scanf("%d:%d%s%d:%d%s",&p,&q,str[i],&r,&s,str[i+1]);
		p=p*60+q;
		r=r*60+s;
		if(i){
			if(p-last>=b){
				t[ret]=p-last;
				ans[ret++]=i;
			}
		}
		last=r;
	}
	printf("%d\n",ret);
	for(int i=0;i<ret;i++)printf("%s %d\n",str[ans[i]],t[i]);
}

Measured memory_bytes: 1036
import java.util.*;
public class Main {

	public static void main(String[] args) {
		//儅奇偶項需要換的數相同時，比較那個用的步驟比較少	

		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int n=N/2;
		
		//兩個放取得的奇偶
		int	SetO[]=new int [n];
		int SetE[]=new int [n];
		//將數列分開奇偶項
		for(int i=0;i<n;i++) {
			SetO[i]=sc.nextInt();
			SetE[i]=sc.nextInt();
			//System.out.print("奇數："+SetO[i]);//檢查是否抓到奇數
			//System.out.print("偶數："+SetE[i]);
		}
		
		
		//將矩陣丟入判斷出現最多次數和出現最多的是什麽數的方法
		//max中第一位是出現最多的數，第二位是最多的出現次數,第三位是出現第二多的數，第四位是第二多的出現次數
		int [] maxO=new int[4];
		maxO=max(SetO,n);
		int [] maxE=new int[4];
		maxE=max(SetE,n);
		for(int i=0;i<4;i++){
		//System.out.println("maxO"+(i+1)+":"+maxO[i]);//檢查maxO是否取得set這種出現最多次數的數
		//System.out.println("maxE"+(i+1)+":"+maxE[i]);
	}
		
		//判斷奇數偶數出現最多的數是否相同
		if(maxO[0]==maxE[0]) {
			if((n-maxO[1] + n - maxE[3])<(n-maxE[1] + n - maxO[3])) // 條件是這樣
				System.out.println(n-maxO[1]+n-maxE[3]);
			else
				System.out.println(n-maxO[3]+n-maxE[1]);
		}
		//不同的話直接輸出需要變化數的和
		else
			System.out.println(n-maxO[1]+n-maxE[1]);
			
	}
	
	
	public static int[] max (int [] set,int n) {
		int max=0;
		int maxv=0;
		int maxS=0;
		int maxSv=0;		
		int [] re=new int[4];
		//計數矩陣
		
		int count[]=new int [100001];
		/* JAVA 裡陣列初始值已經是 0
		for(int i=0;i<100001;i++) {
			count[i]=0;
		}
		*/
		//比較后纍加
		for(int j=0;j<n;j++) {
			/*
			for(int f=1;f<10001;f++) {
				if(set[j]==f)
					count[f]++;
			}
			*/
			//等同於直接這樣寫
			count[set[j]]++;
		}
		//選出出現最多次
		//直接找最多次的值
		for(int i=0;i<=100000;i++) {
			if(count[i]>count[maxv])
				maxv=i;
		}
		//選出出現最多次的值
		/*
				for(int f=0;f<100000;f++) {
					if(count[f]==max)
						maxv=f;
				}
		*/
		//選出次數第二多
		//直接找次多的值
		for(int i=0;i<=100000;i++) {
			if(count[i]>count[maxSv] && i != maxv)
				maxSv=i;
		}
		
		//選出次數第二多的值
		/*
		for(int i=0;i<100000;i++) {
			if(count[i]==maxS)
				maxSv=i;
		}
		*/
		re[0]=maxv;
		re[1]=count[maxv];
		re[2]=maxSv;
		re[3]=count[maxSv];
		return re;
	}	
		
		
		
		
		
		

}


Measured memory_bytes: 51740
#!/usr/bin/env python3
import sys
from collections import deque

def solve():
    S = input()
    ans = deque()
    ans.append(S)
    Q = input()
    reverseFlg = False
    for i in range(int(Q)):
        TFC = input()
        l = TFC.split()
        if l[0] == "1":
            reverseFlg = not reverseFlg
        else:
            if reverseFlg:
                if l[1] == "1":
                    ans.append(l[2])
                else:
                    ans.appendleft(l[2])
            else:
                if l[1] == "1":
                    ans.appendleft(l[2])
                else:
                    ans.append(l[2])
    
    res = ''.join(ans)
    if(reverseFlg):
        print(res[::-1])
    else:
        print(res)


            

    return 

def main():
    solve()

if __name__ == '__main__':
    main()


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


int main (){
  ll x, k, d;
  cin >> x >> k >> d;
  
  ll dist = abs(x);
  ll ans = 0;
  ll step = dist/d;
  if(k <= step) ans = dist - d*k;
  else{
    ll num = k - dist/d;
    if(num % 2 == 0) ans = dist - d*(dist/d);
    else ans = d*(dist/d + 1) - dist;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ABC052A
{
    class Program
    {
        static void Main(string[] args)
        {
            int s,S,A, B, C, D;
 
			var word = Console.ReadLine().Split(' ');
			A = int.Parse(word[0]);
			B = int.Parse(word[1]);
			C = int.Parse(word[2]);
			D = int.Parse(word[3]);
 
			s = A * B; S = C * D;
 
            if (s < S)
            {
                Console.WriteLine(S);
            }
 
            else if (A * B > C * D)
            {
                Console.WriteLine(s);
            }
 
            else if (A * B == C * D)
            {
                Console.WriteLine(s);
            }
               
			Console.ReadKey();
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#if LOCAL
#include "../cout.hpp"
#endif
using namespace std;

#define forn(i,n) for (unsigned i = 0; i < n; ++i)
#define pb push_back

typedef unsigned long long ull;

struct Edge {
    unsigned to;
    ull cost;

    Edge(unsigned t, unsigned c) : to(t), cost(c) {}
};

struct Vertex {
    unsigned id;
    vector<Edge> edges;
    ull cost;
    int parent;

    Vertex(unsigned i) : id(i), cost(0), parent(-1) {}
};

vector<Vertex> graph;

ull sp[100005];

void shortest_paths(int k)
{
    queue<unsigned> q;
    q.push(k);
    graph[k].cost = 0;
    while(!q.empty()) {
	unsigned n = q.front();
	q.pop();	    
	for(const auto &e : graph[n].edges) {
	    if(e.to != graph[n].parent) {
		graph[e.to].parent = n;
		graph[e.to].cost = graph[n].cost + e.cost;
		q.push(e.to);
	    }
	}
    }
}

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

    int n;
    cin >> n;

    forn(i, n) {
	graph.pb(Vertex(i));
    }

    forn(i, n - 1) {
	int a, b, c;
	cin >> a >> b >> c;
	a--; b--;
	graph[a].edges.pb(Edge(b, c));
	graph[b].edges.pb(Edge(a, c));
    }

    int q, k;
    cin >> q >> k;

    k--;
    shortest_paths(k);

    forn(i, q) {
	int x, y;
	cin >> x >> y;
	x--; y--;
	cout << (graph[x].cost + graph[y].cost) << "\n";
    }
}


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

using namespace std;
typedef long long ll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
// https://task4233.hatenablog.com/entry/2018/08/16/222107

#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)

int main() {
  int N;
  cin >> N;
  vector<double> t(N), v(N);
  for (int i = 0; i < N; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }

  int T = 0;
  for (int i = 0; i < N; i++) {
    T += t[i];
  }

  vector<double> maxV(2 * T + 1, (double) INF);
  int nowT = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < t[i]; j++) {
      int t1 = nowT + j * 2;
      int t2 = nowT + j * 2 + 1;
      maxV[t1] = min(maxV[t1], v[i]);
      maxV[t2] = min(maxV[t2], v[i]);
    }
    nowT += t[i] * 2;
    maxV[nowT] = min(maxV[nowT], v[i]);
  }

  maxV[0] = maxV[2 * T] = 0.0;

  for(int i = 0; i < 2 * T + 1; i++) {
    maxV[i + 1] = min(maxV[i + 1], maxV[i] + 0.5);
  } 

  for (int i = 2 * T; i >= 0; i--) {
    maxV[i] = min(maxV[i], maxV[i + 1] + 0.5);
  }

  double ans = 0.0;
  for (int i = 0; i <  2 * T + 1; i++) {
    ans += (maxV[i] + maxV[i + 1]) * 0.5 / 2.0;
  }
  cout << fixed << ans << endl;

  return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    if(((s.equals("hi"))||(s.equals("hihi"))||(s.equals("hihihi"))||(s.equals("hihihihi"))||(s.equals("hihihihihi"))))
       {System.out.println("Yes");}
       else{System.out.println("No");}
  }
}

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

int main() {
  int k, s;
  cin >> k >> s;
  
  int count = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      int z = s - x - y;
      if (0 <= z && z <= k) count++;
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int	main(void)
{
  	int	a;
  	int	b;
  	int	c;
  	int	num;
  
  	num = scanf("%d %d %d", &a, &b, &c);
  
  	if (a == b && a != c)
      	printf("Yes");
  	else if (a == c && a != b)
      	printf("Yes");
  	else if (b == c && a != b)
      	printf("Yes");
  	else
      	printf("No");
  	return (0);
}


      

Measured memory_bytes: 128
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
	t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])

Measured memory_bytes: 9668
ab = [0 for _ in range(2001)]
for a in range(1001):
    for b in range(1001):
        ab[a+b] += 1

while True:
    try:
        n = int(input())
    except:
        break
    ans = sum(ab[i]*ab[n-i] for i in range(2001) if n-i >= 0 and  n-i <= 2000)
    print(ans)

Measured memory_bytes: 7716
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)

bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt
strToInt s = (read :: String -> Int) s

main = do
    n <- readLn :: IO Int
    a <- listArray (1,n) <$> replicateM n (bsreadInt <$> BC.getLine)
    print $ solve 1 0 n a
 
solve :: Int -> Int -> Int -> (Array Int Int) -> Int
solve 2 x n a = x
solve i x n a = if x > n + 1
                         then -1
                         else solve (a ! i) (x+1) n a

Measured memory_bytes: 21628
#include <bits/stdc++.h>
using namespace std;
int main(void){
    vector<string> YN={"NO","YES"};
    vector<string> yn={"No","Yes"};
    int a;
    cin>>a;
    cout<<yn[!((a%1000)%111)||!((a/10)%111)]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string al = "abcdefghijklmnopqrstuvwxyz";
  char c;
  cin>>c;
  for(int i=0;i<25;i++){
    if (al.at(i)==c){
      cout<<al.at(i+1)<<endl;
      break;
    }
  }
}

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = 0; i <= b; i++) {
    if (i * a % b == c) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from fractions import gcd
from functools import lru_cache

Q = int(input())
AM = (tuple(int(x) for x in row.split()) for row in sys.stdin.readlines())

U = int(10**4.5 + 100)
euler_phi = np.arange(U,dtype=np.int64)
euler_phi[::2] //= 2
for p in range(3,U,2):
    if euler_phi[p] == p:
        euler_phi[p::p] -= euler_phi[p::p]//p
primes = np.where(euler_phi == np.arange(U)-1)[0]

@lru_cache(None)
def phi(n):
    if n < U:
        return int(euler_phi[n])
    factor = primes[n%primes==0]
    x = n
    for p in factor:
        x -= x//p
        while n%p == 0:
            n //= p
    if n > 1:
        # 大きい素数が残っていた場合
        x -= x//n
    return int(x)

def F(A,M):
    if M == 1:
        return 1
    # find x s.t. A^x = x mod M
    P = phi(M)
    D = gcd(M,P)
    y = F(A,D)
    """
    A^y = y mod Dを満たしている。x = y + Pt として、A^x = x mod Mを作りたい。
    A^{y+Pt} = A^y mod M となるので、y+Pt = A^y mod M となるようにしたい
    """
    k = pow(A,y,M)
    p,m = P//D,M//D
    # Pt = k-y mod M にしたい。
    # pt = (k-y)//D mod mにしたい。
    p_inv = pow(p,phi(m)-1,m)
    t = (k-y)//D * p_inv
    y += P*t
    y %= (M*P//D)
    y += (M*P//D)
    return y

for A,M in AM:
    x = F(A,M)
    print(x)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  for ( int i = 0; i < M ; i++){
    cin >> A.at(i) >> B.at(i);
  }
  
  int num[100] = {0};
  for ( int i = 0 ; i < M ; ++i){
    num[A.at(i)]++;
    num[B.at(i)]++;
  }
  
  for ( int i = 0 ; i < N ;++i) cout << num[i+1] << endl;
}


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

typedef unsigned long long ll;

ll md = 1000000007;

vector<ll> a;
vector<ll> b;
vector<ll> c;

int main(int, char**) 
{
	ll n, ans = 0;
	cin >> n;

	a.resize(n);
	b.resize(n);
	c.resize(n -1);
	ll x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n - 1; i++) {
		cin >> c[i];
	}
	for (int i = 0; i < n; i++) {
		x = a[i]-1;
		ans += b[x];
		if (i < n -1) {
			// cerr << i << ":" << x << "," << a[i+1] << endl;
			if (a[i+1] == x + 2)
				ans += c[x];
		}
	}

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


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n, l = MAP()
s = [STR() for _ in range(n)]
s.sort()
print(''.join(s))

Measured memory_bytes: 60908
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
 
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
 
//#endif
 
using namespace std;
 
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
 
#define VV(T) vector<vector< T > >
 
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
 
template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
 
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

string ok = "Possible";
string ng = "Impossible";



void mainmain(){
    int n;
    cin>>n;
    vint v(n);
    rep(i,n) cin>>v[i];
    if(n == 2){
        if(v[0] == 1 && v[1] == 1) cout << ok << endl;
        else cout << ng << endl;
        return;
    }
    bool f = true;
    sort(ALL(v));
    int m = v.back();
    vint w;
    int p = 0;
    vint cnt(n);
    rep(i,n) cnt[v[i]]++;
    int t = m;
    while(1){
        if(2*t == m){
            if(cnt[t]){
                cnt[t]--;
            }
            else{
                f=false;
                cout << t << endl;
            }
            break;
        }
        if(2 * t < m){
            break;
        }
        if(cnt[t] >= 2) cnt[t]-=2;
        else f=false;
        t--;
    }
    rep(i,n){
        if(cnt[i]){
            if(i < (m+1)/2 + 1) f = false;
        }
    }
    if(f) cout<< ok << endl;
    else cout<<ng<<endl;
}
 
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

int main() {
	int n, al = 0;
	cin >> n;
	vector<int> mt(n);
	vector<int> dm(n);
	for (int i = 0; i < n; i++)
	{
		cin >> dm[i];
		al += dm[i];
	}
	for (int i = 0; i < n - 1; i += 2)
	{
		al -= dm[i] * 2;
	}
	mt[n - 1] = al;
	for (int i = n - 2; i >= 0; i--)
	{
		mt[i] = 2 * dm[i] - mt[i + 1];
	}
	for (int i = 0; i < n; i++)
	{
		cout << mt[i] << ' ';
	}
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    string s, t; cin >> s >> t;
    int n = s.size();
    int cnt = 0;
    rep(i, n) {
        if (s[i]!=t[i]) cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 3828
#include<stdio.h>
#define MAX 45
int Fibonacci(int,int *);
int main(){
  int n,i,fibonacci[MAX];
  scanf("%d",&n);
  for(i=0;i<MAX;i++) fibonacci[i]=0;//初期化
  printf("%d\n",Fibonacci(n,fibonacci));
  return 0;
}

int Fibonacci(int n,int *fibonacci)
{
  if(n==0||n==1) return fibonacci[n]=1;
  if(fibonacci[n]!=0) return fibonacci[n];
  return fibonacci[n]=Fibonacci(n-1,fibonacci)+Fibonacci(n-2,fibonacci);
}



Measured memory_bytes: 2044
import java.util.ArrayList;
import java.util.Scanner;
class Main{


	static final int MOD = 1000000007;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();
	
		int[] a = new int[Q];
		int[] data = new int[N+1];
		for(int i = 0;i < Q;i++){
			a[i] = sc.nextInt();
			data[a[i]]++;
		}
		for(int i = 1; i <= N;i++){
			if(K -(Q - data[i]) > 0){
				System.out.println("Yes");
			}else{
				System.out.println("No");

			}
		}
		
		

		




	}

	static void sieve(ArrayList<Long> list){
		int n = 50000000;
		boolean[] is_prime = new boolean[n+1];
		int[] prime = new int[n];
		for(int i= 0;i <=n;i++){
			is_prime[i] = true;
		}
		list.add((long) 1);
		for(int i = 2;i <= n;i++){
			if(is_prime[i]){
				list.add((long)i);
				for(int j = 2*i;j <= n;j+=i){
					is_prime[j] = false;
				}
			}
		}



	}




	static int upperbond(int k,int min,int[] data){		//kより小さい最大の値をdataの中から探し、返す二分探索
		int max = data.length;
		//		if(min == data.length-1){
		//			if(data[min] > k){
		//				return min;
		//			}
		//		}

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}

		return max;
	}

	static int lowerbond(int k,int min,int[] data){		//kより大きい最小の値をdataの中から探し、返す二分探索
		int max = data.length;

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return min;
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}


class Edge extends ArrayList<P>{

}

class P{
	int to;
	long cost;
	P(int to,long cost){
		this.to = to;
		this.cost = cost;
	}
}


class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   from- otherpair.from;
	}








}






Measured memory_bytes: 55240
main = readAndDo showCase isEnd 1

readAndDo fn fin depth = do
  line <- getLine
  if fin line then return ()
  else do
    fn (show depth) line
    readAndDo fn fin $ depth + 1

-- 終了判定関数
isEnd line = line == "0"

-- 毎行実行する関数
showCase s1 s2 = do
  putStrLn $ "Case " ++ s1 ++ ": " ++ s2



Measured memory_bytes: 4040
import java.util.Scanner
fun max(a:Int, b:Int):Int{
  return if(a<b)b else a
}
fun main(args:Array<String>){
  val reader = Scanner(System.`in`);
  var A = reader.nextInt()
  var B = reader.nextInt()
  var C = reader.nextInt()
  var ans = max(0, C-(A-B))
  println("$ans")
}

Measured memory_bytes: 29472
from collections import defaultdict

n, ma, mb = map(int, input().split())
dp = defaultdict(lambda: float('inf'))
dp[0, 0] = 0
sa = 0
for _ in range(n):
    a, b, c = map(int, input().split())
    for (i, j), d in dp.copy().items():
        k = (i + a, j + b)
        dp[k] = min(dp[k], d + c)
    sa += a

ans = float('inf')
i = 1
while ma * i <= sa:
    ta = ma * i
    tb = mb * i
    i += 1
    ans = min(ans, dp[ta, tb])

print(-1 if ans == float('inf') else ans)


Measured memory_bytes: 8496
while True:
  h, w = map(int, input().split())
  if h == 0 and w == 0:
    break
  
  for x in range(0, h):
    string = ""
    for y in range(0, w):
      if x == 0 or x == h - 1 or y == 0 or y == w - 1:
        string += "#"
      else:
        string += "."
    print(string)
  
  print()


Measured memory_bytes: 5612
import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val graph = Graph(N)
    repeat(M) {
        val (A, B) = readLine()!!.split(" ").map(String::toInt)
        graph.addEdge(A, B)
        graph.addEdge(B, A)
    }
    val d = graph.bfs(1).drop(2)
    if (d.contains(-1)) {
        println("No")
    } else {
        println("Yes")
        println(d.joinToString("\n"))
    }
}

class Graph(v: Int) {
    private val vec = Array(v + 1) { mutableListOf<Int>() }

    fun addEdge(a: Int, b: Int) {
        vec[a].add(b)
    }

    fun bfs(start: Int): IntArray {
        val que = ArrayDeque<Int>()
        que.addLast(start)
        val d = IntArray(vec.size) { -1 }
        d[start] = start
        while (que.size > 0) {
            val p = que.removeFirst()
            for (next in vec[p]) {
                if (d[next] == -1) {
                    que.addLast(next)
                    d[next] = p
                }
            }
        }
        return d
    }
}

Measured memory_bytes: 83256
def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b

n, x = map(int, input().split())
town = map(int, input().split())

distance = (abs(x-y) for y in town)
res = next(distance)
for d in distance:
    if d % res != 0:
        res = gcd(res, d)

print(res)


Measured memory_bytes: 11180
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
unordered_map<string, string> m = {
    {"Sunny","Cloudy"},
    {"Cloudy","Rainy"},
    {"Rainy","Sunny"}
};

string Main(string S)
{
    return m[S];
}

int main(void){
    string S;
    cin >> S;
    cout << Main(S) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n;
    cin >> n;
    Vi a(n);
    rp(i,n) cin >> a.at(i);
    ll mini=10000000,maxi=-100000000;
    ll minpos,maxpos;
    rp(i,n){
        if(chmax(maxi,a[i])) maxpos=i;
        if(chmin(mini,a[i])) minpos=i;
    }
    bool plus=true;
    if(mini<0&&maxi>0){
        if(abs(mini)<abs(maxi)){
            print(2*n-1);
            repi(i,1,n+1){
                princ(maxpos+1);
                print(i);
            }
        }else{
            print(2*n-1);
            repi(i,1,n+1){
                princ(minpos+1);
                print(i);
            }
            plus=false;
        }
    }else{
        print(n-1);
        if(mini<0) plus=false;
    }
    if(plus){
        rp(i,n-1){
            princ(i+1);
            print(i+2);
        }
    }else{
        rp(i,n-1){
            princ(n-i);
            print(n-i-1);
        }
    }


    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

int func(int N)
{
    int ans = 0;

    while(N)
        ans++, N /= 10;

    return ans;
}

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N;
    cin >> N;

    int ans = 0;

    for(int i=1; i<=N; i++)
        ans += func(i) % 2;

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256