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

using ll = long long;

using namespace std;

using P = pair<int, int>;
#define fi first
#define se second

int main() {
    int n;
    cin >> n;
    ll a[n];
    for (auto &ai:a) cin >> ai;
    ll osum=0, esum=0;
    int maxi=0;
    bool no_plus = true;
    for (int i=0; i<n; i++) {
        if (a[i] > 0) no_plus = false;
        if (a[i] > a[maxi]) maxi = i;
        if (i % 2) osum += max(a[i], 0ll);
        else esum += max(a[i], 0ll);
    }
    if (no_plus) {
        cout << a[maxi] << '\n'
             << n - 1   << '\n';
        for (int i=n; i>maxi+1; i--) cout << i << '\n';
        for (int i=0; i<maxi; i++) cout << 1 << '\n';
        return 0;
    }
    int s = (osum > esum ? 1 : 0), c = 0, e = n-1;
    vector<int> ans;
    for ( ; (e - s) % 2 || a[e] <= 0; e--) ans.push_back(e+1);
    for ( ; (c - s) % 2 || a[c] <= 0; c++) ans.push_back(1);
    for ( ; c<e; c+=2) ans.push_back(a[c+2] > 0 ? 2 : 3);

    cout << max(osum, esum) << '\n'
         << ans.size()      << '\n';

    for (auto &ai:ans) cout << ai << '\n';

    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, int>;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, q;
	cin >> a >> b >> q;
	vector<ll> s(a), t(b);
	vector<P> v;
	for (int i = 0; i < a; i++) {
		cin >> s[i];
		v.emplace_back(s[i], 0);
	}
	for (int i = 0; i < b; i++) {
		cin >> t[i];
		v.emplace_back(t[i], 1);
	}
	sort(v.begin(), v.end());

	for (int i = 0; i < q; i++) {
		ll x;
		cin >> x;
		int idx = lower_bound(v.begin(), v.end(), P(x, -1)) - v.begin();

		ll ans = 1e18;
		if (idx < a + b) {
			ll ans1 = abs(v[idx].first - x);
			if (v[idx].second == 0) {
				int idx1 = lower_bound(t.begin(), t.end(), v[idx].first) - t.begin();
				ll tmp1 = 1e18;
				if (idx1 < b) {
					tmp1 = min(tmp1, abs(v[idx].first - t[idx1]));
				}

				if (idx1 > 0) {
					tmp1 = min(tmp1, abs(v[idx].first - t[idx1-1]));
				}
				ans1 += tmp1;
			} else {
				int idx1 = lower_bound(s.begin(), s.end(), v[idx].first) - s.begin();
				ll tmp1 = 1e18;
				if (idx1 < a) {
					tmp1 = min(tmp1, abs(v[idx].first - s[idx1]));
				}

				if (idx1 > 0) {
					tmp1 = min(tmp1, abs(v[idx].first - s[idx1-1]));
				}
				ans1 += tmp1;
			}
			ans = min(ans, ans1);
		}

		if (idx > 0) {
			idx--;
			ll ans1 = abs(v[idx].first - x);
			if (v[idx].second == 0) {
				int idx1 = lower_bound(t.begin(), t.end(), v[idx].first) - t.begin();
				ll tmp1 = 1e18;
				if (idx1 < b) {
					tmp1 = min(tmp1, abs(v[idx].first - t[idx1]));
				}

				if (idx1 > 0) {
					tmp1 = min(tmp1, abs(v[idx].first - t[idx1-1]));
				}
				ans1 += tmp1;
			} else {
				int idx1 = lower_bound(s.begin(), s.end(), v[idx].first) - s.begin();
				ll tmp1 = 1e18;
				if (idx1 < a) {
					tmp1 = min(tmp1, abs(v[idx].first - s[idx1]));
				}

				if (idx1 > 0) {
					tmp1 = min(tmp1, abs(v[idx].first - s[idx1-1]));
				}
				ans1 += tmp1;
			}
			ans = min(ans, ans1);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 7920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	queue<ll>ch[1010];
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n-1;j++){
			ll now;
			cin>>now;
			now--;
			ch[i].push(now);
		}
	}
	queue<ll>st;
	for(ll i=0;i<n;i++){
		st.push(i);
	}
	ll ans=0;
	while(st.size()!=0){
		ll z=st.size();
		ans++;
		bool mi=false;
		map<ll,ll>sumi;
		for(ll i=0;i<z;i++){
			ll now=st.front();
			st.pop();
			if(ch[now].size()!=0){
			ll nex=ch[now].front();
			
			if(now==ch[nex].front()&&sumi[now]==0&&sumi[nex]==0){
				sumi[now]++;
				sumi[nex]++;
				ch[now].pop();
				ch[nex].pop();
				if(ch[now].size()!=0){
				st.push(now);
				}
				if(ch[nex].size()!=0){
				st.push(nex);
				}
				mi=true;
		//		cout << now<<" "<<nex<<endl;
			}
			}
		}
		if(mi!=true){
			break;
		}
	}
	for(ll i=0;i<n;i++){
		if(ch[i].size()!=0){
			cout << -1;
			return 0;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 12408
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}

int main() {
    int k,n;
    cin >> k >> n;
    VI a(n);
    rep(i,n) cin >> a[i];
    a.push_back(a[0] + k);

    VI e(n);

    rep(i,n) {
        e[i] = a[i+1] - a[i];
    }
    SORT(e);

    LL ans = 0;

    rep(i,n-1) {
        ans += e[i];
    }

    cout << ans << endl;




}


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

using namespace std;

int main()
{
	int h, n, x, i;
	cin>>h>>n;
	for (i=0; i<n; i++)
	{
		cin>>x;
		h -= x;
	}
	if (h <= 0) cout<<"Yes"<<endl; else cout<<"No"<<endl; 
	return 0;
}

Measured memory_bytes: 256
a=int(input())

def gen(a):
    while True:
        yield a
        a = a // 2 if a % 2 == 0 else a * 3 + 1

seen = set()

for ix, x in enumerate(gen(a)):
    if x in seen:
        print(ix+1)
        break
    seen.add(x)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
typedef long long ll;
int fact(int n){
  if(n==0) return 1;
  return fact(n-1)*n;
}
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  rep(i,n) cin >> p.at(i);
  rep(i,n) cin >> q.at(i);

  vector<int> a(n);
  rep(i,n) a[i]=i+1;
  map<vector<int>,int> mp;

  do{
    mp[a]=mp.size();
  }while(next_permutation(ALL(a)));

  int ans=abs(mp[p]-mp[q]);
  cout << ans << endl;
  return 0; 

}



Measured memory_bytes: 5248
def solve(n,m):
	A=[i for i in range(1,n+1)]
	i=n-1
	while True:
		if len(A)==1:
			break
		i=(i+m)%len(A)
		A.pop(i)
		i=i-1 if i>0 else len(A)-1
	return A[0]




while True:
	n,m=map(int,input().split())
	if n==m==0:
		break
	print(solve(n,m))

Measured memory_bytes: 7744
import math

n, k = map(int, input().split(" "))
pL = list(map(int, input().split(" ")))

mx = 0
cs = 0
for i in range(k):
    cs += pL[i]
    mx = cs
for i in range(1, len(pL) - k + 1):
    cs = cs - pL[i - 1] + pL[i + k - 1]
    mx = max(mx, cs)
print((mx + k) / 2)

Measured memory_bytes: 25064
#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int maxn = 1 << 26;
int dp[maxn], opt[200010], pre[200010], cnt[26], INF = 1e9;
char s [200010];

int main()
{
    for(int i = 1; i < maxn; i++)
        dp[i] = INF;
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    for(int i = 1; i <= n; i++) {
        cnt[s[i] - 'a']++;
        for(int j = 0; j < 26; j++)
            pre[i] += (cnt[j] & 1 ) << j;
    }

    for(int i = 1; i <= n; i++) {
        int mn = INF;
        for(int j = 0; j < 26; j++) {
            int cur = dp[(1 << j) ^ pre[i]];
            mn = min(mn, cur);
        }
        mn = min(mn, dp[pre[i]]);
        opt[i] = mn + 1;
        dp[pre[i]] = min(dp[pre[i]], opt[i]);
    }
    printf("%d\n", opt[n]);
    return 0;
}


Measured memory_bytes: 264192
#include <stdio.h>
#include <stdlib.h>
int f[45];
int fibonacci(int n);
int main(int argc, char** argv) {
    int n;
    scanf("%d",&n);
    printf("%d\n",fibonacci(n));
    return (EXIT_SUCCESS);
}
int fibonacci(int n)
{
   
    if(f[n]!=0)
        return f[n];
    if(n==0||n==1)
        return 1;
    return f[n] = fibonacci(n-2) + fibonacci(n-1);
}



Measured memory_bytes: 2104
from math import *
x1,y1,x2,y2=map(int,input().split())
b=x2-x1
h=y2-y1

d=sqrt(h**2+b**2)

if(h==0):
    if(x2>x1):
        x3=x2
        y3=y2+d
        x4=x1
        y4=y1+d
    else:
        x3=x2
        y3=y2-d
        x4=x1
        y4=y1-d
    print(x3,round(y3),x4,round(y4))
else:
    ratio=b/h
    val1=sqrt((d**2)/(1+ratio**2))
    val2=sqrt(((d**2)*(ratio**2))/(1+ratio**2))
    if(x1<=x2 and y1<=y2):
        x3=x2-val1
        y3=y2+val2
        x4=x1-val1
        y4=y1+val2
    elif(x1>=x2 and y1<=y2):
        x3=x2-val1
        y3=y2-val2
        x4=x1-val1
        y4=y1-val2
    elif(x2<x1 and y2<y1):
        x3=x2+val1
        y3=y2-val2
        x4=x1+val1
        y4=y1-val2
    else:
        x3=x2+val1
        y3=y2+val2
        x4=x1+val1
        y4=y1+val2
    print(round(x3),round(y3),round(x4),round(y4))


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
template<class T> inline bool chmax(int a, int b, T c, T d) { return c > d ? a : b; }
template<class T> inline bool chmin(int a, int b, T c, T d) { return c > d ? a : b; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<ppr, Vppr, greater<ppr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 3e5 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
typedef pair<ld, ut> pld;
ut N, M, K, L, Q, D, H, W, R;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
LL maps[SIZE2][SIZE2];
//LL A[SIZE];
LL solve() {
	LL C;
	cin >>  N;
	VI A(N,0);
	LL ans=0,last = 0;
	REP(i, N) cin >> A[i];
	sort(ALL(A));
	LL sum = 0;
	REP(i, N - 1) {
		if ((sum + A[i]) * 2 >= A[i + 1]) {
			ans++;
		}
		else {
			ans = 0;
		}
		sum += A[i];
	}
	ans++;
	cout << ans << endl;
	return 0;
}




//!!!!!!!!!!!!!!!!!!!実装を詰める!!!!!!!!!!!!!!!!!!!!!!!!!
signed main() {

	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	solve();


	//cin >> N;
	return 0;

}


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

struct node
{
    int value,key;
} odd[100007],even[1000007];


bool cmp(node a,node b)
{
    return a.value > b.value;
}


int main()
{
    int n,ans;
    cin>>n;
    for(int i = 1; i <= 100000; i++)
    {
        odd[i].key = i;
        even[i].key = i;
    }
    for(int i = 1; i <= n; i++)
    {
        int x;
        cin>>x;
        if(i%2==1)
            odd[x].value++;
        else
            even[x].value++;
    }
    sort(odd+1, odd+1+100000, cmp);
    sort(even+1, even+1+100000, cmp);

    if(odd[1].key != even[1].key)
    {
        ans = n - odd[1].value - even[1].value;
    }
    else
    {
        ans = min(n-odd[1].value-even[2].value, n-odd[2].value-even[1].value);
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n,m; cin >> n >> m;
    vl a(m),b(m);
    vl tmp(200001,0);
    bool f = false;
    rep(i,m){
        cin >> a[i] >> b[i];
        if(a[i] == 1) tmp[b[i]]++;
    }
    rep(i,m){
        if(b[i] == n && tmp[a[i]] > 0) f = true;
    }
    string yes = "POSSIBLE", no = "IMPOSSIBLE";
    if(!f) cout << no << endl;
    else cout << yes << endl;
}

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

using namespace std;
int main(){
    string S;
    int K;

    cin>>K;
    cin>>S;

    if(S.length() <= K){
        cout<<S<<"\n";
    }
    else{
        for(int i=0;i<K;i++){
            cout<<S[i];
        }
        cout<<"...\n";
    }

    return 0;
}



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

const int maxn=200010;
int a[maxn],k[maxn];

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	memset(k,0,sizeof(k));
	for(int i=n/2+1;i<=n;i++)
		k[i]=a[i];
	for(int i=n/2;i>=1;i--){
		int f=a[i];
		for(int j=2*i;j<=n;j+=i){
			f=(f-k[j])%2;
		}
		k[i]=f;
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
		if(k[i]) cnt++;
	if(!cnt){
		cout<<0<<endl;
		return 0;
	}
	cout<<cnt<<endl;
	for(int i=1;i<=n;i++)
		if(k[i]) cout<<i<<" ";
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<tuple<int, int>> a;

    for (int i = 0; i < n; i++)
    {
        int A;
        cin >> A;
        a.push_back(tie(A, i));
    }

    sort(a.rbegin(), a.rend());

    for (int j = 0; j < n; j++)
    {
        if (get<1>(a[0]) == j)
            cout << get<0>(a[1]) << endl;
        else
            cout << get<0>(a[0]) << endl;
    }
    return 0;
}

Measured memory_bytes: 3312
import java.io.*;
// import java.math.*;
// import java.util.*;
// import java.util.Map.*;
// import java.util.stream.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        int N, A, B;
        N = Integer.parseInt (arr[0]);
        A = Integer.parseInt (arr[1]);
        B = Integer.parseInt (arr[2]);
        System.out.println (Math.min (A * N, B));
        return;
    }
}

Measured memory_bytes: 32408
#include <cassert>
#include <cmath>
#include <iostream>
#include <limits>
#include <vector>

int main(int argc, char const* argv[])
{
    int n;
    std::cin >> n;

    constexpr auto max_val = 10 * 10 * 10 * 10 * 10;

    auto vec = std::vector<int>(max_val, 0);

    for(int i=0; i< n; ++i)
    {
        int tmp;
        std::cin >> tmp;
        vec[tmp]++;
    }

    int result = 0;
    for(int i=0; i<max_val; ++i)
    {
        if(i == 0)
        {
            result = vec[0] + vec[1];
        }
        else if(i == (max_val - 1))
        {
            result = std::max(result, vec[max_val - 2] + vec[max_val - 1]);
        }
        else
        {
            result = std::max(result, vec[i - 1] + vec[i] + vec[i + 1]);
        }
    }
    std::cout << result << std::endl;
}

Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	ll n, a, b;
  	cin >> n >> a >> b;
  	ll c = a + b;
  	ll r = n%c;
  	
  	cout << (n/c)*a + min(a,r) << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000;
const ll mod = 1000000007;
ll test[12345678], res[12345678], aa[1234][1234], bb[1234][1234];
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
char maze[1234][1234];
signed main() {
	ll n, m, k, sum = 0, cnt = 1, ans = 0; string s; cin >> s;
	reverse(s.begin(), s.end()); test[0] = 1;
	for (int h = 0; h < s.size(); h++) {
		sum = ((ll)(s[h] - '0') * cnt + sum) % 2019;
		test[sum]++; //cout << sum << endl;
		cnt *= 10; cnt %= 2019;
	}
	for (int h = 0; h < 2019; h++) {
		ans += test[h] * (test[h] - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3740
l = list(map(int, input().split()))

a = l[0]
b = l[1]
t = l[2]

#print(a,b,t)

seisan = 0

for i in range(1,t+1):
	#print(i)
	if i%a == 0:
		#生産
		seisan += b

print(seisan)


Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll , ll> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 5100;
const int MOD = 1000000007;

vector<vector<ll> > dp(MAX, vector<ll>(MAX, -INF));

int main(){
  ll N;cin>>N;
  vector<P> a(N);
  rep(i,N){
    cin>>a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end(), greater<P>());


  // vector<vector<ll> > dp(N+1, vector<ll>(N+1, -INF));


  dp[0][0] = 0;

  //dp[i][j]は左にi,みぎにj移動が決まった場合の最大値
  rep(i,N+1){
    rep(j,N+1){
      if(i == 0){
        dp[i][j+1] = dp[i][j] + a[j].first * ( abs(  (N-1-j) - a[j].second ) );
      }
      else{
        if(j == 0){
          dp[i][j] = dp[i-1][j] + a[i-1].first * (abs(a[i-1].second  -  (i-1) ) );
        }
        else{
          if(i+j>N+1) continue;
          //どっちかからのmaxをとる
          dp[i][j] = max(dp[i-1][j] + a[i+j-1].first * (abs(a[i+j-1].second - (i-1) ) ),
          dp[i][j-1] + a[i+j-1].first * ( abs(a[i+j-1].second - (N-1-(j-1) ) ) ) );
          //右からN-1 - j
        }
      }
    }
  }

  //check
  /*
  rep(i,N+1){
    rep(j,N+1){
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }
  */

  ll ans = 0;
  rep(i,N+1){
    ans = max(ans , dp[i][N-i]);
  }
  cout<<ans<<endl;
}


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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cerr << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cerr << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
signed main() {
  int a, b; cin >> a >> b;
  cout << a * b;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3636
// Problem : E - Sum of gcd of Tuples (Hard)
// Contest : AtCoder - AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;
const int MOD=1e9+7;


ll Pow(ll x,ll p){
	ll ret=1;x%=MOD;
	for(;p;p>>=1,x=x*x%MOD) if(p&1) ret=ret*x%MOD;
	return ret;
}

const int maxn=100000+10;

ll dp[maxn];

int main()
{
	int n,k;cin>>n>>k;
	ll sum=0;
	for(int g=k;g>=1;--g){
		dp[g]=Pow(k/g,n);
		for(int j=g*2;j<=k;j+=g) dp[g]-=dp[j];
		dp[g]=(dp[g]%MOD+MOD)%MOD;
		sum+=(dp[g]*g)%MOD;
	}
	cout<<sum%MOD<<endl;
	return 0;
}


Measured memory_bytes: 4416
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

void YNout(bool check){
	if(check)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return;
}

void Yayout(bool check){
	if(check) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	
	return;
}

/*
template <typename T>
void vecout(vector<T>& vecout_vec){
	
	rep(i,0,vecout_vec.size()){
		cout << vecout_vec.at(i) << endl;
	}
	
	return ;
}

template <typename T>
void vecin(vector<T>& vecin_vec, ll n){
	
	ll temp ;
	
	rep(i,0,n){
		cin >> temp;
		vecin_vec.push_back(temp);
		
	}
}

template <typename T>
void in(T& literal_in, T& literal_in2, ...){
	cin >> literal_in;
	in(literal_in2, ...);
	
	return;
}

template <typename T>
void in(T& literal_in){
	
	cin >> literal_in;
	
	return;
}

template <typename T>
void out(T& literal_out, T& literal_out2, ...){
	cout << literal_out << endl;
	out(literal_out2, ...);
	
	return;
}

template <typename T>
void out(T& literal_out){
	
	cout << literal_out << endl;
	
	return;
}
*/


signed main(){
	ll n;
	cin >> n;
	
	ll a[n] = {};
	ll b[n] = {};
	
	
	rep(i,0,n){
		cin >> a[i];
	}
	
	ll temp = 0;
	
	rep(i,0,n){
		b[i] = a[i] - temp;
		temp = b[i];
	}
	
	ll memo = b[n-1] / 2;
	
	cout << memo*2;
	
	rep(i,0,n-1){
		cout << " ";
		
		if((i+1) % 2 != 0) cout << (b[i] - memo)*2;
		else cout <<  (b[i] + memo)*2;
		
	}
	
	cout << endl;
	return 0;
}


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n;
    while(cin >> n, n){
        vs v(n);
        rep(i, n) cin >> v[i];
        rep(i, n)rep(j, v[i].size()) if(v[i][j] == '.') v[i][j] = ' ';
        rep(i, n)rep(j, v[i].size()) if(v[i][j] == ' ' && v[i][j+1] != ' ') v[i][j] = '+';
        rep(i, n-2)rep(j, v[i].size()){
            if(v[i][j] == '+'){
                bool is = false;
                if(v[i+1][j] != ' ') continue;
                for(int k=i+2; k < n; k++){
                    if(v[k].size() < j) break;
                    if(v[k][j] == '+'){is = true; break;}
                    else if(v[k][j] != ' ')break;
                }
                if(is){
                    for(int k=i+1; k < n; k++){
                        if(v[k][j] != '+') v[k][j] = '|';
                        else break;
                    }
                }
            }
        }
        rep(i, n) cout << v[i] << endl;
    }
}

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

int main(void){
  int N, cnt = 0;
  int d[100];
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> d[i];
  }
  sort(d, d + N);
  for(int i = 0; i < N; i++){
    if(d[i] != d[i + 1]){cnt++;}
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

char s[4];

int main()
{
    cin>>s;
    int f = 0;
    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3])f = 1;
    if(s[0] == s[1] && s[1] == s[2]) f = 1;
    if(s[1] == s[2] && s[2] == s[3]) f = 1;
    cout<<(f?"Yes":"No")<<endl;
     return 0;
}


Measured memory_bytes: 764
using System;

class Program{
    public static void Main(){
        var n=int.Parse(Console.ReadLine());
        var s=Console.ReadLine().Split(' ');
        var S=new int[n];
        for(var i=0; i<n; i++){
            S[i]=int.Parse(s[i]);
        }
        Console.ReadLine();
        s=Console.ReadLine().Split(' ');

        var cnt=0;
        foreach(var c in s){
            var t=int.Parse(c);
            if(Array.BinarySearch(S, t)>=0){
                cnt++;
            }
        }

        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 19408
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Who Says a Pun?
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 5000;

/* typedef */

/* global variables */

char s[MAX_N + 4];
int as[MAX_N];

/* subroutines */

void z_algorithm(const int n, const char s[], int as[]) {
  as[0] = n;
  for (int i = 1, j = 0; i < n;) {
    while (i + j < n && s[j] == s[i + j]) j++;
    as[i] = j;
    if (j == 0)
      i++;
    else {
      int k = 1;
      while (i + k < n && k + as[k] < j)
        as[i + k] = as[k], k++;
      i += k; j -= k;
    }
  }
}

/* main */

int main() {
  int n;
  scanf("%d%s", &n, s);

  int maxl = 0;
  for (int i = 0, m = n; m > 1; i++, m--) {
    z_algorithm(m, s + i, as);

    for (int j = 1; j < m; j++) {
      int l = min(j, as[j]);
      if (maxl < l) maxl = l;
    }
  }

  printf("%d\n", maxl);
  return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N,K = cin.mapInt()
    H = cin.intColsList(N)
    H.sort()
    ans = int(1e09)
    for i in range(N - K + 1):
        ans = min(ans,H[i + K - 1] - H[i])
    print(ans)
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 50520
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();

    let v: Vec<u32> = (0..n).map(|_| read()).collect();

    println!("{}", v.iter().max().unwrap() - v.iter().min().unwrap());
}

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

int main(){
  int n,array[100000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>array[i];
  }
  long long ans=0;
  for(int i=0;i<n;i++){
    ans+=(array[array[i]-1]==i+1);
  }
  cout<<ans/2<<endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>

const long long INF = 1000000007;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int , pii> piii;
typedef pair<pii, pii> piiii;

int n;
ll k;
ll mat[101][101][101];
ll ans[101][101];

int main() {
	scanf("%d %lld", &n,&k);
	int m1[101][101],m2[101][101];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &mat[i][j][0]);
			if (i == j) ans[i][j] = 1;
			else ans[i][j] = 0;
		}
	}
	for (int x = 0; x < 100; x++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				ll sum = 0;
				for (int k = 0; k < n; k++) sum =(sum + mat[i][k][x] * mat[k][j][x])%INF;
				mat[i][j][x+1] = sum;
			}
		}
	}
	int cur = 0;
	while (k > 0) {
		if (k % 2 == 0) {
			k = k / 2;
			cur++;
			continue;
		}
		ll tmp[101][101];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				ll sum = 0;
				for (int k = 0; k < n; k++) sum = (sum+ans[i][k] * mat[k][j][cur])%INF;
				tmp[i][j] = sum;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) ans[i][j] = tmp[i][j];
		}
		k = k / 2;
		cur++;
	}
	ll sum = 0;


	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) sum = (sum + ans[i][j]) % INF;
	}
	printf("%lld\n", sum);
}


