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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

int main(int argc, char const* argv[])
{
    string s1,s2;
    cin >> s1 >> s2;
    if (s1.length() == s2.length()) {
        if (s1 > s2) {
            cout << "GREATER" << endl;
        }else if (s1 == s2){
            cout << "EQUAL" << endl;
        }else{
            cout << "LESS" << endl;
        }
    }else if (s1.length() > s2.length()){
        cout << "GREATER" << endl;
    }else{
        cout << "LESS" << endl;
    }


    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


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

int main(int argc, char **argv)
{
	int f=0, i, l, a, b;
	char g[100];
	
	while(scanf("%s", g)!=EOF){
		if(g[0] == '0'){
			if(a < b){
				b++;
			} else {
				a++;
			}
			printf("%d %d\n", a, b);
			break;
		} else if(f == 3){
			f = 0;
			if(a > b){
				a++;
			} else {
				b++;
			}
			printf("%d %d\n", a, b);
		} else if(f > 0 && f < 3){
			if(g[0] == 'A'){
				a++;
			} else {
				b++;
			}
			printf("%d %d\n", a, b);
		}
		l = strlen(g);
		a = b = 0;
		for(i = 1; i < l; i++){
			if(g[i] == 'A'){
				a++;
			} else {
				b++;
			}
		}
		
		f++;
	}
	
	return 0;
}

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

int main() {

	int N,score = 0,result = 0;

	cin >> N;
	int A[2][110];

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

	

	for (int c = 0; c < N; c++) {
		int i = 0, j = 0;
		score = 0;
		for (j = 0; j <= c; j++) {
			score += A[i][j];
		}
		i++;
		for (j = c; j < N; j++) {
			score += A[i][j];
		}
		if (score > result) result = score;
	}

	cout << result;

	return 0;
}

//made by myself

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

const int MAX_N = 100000;
int N;
int A, B, C;
int H[MAX_N];

bool f(int x) {
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int remain = H[i] - x * B;
        if (remain > 0) {
            if (C == 0) return false;
            cnt += ceil(1.0 * remain / C);
        }
    }

    return cnt <= x;
}

signed main() {
    cin >> N >> A >> B;
    C = A - B;
    for (int i = 0; i < N; i++) cin >> H[i];

    int lb = 0;
    int ub = 10000000000;
    while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if (f(mid)) {
            ub = mid;
        } else {
            lb = mid;
        }
    }

    cout << ub << endl;

    return 0;
}

Measured memory_bytes: 1024
<?php
function calc($p1, $p2, $c) {
  switch($c) {
    case "+":
      return $p1 + $p2;
      break;
    case "-":
      return $p1 - $p2;
      break;
    case "*":
      return $p1 * $p2;
      break;
  }
  return 0;
}

function RPN($A) {
  $arr = array();
  while($v = array_shift($A)) {
    if (ctype_digit($v)) {
      $arr[] = intval($v);
    } else {
      if (count($arr) >= 2) {
        $p2 = array_pop($arr);
        $v = calc(array_pop($arr), $p2, $v);
        $arr[] = $v;
      }
    }
  }
  return $arr[0];
}

$A = explode(' ', trim(fgets(STDIN)));
echo(RPN($A));

?>



Measured memory_bytes: 9316
! 2019.10.27
!
      program answer
      implicit none
      integer(16) :: N
      integer(16) :: ans
      real :: ru_N
      integer(16) :: S
      integer(16) :: T
      intrinsic dble,sqrt,mod
      read(*,*) N
!
      ru_N = sqrt(dble(N))
      S = ru_N+1
      do
        if(mod(N,S) == 0) then
          T=N/S
          exit
        end if
        S = S-1
      end do
!
      write(*,*) T+S-2
      end program answer


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n, k, x, y;
	cin >> n >> k >> x >> y;

	if (n > k) {
		cout << k * x + (n - k) * y << endl;
	}
	else {
		cout << n * x << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=10000020;
int bufpos;
char buf[MAXSIZE];
#define NEG 0
void init(){
    #ifdef LOCAL
        freopen("A.txt","r",stdin);
    #endif
    buf[fread(buf,1,MAXSIZE,stdin)]='\0';
    bufpos=0;
}
#if NEG
int readint(){
    bool isneg;
    int val=0;
    for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
    bufpos+=(isneg=buf[bufpos]=='-');
    for(;isdigit(buf[bufpos]);bufpos++)
        val=val*10+buf[bufpos]-'0';
    return isneg?-val:val;
}
#else
int readint(){
    int val=0;
    for(;!isdigit(buf[bufpos]);bufpos++);
    for(;isdigit(buf[bufpos]);bufpos++)
        val=val*10+buf[bufpos]-'0';
    return val;
}
#endif
char readchar(){
    for(;isspace(buf[bufpos]);bufpos++);
    return buf[bufpos++];
}
int readstr(char* s){
    int cur=0;
    for(;isspace(buf[bufpos]);bufpos++);
    for(;!isspace(buf[bufpos]);bufpos++)
        s[cur++]=buf[bufpos];
    s[cur]='\0';
    return cur;
}
int main(){
    init();
    int n=readint(),a=readint(),b=readint();
    puts((a^b)%2?"Borys":"Alice");
}

Measured memory_bytes: 256
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//1:数値へ変換 2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字に分割 7:1文字に分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
  var one = myconv(next(),4);
  var N = one[0];
  var M = one[1];
  var list = new Array(N);
  for(var i = 0; i < N; i++){
    list[i] = {
    	"child" : [],
        "visit" : false
    };
  }
  for(var i = 0; i < M; i++){
    var tmp = myconv(next(),4);
    list[tmp[0]-1].child.push(tmp[1]-1);
    list[tmp[1]-1].child.push(tmp[0]-1);
  }
  var count = 0;
  
  for(var i = 0; i < N; i++){
    if(!list[i]["visit"]){
      count++;
      var queue = [list[i]];
      while(queue.length > 0){
        var tmpQueue = queue.shift();
        tmpQueue["visit"] = true;
        var children = tmpQueue["child"];
        for(var j = 0; j < children.length; j++){
          if(list[children[j]]["visit"]){continue;}
           queue.push(list[children[j]]);
        }
      }
    }
  }
  /*function dfs(parent){
    list[parent]["visit"] = true;
    var children = list[parent]["child"];
    //myout(parent +" : "+children);
    for(var i = 0; i < children.length; i++){
      if(list[children[i]]["visit"]){continue;}
      if(children[i] == parent){continue;}
      dfs(children[i]);
    }
  }*/
  
  myout(count);
}

