akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  int w,h,n;cin>>w>>h>>n;
  int wl=0;int wr=w;
  int hl=0;int hr=h;
  rep(i,n){
   int x,y,a;cin>>x>>y>>a;
    if(a==1)wl=max(wl,x);
    else if(a==2)wr=min(wr,x);
    else if(a==3)hl=max(hl,y);
    else if(a==4)hr=min(hr,y);
  }
  int ans=(wr-wl)*(hr-hl);
  if(wr-wl<=0||hr-hl<=0||ans<=0)cout<<0<<endl;
  else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <array>

using namespace std;

class LRectangle
{
public:
  int h,w;
  vector<vector<int>> t;
  vector<vector<int>> hl;
  LRectangle(){}
  LRectangle( int h, int w ) : h(h), w(w), t(h, vector<int>(w)), hl(h, vector<int>(w+1)) {}
  int solve();
  int maxrec( vector<int> &v );
};

int LRectangle::maxrec( vector<int> &v )
{
  stack<pair<int,int>> st;

  int vs = v.size();
  int ret = 0;
  
  for ( auto i = 0; i < vs; ++i )
    {
      int tidx = i;
      pair<int,int> stt;
      
      while(true)
        {
          if ( st.size() == 0 ) break;

          stt = st.top();

          if ( stt.second <= v[i] ) break;

          ret = max( ret, stt.second * (i - stt.first) );

          tidx = stt.first;
          st.pop();
        }

      if ( st.size() == 0 )
        st.push( make_pair( tidx, v[i] ) );
      else
        {
          stt = st.top();
          if ( stt.second < v[i] )
            st.push( make_pair( tidx, v[i] ) );
        }
    }
  
  return ret;
}

int LRectangle::solve()
{
  int ret = 0;
  
  for ( auto i = 0; i < w; ++i )
    {
      int v = 0;
      for ( auto j = 0; j < h; ++j )
        {
          if ( t[j][i] == 1 )
            {
              hl[j][i] = 0;
              v = 0;
            }
          else
            {
              hl[j][i] = ++v;
            }
        }
    }

  for ( auto i = 0; i < h; ++i )
    hl[i][w] = 0;


  for ( auto i = 0; i < h; ++i )
    ret = max( ret, maxrec( hl[i] ) );
  
  cout << ret << endl;
  
  return 0;
}

int main()
{
  int h, w;
  cin >> h >> w;

  LRectangle lr( h, w );

  for ( auto i = 0; i < h; ++i )
    for ( auto j = 0; j < w; ++j )
      cin >> lr.t[i][j];
  
  lr.solve();

  return 0;
}

Measured memory_bytes: 16572
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long memo[100010] = { 0 }, memo1[100010] = { 0 };
int main() {
	long long n, x, m;
	cin >> n >> x >> m;
	long long ans = x;
	long long loop, loop1;
	bool loop2 = false;
	memo[x] = 1;
	memo1[1] = x;
	for (int i = 2; i <= min(n, m); i++) {
		x *= x;
		x %= m;
		if (memo[x] != 0) {
			loop = ans - memo1[memo[x] - 1];
			loop1 = i - memo[x];
			loop2 = true;
			n -= i - 1;
			break;
		}
		ans += x;
		memo[x] = i;
		memo1[i] = ans;
	}
	if (loop2) {
		ans += loop * (n / loop1);
		for (int i = 0; i < n % loop1; i++) {
			ans += x;
			x *= x;
			x %= m;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4664
line = gets.split(' ').map(&:to_i)

X = line[0]
Y = line[1]

ans = "No"
for i in 0..100 do
  for j in 0..100 do
    if i + j == X and 2 * i + 4 * j == Y then
      ans = "Yes"
    end
  end
end
  
print ans

Measured memory_bytes: 14368
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int dp[5001][2][5001][2];

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

	cin >> N >> L >> R;
	if (L > R)swap(L, R);
	dp[0][1][0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 2; j++) {
			if (j == 0) {
				for (int k = 0; k < N; k++) {
					for (int l = 0; l < 2; l++) {
						if (k + 1 < L) {
							dp[i + 1][j][k + 1][l] += dp[i][j][k][l];
							dp[i + 1][j][k + 1][l] %= MOD;
						}
						if (k < L) {
							dp[i + 1][j ^ 1][1][l] += dp[i][j][k][l];
							dp[i + 1][j ^ 1][1][l] %= MOD;
						}
						if (k >= L) {
							int nx = l;
							if (k + 1 >= R)nx = 1;
							dp[i + 1][j][k + 1][nx] += dp[i][j][k][l];
							dp[i + 1][j][k + 1][nx] %= MOD;
							dp[i + 1][j ^ 1][k + 1][nx] += dp[i][j][k][l];
							dp[i + 1][j ^ 1][k + 1][nx] %= MOD;
						}
					}
				}
			}
			else {
				for (int k = 0; k < N; k++) {
					for (int l = 0; l < 2; l++) {
						int nx = l;
						if (k + 1 == R)nx = 1;
						dp[i + 1][j][k + 1][nx] += dp[i][j][k][l];
						dp[i + 1][j][k + 1][nx] %= MOD;
						nx = l;
						if (L > 1) {
							dp[i + 1][j ^ 1][1][nx] += dp[i][j][k][l];
							dp[i + 1][j ^ 1][1][nx] %= MOD;
						}
						if (k + L >= R)nx = 1;
						if (i + L <= N) {
							dp[i + L][j ^ 1][k + L][nx] += dp[i][j][k][l];
							dp[i + L][j ^ 1][k + L][nx] %= MOD;
						}
					}
				}
			}
		}
	}
	/*
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k <= N; k++) {
				for (int l = 0; l < 2; l++) {
					cout << i << " " << j << " " << k << " " << l << " " << dp[i][j][k][l] << endl;
				}
			}
		}
	}
	*/
	int ans = 0;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j <= N; j++) {
			ans += dp[N][i][j][1];
			ans %= MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 394372
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String o = sc.next();
		String e = sc.next();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < e.length(); i++) {
			sb.append(o.charAt(i));
			sb.append(e.charAt(i));
		}
		if(o.length()>e.length())sb.append(o.charAt(o.length()-1));
		System.out.println(new String(sb));
		sc.close();
	}
}

