akhauriyash/Code-Regression huggingface dataset:
#include<set>
#include<queue>
#include<cstdio>

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

using namespace std;

typedef	pair<int,int>	pii;

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

int main(){
	for(int w,h;scanf("%d%d",&w,&h),w;){
		int n;	scanf("%d",&n);
		int x1[1000],y1[1000],x2[1000],y2[1000];
		set<int> xorg,yorg;
		xorg.insert(0),xorg.insert(w-1);
		yorg.insert(0),yorg.insert(h-1);
		rep(i,n){
			scanf("%d%d%d%d",x1+i,y1+i,x2+i,y2+i);
			if(x1[i]<w)	xorg.insert(x1[i]);	if(x1[i]>1)	xorg.insert(x1[i]-1);
			if(y1[i]<h)	yorg.insert(y1[i]);	if(y1[i]>1)	yorg.insert(y1[i]-1);
			if(x2[i]<w)	xorg.insert(x2[i]);	if(x2[i]>1)	xorg.insert(x2[i]-1);
			if(y2[i]<h)	yorg.insert(y2[i]);	if(y2[i]>1)	yorg.insert(y2[i]-1);
		}

		int ww=xorg.size(),hh=yorg.size();
		static int f_x[1000001],f_y[1000001];
		{
			int t;
			set<int>::iterator it;
			for(it=xorg.begin(),t=0;it!=xorg.end();it++,t++)	f_x[*it]=t;
			for(it=yorg.begin(),t=0;it!=yorg.end();it++,t++)	f_y[*it]=t;
		}

		static bool mask[4000][4000]={};
		rep(y,hh)rep(x,ww)	mask[y][x]=false;
		rep(i,n){
			int l=f_x[x1[i]],r=f_x[x2[i]-1],u=f_y[y1[i]],b=f_y[y2[i]-1];
			for(int y=u;y<=b;y++)for(int x=l;x<=r;x++)	mask[y][x]=true;
		}

		int cnt=0;
		rep(y,hh)rep(x,ww){
			if(mask[y][x])	continue;

			queue<pii> qu;	qu.push(mp(y,x));
			while(!qu.empty()){
				pii a=qu.front();	qu.pop();
				int px=a.second,py=a.first;
				if(mask[py][px])	continue;
				mask[py][px]=true;
				rep(i,4){
					int xx=px+dx[i],yy=py+dy[i];
					if(0<=xx && xx<ww && 0<=yy && yy<hh && !mask[yy][xx]){
						qu.push(mp(yy,xx));
					}
				}
			}
			cnt++;
		}

		printf("%d\n",cnt);
	}

	return 0;
}

Measured memory_bytes: 4796
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>

using namespace std;

template <class T> using V = vector<T>;

using ll = long long;
using vll = V<ll>;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)

void Solve();

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/


void Solve(){
  ll n;
    cin>>n;
  vll ans(0);
  ll count=n;
  FOR(i,2,55555){
    bool b=true;
    FOR(j,2,sqrt(i)+1){
      if(i%j==0){
        b=false;
        break;
      }
    }
    if(b&&i%5==1){
      ans.push_back(i);
      count--;
    }

    if(count==0){
      break;
    }
  }

  FOR(i,0,n){
    cout<<ans[i]<<" ";
  }
  cout<<"\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 100005;
const int mod = 1000000007;

LL F[N], IF[N];
int p[N];

LL _pow(LL a, LL b) {
  if(!b) return 1;
  if(b == 1) return a;
  if(b == 2) return a * a % mod;
  if(b & 1) {
    return a * _pow(a,b-1) % mod;
  }
  return _pow(_pow(a,b/2),2);
}

void pre() {
  F[0] = 1;
  rep(i,1,N) {
    F[i] = i * F[i-1] % mod;
  }
  IF[N - 1] = _pow(F[N - 1], mod - 2);
  for(int i = N - 2; i >= 0; i--) {
    IF[i] = IF[i + 1] * (i + 1) % mod;
  }
}

LL nCr(int n, int r) {
  if(r > n) return 0;
  return F[n] * (IF[r] * IF[n-r] % mod) % mod;
}

int main() {
  pre();
  int n;
  S(n);
  int cnt = 0;
  rep(i,1,n+2) {
    int x;
    S(x);
    if(p[x]) {
      cnt = p[x] - 1 + n + 1 - i;
    }
    p[x] = i;
  }
  rep(i,1,n+2) {
    int ans = nCr(n + 1, i) - nCr(cnt, i - 1) + mod;
    if(ans >= mod) ans -= mod;
    P(ans);
  }
  return 0;
}

Measured memory_bytes: 3200
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    s = input()

    ans = 0
    for i in s[1:]:
        if i == "E":
            ans += 1
    l = [ans]

    for i in range(n-1):
        trial = 0
        if s[i] == "W":
            trial += 1
        if s[i+1] == "E":
            trial -= 1
        ans += trial
        l.append(ans)

    print(min(l))


if __name__=="__main__":
    main()


Measured memory_bytes: 21660
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<bitset>
#define ll long long
using namespace std;
int read()
{
	char ch=getchar();int f=0,x=1;
	while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();}
	return f*x;
}
bitset<4000005> a;
bitset<4000005> b; 
int n,sum;
int main()
{
	a[0]=1;
	n=read();
	for(int i=1;i<=n;i++)
	{
		int x=read();
		b=a<<x;
		a=a|b;
		sum+=x;
	}
	for(int i=sum/2+(sum%2?1:0);i<=sum;i++)
	{
		if(a[i])
		{
			printf("%d",i);
			return 0;
		}
	}
}