Measured memory_bytes: 66700
#include <iostream>
#include <string>
#include <vector>

#define cal(i, n) for(int i = 0 ; i < n ; i++)
#define find(i, p, n) for(int i = p ; i <= n; i++)

using namespace std;

int main(){
    int H, W;
    vector<string> S(50);
    cin >> H >> W;
    cal(i, H) cin >> S[i];
    cal(i, H){
        cal(j, W){
            if(S[i].substr(j,1) != "#"){
                int count = 0;
                int imin = i - 1; int imax = i + 1;
                int jmin = j - 1; int jmax = j + 1;
                if(imin < 0){
                    imin = 0;
                }
                if(jmin < 0){
                    jmin = 0;
                }
                if(imax >= H){
                    imax = H - 1;
                }
                if(jmax >= W){
                    jmax = W - 1;
                }
                find(k, imin, imax) find(l, jmin, jmax) if(S[k].substr(l,1) == "#")count++;
                S[i].replace(j, 1, to_string(count));
            }
        }
    }
    cal(i, H) cout << S[i] << endl;
    
    return 0;
}


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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int n,l;
int data[200000];


int solve(int num){
	if( data[num-1]<data[num] && data[num+1]<data[num] )return l-data[num];
	if( data[num-1]<data[num] && num==n-1 )	return l-data[num];
	if( data[num+1]<data[num] && num==0	)	return l-data[num];

	int left=0,right=0;
	if( data[num-1]>data[num] )left = solve(num-1);
	if( data[num+1]>data[num] )right= solve(num+1);

	return l-data[num] + max(left,right);
}


int main(){
    cin>>n>>l;
    rep(i,n) cin>>data[i];
    
    int ans = 0;
    rep(i,n){
        ans = max(ans,solve(i));
    }
    cout<<ans<<endl;
}

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

class Main{

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

        int n = Integer.parseInt(scan.nextLine());
        String[] inputStr = scan.nextLine().split(" ");
        int inputLen = inputStr.length;
        int[] inputInt = new int[inputLen];

        for (int i=0; i<inputLen; i++){
            inputInt[i] = Integer.parseInt(inputStr[i]);
        }

        int tmp;
        int numExchange = 0;
        int minj;
        for (int i=0; i<inputLen-1; i++){
            minj = i;
            for (int j=i+1; j<inputLen; j++){
                if (inputInt[minj] > inputInt[j]){
                    minj = j;
                }
            }
            tmp = inputInt[i];
            inputInt[i] = inputInt[minj];
            inputInt[minj] = tmp;
            if (i != minj)
                numExchange += 1;
        }
        for (int i=0; i<inputLen; i++){
            inputStr[i] = String.valueOf(inputInt[i]);
        }
        System.out.println(String.join(" ", inputStr));
        System.out.println(numExchange);
    }
}

Measured memory_bytes: 26132
// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;
 
#define int long long
#define F first
#define S second
#define sz(x) ((int)x.size())
#define rep(i,a,n) for (int i = a; i <= n; ++i)
#define all(v)  v.begin(), v.end()
#define pb push_back
#define P pair < int, int >
#define E cout << '\n'

const int mod = 1e9 + 7;
const int N = 4e5 + 5;

vector < int > v[N>>1];
int idx[N>>1], cnt, dp[N>>1], pre[N>>1];

void dfs(int node, int p) {
  idx[node] = ++cnt;
  dp[node] = 1;
  for (auto i : v[node]) {
    if (i - p) {
      dfs(i, node);
      dp[node] += dp[i];
    }
  }
}

inline void solve() {
   int numberOfNodes, v1, v2, queries;
   cin >> numberOfNodes >> queries;
   rep(i,2,numberOfNodes) {
    cin >> v1 >> v2;
    v[v1].pb(v2);
    v[v2].pb(v1);
   }
   dfs(1, 1);
   while (queries--) {
    cin >> v1 >> v2;
    pre[idx[v1]] += v2;
    pre[idx[v1]+dp[v1]] -= v2;
   }
   rep(i,1,numberOfNodes)
    pre[i] += pre[i-1];
   rep(i,1,numberOfNodes) {
    cout << pre[idx[i]] << ' ';
   }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  //cin >> t; while(t--)
  solve();
  return 0;
}