Measured memory_bytes: 23508
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include <map>
#include <set>

using namespace std;

#define REP(i,x) for(int i=0; i<(int)(x); i++)       // 0 <= i < x
#define REPS(i,x) for(int i=1; i<=(int)(x); i++)     // 0 < i <= x
#define RREP(i,x) for(int i=((int)(x)-1); i>=0; i--) // x > i >= 0
#define RREPS(i,x) for(int i=((int)(x)); i>0; i--)   // x >= i > 0
#define INF 100000000

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

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

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

    int a, b;
    a = n / 10;
    b = n % 1000;
    if(a % 111 == 0 || b % 111 == 0){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }

    return 0;
}


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

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

	int N, W;
	std::cin >> N >> W;
	std::vector<ll> V(N), wei(N), dp(W+1, 0);
	for(int i=0; i<N; i++){
		std::cin >> wei[i] >> V[i];
	}
	for(int i=0; i<N; i++){
		for(int w=W; w >= wei[i]; w--){
			dp[w] = std::max( dp[w], dp[w-wei[i]] + V[i] );
		}
	}
	std::cout << dp[W] << '\n';
	return 0;
}

Measured memory_bytes: 1024
n=int(input())
a=[]
for i in range(n):
    a.append([0,0,0])
    a[i][0],a[i][1],a[i][2]=map(int,input().split())
a.reverse()
b=[a[0][0],a[0][1],a[0][2]]
for i in range(1,n):
    b1=b[:]
    b[0]=max(a[i][0]+b1[1],a[i][0]+b1[2])
    b[1]=max(a[i][1]+b1[0],a[i][1]+b1[2])
    b[2]=max(a[i][2]+b1[1],a[i][2]+b1[0])
print(max(b))



Measured memory_bytes: 62936
import sys
sys.setrecursionlimit(1000000)

