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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N, K; cin >> N >> K;
  int a[N+1] = {}; rep(i,N) cin >> a[i]; sort(a,a+N+1);
  int l = 0, r = 0; while (a[r]<K&&r!=N+1) r++;
  while (l!=r) {
    int mid = (l+r)/2;

    bool dp[N+2][K] = {}; dp[0][0] = true;
    rep(i,N+1) {
      rep(j,K) {
        if (i==mid) dp[i+1][j] = dp[i][j];
        else {
          dp[i+1][j] = dp[i][j];
          if (j>=a[i]) dp[i+1][j] |= dp[i][j-a[i]];
        }
      }
    }
    // cout << mid << endl;
    // rep(i,K) cout << dp[N+1][i] << " "; cout << endl;
    bool noneed = false;
    repr(i,K-a[mid],K) noneed |= dp[N+1][i];
    if (noneed) r = mid;
    else l = mid+1;
  }
  int result = l-1;
  cout << result << endl;
  return 0;
}

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

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	 printf
#define sf			 scanf
#define pb(a)        push_back(a)
#define mp			 make_pair
#define ff			 first
#define ss			 second
#define for0(i,n)    for(int i=0;i<n;i++)
#define for1(i,n)    for(int i=1;i<=n;i++)
#define forab(i,a,b) for(int i=a;i<=b;i++)
#define lcm(a, b)    ((a)*((b)/gcd(a,b)))
#define sq(a)		 (a)*(a)
#define endl		     "\n"
#define abs(x)		 fabs(x)
#define all(v) 		 v.begin(),v.end()
#define pcase(z,x)   cout<<"Case "<<z<<": "<<x<<"\n"
#define mod          1000000007
#define WakandaForever     ios_base::sync_with_stdio(0); cin.tie(0);
int a[1000][4];
int main()
{
    WakandaForever
    int n;
    cin>>n;
    for0(i,n){
        for0(j,2){
            cin>>a[i][j];
        }
    }
    bool ok=0;
    for0(i,n-2){
        if(a[i][0] == a[i][1] && a[i+1][0] == a[i+1][1] && a[i+2][0] == a[i+2][1]){ok=1; break;}
    }
    pf(ok? "Yes\n" : "No\n");
    return 0;
}

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

int main() {
  	int n,k;
 	cin >> n >> k;
 	 int p[n];
 	 for(int i=0; i<n; i++) 
 	 {cin >> p[i];}

	sort(p,p+n);
  
  int ans = 0;
  
   	 for(int j=0; j<k; j++) 
 	 {
       	ans += p[j];
     }

	cout << ans << endl;
 
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		sc.nextLine();
		String[] info=sc.nextLine().split(" ");
		Double t=Double.valueOf(info[0]);
		Double a=Double.valueOf(info[1]);

		List<Double> input=Arrays.asList(sc.nextLine().split(" "))
				.stream()
				.map(s->Double.valueOf(s))
				.map(s->Math.abs(a-(t-s*0.006)))
				.collect(Collectors.toList());
		System.out.println(input.indexOf(Collections.min(input))+1);
	}
}

Measured memory_bytes: 28856
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,T,t,c;
int main()
{
  cin>>n>>T;int ans=2147483647;
  for(int i=1;i<=n;++i){
	cin>>t>>c;
	if(c<=T) ans=min(ans,t);
  }
  if(ans==2147483647) puts("TLE");
  else cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 7/14/2018 AGC026
 
 23:00-23:30 time is up
 
 7/18/2018
 
 15:45-
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
//const int MAX_N=1e5+1;
int N;
string S;
void solve() {
  LL res=0;
  unordered_map<string, unordered_map<string, LL>> M;
  REP(mask,1<<N) {
    string a,b;
    REP(i,N) (((mask>>i)&1)?a:b)+=S[N+i];
    M[a][b]++;
  }
  REP(mask,1<<N) {
    string a,b;
    REP(i,N) (((mask>>i)&1)?a:b)+=S[i];
    reverse(a.begin(),a.end()),reverse(b.begin(),b.end());
//    dump3(a,b,M[b][a]);
    res+=M[b][a];
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>S;
  solve();
  return 0;
}


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

int main(){
    int n,m,c; cin>>n>>m>>c;

    vector<int>b(m);

    vector<vector<int>> a(n,vector<int>(m));

    for(int i=0; i<m; i++){
        cin>>b[i];
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>a[i][j];
        }
    }

    vector<int> com(m,0);

    int count =0;

    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            com[i] += (a[i][j] *  b[j]);
        }
        com [i] += c;
        if (com[i] > 0) count++;
    }

    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    Scanner(System.`in`).use {
        val n = it.nextInt()
        val x = it.nextInt()
        val xx = mutableListOf<Int>()

        for (i in 0 until n) {
            xx.add(Math.abs(it.nextInt() - x))
        }

        while (1 < xx.size) {
            if (xx[0] < xx[1]) {
                val tmp = xx[0]
                xx[0] = xx[1]
                xx[1] = tmp
            }

            val r = xx[0] % xx[1]
            xx[0] = xx[1]

            if (r == 0) {
                xx.removeAt(1)
            } else {
                xx[1] = r
            }
        }

        println(xx[0])
    }
}