Measured memory_bytes: 27392
#include<stdio.h>

int main() {
  int H, W ,i ,j;
  char a[105][105];

  scanf("%d %d", &H, &W);
  for (i = 0; i < H; i++) {
	scanf("%s", a[i]);
  }
  for (i = 0; i < W + 2; i++) {
	printf("#");
  }
  printf("\n");
  for (i = 0; i < H;i++) {
	printf("#%s#\n", a[i]);
  }
  for (i = 0; i < W + 2; i++) {
	printf("#");
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

int x;

int main(){

	cin >> x;

	if (x == 7 || x == 5 || x == 3){
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

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

vector<pair<int, int>>a, b;
int w, h;
int c[1000][1000];

int main() {
	int n = 0;
	cin >> h >> w;
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			cin >> c[i][j];
		}
	}
	for (int i = 0;i < h;i++) {
		for (int j = 0;j + 1 < w;j++) {
			if (c[i][j] % 2 == 1) {
				c[i][j]--;
				c[i][j + 1]++;
				n++;
				pair<int, int>p = make_pair(i, j);
				pair<int, int>q = make_pair(i, j + 1);
				a.push_back(p);
				b.push_back(q);
			}
		}
	}
	for (int i = 0;i < h;i++) {
		if (c[i][w - 1] % 2 == 1 && i + 1<h) {
			c[i][w - 1]--;
			c[i + 1][w - 1]++;
			n++;
			pair<int, int>p = make_pair(i, w - 1);
			pair<int, int>q = make_pair(i + 1, w - 1);
			a.push_back(p);
			b.push_back(q);
		}
	}
	cout << n << endl;
	for (int i = 0;i < n;i++) {
		cout << a[i].first + 1 << " " << a[i].second + 1 << " " << b[i].first + 1 << " " << b[i].second + 1 << endl;
	}
}

Measured memory_bytes: 6252
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b,x,y;
  cin >> n >> a >> b;
  if(abs(a-b)%2==0) {
    cout << abs(a-b)/2 << endl;
  }
  else {
    if(abs(a-b)==1) {
      cout << min(max(a-1,b-1),max(n-a,n-b)) << endl;
    }
    else {
      x=min({a-1,b-1,n-a,n-b});
      x+=1+(abs(b-a)-1)/2;
      cout << x << endl;
    }
  }
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() 
{
	int a;
	int b;
	cin >> a;
	cin >> b;
	cout << a*b << " " << 2*a+2*b << endl;
}


Measured memory_bytes: 3076
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/


struct graph {
	int n;
	vector<pair<int, int>> ed0;
	vector<pair<int, int>> ed1;
	vector<int> eds2[55];
	vector<int> eds1[55];
	vector<int> eds[55];
	int en[55];
	int cc[55];
	int en2[55];
	void dfs1(int v) {
		en[v] = 1;
		for (int u: eds[v])
			if (!en[u])
				dfs1(u);
	}
	int get(int x) {
		set<pair<int, int>> ss;
		fill(cc, cc + n, 0);
		for (int i = 0; i < ed0.size(); ++i) {
			if (ed0[i].first > ed0[i].second)
				swap(ed0[i].first, ed0[i].second);
			ss.insert(ed0[i]);
			int a = ed0[i].first;
			int b = ed0[i].second;
			++cc[a], ++cc[b];
			eds1[a].push_back(b);
			eds1[b].push_back(a);
		}
		for (int i = 0; i < ed0.size(); ++i) {
			if (ed1[i].first > ed1[i].second)
				swap(ed1[i].first, ed1[i].second);
			if (ss.count(ed1[i])) {
				int a = ed1[i].first;
				int b = ed1[i].second;
				eds[a].push_back(b);
				eds[b].push_back(a);
			}
			int a = ed1[i].first;
			int b = ed1[i].second;
			eds2[a].push_back(b);
			eds2[b].push_back(a);
		}
		fill(en, en + n, 0);
		fill(en2, en2 + n, 0);
		dfs1(x);
		int lf = n;
		for (int i = 0; i < n; ++i) {
			lf -= en[i];
			if (en[i]) {
				for (int u: eds2[i])
					en2[u] = 1;
			}
		}
		int ans = 0;
		while (lf) {
			int fl = 0;
			for (int i = 0; i < n; ++i)
				if (cc[i] == 1 && !en[i] && en2[i]) {
					--lf;
					++ans;
					en[i] = 1;
					fl = 1;
					for (int u: eds2[i])
						en2[u] = 1;
					for (int u: eds1[i])
						if (!en[u])
							--cc[u];
				}
			if (!fl)
				return n + 1;
		}
		return ans;
	}
};
int cc0[100], cc1[100];


void solve() {
	graph now;
	int n;
	cin >> n;
	now.n = n;
	for (int i = 0; i < n; ++i)
		cc0[i] = cc1[i] = 0;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		++cc0[a];
		++cc0[b];
		now.ed0.emplace_back(a, b);
	}
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		++cc1[a], ++cc1[b];
		now.ed1.emplace_back(a, b);
	}
	int ans = n + 1;
	for (int i = 0; i < n; ++i) {
		graph tmp = now;
		ans = min(ans, tmp.get(i));
		if (cc0[i] == 1) {
			int k = 0;
			while (now.ed0[k].first != i && now.ed0[k].second != i)
				++k;
			for (int j = 0; j < n; ++j) 
				if (j != i) {
					tmp = now;
					tmp.ed0[k] = {i, j};
					ans = min(ans, tmp.get(i) + 1);
				}
		}
	}
	if (ans == n + 1)
		cout << -1 << "\n";
	else
		cout << ans << "\n";
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	int tt;
	cin >> tt;
	for (int i = 0; i < tt; ++i)
		solve();
	return 0;
}




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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int k;
    cin >> k;

    for (char &c: s) {
        if (c == 'a') {
            continue;
        } else if ('z' - c + 1 <= k) {
            k -= ('z' - c + 1);
            c = 'a';
        }
    }
    s.back() = char('a' + (s.back() - 'a' + k) % 26);
    cout << s << endl;
    return 0;
}

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