Measured memory_bytes: 3456
a,b,k=map(int,input().split())
ans=[]
def gcd(a,b):
    if b>a:
        return(gcd(b,a))
    elif b==0:
        return a
    else:
        return(gcd(b,a%b))
g=gcd(a,b)
for i in range(1,g+1):
    if g%i==0:
        ans.append(i)
print(ans[-k])

Measured memory_bytes: 3064
n, m = map(int, input().split())
a = 1
b = n
for i in range(m):
    l, r = map(int, input().split())
    if a < l:
        a = l
    if b > r:
        b = r
if a > b:
    print(0)
else:
    print(b - a + 1)

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

int cnt[10][10];
const int N = 2e5+7;
int ans[N];

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

    int n;
    cin>>n;

    for (int i=1; i<=n; i++) {
        string s = to_string(i);
        cnt[s[0]-'0'][s.back()-'0']++;
    }

    int ans = 0;
    for (int i=0; i<10; i++)
        for (int j=0; j<10; j++)
            ans += cnt[i][j]*cnt[j][i];
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>                                                                                                                                                                  #include <stdlib.h>                                                                                                                                                                                                                                                                                                                                                     int main (void) {                                                                                                                                                                       int h, a, ans=0;                                                                                                                                                                    scanf("%d%d", &h, &a);                                                                                                                                                                                                                                                                                                                                                  while ( h > 0 ) {                                                                                                                                                                       h -= a;                                                                                                                                                                             ans++;                                                                                                                                                                          }                                                                                                                                                                                                                                                                                                                                                                       printf("%d\n", ans);                                                                                                                                                                                                                                                                                                                                                    return EXIT_SUCCESS;                                                                                                                                                            }#include <stdio.h>
#include <stdlib.h>