Measured memory_bytes: 55616
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i64 a, b;

i32 main()
{
    cin >> a >> b;
    cout << (a + b) % 24 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<int>  A(N);
    rep(i, N) cin >> A[i];
    
    int ret = 1;
    rep(i, N) ret *= 3;
    int cnt = 1;
    rep(i, N){
        if(A[i] % 2 == 0) cnt *= 2;
    }
    output(ret - cnt);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string s;
    cin >> s;
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL N, K; cin >> N >> K;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	RSORT(a);
	LL ans = accumulate(a.begin(),a.begin()+K,0LL);
	cout<<ans<<endl;

	return 0;
}


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



int main ()  {
	int a,nb,i,n,k ;
	scanf("%d %d",&n,&k) ;

a=k ;
nb=1;
while (k<n) {
	k=k-1+a;
	nb++;
}
	printf("%d",nb) ;

	
	return(0) ;
}

Measured memory_bytes: 128
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 2000000000

const double EPS = 1e-10;
const double PI  = acos(-1.0);
////////////////////////////////////////////////
int q;
string X,Y;
int a[1010][1010];



int main()
{
	cin>>q;
	REP(i,q)
	{
		cin>>X>>Y;
		int m=SZ(X);
		int n=SZ(Y);
		X=' '+X;
		Y=' '+Y;
		FOR(i,1,m+1)
		{
			FOR(j,1,n+1)
			{
				if(X[i]==Y[j])a[i][j]=a[i-1][j-1]+1;
				else a[i][j]=max(a[i-1][j],a[i][j-1]);
			}
		}
		cout<<a[m][n]<<endl;
	}
	return 0;
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	
	while (1) {
		int t, p, r;
		int tl, pl, time;
		int tmp1, tmp2;
		int pena[51][11] = {};
		int res[51] = {};
		int ans[51] = {};
		string message;

		cin >> t >> p >> r;
		if (t == 0) {
			break;
		}
		FOR(i, 1, r) {
			cin >> tl >> pl >> time >> message;
			if (message == "WRONG") {
				pena[tl][pl]++;
			}
			else {
				ans[tl]++;
				res[tl] += time + pena[tl][pl] * 1200;
			}
		}
		vector< pair<int, int> > dp(t);
		FOR(i, 1, t) {
			dp[i - 1].first = ans[i];
			dp[i - 1].second = i;
		}
		sort(dp.begin(), dp.end());
		RFOR(i, t-1, 1) {
			RFOR(u, i-1, 0) {
				if (dp[i].first == dp[u].first) {
					if (res[dp[i].second] > res[dp[u].second]) {
						tmp1 = dp[i].first;
						tmp2 = dp[i].second;
						dp[i].first = dp[u].first;
						dp[i].second = dp[u].second;
						dp[u].first = tmp1;
						dp[u].second = tmp2;
					}
					if (res[dp[i].second] == res[dp[u].second]) {
						tmp1 = dp[i].second;
						dp[i].second = dp[u].second;
						dp[u].second = tmp1;
					}
				}
			}
		}
		RFOR(i, t-1, 0) {
			cout << dp[i].second << " " << dp[i].first << " " << res[dp[i].second] << endl;
		}
	}
	
}


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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n;

