akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define mkp make_pair
#define cerr if (0) cerr

const int INF = 1e18;

void solve() {
    double ans = 1;
    int n; cin >> n;
    loop(i, n) {
        int x; cin >> x;
        ans *= x;
        if (ans > INF) {
            bool zero = 0;
            for (int j = i + 1; j < n; ++j) {
                cin >> x;
                zero |= (x == 0);
            }
            if (zero)
                cout << 0;
            else
                cout << -1;
            return;
        }
    }
    cout << (ll)ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }

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

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (int)N; i++)

vector<int> component;
stack<int> s;
vector<bool> used;
vector<vector<int>> adjacentList;
vector<vector<int>> adjacentListR;

void dfs(int v) {
  used[v] = true;
  for(int nv : adjacentList[v]) {
    if(!used[nv]) dfs(nv);
  }
  s.push(v);
}

void rdfs(int v, int k) {
  used[v] = true;
  component[v] = k;
  for(int nv : adjacentListR[v]) {
    if(!used[nv]) rdfs(nv, k);
  }
}

int main () {
  int V, E, Q;
  cin >> V >> E;
  adjacentList = vector<vector<int>>(V);
  adjacentListR = vector<vector<int>>(V);
  component = vector<int>(V);
  used = vector<bool>(V, false);

  for(int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    adjacentList[s].push_back(t);
    adjacentListR[t].push_back(s);
  }

  for(int v = 0; v < V; v++) {
    if(!used[v]) dfs(v);
  }

  fill(used.begin(), used.end(), false);
  int k = 0;
  while(!s.empty()) {
    int v = s.top(); s.pop();
    if(!used[v]) rdfs(v, k++);
  }

  cin >> Q;
  for(int i = 0; i < Q; i++) {
    int u, v;
    cin >> u >> v;
    cout << (component[u] == component[v]) << endl;
  }

  return 0;
}

Measured memory_bytes: 2848
while True:
    try:
        x = map(int, raw_input().split(' '))
        
        if x[0] < x[1]:
            m = x[1]
            n = x[0]
        else:
            m = x[0]
            n = x[1]
           
           
        # m is greatrer than n
        while n !=0:
            m,n = n,m % n
        
        print m,x[0]*x[1]/m
    except EOFError:
        break

Measured memory_bytes: 5056
#include<cstdio>
#include<algorithm>
using namespace std;
const static int INF = 30000000;

