akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

long long n, a, b;
int main () {
	scanf("%lld%lld%lld", &n, &a, &b);
	if ((b - a) % 2 == 0) printf("%lld\n", b - a >> 1);
	else printf("%lld\n", min(a + b - 1 >> 1, (n << 1) - a - b + 1 >> 1));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(){
  int N,W;
  cin >> N >> W;
  int w[N],v[N];
  for(int i=0;i<N;i++) cin >> w[i] >> v[i];

  //dp[i]:価値iを与える最小の重さ
  int dp[100001];
  fill(dp,dp+100001,W+1);
  dp[0]=0;
  for(int i=0;i<N;i++){
    for(int j=100000;j>=0;j--){
      if(dp[j]!=W+1 && j+v[i]<=100000){
        dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
      }
    }
  }

  int v_max=0;
  for(int i=0;i<=100000;i++){
    if(dp[i]<=W) v_max=max(v_max,i);
  }
  cout << v_max <<endl;
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){

	int a,b,c,i;
	int d=0;

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

	for(i=a;i<=b;i++){
		if(c%i==0){
			d=d+1;
		}
	}

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

	return 0;
}

Measured memory_bytes: 1752
c = Array.new(3) { gets.chomp.split.map(&:to_i) }
a = Array.new(3, 0)
b = Array.new(3, 0)
0.step(2) do |j|
  i = j
  b[j] = c[0][j] - a[0]
  a[i] = c[i][0] - b[0]
end

0.step(2) do |i|
  0.step(2) do |j|
    if c[i][j] != a[i] + b[j]
      puts "No"
      exit
    end
  end
end
puts "Yes"

Measured memory_bytes: 1788
a,b = map(str,input().split())
s_ = a + b

def try_square_root_naive(n):
    m = int(n**.5)
    return m if abs(m*m - n) < 1e-6 else None 

if try_square_root_naive(int(s_)) == None:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC010_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var numberAmount = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray<int>();

            var odd = 0;
            for (int i = 0; i < numberAmount; i++)
            {
                if (input[i] % 2 != 0)
                {
                    odd++;
                }
            }

            if (odd % 2 == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 21600
#include <iostream>
using namespace std;
long long a, n, m;
long long val(long long x){
  long long sum = 0;
  while(x){
    sum += x%10; x /= 10;
  }return sum;
}
int solve(){
  int cnt = 0;
  for ( int y = 1; y <= 72; y++ ){
    long long x = 1;
    for ( int t = 1; t <= n; t++ ) x *= (y+a);
    if (x <= m && val(x) == y) cnt++;
  }return cnt;
}
int main() {
  cin >> a >> n >> m;cout << solve() << endl;
}  


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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int main(void) {
    ll k;
    cin >> k;

    int ans = 1;
    ll x = 7;
    while (x<k) {
        x = x*10+7;
        ans++;
    }
    ll r = 0;
    rep(i, 0, 10000000) {
        ll q = x / k, r = x%k;
        x = r*10+7;
        
        if (r==0) {
            cout << ans << endl;
            return 0;
        }
        ans++;
    }

    
    puts("-1");
  
    


    return 0;
}



Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

void judgePrime(int n, vector<bool>& isNotPrime)
{
	for (auto i = 0; i <= n; ++i)
	{
		isNotPrime.push_back(false);
	}
	isNotPrime[0] = true;
	isNotPrime[1] = true;

	for (auto i = 2; i <= n; ++i)
	{
		if (!isNotPrime[i])
		{
			for (auto j = i * 2ll; j <= n; j += i)
			{
				isNotPrime[(int)j] = true;
			}
		}
	}
}

int main()
{
	auto maxVal = (int)1e5;
	vector<bool> isNotPrime;
	judgePrime(maxVal, isNotPrime);

	vector<int> sum(maxVal + 1);
	for (auto i = 1; i <= maxVal; ++i)
	{
		sum[i] = sum[i - 1];
		if (i % 2 > 0
			&& isNotPrime[i] == false
			&& isNotPrime[(i + 1) / 2] == false)
		{
			++sum[i];
		}
	}

	vector<int> ans;
	int Q;
	cin >> Q;
	for (auto i = 0; i < Q; ++i)
	{
		int l, r;
		cin >> l >> r;
		ans.push_back(sum[r] - sum[l - 1]);
	}

	for (auto i = 0; i < Q; ++i)
	{
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1548
#include<bits/stdc++.h>
using namespace std;
struct rule{
  string a;
  string b;
  string c;
};
int main(){
  while(1){
    
    int n,m;
    cin >> n >> m;
    if(n==0&&m==0)break;
    rule r[1100];
    rule p[1100];
    vector<int> ok(m,0);
    for(int i=0;i<n;i++){
      cin >> r[i].a >>r[i].b >> r[i].c;
    }
    for(int i=0;i<m;i++){
      cin >> p[i].a >>p[i].b >> p[i].c;
    }
    int f=0;
    for(int i=0;i<n;i++){
      if(r[i].a[0]=='p'){
	f=1;
      }
      else f=0;
    
      //cout << f << endl;
      for(int j=0;j<m;j++){
	int fl=0;
	//cout << r[i].b << " "<<p[j].c<< endl;
	for(int k=0;k<r[i].b.size();k++){
	  if(r[i].b[k]!='?'&&r[i].b[k]!=p[j].a[k]){
	    fl=1;
	    break;
	  }
	  if(r[i].c[k]!='?'&&r[i].c[k]!=p[j].b[k]){
	    fl=1;
	    break;
	  }
	}
	if(fl==0){
	  ok[j]=f;
	}
      }
    }
    int co=0;
    for(int i=0;i<m;i++){
      if(ok[i]==1)co++;
      // cout << ok[i] << endl;
    }
    cout << co << endl;  
    for(int i=0;i<m;i++){
      if(ok[i]==1)cout <<p[i].a << " "<< p[i].b << " "<< p[i].c<< endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3484
#include <stdio.h>
#define PI 3.141592653589

int main(void)
{
	double r;
	double s, l;

	scanf("%lf", &r);

	s = r * r * PI;
	l = 2 * PI * r;

	printf("%.6lf %.6lf\n", s, l);

	return 0;
}

Measured memory_bytes: 652
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n ;
  vi a(n+1),b(n+1),c(n+1),d(n+1);
  REP(i,n+1) cin>>a[i];


  if (a[0]!=0){
    if (n!=0){
      cout<<-1<<endl;
      return 0;
    }else{
      if (a[0]!=1){
        cout<<-1<<endl;
        return 0;
      }
      cout<<1<<endl;
      return 0;
    }
  }



  if (n==0){
    if (a[0]==0){
      cout<<1<<endl;
      return 0;
    }
  }







  
  ll nown=1;
  b[0]=1;
  c[0]=1;
  for(ll i=1;i<n+1;i++){
    nown=min(nown,(ll)4611686018427387903)*2;
    b[i]=nown;
    nown-=a[i];
    c[i]=nown;
    if (nown<0){
      cout<<-1<<endl;
      return 0;
    }
  }




  ll lasti=-1;
  d[n]=a[n];
  for(ll i=n-1;i>=0;i--){
    d[i]=d[i+1]+a[i];

    if (lasti==-1){
      if (b[i]<d[i]){
        lasti=i;
      }
    }
  }



  //cout<<"!!!!"<<lasti<<endl;
  lasti++;
    //この時点のnownとしたから数えたやつを比較
  b[lasti]=d[lasti];
  c[lasti]=d[lasti]-a[lasti];
  for(ll j=lasti+1;j<n+1;j++){
    b[j]=d[j];
  }
    







  int flag=0;
  for(ll i=0;i<n+1;i++){
    ans+=b[i];
    //cout<<b[i]<<" "<<c[i]<<endl;
    flag+=(b[i]<=0);
  }
  if (flag!=0){
    cout<<-1<<endl;
    return 0;
  }



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


/*
4
0 1 0 0 8
*/

Measured memory_bytes: 6404
n=int(input())
a=[]
b=list(map(int,input().split()))
for i in range(n):
  for j in range(n)[n-i-1::-1]:
    if b[j]==j+1:
      a.append(b.pop(j))
      break
if len(a)<n:
  print(-1)
  exit()
a.reverse()
for i in a:
  print(i)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

int main(){
    int N,T,mi=1000000;
    cin>>N>>T;

    for(int i=0;i<N;i++){
        int cost,time;
        cin>>cost>>time;
        if(time<=T){
           mi = min(mi,cost); 
        }
    }
    if(mi==1000000){
        cout<<"TLE"<<endl;
    }else{
        cout<<mi<<endl;
    }
    return 0;
}

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


void solve(long long a, long long b, long long c, long long d, long long e, long long k){
    if(e-a<=k)
    {
        cout << "Yay!" << endl;
    }else
    {
        cout << ":(" << endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    long long d;
    scanf("%lld",&d);
    long long e;
    scanf("%lld",&e);
    long long k;
    scanf("%lld",&k);
    solve(a, b, c, d, e, k);
    return 0;
}


Measured memory_bytes: 256
n, x, y = map(int, input().split())

result = [0 for _ in range(n)]
for i in range(1, n):
    for j in range(i+1, n+1):
        result[min(j-i, abs(x-i)+abs(y-j)+1)] += 1
for i in result[1:]:
    print(i)

Measured memory_bytes: 3444
#include<iostream>
#include<cmath>
using namespace std;
#define ll long long
ll x;
ll p[245][245];
signed main(){
	cin>>x;
	for(int i=0;i<120;i++){
		p[i][0]=i-120;
		p[i][1]=pow((i-120),5);
		p[i+120][0]=i;
		p[i+120][1]=pow(i,5);
	}
	for(int i=0;i<=238;i++){
		for(int j=i+1;j<=239;j++){
			if((p[j][1]-p[i][1])==x){cout<<p[j][0]<<" "<<p[i][0];return 0;}
		}
	}
} 

Measured memory_bytes: 4496
N, W = map(int, input().split(" "))

v = [0] * N
w = [0] * N
dp = [[-1 for i in range(W + 1)] for j in range(N + 1)]

for i in range(N):
    v[i], w[i] = map(int, input().split(" "))

def rec(i, j):
    if dp[i][j] != -1:
        return dp[i][j]

    if i == N:
        res = 0
    elif j < w[i]: 
        res = rec(i + 1, j) 
    else: 
        res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]) 
        dp[i][j] = res 
    return res 
print(rec(0, W))

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

const int maxn=1e5+10;

int n,m,u[maxn],v[maxn],Ans;
bitset<410> need[410];

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i,j;
	bool flag;
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++)
		scanf("%d%d",&u[i],&v[i]);

	for (i=1;i<=n;i++)
	{
		need[i][i]=1;
		flag=1;
		for (j=m;j>=1;j--)
		{
			if (need[i][u[j]]&&need[i][v[j]])
			{
				flag=0;
				break;
			}
			if (need[i][u[j]]||need[i][v[j]])
				need[i][u[j]]=need[i][v[j]]=1;
		}
		need[i][0]=!flag;
	}

	for (i=1;i<=n;i++) if (!need[i][0])
	for (j=i+1;j<=n;j++) if (!need[j][0])
		Ans+=!(need[i]&need[j]).count();
	printf("%d\n",Ans);
}


Measured memory_bytes: 1024
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL n;
	VL a;
	cin >> n;
	FOR(i, 0, n)
		a.push_back(IN<LL>());

	sort(a.begin(), a.end());

	double center = a[n - 1] / 2.0;
	double sa = 999999999.0;
	LL ansb = 0;
	FOR_REV(i, n - 2, 0) {
		if (abs(a[i] - center) < sa) {
			ansb = a[i];
			sa = abs(a[i] - center);
		}

	}
	cout << a[n - 1] << " " << ansb << endl;


	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> a(m);
    rep(i,m){
        cin >> a[i].se >> a[i].fi;
    }
    sort(a.begin(),a.end());
    int cnt = 1;
    int r=a[0].fi;
    REP(i,1,m){
        if(r <= a[i].se){
            cnt++;
            r = a[i].fi;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <iomanip> //小数点以下を表示させる(setprecision())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n';

typedef long long ll;

using namespace std;

int main()
{

    ll W, H, x, y;
    cin >> W >> H >> x >> y;

    int same = 0;
    if (2 * x == W && 2 * y == H)
    {
        same = 1;
    }
    double ans = H * W / 2.0;

    cout << fixed;
    cout << setprecision(8) << ans << ' ';
    cout << same << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rept(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}


//最大公約数を返す関数
int gcd(int n) {
	return 0;
}


//最小公倍数を返す関数
int mcd(int n) {
	return 0;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1-x2),2) + pow(abs(y1-y2),2));
}


int main()
{
	int n; cin >> n;
	vi d(n);
	for (int i = 0;i < n;i++) {
		cin >> d[i];
	}

	
	sort(d.begin(), d.end());
	int ans = d[d.size()/2] - d[d.size()/2 - 1];
	cout << ans << endl;


	system("pause");
	return 0;
}

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

int main() {
  int N;
  cin >> N;

  int sum = 0;
  int max = 0;
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;

    if (p > max) {
      max = p;
    }
    sum += p;
  }

  cout << sum - (max/2) << endl;
}

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

int main() {
  int a, b; cin >> a >> b;
  if ((a+b)%2 == 0) cout << (a+b)/2 << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

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

template <LL MOD=1000000007> class MODLL {
public:
  LL x;
  MODLL(const LL _x) : x(_x % MOD) {};
  MODLL operator+(const MODLL rhs) const { return MODLL(*this) += rhs; }
  MODLL operator-(const MODLL rhs) const { return MODLL(*this) -= rhs; }
  MODLL operator*(const MODLL rhs) const { return MODLL(*this) *= rhs; }
  MODLL operator/(const MODLL rhs) const { return MODLL(*this) /= rhs; }
  MODLL& operator+=(const MODLL rhs) { x += rhs.x; x %= MOD; return *this; }
  MODLL& operator-=(const MODLL rhs) { x -= rhs.x; x %= MOD; if(x<0) x += MOD; return *this; }
  MODLL& operator*=(const MODLL rhs) { x *= rhs.x; x %= MOD; return *this; }
  MODLL inv() const {
    if(x == 0) { throw "does not have inverse"; }
    LL a = x, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return MODLL(u);
  }
  MODLL& operator/=(const MODLL rhs) { (*this) *= rhs.inv(); return *this; }
  MODLL pow(ULL n) const {
    MODLL res = 1;
    MODLL a = x;
    while (n > 0) {
      if (n & 1) res *= a;
      a = a * a;
      n >>= 1;
    }
    return res;
  }
};

typedef MODLL<> ML;


void test() {
  {
    ML x = 3;
    assert(x.pow(45).x == 644897553);
  }
  {
    for(int i=1; i<13; i++) {
      MODLL<13> x = i;
      assert( (x.inv().x * i) % 13 == 1 );
    }
  }
}


int main() {
  LL N;
  std::cin >> N;
  std::vector<LL> s(N);
  for(LL i=0; i<N; i++) {
    std::cin >> s[i];
  }

  LL ans = 0;
  for(LL c = 1; c < N; c++) {
    LL score = 0;
    for(LL k=1; N-1-k*c > 0; k++) {
      LL A = N-1-k*c;
      LL B = A - c;
      if(B <= 0) break;
      LL left = k*c;
      LL right = N-1-k*c;
      if(left >= right && ((N-1)-left) % c == 0) continue;
      if(left >= right && right % c == 0) continue;
      score += s[left];
      score += s[right];
      ans = std::max(ans, score);
    }
  }

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



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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int L, R;

        void solve(InputReader in, PrintWriter out) {
            L = in.nextInt();
            R = in.nextInt();
            if (R - L + 1 >= 2019) {
                out.println(0);
            } else {
                int ans = Integer.MAX_VALUE;
                for (int i = L; i <= R; ++i) {
                    for (int j = i + 1; j <= R; ++j) {
                        ans = Math.min(ans, ((i % 2019)*(j % 2019)) % 2019);
                    }
                }
                out.println(ans);
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}

Measured memory_bytes: 22228
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [(f64, f64); n]
    }
    let mut ans = 0.0;
    for i in 0..n - 1 {
        for j in i + 1..n {
            ans += ((v[i].0 - v[j].0).powf(2.0) + (v[i].1 - v[j].1).powf(2.0)).sqrt();
        }
    }
    ans = ans * 2.0 / n as f64;
    println!("{}", ans);
}


Measured memory_bytes: 4352
def count_neighbor_beauties(n, d):
    if d == 0:
        return n
    return 2 * (n - d)


def calc_ave(cnt, n, m):
    return cnt * (m - 1) / n ** 2


def solve(n, m, d):
    cnt = count_neighbor_beauties(n, d)
    ans = calc_ave(cnt, n, m)
    print(ans)


def main():
    n, m, d = map(int, input().split())
    solve(n, m, d)


main()


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N - 1), B(N - 1);
  vector<vector<int>> G(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i] >> B[i];
    A[i]--, B[i]--;
    G[A[i]].emplace_back(B[i]);
    G[B[i]].emplace_back(A[i]);
  }

  map<pair<int, int>, int> color;

  vector<int> vc(N, -1);

  vector<bool> visited(N, false);
  visited[0] = true;

  queue<int> que;
  que.push(0);

  int k = 0;

  while (!que.empty()) {
    int u = que.front();
    que.pop();

    int c = 1;

    for (int v : G[u]) {
      if (visited[v]) continue;
      if (c == vc[u]) c++;
      vc[v] = color[make_pair(u, v)] = color[make_pair(v, u)] = c++;
      que.push(v);
      visited[v] = true;
    }

    k = max(k, c - 1);
  }

  cout << k << '\n';
  for (int i = 0; i < N - 1; i++) {
    cout << color[make_pair(A[i], B[i])] << '\n';
  }
  return 0;
}


Measured memory_bytes: 19712
#include <bits/stdc++.h>
using namespace std;
long long AccXor(long long N){
  long long dpN;
  switch(N%4){
    case 0:
      dpN=N;
      break;
    case 1:
      dpN=1;
      break;
    case 2:
      dpN=N^1;
      break;
    case 3:
      dpN=0;
      break;
  }
  return dpN;
}

int main(){
  long long A, B, dpA, dpB, ans;
  cin >> A >> B;
  A--;
  dpA=AccXor(A);
  dpB=AccXor(B);
  ans=dpA^dpB;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	string a[3] = {"Sunny", "Cloudy", "Rainy"};
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s == a[i]) {
			dump(a[(i + 1) % 3]);
			return 0;
		}
	}

	return 0;
}


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