n = int(input())
g = [[] for _ in range(n)]
for i in range(n-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  g[a].append([b, i])
  g[b].append([a, i])
  
ans = [0]*(n-1)
  
def dfs(v, c=-1, p=-1):
  k = 1
  for u, ei in g[v]:
    if u == p:
      continue
    if k == c:
      k += 1
    ans[ei] = k
    k += 1
    dfs(u, ans[ei], v)
 
dfs(0)
print(max(ans))
for i in range(n-1):
  print(ans[i])

Measured memory_bytes: 108060
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define int ll
#define pb push_back
#define sz(i) (int)(i.size())
#define fi first
#define se second
#define ld long double
#define pii pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = 1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << std::endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 1e3 + 100;
const int M = 1e4 + 100;
const int T = 1e4;
// make sure N size is correctttt!!!!!!!!!

int v[M], n, dp[N][M+1000];
pair<pii, int> p[M];

bool cp(const pair<pii, int> idx1, const pair<pii, int> idx2){
   return idx1.fi.fi + idx1.fi.se < idx2.fi.fi + idx2.fi.se;
}

int solve(int idx1, int wt){
   if(wt > T)
      return 0;
   if(idx1 > n)
      return 0;
   int &ans = dp[idx1][wt];
   if(ans != -1)
      return ans;
   smax(ans, solve(idx1+1, wt));
   if(wt <= p[idx1].fi.se){
      int vals = p[idx1].se, weights = p[idx1].fi.fi;
      smax(ans,  vals + solve(idx1+1, wt+weights));
   }
   return ans;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main(){_

   cin>>n;
   // n = 1 + rng()%N;
   int tt = 1e9;
   for (int i = 1; i <= n; ++i)
   {
      // p[i].fi.fi = 1+rng()%M;
      // p[i].fi.se = 1+rng()%M;
      // p[i].se = 1+rng()%(tt);
      cin>>p[i].fi.fi>>p[i].fi.se>>p[i].se;
   }

   sort(p+1, p+n+1, cp);
   memset(dp, -1, sizeof dp);
   
   cout<<solve(0,0);
   //make sure N size is correct!!!!!!!!!
   return 0;
}

Measured memory_bytes: 95744
li = list(map(int, input().split()))
N = li[0]
L = li[1]
m = 10001
idx = 0
flag=0
for i in range(N):
    li = list(map(int, input().split()))
    if li[1] <= L and li[0]<m:
        m=li[0]
        idx = i
        flag=1

if flag:
    print(m)
else:
    print('TLE')

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

#define INF 1e10

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m; cin>>n>>m;
	ll l; cin>>l;
	vector<vll> cost(n+1, vll(n+1, INF));
	for(int i=1; i<=n; i++) cost[i][i] = 0;
	rep(i, m){
		int a, b; ll c;
		cin>>a>>b>>c;
		cost[a][b] = c;
		cost[b][a] = c;
	}

	for(int k=1; k<=n; k++)
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);

	vector<vi> ans(n+1, vi(n+1, -1));
	for(int i=1; i<=n; i++){
		using P = pair<int, int>;
		queue<P> que;
		que.emplace(i, -1);
		ans[i][i] = 0;
		while(que.size()){
			int v, c;
			tie(v, c) = que.front(); que.pop();
			for(int j=1; j<=n; j++){
				if (cost[v][j]<=l && ans[i][j]==-1){
					ans[i][j] = c+1;
					que.emplace(j, c+1);
				}
			}
		}
	}
	int Q; cin>>Q;
	rep(i, Q){
		int s, t; cin>>s>>t;
		cout << ans[s][t] << "\n";
	}
	return 0;
}


Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] str = br.readLine().split(" ");
        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        System.out.println((a * b) + " " + ((a * 2) + (b * 2)));
    }
}

Measured memory_bytes: 24240
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <functional>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <cmath>
#include <numeric>

using namespace std;

inline int solution(istream &cin, ostream &cout) {
  int n;
  cin >> n;
  vector<int> data(n);
  for (int i = 0; i < n; ++i) {
    cin >> data[i];
  }
  double avg = accumulate(data.begin(), data.end(), 0.0) / data.size();
  int ans = 0;
  double diff = fabs(avg - data[0]);
  for (int i = 1; i < n; ++i) {
    if (diff > fabs(avg - data[i])) {
      ans = i;
      diff = fabs(avg - data[i]);
    }
  }
  cout << ans << endl;
  return 0;
}

#if defined(LOCAL_TEST_RUN)

#include "gtest/gtest.h"
#include "gmock/gmock-matchers.h"
#include "gmock/gmock-more-matchers.h"
#include <sstream>

typedef pair<string, string> TestParam;
class ATest : public ::testing::TestWithParam<TestParam> {};

TEST_P(ATest, ExampleTest) {
  string input, expected_output;
  tie(input, expected_output) = GetParam();

  stringstream ss(input);
  stringstream out;
  solution(ss, out);
  EXPECT_THAT(out.str(), ::testing::StartsWith(expected_output));
}

INSTANTIATE_TEST_CASE_P(Case1, ATest, ::testing::Values(
  make_pair(
      /*input=*/R"(3
1 2 3)",
      /*output=*/R"(1
)")
));

INSTANTIATE_TEST_CASE_P(Case2, ATest, ::testing::Values(
    make_pair(
        /*input=*/R"(4
2 5 2 5)",
        /*output=*/R"(0)")
));