int main() {
  srand(time(0));
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n);
  range(i, 0, n) a[i] = s[i] - '0';
  {
    range(i, 0, n - 1) a[i] = abs(a[i] - a[i + 1]);
    a.pop_back();
    if(a.size() == 1) {
      cout << a[0];
      return 0;
    }
    n--;
  }  
  bool one = false;
  range(i, 0, n) one |= a[i] == 1;
  auto solve = [&](vector<int> v) {
    int res = 0;
    range(i, 0, n) {
      res += v[i] * ((((n - 1) & i) == i) ? 1 : 0);
      res &= 1;
    }
    return res;
  };
  int res;
  if(one) {
    res = solve(a);
  } else {
    for(int &i : a) i /= 2;
    res = solve(a) * 2;
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 9220
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define INF 1e9

static const int seed=6;
static const int D=365;
static const int ntype=26;
static const double swap_rate=0.8;
static const double change_rate=1-swap_rate;
static int ans[D+1];
static int max_score=0;
static int t=1e6;

class Contest{
public:
    Contest(){
        last=0;
    }
    int s[D+1];
    int c;
    int last;
};

static Contest contest[ntype+1];

void Input(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int d;
    cin>>d;
    for(int i=1;i<=ntype;++i){
        int t;
        cin>>t;
        contest[i].c=t;
    }
    for(int day=1;day<=D;++day){
        for(int type=1;type<=ntype;++type){
            int t;
            cin>>t;
            contest[type].s[day]=t;
        }
    }
}

int Score(int type){
    int sum=0;
    contest[type].last=0;
    for(int day=1;day<=D;++day){
        if(ans[day]==type){
            sum+=contest[type].s[day];
            int n=day-contest[type].last;
            sum-=contest[type].c*(n*(n-1)/2);
            contest[type].last=day;
        }
    }
    if(ans[D]!=type){
        int n=D-contest[type].last;
        sum-=contest[type].c*(n*(n+1)/2);
    }
    return sum;   
}

void Output(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for(int d=1;d<=D;++d) cout<<ans[d]<<'\n';
}

void Init(){
    for(int d=1;d<=D;++d) ans[d]=rand()%ntype+1;
}

void Greedy(){
    vector<int> l(ntype+1,0);
    int score=0;
    for(int d=1;d<=D;++d){
        for(int i=1;i<=ntype;++i) score-=contest[i].c*(d-l[i]);
        int temp=score;
        int t=-1;
        for(int i=1;i<=ntype;++i){
            int k=contest[i].s[d]+contest[i].c*(d-l[i])+score;
            if(k>temp){
                temp=k;
                t=i;
            }
        }
        ans[d]=t;
        l[t]=d;
    }
}

void change(){
    int p=rand()%D+1;
    int before=ans[p];
    int after=rand()%ntype+1;
    int before_score=Score(before)+Score(after);
    ans[p]=after;
    int delta=Score(before)+Score(after)-before_score;
    if(delta>0){ 
        max_score+=delta;
    }
    else ans[p]=before;
}

void swap(){
    int p1=rand()%D+1;
    int p2=rand()%D+1;
    while(p1==p2) p2=rand()%D+1;
    int temp_score=Score(ans[p1])+Score(ans[p2]);
    int temp=ans[p1];
    ans[p1]=ans[p2];
    ans[p2]=temp;
    int delta=Score(ans[p2])+Score(ans[p1])-temp_score;
    if(delta>0){
        max_score+=delta;
    }
    else{
        ans[p2]=ans[p1];
        ans[p1]=temp;
    }
}

void Solve(int times){
    Greedy();
    for(int i=1;i<=ntype;++i) max_score+=Score(i);
    for(int i=0;i<times;++i){
        double p=(double)rand()/RAND_MAX;
        if(p<swap_rate) swap();
        else change();
    }
}

int main(){
    srand(seed);
    Input();
    Solve(t);
    Output();
}


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

signed main(){
    int n,m; cin>>n>>m;
    if(n>=m/2){
        cout<<m/2<<endl;
    }else{
        cout<<n+(m-n*2)/4<<endl;
    }
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n,m,ansn=1,ansm=1,ans;
    cin >> n >> m;
    for(int i=n;i>0;i--){
        ansn *= i;
        ansn %= 1000000007;
    }
    for(int i=m;i>0;i--){
        ansm *= i;
        ansm %= 1000000007;
    }
    ans = (ansn*ansm)%1000000007;
    /*cout << ansn << endl;
    cout << ansm << endl;
    cout << ans << endl;*/
    if(abs(n-m) >  1)ans=0;
    if((n+m) % 2 == 0)ans*=2;
    cout << ans % 1000000007 << endl;
    return 0;
}

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

#define         eps         10e-9
#define         pi          2*acos(0)
#define         P1          1e9+7
#define         P2          1e9+9
#define         ll          long long
#define         ST          stack
#define         V           vector
#define         Q           queue
#define         S           set
#define         M           map

using namespace std;

///ISNNJB

int main()
{
    int n,ara[55],b[55],i,j,ctn=0;
    cin>>n;
    for (i=1; i<=n; i++)
        cin>>ara[i];
    for (i=1; i<=n; i++)
        b[i]=ara[i];
    sort(ara+1, ara+n+1);
    for (i=1; i<=n; i++)
    {
        if (ara[i]!=b[i])
            ctn++;
    }
    if(ctn<=2)
        cout<<"YES\n";
    else
        cout<<"NO\n";

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
char s[110];
int l,f[110][110],num,num1,num2,i,j,k,len;
int min(int a,int b){return a<b?a:b;}
int main()
{
	scanf("%d",&l);
	scanf("%s",s);
	/*for (i=1;i<=l;i++) f[i][i]=1;
	for (len=2;len<=l;len++)//length first!
	  for (i=1;i<=l-len+1;i++)//starting point
	    {
	    	j=i+len-1;
	    	f[i][j]=1000;
	    	if (s[i-1]=='('&&s[j-1]==')') f[i][j]=f[i+1][j-1];
	    	for (k=i;k<j;k++)
	    	  f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]);
		}*/
	int d=0;
	for (i=0;i<l;i++)
	{
		if (s[i]=='(') num1++;
		else num2++;
		if (num2-num1>d) d=num2-num1; //compensate how much?
	}
	for (i=1;i<=d;i++) printf("(");
	num1+=d;//now num1>=num2
	printf("%s",s);
	for (i=1;i<=num1-num2;i++) printf(")");
}
//valid iff number of ( and ) match ans sum1[i]>=sum2[i]
//find the shortest length==(num1-num2)+min(sum1[i]-sum2[i])
//DP or direct work 
//((((((................))))))))))) is the lexicographically smallest string

Measured memory_bytes: 128
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    int n,k,ans=0;
	cin >> n >> k;
	double x[n][k];
	rep(i,n){
		rep(j,k){
		cin >> x[i][j];
		}
	}

	rep(i,n){
		for(int j=i+1;j<n;j++){
			double dis=0;
			rep(l,k){
				dis += pow(x[i][l]-x[j][l],2);
			}
			if(sqrt(dis)-(int)sqrt(dis)==0){
				ans++;
			}
		}
	}
	

	cout << ans << endl;
}

Measured memory_bytes: 256
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    let S = lines[0]
    
    let on = S[0] == 'R' 
    let tw = S[1] == 'R'
    let th = S[2] == 'R'

    if(on && tw && th) {
        console.log(3);
    } else if ((on && tw) || (tw && th)) {
        console.log(2);
    } else if (on || tw || th) {
        console.log(1);
    } else {
        console.log(0);
    }
});