int main()
{
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    //累積和つくる
    int a[s.length()+1],sum[s.length()+1];
    a[0]=0;
    for(int i=0;i<s.length();i++){
        if(i==0)a[i]=0;
        else if(s[i-1]=='A' && s[i]=='C'){
            a[i]=1;
        }else{
            a[i]=0;
        }
    }
    sum[0]=0;
    for(int i=0;i<s.length();i++){
        sum[i+1]=sum[i]+a[i];
    }



    for(int i=0;i<q;i++){
        int start,end;
        cin >> start >> end;

        cout << sum[end]-sum[start] << endl;
    }
    
    return 0;
}






Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	string s;
	cin>>n>>s;
	int t=n;
	for(int i=0;i<n-1;i++)
	{
		if(s[i]==s[i+1])t--;
	}
	cout<<t;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
  int a, b;
  scanf("%d %d", &a, &b);

  if(a < b){
    printf("a < b\n");
  } else if(a == b){
    printf("a == b\n");
  }else{
    printf("a > b\n");
  }
  return 0;
}


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

using namespace std;

const int MAX_N = 2e5 + 10;

typedef long long ll;

int N, P[MAX_N], V[MAX_N];
ll ans;

struct DSU {
    int pa[MAX_N];

    void init(int n) { for (int i = 1; i <= n; i++) pa[i] = i; }

    int query(int x) { return pa[x] == x ? x : pa[x] = query(pa[x]); }

    void merge(int a, int b) {
        a = query(a); b = query(b);
        pa[a] = b;
    }
} dsu;

struct Group {
    ll c0, c1;
    int id;
    Group() {}
    Group(ll c0, ll c1, int id) : c0(c0), c1(c1), id(id) {}
    bool operator<(const Group &rhs) const {
        ll t = c1 * rhs.c0 - rhs.c1 * c0;
        if (t != 0) return t < 0;
        return id < rhs.id;
    }
} groups[MAX_N];

