akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define INF (1LL<<60)


int main(){
	vector<pair<ll,ll> > v;
	int n;
	cin >> n;
	ll amx = 0;
	ll ami = INF;
	ll bmx = 0;
	ll bmi = INF;
	rep(i,n){
		ll x,y;
		cin >> x >> y;
		if(y>x){
			swap(x,y);
		}
		v.push_back(MP(x,y));
		amx = max(amx,x);
		ami = min(ami,x);
		bmx = max(bmx,y);
		bmi = min(bmi,y);
	}
	ll ans = (amx-ami)*(bmx-bmi);
	ll mx = amx;
	ll mi = bmi;
	sort(v.begin(),v.end(),greater<pair<ll,ll> >());
	vector<bool> flag(n);
	multiset<ll> st;
	rep(i,n){
		if(v[i].first==mx){
			flag[i] = true;
			st.insert(v[i].second);
		}else if(v[i].second==mi){
			flag[i] = true;
			st.insert(v[i].first);
		}else{
			st.insert(v[i].first);
		}
	}
	auto x = st.begin();
	auto y = st.end();
	y--;
	ans = min(ans,(mx-mi)*((*y)-(*x)));
	rep(i,n){
		if(!flag[i]){
			auto p = st.find(v[i].first);
			st.erase(p);
			st.insert(v[i].second);
			x = st.begin();
			y = st.end();
			y--;
			ans = min(ans,(mx-mi)*((*y)-(*x)));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13676
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 3002;
ll dp[M][M][3];
int val[M][M],r,c;
ll solve(int x,int y,int f)
{
	if(x>r || y>c)
		return 0;
	if(dp[x][y][f]!=-1)
		return dp[x][y][f];
	ll res = max(solve(x+1,y,0),solve(x,y+1,f));
	if(f<2)
	{
		res = max(res,(ll)val[x][y]+max(solve(x+1,y,0),solve(x,y+1,f+1)));
	}
	else
	{
		res = max(res,(ll)val[x][y]+solve(x+1,y,0));
	}
	return dp[x][y][f] = res;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	memset(dp,-1,sizeof(dp));
	int k;
	cin>>r>>c>>k;
	for(int i=1;i<=k;i++)
	{
		int r,c,v;
		cin>>r>>c>>v;
		val[r][c] = v;
	}
	cout<<solve(1,1,0)<<"\n";
	return 0;
}

Measured memory_bytes: 250564
#include <functional>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 1000000000000000;

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while(sz < n) sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x) {
        seg[k + sz] = x;
    }

    void build() {
        for(int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid &x) {
        k += sz;
        seg[k] = x;
        while(k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) L = f(L, seg[a++]);
            if(b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const {
        return seg[k + sz];
    }
};

priority_queue<ll, vector<ll>, greater<ll>> que;
int k[200005];
ll l[200005], r[200005];
vector<int> bl[200005], br[200005];

int main()
{
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        ll ans = 0;
        for(int i = 0; i < n; i++){
            cin >> k[i] >> l[i] >> r[i];
            if(l[i] > r[i]) bl[k[i]].push_back(i);
            else br[k[i]].push_back(i);
            ans += max(l[i], r[i]);
        }
        int c = 0;
        for(int i = 1; i <= n; i++){
            c += (int)bl[i].size();
            for(int j : bl[i]){
                que.push(l[j] - r[j]);
            }
            while(c > i){
                ans -= que.top();
                que.pop();
                c--;
            }
        }
        while(que.size()) que.pop();
        c = 0;
        for(int i = n; i > 0; i--){
            c += (int)br[i].size();
            for(int j : br[i]){
                que.push(r[j] - l[j]);
            }
            while(c > n - i){
                ans -= que.top();
                que.pop();
                c--;
            }
        }
        while(que.size()) que.pop();
        cout << ans << endl;
        for(int i = 1; i <= n; i++){
            bl[i].clear();
            br[i].clear();
        }
    }
}


Measured memory_bytes: 22092
#include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

int main()
{
	int N, X, T;
	cin >> N >> X >> T;
	int Y = (N - 1) / X + 1;
	cout << Y * T << endl;
	return 0;
}

Measured memory_bytes: 3632
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

ans = 0
for i in range(1000):
    cnt = 0
    for j in range(N):
        if S[j] == str(i).zfill(3)[cnt]:
            cnt += 1
            if cnt == 3:
                ans += 1
                break

print(ans)


Measured memory_bytes: 69924
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
    int n,k;   
    cin>>n>>k;
    long long x[100000];
    for (int i = 0; i < n; ++i) {
        cin>>x[i];
    }
    long long ans=10000000000; 
    for (int i = 0; i <= n-k; ++i) {
        int y;
	if(x[i]*x[i+k-1]>=0){
	    if(x[i]<0) y=abs(x[i]);
	    else y=abs(x[i+k-1]);
	}else{
	    y=min(abs(x[i]*2)+abs(x[i+k-1]),
	    abs(x[i])+abs(x[i+k-1]*2));
	}
	if(y<=ans) ans=y;
    }
    cout<<ans<<endl;
}



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

using namespace std;

int main(void){

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    
    sort(a.begin(), a.end());
    vector<int> count(200000);
    for(int i=0; i<200000; i++) count[i] = 0;
    
    int index = 0;
    count[index]++;
    for(int i=1; i<n; i++) {
        if(a[i-1] != a[i]) {
            index++;
            count[index]++;
        }
        else {
            count[index]++;
        }
    }
    

    count.resize(index+1);
    sort(count.begin(), count.end());

    index = 0;
    int result = 0;
    int size = count.size();
    while(k < size) {
//        cout << count[index] << endl;
        result += count[index++];
        size--;
    }
    
    cout << result << endl;
    
    return 0;
    
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N;cin>>N;long a=0;
  for(long i=1;i<=N;i+=2){
    long b=0;
    for(long j=1;j<=i;j++)if(i%j==0)b++;
    if(b==8)a++;
  }
  cout<<a<<endl;
  
}



Measured memory_bytes: 3592
#include<stdio.h>

int main(void){
    int h,w,i,j;
    for(;;){
        scanf("%d %d",&h,&w);
        if(h==0&&w==0) break;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if(i%2==0){
                    if(j%2==0) printf("#");
                    if(j%2==1) printf(".");
                }
                if(i%2==1){
                    if(j%2==1) printf("#");
                    if(j%2==0) printf(".");    
                }
            } 
            printf("\n");
        }  
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1736
input_data = gets.chomp.split(" ")
n = input_data[0].to_i
m = input_data[1].to_i

while n != 0 do
    #arrayオブジェクト １００日で、0日から始める。
    date = Array.new(100, 0)
    n.times do 
        g = gets.chomp.split(" ")
        g.shift
        g.each do |i|
            date[i.to_i] += 1
        end
    end
    
    if date.max.to_i >= m
        p date.index(date.max)
    else 
        p 0
    end
    input_data = gets.chomp.split(" ")
    n = input_data[0].to_i
    m = input_data[1].to_i
end



Measured memory_bytes: 6924
/*
*/

typedef long long ll;
#include <bits/stdc++.h>
using namespace std;

int main() {
    ll n;
    std::cin >> n;
    vector<bool> tate_yoko;
    string s1;
    std::cin >> s1;
    for (int i = 0; i < n; i++) {
        if( s1[i] == s1[i+1] && i!=n-1) {
            tate_yoko.push_back(false);
            i++;
        }else{
            tate_yoko.push_back(true);
        }
    }
    ll val = 0;
    if(tate_yoko[0]){
        val = 3;
    }else{
        val = 6;
    }
    
    ll const mod = 1000000007;
    
    for (int i = 1; i < tate_yoko.size(); i++) {
        if(tate_yoko[i-1]){
            val *= 2;
        }else{
            if(tate_yoko[i]){
                
            }else{
                val *= 3;
            }
        }
        val %= mod;
    }
    
    std::cout << val << std::endl;
}



Measured memory_bytes: 256
// Author : Syed Mujtaba
// Seek knowledge from the Cradle to the Grave !!
// https://www.linkedin.com/in/syed-mujtaba-064a5016a 

#include <bits/stdc++.h>
using namespace std;
#define int     long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
signed main()
{
	fast_io
	int n;
	cin >> n;
	vector < int > a(n), b(n), c(n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
	}
	int dp[n + 1][3];
	dp[1][0] = a[0];
	dp[1][1] = b[0];
	dp[1][2] = c[0];
	for(int i = 2; i <= n; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			dp[i][j] = -1;
			int x;
			if(j == 0)
				x = a[i - 1];
			else if(j == 1)
				x = b[i - 1];
			else
				x = c[i - 1];
			dp[i][j] = max(dp[i - 1][(j + 1)%3] + x , max(dp[i][j], dp[i - 1][(j + 2)%3] + x));

		}
	}
	cout << max(dp[n][0],  max(dp[n][1], dp[n][2]) ) << endl;

}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll calc(ll x,ll y){

	if(y > x)swap(x,y);

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


int main(){

	int N,K;
	scanf("%d %d",&N,&K);

	if(N > K){
		printf("0\n");
		return 0;
	}

	//KPN
	ll ans = 1;
	for(ll i = 0; i < N; i++){
		ans *= (K-i);
		ans %= MOD;
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 3208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws IOException {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        
        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        int d = a / b;
        int r = a % b;
        double f = (double)a / b;
        System.out.printf("%d %d %.5f\n", d, r, f);
    } 
}

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

int main()
{
    int N;
    cin >> N;
    int L[N];
    for (int i = 0; i < N; i++) cin >> L[i];
    sort(L, L + N);

    int ans = 0;
    for (int i = 0; i < N - 2; i++) {
        for (int j = i + 1; j < N - 1; j++) {
            for (int k = j + 1; k < N; k++) {
                if (L[i] != L[j] && L[j] != L[k] && L[i] + L[j] > L[k]) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    string N ;
    cin >> N ;
    int n = 4 ;
    int cnt = 0 ;
    for(int i = 0 ; i< 4 ;i++){
        if(N[i] == '2'){
            cnt++ ;
        }
    }
    cout << cnt << endl;
  
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_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())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;

  vll a(n);
  REP(i, n)
    cin >> a[i];

  ll ans = 1;
  vll v(3, 0);
  REP(i, n){
    ll cnt = 0;
    ll flag = true;
    REP(j, v.size()){
      if(v[j] == a[i]){
        cnt++;

        if(flag){
          v[j]++;
          flag = false;
        }
      }
    }

    ans *= cnt;
    ans %= MOD;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,-1,1,-1,1}; 
const int mod = 1e9+7;
const ll N = 2e5+5;


void solve(){
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	pqueue<int,vector<int>,greater<int>>A,B;
	pqueue<int>C;
	for(int i=0;i<a;++i){
		int xx;
		cin>>xx;
		A.push(xx);
	}
	for(int i=0;i<b;++i){
		int xx;
		cin>>xx;
		B.push(xx);
	}
	for(int i=0;i<c;++i){
		int xx;
		cin>>xx;
		C.push(xx);
	}
	while(sz(A)>x){
		A.pop();
	}
	while(sz(B)>y){
		B.pop();
	}
	while(!C.empty()){
		int xx=C.top();
		C.pop();
		if(A.top()<=B.top()){
			if(A.top()<xx){
				A.pop();
				A.push(xx);
			}
			else break;
		}
		else{
			if(B.top()<xx){
				B.pop();
				B.push(xx);
			}
			else break;
		}
	}
	ll ans=0;
	while(!A.empty()){
		ans+=A.top();
		A.pop();
	}
	while(!B.empty()){
		ans+=B.top();
		B.pop();
	}
	cout<<ans;

}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 4660
object Main {

  def main(args: Array[String]): Unit = {
    scala.io.StdIn.readLine().split("\\s").map(_.toInt) match {
      case Array(a, b, c) =>
        if ((c > a && c < b) || (c > b && c < a)) println("Yes") else println("No")
    }
  }

}

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

using namespace std;

signed main()
{
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());

	if (a[0] == 5 && a[1] == 5 && a[2] == 7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <bitset>
#include <random>
#include <ctime>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    ans = (n + 1000 - 1) / 1000;
    cout << (1000 * ans) - n << endl;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

long long dp[1000010][2];
//dp[i][j]:=下からi桁目まで決めて繰り下がりがjのときの最小値
int K;

long long solve(string s){

    fill((long long*)dp,(long long*)dp+sizeof(dp)/sizeof(long long),INF);

    const int L=s.size();

    //各桁について、金額のその桁までを見たときの「ぴったり払うときの最小」
    //「1余分に払うときの最小」を上の桁から計算する

    dp[0][0]=0;
    for(int i=0;i<L;i++)
    {
        
        for(int k=0;k<2;k++)
        {   

            int D=s[i]-'0';
            //繰り下がりのぶん、引く数を+1する
            D+=k;
            for(int d=0;d<10;d++)
            {
                int ni=i+1,nj=0;
                int b=d-D;
                //繰り下がりが発生するとき
                if(b<0){
                    nj=1;
                    b+=10;
                }
                dp[ni][nj]=min(dp[ni][nj],dp[i][k]+d+b);
            }
        }
    }
    return dp[L][0];

}

int main(){

    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    s+='0';
    cout<<solve(s)<<endl;

    return 0;

}
/*


*/


Measured memory_bytes: 17924
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


bool c[64][64];
void destroy(int x, int y)
{
	if (!c[y][x])
		return;
	c[y][x] = false;
	for (int dy = -1; dy <= 1; ++dy)
		for (int dx = -1; dx <= 1; ++dx)
			destroy(x + dx, y + dy);
}
int main()
{
	int w, h;
	while (cin >> w >> h, w)
	{
		clear(c, 0);
		rep (y, h) rep (x, w)
			cin >> c[y + 1][x + 1];
		int res = 0;
		for (int y = 1; y <= h; ++y)
			for (int x = 1; x <= w; ++x)
				if (c[y][x])
					++res, destroy(x, y);
		cout << res << endl;
	}
}

Measured memory_bytes: 0
K = int(input())
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(K):
    t = l[i] % 10
    if t == 0:
        l.append(l[i] * 10 + 0)
        l.append(l[i] * 10 + 1)
    elif t == 9:
        l.append(l[i] * 10 + 8)
        l.append(l[i] * 10 + 9)
    else:
        l.append(l[i] * 10 + t - 1)
        l.append(l[i] * 10 + t)
        l.append(l[i] * 10 + t + 1)

print(l[K-1])

Measured memory_bytes: 22672
#include <stdio.h>
#include <cmath>
#include <algorithm>

#define NUM 60000

int main(){
	int table[NUM],limit;

	for(int i=0; i < NUM;i++)table[i] = 1;
	table[0] = 0;

	limit = sqrt(NUM);

	for(int i=2;i<=limit;i++){
		if(table[i] == 1){
			for(int k=2*i;k < NUM; k += i){
				table[k] = 0;
			}
		}
	}

	int n;

	while(scanf("%d",&n)!=EOF){
		for(int k=n-1;k>=0;k--){
			if(table[k] == 1){
				printf("%d ",k);
				break;
			}
		}
		for(int k=n+1;k<NUM;k++){
			if(table[k] == 1){
				printf("%d\n",k);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2820
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    /** constance */
    String conABC = "ABC";
    String conARC = "ARC";
      
    /** Scanner */
    Scanner sc = new Scanner(System.in);
    
    /** input */
    String lastHolded = sc.next();

    if(lastHolded.equals(conABC)){
      System.out.println(conARC);
    } else {
      System.out.println(conABC);
    }

  }
}


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

#define INX(x) (cin >> x)
#define INXV(vec, cnt) for(ll i; i < cnt; i++) INX(vec[i])
#define OUTX(x) (cout << x << endl)
#define OUTXV(vec) for(ll i; i < (ll)vec.size(); i++) OUTX(vec[i])

#define ADD emplace_back
#define MP make_pair

int main()
{
    ll A;
    INX(A);

    string B;
    INX(B);

    ll Bupper = atoi((B.substr(0,1)).c_str());
    ll Blower100 = atoi((B.substr(2,2)).c_str());
    OUTX((ll)(A * Bupper + (A * Blower100) / 100));


    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(), (c).end());
const long long MOD = 1e9 + 7;
typedef long long ll;

int main(){
	int N;
	cin >> N;
	if(N == 1){
		cout << "Hello World" << endl;
	} else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vll vector<ll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,s,e) for(ll i=(s);(s>e)?i>e:i<e;(s>e)?i--:i++)
ll mod1 = 1e9 + 7;
ll mod2 = 998244353;

//ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}







int main(){
    ll n;
    cin>>n;
    ll sum = 0;
    for(ll i=1;i<=n;i++){
        if(i%15 && i%5 && i%3)sum+=i;

    }
    cout<<sum<<endl;
	
	
}

Measured memory_bytes: 3640
/** Which of the favors of your Lord will you deny ? **/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define F first
#define S second

#define ALL(x)      (x).begin(), (x).end()
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#ifndef ONLINE_JUDGE
#define DBG(x)      cout << __LINE__ << " says: " << #x << " = " << (x) << endl
#else
#define DBG(x)
#define endl "\n"
#endif

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

#define int long long

const int MOD = 1e9+7;
const int MAXBIT = 60;

int n;
int dp[70][3][3];

int solve(int pos,int carry,int ok)
{
    if(pos==MAXBIT) return (carry==0 && ok==1);
    int &ret = dp[pos][carry][ok];
    if(ret != -1) return ret;

    int nthbit = (n>>pos)&1;

    ret = 0;

    for(int a=0;a<2;a++)
    {
        for(int b=0;b<=a;b++)
        {
            int curbit = (a+b+carry)%2;
            int ncarry = (a+b+carry)/2;

            int nok = ok;

            if(curbit < nthbit) nok = 1;
            if(curbit > nthbit) nok = 0;

            ret += solve(pos+1,ncarry,nok);
            ret %= MOD;
        }
    }

    return ret;
}

int32_t main()
{
    optimizeIO();
    cin>>n;

    memset(dp,-1,sizeof dp);
    int ans = solve(0,0,1);
    DBG(ans);
    cout<<ans<<endl;

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
bool ask(LL x){
    printf("? %lld\n",x);
    fflush(stdout);
    char s[9];
    RS(s);
    return s[0]=='Y';
}
int main(){
    LL ten=10;
    while(ask(ten)&&ten<1e12)ten*=10;
    if(ten>1e10){
        LL one=222222222LL;
        ten=1000000000;
        while(one&&ask(one))one/=10,ten/=10;
        printf("! %lld\n",ten);
        return 0;
    }
    LL ll=ten/10,rr=ten-1;
    while(ll<rr){
        LL mm=(ll+rr)/2;
        if(ask(mm*10))rr=mm;
        else ll=mm+1;
    }
    printf("! %lld\n",ll);
    return 0;
}


Measured memory_bytes: 596
N, M = map(int, input().split())
graph = [[] for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  graph[a-1].append(b-1); graph[b-1].append(a-1)

dist = [2] * N
dist[0] = 0
d = [[0, -1]]
num = {0:1, 1:0}
while d:
  node, par = d.pop()
  children = graph[node]
  for child in children:
    if child == par:
      continue
    if dist[child] < 2:
      if dist[child] == (dist[node] + 1) % 2:
        continue
      print(N*(N-1)//2 - M)
      quit()
    else:
      dist[child] = (dist[node] + 1) % 2
      num[dist[child]] += 1
      d.append([child, node])

print(num[0] * num[1] - M)

Measured memory_bytes: 26172
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()
	n := readInt64()
	var ans int64
	for i := int64(0); i < n; i++ {
		ans += readInt64()
	}
	println(ans - n)
}


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>

using namespace std;

#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;

  bool operator < (const Puzzle &p) const{
    for(int i = 0; i < N2; i++){
      if(f[i] == p.f[i]){
	continue;
      }
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p){
  for(int i = 0; i < N2; i++){
    if(p.f[i] != (i + 1)) return false;
  }
    return true;
}

string bfs(Puzzle s){
  
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u, v;
  
  s.path = "";
  Q.push(s);
  V[s] = true;

  while(!Q.empty()){
    u = Q.front();
    Q.pop();
    if(isTarget(u)) return u.path;

    int sx = u.space / N;
    int sy = u.space % N;

    for(int r = 0; r < 4; r++){
      int tx = sx + dx[r];
      int ty = sy + dy[r];

      if(tx < 0 || ty < 0 || tx >= N || ty >= N){
	continue;
      }

      v = u;

      swap(v.f[u.space], v.f[tx * N + ty]);
      v.space = tx * N + ty;

      if(!V[v]){
	V[v] = true;
	v.path += dir[r];
	Q.push(v);
      }
    }
  }
  return "unsolvable";
}

int main(){
  Puzzle in;

  for(int i = 0; i < N2; i++){
    cin >> in.f[i];
    
    if(in.f[i] == 0){
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = bfs(in);
  cout << ans.size() << endl;

  return 0;
}
  
	  
      



Measured memory_bytes: 30604
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 100005
using namespace std;
int n,m,in[M];
int main()
{
    while (~scanf("%d %d", &n, &m)) {
        REP(i,1,m) scanf("%d", &in[i]);
        sort(in+1, in+m+1);

        REP(i,1,m-1) in[i] = in[i+1]-in[i];
        sort(in+1, in+m);

        if (n>=m) {
            puts("0");
        } else {
            printf("%lld\n", accumulate(in+1, in+m-n+1, 0LL));
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;

int main(){
    int n;
    cin >> n;
    char s;
    string ans = "Three";
    for (int i = 0; i < n; i++) {
        cin >> s;
        if(s == 'Y') ans = "Four";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
c1 = 0
c2 = 0
c3 = 0
count = 0
for i in range(N):
  s = input()
  count += s.count('AB')
  if s[0] == 'B' and s[-1] == 'A':
    c1 += 1
  elif s[0] == 'B' and s[-1] != 'A':
    c2 += 1
  elif s[0] != 'B' and s[-1] == 'A':
    c3 += 1
  else:
    pass

if c1 == 0:
  print(count + min(c2,c3))
else:
  if c2 > 0 or c3 > 0:
    print(count + c1 + min(c2,c3))
  else:
    print(count + c1-1)


Measured memory_bytes: 3064
def main():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    ab.sort()
    ans = 0
    cnt = 0
    for i in range(n):
        for j in range(ab[i][1]):
            ans += ab[i][0]
            cnt += 1
            if cnt == m:
                print(ans)
                exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 60760
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include<functional>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 3;
int num[maxn];
deque<int>ans;
int n;
int main() {
	while (~scanf("%d", &n)) {
		ans.clear();
		for (int i = 0; i < n; i++) {
			scanf("%d", &num[i]);
		}
		for (int i = 0; i < n; i++) {
			if (i % 2 == 0) {
				ans.push_front(num[i]);
			}
			else
				ans.push_back(num[i]);
		}
		if (n % 2 == 1) {
			cout << ans[0];
			for (int i = 1; i < n; i++)
			{
				printf(" %d", ans[i]);
			}
			cout << endl;
		}
		else {
			cout << ans[n-1];
			for (int i = n-2; i >=0; i--)
			{
				printf(" %d", ans[i]);
			}
			cout << endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>

#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>

#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

int bruteForce(string s) {
  set<string> result;
  REP(i,s.length()) FOR(j,i+1,s.length()) {
    reverse(s.begin() + i, s.begin() + j + 1);
    result.insert(s);
    reverse(s.begin() + i, s.begin() + j + 1);
  }
  result.insert(s);

  return result.size();
}

ll solve(string s) {
  vector<ll> cnt(26);
  REP(i,s.length()) {
    cnt[s[i]-'a']++;
  }
  ll result = ((ll)s.length()) * (s.length() - 1) / 2 + 1;
  REP(i,cnt.size()) {
    result -= cnt[i] * (cnt[i] - 1) / 2;
  }
  return result;
}

int main(){
  string s;
  while (cin >> s) {
    cout << solve(s) << endl;
  }
}


Measured memory_bytes: 772
a,b,c,x,y = map(int,input().split())

mi = min(x,y)
sa = abs(x-y)
if c*2 <= a+b:
    daikin = c*2*mi
    if x >= y:
        piza = min(c*2,a)
        daikin += piza*sa
    else:
        piza = min(c*2,b)
        daikin += piza*sa
    print(daikin)
else:
    print(a*x + b*y)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
struct Condition
{
public:
    double l;
    double r;
    double v;
};
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<double> t(N);
    vector<double> v(N);
    rep(i, 0, N) cin >> t[i];
    rep(i, 0, N) cin >> v[i];
    double T = 0.0;
    vector<Condition> conds;
    {
        conds.push_back({0, 0, 0});
        rep(i, 0, N)
        {
            conds.push_back({T, T + t[i], v[i]});
            T += t[i];
        }
        conds.push_back({T, T, 0});
    }
    double ans = 0.0;
    double time = 0.5;
    double vel = 0.0;
    while (true)
    {
        double v = 10000.0;
        for (const auto& cond : conds)
        {
            if (time <= cond.l)
            {
                chmin(v, cond.v + (cond.l - time));
            }
            else if(time >= cond.r)
            {
                chmin(v, cond.v + (time - cond.r));
            }
            else
            {
                chmin(v, cond.v);
            }
        }

        ans += (vel + v) * 0.5 * 0.5;

        if (time >= T) break;

        time += 0.5;
        vel = v;
    }
    cout << setprecision(15) << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K,A[100001];
	scan(N>>K);
	rep(i,N){
		scan(A[i]);
	}
	prin((N-1)/(K-1)+((N-1)%(K-1)!=0));
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>

#define dprintf(s,...) printf("%s:%d" s,__func__,__LINE__,__VA_ARGS__)
using namespace std;

typedef pair<int,int> P;
typedef long long int ll;



int N,K;
int S[101],B[101][101];

bool solve(){
  
  for(int i=0;i<K;i++){
    int t=0;
    for(int j=0;j<N;j++)
      t+=B[j][i];

    if(t>S[i]) return false;
  }

  return true;
}



int main(){

  while(1){
    cin>>N>>K;
    if(N==0 && K==0) break;
    
    for(int i=0;i<K;i++)
      cin>>S[i];
    
    for(int i=0;i<N;i++)
      for(int j=0;j<K;j++)
	cin>>B[i][j];

    if(solve())cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }

  
  return 0;
}

Measured memory_bytes: 3124
import java.util.*;

public class Main {
	void solve() {
		Scanner scan = new Scanner(System.in);
		String n = scan.next();
		for(int i = 0; i < 3; i++) {
			if(n.charAt(i) == '1') System.out.print(9);
			else if(n.charAt(i) == '9') System.out.print(1);
			else System.out.print(n.charAt(i));
		}
		scan.close();
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}


Measured memory_bytes: 35524
#include <stdio.h>  
int main()
{
    int r, c, i, j; 
    int hyou[101][101] = {0};
     
    scanf("%d %d", &r, &c);
     
    for(i=0; i<r; i++)
    {
        for(j=0; j<c; j++) 
        {
            scanf("%d",&hyou[i][j]);
        }
    } 
     
    for (i=0; i<r; i++)
    {
        for (j=0; j<c; j++)
        {
            hyou[i][c] += hyou[i][j]; 
        }
    }
     
    for (j=0; j<c+1; j++)
    {
        for (i=0; i<r; i++)
        {
            hyou[r][j] += hyou[i][j];
        }
    }
     
    for (i=0; i<r+1; i++)
    {
        for (j=0; j<c; j++) 
        {
            printf("%d ",hyou[i][j]);
        }
         
        printf("%d\n",hyou[i][c]); 
    }
    return 0;
}
 

 

Measured memory_bytes: 648
import math
A, B, H, M = map(int, input().split())

rad_h = (H / 12  + M / 12 / 60 ) * 2 * math.pi
rad_m = M / 60 * 2 * math.pi

res = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(abs(rad_h - rad_m)))
print(res)



Measured memory_bytes: 9436
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> PP;
int H,W,A,B,sx,sy,gx,gy;
int dx[4] = {-1,1,0,0},dy[4] = {0,0,-1,1};
int dx2[4] = {-1,-1,1,1},dy2[4] = {-1,1,-1,1};
int ok[1002010] = {},cost[1002010] = {},D[1002010] = {};
char C[1010][1010];
vector<vector<P>> v(1002010);
bool in(int x,int y){
    return 1<=x && x<=H && 1<=y && y<=W;
}

int main() {
    cin >> H >> W >> A >> B;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin >> C[i][j];
            if(C[i][j]=='s'){
                sx = i; sy = j;
            }
            if(C[i][j]=='g'){
                gx = i; gy = j;
            }
        }
    }
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(C[i][j]=='*'){
                ok[i*W+j] = -1;
                for(int k=0;k<4;k++){
                    int nx = i+dx2[k],ny = j+dy2[k];
                    if(in(nx,ny)) ok[nx*W+ny] = -1;
                }
                for(int k=0;k<4;k++){
                    int nx = i+dx[k],ny = j+dy[k];
                    if(in(nx,ny)) ok[nx*W+ny] = -1;
                }
            }
        }
    }
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            for(int k=0;k<4;k++){
                int nx = i+dx[k],ny = j+dy[k];
                if(!in(nx,ny)) continue;
                if(C[nx][ny]=='#'){
                    if(ok[i*W+j]!=-1) v[i*W+j].push_back(P(A+B,nx*W+ny));
                }else v[i*W+j].push_back(P(A,nx*W+ny));
            }
            for(int k=0;k<4;k++){
                int nx = i+dx2[k],ny = j+dy2[k];
                if(!in(nx,ny)) continue;
                if(C[nx][ny]=='#'){
                    if(ok[i*W+j]!=-1) v[i*W+j].push_back(P(2*A+B,nx*W+ny));
                }
            }
        }
    }
    priority_queue<P,vector<P>,greater<P>> Q;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            D[i*W+j] = INT_MAX;
        }
    }
    D[sx*W+sy] = 0;
    Q.push(P(0,sx*W+sy));
    while(!Q.empty()){
        P p = Q.top(); Q.pop();
        int n = p.second;
        if(n==gx*W+gy){
            cout <<  p.first << endl;
            return 0;
        }
        if(D[n]<p.first) continue;
        for(auto x:v[n]){
            if(D[x.second]>p.first+x.first){
                D[x.second] = p.first+x.first;
                Q.push(P(D[x.second],x.second));
            }
        }
    }
    cout << "INF" << endl;
    return 0;
}


Measured memory_bytes: 109416
def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)
H,W,T=map(int, input().split())
gh, gw = gcd(H, T), gcd(W, T)
h, w = H // gh, W // gw
MOD = 1000000007
print(pow(pow(2, h, MOD) + pow(2, w, MOD) + pow(2, gcd(h, w), MOD) - 3, gh * gw, MOD))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		ll n;
		cin>>n;
		vector<int> friendliness(n,0);

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

		sort(friendliness.begin(),friendliness.end(),greater<int>());

		if(n == 2) {
			cout<<friendliness[0]<<endl;
		}
		else {
			ll sum = friendliness[0];
			ll left = n - 2;
			ll j = 1;
			while(left) {
				
				if(left>1) {
					sum += friendliness[j++]*2;
					left = left - 2;
				}
				else {
					sum += friendliness[j++];
					left = left - 1;
				}
			}
			cout<<sum<<endl;
		}

		return 0;
	}


Measured memory_bytes: 4060
// E - Sequence Sum
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	ll n; int x, m; cin>>n>>x>>m;
	int mn = min(n, (ll)m);
	vector<int> P; // value of pre & cycle
	ll sum_p = 0; // sum of pre + cycle
	vector<bool> X(m, false); // for cycle check
	while(mn--){
		if(X[x]){
			int pre_len = find(P.begin(), P.end(), x) - P.begin();
			int cyc_len = P.size() - pre_len;
			int nxt_len = (n - pre_len) % cyc_len;
			ll pre = 0; rp(i, 0, pre_len) pre += P[i];
			ll nxt = 0; rp(i, pre_len, pre_len + nxt_len) nxt += P[i];
			ll cyc = (sum_p - pre) * ((n - pre_len) / cyc_len);
			cout<< pre + cyc + nxt <<endl;
			return 0;
		}
		X[x] = true;
		P.push_back(x);
		sum_p += x;
		x = (ll)x*x % m;
	}
	cout<< sum_p <<endl;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  string s;
  int q;
  cin >> s >> q;
  bool mae = true;
  for (int i = 0; i < q; i++) {
    int suuji;
    cin >> suuji;

    if (suuji == 1) {
      //反転する
      // RSORT(s);
      if (mae)
        mae = false;
      else
        mae = true;
    } else {
      int f;
      string c;
      cin >> f >> c;
      if (mae) {
        if (f == 1) {
          //先頭に追加
          s.insert(0, c);
        } else {
          //末尾に追加
          s.push_back(c[0]);
        }
      } else {
        if (f == 1) {
          s.push_back(c[0]);
        } else {
          s.insert(0, c);
        }
      }
    }
  }
  if (mae)
    cout << s << endl;
  else {
    RSORT(s);
    cout << s << endl;
  }
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define debug(x) cout << #x << " -> " << x << endl
#define booga cout << "booga" << endl
#define ll long long int
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;


void testcase(){
	ll a;
	cin >> a;
	cout << a + (a*a) + (a*a*a) << "\n";
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 3648
import sys
def input():
    return sys.stdin.readline()[:-1]


def test():
    # n,m,q = map(int, input().split())
    n = input()

    if n[-1] == "3":
        return("bon")
    elif n[-1] in {"0","1","6","8"}:
        return("pon")
    else:
        return("hon")

print(test())

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

int main() {
    vector<int> food (5);
    for(int i=0; i<5; i++){
        cin >> food.at(i);
    }
    int ans = 0;
    int mi = 10;
    int last;
    vector<int> amari (5);
    for(int i=0; i<5; i++){
        amari.at(i) = food.at(i)%10;
        if(amari.at(i) < mi && amari.at(i) != 0){
            mi = amari.at(i);
            last = i;
        }
    }
    for(int i=0; i<5; i++){
        if(i == last)continue;
        if(food.at(i)%10 == 0) ans += food.at(i);
        else ans += (food.at(i)/10)*10 + 10;
    }
    cout << ans + food.at(last) << endl;
}

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

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

	int n,q;
	cin>>n>>q;
	vector<int> cnt(n,0);
	string s;
	cin>>s;
	int a1,ans=0;
	for(a1=1;a1<n;++a1){
		if(s[a1]=='C' && s[a1-1]=='A'){
			++ans;
			cnt[a1]=ans;
			// cout<<cnt[a1]<<"-"<<a1<<" ";
		}
		else{
			cnt[a1]=cnt[a1-1];
			// cout<<cnt[a1]<<"-"<<a1<<" ";
		
		}
	}
	// cout<<"\n";
	while(q--){
		int l,r;
		cin>>l>>r;
		--l,--r;
		cout<<cnt[r]-cnt[l]<<"\n";
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll a,b;
int main(){
  cin >> a >> b;
  if(a >= 13) cout << b << endl;
  else if(a >= 6) cout << b/2 << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 256