int main (void) {
    int h, a, ans=0;
    scanf("%d%d", &h, &a);

    while ( h > 0 ) {
        h -= a;
        ans++;
    }

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

    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#![allow(unused_imports)]
#![allow(dead_code)]

use std::thread;
use std::io::{ self, Read };
use std::fmt;
use std::iter::Iterator;
use std::cmp::*;
use std::collections::*;
use std::str::*;
use std::mem::*;
use std::cell::*;

#[derive(Default)]
struct Input {
    buf: VecDeque<String>
}

impl Input {
    fn new() -> Input {
        Input { buf: VecDeque::new() }
    }

    fn read<T: FromStr>(&mut self) -> T 
    where <T as FromStr>::Err: fmt::Debug {
        self.next().unwrap().parse::<T>().unwrap()
    }

    fn read_2<T: FromStr, U: FromStr>(&mut self) -> (T, U)
    where <T as FromStr>::Err: fmt::Debug,
          <U as FromStr>::Err: fmt::Debug {
        (self.read(), self.read())
    }

    fn read_3<T: FromStr, U: FromStr, V: FromStr>(&mut self) -> (T, U, V)
    where <T as FromStr>::Err: fmt::Debug,
          <U as FromStr>::Err: fmt::Debug,
          <V as FromStr>::Err: fmt::Debug {
        (self.read(), self.read(), self.read())
    }

    fn read_bytes(&mut self) -> Vec<u8> {
        self.next().unwrap().into_bytes()
    }

    fn read_n<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where <T as FromStr>::Err: fmt::Debug {
        let mut v = Vec::new();
        for _ in 0..n { v.push(self.read::<T>()); }
        v
    }
}

impl Iterator for Input {
    type Item = String;
    fn next(&mut self) -> Option<String> {
        while self.buf.is_empty() {
            let mut s = String::new();
            let _res = io::stdin().read_line(&mut s);
            self.buf.extend(s.split_whitespace().map(|s| s.to_owned()));
        }
        self.buf.pop_front()
    }
}

fn run() {
    let mut ip = Input::new();
    const MOD: i64 = 1000000007;
    let n = ip.read();
    let k = ip.read();
    let mut v = Vec::<(i64, i64)>::new();
    for _ in 0..n {
        v.push(ip.read_2());
    }
    v.sort();
    let mut c = 0;
    for (a, b) in v {
        c += b;
        if c >= k {
            println!("{}", a);
            return;
        }
    }
}

fn main() {
    let _ = thread::Builder::new()
        .stack_size(50 * 1024 * 1024)
        .spawn(run).unwrap()
        .join();
}

Measured memory_bytes: 10620
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val xs = IntArray(n)
    val ys = IntArray(n)
    for (i in 0 until n) {
        val (x, y) = readLine()!!.split(' ').map { it.toInt() }
        xs[i] = x
        ys[i] = y
    }

    var ans = 1L shl 62

    for (xi in 0 until n) {
        for (xj in 0 until n) {
            for (yi in 0 until n) {
                for (yj in 0 until n) {
                    val xl = xs[xi]
                    val xr = xs[xj]
                    val yb = ys[yi]
                    val yt = ys[yj]
                    if (!(xl < xr && yb < yt)) continue

                    val cnt = (0 until n).count { xs[it] in xl..xr && ys[it] in yb..yt }
                    if (cnt >= k) {
                        ans = Math.min(1L * (xr - xl) * (yt - yb), ans)
                    }
                }
            }
        }
    }

    println(ans)
}