int main() {
    scanf("%d", &N);
    for (int i = 2; i <= N; i++) scanf("%d", &P[i]);
    for (int i = 1; i <= N; i++) scanf("%d", &V[i]);
    dsu.init(N);
    for (int i = 1; i <= N; i++) {
        groups[i] = Group(V[i] == 0, V[i] == 1, i);
    }
    set<Group> st;
    for (int i = 2; i <= N; i++) {
        st.insert(groups[i]);
    }
    for (int i = 1; i < N; i++) {
        Group x = *st.begin(), y = groups[dsu.query(P[x.id])];
        st.erase(x);
        if (y.id != 1) {
            st.erase(y);
        }
        ans += y.c1 * x.c0;
        groups[y.id] = Group(x.c0 + y.c0, x.c1 + y.c1, y.id);
        dsu.merge(x.id, y.id);
        if (y.id != 1) {
            st.insert(groups[y.id]);
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 19840
#include<iostream>
#include<cstring>
char s[100];

int fun(int a,int b)
{
    int i;
    for(i=0;i<=b-a;i++)
    {
        if(s[a+i]!=s[b-i])
        {
            break;
        }
    }
    if(i==b-a+1)
        return 0;
    else
        return 1;
}

int main()
{
    long n;
    int flag=0;
    scanf("%s",s);
    n=strlen(s);
    
    if(n%2==0)
    {
        flag=1;
    }
    else
    {
        flag=fun(0,(int)n-1);
        if(flag==0)
        {
            flag=fun(0,(int)((n-1)/2)-1);
        }
    }
    if(flag==0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=300005;
int t[MAXN],n,L,x[MAXN],MID;
int main()
{
	n=read();L=read();
	for(int i=1;i<=n;i++)x[i]=read(),x[i]<=L-x[i]?MID=i:MID=MID;
	int ans=0,cnt=0;
	for(int i=1;i<=n;i++)
	{
		t[i]=read();
		cnt+=(t[i]/(2*L));t[i]%=(2*L);
		if(t[i]>2*max(x[i],L-x[i]))t[i]=0,++cnt;
	}bool fl=false,fm=false,fr=false;
	int l=0,m=0,r=0;
	for(int i=MID;i>=1;i--)if(t[i])
	{
		if(t[i]<=2*min(x[i],L-x[i]))//1
		{
			if(!l)++m;
			else --l,++cnt,fl|=(l==0);
		}else ++l;
	}
	for(int i=MID+1;i<=n;i++)if(t[i])
	{
		if(t[i]<=2*min(x[i],L-x[i]))//1
		{
			if(!r)++m,fr=false;
			else --r,++cnt,fr=true;
		}else ++r;
	}
	fm=(m>=2);cnt+=(m/2);m%=2;
	if(r)ans=l+m+r+1;
	else
	{
		ans=l+m+r;
		if(!t[n]||fr)++ans;
		else if(!m&&(fl||fm))++ans;
	}pr2(2LL*(ans+cnt)*L);
	return 0;
}


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

int main(){
    int n, ans = 0;
    cin >> n;
    int dig;
    while(n > 0){
        dig = n % 10;
        ans += dig;
        n /= 10;
    }
    if(ans == 1){
        ans = 10;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;


int main(){
    int a,b;cin >> a >> b;
    int ans;
    if(a != 1 && b != 1) ans = 1;
    else if(a != 2 && b != 2) ans = 2;
    else ans = 3;

    cout << ans;
}


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

int f( char x ){
	switch (x){
		case '0' : return 0 ;
		case '1' : return 1 ;
		case '2' : return 2 ;
		case '3' : return 3 ;
		case '4' : return 4 ;
		case '5' : return 5 ;
		case '6' : return 6 ;
		case '7' : return 7 ;
		case '8' : return 8 ;
		case '9' : return 9 ;
	}
}

int main(){
	
	int n ;
	for( cin >> n ; n-- ; ){
		string a,b ;
		cin >> a >> b ;
		if( a.size() > b.size() ) swap(a,b) ;
		reverse( a.begin() , a.end() ) ;
		reverse( b.begin() , b.end() ) ;
		while( a.size() < b.size() ) a+='0' ;
		
		vector<int> c ;
		c.push_back(0) ;
		for( int i=0 ; i<a.size() ; i++ ){
			c[i] += f(a[i]) + f(b[i]) ;
			c.push_back( c[i]/10 ) ;
			c[i] %= 10 ;
		}
		if( c[c.size()-1] == 0 ) c.pop_back() ;
		//for( int i=c.size()-1 ; c[i]!=0 ; i-- ) c.pop_back() ;
		reverse( c.begin() , c.end() ) ;
		
		if( c.size() >= 81 ) cout << "overflow" << endl ;
		else {
			for( int i=0 ; i<c.size() ; i++ ) cout << c[i] ;
			cout << endl ;
		}
	}
	
return 0 ;
}

Measured memory_bytes: 1240
import bisect
a,b,q=map(int,input().split())
s=[int(input()) for i in range(a)]
t=[int(input()) for i in range(b)]
s.sort()
t.sort()
for _ in range(q):
  x=int(input())
  idx1=bisect.bisect_left(s,x)
  idx2=bisect.bisect_left(t,x)
  d=[]
  if idx1<a and idx2<b:
    d.append(max(s[idx1]-x,t[idx2]-x))
  if 1<=idx1 and 1<=idx2:
    d.append(max(x-s[idx1-1],x-t[idx2-1]))
  if 1<=idx1 and idx2<b:
    d.append((t[idx2]-x)*2+x-s[idx1-1])
    d.append((x-s[idx1-1])*2+t[idx2]-x)
  if idx1<a and 1<=idx2:
    d.append((s[idx1]-x)*2+x-t[idx2-1])
    d.append((x-t[idx2-1])*2+s[idx1]-x)
  print(min(d))

Measured memory_bytes: 12092
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(n) n.begin(),n.end()
struct P{
	int x,y;
	P(int a,int b){x=a,y=b;}
};

int compress(vector<int> &org,int length,vector<int> &one,vector<int> &two){
	sort(all(org));
	org.erase(unique(all(org)),org.end());
	int cur = 0;
	for(int i=(org[0]==0?1:0);i<org.size();i++){ //org[0]ª0¾Á½çíé(»êÍ±Üé)B
		if(org[i] == cur+1) cur += 1; //×ÚµÄ½ç1Â¾¯¸ç·B
		else cur += 2;	//×ÚµÄÈ¢ñ¾Á½ç2Â(1ÂÔªó­æ¤Éæéæ)
		rep(j,one.size()){
			if(one[j] == org[i]) one[j] = cur;
			if(two[j] == org[i]) two[j] = cur;
		}
	}
	return cur + (org.back()!=length); // org.back() !- length¾Á½êóÔÉÜ¾]Tª éÌÅTCYÍlength = cur+1Æ·éB
}

bool board[3000][3000];
void dfs(bool Map[3000][3000],P start,int W,int H){
	static const int dx[] = {0,0,-1,1} , dy[] = {1,-1,0,0};
	
	stack<P> S;
	S.push(start);
	while(S.size()){
		P s = S.top(); S.pop();
		rep(i,4){
			P t = P(s.x+dx[i],s.y+dy[i]);
			if(t.y >= 0 && t.x >= 0 && t.y < H && t.x < W && Map[t.y][t.x] == 0){
				Map[t.y][t.x] = true;
				S.push(t);
			}
		}
	}
}


int main(){
	int W,H;
	while(cin >> W >> H , W){
		vector<int> ox,oy,sx,ex,sy,ey;
		int n; cin >> n;
		rep(i,n){
			int x1,y1,x2,y2;
			cin >> x1 >> y1 >> x2 >> y2;			
			sx.push_back(x1),sy.push_back(y1); //s? = ¶º (ÀW³k³êéû1)
			ex.push_back(x2),ey.push_back(y2); //e? = Eã (ÀW³k³êéû2)
			
			ox.push_back(x1),oy.push_back(y1); //o? = s?àe?àÇÁ¿àÂÁ±ÞB(ÀW³kÌÚóÉg¤)
			ox.push_back(x2),oy.push_back(y2); //
		}
		// ³k compress(...)ÌÔèlÍ³kãÌÕÊTCYB
		W = compress(ox,W,sx,ex);
		H = compress(oy,H,sy,ey);
		
		
		rep(i,H)rep(j,W)board[i][j] = false; // ú»
		
		//³kãÌ¶ºÆEãÀWðgÁÄÕÊðhèÂÔ·B
		rep(i,n){
			for(int x = sx[i] ; x < ex[i] ; x++){
				for(int y = sy[i] ; y < ey[i] ; y++){
					board[y][x] = true;
				}
			}
		}
		//hèÂÔµÈªç¦é´¶BÀÛÉhèÂÔ·ÌÍdfs()ÖB
		int ans = 0;
		rep(y,H){
			rep(x,W){
				if(board[y][x] == false){
					ans++;
					dfs(board,P(x,y),W,H);
				}
			}
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 5168
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    a, b = LI()

    def func(x):
        return (x, 1, x + 1, 0)[x % 4]

    return func(b) ^ func(a - 1)


print(main())


Measured memory_bytes: 3064
def amida():
    line_number=int(input())
    line=[]
    for j in range(1,line_number+1):
        line.append(j)
    yoko=int(input())
    for i in range(yoko):
        a,b=map(int,input().split(","))
        line[a-1],line[b-1]=line[b-1],line[a-1]
    return line
while True:
    try:
        ans=amida()
        for i in range(int(len(ans))):
            print(ans[i])
        break
    except:break



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

int main(){
    int a,b;
    char op;
    
    while(cin>>a>>op>>b && op!='?'){
        switch(op){
        case '+':
            cout<<a+b<<endl;
            break;
        case '-':
            cout<<a-b<<endl;
            break;
        case '*':
            cout<<a*b<<endl;
            break;
        case '/':
            cout<<a/b<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> G[maxn],order;
int n,known[maxn],val[maxn],l[maxn],r[maxn],k,used[maxn],known_parity[maxn][2],shit,par[maxn],ans[maxn];
void dfs(int v)
{
	used[v] = 1;
	l[v] = -1e9;
	r[v] = 1e9;
	for(int i = 0;i < G[v].size(); ++i)
	{
		int to = G[v][i];
		if(used[to]) continue;
		dfs(to);
		par[to] = v;
		if(known_parity[to][0]) known_parity[v][1] = 1;
		if(known_parity[to][1]) known_parity[v][0] = 1;
		l[v] = max(l[v],l[to] - 1);
		r[v] = min(r[v],r[to] + 1);
	}
	if(known[v] == 1)
	{
		l[v] = max(l[v],val[v]);
		r[v] = min(r[v],val[v]);
		known_parity[v][val[v] % 2] = 1;
	}
	if(known_parity[v][0] == 1 && known_parity[v][1] == 1) shit = 1;
	if(l[v] > r[v]) shit = 1;
	order.push_back(v);
}
int solve_val(int v,int par)
{
	if(par == 0) return l[v];
	l[v] = max(l[v],ans[par] - 1);
	r[v] = max(r[v],ans[par] + 1);
	while(l[v] % 2 == ans[par] % 2) ++l[v];
	return l[v];
}
int main(int argc, char const *argv[])
{
	cin>>n;
	for(int i = 0;i < n - 1; ++i)
	{
		int a,b;
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	cin>>k;
	for(int i = 1;i <= k; ++i)
	{
		int a,b;
		cin>>a>>b;
		known[a] = 1;
		val[a] = b;
	}
	dfs(1);
	if(shit)
	{
		cout<<"No\n";
		return 0;
	}
	reverse(order.begin(),order.end());
	printf("Yes\n");
	for(int i = 0;i < order.size(); ++i)
	{
		int v = order[i];
		ans[v] = solve_val(v,par[v]);
	}
	for(int i = 1;i <= n; ++i) cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 15096
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int num1,num2;
    int a[5],b[5];
    while(~scanf("%d",&a[1])){
          for(int i=2;i<=4;i++){
            scanf("%d",&a[i]);
          }
          for(int i=1;i<5;i++){
            scanf("%d",&b[i]);
          }
          num1=0;
          num2=0;
          for(int i=1;i<=4;i++){
            if(a[i]==b[i]) num1++;
            for(int j=0;j<=4;j++){
                if(i!=j){
                    if(a[i]==b[j]) num2++;
                }
            }
          }
          printf("%d %d\n",num1,num2);

    }
return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,K; cin >>A >>B >> K;
  if((B - A)/2 + 1> K){
  for(int i = A; i <A + K; i++)
    cout << i << endl;
  for(int i = B - K + 1; i <= B; i++)
    cout << i << endl;
  }
  
  else{
    for(int i = A; i <= B; i++)
      cout << i <<endl;
  }
  
}

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


int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int ans = 0;
  if (a >= k) {
    ans = ans + k;
  } else {
    ans = ans + a;
    if ((k - a - b) > 0) {
      ans = ans - (k - a - b);
    }
  }
  
  cout << ans;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	string S;
	cin>>S;
	S.replace(5,1," ");
	S.replace(13,1," ");
	cout<<S<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;
class AOJ
{
    static void Main()
    {
        char[] a = new char[100];
        string []b = new string [3];
        int j = 100;
        int i;
        for (i = 0; i < j; i++)
        {
            string c;
            c = Console.ReadLine();
            b = c.Split(' ');
            if (b[0] == "-1" && b[1] == "-1" && b[2] == "-1")
            {
                goto stop;
            }
            else if (b[0] == "-1" || b[1] == "-1")
            {
                a[i] = 'F';
                
            }
            else if ((int.Parse(b[0]) + int.Parse(b[1])) >= 80)
            {
                a[i] = 'A';
               
            }
            else if ((int.Parse(b[0]) + int.Parse(b[1])) >= 65&& (int.Parse(b[0]) + int.Parse(b[1])) < 80)
            {
                a[i] = 'B';
            }
            else if(((int.Parse(b[0]) + int.Parse(b[1]))>=50&& (int.Parse(b[0]) + int.Parse(b[1]))<65)|| ((((int.Parse(b[0]) + int.Parse(b[1]))>=30&&(int.Parse(b[0]) + int.Parse(b[1])) < 50 && int.Parse(b[2]) >= 50)))){
                a[i] = 'C';
               
            }
            else if((int.Parse(b[0]) + int.Parse(b[1])) >= 30 && (int.Parse(b[0]) + int.Parse(b[1])) < 50)
            {
                a[i] = 'D';
               
            }
            else if (int.Parse(b[0]) + int.Parse(b[1]) < 30)
            {
                a[i] = 'F';
            
            }
            
        }
        stop:;
        for(int k = 0; k < i; k++)
        {
            Console.WriteLine(a[k]);
        }
        
        Console.ReadKey();
        
    }
}

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int n,x,ans;
    for(;;){
        scanf("%d %d",&n,&x);
        ans=0;
        if(n==0) break;
        for(int i=1;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                for(int k=j+1;k<=n;k++){
                    if(i+j+k==x){
                        ans++;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1172
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <set>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	ll h, w, yan[15][15], a[210][210], ans = 0;
	cin >> h >> w;
	for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) cin >> yan[i][j];
	for (int k = 0; k < 10; k++) for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) yan[i][j] = min(yan[i][j], yan[i][k] + yan[k][j]);
	for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) {
		cin >> a[i][j];
		if (a[i][j] > 1 || a[i][j] == 0) ans += yan[a[i][j]][1];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
aa = []

for i in range(n):
    a = ni()
    aa.append(a)

bb = sorted(aa)
o = bb[-1]
p = bb[-2]

for i in range(n):
    k = p if aa[i] == o else o
    print(k)

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

int main()
{
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    int ai = a[n-1]; a.erase(a.end() - 1);
    double mid = 1.*ai / 2;
    int aj1 = *lower_bound(a.begin(), a.end(), mid);
    int aj2 = *(upper_bound(a.begin(), a.end(), mid) - 1);
    int aj = (abs(aj1 - mid) < abs(aj2 - mid) ? aj1 : aj2);
    cout << ai << ' ' << aj << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k, a, b;
    cin >> k >> a >> b;
    int d = b - a;
    if(k < a || d <= 2) {
        cout << 1 + k << endl;
        return 0;
    }
    int ans = a;
    k -= a - 1;
    ans += d * (k / 2);
    ans += k % 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,c = map(int,input().split())
L = [[] for i in range(c)]
for i in range(n):
    s,t,k = map(int,input().split())
    L[k-1].append([s,t])
for i in range(c):
    L[i].sort()
for i in range(c):
    d = [0]*(10**5+1)
    T = []
    for j in range(len(L[i])):
        d[L[i][j][0]] += 1
        d[L[i][j][1]] -= 1
    for j in range(10**5):
        d[j+1] += d[j]
    cur = 0
    start = 0
    end = 0
    for j in range(10**5+1):
        if d[j] == 1 and cur == 0:
            start = j
            cur = 1
        elif d[j] == 0 and cur == 1:
            end = j
            cur = 0
            T.append([start*2-1, end*2])
    L[i] = T
dp = [0]*(10**5)*3
ans = 0
for i in range(c):
    for j in range(len(L[i])):
        dp[L[i][j][0]] += 1
        dp[L[i][j][1]] -= 1
for j in range(1,(10**5)*3):
    dp[j] = dp[j-1]+dp[j]
    ans = max(ans, dp[j])
print(ans)


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s1;
  while ( cin >> s1, s1 != "." ) {
    string s2;
    cin >> s2;
    vector<string> t1, t2;
    {
      string s = "";
      for ( int i = 0; i < (int)s1.size(); i++ ) {
	if ( s1[i] == '"' ) {
	  t1.emplace_back(s);
	  s = "";
	} else s += s1[i];	
      }
      t1.emplace_back(s);      
    }
    {
      string s = "";
      for ( int i = 0; i < (int)s2.size(); i++ ) {
	if ( s2[i] == '"' ) {
	  t2.emplace_back(s);
	  s = "";	    
	} else s += s2[i];	
      }
      t2.emplace_back(s);      
    }

    if ( t1.size() != t2.size() ) {
      cout << "DIFFERENT" << endl;
      continue;
    }
    
    int cnt = 0;
    for ( int i = 0; i < (int)t1.size(); i++ ) {
      if ( i%2 ) {     
	if ( t1[i] != t2[i] ) cnt++;	
      } else {
	if ( t1[i] != t2[i] ) cnt += 2;
      }
    }
  
    if ( cnt == 0 ) cout << "IDENTICAL" << endl;
    else if ( cnt == 1 ) cout << "CLOSE" << endl;
    else cout << "DIFFERENT" << endl;    
  }
  
  return 0;
}



Measured memory_bytes: 3172
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict

class Solution:
    def main(self):
        N = int(input())
        A = []
        B = []
        path =  defaultdict(set)
        for _ in range(N-1):
            a, b = map(int, input().split())
            path[a-1].add(b-1)
            path[b-1].add(a-1)
            A.append(a-1)
            B.append(b-1)
        c = sorted(list(map(int, input().split())))

        cnt = [None] * N
        max_idx = 0
        max_val = 0
        for i in range(N):
            cnt[i] = len(path[i])
            if max_val < cnt[i]:
                max_val = cnt[i]
                max_idx = i

        stack = [max_val]
        res = [None] * N
        while stack:
            p = stack.pop(0)
            if res[p] == None:
                res[p] = c.pop()
                for n in path[p]:
                    stack.append(n)

        score = 0
        for a, b in zip(A, B):
            score += min(res[a], res[b])

        print(score)
        print(' '.join([str(v) for v in res]))


if __name__ == '__main__':
    Solution().main()

Measured memory_bytes: 9020
import java.util.Arrays;
import java.util.Scanner;
 
class Main {
    Scanner sc = new Scanner(System.in);
 
    int[][][] data=new int[5][4][11];
     
     
    public void run() {
        int N = sc.nextInt();
        for(int i=0;i<data.length;i++)for(int j=0;j<data[i].length;j++)Arrays.fill(data[i][j],0);
        for(int i=0;i<N;i++){
            int b=sc.nextInt(),f=sc.nextInt(),r=sc.nextInt(),v=sc.nextInt();
                data[b][f][r]+=v;
        }
         
        for(int b=1;b<=4;b++){
            for(int f=1;f<=3;f++){
                for(int r=1;r<=10;r++){
                    pr(" "+data[b][f][r]);
                }
                ln();
            }
            if(b!=4)ln("####################");
        }
    }
 
    public static void main(String[] args) {
        new Main().run();
    }
 
    public static void pr(Object o) {
        System.out.print(o);
    }
 
    public static void ln(Object o) {
        System.out.println(o);
    }
 
    public static void ln() {
        System.out.println();
    }
}


Measured memory_bytes: 30000
h, n = list(map(int,input().split()))
a = [list(map(int,input().split())) for _ in range(n)]

INF = 10**18
dp = [INF]*(h+10001)

dp[0] = 0

for i in range(n):
  for j in range(h):
    if dp[j] == INF:
      continue
    dp[j+a[i][0]] = min(dp[j+a[i][0]],dp[j]+a[i][1])
print(min(dp[h:]))

Measured memory_bytes: 42476
import java.util.Scanner;

class Main {
	
	static void swap(int[] a,int x,int y){
		int temp=a[x];
		a[x]=a[y];
		a[y]=temp;
		return;
	}
	
	static void printa(int[] a,int n){
		for(int i=0;i<n-1;i++){
			System.out.printf("%d ",a[i]);
		}
		System.out.println(a[n-1]);
		return;
	}
	
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		int n=scan.nextInt();
		int[] a=new int[n];
		
		for(int i=0;i<n;i++)
			a[i]=scan.nextInt();
		
		for(int i=0;i<n;i++){
			int x=a[i];
			int j=i-1;
			while(j>=0 && a[j] > x){
				a[j+1]=a[j];
				j--;
			}
			a[j+1]=x;
			
			printa(a,n);
			
		}
	}
}


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

#define pb push_back
#define F first
#define S second
#define fo(i,a,b)  for(int i = a; i < b; i++)

using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
#define Mosta     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ReadFile            freopen("input.in","r",stdin)
#define WriteFile           freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f;
const ld EPS = 1e-7;
double Pi=acos(-1);
const ld rad=Pi/180.0;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll nCr (ll n,ll m)
{
        return(m == 0)?1:n*nCr(n-1,m-1)/m;
}
/*****************************************************/

int main()
{
    int n;
    cin >> n;
    int a[n];
    ll ans = 0 , x = 0;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];

    for(int i = 1; i <= n-1; ++i){
        if(a[i] >= a[i+1]){
            x++;
        }else{
            ans = max(ans , x);
            x = 0;
        }
    }
    if(x >= 1)
        ans = max(ans , x);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 768
import java.util.*;

class Main {

    public static void main(String[] args) {
        Deque<Integer> stack = new ArrayDeque<Integer>();
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        while (n != 0) {
            for (int i = 0; i < n; i++) {
                stack.addLast(i+1);
            }
            int ans = 0;
            while (stack.peekFirst() != null) {
                for (int i = 0; i < m-1; i++) {
                    int tmp = stack.pollFirst();
                    stack.addLast(tmp);
                }
                ans = stack.pollFirst();
            }
            System.out.println(ans);
            n = scan.nextInt();
            m = scan.nextInt();
        }
    }
}

Measured memory_bytes: 35180