Measured memory_bytes: 30100
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF 2000000000
using namespace std;
 
 
int main(){
    int n;
    while(cin >> n,n){
        int edge[20][20], dp[(1<<n)];
        rep(i,n) rep(j,n + 1) cin >> edge[i][j];
        rep(i,(1<<n)) dp[i] = INF;
 
        dp[0] = 0;
 
        rep(i,(1<<n)){
            rep(j,n){ //jbit??¶?????§??????????????§
                if( (i & (1 << j)) == 0) { //??§???????????§??¢???????????§????????????
                    int time = edge[j][0];
                    rep(k,n){ //???????????§???????????§??¢????????£??§?????????
                        /*
                           ?¬??¬¬?§¶?????±??????????????§??????????????§??? j
                           ??´????????¨?????¶?????§??¢??§???????????????????????????????§????????§???????????§??¢?????±?????§??????????????§?????? k
                         */
                        if( (i & (1<<k)) == (1<<k)){
                            time = min(time,edge[j][k + 1]); 
                        }
                    }
                    dp[i | 1<<j] = min(dp[i | 1<<j], dp[i] + time);
                    //rep(i,7){ cout << dp[i] << endl; }
                }
            }
        }
        cout << dp[(1<<n)-1] << endl;
    }
}

Measured memory_bytes: 1416
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

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

    ll p[n], q[n];
    rep(i, n)cin >> p[i];
    rep(i, n)cin >> q[i];

    vector<ll> ary(n);
    iota(ALL(ary), 1);

    ll cnt = 0;
    ll turn_p, turn_q;

   do{
       bool isP, isQ;
       isP = isQ = true;

        rep(i, n){
            if(p[i] != ary[i])isP = false;
            if(q[i] != ary[i])isQ = false;
        }

        if(isP)turn_p = cnt;
        if(isQ)turn_q = cnt;

        cnt++;
    }while(next_permutation(ALL(ary)));

    cout << abs(turn_p - turn_q) << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import defaultdict


