akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<complex>

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

#define pb push_back

using namespace std;


#define EPS (1e-10)
typedef complex<double> P;

class L:public vector<P>{
	public:
	L(P a, P b){
		this->pb(a);
		this->pb(b);
	}
};

double cross(P a, P b){
	return (a.real()*b.imag() - a.imag()*b.real());
}

bool isCross(P a1, P a2, P b1, P b2){
	
	P a = a2-a1;
	P b = b2-b1;;
	if(abs(cross(b,a))>EPS)return true;
	return false;
}

P intersection_l(P a1, P a2, P b1, P b2){
	P a = a2-a1;
	P b = b2-b1;
	/*
	cout<<a1<<" "<<a2<<" "<<b1<<" "<<b2<<endl;
	cout<<"c1 = "<<cross(b,b1-a1)<<endl;
	cout<<"c2 = "<<cross(b,a)<<endl;
	*/
	return a1 + a*cross(b,b1-a1)/cross(b,a);
}

int n;
vector<L> dat;
bool input(){
	cin>>n;
	if(n==0)return false;
	
	dat.clear();
	rep(i,n){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		dat.pb(L(P(a,b),P(c,d)));
	}
	
	return true;
}

double norm(P x){
	return real(x)*real(x) + imag(x)*imag(x);
}

bool isSame(P a, P b){
	double len = sqrt(norm(a-b));
	if(len<EPS)return true;
	return false;
}

bool isOut(P a){
	double x = a.real();
	double y = a.imag();
	
	if(abs(x)+EPS>=100)return true;
	if(abs(y)+EPS>=100)return true;
	return false;
}


void solve(){
	
	int ans = 1;
	rep(i,n){
		vector<P> pos;
		rep(j,i){
			if(isCross(dat[i][0], dat[i][1], dat[j][0], dat[j][1])){
				
				pos.pb(intersection_l(dat[i][0], dat[i][1], dat[j][0], dat[j][1]));
			
			}
		}
		
		rep(j,pos.size()){
			bool hit = false;
			rep(k,j){
				if(isSame(pos[j], pos[k]))hit=true;
			}
			if(isOut(pos[j]))hit=true;
			
			if(hit){
				pos.erase(pos.begin()+j);
				j--;
			}
			
		}
		ans += pos.size()+1;
	}
	cout<<ans<<endl;
}

int main(){
	while(input())solve();
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n, k;
  cin >> n >> k;

  ll t = n / k;

  ll ans = min({abs(n - k * t), abs(n - k), abs(n - k * (t + 1))});

  cout << min(ans, n) << ln;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define help freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);

int main()
{
    int n;
    cin >> n;
    ll mod = 1000000007;
    ll prefix[n + 5];
    prefix[0] = 0;
    ll arr[n + 5];
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        prefix[i] = prefix[i - 1] + arr[i];
    }
    ll ans = 0ll;

    for (int i = 1; i <= n; i++)
    {
        ll x = (prefix[n] - prefix[i]);
        x = x % mod;
        ans = ans + (arr[i] * x);
        ans = ans % mod;
    }

    if (ans >= mod)
        ans = ans % mod;

    if (ans < 0)
        ans = ans + mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6756
def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    dp = [[0] * (N+1) for _ in range(N+1)]
    # 左側をとる: 区間 [i+1,j)[i+1,j) に遷移
    # 右側をとる: 区間 [i,j−1)[i,j−1) に遷移
    for L in range(1, N + 1):
        i = 0
        while i + L <= N:
            j = i + L
            # 先手番
            if (N - L) % 2 == 0:
                dp[i][j] = max(dp[i + 1][j] + A[i], dp[i][j - 1] + A[j - 1])
            # 後手番
            else:
                dp[i][j] = min(dp[i + 1][j] - A[i], dp[i][j - 1] - A[j - 1])
            i += 1

    print(dp[0][N])


if __name__ == "__main__":
    resolve()

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


public class Main {
	
	public static class Path implements Comparable<Path>{
		int h, start, end;
		
		public Path(int h, int start, int end) {
			super();
			this.h = h;
			this.start = start;
			this.end = end;
		}

		@Override
		public int compareTo(Path arg0) {
			return this.h - arg0.h;
		}
		
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			final int m = sc.nextInt();
			final int a = sc.nextInt();
			