Measured memory_bytes: 2688
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

i64 gcd(i64 a, i64 b) {
	if (a % b == 0) {
		return b;
  }
  return gcd(b, a % b);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n;
  cin >> n;
  vi64 a(n);
  rep(i, n) cin >> a[i];
  i64 ans = a[0];
  reps(i, n - 1) ans = gcd(ans, a[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    a = [0]+list(map(int,input().split()))+[0] #端の項
    #抜かす項はどうする？
    cost = sum(abs(a[i+1]-a[i]) for i in range(n+1)) #まずは全工程通るパターン
    for i in range(1,n+1): #順番に抜かす項を設定してプリント
        print(cost - abs(a[i+1]-a[i]) - abs(a[i]-a[i-1]) + abs(a[i+1]-a[i-1])) #集合の考え方

Measured memory_bytes: 15992
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define N  100000
#define mod 1000000007


typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

using namespace std;

ll power(int x,int y){
    if(y==0)	return 1LL;
	if(y==1)	return x%mod;
	ll m = power(x, y/2);
	if(y%2)	return (m*m%mod)*x%mod;
	return (m*m)%mod;
	}
	
int main() {
	fast;
	int n;
	cin>>n;
	vector<int> a(n);
	unordered_map<int,int> m;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if((a[i]%2==0 && n%2!=1) || a[i]>(n-1)){
			cout<<0;
			return 0;
			}
		if (m.find(a[i]) == m.end()) m[a[i]]=1;
		else if(m[a[i]]==1) m[a[i]]++;
		else if(m[a[i]]==2){
			cout<<0;
			return 0;
			}
		}
	if(n%2==1 && m[0]==2) cout<<0;
	else{
		cout<<power(2,(n/2));
		}
	
}


Measured memory_bytes: 2700
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    cout << n * n * n << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]

diff = [abs(a[0])]

for i in range(n-1):
    diff.append(abs(a[i+1] - a[i]))

diff.append(abs(a[-1]))

min_cost = 10**10
ori = sum(diff)
a.append(0)
a.insert(0,0)
for i in range(n):
    cost = ori - diff[i] - diff[i+1]
    cost += abs(a[i] - a[i+2])
    print(cost)


Measured memory_bytes: 14048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, X;
  int L;
  int lsum = 0;
  int out = 0;
  cin >> N >> X;
  for (int i=1; i<N+1; i++) {
    cin >> L;
    lsum += L;
    if (lsum > X) {
      out = i;
      break;
    }
  }
  if (out == 0) out = N+1;
  cout << out << endl;
}

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


def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    ans = [0 for _ in range(10 ** 6 + 2000)]
    candidate = 110

    for x in range(1, candidate + 1):
        for y in range(1, candidate + 1):
            for z in range(1, candidate + 1):
                total = 0
                total += (x ** 2) + (y ** 2) + (z ** 2)
                total += (x * y) + (y * z) + (z * x)

                if total < (10 ** 6 + 2000):
                    ans[total] += 1

    for i in range(1, n + 1):
        print(ans[i])


if __name__ == '__main__':
    main()


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