def sim(N, s, t, d, i):
    # print(s, i)
    curr = i
    for tt, dd in zip(t, d):
        if tt == s[curr]:
            if dd == "R":
                curr += 1
                # print("cuz", tt, dd, curr)
            else:
                curr -= 1
                # print("cuz", tt, dd, curr)
        if curr >= N:
            return "right"
        elif curr < 0:
            return "left"
    return "stay"


# def dfs_2(N, Q, s, t, d):
#     # 消滅は、(s[-1],R)の呪文
#     if Q == 0:
#         return 0
#     ans = 0
#     for i in range(Q):
#         if t[i] == s[-1] and d[i] == 'R':
#             ans += 1 + dfs_2(N, i, s[:-1], t[:i], d[:i])
#     return ans


def solve(N: int, Q: int, s: str, t: "List[str]", d: "List[str]"):

    wa = 0

    ca, cb = -1, N
    while True:
        if ca == cb or ca + 1 == cb:
            break
        # 右側に飛び出す
        curr = (cb+ca) // 2
        # print("1 ca, curr, cb", ca, curr, cb)
        state = sim(N, s, t, d, curr)
        if state == "right":
            cb = curr
        else:
            ca = curr

    # print("1 ca, curr, cb", ca, curr, cb)
    wa += N - cb

    ca, cb = -1, N
    while True:
        if ca == cb or ca + 1 == cb:
            break
        # 左に飛び出す
        curr = (cb+ca) // 2
        # print("2 ca, curr, cb", ca, curr, cb)
        state = sim(N, s, t, d, curr)
        # print("2 ", state)
        if state == "left":
            ca = curr
        else:
            cb = curr
    # print("2 ca, curr, cb", ca, curr, cb)
    wa += ca+1

    print(N-wa)
    # print(sim(N, s, t, d, 1))
    # guide = defaultdict(list)
    # for i in range(N):          # O(N)
    #     guide[s[i]] += [i]
    # pos = [1]*N

    # for i in range(Q):          # O(Q*(N/26))
    #     direc = 1 if d[i] == 'R' else -1
    #     copied = guide[t[i]].copy()
    #     guide[t[i]] = []
    #     for j in copied:
    #         pos[j] -= 1
    #         if 0 <= j + direc and j + direc < N:
    #             pos[j+direc] += 1
    #             guide[s[j+direc]] += [j+direc]
    #             # print("here", s[j+direc])
    #     # print(pos)
    #     # print(guide)
    # print(sum(pos))
    # return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    t = [str()] * (Q)  # type: "List[str]"
    d = [str()] * (Q)  # type: "List[str]"
    for i in range(Q):
        t[i] = next(tokens)
        d[i] = next(tokens)
    solve(N, Q, s, t, d)


if __name__ == '__main__':
    main()


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

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

  int n, k;
  cin >> n >> k;
  vector<int> h;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    h.push_back(t);
  }
  sort(h.begin(), h.end());
  int m = 1000000000;
  for (int i = 0; i + k - 1 < n; ++i) {
    m = min(m, h[i + k - 1] - h[i]);
  }
  cout << m << endl;

  return 0;
}


Measured memory_bytes: 892
num = int(input())
dish=[] #appendのために宣言が必要
while True:
    try:
        dish.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。
cnt=0
#print(dish)
#print(dish[1][0])
for i in range(num):
    cnt= cnt+dish[1][i]
    