			if(n == 0 && m == 0 && a == 0){
				break;
			}
			
			int[] ans = new int[n];
			for(int i = 0; i < n; i++){
				ans[i] = i + 1;
			}
			
			Path[] paths = new Path[m];
			for(int i = 0; i < m; i++){
				final int h = sc.nextInt();
				final int p = sc.nextInt() - 1;
				final int q = sc.nextInt() - 1;
				
				paths[i] = new Path(h, p, q);
			}
			
			Arrays.sort(paths);
			
			for(int i = 0; i < m; i++){
				int tmp = ans[paths[i].start];
				ans[paths[i].start] = ans[paths[i].end];
				ans[paths[i].end] = tmp;
			}
			
			System.out.println(ans[a - 1]);
		}
		
	}

}

Measured memory_bytes: 12000
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define ll long long
#define For(i, j, k) for(int i = j; i <= (int)k; ++ i)
#define Forr(i, j, k) for(int i = j; i >= (int)k; -- i)
#define INF 0x3f3f3f3f
using namespace std;

const int maxn = 2e5 + 5;

int n, m;
int dep[maxn], tot[2];
int cnt, Begin[maxn], Next[maxn<<1], To[maxn<<1];
bool vis[maxn], flag = true;

inline void file(){
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
}

inline int Read(){
	int x = 0;	char c = getchar();
	for(; !isdigit(c); c = getchar());
	for(; isdigit(c); c = getchar())	x = (x << 3) + (x << 1) + (c ^ 48);
	return x;
}

inline void Add(int x, int y){
	To[++cnt] = y;
	Next[cnt] = Begin[x];
	Begin[x] = cnt;
}

void dfs(int x, int f){
	vis[x] = 1;    ++ tot[dep[x]];
	for(int i = Begin[x], v; i; i = Next[i]){
		v = To[i];
		if(v == f)	continue;
		if(vis[v]){
			if(dep[v] == dep[x]){
				flag = false;	continue;
			}
		}
		else{
			dep[v] = dep[x] ^ 1;	dfs(v, x);
		}
	}
}

int main(){
	int x, y;
	n = Read();  m = Read();
	For(i, 1, m){
		x = Read();  y = Read();
		Add(x, y);  Add(y, x);
	}
	
	dfs(1, 0);
	if(flag)	printf("%lld", 1ll * tot[0] * tot[1] - m);
	else	printf("%lld", 1ll * n * (n-1) / 2 - m);
	return 0;
}

Measured memory_bytes: 5120
c1 = input()
c2 = input()

length = len(c1)
list1 = {}
list2 = {}
ok = True
for i in range(length):
    if(c2[i] in list1):
        if(list1[c2[i]] != c1[i]):
            ok = False
            exit
    else:
        list1[c2[i]] = c1[i]

    if(c1[i] in list2):
        if(list2[c1[i]] != c2[i]):
            ok = False
            exit
    else:
        list2[c1[i]] = c2[i]

if(ok):
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    int cnt4=0, cntx=0;
    bool no2 = true;
    for (int i=0; i<n; i++) {
        int a; cin >> a;
        if (a % 4 == 0) cnt4++;
        else if (a % 2 != 0) cntx++;
    }
    if (cnt4 + cntx < n) cntx++;
    cout << (cnt4 + 1 >= cntx ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 256
// * It's time to PLAY !

#include <bits/stdc++.h>

using namespace std;

#ifdef EXILE
#include "prettyprint.hpp"
#define debug(args) cerr << #args << " = " << args << endl;
#else
#define debug(args) 20040119
#endif

#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

void OPEN(string str)
{
    freopen((str + ".inp").c_str(), "r", stdin);
    freopen((str + ".out").c_str(), "w", stdout);
}

const int N = 301;

double dp[N][N][N];
vector<int> cnt(4);

void PLAY()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        ++cnt[x];
    }
    for (int k = 0; k <= n; ++k)
    {
        for (int j = 0; j + k <= n; ++j)
        {
            for (int i = 0; i + j + k <= n; ++i)
            {
                dp[i][j][k] = 0;
                if (i == 0 && j == 0 && k == 0)
                {
                    continue;
                }
                dp[i][j][k] += n;
                if (i > 0)
                    dp[i][j][k] += i * dp[i - 1][j][k];
                if (j > 0)
                    dp[i][j][k] += j * dp[i + 1][j - 1][k];
                if (k > 0)
                    dp[i][j][k] += k * dp[i][j + 1][k - 1];
                dp[i][j][k] *= 1.0 / (i + j + k);
            }
        }
    }
    cout << fixed << setprecision(50) << dp[cnt[1]][cnt[2]][cnt[3]];
}