int main(){
	int N, M, R;
	scanf("%d %d %d", &N, &M, &R);
	int r[R];
	for (int i = 0; i < R; ++i){
		scanf("%d", r+i);
		r[i]--;
	}
	int d[N][N];
	for (int i = 0; i < N; ++i){
		for (int j = 0; j < N; ++j) d[i][j] = INF;
	}
	for (int i = 0; i < N; ++i) d[i][i] = 0;
	for (int i = 0; i < M; ++i){
		int u, v, cost;
		scanf("%d %d %d", &u, &v, &cost);
		d[--u][--v] = cost;
		d[v][u] = cost;
	}
	for (int k = 0; k < N; ++k){
		for (int i = 0; i < N; ++i){
			for (int j = 0; j < N; ++j){
				if(d[i][j] > d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j];
			}
		}
	}
	sort(r, r + R);
	int answer = 170000000;
	do{
		int answer_candidate = 0;
		for (int i = 0; i < R - 1; ++i) answer_candidate += d[r[i]][r[i + 1]];
		if(answer_candidate < answer) answer = answer_candidate;
	}while(next_permutation(r, r + R));
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace CsTest
{

    public class Program
    {
        static void Main(string[] args)
        {
            int[] NM = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int L = 1;
            int R = NM[0];
            for (int i = 0; i < NM[1]; ++i)
            {
                int[] LR = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                L = Math.Max(LR[0], L);
                R = Math.Min(LR[1], R);
            }
            if (R < L)
                Console.WriteLine(0);
            else
                Console.WriteLine(R - L + 1);
        }
    }
}

Measured memory_bytes: 17460
import java.util.Scanner;
 
public class Main {
  public static void main (String[] args){
    
   String a,b,c; 
 
   Scanner sc = new Scanner (System.in);
   a=sc.nextLine();
   b=sc.nextLine();
   c=sc.nextLine();

   String new_a = a.substring(0,1);
   String new_b = b.substring(1,2);
   String new_c = c.substring(2,3);

   System.out.print(new_a);
   System.out.print(new_b);
   System.out.println(new_c);
  }
}

Measured memory_bytes: 21844
#include <atcoder/dsu>
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int main() {
  int N;
  scanf("%d", &N);
  vector<pair<PII, int>> in;
  for (int i = 1; i <= N; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    in.PB(MP(MP(x, y), i));
  }
  sort(ALL(in));
  atcoder::dsu d(N + 1);
  vector<PII> st;
  for (auto t : in) {
    if (!st.empty()) {
      auto top = st.back();
      while (!st.empty() && st.back().F < t.F.S) {
        d.merge(t.S, st.back().S);
        st.pop_back();
      }
      st.push_back(top);
    }
    if (st.empty() || st.back().F > t.F.S)
      st.push_back(MP(t.F.S, t.S));
  }
  /*
  reverse(ALL(in));
  st.clear();
  for (auto t : in) {
    while (!st.empty() && st.back().F > t.F.S) {
      d.merge(t.S, st.back().S);
      st.pop_back();
    }
    st.push_back(MP(t.F.S, t.S));
  }
  */
  for (int i = 1; i <= N; i++) {
    printf("%d\n", d.size(i));
  }
  return 0;
}


Measured memory_bytes: 8124
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N;
  cin >> N;
  vector<int> t(N), x(N), y(N);
  for (int i=0; i<N; i++) cin >> t[i] >> x[i] >> y[i];
  bool can = true;
  for (int i=0; i<N; i++) {
    can = (t[i]>=x[i]+y[i])&&(t[i]%2==0&&((x[i]+y[i])%2==0)||(t[i]%2!=0&&(x[i]+y[i])%2!=0));
    if (!can) break;
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	static int r = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}	
		}
		sc.close();
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				solve(D, X, i, j);
			}
		}
		System.out.println(r);
	}
	
	static void solve(int D, int[][] X, int idx1, int idx2) {
		int sum = 0;
		for(int i = 0; i < D; i++) {
			int yx = Math.abs(X[idx1][i] - X[idx2][i]);
			sum += yx * yx;
		}
		boolean f = false;
		for(int i = 0; i <= sum; ++i) {
			if(i * i == sum) f = true;
		}
		if(f) r++;
		// double sqrt1 = Math.sqrt(sum);
		// int sqrt2 = (int)sqrt1;
		// if(sqrt1 == (double)sqrt2) r++;
		// System.out.println("# " + (sqrt1 == (double)sqrt2) + " = " + sum + " : " + sqrt1 + " " + sqrt2);
	}
}	


Measured memory_bytes: 23252
n, a, b = map(int, input().split())
cnt = 0
for i in range(1, n + 1):
    c = i//10000 + (i%10000)//1000 + (i%1000)//100 + (i%100)//10 + i%10
    if(a <= c <= b):
        cnt += i
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

int a[200000];
int main(void)
{
	int N;
	cin >> N;
	Rep(i, N) cin >> a[i];
	ll sum = 0;
	Rep(i, N) sum += a[i];

	ll sum2 = 0;
	ll ans = abs(sum - 2 * a[0]);
	Rep(i, N){
		sum2 += a[i];
		if(i != 0 && i != N - 1){
			ans = min(ans, abs(sum2 - (sum - sum2)));
		}
	}
	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
    int i,j;
    int n;
    int m = 256;
    while(cin >> n, n){
        vi in(n);
        rep(i,n) cin >> in[i];
        double H = INF, S, A, C;
        rep(s,16)rep(a,16)rep(c,16){
            int cnt[256] = {};

            int r = s;
            rep(i,n){
                r = (a * r + c) % m;
                cnt[(in[i]+r)%m]++;
            }

            double out = 0;
            rep(i,256)if(cnt[i]){
                double t = 1.*cnt[i]/n;
                out -= t*log2(t);
            }

            if(out < H){
                H = out;
                S = s;
                A = a;
                C = c;
            }
        }

        cout << S << " " << A << " " << C << endl;
    }
}



Measured memory_bytes: 3320
n, x = map(int, input().split())