#print(cnt)
for i in range(0,num-1):
    if dish[0][i+1]-dish[0][i]==1:
        cnt = cnt+ dish[2][int(dish[0][i])-1]
       # print(dish[2][i-1])
     
    else:
        pass
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<int, int, int> ti;

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

    int H, W;
    cin >> H >> W;
    vector<string> map(H);
    for (int i = 0; i < H; i++)
    {
        string M;
        cin >> M;
        map.at(i) = M;
    }

    queue<ti> moves;
    //全マスを起点で全探索
    int answer = 0;
    vector<int> dh = {-1, 1, 0, 0};
    vector<int> dw = {0, 0, -1, 1};
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (map.at(i).at(j) == '#')
            {
                continue;
            }
            vector<vector<bool>> alreadyMoved(H, vector<bool>(W, false));
            moves.push(make_tuple(i, j, 0));
            alreadyMoved.at(i).at(j) = true;
            while (moves.size())
            {
                ti move = moves.front();
                moves.pop();
                int curH, curW, count;
                tie(curH, curW, count) = move;
                answer = max(answer, count);
                alreadyMoved.at(curH).at(curW) = true;
                int nextH, nextW;
                for (int k = 0; k < 4; k++)
                {
                    nextH = curH + dh.at(k);
                    nextW = curW + dw.at(k);
                    if (0 <= nextH && nextH < H && 0 <= nextW && nextW < W && map.at(nextH).at(nextW) == '.' && !alreadyMoved.at(nextH).at(nextW))
                    {
                        moves.push(make_tuple(nextH, nextW, count + 1));
                        alreadyMoved.at(nextH).at(nextW) = true;
                    }
                }
            }
        }
    }
    cout << answer << endl;
    return 0;
}

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

using ll = long long;
const int sz = 1e5 + 10;


int main() {
    #ifdef CLown1331
        freopen( "in.txt","r",stdin );
    #endif /// CLown1331
    string s;
    while( cin >> s ) {
        cout << s[0] << int(s.size())-2 << s.back() << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int a, b;
    cin >> a >> b;
    int Min = min(a, b), Max = max(a, b);
    rep(i, Max) cout << Min;
    cout << endl;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#include<map>
#define MEM(var,val) memset(var,(val),sizeof(var))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define nitro   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define F first
#define S second
vll dp,h;
ll n;

ll rec(ll i)
{
    if(i>n)
        return 1000000000;
    if(i==n)
        return dp[i]=0;
    if(i==n-1)
        return dp[i]=abs(h[i+1]-h[i]);
        if(dp[i]!=-1)
            return dp[i];
   return dp[i]=MIN(abs(h[i+1]-h[i])+rec(i+1),abs(h[i+2]-h[i])+rec(i+2));
}
int main()
{

    cin>>n;
    dp.resize(n+1,-1);
     h.resize(n+1);
    for(int i=1;i<n+1;i++)
        cin>>h[i];
    cout<<rec(1);

}


Measured memory_bytes: 9600
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;

int main()
{
    fastio;
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll ans1=a*c;
        ll ans2=a*d;
        ll ans3=b*c;
        ll ans4=b*d;
        cout<<max(max(ans1,ans2),max(ans3,ans4));


    }

}


Measured memory_bytes: 3608
#include<stdio.h>
#define N 100000

typedef struct{
  int parent,left,right;
}Node;

Node Tree[N];
void Print(int);
int depth(int);
int PrintChild(int);

main(){

  int i,n,id,k,c,q,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    Tree[i].parent=-1;
    Tree[i].left=-1;
    Tree[i].right=-1;
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&c);
      Tree[c].parent=id;
      if(j==0) Tree[id].left=c;
      else Tree[q].right=c;
      q=c;
    }
  }
  for(i=0;i<n;i++){
    Print(i);
  }
  return 0;
}

void Print(int u){
  int i;
  printf("node %d: parent = %d, depth = %d, ",u,Tree[u].parent,depth(u));
  if(Tree[u].parent==-1) printf("root, [");
  else if(Tree[u].left==-1) printf("leaf, [");
  else printf("internal node, [");
  PrintChild(Tree[u].left);
  printf("]\n");
}

int PrintChild(int o){
  if(o==-1) return 0;
  if(Tree[o].right==-1) printf("%d",o);
  else {
    printf("%d, ",o);
    PrintChild(Tree[o].right);
  }
  return 0;
}
int depth(int o){
  if(Tree[o].parent==-1) return 0;
  return 1+depth(Tree[o].parent);
}

Measured memory_bytes: 3344
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto s = sread();
    auto t = sread();
    if (s.length < t.length)
    {
        writeln("UNRESTORABLE");
        return;
    }
    long insert = -1;
    foreach (i; iota(s.length - t.length + 1))
    {
        if (is_pass(s[i .. i + t.length], t))
            insert = i;
    }
    if (insert >= 0)
    {
        fill_a(s, t, insert).writeln();
    }
    else
    {
        writeln("UNRESTORABLE");
    }
}