signed main()
{
    fastio;
    PLAY();
    return 0;
}

Measured memory_bytes: 213248
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int rate = scan.nextInt();
        
        if (rate < 1200) {
            System.out.println("ABC");
        } else {
            System.out.println("ARC");
        }
        scan.close();
    }
}

Measured memory_bytes: 22608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class abc160_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String[] S = in.next().split("");
            boolean pair1 = false;
            boolean pair2 = false;
            int i = 3;
            if (S[i - 1].compareToIgnoreCase(S[i]) == 0) {
                if (pair1 == false) {
                    pair1 = true;
                }
            }
            i = 5;
            if (S[i - 1].compareToIgnoreCase(S[i]) == 0) {
                if (pair2 == false) {
                    pair2 = true;
                }
            }
            if ((pair1 == true) && (pair2 == true)) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }
}



Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, A, B;
ll a[100010], ans;

int main()
{
	scanf("%d%d%d",&n,&A,&B);
	ll l = 0, r = 0;
	for(int i = 1; i <= n; i ++)
		scanf("%lld", &a[i]), r += a[i] / A + 1;
	A -= B;
	while(l <= r)
	{
		ll mid = (l + r) >> 1, t = 0;
		for(int i = 1; i <= n; i ++)
		{
			ll g = a[i] - mid * B;
			if(a[i] / B + 3 < mid || g < 0) g = 0;
			t += (g + A - 1) / A;
		}
		if(t > mid) l = mid + 1;
		else r = mid - 1, ans = mid;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(int n){
	string in;
	ll mn=-LINF,mx=LINF;
	vl v(n);
	rep(i,n){
		cin>>in;
		if(in=="x")v[i]=LINF;
		else v[i]=stoll(in);
	}
	rep(i,n){
		if(v[i]==LINF){
			if(i%2==0){
				if(i!=0)chmin(mx,v[i-1]-1);
				if(i!=n-1)chmin(mx,v[i+1]-1);
			}
			else{
				chmax(mn,v[i-1]+1);
				if(i!=n-1)chmax(mn,v[i+1]+1);
			}
		}
	}
	bool safe=true;
	rep(i,n){
		if(v[i]==LINF)v[i]=mx;
		if(i==0)continue;
		safe&=(i%2==0?(v[i-1]>v[i]):(v[i-1]<v[i]));
	}
	if(safe){
		if(mx==mn)cout<<mx<<"\n";
		else cout<<"ambiguous"<<"\n";
	}
	else cout<<"none"<<"\n";

}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n,n)solve(n);
}



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