INSTANTIATE_TEST_CASE_P(Case3, ATest, ::testing::Values(
    make_pair(
        /*input=*/R"()",
        /*output=*/R"()")
));

INSTANTIATE_TEST_CASE_P(Case4, ATest, ::testing::Values(
    make_pair(
        /*input=*/R"()",
        /*output=*/R"()")
));

INSTANTIATE_TEST_CASE_P(Case5, ATest, ::testing::Values(
    make_pair(
        /*input=*/R"()",
        /*output=*/R"()")
));

INSTANTIATE_TEST_CASE_P(Case6, ATest, ::testing::Values(
    make_pair(
        /*input=*/R"()",
        /*output=*/R"()")
));

#else

int main() {
  return solution(cin, cout);
}

#endif

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func nextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	x := make([]int, N)
	y := make([]int, N)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		x[i], y[i] = getInt(), getInt()
		a[i] = i
	}

	var cnt, ans float64
	for {
		for i := 1; i < N; i++ {
			dx := float64(x[a[i]] - x[a[i-1]])
			dy := float64(y[a[i]] - y[a[i-1]])
			ans += math.Sqrt(dx*dx + dy*dy)
		}
		cnt += 1.0
		ok := nextPermutation(sort.IntSlice(a))
		if !ok {
			break
		}
	}
	out(ans / cnt)
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;


int main()
{
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif
 
    fastio
    ll n, cw=0, cr=0, cw1=0, cr1=0;
    cin>>n;
    char a[n+9];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        if(a[i]=='W')
            cw++;
        else
            cr++;
    }
    for (int i = 0; i < cr; ++i)
    {
        if(a[i]=='R')
            cr1++;
    }
    cout<<cr-cr1;
}



Measured memory_bytes: 3836
using System;
using System.Linq;
using System.Text;

class Program
{
	static void Main(string[] args)
	{
		var ABC = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int A = ABC[0], B = ABC[1], C = ABC[2];
		if (A - B >= C)
		{
			Console.WriteLine(0);
		}
		else
		{
			Console.WriteLine(Math.Max(C - (A - B), 0));
		}
	}
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        unordered_map <int,int> mp;
        int l = 0;
        for(int i=0;i<n;i++)
        {
            int x;
            cin>>x;
            mp[x]++;
            if(mp[x]>1)
            {
                l = 1;
                break;
            }
        }
        if(l)
        {
            cout<<"NO\n";
        }
        else
        {
            cout<<"YES\n";
        }
    }
    return 0;
}


Measured memory_bytes: 11308
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

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

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}

int main(){
    ll k; cin >> k;
    vector<ll> vec;
    rep(i,9)vec.emplace_back(i+1);
    vector<ll> pre, next, clear;
    pre = vec;
    ll cnt = 9;
    while(cnt < k){
        for(auto s : pre){
            int t = s % 10;
            for(int i = -1; i < 2; i++){
                if(t + i < 0 || t + i >= 10)continue;
                next.emplace_back(s * 10 + t + i);
                cnt++;
            }
        }
        // print(next);
        copy(all(next), back_inserter(vec));
        pre = next;
        next = clear;
    }

    cout << vec[k-1] << endl;
}

Measured memory_bytes: 4376
def main():
    N = int(input())
    As = [int(input()) for _ in range(N)]

    maxs = sorted(As, reverse=True)[:2]

    for a in As:
        if a in maxs:
            print(maxs[0] if a != maxs[0] else maxs[1])
        else:
            print(maxs[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 68924
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  
    label:
    while(sc.hasNextLine()){
      int h = sc.nextInt();
      int w = sc.nextInt();
        
      if(h==0 && w==0) break label;
      for(int i = 1; i<=h; i++){
        for(int j = 1; j<=w; j++){
          if(i %2 != 0){             //?\???°???
            if(j % 2 != 0){
             System.out.print("#");
            }else{
              System.out.print(".");
            }
          }else if(i % 2 == 0){      //??¶??°???
            if(j % 2 != 0){
             System.out.print(".");
            }else{
              System.out.print("#");
            }
          }
        }
System.out.println("");
      }
System.out.println("");
    }
      
  }
}


Measured memory_bytes: 35692
n = int(input())
s = input()
ls = list(s)
all = ls.count('R')* ls.count('G')* ls.count('B')

cnt = 0

for i in range(n):
    for j in range(i+1, n):
        if 2*j - i < n:
            if s[i] != s[j] and s[i] != s[2*j-i] and s[j] != s[2*j -i]:
                cnt +=1