a = [1]
p = [1]
for i in range(n):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(N, X):
    if N<=0:
        if X<=0:
            return 0
        else:
            return 1
    elif X <= 1 + a[N-1]:
        return f(N-1, X-1)
    else:
        return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(n, x))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int n,m; cin >> n >> m;
	cout << (n-1)*(m-1) << endl;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]) {
    var datas        = Array[Int](0)
    var factors_list = Array[String]()
    var count        = 0
    for (line <- io.Source.stdin.getLines()) {
      if (count == 0) {
        datas = line.split(" ").map{_.toInt}
      }
      else {
        if (!line.matches("""^\.+$""")) {
          factors_list = factors_list :+ line
        }
      }
      count += 1
    }

    var road_only = Array[Int]()
    for(i <- 0 until factors_list(0).length) {
      var check = true

      for(j <- 0 until factors_list.length) {
        if(factors_list(j)(i) == '#') {
          check = false
        }
      }

      if(check) {
        road_only = road_only :+ i
      }
    }


    for(i <- 0 until factors_list.length) {
      for(j <- 0 until factors_list(0).length) {
        if (!road_only.contains(j)) {
          print(factors_list(i)(j))
        }
      }
      println()
    }

  }
}


Measured memory_bytes: 28540
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main(void)
{
	int n, t, a;
	cin >> n >> t >> a;

	vector<float> h(n);
	vector<float> ondo(n);
	float sabun;
	float sml = 20000;
	int smlidx = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
		ondo[i] = t - h[i] * 0.006;
		sabun = fabs(a - ondo[i]);
		if (sml > sabun)
		{
			sml = sabun;
			smlidx = i + 1;
		}
	}

	cout << smlidx << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <complex>

using namespace std;
typedef long long ll;

typedef double R;
typedef complex<R> P;

double cross(const P &a, const P &b) { return imag(conj(a)*b); }
double dot(const P &a, const P &b) { return real(conj(a)*b); }

int n;
P p[100];
R solve() {
    R res = 0;
    for (int i = 2; i < n; i++) {
        res += cross(p[i-1]-p[0], p[i]-p[0]) / 2.0;
    }
    return abs(res);
}


int main() {
    int t = 1;
    while (true) {
        scanf("%d", &n);
        if (!n) break;
        for (int i = 0; i < n; i++) {
            R x, y;
            scanf("%lf %lf", &x, &y);
            p[i] = P(x, y);
        }
        printf("%d %.1f\n", t, solve());
        t++;
    }
    return 0;
}

Measured memory_bytes: 1232
let num = Int(readLine()!)
let str = readLine()!
let mask = Int(readLine()!)

var count = 1
var masks = ""
var out = ""

for s in str.characters {
  if( count == mask ) {
  	masks = String(s)
  }
  count += 1
}

for s in str.characters {
  if( String(s) != masks ) {
    out += "*"
  } else {
  	out += String(s)
  }
}

print( out )


Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin>>s;
	if(s=="ABC") cout<<"ARC";
	else cout<<"ABC";
	
}



Measured memory_bytes: 3636
#include<cstring>
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;
const int N=2e5+5;
string s1,s2;
int a[N],b[N];
int main() {
	cin>>s1>>s2;
	int len1=s1.length(),len2=s2.length();
	if(len1!=len2)return puts("No"),0;
	for(int i=1;i<len1;i++) {
		if(!a[s1[i]-'a']&&!b[s2[i]-'a'])a[s1[i]-'a']=s2[i]-'a',b[s2[i]-'a']=s1[i]-'a';
		if(a[s1[i]-'a']==s2[i]-'a'&&b[s2[i]-'a']==s1[i]-'a')continue;
		if(a[s1[i]-'a']!=(s2[i]-'a')||(b[s2[i]-'a']!=s1[i]-'a'))return puts("No"),0;
	}
	puts("Yes");
}

Measured memory_bytes: 1020
#include <stdio.h>

int abs(int x){
    return (x > 0) ? x : -x;
}
int max(int a, int b){
    return (a > b) ? a : b;
}

int main(void){
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    int d, e, f;

    d = abs(a-b);
    e = abs(b-c);
    f = abs(c-a);
    int m = max (d, max(e, f)); 
    printf("%d\n", d + e + f - m);
    return 0; 
}

Measured memory_bytes: 128
//  A - ABC Swap
// https://atcoder.jp/contests/abc161/tasks/abc161_a
#include <iostream>
#include <bits/stdc++.h>
#include <map>
#include <queue>
#include <set>
#include <string> 
#include <vector>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, int> PLI;
typedef pair<int, int> PII;

#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x , val) memset(x , val , sizeof(x));

const ll mxsize = 2e5 + 5;
const ll linf = 1e9;
const long double inf = 10000000000.0;