Measured memory_bytes: 52676
w, h, n = map(int, input().split())
whl = [[0 for _ in range(w)] for _ in range(h)]

xyal = []
for _ in range(n):
    xyal.append(list(map(int, input().split())))

for xya in xyal:
    if xya[2] == 1:
        for y in range(h):
            for x in range(xya[0]):
                whl[y][x] = 1

    if xya[2] == 2:
        for y in range(h):
            if xya[0]+1 > w:
                break
            for x in range(xya[0], w):
                whl[y][x] = 1

    if xya[2] == 3:
        for y in range(xya[1]):
            for x in range(w):
                whl[y][x] = 1

    if xya[2] == 4:
        for y in range(xya[1], h):
            for x in range(w):
                whl[y][x] = 1

ans = 0
for wh in whl:
    ans += wh.count(0)
print(ans)


Measured memory_bytes: 3188
#include<stdio.h>
int main(void)
{
	int n,s[100],i,j,x,y,z,a;
	scanf("%d",&n);
	for(i=0;i<n;i++) {
		scanf("%d",&s[i]);
	}
	for(i=0;i<n;i++) {
		for(j=i+1;j<n;j++){
			if(s[i]<=s[j]){
				x=s[j];
				s[j]=s[i];
				s[i]=x;
			}
		}
	}
	for(i=0;i<n;i++) {
		if(i%2==0) y=y+s[i];
		else z=z+s[i];
	}
	
	a=y-z;
	printf("%d\n",a);
	return 0;
}
	