bool is_pass(string pat, string str)
{
    bool ret = true;
    foreach (i; iota(pat.length))
    {
        if (pat[i] == '?')
            continue;

        ret &= (pat[i] == str[i]);
    }
    return ret;
}

auto fill_a(string s, string t, long insert)
{
    string ret;
    foreach (i, e; s)
    {
        if (i >= insert && i < insert + t.length)
        {
            ret ~= t[i - insert];
        }
        else
        {
            ret ~= (e == '?' ? 'a' : e);
        }
    }
    return ret;
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2564
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,m;
  int a[1111];
  int x=-1;
  while(1){
    x=-1;
    int ans=0;
    cin >> n >> m;//nは購入数　mは最大数
    if(n==0 && m==0)break;
    for(int i=0;i<n;i++){
      cin >> a[i];
      ans+=a[i];
    }
    
    sort(a,a+n,greater<int>());
    
    
    while(n>=m){
      x+=m;
      ans-=a[x];
      n-=m;
    }
    
    cout << ans << endl;
  }
}

Measured memory_bytes: 1180
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
#define tc int t;cin>>t;while(t--)
#define get cin>>
#define geta ll a[n];for (int i = 0; i < n; ++i){cin>>a[i];}
#define puta for (int i = 0; i < n; ++i){cout<<a[i];}
#define put cout<<
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
int dp[105][100005];
int main() 
{
   fast();
   int n,k;cin>>n>>k;
   int a[n+1];
   for (int i = 1; i <= n; ++i)
   {
   	cin>>a[i];
   }
   dp[0][0]=1;
   for (int i = 0; i <= k; ++i)
   {
   	dp[0][i]=0;
   }
   for (int i = 0; i <= n ; ++i)
   {
   	dp[i][0]=1;
   }
   for (int i = 1; i <= n; ++i)
   {
   	int pre[k+1]={0};
   	pre[0]=dp[i-1][0]%MOD;
   	for (int j = 1; j <= k ; ++j)
   	{
   		pre[j]=(pre[j-1]+dp[i-1][j])%MOD;
   		pre[j]+=MOD;
   		pre[j]%=MOD;
   	}
   	for (int j = 0; j <= k ; ++j)
   	{
   		if (j-a[i]-1>=0)
   		{
   			dp[i][j]=(pre[j]-pre[j-a[i]-1])%MOD;
   			dp[i][j]+=MOD;
   			dp[i][j]%=MOD;
   		}
   		else {dp[i][j]=pre[j]%MOD;}
   		// for (int l = 0; l <= min(a[i],k) ; ++l)
   		// {
   		// 	dp[i][j]+=dp[i-1][j-l];
   		// }
   	}
   }
   cout<<dp[n][k];
   return 0;
}

Measured memory_bytes: 41600
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#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 <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    LL k, a, b;
    cin >> k >> a >> b;
    if( b <= 2 || a >= b - 1 ) {
        cout << k + 1 << endl;
        return 0;

    }

    if( k - (a - 1) <= 0 ) {
        cout << k + 1 << endl;
        return 0;

    }

    if( a != 1 ) {
        k -= a - 1;

    }
    
    LL res = (k / 2) * (b - a) + a;
    if( k % 2 == 1 ) ++res;
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX_S (100001)