#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

const ll mod = 998244353;
 
/******************************************** CODE STARTS FROM HERE *************************************************/ 

int main()
{
    fastIO;
    vector < ll > arr(3);
    int i;
    fo(i , 3)
    {
        cin >> arr[i];
    }
    swap(arr[0] , arr[1]);
    swap(arr[0] , arr[2]);
    cout << arr[0] << " " << arr[1] << " " << arr[2] << endl;
}

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

public class Main {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	int mod = 1000000007;
	int index = 0;

	void run() {
		int N = sc.nextInt();
		while (N-- > 0) {
			index = 0;
			String input = sc.next();
			System.out.println(expression(new StringBuilder(input.substring(0,
					input.length() - 1))));
		}
	}

	int expression(StringBuilder sb) {
		int res = term(sb);
		for (; index < sb.length();) {
			if (sb.charAt(index) == '+') {
				index++;
				res += term(sb);
			} else if (sb.charAt(index) == '-') {
				index++;
				res -= term(sb);
			} else {
				break;
			}
		}
		return res;
	}

	int term(StringBuilder sb) {
		int res = factor(sb);
		for (; index < sb.length();) {
			if (sb.charAt(index) == '*') {
				index++;
				res *= factor(sb);
			} else if (sb.charAt(index) == '/') {
				index++;
				res /= factor(sb);
			} else {
				break;
			}
		}
		return res;
	}

	int factor(StringBuilder sb) {
		int res = 0;
		if (index < sb.length() && sb.charAt(index) == '(') {
			index++;
			res = expression(sb);
			index++;
		} else {
			res = number(sb);
		}
		return res;
	}

	int number(StringBuilder sb) {
		int res = 0;
		while (index < sb.length() && Character.isDigit(sb.charAt(index))) {
			res *= 10;
			res += sb.charAt(index) - '0';
			index++;
		}
		return res;
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
}

Measured memory_bytes: 17132
input_line = gets.chomp.split(" ")
A, B, C, D = input_line.map {|i| i.to_i}
def winner(a,b,c,d)
    while (c > 0 || a > 0) do
        c -= b
        return 'Yes' if c <= 0
        a -= d
        return 'No' if a <= 0
    end
end
print winner(A,B,C,D)

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

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

  int now;
  int before;
  cin >> before;
  int gap = before;
  int first = before;
  int newgap;
  for (int i = 1; i < N; i++)
  {
    scanf("%d", &now);
    newgap = now - before;
    gap = max(gap, newgap);
    before = now;
  }

  gap = max(gap, K - now + first);
  cout << K - gap << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Pipes;

namespace cswork
{
    class Program
    {
        public Program() { }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        void Omame()
        {
            cin = new Scanner();
            int n = cin.nextInt();

            string ans = "";
            if(n < 1200)
            {
                ans = "ABC";
            }else if(n < 2800)
            {
                ans = "ARC";
            }
            else
            {
                ans = "AGC";
            }
            Console.WriteLine(ans);

        }