print(all - cnt)

Measured memory_bytes: 9232
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str_nums = br.readLine().split(" ");
        int[] nums = new int[3];
        nums[0] = Integer.parseInt(str_nums[0]);
        nums[1] = Integer.parseInt(str_nums[1]);
        nums[2] = Integer.parseInt(str_nums[2]);
        int count = 0;
        
        while (!(nums[0] == nums[1] && nums[1] == nums[2])) {
            Arrays.sort(nums);
            if ((nums[0] == nums[1] || nums[1] == nums[2] || nums[2] == nums[0]) && (!(nums[0] == nums[1] && nums[1] == nums[2]))) {
                if (nums[2] > nums[1]) {
                    nums[0] += 1;
                    nums[1] += 1;
                    count++;
                }
                else {
                    nums[0] += 2;
                    count++;
                }
            }
            else {
                nums[0] += 1;
                nums[1] += 1;
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21332
n, m, k = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0

a, b = [0], [0]

j = m

for i in range(n):
  a.append(a[i] + A[i])
for i in range(m):
  b.append(b[i] + B[i])
  
for i in range(n+1):
  if a[i] > k:
    break
  
  while b[j] + a[i] > k:
    j -= 1
  
  ans = max(ans, i + j)

print(ans)

Measured memory_bytes: 47596
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
A = np.array(rl())
answer = 0
while A.max() >= N:
    B = A // N
    count = B.sum()
    answer += count
    A = A - B * N + (count - B)

print(answer)


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

typedef long long ll;

#define PB push_back
#define MP make_pair

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    string s; cin >> s;
    int ans1 = 0;
    int ans2 = 0;
    int cur = s[0] - '0';
    for (int i = 1; i < s.size(); ++i) {
        int c = s[i] - '0';
        if (c != !cur) {
            ++ans1;
            cur = !cur;
        } else cur = c;
    }
    cur = !(s[0] - '0');
    for (int i = 1; i < s.size(); ++i) {
        int c = s[i] - '0';
        if (c != !cur) {
            ++ans2;
            cur = !cur;
        } else cur = c;
    }
    ++ans2;
    cout << min(ans1, ans2) << "\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll INF = (1LL<<60);

int main(){

    ll a1, a2, a3; cin >> a1 >> a2 >> a3;

    if(a1+a2+a3>=22){
        cout << "bust" << endl;
    }
    else{
        cout << "win" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"reflect"
	"strconv"
	"strings"
)

// SENTINEL is used for merge sort by adding the last index
var SENTINEL = 2000000000

type Card struct {
	suit  string
	value int
}

func merge(A []Card, n, left, mid, right int) {
	n1 := mid - left
	L := make([]Card, n1+1)
	n2 := right - mid
	R := make([]Card, n2+1)
	for i := 0; i < n1; i++ {
		L[i] = A[left+i]
	}
	for i := 0; i < n2; i++ {
		R[i] = A[mid+i]
	}
	L[n1].value, R[n2].value = SENTINEL, SENTINEL

	i, j := 0, 0
	for k := left; k < right; k++ {
		if L[i].value <= R[j].value {
			A[k] = L[i]
			i++
			continue
		}
		A[k] = R[j]
		j++
	}
}

func mergeSort(A []Card, n, left, right int) {
	mid := 0
	if left+1 < right {
		mid = (left + right) / 2
		mergeSort(A, n, left, mid)
		mergeSort(A, n, mid, right)
		merge(A, n, left, mid, right)
	}
}

func partition(A []Card, n, p, r int) int {
	x := A[r]
	i := p - 1
	for j := p; j < r; j++ {
		if A[j].value <= x.value {
			i++
			A[i], A[j] = A[j], A[i]
		}
	}
	A[i+1], A[r] = A[r], A[i+1]
	return i + 1
}

func quickSort(A []Card, n, p, r int) {
	q := 0
	if p < r {
		q = partition(A, n, p, r)
		quickSort(A, n, p, q-1)
		quickSort(A, n, q+1, r)
	}
}

func answer(r io.Reader) string {
	sc := bufio.NewScanner(r)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	A, B := make([]Card, n), make([]Card, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss := strings.Split(sc.Text(), " ")
		A[i].suit = ss[0]
		A[i].value, _ = strconv.Atoi(ss[1])
		B[i].suit, B[i].value = A[i].suit, A[i].value
	}

	mergeSort(A, n, 0, n)
	quickSort(B, n, 0, n-1)

	var buf bytes.Buffer
	if reflect.DeepEqual(A, B) {
		buf.WriteString("Stable\n")
	} else {
		buf.WriteString("Not stable\n")
	}

	for i := 0; i < n; i++ {
		buf.WriteString(B[i].suit + " " + strconv.Itoa(B[i].value) + "\n")
	}
	return strings.TrimRight(buf.String(), "\n")
}

func main() {
	fmt.Println(answer(os.Stdin))
}



Measured memory_bytes: 16316
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define X first
#define Y second
#define pb push_back
#define CL(x) (x << 1)
#define CR(x) ((x << 1) + 1)
#define sqr(x) ((x) * (x))
#define Task ""

typedef long long cc;
typedef long double ld;
typedef pair <int, int> pii;
const int N = 100005;
vector <int> e[N];
bool le[N], chan[N];
int n, m;
int res;
bool was[N];
int odd, even;
bool ok;
void dfs(int u, int p) {
    was[u] = true;
    if (le[u]) odd++;
    if (chan[u]) even++;
    if (le[u] && chan[u]) ok = true;
    for (auto v: e[u])
        if (v != u) {
            le[v] = le[v] | (chan[u] & 1);
            chan[v] = chan[v] | (le[u] & 1);
            if (!was[v]) dfs(v, u);
        }
}
int main() {
    std :: ios_base :: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    //freopen("input.inp", "r", stdin);
    //-------------------------------------------------------------------------------------------------------
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        e[u].pb(v);
        e[v].pb(u);
    }
    le[1] = 1;
    dfs(1, -1);
    for (int i = 1; i <= n; i++)
        ok = ok | (le[i] && chan[i]);
    if (ok) cout << 1ll * n * (n - 1) / 2 - m;
    else {
        cc tmp = 0;
        for (int i = 1; i <= n; i++) {
            if (!le[i]) tmp += 1ll * even - 1;
            if (!chan[i]) tmp += 1ll * odd - 1;
        }
        cout << max(0ll, 1ll * n * (n - 1) / 2 - m - tmp / 2);
    }
    //-------------------------------------------------------------------------------------------------------
    return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,m,v,p;cin>>n>>m>>v>>p;
    vector<ll>a(n);
    vector<ll>b(n);
    rep(i,n){
        cin>>a[i];
        b[i]=-a[i];
    }
    sort(all(a));
    sort(all(b));
    reverse(all(a));
    ll ans=0;
    ll d=0;
    rep(i,n){
        if(i<p){
            ans++;
            continue;
        }
        auto itr=lower_bound(all(b),b[i]);
        ll k=(b.end()-itr);
        if(p-1+k>=v&&(m+a[i])>=a[p-1]){
            ans++;
        }
        else{
            if(m+a[i]>=a[p-1]){
                if(m+a[i]>=a[p-1]){
                    if((d+(i+1-p)*(m+a[i]-a[p-1]))>=(v-(p-1+k))*m){
                        //cout<<a[i]<<' '<<(i+1-p)*(m+a[i]-a[i-1])<<endl;
                        ans++;
                    }else{
                        break;
                    }
                }else{
                    break;
                }
            }else{
                break;
            }
        }
        d+=a[p-1]-a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

 
signed main(void){
    int N;
    int A[4][4];
    bool c[4][4]={};
    int b[17];
    REP(i,3){
        REP(j,3){
            cin >> A[i][j];
        }
    }
    cin >> N;
    REP(i,N){
        cin >> b[i];
    }
    
    REP(i,N){
        REP(j,3){
            REP(k,3){
                if(b[i]==A[j][k]){
                    c[j][k]=1;
                }
            }
        }
    }
    
    REP(i,3){
        bool bingo=true;
        REP(j,3){
            if(c[i][j]!=1){
                bingo=false;
            }
        }
        if(bingo){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    REP(j,3){
        bool bingo=true;
        REP(i,3){
            if(c[i][j]!=1){
                bingo=false;
            }
        }
        if(bingo){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    if(c[0][0] && c[1][1] && c[2][2]){
        cout << "Yes" << endl;
        return 0;
    }
    if(c[0][2] && c[1][1] && c[2][0]){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){
		//A
		/*
		String s = sc.next();
		int ans = 0;
		for(int i = 0 ; i < 4 ; i++){
			if(s.charAt(i) == '+')
				ans++;
			else
				ans--;
		}
		System.out.println(ans);
		*/
		//B
		/*
		int n = sc.nextInt();
		int length = String.valueOf( n ).length();
		int sn = 0;
		for(int i  = 0; i < length ; i++){
			sn += n/(int)(Math.pow(10, i))%10;
		}
		if(n % sn == 0)
			System.out.println("Yes");
		else
			System.out.println("No");
			*/
		//C
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++){
			a[i] = sc.nextInt();
		}
		double ans = Math.ceil((n-1)/(double)(k-1));
		System.out.println((int)ans);
	}
}


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

int main(){
  std::string S;
  cin >> S;
  int ans=0;
  for(int i=0; i<S.size();i++){
    if( S[i] == '+'){
      ans++;
    }else{
      ans--;
    }
  }
    cout << ans <<endl;
    
return 0;
}

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

using namespace std;
int main()
{
int n;
cin>>n;
int maks=0, a;
for(int i=0; i<n; i++)
    {
    cin>>a;
    maks=max(maks,a);
    if(a<maks-1)
        {
        cout<<"No";
        return 0;
        }
    }
    cout<<"Yes";

    return 0;
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 3010, M = 3010;

int n, m;
int a[N], b[N];
int f1[N][N], f2[N][N];

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i ++ ) cin >> a[i] >> b[i];
	
	for (int i = 1; i <= n; i ++ )
		for (int j = 0; j < m; j ++ )
		{
			f1[i][j] = max(f1[i][j], f1[i - 1][j]);
			if (j >= a[i]) f1[i][j] = max(f1[i][j], f1[i - 1][j - a[i]] + b[i]);
		}
	
	for (int i = n; i >= 1; i -- )
		for (int j = 0; j < m; j ++ )
		{
			f2[i][j] = max(f2[i][j], f2[i + 1][j]);
			if (j >= a[i]) f2[i][j] = max(f2[i][j], f2[i + 1][j - a[i]] + b[i]);
		}
	
	int res = 0;
	for (int i = 1; i <= n; i ++ )
		for (int j = 0; j < m; j ++ ) 
			res = max(res, b[i] + f1[i - 1][j] + f2[i + 1][m - 1 - j]);
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 70912
#include <iostream>
#include <vector>
#include <string>
#include <cstring>

using namespace std;

int main(){
	int N, M;
	int HP[100];
	int costS[100001], costA[100001];
	while(cin >> N, N){
		int maxHP = 0;
		for(int i=0;i<N;i++){
			cin >> HP[i];
			maxHP = max(maxHP, HP[i]);
		}
		cin >> M;
		string target;
		int MP, damage;
		vector< pair<int,int> > single;
		vector< pair<int,int> > all;
		for(int i=0;i<M;i++){
			cin >> target >> MP >> target >> damage;
			if(damage==0) continue;
			if(target=="Single") single.push_back(make_pair(MP,damage));
			else                 all.push_back(make_pair(MP,damage));
		}
		memset(costS,-1,sizeof(costS)); costS[0] = 0;
		memset(costA,-1,sizeof(costA)); costA[0] = 0;
		for(int i=1;i<=maxHP;i++){
			for(int j=0;j<single.size();j++){
				int prev = max(0,i-single[j].second);
				if(costS[i]==-1||costS[i]>costS[prev]+single[j].first)
					costS[i] = costS[prev]+single[j].first;
			}  
			for(int j=0;j<all.size();j++){
				int prev = max(0,i-all[j].second);
				if(costA[i]==-1||costA[i]>costA[prev]+all[j].first)
					costA[i] = costA[prev]+all[j].first;
			}
		}
		int ans = -1;
		for(int i=0;i<=maxHP;i++){
			if(costA[i]==-1) continue;
			if(costS[maxHP-i]==-1) continue;
			int tmp = costA[i];
			for(int j=0;j<N;j++)
				tmp += costS[max(0,HP[j]-i)];
			if(ans==-1||ans>tmp) ans = tmp;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, K;
ll A[505];
ll sum;

vector<ll> divisor;
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    for(ll i = 1; i * i <= sum; i++) {
        if(sum % i != 0) continue;
        divisor.push_back(i);
        if(i * i != sum) divisor.push_back(sum / i);
    }
    sort(divisor.begin(), divisor.end(), greater<ll>());
    for(int index = 0; index < divisor.size(); index++) {
        ll now = divisor[index];
        vector<ll> v;
        ll nowsum = 0;
        for(int i = 1; i <= N; i++) {
            if(A[i] % now == 0) continue;
            v.push_back(A[i] % now);
            nowsum += v.back();
        }
        sort(v.begin(), v.end(), greater<ll>());
        if(nowsum <= K) {
            cout << now << endl;
            return 0;
        }
        ll subsum = 0;
        for(int border = 0; border < v.size(); border++) {
            nowsum -= v[border];
            subsum += now - v[border];
            if(max(nowsum, subsum) <= K) {
                cout << now << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define F(i, a, n, b) for(int i=a;i<n;i+=b)
#define REVF(i, a, b, c) for(int i=a;i>=b;i-=c)
#define REP(i, n) F(i, 0, n, 1)
#define REP1(i, n) F(i, 1, n+1, 1)
#define REV(i, n) REVF(i, n, 0, 1)
#define PTR(it, x) for(auto it=x.begin();it!=x.end();++it)
#define MOD 1000000007

typedef long long ll;

const ll MAX = 2e6 + 5;

int n,x;
map<int,int> a;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	REP(i,n){
		cin>>x;
		a[x] = i;
	}
	REP1(i,n){
		cout<<a[i] + 1<<' ';
	}
	return 0;
}

Measured memory_bytes: 5504
#include <iostream>
#include <vector>
#include <queue>
#include <string>

using namespace std;
typedef long long ll;

template<typename T>
void vecprint(vector<T> v) {
    for(auto x : v) {
        cout << x << " ";
    }
    cout << endl;
}

template<typename T>
void qprint(priority_queue<T> q) {
    while(!q.empty()) {
        cout << q.top() << " ";
        q.pop();
    }
    cout << endl;
}

int main(void) {
    string s, t;
    cin >> s >> t;
    
    int count = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == t[i]) count++;
    }
    
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{

    long long int a, b, sum;
    scanf("%lld%lld", &a, &b);
    if(a > b / 2)
    {
        sum = b / 2;
        printf("%lld", sum);
    }
    else
    {
        sum = a;
         printf("%lld", (b - 2*a) / 4 + sum);
    }


    return 0;
}


Measured memory_bytes: 128
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string & str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int d, l;
	scanf("%d%d", &d, &l);
	printf("%d\n", d / l + (d % l));

	Please AC;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

struct Node {
  ll value;
  V<int> adj;
};

V<Node> graph;
V<bool> visited;

// DFS
void accum(int current_i) {
  for(auto next_i : graph[current_i].adj) {
    if(visited[next_i]) {
      continue;
    }

    visited[current_i] = true;
    graph[next_i].value += graph[current_i].value;
    accum(next_i);
  }
}

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

  graph.resize(n);
  visited.resize(n);

  rep(i, n - 1) {
    int from, to;
    cin >> from >> to;
    from--; to--;
    graph[from].value = 0;
    graph[from].adj.push_back(to);
    graph[to].adj.push_back(from);
    visited[from] = false;
  }

  rep(i, q) {
    int to;
    ll x;
    cin >> to >> x;
    to--;
    graph[to].value += x;
  }

  visited[0] = true;
  accum(0);

  rep(i, n) {
    cout << graph[i].value << " ";
  }
  cout << endl;
}


Measured memory_bytes: 31372
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long i,j,t,a,b,n,c,d,y,temp,m,r,sum,count,k,l,ans;
    t=1;
    // cin>>t;
    while(t--)
    {
    ans=1;
    cin>>n>>k;
    while(n--)
    {
        ans=min(2*ans,ans+k);
    }
    cout<<ans;
    }
}

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

typedef struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
}node;
typedef node* Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while (x->left != NIL) x = x->left;
  return x;
}

Node treeSearch(Node u, int key){
  while (u != NIL && u->key != key) {
    if (key < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;

  if (x->right != NIL) return treeMinimum(x->right);

  y = x->parent;

  while (y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }

  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if (z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if (y->left != NIL) x = y->left;
  else x = y->right;

  if (x != NIL) x->parent = y->parent;

  if (y->parent == NIL) root = x;
  else if (y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if (y != z) z->key = y->key;

}

void insert(int key){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(node));
  z->key = key;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if (y == NIL) root = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;

}

void inorder(Node u){
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node u){
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n, i, key;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( *com == 'f' ){
      scanf("%d", &key);
      Node t = treeSearch(root, key);
      if ( t != NIL ) puts("yes");
      else puts("no");
    } else if ( *com == 'i' ){
      scanf("%d", &key);
      insert(key);
    } else if ( *com == 'p' ){
      inorder(root);
      puts("");
      preorder(root);
      puts("");
    } else if ( *com == 'd' ){
      scanf("%d", &key);
      treeDelete(treeSearch(root, key));
    }
  }

  return 0;
}

Measured memory_bytes: 24048