int main(){
  int D; cin >> D;
  vector<int> c(26);
  for(int i=0; i<26; i++) cin >> c[i];
  vector<vector<int>> s(D,vector<int>(26));
  for(int i=0; i<D; i++){
    for(int j=0; j<26; j++){
      cin >> s[i][j];
    }
  }
  vector<vector<int>> lastc(D+1,vector<int>(26,0));
  vector<int> t(D);
  
    srand(std::time(nullptr));
  
  for(int i=1; i<=D; i++){
    
    int cont; /*cin >> cont;
    cont--;*/ cont=rand()%26;
    t[i-1]=cont;
    
    //lastcの更新
    for(int j=0; j<26; j++){
      if(j==cont) lastc[i][j]=i;
      else lastc[i][j]=lastc[i-1][j];
    }
  }
  
  int M=1000000;//調整
  for(int i=0; i<M; i++){
    int d,q; /*cin >> d >> q; q--;
    */
    d=rand()%D+1; 
    q=rand()%26;
    int qold=t[d-1];
    
    int sat=0;
    
    sat = sat - s[d-1][qold];
    sat = sat + s[d-1][q];
    
    int lastcold = lastc[d-1][qold];
    for(int j=d; j<=D; j++){
      if(j==d){
        sat-=c[qold]*(j-lastcold);
      }
      else if(lastc[j][qold]==j){
        break;
      }
      else{
        sat-=c[qold]*(lastc[j][qold]-lastcold);
      }
    }
    
    for(int j=d; j<=D; j++){
      if(lastc[j][q]==j){
        break;
      }
      else{
        sat+=c[q]*(d-lastc[j][q]);
      }
    }
    
    if(sat>0){
      for(int j=d; j<=D; j++){
        if(j==d){
          lastc[j][qold]=lastc[j-1][qold];
        }
        else if(lastc[j][qold]==j){
          break;
        }
        else{
          lastc[j][qold]=lastc[j-1][qold];
        }
      }
      
      for(int j=d; j<=D; j++){
        if(j==d){
          lastc[j][q]=d;
        }
        else if(lastc[j][q]==j){
          break;
        }
        else{
          lastc[j][q]=lastc[j-1][q];
        }
      }
      
      t[d-1]=q;
    }
  }
  
  for(int i=0; i<D; i++){
    cout << t[i]+1 << endl;
  }
}

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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int m = 800;
  for(int i = 0; i < n-2 ; i++){
  	int a = (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10 + (s.at(i+2)-'0');
  	m = min(m, abs(a - 753));
  }
   cout << m << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int a[100][3]={0};
int b[100];

int main()
{
    int n,x,y,h;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
    int i,j,ok;
    if(n==1)
    {
        printf("%d %d %d",a[0][0],a[0][1],a[0][2]);
        return 0;
    }
    for(i=0;i<=100;i++){
        for(j=0;j<=100;j++)
    {
        ok=1;
        int k=0;
        while(!a[k][2]) k++;
        h=a[k][2]+abs(a[k][0]-i)+abs(a[k][1]-j);
        for(int index=0;index<n;index++)
        {
            int t;
            t=a[index][2]+abs(a[index][0]-i)+abs(a[index][1]-j);
            if(a[index][2]) {if(h!=t) ok=0;}
            else {if(h>t) ok=0;}
        }
        if(ok) break;
    }if(ok) break;}
    printf("%d %d %d",i,j,h);
    return 0;
}


Measured memory_bytes: 128
n, k, q = map(int, input().split())
points = [k] * n
a = []
for i in range(q):
    a.append(int(input())-1)
for cand in a:
    points[cand] += 1
points = [i-q for i in points]
ans = ["Yes" if i > 0 else "No" for i in points]
print(*ans, sep="\n")

Measured memory_bytes: 19628
s=list(input())
t=list(input())
s.sort()
t.sort(reverse=True)
s_=str()
t_=str()
for i in range(len(s)):
    s_+=s[i]
for j in range(len(t)):
    t_+=t[j]
    
dic=[s_,t_]
dic.sort()
print("Yes" if dic[0]==s_ and s!=t else "No")


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
  int Left, Right;
  int c;
  int result;
  scanf("%d %d", &Left, &Right);
  int i,j;
  if((Right - Left) >= 2019){
    result = 0;
    printf("%d",result);
  }else{
    for(i = Left; i < Right; i++){
      for(j = i + 1; j <= Right; j++){
        c = (i % 2019) * (j % 2019) % 2019;
        if(i == Left && j == i + 1){
          result = c;
        }
        if(c < result){
          result = c;
        }
        if(result == 0){
          printf("%d",result);
          exit(0);
        }
      }
    }
    printf("%d",result);
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  int count = 0;
  cin >> n >> m;
  for(int i=n;i<=m;i++){
    if( i%10 == i/10000 && (i/10)%10 == (i/1000)%10 ){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const LL MOD=1000000007ll;
const LL INF=2000000000ll;

long power(long a,long b){return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}
long comb(int N,int K)
{
	long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
		y=y*i%MOD;
	}
	return x*power(y,MOD-2)%MOD;
}

long hcomb(int N, int K){
    return comb(N+K-1, N-1);
}


int t = 1;
void dfs(const vector<vector<int> > &G, int v, vector<bool> &seen, VI &d, VI &f) {
    seen[v] = true; // v を訪問済にする
    d[v] = t;

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v] == false) { // next_v が探索済だったらスルー
          	t++;
        	dfs(G, next_v, seen, d, f); // 再帰的に探索     	
        }
    }
    t++;
    f[v] = t;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);

    int n, u, k;
    cin >> n;
    VVI G(n);
    REP(i,n){
        cin >> u >> k;
        if (k){
            G[i].resize(k);
            REP(j,k) {
                cin >> G[i][j];
                G[i][j]--;
            }
          	sort(ALL(G[i]));
        }
    }

    vector<bool> seen(n,false);

    VI d(n,0), f(n,0);

  	REP(i,n){
      	if (d[i] == 0){
        	dfs(G, i, seen, d, f);
          	t++;
        }
    }

    REP(i,n) cout << i+1 << " " << d[i] << " " << f[i] << endl;

}


