akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;


int main(void)
{
	int N; cin >> N;
	map<int, int> count;
	rep(i, 0, N) {
		int a; cin >> a;
		count[a - 1]++;
		count[a]++;
		count[a + 1]++;
	}
	
	int ans = 0;
	map<int, int>::iterator it;
	for (it = count.begin(); it != count.end(); it++) {
		ans = max(it->second, ans);
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
using P = pair<int,int>;
//Write From this Line

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	rep(i, n)cin>>v[i];
	
	ll ans = -1e9-9;
	for(int i = 0; i <= k; i++){
		for(int j = 0; i + j <= k; j++){
			ll now = 0 ;
			// 戻せる回数は, k - (i + j)
			int can_rev = k - (i + j);
			// 左i個、右からj個取り出す。
			vector<int> hand(0);

			rep(x,i){
				hand.push_back(v[x]);
				now += v[x];
				if(hand.size() >= n) break;
			}
			for(int x = 0; x < j; x++){
				if(hand.size() >= n) break;
				hand.push_back(v[n-1-x]);
				now += v[n-1-x];
			}
			sort(hand.begin(),hand.end());

			for(int x = 0; x < can_rev; x++){
				if(x >= hand.size())break;
				if(hand[x] <= 0) now -= hand[x];
			}
			chmax(ans,now);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = sorted(list(map(int, input().split())))

hen = [0, 0]
i, j = 0, 0
while i<n:
    if a[i]==a[i-1]:
        hen[j] = a[i]
        j = (j+1)%2
        i += 1
    i += 1
print(hen[0]*hen[1])

Measured memory_bytes: 14244
program prob1
    implicit none
    integer::i, j
    character(len=10)::s1, s2, s3
    read(*,*) s1, s2, s3

    write(*,'(3a)') char(ichar(s1(1:1)) - 32), char(ichar(s2(1:1)) - 32), char(ichar(s3(1:1)) - 32)
    stop
end program

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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
 
using namespace std;

int MOD = 998244353;
int fac[300005] = {0};
int inv[300005] = {0};

ll bitpow(ll x,ll n){
    ll ans = 1;
    while(n > 0){
        if(n%2 == 1) ans = ans * x % MOD;
        x = x * x %MOD;
        n = n >> 1;
    }
    return ans;
}

ll COM(ll n,ll k){
    return fac[n]*inv[k]%MOD*inv[n-k]%MOD;
}

signed main(){
    
    int  n,A,B,k;
    cin >> n >> A >> B >> k;
    
    int ans = 0;

    fac[0] = 1;
    inv[0] = 1;
    for(int i = 1;i <= 300003;i++){
        fac[i] = (fac[i-1]*i)%MOD;
        inv[i] = bitpow(fac[i]%MOD,MOD-2)%MOD;
    }


    REP(i,n+1){
        if((k - A*i)%B == 0){
          
            int a = i;
            int b = (k - A*i)/B;
          if(b >= 0 && b <= n){
            ans += COM(n,a)%MOD*COM(n,b)%MOD;
            ans %= MOD;
          }
        }
    }

    cout << ans << endl;
    
    return 0;
}
//g++ -std=c++14 code1.cpp



Measured memory_bytes: 4992
#include<cmath>
#include<string>
#include<fstream>
#include<iostream>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){
	int N;
	int A[200];
	cin >> N;
	rep(i,N) cin >> A[i];
	int cnt=0;
	int flag=1;
	do {
		rep(i,N) {
			if(A[i]%2==1) flag=0;
			else A[i]=A[i]/2;
		}
		if(flag) cnt++;
	}while(flag==1);
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
//python interactive_runner.py python3 local_testing_tool.py 0 -- ./Code
 
#define x first
#define y second
#define rep(i, a,b) for(int i = int(a); i < int(b); ++i)
#define forn(i,b) for(int i = 0; i < int(b); ++i)
const long long INF =1000000000000000000;

void solve(){
	int N;
	cin>>N;
	vector<int> num1(N);
	vector<int> num2(N);
	forn(j,N){
		cin>>num1[j]>>num2[j];
	}
	sort(num1.begin(),num1.end());
	sort(num2.begin(),num2.end());
	int ans;
	if(N%2==1){
		ans = num2[N/2]-num1[N/2]+1;
	}
	else{
	   ans = num2[(N/2)-1]+num2[(N/2)]-(num1[(N/2)-1]+num1[(N/2)])+1;
	}
	cout<<ans<<'\n';
}
int main(){

	 solve();
	return 0;
}

Measured memory_bytes: 4840
#include<iostream>
using namespace std;
int main() {
    string s;
    cin >> s;
    //cout << s << endl;
    if (s[0] != 'A') {
        //cout << "1" << endl;
        cout << "WA" << endl;
        return 0;
    } else {
        int cnt = 0;
        int j;
        for (int i = 1; i < s.length(); i++) {
            if (i >= 2 && i <= (s.length() - 1) - 1 && s[i] == 'C') { //front 3, end 2
                cnt++;
                j = i;
            }
            //cout << "i " << i << " cnt " << cnt << endl;
            if ((s[i] < 'a' || s[i] > 'z') && i != j) {
                //cout << "2" << endl;
                cout << "WA" << endl;
                return 0;
            }
        }
        if (cnt == 1) {
            cout << "AC" << endl;
        } else {
            cout << "WA" << endl;
        }
    }
}


Measured memory_bytes: 256
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

N,Q = imn()
S = input()
L = []
R = []
for _ in range(Q):
    l,r = imn()
    L.append(l-1)
    R.append(r-1)

s = [0 for _ in range(N+1)]
for i in range(1, N+1):
    s[i] = s[i-1]
    if S[i-1:i+1] == 'AC':
       s[i] += 1

for i in range(Q):
    print(s[R[i]]-s[L[i]])


Measured memory_bytes: 16308
import java.util.*;

public class Main {

    static long mod = 1_000_000_007l;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] a = new long[k+1];
        long ans = 0L;
        for (int i = k; i > 0; i--) {
            long c = (long)(k / i);
            long p = modPow(c, n);
            if(1 < c){
                int b = 2;
                while(b * i <= k){
                    p = (p + mod - a[b*i]) % mod;
                    b++;
                }
            }
            a[i] = p;
            ans = (ans + (p*i%mod)) %mod;
        }
        System.out.println(ans);
        sc.close();

    }

    private static long modPow(long base, int exp) {
        long ret = 1;
        while(exp > 0){
            if((exp & 1) == 1){
                ret = ret * base %mod;
            }
            base = base * base %mod;
            exp >>= 1;
        }
        return ret;
    }

}


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

int main(void) {
  string ss, tt;
  int cnt = 0;

  cin >> ss >> tt;

  for(int i=0;i<3;i++) {
    if (ss.at(i) == tt.at(i)) cnt++;
  }

  cout << cnt << endl;

  return (0);
}


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

int main(){
  vector<int>a(3);
  for(int i=0;i<3;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  int count=0;
  for(int i=1;i<3;i++){
    count+=(a[i]-a[i-1]);
  }
  cout << count << endl;
}

Measured memory_bytes: 3544
import math


def actual(a, b):
    num = int(str(a) + str(b))

    is_square_number = math.sqrt(num) % 1 == 0

    if is_square_number:
        return 'Yes'
    else:
        return 'No'
      
a, b = map(int, input().split())
print(actual(a, b))

Measured memory_bytes: 9108
l = input()
mod = 10**9 + 7

len_l = len(l)
dp = [[0] * 2 for _ in range(len_l + 1)]

dp[0][1] = 1

for i in range(1,len_l+1):
    dp[i][0] += dp[i-1][0] * 3

    if(l[i-1] == '0'):
        dp[i][1] += dp[i-1][1]
    else:
        dp[i][0] += dp[i-1][1]
        dp[i][1] += dp[i-1][1] * 2

    dp[i][0] %= mod
    dp[i][1] %= mod

ans = sum(dp[-1]) % mod
print(ans)

Measured memory_bytes: 54236
import java.util.Scanner;

public class Main {
 	public static void main(String[] args) {
 		Scanner scanner = new Scanner(System.in);
 		String S = scanner.next();
 		String[] splitArray = S.split("");
 		int sum = 0;
 
// 		for (int i = 0; i < splitArray.length; i++) {
// 			System.out.println(splitArray[i]);
// 		}
 		
 		for (int j = 0; j < splitArray.length / 2; j++) {
 			if (splitArray[2*j].equals("L")) {
 				sum += 1;
 			}
 			//System.out.println (sum);
 			
 			if (splitArray[2*j + 1].equals("R")) {
 				sum += 1;
 			}
 			//System.out.println (sum);
 		}
 		if (splitArray.length % 2 == 1) {
 			if (splitArray[splitArray.length - 1].equals("L")) {
 				sum += 1;
 			}
 		}
 		if (sum != 0) {
 			System.out.println ("No");
 		} else {
 			System.out.println ("Yes");
 		}
 	}
 }

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

long long f(long long n){
    long long sum = 0, a = 10;
    
    if(n % 2 == 1){
        return 0;
    }
       
    while(n/a != 0){
        sum += n/a;
        a *= 5;
    }

    return sum;
}

int main(void){
   long long n;
   
   cin >> n;
   
   cout << f(n) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

struct UnionFind {
    vector<int> d;
    // コンストラクタ　親は-頂点数を保管
    UnionFind(int N) : d(N, -1) {}

    int find(int x) {
        if (d[x] < 0) {
            return x;
        }
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        }
        if (d[x] > d[y]) {
            swap(x, y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return -d[find(x)];
    }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    vector<vector<int>> to(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<vector<int>> block(n);
    rep(i, k){
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        block[c].push_back(d);
        block[d].push_back(c);
    }

    rep(i, n){
        int ans = uf.size(i) - 1 - to[i].size();
        for(int t : block[i]){
            if(uf.same(i, t))ans--;
        }
        cout << ans << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 12152
function Main(input) {
    input = input.trim().split("\n");
    var N = parseInt(input[0],10);
    tmp = input[1].split(" ");
    var W = [];
    for(var i = 0; i < N; i++){
        W[i] = parseInt(tmp[i],10);
    }
    var sum = 0;
    for(var i = 0; i < N; i++){
        sum += W[i];
    }

    var output;
    if(W[0] >= sum/2){
        var S1 = W[0];
        var S2 = 0;
        for(var i = 1; i < N; i++){
            S2 += W[i];
        }
        output = Math.abs(S1-S2);
    }
    else if(W[N-1] >= sum/2){
        var S1 = 0;
        for(var i = 0; i < N-1; i++){
            S1 += W[i];
        }
        var S2 = W[N-1];
        output = Math.abs(S1-S2);
    }
    else{
        var S1 = 0;
        for(var i = 0; i < N; i++){
            S1 += W[i];
            if(S1 >= sum/2){
                break;
            };
        }
        var S2 = sum - S1;
        output = Math.min(Math.abs(sum - 2*S1),Math.abs(sum - 2*(S1-W[i])));
    }
    console.log(output);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
from operator import itemgetter

n = int(input())
l = [input().split() for x in range(n)]

for i in range(n):
    l[i][1] = int(l[i][1])
    l[i].append(i+1)

l.sort(key=itemgetter(1), reverse=True)
l.sort(key=itemgetter(0))

for i in range(n):
    print(l[i][2])
    

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
  string a;
  cin >> a ;
  if(a[a.size()-1]=='0'||a[a.size()-1]=='1'||a[a.size()-1]=='6'||a[a.size()-1]=='8')
  {
  
    
    
    
    
    
    cout << "pon" ;
  }
  else if(a[a.size()-1]=='3')
  {
  cout<< "bon" ;}
  else
  {
   cout << "hon" ;
  }
}


Measured memory_bytes: 3592
# -*- coding: utf-8 -*-

N = int(input())

Cake = 4
Donuts = 7

ans = 'No'
for i in range(N//4 + 1):
    for j in range(N//7 + 1):
        if N == Cake * i + Donuts * j:
            ans = 'Yes'
            break

print(ans)


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	int ans=((n*(n-1))/2)+((m*(m-1))/2);
	cout<<ans<<"\n";
	
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
#include<limits.h>
 
using namespace std;
int counter = 0;
void merge(int A[], int l, int m, int r){
    int n1 = m-l+1;
    int n2 = r-m;
    int *B = (int *)calloc(n1+1, sizeof(int));
    int *C = (int *)calloc(n2+1, sizeof(int));
    for(int i=0; i<n1; i++){
        B[i] = A[l+i];
    }
    for(int i=0; i<n2; i++){
        C[i] = A[m+1+i];
    }
    B[n1] = INT_MAX;
    C[n2] = INT_MAX;
    int i = 0;
    int j = 0;
    for(int k=0; k<r-l+1; k++){
        counter++;
        if(B[i] < C[j]){
            A[k+l] = B[i];
            i++;
        }else{
            A[k+l] = C[j];
            j++;
        }
    }
}

void merge_sort(int A[], int l, int r){
    int m = (l+r)/2;
    if(l < r){
        merge_sort(A, l, m);
        merge_sort(A, m+1, r);
        merge(A, l, m, r);
    }
}

int main(){
    int n;
    cin >> n;
    int *A = new int[n];
    for(int i=0; i<n; i++){
        cin >> A[i];
    }
    merge_sort(A, 0, n-1);
    for(int i=0; i<n; i++){
        if(i != 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << counter << endl;
}


Measured memory_bytes: 65824
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define reps(i,n) for(int i=1;i<=(int)n;i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define MOD 1000000007
#define itn int
#define enld endl
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    map<int,int> mp;
    rep(i,3){
        int a,b; cin >> a >> b;
        a--; b--;
        mp[a]++;
        mp[b]++;
    }
    bool flag = true;
    rep(i,4){
        if(mp[i] >= 3) flag = false;
    }
    if(flag){
        cout << "YES" << enld;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
package main

import (
	"fmt"
)

func main() {
	var h, n int
	fmt.Scan(&h, &n)

	cal := 0
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		cal = cal + a
		if h <= cal {
			fmt.Print("Yes")
			return
		}
	}
	fmt.Print("No")

}


Measured memory_bytes: 5504
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        a: u64, b: u64
    }

    println!("{}", if a <= 8 && b <= 8 {"Yay!"} else {":("});
}

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

#define fi first
#define se second
typedef pair<int, int> ii;

const int len = 1e5+5;
ii cnt[len];

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++){
        cnt[i].fi = 1;
        cnt[i].se = 0;
    }
    cnt[1].se = 1;

    while (m--){
        int a, b;
        scanf("%d %d", &a, &b);
        cnt[b].fi++;
        cnt[a].fi--;
        if (cnt[a].se)
            cnt[b].se = 1;
        if (cnt[a].fi == 0)
            cnt[a].se = 0;
    }

    int ans = 0;
    for (int i = 1; i <= n; i++)
        if (cnt[i].se) ans++;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
# n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
check = False
for i in range(n):
    if a[i] % 2 != 0:
        check = True
        break
count = 0
while check == False:
    for i in range(n):
        a[i] /= 2
        if a[i] % 2 != 0:
            check = True
            break
    count += 1
print(count)


Measured memory_bytes: 3188
#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
int cost[101][11];
int main(){
	int c,N,m,s,d,i,j,k,x;
	for(;scanf("%d%d%d%d%d",&c,&N,&m,&s,&d),N;){
		vector<map<int,int> >dist(N+1);
		memset(cost,99,sizeof(cost));
		for(k=0;k<m;k++){
			scanf("%d%d%d",&i,&j,&x);dist[i][j]=dist[j][i]=x;
		}
		for(i=0;i<=c;i++)cost[s][i]=0;
		for(;~c;c--){
			vector<bool>used(N+1);
			for(;;){ //dijkstra
				int m=9999999;
				for(i=1;i<=N;i++)if(!used[i]&&m>cost[i][c])m=cost[i][c];
				if(m==9999999)break;
				for(j=1;j<=N;j++)if(m==cost[j][c]){
					map<int,int>::iterator it=dist[j].begin();
					for(used[j]=1;it!=dist[j].end();it++){
						if(cost[it->first][c]>it->second+cost[j][c])cost[it->first][c]=it->second+cost[j][c];
						if(c&&cost[it->first][c-1]>it->second/2+cost[j][c])cost[it->first][c-1]=it->second/2+cost[j][c];
					}
				}
			}
		}
		printf("%d\n",cost[d][0]);
	}
}

Measured memory_bytes: 1080
h, w = map(int, input().split())

res = []
for i in range(h):
    line = input()
    if '#' in line:
        res.append(line)

ok_v_line = []
for i in range(w):
    v_line = [line[i] for line in res]
    if '#' in v_line:
        ok_v_line.append(i)

for line in res:
    final_line = [line[x] for x in ok_v_line]
    print(''.join(final_line))


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

using namespace std;

string s;
long long open, close;

long long cnt(long long u)
{
    if (u <= 0) return 0;
    return (u * (u+1)) / 2;
}

void Input()
{
    ios_base::sync_with_stdio(0);       cin.tie(0);

    cin >> s;
}

void Process()
{
    long long ans = 0;

    for (int i=0; i<=s.length(); i++)
    {
        if (i == s.length())
        {
            if (open < close) swap(open, close);
            ans += cnt(open) + cnt(close-1);

            cout << ans;        return;
        }

        if (s[i] == '>') close++;
            else open++;
        if (s[i] == '>' && s[i+1] == '<')
        {
            if (open < close) swap(open, close);
            ans += cnt(open) + cnt(close-1);
            open = close = 0;
        }
    }
}

int main()
{
    Input();
    Process();
    return 0;
}


Measured memory_bytes: 1172
#include <iostream>
using namespace std;
typedef long long ll;
ll n, k, a, ans, lar;

ll func(ll x, ll y){
    if (y == 0) {
        return x;
    } else {
        return func(y, x % y);
    }
}

int main(void){
    // Your code here!
    cin >> n >> k;
    for (ll i = 0; i < n; i++) {
        cin >> a;
        lar = max(lar, a);
        ans = func(ans, a);
    }
    cout << (k % ans || lar < k ? "IMPOSSIBLE" : "POSSIBLE");
}


Measured memory_bytes: 384
line = gets
line.chomp!

# /(\d+)\s+(\d+)/ =~ line
# a = $1.to_i
# b = $2.to_i

/(\w+)/ =~ line
a = $1

if (a == 'A') then
  print 'T'
elsif (a == 'T') then
  print 'A'
elsif (a == 'C') then
  print 'G'
elsif (a == 'G') then
  print 'C'
end


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

int main() {
	char c;
	cin >> c;
	if (c == 'A') cout << "T" << endl;
	else if (c == 'T') cout << "A" << endl;
	else if (c == 'C') cout << "G" << endl;
	else cout << "C" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>
#include<map>

// typedef std::pair<int, std::pair<int, int> > ipair;
typedef std::pair<int, int> ipair;
/*
bool greaterPair(const ipair& l, const ipair& r) {
   if (l.second.first == l.second.first) return l.second.second > l.second.second;
   else return l.second.first > l.second.first;
}
*/
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}


int main() {

   int N, M;
   std::cin >> N >> M;
   int P[M];
   int Y[M];
   int Ys[M];
   // int PY[N][M];
   std::vector< std::vector<int> > PY;
   PY.resize(N);
   // std::vector<<pair<int, int> > pairs(M);
   
   
   for (int i = 0; i < M; i++) {
      std::cin >> P[i] >> Y[i];
      // PY[P[i]][i] = Y[i];
      PY[P[i]-1].push_back(Y[i]);
      // make_pair(P[i], Y[i]);
      // y.push_back(ipair(i, std::make_pair(P[i], Y[i])));
   }
   for (int i = 0; i < N; i++) {
      std::vector<ipair> y;
      for (int j = 0; j < PY[i].size(); j++) {
         y.push_back(ipair(j, PY[i][j]));
      }
      std::sort(y.begin(), y.end(), lessPair);
      int j = 0;
      for (std::vector<ipair>::iterator it = y.begin(); it != y.end(); ++it) {
         // std::cout << it->first << " " << it->second << std::endl;
         PY[i][it->first] = j;
         j++;
      }
   }
   
   int count[N];
   for (int i = 0; i < N; i++) count[i] = 0;
   for (int i = 0; i < M; i++) {
      printf("%06d", P[i]);
      printf("%06d", PY[P[i]-1][count[P[i]-1]]+1);
      printf("\n");
      //std::cout << PY[P[i]-1][count[P[i]-1]] << std::endl;
      count[P[i]-1]++;
   }


   return 0;
}


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

struct line {
    long double k, b;
};

vector<line> vt;

long double intersect(line preLast, line last) {
    return - (double)(preLast.b - last.b) / (double)(preLast.k - last.k);
}

long double binarySearch(long double x) {
    int n = vt.size();
    int l = 1, r = n - 1, ans = -1;
    while (l <= r) {
        int m = (l + r) / 2;
        //cout << l << ' ' << m << ' ' << r << ' ' << ans << endl;
        line lcur = vt[m], lprev = vt[m - 1];
        long double xint = intersect(vt[m - 1], vt[m]);
        if (x >= xint) {
            ans = m, l = m + 1;
        } else {
            r = m - 1;
        }
    }
    //cout << vt[0].k * x + vt[0].b << endl;
    if (ans == -1)
        return vt[0].k * x + vt[0].b;
    else
        return vt[ans].k * x + vt[ans].b;
}

void addLine(line l) {
    while (vt.size() >= 2) {
        int n = vt.size();
        line preLast = vt[n - 2], last = vt[n - 1];
        //cout << "go " << preLast.k << ' ' << preLast.b << ' ' << last.k << ' ' << last.b << ' ' << l.k << ' ' << l.b << ' ' << intersect(preLast, last) << endl;
        //cout << - (preLast.b - l.b) * (preLast.k - last.k) << ' ' << - (preLast.b - last.b) * (preLast.k - l.k) << endl;
        long double x1 = intersect(preLast, last), x2 = intersect(preLast, l);
        if (x2 <= x1)
            vt.pop_back();
        else
            break;
    }
    vt.push_back(l);
}

void solve() {
    int n;
    long double c;
    cin >> n >> c;
    vector<long double> h(n);
    for (int i = 0; i < n; i++)
        cin >> h[i];
    vector<long double> dp(n);
    dp[0] = 0;
    addLine({-2 * h[0], h[0] * h[0]});
    for (int i = 1; i < n; i++) {
        dp[i] = binarySearch(h[i]) + h[i] * h[i] + c;
        //cout << binarySearch(h[i]) << ' ' << h[i] * h[i] << ' ' << c << ' ' << dp[i] << endl;
        addLine({-2 * h[i], dp[i] + h[i] * h[i]});
        //cout << vt.size() << endl;

        // cout << "line" << endl;
        // for (auto x : vt)
        //     cout << x.k << ' ' << x.b << endl;
        // cout << "endline" << endl;
    }
    cout << dp[n - 1];
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(0);
    solve();
    return 0;
}


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

const int N = 2005;
const int INF = 1e9;

int n, a[N * 2], pos[N * 2];
char c[N * 2];
int dp[N * 2][N];

struct Fenwick {
    int t[N];

    void upd(int x) {
        for(;x < N; x += x&(-x)) t[x] ++;
    }

    int get(int x) {
        int ret = 0;
        for (;x > 0;x -= x&(-x)) ret += t[x];
        return ret;
    }
} bitB[N * 2], bitW[N * 2];

int main() {
    //freopen("in.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for (int i = 1; i <= n + n; ++i) {
        cin >> c[i] >> a[i];
        if (c[i] == 'B') pos[a[i]] = i;
        else pos[a[i] + n] = i;
    }

    for (int i = n + n; i >= 1;i --) {
        bitB[i] = bitB[i + 1];
        bitW[i] = bitW[i + 1];
        if (c[i] == 'W') {
            bitW[i].upd(a[i]);
        } else {
            bitB[i].upd(a[i]);
        }
    }

    for (int i = 0; i <= n + n; ++i) {
        for (int j = 0; j <= n; ++j) {
            dp[i][j] = INF; // reset
        }
    }

    dp[0][0] = 0;
    for (int i = 0; i < n + n; ++i) {
        for (int b = 0; b <= i && b <= n; ++b) { // B
            if (dp[i][b] == INF) continue;
            int w = i - b; // W
            if (w < n) {
                int p = pos[w + 1 + n];
                dp[i + 1][b] = min(dp[i + 1][b], dp[i][b] + bitW[p + 1].get(w) + bitB[p + 1].get(b));
            }
            if (b < n) {
                int p = pos[b + 1];
                dp[i + 1][b + 1] = min(dp[i + 1][b + 1], dp[i][b] + bitW[p + 1].get(w) + bitB[p + 1].get(b));
            }
        }
    }

    cout << dp[n + n][n] << endl;
}


Measured memory_bytes: 94464
from functools import reduce

def cin():  return list(map(int,input().split()))

def cmb(n, r):
    INF = 10 ** 9 + 7
    r = min(n - r, r)
    if r == 0:  return 1
    numer = reduce(lambda x, y: (x * y) % INF, range(n, n - r, -1))
    denom = reduce(lambda x, y: (x * y) % INF, range(1, r + 1))
    return (numer * pow(denom, INF - 2, INF)) % INF

def nHr(n, r):  
    if n == 0:  return 1
    return cmb(n + r - 1, n)

INF = 10 ** 9 + 7

N, K = cin()
ans = [N - K + 1]
for i in range(2, K + 1):
    if N - K + 1 >= i:  cnt = cmb(N - K + 1, i) * nHr(K - i, i)
    else:  cnt = 0
    ans.append(cnt % INF)

for i in range(K):  print(ans[i])

Measured memory_bytes: 75520
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

int main() {
   char cs[] = "MARCH";
   Int xs[8] = {};
   Int n;
   std::cin >> n;
   rep(i,n) {
      std::string ss;
      std::cin >> ss;
      rep(k,5)
         if( cs[k] == ss[0] )
            xs[k] += 1;
   }
   Int res = 0;
   rep(i,1<<5) {
      guard( __builtin_popcountll(i) == 3 );
      Int t = 1;
      rep(k,5)
         if( i & (1<<k) )
            t *= xs[k];
      res += t;
   }
   printf("%ld\n", res);
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;

public class Main {

	//@2252  koukyoukoukokukikou
	public static void main(String[] args) throws IOException {
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		for(;;) {
		String s = reader.readLine();
		if (s.equals("#")) {
			break;
		}
		
		int t = 0; // 0Å 1¶ 2E
		int cnt = 0;
		
		for(int i = 0; i < s.length(); i++) {
			int t2 = 1;
			if ("yuiophjklnm".indexOf(s.charAt(i)) >=  0) {
				t2 = 2;
			}
			if (t != 0 && t != t2) {
				cnt++;
			}
			t = t2;
		}
		System.out.printf("%d\n", cnt);
		}
		
		reader.close();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 100010
#define aout(a) REP(i,sizeof(a)) cout << a[i] << " "; cout << endl;
#define vout(v) REP(i,v,size()) cout << v[i] << " "; cout << endl;
using namespace std;
using Graph = vector<vector<int>>;
 
int main(){
  int k; cin>>k;
  string s; cin>>s;
  if(s.size() <= k) cout << s;
  else{
    REP(i,k) cout << s[i];
    cout << "...";
  }
}

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

int main(){
  long long N;
  cin >> N;
  vector<int> A(N);
  A.at(0) = 0;
  for(int i = 1; i < N; i++){
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  vector<long long> B(1000000);
  for(int i = 1; i < N; i++){
    B.at(A.at(i) - 1) += 1;
  }
  for(int i = 0; i < N; i++){
    cout << B.at(i) << endl;
  }
}

Measured memory_bytes: 11916
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int count =0;
    string s1,s2;
    cin>>s1>>s2;

    for(int i=0;i<s1.size();i++)
    {
        if(s1[i]!=s2[i])
        {
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3468
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DDiceInLine solver = new DDiceInLine();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDiceInLine {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), k = in.nextInt();
            int[] p = in.readIntArray(n);
            double[] e = new double[n];
            for (int i = 0; i < n; i++) {
                e[i] = (1.0 + p[i]) / 2;
            }

            double[] prefix = new double[n + 1];
            for (int i = 0; i < n; i++) {
                prefix[i + 1] = prefix[i] + e[i];
            }

            double answer = 0;
            for (int i = 0; i + k < prefix.length; i++) {
                answer = Math.max(answer, prefix[i + k] - prefix[i]);
            }

            out.println(Util.formatDouble(answer));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readIntArray(int n) {
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = nextInt();
            }
            return x;
        }

    }

    static class Util {
        public static String formatDouble(double x) {
            return String.format("%.15f", x);
        }

        private Util() {
        }

    }
}



Measured memory_bytes: 43808
N = int(input())
l = []
for i in range(N):
    A, B = [int(_c) for _c in input().split(" ")]
    l.append({"A": A, "B": B, "sum": A + B})

l = sorted(l, key=lambda x: x["sum"], reverse=True)

a_total = 0
b_total = 0
for i, _l in enumerate(l):
    if i % 2 == 0:
        a_total += _l["A"]
    else:
        b_total += _l["B"]

print(a_total - b_total)

Measured memory_bytes: 45528
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <sstream>

using namespace std;

int main() {
    int a,b,i,j;
    char str[100][101];

    cin >> a >> b;

    for(i = 0;i < a;i++){
        for(j = 0;j < b;j++){
            cin >> str[i][j];
        }
    }

    for(i = -1;i <= a;i++){
        for(j = -1;j <= b;j++){
            if(i == -1 || i == a || j == -1 || j == b){
                cout << '#';
            }
            else{
                cout << str[i][j];
            }
        }
        cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int C[N-1], S[N-1], F[N-1];
    for(int i = 0; i < N-1; i++){
        cin >> C[i] >> S[i] >> F[i];
    }

    int t;
    for(int i = 0; i < N; i++){
        t = 0;
        for(int j = i; j < N-1; j++){
            if(t < S[j]){
                t = S[j];
            }else if(t % F[j] != 0){
                t = t + F[j] - t % F[j];
            }
            t = t + C[j];
        }
        cout << t << endl;
    }


    return 0;
}

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

#define ll long long
vector < ll > val; long long N;
void euclid(ll a , ll b , ll &x , ll &y){!b ? (x = 1 , y = 0) : (euclid(b , a % b , y , x) , y -= a / b * x);}

int main(){
	cin >> N; N *= 2; ll ans = 2 * N;
	for(int i = 2 ; 1ll * i * i <= N ; ++i)
		if(N % i == 0){ll pw = 1; while(N % i == 0){N /= i; pw *= i;} val.push_back(pw);}
	if(N != 1) val.push_back(N);
	for(int i = 1 ; i < 1 << val.size() ; ++i){
		ll p1 = 1 , p2 = 1; for(int j = 0 ; j < val.size() ; ++j) (i >> j & 1 ? p1 : p2) *= val[j];
		ll x , y; euclid(p1 , p2 , x , y); if(x <= 0) x += p2;
		ans = min(ans , p1 * x - 1);
	}
	cout << ans; return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int main() {
	int w,h,k, n,tu,now1,now2,fut1,fut2; int ans = 0;
	cin >> w >> h >> n>>now1>>now2;
	for (int i = 1; i < n; i ++) {
		int d1 = 0; int d2 = 0;
		cin >> fut1 >> fut2;
		d1 = now1 - fut1;
		d2 = now2 - fut2;
		if (d1*d2 >= 0) {
			ans = ans + max(abs(d1), abs(d2));
		}
		else {
			ans = ans + abs(d1) + abs(d2);
		}
		now1 = fut1;
		now2 = fut2;
	}
	cout << ans<<endl;
}



Measured memory_bytes: 3092
import math
N = int(input())
cnt_list = [0] * N
for i in range(1, N + 1):
    for j in range(i, N + 1, i):
        cnt_list[j - 1] += 1
ans = 0
for h in range(1, N + 1):
    ans += h * cnt_list[h -1]
print(ans)

Measured memory_bytes: 151700
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

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

	if ((a * b) % 2 == 0) {
		cout << "Even" << endl;
		return 0;
	}
	cout << "Odd" << endl;
	return 0;

}


Measured memory_bytes: 256
import java.util.*;
class Main{
	Scanner sc=new Scanner(System.in);
	int[][][] gundam=new int[4][3][10];
	void Main(){
		int N=sc.nextInt();
		int b,f,r,v;
		for(int i=0;i<N;i++){
			b=sc.nextInt();
			f=sc.nextInt();
			r=sc.nextInt();
			v=sc.nextInt();
			gundam[b-1][f-1][r-1]+=v;
		}
		for(int i=0;i<4;i++){
			output(i);
			if(i!=3)System.out.println("####################");
		}
	}
	void output(int b){
		for(int i=0;i<3;i++){
			for(int j=0;j<10;j++){
				System.out.print(" "+gundam[b][i][j]);
			}
			System.out.println();
		}
	}
		public static void main(String[]args){
			new Main().Main();
	}
}

Measured memory_bytes: 21064
n = int(input())
pos = [0] + [int(i) for i in input().split()] + [0]

s = 0
for i in range(n+1):
    s += abs(pos[i+1] - pos[i])

for i in range(1, n+1):
    cost = s + abs(pos[i+1] - pos[i-1]) - abs(pos[i] - pos[i-1]) - abs(pos[i+1] - pos[i])
    print(cost)

Measured memory_bytes: 14048
#include <iostream>
int main()
{
  int d;
  while (std::cin >> d) {
    int n = 0, s = 0;
    while (n < 600) {
      s += n * n * d;
      n += d;
    }
    std::cout << s << std::endl;
  }
  return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 100005;

int n;
int a[N];

int main() {

    FAST;

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = (a + d - 1) / d;
    int y = (c + b - 1) / b;
    cout << ((x >= y) ? "Yes\n" : "No\n");
    return 0;
}


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

const int M = 100;
const int Inf = 1e9;
int N;
int x[M], y[M], h[M];
int bufx, bufy, bufh;
int X, Y, H;

bool solve(int cx, int cy) {
  int buf = bufh + abs(bufx - cx) + abs(bufy - cy);
  rep(i, N) {
    int tmp = h[i] + abs(x[i]-cx) + abs(y[i]-cy);
    if (h[i]) {
      if (buf != tmp) return false;
    }
    else {
      if (buf > tmp) return false;
    }
  }
  X = cx; Y = cy; H = buf;
  return true;
}

int main() {
  cin >> N;
  rep(i, N) cin >> x[i] >> y[i] >> h[i];
  rep(i, N) {
    if (h[i]) {
      bufx = x[i]; bufy = y[i]; bufh = h[i];
      break;
    }
  }
  for (int i = 0; i <= 100; ++i) {
    for (int j = 0; j <= 100; ++j) {
      if (solve(i, j)) printf("%d %d %d\n", i, j, H);
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a, n) priority_queue<int>a(n)
#define PQmin(a, n) priority_queue< int, std::vector<int>, std::greater<int> >a(n)

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int k,a,b;
    cin>>k>>a>>b;
    if(a+1>=b){
        cout<<k+1<<endl;
    }
    else{
        int cnt=0;
        int yen=0;
        ll biscuit=1;
        while(cnt<=k-2){
            if(yen>=1){
                yen--;
                biscuit+=b;
            }
            else if(biscuit>=a){
                biscuit-=a;
                yen++;
            }
            else{
                biscuit++;
            }
            cnt++;
        }
        if(yen>=1){
            biscuit+=b;
        }
        else{
            biscuit++;
        }
        cout<<biscuit<<endl;
    }





    return 0;
}


Measured memory_bytes: 256
import sys

class Dice(object):
    def __init__(self, dice):
        self.__dice = tuple(dice)

    def roll_north(self):
        self.__dice = (self.__dice[1], self.__dice[5], self.__dice[2],
                       self.__dice[3], self.__dice[0], self.__dice[4])

    def roll_south(self):
        self.__dice = (self.__dice[4], self.__dice[0], self.__dice[2],
                       self.__dice[3], self.__dice[5], self.__dice[1])

    def roll_west(self):
        self.__dice = (self.__dice[2], self.__dice[1], self.__dice[5],
                       self.__dice[0], self.__dice[4], self.__dice[3])

    def roll_east(self):
        self.__dice = (self.__dice[3], self.__dice[1], self.__dice[0],
                       self.__dice[5], self.__dice[4], self.__dice[2])

    def number(self, face_id):
        return self.__dice[face_id - 1]

    def equals(self, dice):
        for i in range(4):
            for j in range(4):
                if self.__dice == dice.__dice:
                    return True
                dice.roll_north()
            dice.roll_west()
        return False

n = int(sys.stdin.readline())
dices = []
for i in range(n):
    dices.append(Dice([int(a) for a in sys.stdin.readline().split()]))

for i in range(n):
    for j in range(i + 1, n):
        if dices[i].equals(dices[j]):
            print("No")
            exit(0)
print("Yes")

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

int main(){
    int n;
    cin >> n;
    char s[n];
    for(int i=0;i<n;i++)cin >> s[i];
    char t[n];
    for(int i=0;i<n;i++)cin >> t[i];
    int count=n;
    for(int i=0;i<n;i++){
        bool a = true;
        for(int j=0;j<n-i;j++){
            if(t[j]!=s[i+j])a=false;
        }
        if(a==true)break;
        count++;
    }
    cout << count << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
vector<ll> divisor(ll x){
	vector<ll> div;
	for(int i=1;i*i<=x;i++){
		if(i*i!=x && x%i==0){
			div.pb(i);
			div.pb(x/i);
		}
		else if(x%i==0) div.pb(i);
	}
	return div;
}
vector<ll> vectorprime(ll x){
	vector<bool> is_prime(x+1);
	vector<ll> prime;
	rep(i,x+1) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=x;i++){
		if(is_prime[i]){
			prime.pb(i);
		}
		for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
	}
	return prime;
}

//a,b x
int main(){
	ll A,B; cin>>A>>B;
	if(A==1) A+=100;
	if(B==1) B+=100;

	cout<<(A<B?"Bob":A==B?"Draw":"Alice");	
	
}

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

#define int long long
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 a[200010];
int b[200010];

int n, m, k;
int solve(int k){
	int l = 0, r = m+1;

	while(r-l > 1){
		int m = (r+l)/2;
		if(b[m] <= k) l = m;
		else r = m;
	}

	return l;
}

signed main(){
	cin >> n >> m >> k;

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

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

	int ans = 0;
	for(int i = 0;i <= n;i++){
		if(a[i] > k) break; 
		chmax(ans, i+solve(k-a[i]));
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6728
#include <bits/stdc++.h>
using namespace std;
#define FOR(x,to) for(x=0;x<(to);x++)

int main()
{
    int a[2];cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if (a[0]+a[1]==a[2]) {
        cout<<"Yes";
    }
    else std::cout << "No" << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
char a[1000000][13];
void init()
{
    for(int i=0;i<1000000;i++)
        a[i][0] = '\0';
}
int getkey(char s[])
{
    int i = 0,key = 0,mul = 1,j;
    for(i=0;s[i]!='\0';i++)
    {
        switch(s[i]){
            case 'A':j = 1;break;
            case 'G':j = 2;break;
            case 'C':j = 3;break;
            case 'T':j = 4;
        }
        key += mul*j;
        mul *= 5;
    }
    return key;
}
int h1(int key)
{
    return key%1000000;
}
int h2(int i)
{
    return i;
}
bool insert(char s[])
{
    int key = getkey(s);
    int i,index;
    for(i=0;i<1000000;i++)
    {
        index = (h1(key)+h2(i))%1000000;
        if(a[index][0]=='\0')
        {
            strcpy(a[index],s);
            return true;
        }
        else if(strcmp(a[index],s)==0)
            return true;
        else
            continue;
    }
    return false;

}
bool find(char s[])
{
    int key,i,index;
    key = getkey(s);
    for(i=0;i<1000000;i++)
    {
        index = (h1(key)+h2(i))%1000000;
        if(a[index][0]=='\0')
            return false;
        else if(strcmp(a[index],s)==0)
            return true;
        else
            continue;
    }
    return false;
}
int main()
{
    int n;
    char s1[7],s2[13];
    cin>>n;
    init();
    while(n--)
    {
        cin>>s1>>s2;
        if(s1[0]=='i')
        {
            insert(s2);
        }
        else
        {
            if(find(s2))
                cout<<"yes"<<endl;
            else
                cout<<"no"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 15784