Measured memory_bytes: 128
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int h = scanner.nextInt();
		int w = scanner.nextInt();
		for(int i = 0; i < h; i++){
			String string = scanner.next();
			System.out.println(string);
			System.out.println(string);
		}
	}
}

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

using namespace std;

#define    					IO        										ios_base::sync_with_stdio(0); cin.tie(0)
#define INF 1000000009
#define maxn 100005

int n,k;
int a[maxn],memo[maxn];

int call(int pos){
  if(pos == n - 1) return 0;
  if(memo[pos] != -1) return memo[pos];
  int maxi = INF;
  for(int i = 1; i <= k; i++){
    if(pos + i < n){
      maxi = min(maxi,abs(a[pos] - a[pos + i])+ call(pos + i));
    }
  }
  return memo[pos] = maxi;
}

int main(){
  IO;
  cin >> n >> k;
  for(int i = 0; i < n; i++) cin >> a[i];
  memset(memo,-1,sizeof(memo));
  cout << call(0) << endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int z=n%10;
	if(z==2||z==4||z==5||z==9||z==7)
	{
		printf("hon");
	}
	else
	if(z==0||z==1||z==6||z==8)
	{
		printf("pon");
	}
	else
	if(z==3)
	{
		printf("bon");
	}
}

Measured memory_bytes: 3764
from itertools import product
H,W,K=map(int, input().split())
pr=10**9+7
b=[0]*W
b[0]=1
z=[0]*W
rl=tuple(product([0,1], repeat=(W-1)))
l=[]
for i in rl:
    for j in range(W-2):
        if i[j] and i[j+1]:
            break
    else:
        l.append([0]+list(i)+[0])