Measured memory_bytes: 3176
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int A[100010];
int N;
int isOK(int key) {
    int B[100010];
    B[0] = key;
    rep(i, N) {
        B[i + 1] = A[(i) % N] * 2 - B[i];
    }
    //cout << B[0] << " " << B[N] << endl;
    //rep(i, N + 1) cout << i << " " << B[i] << endl;
    if (B[0] < B[N]) return -1;
    else if (B[0] == B[N]) return 0;
    else return 1;
}

// 汎用的な二分探索のテンプレ
int binary_search() {
    int lower = 0;
    int upper = 2000000000;

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (true) {
        //cout << lower << " " << upper << endl;
        int mid = (upper + lower) / 2;
        if (isOK(mid * 2LL) == -1) lower = mid;
        else if (isOK(mid * 2LL) == 1) upper = mid;
        else return mid * 2LL;
    }
}
void output(int key) {
    int B[100010];
    B[0] = key;
    rep(i, N) {
        B[i + 1] = A[(i) % N] * 2 - B[i];
    }
    rep(i, N) {
        if (i != 0) cout << " ";
        cout << B[i];
    }
    cout << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) {
        cin >> A[i];
    }
    output(binary_search());
    //cout << isOK(2) << endl;


    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const int MAX_N = 1e3+5;