int main(void) {
  char S[MAX_S];
  scanf("%s", S);
  int ANS[MAX_S];
  int RtoL[MAX_S];
  int LtoR[MAX_S];
  int LEN = 0;
  for(int i = 0; S[i] != '\0'; i++) {
    LEN++;
    ANS[i]  = 0;
    RtoL[i] = 0;
    LtoR[i] = 0;
  }

  int r_lp = -1;
  int r_rp = -1;
  for(int i = 0; S[i] != '\0'; i++) {
    if(S[i] == 'R') {
      if(r_lp == -1) {
	r_lp = i;
	r_rp = i;
      } else {
	r_rp++;
      }
    } else {// L
      if(r_lp == -1)
	continue;
      for(int j = r_lp; j <= r_rp; j++) {
	RtoL[j] = (i - j) % 2;
	if(RtoL[j])
	  ANS[r_rp]++;
	else
	  ANS[i]++;
      }
      r_lp = -1;
      r_rp = -1;
    }
  }
  
  int l_lp = -1;
  int l_rp = -1;
  for(int i = LEN; i >= 0; i--) {
    if(S[i] == 'L') {
      if(l_lp == -1) {
	l_lp = i;
	l_rp = i;
      } else {
	l_lp--;
      }
    } else {// R
      if(l_lp == -1)
	continue;
      for(int j = l_lp; j <= l_rp; j++) {
	LtoR[j] = (i - j) % 2;
	if(LtoR[j] == 0)
	  ANS[i]++;
	else
	  ANS[l_lp]++;
      }
      l_lp = -1;
      l_rp = -1;
    }
  }

  for(int i = 0; S[i] != '\0'; i++) {
    printf("%d ", ANS[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    int n,k;
    cin >> n >> k;

    vector<ll> H(n);
    for(int i = 0; i < n;i++){
        cin >> H[i];
    }

    VSORT(H);
    reverse(ALL(H));
    ll ans = 0;

    for(int i = 0; i < n;i++){
        if(i < k){

        }else{
            ans += H[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
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 (b<a) { a=b; return 1; } return 0; }

int inf=1E9;

int main(){
    int N;
    cin>> N;
    vector<int> a(N), b(N);

    rep(i,N){
        cin >> a[i] >> b[i];
    }

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    if(N%2==1){
        cout << b[(N-1)/2] - a[(N-1)/2] +1 << endl;
    }
    else{
        cout << ((b[N/2]+b[N/2-1]) - (a[N/2]+a[N/2-1])) + 1 << endl;
    }
        
    return 0;
}


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

int main () {
  int N;
  cin >> N ;
  int A = 0 ;
  int B = 0 ;
  vector<int> vec(N);
  for ( int i = 0 ; i < N ; i++ ) {
    cin >> vec.at(i);
    if (vec.at(i)%2 == 0){
      A++;
      if (vec.at(i)%3 == 0 || vec.at(i)%5 == 0){
        B++;
      }
    }
  }
  
  if ( A == B ){
    cout << "APPROVED" << endl;
  }
  else {
    cout << "DENIED" << endl;
  }
}

Measured memory_bytes: 256
# import math
from itertools import permutations as permus
# from fractions import gcd

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
arrP = tuple(map(int, input().split()))
arrQ = tuple(map(int, input().split()))

perms_list = list(permus(range(1,n+1)))
a = perms_list.index(arrP)
b = perms_list.index(arrQ)

ans = abs(a-b)
# y = abs(a-b)
print(ans)

Measured memory_bytes: 8052
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int i,j,key;
		int N;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		int [] A = new int [N];
		
		for(i=0; i<N; i++){
			A[i] =sc.nextInt();
		}
		System.out.print(A[0]);
		for(i=1; i<N; i++){
			System.out.print(" "+A[i]);
		}
		System.out.println("");
		
		for(i=1; i<N; i++){
			key = A[i];
			for(j=i-1;j>=0;j--){
				if(key<A[j]){
					A[j+1] = A[j];
					A[j] = key;
				}
			}
			System.out.print(A[0]);
			for(int r=1; r<N; r++){
				System.out.print(" "+A[r]);
			};
			System.out.println("");
		}

	}

}



Measured memory_bytes: 32088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, K; cin >> N >> K;
    vector<ll> x(N), y(N);
    for(int i=0; i<N; i++) cin >> x[i] >> y[i];

    ll ans = LLONG_MAX;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            for(int k=0; k<N; k++){
                for(int l=0; l<N; l++){
                    if(x[j] <= x[i] || y[l] <= y[k]) continue;
                    int cnt = 0;
                    for(int m=0; m<N; m++){
                        if(x[i] <= x[m] && x[m] <= x[j] && y[k] <= y[m] && y[m] <= y[l]) cnt++;
                    }
                    if(cnt >= K) ans = min(ans, (x[j]-x[i])*(y[l]-y[k]));
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
int main(void){
    int a,b,c,d;cin>>a>>b>>c>>d;
    int w=c-a;int h=d-b;
    rep(i,w)cout<<'R';rep(i,h)cout<<'U';rep(i,w)cout<<'L';rep(i,h+1)cout<<'D';rep(i,w+1)cout<<'R';
    rep(i,h+1)cout<<'U';cout<<'L'<<'U';rep(i,w+1)cout<<'L';rep(i,h+1)cout<<'D';cout<<'R';
    
}

Measured memory_bytes: 384