int main() {
    string s; cin >> s;
    if(s[s.length() - 1] == '2' ||s[s.length() - 1] == '4' ||s[s.length() - 1] == '5' ||s[s.length() - 1] == '7' ||s[s.length() - 1] == '9') cout << "hon";
    else if(s[s.length() - 1] == '0' || s[s.length() - 1] == '1' || s[s.length() - 1] == '6' || s[s.length() - 1] == '8') cout << "pon";
    else cout << "bon";

    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>

int main(){
	int n,k;
	int paintPattern = 1;
	scanf("%d %d",&n,&k);
	
	paintPattern *= k;
	n--;
	
	for(n;n>0;n--){
		paintPattern *= (k-1);
	}
	
	printf("%d\n",paintPattern);
	
	return 0;
	
}

Measured memory_bytes: 128
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	string s;
	cin>>s;
	int v=0;
	for(auto r:s){
		v+=r-'0';
		v%=9;
	}
	if(v%9==0){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	#ifdef ANIKET_GOYAL
		// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
	#endif
}

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

using namespace std;

#define FOR(i,l,r) for( int i = l; i < r; i++ )

int n;
vector<double> p;

int main() {
    cin>>n;
    double dp[n+1][n+1];
    p.assign(n,0);
    FOR(i,0,n) cin>>p[i];
    dp[0][0] = 1;
    FOR(i,1,n+1) {
        FOR(j,0,n+1) {
            // n,m -> n-1,m-1+1W or n-1,m+1L
            dp[i][j] = 0;
            if( j-1 >= 0 ) dp[i][j] += dp[i-1][j-1]*p[i-1];
            if( i-1 >= j ) dp[i][j] += dp[i-1][j]*(1.0-p[i-1]);
        }
    }
    double ans = 0.0;
    FOR(j,0,n+1) {
        if( j > n-j ) {
            ans += dp[n][j];
        }
    }
    cout<<setprecision(15)<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 70528
from collections import Counter

n = int(input())
keys = set()
S = []
ans = {}
for i in range(n):
    counter = Counter(input())
    if i == 0:
        keys = set(counter.keys())
    else:
        keys = keys.intersection(counter.keys())
    tmp = {}
    for k in keys:
        tmp[k] = min(ans.get(k, 100), counter[k])
    ans = tmp
        
s = ''
for k in ans.keys():
    s += k * ans[k]
s = sorted(s)
sa = ''
for i in s:
    sa += i
print (sa)

Measured memory_bytes: 3444
#include<cstdio>
#include<functional>
#include<algorithm>

using namespace std;
int main(void)
{
	int n,i,j,a[200000],f[200000],flg;
	long long k,sum,lo,hi,m,x;
	scanf("%d %lld",&n,&k);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	for(i=0;i<n;i++)	scanf("%d",&f[i]);
	sort(a,a+n);
	sort(f,f+n,greater<int>() );
	lo=0;	hi=(long long)a[n-1]*f[0];
	while(lo<=hi)	{
		m=(lo+hi)/2;
//		printf("%lld\n",m);
		sum=0;
		flg=1;
		for(i=0;i<n;i++)	{
			x=m/f[i];
			if(x<a[i])	{
				sum+=a[i]-x;
				if(sum>k)	{
					flg=0;	break;
				}
			}
		}
		if(flg==1)	hi=m-1;
		else lo=m+1;
	}
	printf("%lld\n",lo);
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
int main(void) {
	int h, w;
	cin >> h >> w;
	char c[50][50];
	for (int i = 0; i != h; i++) {
		for (int j = 0; j != w; j++) {
			cin >> c[i][j];
		}
	}
	for (int i = 0; i != h; i++) {
		for (int j = 0; j != w; j++) {
			if(c[i][j] == '#'){
				if (c[i - 1][j] != '#' && c[i][j - 1] != '#' && c[i][j + 1] != '#' && c[i + 1][j] != '#') {
					cout << "No\n";
					return 0;
				}
			}
		}
	}
	cout << "Yes\n";
	return 0;
}

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

const int INF = 1e9;

int main(void){
    int i,n;
    long long m=1-INF,s=2*INF-1,rr;
 
    std::cin >> n;
    for(i=0;i<n;i++){
        std::cin >> rr;
        m = max(rr - s,m);
        s = min(rr,s); 
    }
 
    cout << m << "\n";
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back

ll f[101010], rf[101010];
ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    REP(i, 1, 101010) f[i] = (f[i - 1] * i) % mod;
    REP(i, 0, 101010) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
    ll a = f[n]; // = n!
    ll b = rf[n-k]; // = (n-k)!
    ll c = rf[k]; // = k!

    ll bc = (b * c) % mod;

    return (a * bc) % mod;
}

int main(){
    init();
    ll N,K; cin>>N>>K;
    vec d(N);
    rep(i,N) cin>>d.at(i);
    sort(d.begin(),d.end());
    ll ans=0;
    REP(i,K-1,N){
        ans+=d.at(i)*C(i,K-1);
        ans=ans%mod;
    }
    rep(i,N-K+1){
        ll X=d.at(i)*C(N-i-1,K-1);
        X=X%mod;
        if(X>ans) ans+=mod;
        ans-=X;
    }
    cout<<ans%mod<<endl;

}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define N 100005
#define F first
#define S second
using namespace std;

struct st{
	int s, e, d;
};
int n, ans, b[N];
pair<int, int> x[N], y[N];
vector<st> a;

bool cmp(st p, st q) {return p.d < q.d;}

int f(int p) {
	if (b[p] == p) return p;
	return b[p] = f(b[p]);
}

int main()
{
	int i, t1, t2;
	cin >> n;
	for (i = 1; i <= n; i++) scanf("%d %d", &x[i].F, &y[i].F), x[i].S = y[i].S = i;
	for (i = 1; i <= n; i++) b[i] = i;
	sort(x + 1, x + n + 1);
	sort(y + 1, y + n + 1);
	for (i = 2; i <= n; i++) {
		a.push_back({x[i - 1].S, x[i].S, x[i].F - x[i - 1].F});
		a.push_back({y[i - 1].S, y[i].S, y[i].F - y[i - 1].F});
	}
	sort(a.begin(), a.end(), cmp);
	for (i = 0; i < a.size(); i++) {
		t1 = f(a[i].e), t2 = f(a[i].s);
		if (t1 != t2) b[t1] = t2, ans += a[i].d;
	}
    cout << ans << endl;
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int x; cin >> x;
  int i = 1;
  int maxN = -1;
  while(i * i <= x) {
    for(int j = 1; j <= x; j++ ) {
      if(pow(i, j) <= x) {
        if(maxN < pow(i,j))
          maxN = pow(i,j);
      }
    }
    i++;
  }
  cout << maxN << endl;

  return 0;
}




Measured memory_bytes: 512
N = int(input())
lis = []
for i in range(N):
    lis.append(int(input()))
max_value = max(lis)
max_index = lis.index(max_value)
max_count = lis.count(max_value)
next_max = sorted(lis)[-2]
if max_count ==1:
    for i in range(N):
        if i == max_index:
            print(next_max)
        else:
            print(max_value)
else:
    for i in range(N):
            print(max_value)    


Measured memory_bytes: 19068
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
 
double expValue(int val){
    double ans = 0;
    for(int i = 0; i <= val; i++) ans += i;
    return ans / val;
}
 
int main()
{
    int n, k;
    cin >> n >> k;
    long double tot = 0;
    vector<double> table(200005);
    for(int i = 1; i <= n; i++){
        int a;
        cin >> a;
        table[i] = expValue(a);
    } 
    for(int i = 1; i <= k; i++) tot += table[i];
    long double max = tot;
    for(int i = 1; i + k <= n; i++){
        tot -= table[i];
        tot += table[i+k];
        if(max < tot) max = tot;
    }
    printf("%Lf", max);
}


Measured memory_bytes: 4832
a = [input().split() for i in range(2)]
li = a[-1]
lis = [int(i) for i in li]
lis
n = int(a[0][0])
cnt = 0
for i in range(0,n-2):
    l = [lis[i],lis[i+1],lis[i+2]]
    l_sort = sorted(l)
    if(l[1] == l_sort[1]):
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
typedef long long int ll;



int main(int argc, char const *argv[])
{
	vector<ll> v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(v.begin(), v.end());

	cout << v[0]+v[1] << endl;
}

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


int main(){
  int h,a;
  cin>>h>>a;
  int c=0;
  while(h>0){h-=a;c++;}
  cout<<c<<endl;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORR(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = b - 1; i >= a; i--)
#define FORI(i, a, b, inc) for (int i = a; i <= b; i += inc)
#define FORRI(i, a, b, inc) for (int i = a; i < b; i += inc)
#define REPD(i, a, b, dec) for (int i = b - 1; i >= a; i -= dec)
#define SORT(a, n) sort(a, a + n, greater<int>())
#define PREC(n) cout << fixed << setprecision(n)
#define ULL unsigned long long
#define FT first
#define SN second
#define Vsort(v) sort(v.begin(), v.end())
#define FORV(it, l) for (auto it : l)
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define RESET(a, b) memset(a, b, sizeof(a))
#define PI acos(-1)
#define S " "
typedef vector<int> VC;
typedef vector<VC> VCC;
typedef pair<int, int> PR;
typedef vector<PR> VPR;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef set<PR> STP;
void solve()
{
    /*Md. Bokhtiar Nadeem Shawon
    Institute of Information Technology
    Jahangirnagar University
    */
    int a, sum;
    cin >> a;
    sum = a + (a * a) + (a * a * a);
    cout << sum << endl;

}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*int t;
    cin >> t;
    while (t--)*/
        solve();

    return 0;
}

Measured memory_bytes: 3640
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<ll>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll K, X;
    cin >> K >> X;
    ll b = max(X - K + 1, -1000000LL);
    ll e = min(X + K - 1 + 1, +1000000LL);
    for (ll i= b;i<e;++i)
    {
        cout << i << " ";
    }
    return 0;
}

Measured memory_bytes: 3156
import java.util.Scanner;


public class Main{

	public static void main(String args[]){

		long MOD=1000000007L;

		Scanner sc = new Scanner(System.in);

		int n=sc.nextInt();

		long a[]=new long[n];
		long sum=0L;

		for(int i=0;i<n;++i){
			a[i]=sc.nextLong();
			if(i%2==0)sum=sum+a[i];
			else sum=sum-a[i];

		}

		long a1=sum;

		System.out.print(a1+" ");
		for(int i=0;i<n-2;++i){
			long a2=2*a[i]-a1;
			System.out.print(a2+" ");
			a1=a2;
		}
		System.out.println(2*a[n-2]-a1);

	}
}

Measured memory_bytes: 63312
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
int main(){
    int h=in(),w=in(),k=in(),int_max=2000000;
    int sx=in()-1,sy=in()-1,tx=in()-1,ty=in()-1;
    vector<vec> a(h,vec(w)),cnt(h,vec(w,int_max));
    cnt[sx][sy]=0;
    rep(i,h){
        string s=stin();
        rep(j,w){
            if(s[j]=='.')a[i][j]=0;
            else a[i][j]=1;
        }
    }
    priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>> que;
    que.push(mp(0,mp(sx,sy)));
    while(!que.empty()){
        int cost = que.top().first;
        int x=que.top().second.first;
        int y=que.top().second.second;
        que.pop();
        if(x==tx && y==ty){
            cout<<cost<<endl;
            return 0;
        }
        int xx=x-1;
        int yy=y-1;
        while(xx >= 0 && a[xx][y]==0 && xx >= x-k){
            if(cnt[xx][y] == int_max){
                cnt[xx][y]=cost+1;
                que.push(mp(cost+1,mp(xx,y)));
            }else if(cnt[xx][y] <= cost) break;
            xx--;
        }
        while(yy >= 0 && a[x][yy]==0 && yy >= y-k){
            if(cnt[x][yy]==int_max){
                cnt[x][yy]=cost+1;
                que.push(mp(cost+1,mp(x,yy)));
            }else if(cnt[x][yy] <= cost) break;
            yy--;
        }
        xx=x+1;
        yy=y+1;
        while(xx < h && a[xx][y]==0 && xx <= x+k){
            if(cnt[xx][y]==int_max){
                cnt[xx][y]=cost+1;
                 que.push(mp(cost+1,mp(xx,y)));
             }else if(cnt[xx][y] <= cost) break;
            xx++;
        }
        while(yy < w && a[x][yy]==0 && yy <= y+k){
            if(cnt[x][yy]==int_max){
                cnt[x][yy]=cost+1;
                que.push(mp(cost+1,mp(x,yy)));
            }else if(cnt[x][yy] <= cost) break;
            yy++;
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 14952
<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}

/*		START		*/
$K = getq(1);
echo max($K[0]*$K[1],$K[2]*$K[3]);
?>

Measured memory_bytes: 4604
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll n = inp1;
    vector<ll> a = inp(n+1), b = inp(n);
    ll ans = 0;

    REP(i, n) {
        ll x = min(a[i], b[i]);
        ans += x;
        a[i] -= x;
        b[i] -= x;
        ll y = min(a[i+1], b[i]);
        ans += y;
        a[i+1] -= y;
        b[i] -= y;
    }
    say(ans);
    
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

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

  ll ans = 0;

  if (k < 3) {
    string t = "";
    rep(i, k) t += s;
    rep(i, t.size()) {
      int j = i;
      while (j + 1 < t.size() && t[i] == t[j + 1]) j++;
      ans += (j - i + 1) / 2;
      i = j;
    }
  } else {
    if (s[0] != s[s.size() - 1]) {
      rep(i, s.size()) {
        int j = i;
        while (j + 1 < s.size() && s[i] == s[j + 1]) j++;
        ans += (j - i + 1) / 2;
        i = j;
      }
      ans *= k;
    } else {
      int l = 0;
      int r = s.size() - 1;
      // cout << l << ' ' << r << endl;
      while (l + 1 < s.size() && s[0] == s[l + 1]) l++;
      while (r - 1 >= 0 && s[s.size() - 1] == s[r - 1]) r--;
      // cout << l << ' ' << r << endl;
      if (l >= r) {
        ans = k * s.size() / 2;
      } else {
        REP(i, l + 1, r) {
          int j = i;
          while (j + 1 < r && s[i] == s[j + 1]) j++;
          ans += (j - i + 1) / 2;
          i = j;
        }
        ans *= k;
        ans += (l + 1) / 2;
        ans += (s.size() - r) / 2;
        ans += (l + 1 + s.size() - r) / 2 * (k - 1);
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE TypeApplications #-}
import Data.Int (Int64)
import qualified Data.ByteString.Char8 as BS
import Data.Fixed

type N = Fixed E2
-- type N = Double --> WA

main = do
  [a,b] <- BS.words <$> BS.getLine
  let Just (a',_) = BS.readInteger a
      a'' = fromIntegral a' :: Int64
      b' = read @N (BS.unpack b)
  print $ a'' * truncate (b' * 100) `quot` 100


Measured memory_bytes: 4204
#include<stdio.h>
int main(void){
  int N,X,T;
  scanf("%d",&N);
  scanf("%d",&X);
  scanf("%d",&T);
  int num=N/X;
  if(N%X==0){
    printf("%d",T*num);
  }
  else printf("%d",T*(num+1));
  
  return 0;
}

Measured memory_bytes: 1728
use proconio::input;

fn main() {
    input! {
        k: usize,
        t: usize,
        aa: [usize; t],
    }

    let max = aa.into_iter().max().unwrap();

    if k / 2 >= max {
        println!("0");
        return;
    }

    let ans = if k % 2 == 0 {
        let rem = max - k/2;
        rem * 2 - 1
    } else {
        let rem = max - k/2 - 1;
        rem * 2
    };

    println!("{}", ans);
}


Measured memory_bytes: 2188
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  bool c=false, f=false;
  for(int i=0;i<S.size();++i) {
    if(c) {
      if(S[i]=='F') f = true;
    }
    else {
      if(S[i]=='C') c = true;
    }
  }
  if(f) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 3444
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

typedef long long li;
typedef unsigned long long uli;
typedef pair<int, int> pii;
typedef long double ld;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fr first
#define sc second
#define pb push_back
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forb(i, n) for(int i = int(n) - 1; i >= 0; --i)
//#define x first
//#define y second

const int INF = 1e9;
const li INF64 = 4e18;
const int M = 100 + 10;
const int N = 100 * 1000 + 100;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = 3.14159265359;

li gcd(li a, li b) {
    return a == 0 ? b : gcd(b % a, a);
}

bool dp[N];

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);

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

    vector<int> a(n);
    forn(i, n) {
        cin >> a[i];
    }

    fore(i, a[0], k + 1) {
        for (auto x : a) {
            if (i - x >= 0) {
                dp[i] = (dp[i] | (!dp[i - x]));
            }
        }
    }

    cout << (dp[k] ? "First" : "Second") << '\n';

}

Measured memory_bytes: 384
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_A
  * Structured Program I - Print a Rectangle
  */
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.split(" ").map(_.toInt)).map { case Array(h, w) => (h, w) }
      .takeWhile(_ != (0, 0))
      .map { case (h, w) => createARectangle(h, w) }
      .foreach(_.foreach(println))
  }

  def createARectangle(h: Int, w: Int): Seq[String] = {
    (1 to h).map(_ => "#" * w) :+ ""
  }
}

Measured memory_bytes: 45516
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll K, A, B;

int main(void) {
    cin >> K >> A >> B;
    
    ll ans=K+1;
    
    ll t=A;
    if((K-A+1)%2==0) {
        t+=(K-A+1)/2*(B-A);
    }else {
        t+=(K-A)/2*(B-A)+1;
    }
    chmax(ans, t);
    pt(ans);
    
    
}




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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<long long> a(n);
    long long total = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i == 0) {
            continue;
        } else if (a[i - 1] > a[i]) {
            // cout << a[i - 1] << " " << a[i] << '\n';
            total += a[i - 1] - a[i];
            a[i] += a[i - 1] - a[i];
            // cout << a[i - 1] << " " << a[i] << '\n';
       }
    }
    cout << total << '\n';
    return 0;
}



Measured memory_bytes: 4780
import sys
input = sys.stdin.readline

N, W = map(int, input().split())
table = []
for i in range(N):
  w,v = map(int, input().split())
  table.append((w,v))
dp = [[W+1]*(10**3*N+1) for i in range(N+1)]
dp[0][0] = 0

for i in range(1,N+1):
  w,v = table[i-1]
  for j in range(10**3*N+1):
    dp[i][j] = dp[i-1][j]
    if j>=v:
      dp[i][j] = min(dp[i][j],dp[i-1][j-v]+w)

for i in range(10**3*N,-1,-1):
  if dp[-1][i] <= W:
    print(i)
    exit()

Measured memory_bytes: 119916
/*input
happy,newyear,enjoy
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	int a,b;
	cin>>a>>b;
	cout<<(a+b)%24;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int r;cin >> r;
  cout << r*r << endl;
  return 0;
}


Measured memory_bytes: 256
a, b, c_theta = gets.split.map(&:to_i)

# surface
s = a * b * Math.sin(c_theta / 180.0 * Math::PI) / 2.0
puts s

# length in the circle
c = (a ** 2 + b ** 2 - 2 * a * b * Math.cos(c_theta / 180.0 * Math::PI)) ** (1/2.0)
puts a + b + c

# height h
h = b * Math.sin(c_theta / 180.0 * Math::PI)
puts h



Measured memory_bytes: 6960
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
    int a,b;
    cin>>a>>b;
    bool ans=false;

    int tmp=log10(b);
    a=a*pow(10,tmp+1);

    rep(i,0,1000){
      if((a+b)==i*i) ans=true;
    }

    if(ans) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
constexpr int gcd(int a,int b){return b?gcd(b,a%b):a;}
constexpr int lcm(int a,int b){return a*b/gcd(a,b);}

int main(){
    string s;
    while(cin>>s,s!="#"){
        deque<int> v;
        while(s.length()){
            int isN=s[0]=='n';
            s=s.substr(isN+4);
            v.push_front(!isN);
        }
        int a=0;
        for(auto i : v){
            a=max(a*2+(i?1:-1),0);
        }
        a*=90;
        int b=pow(2,v.size()-1);
        int e=a?gcd(a,b):1;
        a/=e,b/=e;
        cout<<a;
        if(b!=1) cout<<"/"<<b;
        cout<<endl;
    }
}

Measured memory_bytes: 3172
a, b, k = map(int, input().split())
num = max(a, b)
b = min(a, b)
a = num
while 1:
    num = a % b
    if num == 0:
        break
    a = b
    b = num
num = 0
for i in range(1, b+1):
    if b % i == 0:
        num += 1

    if num == k:
        print(b//i)
        break


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }

using namespace std;

void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }

}

int main() {
    int X, Y, z;
    cin >> X >> Y >> z;
    cout << z << " " << X  << " "<< Y << endl;
}

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

int main(void){

  char str[101] ="\0";
  scanf("%s",str);
  int len = strlen(str);
	int moji[26];
  int j = 0;/*アルファベットに対応する数字*/
  int Flag = 0; /*w判定フラグ*/

  for(int i=0; i<27;i++){
    moji[i] = 0;
  }
  
  for(int i=0; i<len; i++){
    for(char m = 'a'; m <= 'z'; m++){
      
      if( m == 'a'){　/*文字と番号を同期*/
        j = 0;
      }else{
        /*何もしない*/
      }

      if( str[i] == m ){
          moji[j] ++;
      }else{
        /*何もしない*/
      }
      j++;
    }    
  }

  for( j=0; j<27; j++){
    if( (moji[j] %2) == 0 ){
      /*何もしない*/
    }else{
      Flag = 1;
    }
  }

  if(Flag ==0 ){
    printf("Yes");
  }else{
    printf("No");
  }


  return 0;
}

Measured memory_bytes: 128
from sys import stdin

def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    n = sum(A) / N
    ans, d = 0, float('inf')
    for i, a in enumerate(A):
        if abs(n - a) < d:
            ans = i
            d = abs(n - a)
    print(ans)

input = lambda: stdin.readline()
main()


Measured memory_bytes: 3060