const int MAX_H = 2e4+5;

LL dp[MAX_N][MAX_H] = {};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int H,N; cin >> H >> N;
    REP(i,MAX_N) REP(j,MAX_H) dp[i][j] = INF;
    dp[0][0] = 0;
    REP(i,N){
        int A,B; cin >> A >> B;
        REP(j,MAX_H){
            if(j - A >= 0){
                dp[i+1][j] = min(dp[i][j], dp[i+1][j-A]+B);
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    LL ans = INF;
    FOR(i,H,MAX_H){
        chmin(ans,dp[N][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 157312
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=chomp(readline())
    t=chomp(readline())
    n=length(s)
    l=length(t)
    ans="UNRESTORABLE"
    flg1=false
    for i in n-l+1:-1:1
        tmp=s[i:i+l-1]
        if tmp==t
            ans=s
            flg1=true
            break
        end
    end
    if !flg1
        for i in n-l+1:-1:1
            tmp=s[i:i+l-1]
            flg=true
            for j in 1:l
                if tmp[j]!=t[j] && tmp[j]!='?'
                    flg=false
                    break
                end
            end
            if flg
                ans=s[1:i-1]*t*s[i+l:end]
                break
            end
        end
    end
    for i in 1:length(ans)
        if ans[i]=='?'
            ans=ans[1:i-1]*"a"*ans[i+1:end]
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 170220
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int h,w,ans;
  scanf("%d%d",&h,&w);
  if(h%3==0 || w%3==0){
    printf("0\n");
    return 0;
  }
  ans=min(h,w);
  int Smax=w*(h/3), Smin=w*(h/3);
  Smax=max(Smax,(h-h/3)*(w/2));
  Smax=max(Smax,(h-h/3)*((w+1)/2));                          
  Smin=min(Smin,(h-h/3)*(w/2));
  Smin=min(Smin,(h-h/3)*((w+1)/2));
  ans=min(ans,Smax-Smin);
  
  Smax=w*(h/3+1), Smin=w*(h/3+1);
  Smax=max(Smax,(h-h/3-1)*(w/2));
  Smax=max(Smax,(h-h/3-1)*((w+1)/2));                          
  Smin=min(Smin,(h-h/3-1)*(w/2));
  Smin=min(Smin,(h-h/3-1)*((w+1)/2));
  ans=min(ans,Smax-Smin);
  
  Smax=h*(w/3), Smin=h*(w/3);
  Smax=max(Smax,(w-w/3)*(h/2));
  Smax=max(Smax,(w-w/3)*((h+1)/2));                          
  Smin=min(Smin,(w-w/3)*(h/2));
  Smin=min(Smin,(w-w/3)*((h+1)/2));
  ans=min(ans,Smax-Smin);
  
  Smax=h*(w/3+1), Smin=h*(w/3+1);
  Smax=max(Smax,(w-w/3-1)*(h/2));
  Smax=max(Smax,(w-w/3-1)*((h+1)/2));                          
  Smin=min(Smin,(w-w/3-1)*(h/2));
  Smin=min(Smin,(w-w/3-1)*((h+1)/2));
  ans=min(ans,Smax-Smin);
  
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
from collections import deque
N,M,X=map(int,input().split())
A=[0]*N;cost=0;C=[0]*N;bit=0;v=[0]*M;f=0;minimum=100000*12+1;e=0
for i in range(N):
  a = deque(list(map(int, input().split())))
  C[i]=a[0]
  a.popleft()
  A[i]=a

#print(A[2][2])
#print(C)

for i in range(2**N):
  for j in range(N):
    bit=(1<<j)
    if (i & bit)>0:
      cost+=C[N-1-j]
      for k in range(M):
        v[k]=v[k]+A[N-1-j][k]
  for l in range(M):
    if v[l]<X:
      f=1
     
  if f!=1 and cost<minimum:
    minimum=cost
    e=i
  cost=0;v=[0]*M;f=0
            
print(minimum if minimum!=100000*12+1 else "-1")

Measured memory_bytes: 9408
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std;
using boost::irange;

using ll = int64_t;
constexpr char LN = '\n';
template<class T> bool chmax(T& a, const T& b) {if(a<b){a=b;return true;}else{return false;}}
template<class T> bool chmin(T& a, const T& b) {if(b<a){a=b;return true;}else{return false;}}

#ifdef LOCAL
template<class H> void dump_(const char* s, H h) {cout<<s<<"="<<h<<LN; }
template<class H, class... T> void dump_(const char* s, H h, T... t) {for(;*s!=',';++s){cout<<*s;}cout<<"="<<h<<",";dump_(++s,t...);}
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#endif

struct init_ {init_(){ 
    cin.tie(nullptr); ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}} init_;

template<class C> C scan(size_t n) {C c(n);for(auto& v:c){cin>>v;}return c;}
template<class C> C scan(size_t n, size_t m) {C vss(n);for(auto& vs:vss){vs.resize(m);for(auto& v:vs){cin>>v;}}return vss;}

template<class R> struct Joined { const R& r; const char* s; };
template<class R> Joined<R> joined(const R& r, const char* s = " ") {return{r,s};}
template<class R> ostream& operator<<(ostream& out, Joined<R> j) {bool f=true;for(const auto& v:j.r){if(f){f=false;}else{out<<j.s;}out<<v;}return out;}

template<class T> using matrix = vector<vector<T>>;
template<class T> matrix<T> make_matrix(size_t n, size_t m, const T& init = T()) {matrix<T> vss(n);for(auto& vs:vss){vs.resize(m,init);}return vss;}
template<class T> ostream& operator<<(ostream& out, Joined<matrix<T>> j) {bool a=true;for(const auto& vs:j.r){if(a){a=false;}else{out<<LN;}bool f=true;for(const auto& v:vs){if(f){f=false;}else{out<<j.s;}out << v;}}return out;}

int main() {
    char c;
    cin >> c;
    cout << (char)(c + 1) << LN;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  ll N;
  std::cin >> N;
  std::vector< ll > va(N+1, 0LL);
  std::vector< ll > vb(N,   0LL);
  for (ll i = 0; i <= N; i++) {
    std::cin >> va[i];
  }
  for (ll i = 0; i < N; i++) {
    std::cin >> vb[i];
  }

  ll sum = 0LL;
  for (ll i = 0; i < N; i++) {
    ll damage = std::min(va[i], vb[i]);
    vb[i]   -= damage;
    sum     += damage;

    ll damage2 = std::min(va[i+1], vb[i]);
    va[i+1] -= damage2;
    sum     += damage2;
  }

  print(sum);
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main()
{
    int n,m;
    int a[100];
    int sum = 0;
    int c = 0;
    
    cin >> n >> m;
    for (int i = 0;i < n;i++){
        cin >> a[i];
        sum += a[i];
    }
    
    for (int i = 0;i < n;i++){
        if (4*m*a[i] >= sum){
            c++;
        }
    }
    if (c >= m){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    long double a,b,c;
    cin >> a >> b >> c;
    if(a + b + 2 * sqrt(a * b) < c)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    long long a,b,c,d;
    long long n;
    cin >> a >> b >> c >> d >> n;
    long long two[4] = {a*8,b*4,c*2,d};
    long long one[3] = {a*4,b*2,c};
    sort(two,two+4);
    sort(one,one+3);
    if(n%2==0){
        cout << n*two[0]/2 << endl;
    }
    else{
        cout << (n-1)*two[0]/2 + one[0] << endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1L << 30

int N;

int main(){
	cin >> N;
	vector<string> S(N);
	string input;
	map<string, int> mp; 
	int max = 0;
	int count_v ;
	rep(i, N){
		cin >> S.at(i);
		//count_v = count(S.begin(), S.end(), S.at(i));
		mp[S.at(i)] += 1;
		
	}
	for (auto itr = mp.begin(); itr!=mp.end(); ++itr){
		count_v = itr->second;
		if (count_v >= max){
			max = count_v;
		}
	}
	for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
       //cout << "key = " << itr->first           // キーを表示
        //                << ", val = " << itr->second << "\n";    // 値を表示
		if (itr->second == max){
			cout << itr->first << endl;
		}
    }


}

Measured memory_bytes: 26752
N = parse(Int, readline())
h = map(x->parse(Int, x), split(readline()))

dps = zeros(Int64, N)
dps[2] = dps[1] + abs(h[1] - h[2])

for i in 3:N
   jump2 = dps[i-2] + abs(h[i-2] - h[i])
   jump1 = dps[i-1] + abs(h[i-1] - h[i])
   dps[i] = min(jump2, jump1)
end
print(dps[N])



Measured memory_bytes: 168848
#include <cstdio>
#include <queue>
using namespace std;

priority_queue<int> PQ;

int main() {
    char cmd[8];
    while (1) {
        scanf("%s", cmd);
        if (cmd[0] == 'i') {
            int val;
            scanf("%d", &val);
            PQ.push(val);
        } else if (cmd[1] == 'x') {
            printf("%d\n", PQ.top());
            PQ.pop();
        } else if (cmd[0] == 'e') {
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 6532
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt" , "r" , stdin);
	// freopen("output.txt" , "w" , stdout);
	// #endif

	ll n,ans=0;
	cin>>n;
	vector<ll>v;
	for(ll i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			ll a=i-1,b=n/i-1;
			if(n/i==i)
			{
				if(a)
				{
					if(n/a==n%a)
						ans+=a;
				}
			}
			else
			{
				if(a)
				{
					if(n/a==n%a)
						ans+=a;
				}
				if(b)
				{
					if(n/b==n%b)
						ans+=b;
				}
			}

		}
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 256