        static void Main(string[] args)
        {
            new Program().Omame();
        }

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

Measured memory_bytes: 13268
'use strict'
const main = arg => {
	const input = arg.trim().split("\n");
	let Ns = input[0].split(' ')
	function uniq(array) {
		let result = []
		result.push(array[0])
		for(let i = 1; i < array.length; i++) {
			if(result.indexOf(array[i]) >= 0) {
				continue
			}
			result.push(array[i])
		}
		return result
	}
	console.log(uniq(Ns).length)
}   
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21188
//by sdfzchy
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int inf=(1<<30),N=300010;
int n,m;
inline int in()
{
	char ch=getchar();
	int f=1,tmp=0;
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {tmp=(tmp<<1)+(tmp<<3)+(ch-'0');ch=getchar();}
	return tmp*f;
}
int cnt[N],k,ans;
int main()
{
	n=in(),k=in();
	for(int i=1;i<=n;i++) cnt[in()]++;
	sort(cnt+1,cnt+n+1);
	for(int i=n;i>=n-k+1;i--) ans+=cnt[i];
	printf("%d\n",n-ans);
	return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(Q: int, H: int, S: int, D: int, N: int):
    x = min(4*Q,2*H,S)
    y = D

    if x<=y/2:
        print(N*x)
    else:
        if N&1:
            print(N//2*y+x)
        else:
            print(N//2*y)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    Q = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(Q, H, S, D, N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;


string s;
int p,n;
int dp[300010],dp2[300010],pow10_inv[300010];
ll table[300010];

int power(int a,long long m){
    //cout << s << endl;
    if (m==0) return 1;
    if (m==1) return a%p;
    if (m%2==1) return power((a*a)%p,m/2)*a%p;
    else return power((a*a)%p,m/2);
}



void solve(){
    cin >> n >> p >> s;
    if(p==2){
        ll ans=0;
        rep(i,n){
            if((s[i]-'0')%2==0){
                ans+=i+1;
            }
        }
        cout << ans << endl;
        return;
    }
    if(p==5){
        ll ans=0;
        rep(i,n){
            if((s[i]-'0')%5==0){
                ans+=i+1;
            }
        }
        cout << ans << endl;
        return;
    }
    pow10_inv[0]=1;
    //cout << 1 << endl;
    pow10_inv[1]=power(10,p-2);
    //cout << pow10_inv[1] << endl;
    Rep(i,1,n){
        pow10_inv[i+1]=pow10_inv[i]*pow10_inv[1]%p;
    }
    //cout << pow10_inv[1] << endl;
    rep(i,n){
        dp[i+1]=(dp[i]*10+(s[i]-'0'))%p;
        dp2[i+1]=dp[i+1]*pow10_inv[i+1]%p;
    }
    ll ans=0;
    //cout << ans << endl;
    rep(i,n+1){
        //cout << dp2[i] << endl;
        ans+=table[dp2[i]];
        table[dp2[i]]+=1;
    }
    cout << ans << endl;
}

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

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

int main(){
  long long x; cin >> x;
  long long count;
  
  count = (x / 11) * 2;
  if(x%11 > 6){
    count += 2;
  }else if(x%11 != 0){
    count += 1;
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long int a,b,a1,b1,i=0;
    scanf("%lld%lld",&a,&b);
    for(i=0;i<=1000;i++)
    {
        a1=i*0.08;
        b1=i*0.1;
        if(a1==a && b1==b)
            break;
    }
    if(i!=1001)
    printf("%lld",i);
else
    printf("-1");
}



Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<iterator>

#define rep(i,n) for(int i = 0; i != n; i++)

using namespace std;

int main(){
	vector<int> count(30);
	string w; cin >> w;
	rep(i, w.size()){
		count[w[i] - 'a']++;
	}
	bool flag = true;
	rep(i,count.size()){
		if(count[i] % 2 == 1)
			flag = false;
	}
	if(flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;


int main() {
  long long n, k;

  scanf("%lli %lli", &n, &k);

  if (n >= k) {
    n = n % k;
  }

  printf("%lli", min(n, abs(n-k)));


  return 0;
}


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

using namespace std;

const int N = 100;

int a[1 + N], b[1 + N];

void go (int x, int i) {
    a[i] = min (a[i], x);
}

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        a[i] = 1e5 + 1;
    for (int i = 1; i < n; i++) {
        cin >> b[i];
        go (b[i], i);
        go (b[i], i + 1);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
       ans += a[i];
    cout << ans << "\n";
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int u = n % 10;
  if (u == 3) {
    cout << "bon" << '\n';
  } else if (u == 0 || u == 1 || u == 6 || u == 8) {
    cout << "pon\n";
  } else {
    cout << "hon\n";
  }
  return 0;
}

Measured memory_bytes: 3656
using System;

public class Test
{
	public static void Main()
	{
		bool isCon = true;
		while(isCon){
			string line = System.Console.ReadLine();
			string[] ab = line.Split(' ');
			if(ab[0] == "0" && ab[1]=="0"){
				isCon = false;
			}else{
				int a = int.Parse(ab[0]);
				int b = int.Parse(ab[1]);
				if ( a > b){
					int c;
					c = a;
					a = b;
					b = c;
				}
				Console.WriteLine("{0} {1}", a, b);
				
			}
		}
	}
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;

int main(){
    int n;
    cin>>n;
    Vi a(n);
    REP(i,n) cin>>a[i];


    int k=1;
    int cnt=0;
    REP(i,n){
        if(a[i] == k){
            k++;
            continue;
        }
        cnt++;
    }
    
    if(k!=1) cout<<cnt<<endl;
    else cout<<-1<<endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        int sum = 0;

        for(int i=1; i<=K; i++){
            for(int j=1; j<=K; j++){
                int a = i;
                int b = j;
                int kou = 0;
                for(int x=0; x<10; x++){
                    int max = Math.max(a, b);
                    int min = Math.min(a, b);
                    if(max%min==0 && x==0){
                        kou = min;
                        break;
                    }
                    a = min;
                    b = max % min;
                    if(a%b==0){
                        kou = b;
                        break;
                    }
                }
                for(int k=1; k<=K; k++){
                    int c = k;
                    int d = kou;
                    for(int x=0; x<10; x++){
                        int max = Math.max(c, d);
                        int min = Math.min(c, d);
                        if(max%min==0 && x==0){
                            d = min;
                            sum += d;
                            break;
                        }
                        c = min;
                        d = max % min;
                        if(c%d==0){
                            sum += d;
                            break;
                        }
                    }
                }
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 36404
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<queue>

using namespace std;

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

#define f first
#define s second

class S{
	public:
	int t;
	int v;
	S(int t,int v):t(t),v(v){}
	bool operator<(const S&a)const{
		return v>a.v;
	}
};

int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0)break;
		
		vector<pair<int,int> > load[111];
		
		rep(i,m){
			int a,b,c;
			cin>>a>>b>>c;
			
			load[a].push_back(make_pair(b,c));
			load[b].push_back(make_pair(a,c));
		}
		
		int visit[111]={0};
		
		priority_queue<S> que;
		
		
		visit[0]=1;
		rep(i,load[0].size()){
			pair<int,int> e = load[0][i];
			que.push(S(e.f, e.s));
		}
		
		int ans=0;
		
		while(1){
			if(que.empty())break;
			
			S u = que.top();
			que.pop();
			
			if(visit[u.t]==1)continue;
			visit[u.t]=1;
			
			ans+=u.v;
			
			
			rep(i,load[u.t].size()){
				pair<int,int> e=load[u.t][i];
				que.push(S(e.f,e.s));
			}
		}
		
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;

int main() {fio;
	int N;
	cin >> N;
	cout << 1000 * (N / 500) + (N % 500) - (N % 5);    return 0;
}

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

int main() {
  char a[51];
  cin >>a;
  int i=strlen(a);
  int j;
  for(j=0;j<i-8;j++) {
  cout << a[j];
  }
  cout << endl;
  return 0;
}     
    

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

int main() {
  int n; cin >> n;
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x; cin >> x;
    mp[x]++, mp[x - 1]++, mp[x + 1]++;
  }
  int ans = 0;
  for (auto p : mp) {
    ans = max (p.second, ans);
  }
  cout << ans;

}


Measured memory_bytes: 6856
# include <bits/stdc++.h>
using namespace std;
string s;
int main() {
	cin >> s;
	int len = s.size();
	int ans = 0;
	for(int i = 0; i < len; ++i)
		for(int j = i; j < len; ++j) {
			bool flag = false;
			for(int k = i; k <= j; ++k) {
				if(s[k] != 'A' && s[k] != 'C' && s[k] != 'G' && s[k] != 'T') break;
				if(k == j) flag = true;
			}
			if(flag) ans = max(ans, j - i + 1); 
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sx := getInt()
	sy := getInt()
	tx := getInt()
	ty := getInt()

	dx := tx - sx
	dy := ty - sy

	ans := ""
	ans += strings.Repeat("R", dx)
	ans += strings.Repeat("U", dy)
	ans += strings.Repeat("L", dx)
	ans += strings.Repeat("D", dy)

	ans += "D"
	ans += strings.Repeat("R", dx+1)
	ans += strings.Repeat("U", dy+1)
	ans += "L"

	ans += "U"
	ans += strings.Repeat("L", dx+1)
	ans += strings.Repeat("D", dy+1)
	ans += "R"

	fmt.Println(ans)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

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

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 768
N = int(input())
point_list = [{'t_0':0, 'x_0':0, 'y_0':0}]
cnt = 0

for i in range(1, N + 1):
    time, x, y = list(map(int, input().split()))
    point_dict = {}
    point_dict['t_{}'.format(i)] = time
    point_dict['x_{}'.format(i)] = x
    point_dict['y_{}'.format(i)] = y
    point_list.append(point_dict)

for i in range(N):
    time = point_list[i + 1]['t_{}'.format(i + 1)] - point_list[i]['t_{}'.format(i)]
    xdist = abs(point_list[i + 1]['x_{}'.format(i + 1)] - point_list[i]['x_{}'.format(i)])
    ydist = abs(point_list[i + 1]['y_{}'.format(i + 1)] - point_list[i]['y_{}'.format(i)])
    if time >= xdist + ydist and time % 2 == (xdist + ydist) % 2:
        continue
    else:
        print('No')
        cnt += 1
        break

if cnt == 0:
    print('Yes')


Measured memory_bytes: 56620
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;


int main() {
    string S;
    cin >> S;

    int a = stoi(S.substr(0, 2));
    int b = stoi(S.substr(2, 2));

    int am = 1 <= a && a <= 12;
    int bm = 1 <= b && b <= 12;

    if (am && bm)
        cout << "AMBIGUOUS" << endl;
    else if (am)
        cout << "MMYY" << endl;
    else if (bm)
        cout << "YYMM" << endl;
    else
        cout << "NA" << endl;

    return 0;
}


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

#define int long long

int n;
vector<int> a;

signed main() {
   // 入力
   cin >> n;
   a.resize(n);
   for (int i = 0; i < n; i++) {
      cin >> a[i];
   }
   sort(a.begin(), a.end());

   int Max = a.back(); // nCrのnにあたる数
   a.pop_back(); // この値は今後使えないので消しておく

   // p, qはパスカルの三角形におけるMaxの中央の値
   int p = Max / 2, q = Max / 2+1;
   if (Max&1) {
      p++;
   }

   int r = 0, dif = 1e10;
   for (int i = 0; i < a.size(); i++) {
      int t = min(abs(p - a[i]), abs(q - a[i]));
      if (t < dif) {
         r = a[i];
         dif = t;
      }
   }

   // nCrを出力
   printf("%lld %lld\n", Max, r);


   return 0;
}

Measured memory_bytes: 1024
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
#include<string.h>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int from,to,cost;};
vector<edge> G;
vector<int> O[10];
P sg[10];
int d[1005];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int fi[1005][1005];
int ans[1005][1005]={};
bool graph[55][55];
bool visited[55];
int a[55],b[55];
int n,m;
int dp[41][405][405];
bool is_prime(int n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    
    if(n%2 == 0) return false;
    if(n%3 == 0) return false;
    // 2と3の倍数でないので6の倍数ではないことが保証された
    
    if(n%6 != 1 && n%6 != 5) return false;
    // 6の倍数前後の数(素数かもしれない数)であることが保証された
    
    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i=5;i*i<=n;i+=6){
        if(n%i     == 0) return false; // 6n-1
        if(n%(i+2) == 0) return false; // 6n+1
    }
    
    return true;
}

signed main(){
    int q;cin>>q;
    int jud[100005]={};jud[3]=1;
    bool key[100005]={};
    key[2]=true;
    for(int i=1;i<=99999;i+=2){
        if(is_prime(i))key[i]=true;
        else key[i]=false;
    }
    for(int i=5;i<=99999;i+=2){
        if(key[i]&&key[(i+1)/2]){
           jud[i]=jud[i-2]+1;
        }else jud[i]=jud[i-2];
    }
    rep(i,q){
        int l,r;cin>>l>>r;
        int ans=jud[r]-jud[l-2];
        cout<<ans<<endl;
    }
    return 0;
}


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

void swap(int *a, int *b){
  int temp;
  temp = *b;
  *b = *a;
  *a = temp;
}

int main(){

  int X, Y, Z;

  cin >> X >> Y >> Z ;

  swap(&X, &Y);
  swap(&X, &Z);

  printf("%d %d %d\n", X, Y, Z);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int count;
  bool owata=false;
  for(int i=0;i<S.size()-1;i++){
    if(S.at(i)==S.at(i+1)){
      cout << i+1 << " " << i+2 << endl;
      owata=true;
      break;
    }
  }
  if(!owata)
  for(int j=0;j<S.size()-2;j++){
    if(S.at(j)==S.at(j+2)){
      cout << j+1 << " " << j+3 << endl;
      owata=true;
      break;
    }
  }
  if(!owata)
    cout << -1<<" "<<-1<<endl;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>   //取り敢えず書く
using namespace std;      //取り敢えず書く
int main(){               //取り敢えず書く
  int a,b,c;
  cin>>a>>b>>c;
  if(a<b && b<c){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
const int inf = 1001001001;

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

  int ans = 0;
  bool flg = true;
  while (flg) {
    flg = false;
    for (int i=n-1; i>0; i--) {
      if (a[i] < a[i-1]) {
        swap(a[i], a[i-1]);
        flg = true;
        ans++;
      }
    }
  }
  rep(i, n) {
    if (i==0) cout << a[i];
    else cout << " " << a[i];
  }
  cout << endl;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    ll n, d;
    cin >> n >> d;

    vector<ll> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    int c = 0;
    rep (i, n) {
        if (x[i] * x[i] + y[i] * y[i] <= d * d) {
c++;
        }
    }
    
    println(c)

    return 0;
}

Measured memory_bytes: 6392
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int n, m, x;
	cin >> n >> m >> x;
	int a;
	int cnt = 0;
	rep(i, m) {
		cin >> a;
		if (a < x) {
			cnt++;
		}
	}
	if (cnt < m / 2) {
		cout << cnt << endl;
	}
	else {
		cout << m - cnt << endl;
	}
	return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int k,a,b;
cin>>k>>a>>b;
ll ans=1;
if(a+1>=b){
    ans+=k;
}
else{
    int money=0;
    rep(i,k){
        if(ans<a){
            ans++;
        }
        else{
            if(money>0){
                ans+=b-a;
                money--;
            }
            else if(money==0 && i<k-1){
                money++;
            }
            else{
                ans++;
            }
        }
    }
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------
struct unionfind{
    vector<int> rank,parent,size;
    unionfind(int n){
        for(int i=0;i<n;i++){
            rank.push_back(1);//树的高度
            parent.push_back(i);//根
            size.push_back(1);//树大小
        }
    }
    int getroot(int x){
        if(parent[x]==x)
            return x;
        return parent[x]=getroot(parent[x]);//押平路径加速以后的查找
    }
    bool issame(int a,int b){
        return getroot(a)==getroot(b);
    }
    void unite(int a,int b){
        a=getroot(a);
        b=getroot(b);
        if(a==b)
            return;
        else if(rank[a]>rank[b]){ //合并到高的树下
            parent[b]=a;
            size[a]+=size[b];
        }
        else if(rank[a]==rank[b]){
            parent[b]=a;
            rank[a]++;
            size[a]+=size[b];
        }
        else{
            parent[a]=b;
            size[b]+=size[a];
        }
    }
};
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,q;cin>>n>>q;
    unionfind uf(n);
    while(q--){
        int c,x,y;
        cin>>c>>x>>y;
        if(c==0){
            uf.unite(x, y);
        }
        else{
            cout<<uf.issame(x, y)<<endl;
        }
    }
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------



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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


auto solve() {
    int n;
    cin >> n;
    vi A(n), B(n);
    for (auto &&e: A) cin >> e;
    for (auto &&e: B) cin >> e;

    ll sumA = accumulate(all(A), 0ll);
    ll sumB = accumulate(all(B), 0ll);

    if (sumA < sumB) return -1;

    vi T(n);
    REP(i, n) {
        T[i] = A[i] - B[i];
    }
    sort(all(T));

    ll lack_v = 0, lack_num = 0;
    vi over;
    for (auto &&e: T) {
        if (e < 0) {
            lack_v += abs(e);
            lack_num++;
        }
        if (e > 0) {
            over.push_back(e);
        }
    }

    if (lack_num == 0) return 0;

    ll over_v = 0;
    int over_use = 0;

    reverse(all(over));
    for (auto &&e: over) {
        over_use++;
        over_v += e;
        if (over_v >= lack_v) break;
    }

    return (int)(lack_num + over_use);
}


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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <unordered_map>

using namespace std;

const int N = 200005;

int n;
int arr[N];

bool ok(int x) {
  map <int, int> cnt;
  for (int i = 1; i < n; i++) {
    if (arr[i] <= arr[i - 1]) {
      int ce = arr[i];
      while (!cnt.empty() && (--cnt.end())->first > ce) {
        cnt.erase(--cnt.end());
      }
      cnt[ce]++;
      while (cnt[ce] >= x) {
        cnt.erase(ce--);
        cnt[ce]++;
        if (ce == 0) return 0;
      }
    }
  }
  return 1;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  bool ww = 1;
  for (int i = 1; i < n; i++) {
    if (arr[i] <= arr[i - 1]) {
      ww = 0;
    }
  }
  if (ww) {
    cout << 1 << endl;
    return 0;
  }
  int l = 2, r = 1e9, ans;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (ok(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024