for i in range(H):
    a=z.copy()
    for j in l:
        for k in range(W):
            if j[k]:
                a[k]=(b[k-1]+a[k])%pr
            elif j[k+1]:
                a[k]=(b[k+1]+a[k])%pr
            else:
                a[k]=(b[k]+a[k])%pr
    b=a
print(b[K-1])

Measured memory_bytes: 3064
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int v[] = new int[n];
    int c[] = new int[n];
    int s[] = new int[n];
    int ans = 0;

    for (int i=0; i<n; i++) {
      v[i] = Integer.parseInt(sc.next());
    }
    for (int i=0; i<n; i++) {
      c[i] = Integer.parseInt(sc.next());
    }
    for (int i=0; i<n; i++) {
      s[i] = v[i] - c[i];
      if (s[i] > 0) {
        ans += s[i];
      }
    }
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const int bb=18;
const double eps=1e-10;
const double pi=acos(-1);
LL n,m;
char str[N];
LL f[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    r(n); r(m);
    LL cnt0=0,cnt1=0,cnt2=0;
    FOR(i,1,n){
        r(f[i]);
        if(f[i]>0) cnt1++;//+
        else if(f[i]<0) cnt2++;//-
        else cnt0++;//0
    }
    sort(f+1,f+n+1);
    if(cnt1*cnt2>=m){//-
        LL l=-1e18,r=-1;
        LL ans;
        while(l<=r){
            LL mid=(l+r)>>1;
            LL sum=0;

            FOR(j,1,cnt2){
                LL ll=cnt2+cnt0+1,rr=n;
                LL res=cnt2+cnt0;
                while(ll<=rr){//最大的乘积大于mid的pos
                    LL midd=(ll+rr)>>1;
                    if(f[j]*f[midd]>mid){
                        res=midd;
                        ll=midd+1;
                    }
                    else rr=midd-1;
                }
                //cout<<res<<endl;
                sum+=res-(cnt2+cnt0);
            }
            //cout<<mid<<' '<<sum<<endl;
            if(sum<=cnt1*cnt2-m){
                ans=mid;
                r=mid-1;
            }
            else l=mid+1;

        }
        cout<<ans<<endl;
        return 0;
    }
    m-=cnt1*cnt2;
    if(m<=cnt0*(cnt1+cnt2)+cnt0*(cnt0-1)/2){
        cout<<0<<endl;
        return 0;
    }
    m-=cnt0*(cnt1+cnt2)+cnt0*(cnt0-1)/2;
    LL l=1,r=1e18;
    LL ans;
    //cout<<m<<endl;
    while(l<=r){
        LL mid=(l+r)>>1;
        LL sum=0;
        FOR(j,1,cnt2){
            LL ll=j+1,rr=cnt2;
            LL res=j;
            while(ll<=rr){//最大的乘积大于mid的pos
                int midd=(ll+rr)>>1;
                if(f[j]*f[midd]>mid){
                    res=midd;
                    ll=midd+1;
                }
                else rr=midd-1;
            }
            sum+=res-j;
        }
        FOR(j,cnt0+cnt2+1,n){
            LL ll=j+1,rr=n;
            LL res=n+1;
            while(ll<=rr){
                LL midd=(ll+rr)>>1;
                if(f[j]*f[midd]>mid){
                    res=midd;
                    rr=midd-1;
                }
                else ll=midd+1;
            }
            sum+=n-ll+1;
        }
        if(sum<=cnt1*(cnt1-1)/2+cnt2*(cnt2-1)/2-m){
            ans=mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ

int main(){
	long long a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	long long ret=b;
	ret+=min(c,a+b+1);
	printf("%lld\n",ret);
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    int a, b, t;
    cin >> a >> b >> t;
    int ans = b * (t / a);
    out(ans);
    return 0;
}


Measured memory_bytes: 256