int main(){
	int t;
	cin >> t;
	int ac=0,wa=0,tle=0,re=0;
	for(int i=0;i<t;i++){
		string inp;
		cin >> inp;
		if(inp=="AC") ac++;
		if(inp=="WA") wa++;
		if(inp=="TLE") tle++;
		if(inp=="RE") re++;
	}
	cout << "AC x " << ac << "\n";
	cout << "WA x " << wa << "\n";
	cout << "TLE x " << tle << "\n";
	cout << "RE x " << re << "\n";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

int main()
{
    string S, T;
    cin >> S >> T;

    rep(i, S.size())
    {
        if (S[i] != T[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}


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

using namespace std;

int main() {
  string S;
  cin >> S;
  for (int i = S.size() - 2; i > 0; --i) {
    if (i % 2 != 0) {
      continue;
    }
    string sub = S.substr(0, i);
    string first = S.substr(0, sub.size() / 2);
    string second = S.substr(sub.size() / 2, sub.size() / 2);
    if (first == second) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll n;

int dfs(ll cur, int a, int b, int c) {
	if (cur > n) return 0;
	int res = 0;
	if (a == 0 || b == 0 || c == 0) res = 0;
	else res += 1;
	res += dfs(cur * 10 + 7, a+1, b, c);
	res += dfs(cur * 10 + 5, a, b+1, c);
	res += dfs(cur * 10 + 3, a, b, c+1);
	return res;
}

int main() {
	cin >> n;
	cout << dfs(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int n, t[4*N][2], lazy[4*N][2];

void build(int v, int tl, int tr, int i) {
	if (tl == tr) {
		t[v][i] = n;
	} else {
		int tm = (tl + tr) / 2;
		build(v*2, tl, tm, i);
		build(v*2+1, tm+1, tr, i);
		t[v][i] = min(t[v*2][i], t[v*2+1][i]);
	}
}

void push(int v, int i) {
	if(lazy[v][i] != inf) {
		t[v*2][i] = min(t[v*2][i], lazy[v][i]);
		lazy[v*2][i] = min(lazy[v*2][i], lazy[v][i]);
		t[v*2+1][i] = min(t[v*2+1][i], lazy[v][i]);
		lazy[v*2+1][i] = min(lazy[v*2+1][i], lazy[v][i]);
		lazy[v][i] = inf;
	}
}

void update(int v, int tl, int tr, int l, int r, int addend, int i) {
	if (l > r) 
		return;
	if (l == tl && tr == r) {
		t[v][i] = min(t[v][i], addend);
		lazy[v][i] = min({lazy[v][i], addend});
	} else {
		push(v, i);
		int tm = (tl + tr) / 2;
		update(v*2, tl, tm, l, min(r, tm), addend, i);
		update(v*2+1, tm+1, tr, max(l, tm+1), r, addend, i);
		t[v][i] = min(t[v*2][i], t[v*2+1][i]);
	}
}

int query(int v, int tl, int tr, int l, int r, int i) {
	if (l > r)
		return inf;
	if (l <= tl && tr <= r)
		return t[v][i];
	push(v, i);
	int tm = (tl + tr) / 2;
	return min(query(v*2, tl, tm, l, min(r, tm), i), query(v*2+1, tm+1, tr, max(l, tm+1), r, i));
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int q;
	cin >> n >> q;
	build(1, 2, n - 1, 0);
	build(1, 2, n - 1, 1);
	for(int i = 0; i < 4*N; i++) {
		lazy[i][0] = inf;
		lazy[i][1] = inf;
	}
	int ans = (n - 2) * (n - 2);
	while(q--) {
		int a, b;
		cin >> a >> b;
		if(a == 1) {
			int mn = query(1, 2, n - 1, b, b, 0);
			ans -= (mn - 2);
			if(mn > 2) {
				update(1, 2, n - 1, 2, mn - 1, b, 1);
			}
		}
		else {
			int mn = query(1, 2, n - 1, b, b, 1);
			ans -= (mn - 2);
			if(mn > 2) {
				update(1, 2, n - 1, 2, mn - 1, b, 0);
			}
		}
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 24356
#include <stdlib.h>

void count_graph(int **g_cost, int n, int x, int y);
int main(void);

void count_graph(int **g_cost, int n, int x, int y){
    int i, j, k, o_cost, new_cost_tmp;
    for(i=0; i<n; i++){
       k = 0;
       for(j=i; j<n; j++){
          g_cost[i][j] = k;
          k++;
       }
    }
    g_cost[x-1][y-1] = 1;
    for(i=0; i<n; i++){
       for(j=i; j<n; j++){
          o_cost = g_cost[i][j];
          new_cost_tmp = g_cost[i][x-1] + g_cost[x-1][i] + g_cost[j][y-1] + g_cost[y-1][j] + 1;
          if(o_cost > new_cost_tmp)
            g_cost[i][j] = new_cost_tmp;
       }
    }
}

int main(void){
    int n, x, y, cnt, i, j;
    scanf("%d %d %d", &n, &x, &y);
    int **g_cost;
    int *cost_cnt;
    cost_cnt = malloc(sizeof(int)*n);
    for(i=0; i<n; i++){
       cost_cnt[i]=0;
    }
    g_cost = malloc(sizeof(int *)*n);
    for(i=0; i<n; i++){
       g_cost[i] = malloc(sizeof(int)*n);
    }
    for(i=0; i<n; i++){
       for(j=0; j<n; j++){
          g_cost[i][j] = 0;
       }
    }
    count_graph(g_cost, n, x, y);
    for(i=0; i<n; i++){
       for(j=i; j<n; j++){
          cost_cnt[g_cost[i][j]]++;
       }
    }

    for(i=1; i<n; i++){
       printf("%d\n", cost_cnt[i]);
    }
    for(i=0; i<n; i++){
       free(g_cost[i]);
    }
    free(g_cost);
    free(cost_cnt);

    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <math.h>
#include <ctype.h>
using namespace std;
int main(){

bool equal = true;
string A, B;
cin >> A >> B;

if (A.size() > B.size()){
  cout << "GREATER" << endl;
  equal = false;
}
else if(B.size() > A.size()){
  cout << "LESS" << endl;
  equal = false;
}
else{
  for (int i = 0; i < A.size(); i++){
    if(A.at(i) == B.at(i)){
      continue;
    }
    else if(A.at(i) > B.at(i)){
      cout << "GREATER" << endl;
      equal = false;
      break;
    }
    else{
      cout << "LESS" << endl;
      equal = false;
      break;
    }
  }
}

if(equal == true){
  cout << "EQUAL" << endl;
}

return 0;
}

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

int main(){
    int H,N;
    cin>>H>>N;
    int A[N],B[N];
    for(int i=0;i<N;i++){
        cin>>A[i]>>B[i];
    }
    long int dp[H+1];
    dp[0]=0;
    for(int i=1;i<=H;i++){
        dp[i]=INT_MAX;
        for(int j=0;j<N;j++){
            dp[i]=min(dp[(i-A[j]<0)?0:i-A[j]]+B[j],dp[i]);

        }
    }
    cout<<dp[H]<<endl;
    
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <utility>
#include <queue>
#include <algorithm>

#define ll long long int
#define INF 1e18

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

int *a;
int n;

int main(int argc, char const* argv[])
{
	cin >> n;
	a = new int[n];
	ll *sum = new ll[n];
	for(int i = 0; i < n; i++){
			cin >> a[i];
			a[i] = a[i] - i - 1;
	}
	sort(a, a + n);
	for(int i = 0; i < n; i++){
			if(i == 0)sum[i] = a[i];
			else sum[i] = sum[i - 1] + a[i];
	}
	ll mini = INF;
	for(int i = 0; i < n - 1; i++){
			ll res = 0;
			res = (ll)sum[n - 1] - (ll)sum[i] * 2;
			ll x;
			if(n - 2 * i - 2 > 0){
					x = a[i + 1];
			}else{
					x = a[i];
			}
			res += - (ll)x * (n - 2 * i - 2);
			if(res < mini)mini = res;
	}
	ll res1 = sum[n - 1] - (ll)n * a[0];
	ll res2 = (ll)n * a[n - 1] - sum[n - 1];
	mini = min(res1, min(res2, mini));
	cout << mini << endl;
	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long f[10000005];

#define rep(i,a,b) for(long long i=(a);i<=(b);++i)
typedef long long ll;
inline ll read() {
    char c=getchar();ll x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
    return x*f;
}
int main(){  
    ll n;
     n=read();
     rep(i,1,n){
        rep(j,1,n/i){
            f[i*j]++;
        }
     }
     ll ans=0;
     rep(i,1,n){
        ans=ans+i*f[i]*1ll;
     }
     printf("%lld",ans);
     return 0;
 } 

Measured memory_bytes: 81884
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int K, N;
	cin >> K >> N;
	vector<int> H(N);
	for (int i=0; i<N; i++)
		cin >> H[i];
	sort(all(H));
	vector<int> dif(N);
	for (int i=0; i<N-1; i++)
	{
		dif[i] = abs(H[i] - H[i+1]);
	}
	dif[N-1] = H[0] + (K - H[N-1]);
	sort(rall(dif));
	cout << K - dif[0] << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s[n], ss, ans = "Yes";
  for (int i = 0; i < n; i++) {
    cin >> ss;
    for (int j = 0; j < i; j++) {
      if (s[j] == ss) {
        ans = "No";
      }
    }
    if (i != 0 && s[i - 1][s[i - 1].length() - 1] != ss[0]) {
      ans = "No";
    }
    s[i] = ss;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
int A[100000];

int main() {

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

    int up = 0;
    int cur = A[0];
    int ret = 1;

    for(int i = 1; i < N; i++){
        if(up == 0 && A[i] > cur){
            up = 1;
        }
        else if(up == 0 && A[i] < cur){
            up = -1;
        }
        else if(up == 1 && A[i] < cur){
            ret++;
            up = 0;
        }
        else if(up == -1 && A[i] > cur){
            ret++;
            up = 0;
        }
        cur = A[i];
    }

	cout << ret << endl;

}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
loop{ # 無限ループをするメソッド
  a, op, b = STDIN.gets.split(' ')
  a = a.to_i
  b = b.to_i
  case op
  when  "+"
    puts  a + b
  when  "-"
    puts  a - b 
  when "*"
    puts  a * b 
  when "/" 
    puts  a / b 
  else
    break
  end
}

Measured memory_bytes: 8628
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a,b,c,k=MI()
    p=min(a,k)
    m=max(k-(a+b),0)
    print(p-m)

main()

Measured memory_bytes: 9204
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int d;
int c[27];
int s[366][27];
int calc(vector<int> t){
    int last[26]={};
    vector<int> ret(d);
    int ans=0;
    for(int i=0; i<d; i++){
        ans+=s[i][t[i]];
        last[t[i]]=i+1;
        for(int j=0; j<26; j++){
            ans-=c[j]*(i+1-last[j]);
        }
        ret[i]=ans;
    }
    return ans;
}
mt19937 mt(334);

int main()
{
    cin>>d;
    for(int i=0; i<26; i++) cin>>c[i];
    for(int i=0; i<d; i++) for(int j=0; j<26; j++) cin>>s[i][j];
    vector<int> t(d);
    
    int last[26]={};
    for(int i=0; i<d; i++){
        int kmx=0, mx=-1e9;
        for(int k=0; k<26; k++){
            int sum=s[i][k];
            int myon=last[k];
            last[k]=i+1;
            for(int j=0; j<26; j++){
                sum-=c[j]*(i+1-last[j]);
            }
            last[k]=myon;
            if(mx<sum) kmx=k, mx=sum;
        }
        t[i]=kmx;
        last[kmx]=i+1;
    }

    set<int> st[26];
    for(int i=0; i<d; i++) st[t[i]].insert(i);

    uniform_int_distribution<> rndk(0, d-1), rndq(0, 25);
    clock_t start = clock();
    int ans=calc(t);
    while((double)(clock()-start)/CLOCKS_PER_SEC<1.95){
        int k, q;
        k=rndk(mt), q=rndq(mt);
        if(t[k]==q){
            continue;
        }
        int pr=t[k], ansp=ans;
        ans-=s[k][pr];
        ans+=s[k][q];
        int l1=-1, l2=-1, r1=d, r2=d;
        auto itr1=st[pr].find(k);
        if(itr1!=st[pr].begin()){
            itr1--;
            l1=*itr1;
            itr1++;
        }
        itr1=st[pr].erase(itr1);
        if(itr1!=st[pr].end()){
            r1=*itr1;
        }
        auto itr2=st[q].insert(k).first;
        if(itr2!=st[q].begin()){
            itr2--;
            l2=*itr2;
            itr2++;
        }
        itr2++;
        if(itr2!=st[q].end()){
            r2=*itr2;
        }
        ans+=c[q]*(k-l2)*(r2-k);
        ans-=c[pr]*(k-l1)*(r1-k);
        t[k]=q;
        if(ansp>ans){
            st[pr].insert(k);
            st[q].erase(k);
            t[k]=pr;
            ans=ansp;
        }
    }
    for(int i=0; i<d; i++){
        cout<<t[i]+1<<endl;
    }
	return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
const int N=8;
pair<int,int> A[N];
long long cnt,n;
long double s,sum;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i)
        scanf("%d %d",&A[i].first,&A[i].second);
    sort(A,A+n);
    do
    {
        s=0;
        for(int i=1;i<n;++i)
            s+=hypot(abs(A[i].first-A[i-1].first),abs(A[i].second-A[i-1].second));
        sum+=s;

        cnt++;
    }while(next_permutation(A,A+n));

    //cout<<sum/cnt<<endl;
    printf("%.9LF",sum/cnt);
    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		BigDecimal sum = BigDecimal.ZERO;
		BigDecimal multiSum = BigDecimal.ONE;
		BigDecimal let;
		MathContext mc = new MathContext(20,RoundingMode.HALF_UP);


		for (int i = 0; i < N; i++) {
			let = new BigDecimal(sc.next());
			sum = sum.add(BigDecimal.ONE.divide(let,mc));
		}

		System.out.println(BigDecimal.ONE.divide(sum,mc));

	}
}




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

int main() {
  int64_t a, b, x, ans;
  cin >> a >> b >> x;
  if (a%x==0 && b%x==0) {
    ans=(b-a+x)/x;
  }
  else {
    if (a%x==0) {
      ans=(b-(b%x)-a+x)/x;
    }
    else {
      if (b%x==0) {
        ans=(b-a+(a%x))/x;
      }
      else {
        ans=(b-(b%x)-a+(a%x))/x;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power(T a, T b) {return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always




int main() {
    
    
    
    
    int n; cin >> n;
    int p[n]; rep(i, n) cin >> p[i];
    int cnt = 0;
    rep3(i, 1, n - 1) {
        if (p[i - 1] < p[i] && p[i] < p[i + 1]) cnt++;
        if (p[i + 1] < p[i] && p[i] < p[i - 1]) cnt++;
    }
    out(cnt);
    
    
}



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

using namespace std;

const int MOD = 1e9 + 7;

int dp[10010][2][128];

void solve()
{
	string K;
	int D;
	cin >> K >> D;

	int N = K.size();

	dp[0][1][0] = 1;

	for (int i = 0; i < N; i++)
	{
		int d = K[i] - '0';
		for (int f = 0; f < 2; f++)
			for (int m = 0; m < D; m++)
				for (int nd = 0; nd <= (f ? d : 9); nd++)
				{
					dp[i + 1][f & (nd == d)][(m + nd) % D] += dp[i][f][m];
					dp[i + 1][f & (nd == d)][(m + nd) % D] %= MOD;
				}
	}

	cout << (dp[N][0][0] + dp[N][1][0] + MOD - 1) % MOD << endl;

}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 10240
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  string s;
  cin >> s;
  int n = s.length();
  bool stuck = s[0] == s[n - 1];
  if (stuck) {
    cout << (n%2 ? "Second" : "First") << endl;
    return 0;
  }
  cout << (n%2 ? "First" : "Second") << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ
int sd(int x)
{
	if(!x) return 0;
	return sd(x/10)+x%10;
}
int main()
{
	int n,m=1e9;
	cin>>n;
	for(int i=1;i<n;++i)
		m=min(m,sd(i)+sd(n-i));
	cout<<m<<"\n";
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.math;

void main(){

    while(true){
	string[] s = [];
	for(int i=0;i<8;i++){
	    string temp = readln();
	    if(stdin.eof()) break;
	    s ~= chomp(temp);
	}
	if(stdin.eof()) break;

	string ans = "none";
	for(int i=0;i<7;i++)
	    for(int j=0;j<7;j++)
		if(s[i][j]=='1'&&s[i][j+1]=='1'&&s[i+1][j]=='1'&&s[i+1][j+1]=='1') ans = "A";

	for(int i=0;i<5;i++)
	    for(int j=0;j<8;j++)
		if(s[i][j]=='1'&&s[i+1][j]=='1'&&s[i+2][j]=='1'&&s[i+3][j]=='1') ans = "B";

	for(int i=0;i<8;i++)
	    for(int j=0;j<5;j++){
		if(s[i][j]=='1'&&s[i][j+1]=='1'&&s[i][j+2]=='1'&&s[i][j+3]=='1') ans = "C";
	    }

	for(int i=0;i<6;i++)
	    for(int j=1;j<8;j++)
		if(s[i][j]=='1'&&s[i+1][j]=='1'&&s[i+1][j-1]=='1'&&s[i+2][j-1]=='1') ans = "D";

	for(int i=0;i<7;i++)
	    for(int j=0;j<6;j++)
		if(s[i][j]=='1'&&s[i][j+1]=='1'&&s[i+1][j+1]=='1'&&s[i+1][j+2]=='1') ans = "E";

	for(int i=0;i<6;i++)
	    for(int j=0;j<7;j++)
		if(s[i][j]=='1'&&s[i+1][j]=='1'&&s[i+1][j+1]=='1'&&s[i+2][j+1]=='1') ans = "F";

	for(int i=0;i<7;i++)
	    for(int j=1;j<7;j++)
		if(s[i][j]=='1'&&s[i][j+1]=='1'&&s[i+1][j-1]=='1'&&s[i+1][j]=='1') ans = "G";

	writeln(ans);
	if(stdin.eof()) break;
	auto a = readln();
	if(stdin.eof()) break;
    }
}

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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    int N, K, h, ans = 0;
    cin >> N >> K;
    rep(i, N) {
        cin >> h;
        if (h >= K) ans++;
    }
    cout << ans << endl;
}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////



ll T;
ll N;
ll K[202020], L[202020], R[202020];
ll i, j, k;


void qqq(){
    
    scanf("%lld", &N);
    ll ans = 0;
    vector<pll> mkl, mkr;
    rep(i,0,N){
        scanf("%lld%lld%lld", &K[i], &L[i], &R[i]);
        if(L[i]>=R[i]){
            mkl.push_back({K[i], -abs(L[i] - R[i])});
        }else{
            mkr.push_back({N - K[i], -abs(L[i] - R[i])});
        }
        ans += min(L[i], R[i]);
    }

    sort(mkl.begin(), mkl.end());
    sort(mkr.begin(), mkr.end());
    j = 0;
    priority_queue<ll> pql,pqr;
    pql.push(-1e18);
    pqr.push(-1e18);
    rep(i,0,mkl.size()){

        while (j < mkl.size() && i + 1 > mkl[j].first)
        {
            if(mkl[j].second<pql.top()){
                ans -= mkl[j].second - pql.top();
                pql.pop();
                pql.push(mkl[j].second);
            }
            ++j;
        }
        if(j==mkl.size())
            break;
        ans -= mkl[j].second;
        pql.push(mkl[j].second);
        ++j;
    }
    //printf("%lld\n", ans);
    j = 0;
    rep(i,0,mkr.size()){

        while (j < mkr.size() && i + 1 > mkr[j].first)
        {
            if(mkr[j].second<pqr.top()){
                ans -= mkr[j].second - pqr.top();
                pqr.pop();
                pqr.push(mkr[j].second);
            }
            ++j;
        }
        //printf("%lldnn\n", j);
        if(j==mkr.size())
            break;
        ans -= mkr[j].second;
        pqr.push(mkr[j].second);
        ++j;
    }
    printf("%lld\n", ans);
}


int main(){
    scanf("%lld", &T);
    
    while(T>0){
        qqq();
        --T;
    }
    
    return 0;
}

Measured memory_bytes: 13680
#include <bits/stdc++.h>
#define LL long long

namespace io {
    template <typename T> inline void read(T & _x) {
        int f = 0, ch; _x = 0;
        while(!isdigit(ch = getchar())) f |= ch == '-';
        while(isdigit(ch)) _x = _x * 10 + ch - '0', ch = getchar();
        if(f) _x = -_x;
    }
    template <typename T, typename ... Args> inline void read(T &_f, Args& ... args) {
        read(_f), read(args ...);
    }
    inline void _deal(char ch) { putchar(ch); }
    template <typename T> inline void _deal(T _x) {
        if (_x < 0) putchar('-'), _x = -_x;
        if (_x > 9) _deal(_x / 10);
        putchar(_x % 10 + '0');
    }
    inline void write() {}
    template <typename T, typename ... Args> inline void write(T _f, Args ... args) {
        _deal(_f), write(args...);
    }
}

int32_t main() {
	int x;
	std::cin >> x;
	puts(x >= 30 ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3632
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    L = input()
    dp = [[0]*2 for _ in range(len(L) + 1)]
    
    dp[0][0] = 1
    for i in range(len(L)):
        if L[i] == '1':
            dp[i + 1][0] = dp[i][0]*2
            dp[i + 1][1] = dp[i][0] + dp[i][1]*3
        else:
            dp[i + 1][0] = dp[i][0]
            dp[i + 1][1] = dp[i][1]*3
        dp[i + 1][0] %= MOD
        dp[i + 1][1] %= MOD
    print(sum(dp[-1])%MOD)
if __name__ == '__main__':
    main()


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

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

double dif[20][20];
double L[20];
double a[20];
double b[20];

int main(){
  int N, M;
  double res;
  while(cin >> N >> M && (N || M)){
    res = 0.0;
    rep(i, N) cin >> L[i] >> a[i] >> b[i];
    rep(i, N)rep(j, N){
      double dL = L[i] - L[j];
      double da = a[i] - a[j];
      double db = b[i] - b[j];
      dif[i][j] = dL * dL + da * da + db * db;
    }
    rep(i, (1 << N)){
      int cnt = 0;
      double value = 0.0;
      rep(j, N) if(i & (1 << j) ) cnt++;

      if(cnt == M){
	rep(j, N){
	  for(int k = 0; k < j; k++){
	    if((i & (1 << j)) && (i & ( 1 << k))){
	      value += dif[j][k];
	    }
	  }
	}
	res = max(res, value);
      }

    }
    cout << fixed << setprecision(9) << res << endl;
  }

  return 0;
}

Measured memory_bytes: 0
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

#n = int(input())
#n,a = [int(i) for i in readline().split()]
n,k = [int(i) for i in readline().split()]
xy = [[int(i) for i in readline().split()] for i in range(n)]

xy.sort()
#print(xy)
ans = 4*10**18+10
for i in range(n):
    for j in range(i+k-1,n):
        dx = xy[j][0] - xy[i][0]
        y = sorted(xy[k][1] for k in range(i,j+1))
#        print(y,i,j)
        L = len(y)-k+1
        for i in range(L):
            dy = y[i+k-1]-y[i]
            ans = min(ans,dy*dx)
        


print(ans)

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

int N;
ll rui[200010];
ll sum(int l, int r){
    return rui[r] - rui[l-1];
}

ll L_sm[200010], L_bg[200010];
ll R_sm[200010], R_bg[200010];

void L_init(){
    for(int i=2, j=1;i<=N;i++){
        for(;j+2<=i;j++){
            if(abs(sum(1,j)-sum(j+1,i)) < abs(sum(1,j+1)-sum(j+2, i))){
                break;
            }
        }
        L_sm[i] = min(sum(1, j), sum(j+1, i));
        L_bg[i] = max(sum(1, j), sum(j+1, i));
    }
}

void R_init(){
    for(int i=N-1, j=N;i>=0;i--){
        for(;j-2>=i;j--){
            if(abs(sum(i, j-2)-sum(j-1, N)) > abs(sum(i, j-1)-sum(j, N))){
                break;
            }
        }
        R_sm[i] = min(sum(i, j-1), sum(j, N));
        R_bg[i] = max(sum(i, j-1), sum(j, N));
    }
}

int main(){

    cin >> N;
    rep(i, N){
        cin >> rui[i+1];
        rui[i+1] += rui[i];
    }
    L_init();
    R_init();
    
    //for(int i=1;i<=N;i++)cout << L_bg[i] << (i==N ? "\n" : " ");
    //for(int i=1;i<=N;i++)cout << L_sm[i] << (i==N ? "\n" : " ");
    //for(int i=1;i<=N;i++)cout << R_bg[i] << (i==N ? "\n" : " ");
    //for(int i=1;i<=N;i++)cout << R_sm[i] << (i==N ? "\n" : " ");
    
    ll ans = 1e17;
    for(int i=2;i+2<=N;i++){
        ll bg = max(L_bg[i], R_bg[i+1]);
        ll sm = min(L_sm[i], R_sm[i+1]);
        ans = min(ans, bg-sm);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
        if(b&1)res = res * x % MOD;
        x = x * x % MOD;
        b>>=1;
    }
    return res;
}

ll modinv(ll x){
    return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
}
void outendl(){
    was_output = false;
    cout << endl;
}
ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
}

int main(){
    ll n = in();
    ll a = in();
    ll b = in();
    ll ans = 0;
    ll s = a + b;
    ans += n / s * a;
    ans += min(a,n%s);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int i;
		for(i = 1; i <= b; i++) {
			if((a * i - c) % b == 0) {
				break;
			}
		}
		if(i <= b) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define int long long 
#define uint unsigned long long 
#define double long double 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sett(c) (c).resize(unique(all(c))-(c).begin())
#define sz(a) (int)(a).size()
#define hell 1000000007
#define pi pair<int,int>
#define vi vector<int> 
#define vb vector<bool> 
#define vpi vector<pair<int,int>> 
#define x first 
#define y second 
#define endl '\n'
#define forn(i,n) for(int i = 0 ; i < n ; i++ )
#define for1(i,n) for(int i = 1 ; i < n ; i++ )
#define fore(i,a,b) for(int i = a ; (a>b)?(i>=b):(i<=b) ; (a>b)?(i--):(i++) ) 
 
using namespace std;
const int MAX = 1e6;

long long binpow(long long a, long long b) {

    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        res %= hell;
        a %= hell;
        b >>= 1;
    }
    return res;
}

bool comp(const pi& a , const pi& b ){
        return a.y < b.y;
}

int ncr(int n , int r ){
	r = min(r,n-r);
	int res = 1 ;
	for(int i = 1 ; i <= r ; i++ ){
		( res *= n-i+1 )%= hell;
		res /= i ;
	}
	return res ;
}

void solve(){
        int a , b , c ;
        cin >> a >> b ; 
        cin >> a >> c ;
        if(c == 1){
			cout << 1  << endl ;
		}else {
			cout << 0 << endl; 
		}
}
 
int32_t main(){
        
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        cout << fixed;
        cout.precision(10);
 
#ifdef LOCAL_DEFINE
        //freopen("input.txt","rt",stdin);
        //freopen("output.txt","w",stdout);
#endif
 
        int t = 1;
        //cin >> t ;
        while(t--){
                solve();
        }
#ifdef LOCAL_DEFINE
        cout << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
#endif
 
        return 0;
}


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

int main(void) {
  int a, b;

  scanf("%d %d", &a, &b);

  printf("%d", (int)fmax((double)a - b, fmax((double)a * b, (double)a + b)));

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define szxb 110
#define F(a,b) for(register int (a)(0);(a)^(b);(a)++)
using namespace std;
int n,m;
string a[szxb];
signed main()
{
	scanf("%d%d",&n,&m);getchar();
	F(i,n){getline(cin,a[i]);}
	sort(a,a+n);
	F(i,n){cout<<a[i];}
	return putchar(10),0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
snk = [-1] * (n+1)
ans = 0
for j in range(k):
	d = int(input())
	lis = list(input().split())
	for i in range(d):
		y = int(lis[i])
		snk[y] = 0
for j in range(n):
    if snk[j+1] == -1:
        ans += 1
print(ans)

Measured memory_bytes: 9220
#include<stdio.h>

int main(void)
{
        int x[3],y[3],n,x1;

        scanf("%d%d%d%d",&x[0],&y[0],&x[1],&y[1]);

        x1 = x[0];
        if(x[0]<x[1]){
                n =x[1] -x[0];
                y[2] = n+y[1];
                y[3] =n+y[0];
        }
        else{
                n =x[0]-x[1];
                y[2] = y[1]-n;
                y[3] = y[0]-n;
        }

        n = y[1] - y[0];
        x[2] = x[1] - n;
        x[3] = x1 - n;

        printf("%d %d %d %d\n",x[2],y[2],x[3],y[3]);

        return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000007;
const int MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < 3; i++) {
    cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 3600
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int A1, A2, A3;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> A1 >> A2 >> A3;
    cout << ((A1 + A2 + A3) >= 22 ? "bust" : "win") << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		StringBuilder a = new StringBuilder(sc.next());
		StringBuilder c = new StringBuilder(a).reverse();
		StringBuilder b = new StringBuilder(sc.next());
		StringBuilder d = new StringBuilder(b).reverse();
		System.out.println((c.compareTo(b)==0 && d.compareTo(a)==0) ? "YES" : "NO");
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35532
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] xi = new int[N];
        int[] yi = new int[N];
        int[] hi = new int[N];

        for(int i = 0; i < N; i++) {
            xi[i] = scanner.nextInt();
            yi[i] = scanner.nextInt();
            hi[i] = scanner.nextInt();
        }

        int X = 0, Y = 0, h = 0;
        for(int i = 0; i < N; i++) {
            if(hi[i] > 0) {
                X = xi[i];
                Y = yi[i];
                h = hi[i];
                break;
            }
        }

        for(int cx = 0; cx <= 100; cx++) {
            for(int cy = 0; cy <= 100; cy++) {
                int H = h + Math.abs(X - cx) + Math.abs(Y - cy);
                boolean ok = true;
                for(int i = 0; i < N; i++) {
                    if(hi[i] != Math.max(0, H - Math.abs(xi[i] - cx) - Math.abs(yi[i] - cy))) {
                        ok = false;
                        break;
                    }
                }
                if(ok) {
                    System.out.println(cx + " " + cy + " " + H);
                    return;
                }
            }
        }
    }
}


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

int main() {
    int M, D;
    cin >> M >> D;

    int ans = 0;
    for (int j = 1; j <= M; j++) {
        for (int i = 20; i <= D; i++) {
            int d1 = i / 10;
            int d2 = i % 10;
            if (d1 < 2 || d2 < 2) continue;
            else {
                if (d1 * d2 == j) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 764
#include <stdio.h>

int compare_int(const void *a, const void *b)
{
  return *(int*)a - *(int*)b;
}

int main(void)
{
  int n;
  scanf("%d", &n);
  int i, a[n];
  i = 0;
  while (i < n)
  {
    scanf("%d", &a[i]);
    i++;
  }

  qsort(a, n, sizeof(int), compare_int);

  i = 0;
  while (i + 1 < n)
  {
    if (a[i] == a[i + 1])
    {
      printf("NO\n");
      return 0;
    }
    i++;
  }
  printf("YES\n");
  return 0;
}


Measured memory_bytes: 1788