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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  VL xs(3);
  cin >> xs;
  LL K;
  cin >> K;
  SORT(xs);
  REP(i,K) xs[2] *= 2;
  cout << xs[0]+xs[1]+xs[2]<<endl;

  return 0;
}


Measured memory_bytes: 256
#define ll long long int
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
void solve(){
    ll n, w;
    cin >> n >> w;
    vector<vector<ll>> dp(n+1, vector<ll>(w+1, 0));
    vector<ll> weight(n+1, 0), val(n+1, 0);
    for(ll i=1; i<=n; i++){
        cin >> weight[i];
        cin >> val[i];
    }
    ll mx = INT_MIN;
    for(ll i=1; i<=n; i++){
        for(ll j=1; j<=w; j++){
            if(j-weight[i] < 0){dp[i][j] = dp[i-1][j];}
            else{
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-weight[i]]+val[i]);
            }
            mx = max(mx, dp[i][j]);
            // cout << dp[i][j] << " ";
        }
        // cout << "\n";
    }
    cout << mx;
}

int main()
{
    fast;
    solve();
    return 0;
}


Measured memory_bytes: 83112
from itertools import chain, combinations


def powerset(iterable):
    s = list(iterable)
    sets = list(chain.from_iterable(combinations(s, r) for r in range(len(s)+1)))
    sets = [s for s in sets if len(s) > 0]
    return sets

def check_row(row, x):
    for el in row:
        if el < x:
            return False
    return True

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

result = float("inf")
sets = powerset([i for i in range(n)])

for s in sets:
    k_rows = [0 for i in range(m)]

    cost = 0
    for idx in s:
        cur_c_k = c_k_table[idx]
        cost += cur_c_k[0]

        k_row = list(cur_c_k[1:])
        for i in range(m):
            k_rows[i] += k_row[i]
    
    if check_row(k_rows, x):
        result = min(result, cost)
if result == float("inf"):
    print(-1)
else:
    print(result)

Measured memory_bytes: 9532
#include <cstdio>
#include <cstring>

const int N(5e5 + 10);
char s[N]; int n, pre[N], nxt[N], ans;
int check(int x)
{
	int p = pre[x], t = n + 1 - nxt[x + 1];
	return ((!p || (x % (x - p))) && (!t || ((n - x) % (n - x - t))));
}

int main()
{
	scanf("%s", s + 1), n = strlen(s + 1), nxt[n] = n + 1;
	for (int i = 2, j = 0; i <= n; i++)
	{
		while (j && s[j + 1] != s[i]) j = pre[j];
		if (s[j + 1] == s[i]) ++j; pre[i] = j;
	}
	for (int i = n - 1, j = n + 1; i; i--)
	{
		while (j <= n && s[j - 1] != s[i]) j = nxt[j];
		if (s[j - 1] == s[i]) --j; nxt[i] = j;
	}
	if (!pre[n] || (n % (n - pre[n]))) return puts("1\n1"), 0;
	if (pre[n] == n - 1) return printf("%d\n1\n", n), 0;
	for (int i = 1; i < n; i++) ans += check(i);
	printf("2\n%d\n", ans);
	return 0;
}


Measured memory_bytes: 4608
n = int(input())
d = list(map(int, input().split()))

d.sort()

# Odd pattern
if n % 2 == 1:
    print(0)
# Even pattern
else:
    ml = int(n / 2) - 1
    mr = int(n / 2)
    if d[ml] == d[mr]:
        print(0)
    else:
        print(d[mr] - d[ml])


Measured memory_bytes: 20632
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

int main() {
	ios::sync_with_stdio(0); cin.tie();
	int N;
	cin >> N;
	int n = ceil((sqrt(1+8*N)-1)/2);
	while(N) {
		int k = min(n,N);
		cout << k << "\n";;
		N -= k;
		--n;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
public class Main {
	
	public static void main(String[] args) throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String x = br.readLine();
		String[] str = x.split(" ");
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		System.out.println(a*b +" " + (a+b)*2);
	}
}

Measured memory_bytes: 24424
/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef double ld;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll >
#define vll vector < ll > 
#define dt cout<<"HERE\n";
#define pii pair < ll , ll >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 
const ll inf=1e18+1e17;
const ll mod =1e9+7;
using cd= complex < double > ;
//const ll mod = 998244353;
ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}
const ll N = 2e5+5;
ll arr[N];
ll n;
ll find(ll x){
	ll val=0;
	for ( ll i=0;i<n;i++)
		val+=abs( arr[i]-x);
	return val;
}
void solve(){
	cin>>n;
	for ( ll i=0;i<n;i++){
		cin>>arr[i];
		arr[i]-=(i+1);
	}
	ll x=*min_element( arr,arr+n);
	ll y=*max_element( arr,arr+n);
	while ( x<y){
		ll mid=( y-x)/3;
		ll c=x+mid;
		ll d=x+2*mid;
		ll j=find ( c);
		ll k=find ( d);
		if ( j<k)
			y=d;
		else
		if ( j>k)
			x=c;
		else{
			x=c;y=d;
		}
		if ( y-x<=3){
			ll p=x;
			ll val=find( p);
			for ( ll i=x;i<=y;i++){
				ll kal=find( i);
				if ( kal<val){
					val=kal;
					p=i;
				}
			}
			x=p;
			y=p;
		}
	}
	cout<<find(y)<<'\n';
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif
	ll t=1;
	//cin>>t;
	for ( ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
    	solve();
    }
}


Measured memory_bytes: 5192
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

int main(){
    int M; cin>>M;
    ll ans=0;
    ll DIGIT=0, SUM=0;
    for(int i=0;i<M;i++){
        ll d,c; cin>>d>>c;
        SUM+=(d*c);
        DIGIT+=c;
    }
    //cout<<SUM<<' '<<DIGIT<<endl;
    if(SUM%9==0) ans--;
    ans+=(DIGIT-1);
    SUM/=9;
    ans+=SUM;
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

# 逆元comb
def comb(n, k):
    k = min(n-k,k)
    ans = 1
    for i in range(1, k + 1):
        ans *= (n + 1 - i) * pow(i,MOD-2,MOD)
        ans %= MOD
    return ans

def solve(n: int, a: int, b: int):
    comb_sum = pow(2,n,MOD)
    aa = comb(n,a)
    bb = comb(n,b)

    print((comb_sum-1-aa-bb)%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(n, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll r(n);
    vll l(n);
    REP(i,n) cin >> l[i] >> r[i];
    sort(ALL(l));
    sort(rALL(r));
    ll ar,al;
    ll n2 = n/2;
    if(n%2==0){
        al = (l[n2-1]*2+l[n2]*2)/2;
        ar = (r[n2-1]*2+r[n2]*2)/2;
    }else{
        al = l[n2];
        ar = r[n2];
    }
    ll ans = ar-al+1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6332
#import<iostream>
#import<map>
#import<queue>
#import<cstdlib>
#import<cstring>
using namespace std;struct B{int z[2];char s[14];bool operator<(const B&r)const{return strcmp(s,r.s)<0;}};main(){int a[13][5]={{2,-1},{2,5,-1},{0,1,3,6,-1},{2,7,-1},{5,-1},{1,4,6,9,-1},{2,5,7,10,-1},{3,6,8,11,-1},{7,-1},{5,10,-1},{6,9,11,12,-1},{7,10,-1},{10,-1},},gx[]={2,1,2,3,0,1,2,3,4,1,2,3,2},gy[]={0,1,1,1,2,2,2,2,2,3,3,3,4},v,d,s,i,j;B g={0,0,"0123456789:;0"};for(;;){map<B,int>m;queue<B>q;B b={-1,-1};for(i=0;i<13;i++){cin>>v;if(v<0)return 0;b.s[i]=48+v;if(!v)b.z[b.z[0]!=-1]=i;}b.s[13]=0;m[b]=1;for(q.push(b);!q.empty();q.pop()){B&b=q.front();if(!strcmp(b.s,g.s))break;d=0;for(i=13;i--;){v=b.s[i]-48;if(v)d+=abs(gx[v]-gx[i])+abs(gy[v]-gy[i]);}s=m[b];if(s+d<22)for(j=2;j--;)for(i=0;~a[b.z[j]][i];i++){B n=b;n.z[j]=a[b.z[j]][i];if(n.z[j]-n.z[1-j]){swap(n.s[b.z[j]],n.s[n.z[j]]);int&b=m[n];if(!b)b=s+1,q.push(n);}}}printf(m[g]?"%d\n":"NA\n",m[g]-1);}}

Measured memory_bytes: 1484
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		Console.WriteLine(Math.Min(p[0] + p[1], Math.Min(p[1] + p[2], p[0] + p[2])));
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int  main(){
    std::ios::sync_with_stdio(false);
   cin.tie(0);
    ll a,b,x;
    cin>>a>>b>>x;
    a!=0?cout << b / x - (a - 1) / x << endl:cout << b / x + 1 << endl;
return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] map = new int[100];
        int[] ans = new int[2];

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

        Arrays.sort(map);

        for (int i = 0; i < 100; i++) {
            ans[i % 2] += map[i];
        }

        System.out.println(ans[1] - ans[0]);
    }



}




Measured memory_bytes: 23508
#include<stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1
 
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
 
int x[N][N];
void initialize(void);
void printBoard(void);
void recursive(int);
 
int main(){
  int i,j;
   
  initialize();
 
  for( i = 0 ; i < N ; i++ ){
    for(j = 0 ; j < N ; j++ ){
      x[i][j] = 0;
 
    }
  }
 
  int k;
  int r,c;
   
  scanf("%d",&k);
 
  for( i = 0 ; i < k ; i++ ){
    scanf("%d%d",&r,&c);
    x[r][c] = 1;
  }
 
  recursive(0);
 
  return 0;
}
 
void initialize(){
  int i,j;
  for( i = 0 ; i < N ; i++ ) {
    row[i] = FREE;
    col[i] = FREE;
  }
 
  for( i = 0 ; i < 2*N-1 ; i++ ){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
 
}
 
 
void printBoard(){
  int i,j;
   
  for( i = 0 ; i < N ; i++ ){
    for( j = 0 ; j < N ; j++ ){
      if(x[i][j]){
    if(row[i] != j) return;
      }
    }
  }
 
  for( i = 0 ; i < N ; i++ ){
    for( j = 0 ; j < N ; j++ ){
      if(row[i] == j ) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
 
void recursive(int i){
  if( i == N ){
    printBoard();
    return;
  }
 
  int j;
 
  for( j = 0 ; j < N ; j++ ){
    if( NOT_FREE == col[j] || NOT_FREE == dpos[i+j] || NOT_FREE == dneg[i-j+N-1]) continue;
 
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
 
    recursive(i+1);
 
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}

Measured memory_bytes: 572
#if defined(__GNUC__)
#include <bits/stdc++.h>
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)

itn main() {
	std::ios::sync_with_stdio(false);

	int h, n;
	cin >> h >> n;

	vector<int> a(n), b(n);

	REP(i, n) {
		cin >> a[i] >> b[i];
	}

	vector<int> dp(30000, 1000000000);
	dp[0] = 0;

	vector<int> vres;

	REP(i, h) {
		REP(j, a.size()) {
			dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j]);
			if (i + a[j] >= h) {
				vres.push_back(dp[i + a[j]]);
			}
		}
	}

	SORT(vres);

	cout << vres[0];

	return 0;
}

Measured memory_bytes: 35172
fun main(arg: Array<String>) {
    val N = nextLong()
    val S = nextLong()
    if (N == S) return print(N + 1)
    val sqrtN = Math.sqrt(N.toDouble()).toLong()
    val list = mutableListOf<Long>()
    fun calC(b: Long, N: Long): Long {
        var n = N
        var cnt = 0L
        while (n > 0) {
            cnt += n % b
            n /= b
        }
        return cnt
    }
    for (n in 2 .. sqrtN)
        if (calC(n, N) == S) return print(n)
    val A = N - S
    if (A < 0) return print(-1)
    for (n in 1 .. sqrtN) {
        if (A % n == 0L) {
            list.add(n + 1)
            if (n != A / n) list.add(A / n + 1)
        }
    }
    list.sort()
    for (n in list) {
        if (n > sqrtN && calC(n, N) == S)
            return print(n)
    }
    return print(-1)
}

fun next() = readLine()!!
fun nextLong() = next().toLong()


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

using namespace std;

#define ll					long long
#define vi					vector<int>
#define vii					vector<vi>
#define ALL(s)			(s).begin(),(s).end()
#define pii					pair<int, int>
#define pll					pair<ll, ll>
#define si					set<int>
#define mp					make_pair
#define F						first
#define S						second
#define pb					push_back
#define tc(t)				int t; cin >> t; int t2 = 1; while(t--)
#define _						ios_base::sync_with_stdio(false); cin.tie(NULL); 
const ll MOD =  998244353;
const ll INF = 1<<29;
const ll MAX_N = 1e6 + 7;





int main() {_
	string s;
	cin >> s;
	int ok = 1;
	
	string s1 = s.substr(0,(int)s.length()/2);
	string s2 = s.substr(s.length()/2+1,(int)s.length()/2);

	for(int i = 0; i < s1.length()/2; ++i) {
		if(s1[i] == s1[s1.length() - 1 -i]) continue;
		else {
			ok =0;
			break;
		}
	}
	for(int i = 0; i < s2.length()/2; ++i) {
		if(s2[i] == s2[s2.length() - 1 -i] && s1[i] == s2[i] && s1[s1.length()/2] == s2[s2.length()/2]) continue;
		else {
			ok =0;
			break;
		}
	}
	
	if(ok)	cout << "Yes\n";
	else 	cout << "No\n";
			
	
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    long int n,i,j,a,count;
    char s[100000];
    scanf("%ld %s",&n,s);
    count = n;
    for(i = 0 ; i < n - 1 ; i++)
    {
        if(s[i] == s[i + 1])
        {
            count--;
        }
    }
    printf("%ld\n",count);
    return 0;
}

Measured memory_bytes: 1824
#include <iostream>
#include <algorithm>
#include <string>

typedef long long ll;

using namespace std;

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

  int n;
  cin >> n;

  int c = 0;
  
  int i = n;
  int tc = -1;
  while (i > 0) {
    if (s[c] != 'a' && 'z' - s[c] + 1 <= i) {
      i -= 'z' - s[c] + 1;
      s[c] = 'a';
      c++;
      if (c >= s.size()) {
        c--;
      }
    } else {
      c++;
      if (c >= s.size()) {
        c--;
      }
      if (tc == c) {
        s[c]++;
        i--;
      }
      tc = c;
    }
    

  }
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		
		int n = s.nextInt();
		int a[] = new int [n];
		int aMax = 0;
		
		for(int i = 0; i< n;i++) {
			a[i]= s.nextInt()-1;
		}
		boolean can = true;
		for(int i = 0; i<n-1&&can;i++) {
			if(!(a[i]<a[i+1])) {
				if(!(a[i+1]+1>=a[i])||a[i+1]+1<aMax) {
					can = false;
				}
			}else {
				aMax = a[i+1];
			}
		}
		
		if(can) {
			System.out.println("Yes");
		}else System.out.println("No");
	}

}

Measured memory_bytes: 51036
N, K = map(int, input().split())
B = [[0] * (2 * K) for _ in range(2 * K)]
for _ in range(N):
    x, y, c = input().split()
    if c == 'B':
        B[int(x) % (2 * K)][int(y) % (2 * K)] += 1
    else:
        B[int(x) % (2 * K)][(int(y) + K) % (2 * K)] += 1

for i in range(2 * K):
    for j in range(2 * K - 1):
        B[i][j + 1] += B[i][j]

for i in range(2 * K):
    for j in range(2 * K - 1):
        B[j + 1][i] += B[j][i]

B = [[0] * (2 * K + 1)] + [[0] + row for row in B]
ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        # 左上
        tmp = B[i - 1][j - 1]
        # 右上
        tmp += B[i - 1][2 * K] - B[i - 1][j + K - 1]
        # 真ん中
        tmp += B[i + K - 1][j + K - 1] - B[i - 1][j + K - 1] \
               - B[i + K - 1][j - 1] + B[i - 1][j - 1]
        # 左下
        tmp += B[2 * K][j - 1] - B[i + K - 1][j - 1]
        # 右下
        tmp += B[-1][-1] - B[i + K - 1][2 * K] - B[2 * K][j + K - 1] \
               + B[i + K - 1][j + K - 1]
        ans = max(ans, tmp, N - tmp)
print(ans)

Measured memory_bytes: 114524
using CompLib.Util;
using System;
using System.Linq;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int[] x = sc.IntArray();

        int ans = int.MaxValue;

        for (int p = 0; p <= 100; p++)
        {
            int sum = 0;
            foreach (int i in x)
            {
                sum += (i - p) * (i - p);
            }

            ans = Math.Min(ans, sum);
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;
    class Scanner
    {
        private int _index;
        private string[] _line;
        const char separator = ' ';

        public Scanner()
        {
            _index = 0;
            _line = new string[0];
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(separator);
                _index = 0;
            }
            return _line[_index++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(separator);
            _index = _line.Length;
            return _line;
        }
        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
    }
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    vector<vector<char>> ss(2 * n, vector<char>(2 * n));
    for (i64 i = 0; i < n; i++) {
        for (i64 j = 0; j < n; j++) {
            cin >> ss[i][j];
            ss[i + n][j] = ss[i][j + n] = ss[i + n][j + n] = ss[i][j];
        }
    }

    i64 ans = 0;
    for (i64 i = 0; i <= 2 * n - 2; i++) {
        i64 ay = min(i, n - 1), ax = min(2 * n - 2 - i, n - 1);

        i64 err = 0;
        for (i64 ry = 0; ry < n; ry++) {
            for (i64 rx = ry; rx < n; rx++) {
                if (ss[ay + ry][ax + rx] != ss[ay + rx][ax + ry]) err++;
            }
        }
        if (!err) ans++;

        while (ay > 0 && ax > 0) {
            ay--, ax--;
            for (i64 j = 0; j < n; j++) {
                i64 by = ay + j, bx = ax + j;
                if (ss[by][bx] != ss[bx][by]) err++;
                i64 ey = ay + n - j, ex = ax + n - j;
                if (ss[ey][ex] != ss[ex][ey]) err--;
            }
            if (!err) ans++;
        }
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    int n; cin >> n;
    int disc = 0, sum = 0;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        disc = max(disc, x/2); sum += x;
    }
    cout << sum - disc << endl;
}


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

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

    int H, W;
    cin >> H >> W;

    vector<vector<char> > s(H, vector<char>(W));

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> s[i][j];
        }
    }

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {

            if(s[i][j] == '.') continue;

            if(i != 0)
                if(s[i - 1][j] == '#') continue;
            if(i != H - 1)
                if(s[i + 1][j] == '#') continue;
            if(j != 0)
                if(s[i][j - 1] == '#') continue;
            if(j != W - 1)
                if(s[i][j + 1] == '#') continue;

            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  if ( (a + b) % 2 == 0 ) {
    cout << (a + b) / 2 << endl;
  } else {
    cout << (a + b + 1) / 2 << endl;
  }
}

Measured memory_bytes: 3444
#include<stdio.h>
int main()
{
  int a,b;
  scanf("%d", &a);

  scanf("%d", &b);

  if(a<b)
   {
    printf("a < b\n");
   }
  else if (a>b)
   {
    printf("a > b\n");
   }
   else
   {
       printf("a == b\n");
   }


return 0;
}


Measured memory_bytes: 2056
while True:
    string = [x for x in input()]
    if string[0] == '-':
        break
    else:
        shuffle_count = int(input())
        for i in range(shuffle_count):
            shuffle_num = int(input())
            for j in range(shuffle_num):
                c = string.pop(0)
                string.append(c)
        print("".join(string))



Measured memory_bytes: 5600
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n,k) = get!(usize, usize);
    
    let mut res = 0.0;
    for i in 1..(n+1) {
        let mut tmp = if k%i==0 {
            k/i
        } else {
            k/i+1
        }-1;
        let mut count = 0;
        while tmp > 0 {
            count += 1;
            tmp >>= 1;
        }
        res += 1.0 / (1 << count) as f64;
    }
    println!("{}", res/n as f64);
}


Measured memory_bytes: 8572
#include <stdio.h>

int main(void){
	int A,B;
	int y;

	scanf("%d",&y);
	if(y == 1){
		printf("Hello World\n");
	}
	else if(y == 2){
		scanf("%d",&A);
		scanf("%d",&B);
		if(A>=0 && A<=9 && B>=0 && B<=9) printf("%d\n",A+B);
	}

	return 0;
}

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

int a, b, c, x, y;
int ans = 0;
int main() {
	cin >> a >> b >> c >> x >> y;
	if(a + b > c + c)	 {
		int d = min(x, y);
		y -= d;
		x -= d;
		ans += c * 2 * d;
	}
	int res = a * x + b * y;
	res = min(res, c * 2 * max(x, y));
	cout << ans + res;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int i = a; i <= (n); ++i)
#define repD(i, a, n) for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a) memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int maxn = 1e5 + 19;
vector <pair<int,int>> g[maxn];
vi x(maxn), v(maxn), cv;
int n,m;
bool possible = true;

int dfs(int i){
	v[i] = true;
	for(auto it: g[i]){
		if(!v[it.fst]){
			x[it.fst] = x[i] + it.snd;
			dfs(it.fst);
		}else if(x[it.fst] != x[i] + it.snd){
			possible = false;
		}
	}
	return 0;
}


int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	cin >> n >> m;
	rep(i,m){
		int l,r,d; cin >> l >> r >> d;
		l--; r--;
		g[l].pb(mp(r,d));
		g[r].pb(mp(l,-d));
	}
	rep(i,n){
		if(v[i] == 0){
			dfs(i);
		}	
	}
	if(possible){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;


void solve(){
  string s; cin >> s;
  int x = s[1] - 48;
  x += (s[0] - 48) * 10;
  int y = s[3] - 48;
  y += (s[2] - 48) * 10;
  string ans;
  if(x > 12 || x == 0){
    if(y > 12 || y == 0) ans = "NA";
    else ans = "YYMM";
  }
  else{
    if(y > 12 || y == 0) ans = "MMYY";
    else ans = "AMBIGUOUS";
  }
  cout << ans << endl;

  return;
}

int main(){
  solve();
  return 0;
}


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

ans = []
while n:
    r = n % 2
    if r < 0:
        r += 2
    ans.append(str(r))
    n = (n-r) // -2
ans.reverse()

if len(ans) == 0:
    print(0)
else:
    print("".join(map(str, ans)))


Measured memory_bytes: 3060
N, M = map(int, input().split())
p = []
for i in range(M):
    tmp = list(map(int, input().split()))
    tmp.append(i)
    p.append(tmp)
p.sort()
ans = []
count = 1
for i in range(M):
    if p[i-1][0] != p[i][0]:
        count = 1
    elif i != 0:
        count += 1
    id = str(p[i][0]).zfill(6)+str(count).zfill(6)
    ans.append((p[i][2],id))
ans.sort()
for i in ans:
    print(i[1])

Measured memory_bytes: 45696
use proconio::input;

fn solve(x: i64) -> (i64, i64) {
    for i in (-199)..200 {
        for j in (-199)..200 {
            if i*i*i*i*i - j*j*j*j*j == x {
                return (i, j);
            }
        }
    }
    panic!();
}

fn main() {
    input! {
        x: i64,
    }
    let r = solve(x);
    println!("{} {}", r.0, r.1);
}


Measured memory_bytes: 2152
#include<bits/stdc++.h>
    #define _USE_MATH_DEFINES
    #include <cmath>
    #define ll long long
    using namespace std;

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll a,b,n;
        cin>>a>>b>>n;
        ll ans=(a)*min(b-1,n)/b;
        cout<<ans<<endl;
    }


Measured memory_bytes: 3608
H,W=map(int,input().split())
L=[list(input()) for _ in range(H)]
for _ in range(H+W):
    ans=[]
    res=[]
    l=[]
    for s in L:
        if '#' in s:
            l.append(s)
    for z in zip(*l):
        if '#' in z:
            res.append(z)
    for z in zip(*res):
        ans.append(list(z))
    L=ans.copy()
for t in L:
  print(''.join(t))

Measured memory_bytes: 3316
#include <iostream>
#include <vector>

int main(void){
  int N, M;
  std::cin >> N >> M;
  std::vector<bool> a(N + 1, false);
  for(int i = 0; i < M; ++i){
    int tmp;
    std::cin >> tmp;
    a[tmp] = true;
  }
  std::vector<int> dp(N + 1, 0);
  dp[0] = 1;
  for(int i = 1; i <= N; ++i){
    if(a[i]) continue;
    dp[i] = (dp[i - 1] + (i >= 2 ? dp[i - 2] : 0)) % 1000000007;
  }
  std::cout << dp[N] << std::endl;
}

Measured memory_bytes: 640
#define first f
#define second s
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=2e5+5;
const double PI=acos(-1);
const double e=2.718281828459;


int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if((a==b&&b==c)||(a!=b&&a!=c&&b!=c)){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }
    return 0;
}


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

int main(){
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	int r[a], g[b], w[c];
	for (int i = 0; i < a; ++i) {
		cin >> r[i];
	}
	for (int i = 0; i < b; ++i) {
		cin >> g[i];
	}
	for (int i = 0; i < c; ++i) {
		cin >> w[i];
	}
	sort(r,r+a);
	sort(g,g+b);
	sort(w,w+c);
	vector <int> v;
	for (int i = 0; i < x; ++i) {
		v.push_back(r[a-1-i]);
	}
	for (int i = 0; i < y; ++i) {
		v.push_back(g[b-1-i]);
	}
	for (int i = 0; i < c; ++i) {
		v.push_back(w[i]);
	}
	sort(v.begin(), v.end());
	int z = v.size();
	long long sum = 0;
	int req = x+y;
	z--;
	while (req--) {
		sum += v[z--];
	}
	
	cout << sum << "\n";
	return 0;
}


Measured memory_bytes: 3572
#include <cstdio>

const int MAXN = 2000 , MAXM = MAXN * MAXN , Mod = 1e9 + 7;
int n , k , Fac[ MAXM + 5 ] , Inv[ MAXM + 5 ] , dp[ MAXN + 5 ][ MAXN + 5 ];

int Quick_pow( int x , int po ) {
	int Ans = 1;
	for( ; po ; po >>= 1 , x = 1ll * x * x % Mod )
		if( po & 1 ) Ans = 1ll * Ans * x % Mod;
	return Ans;
}
void Init( ) {
	Fac[ 0 ] = 1;
	for( int i = 1 ; i <= MAXM ; i ++ )
		Fac[ i ] = 1ll * Fac[ i - 1 ] * i % Mod;
	Inv[ MAXM ] = Quick_pow( Fac[ MAXM ] , Mod - 2 );
	for( int i = MAXM - 1 ; i >= 0 ; i -- )
		Inv[ i ] = 1ll * Inv[ i + 1 ] * ( i + 1 ) % Mod;
}
int C( int n , int m ) {
	return 1ll * Fac[ n ] * Inv[ m ] % Mod * Inv[ n - m ] % Mod;
}

int main( ) {
	Init( );
	scanf("%d %d",&n,&k);
	if( k == 1 ) return !printf("%d\n", 1 );
	
	for( int i = 1 ; i <= n ; i ++ )
		dp[ i ][ 0 ] = 1;
	for( int i = 1 ; i <= n ; i ++ )
		for( int j = 1 ; j <= i ; j ++ )
			dp[ i ][ j ] = ( dp[ i - 1 ][ j ] + 1ll * dp[ i ][ j - 1 ] * ( n - j + 1 ) % Mod * C( n * k - i - ( j - 1 ) * ( k - 1 ) - 1 , k - 2 ) % Mod ) % Mod;// , printf("%d%c",dp[i][j],j==i?'\n':' ');
	printf("%d\n", dp[ n ][ n ] );
	return 0;
}

Measured memory_bytes: 46208
#include<iostream>
#include<string.h>
using namespace std;

int main() {
  int n;
  while(cin>>n, n) {
    int sum = 1;
    if(n == 1) sum = 0;
    for(int i=2; i*i<=n; ++i) {
      if(n%i==0) sum += i + n/i;
      if(i*i==n) sum -= i;
    }
    if(n > sum) cout<<"deficient number"<<endl;
    else if(n < sum) cout<<"abundant number"<<endl;
    else cout<<"perfect number"<<endl;
  }
}

Measured memory_bytes: 0
import sys,bisect
input = sys.stdin.readline
n,m = map(int,input().split())
edge = [[] for i in range(n)]

#st: 今考えている辺の中で入る辺が無い頂点
st = []
#to[i]: 今考えている辺の中で頂点iに入る辺数
to = [0]*n
for i in range(m):
    x,y = map(int,input().split())
    edge[x-1].append(y-1)
    to[y-1] += 1
for i in range(n):
    if to[i] == 0:
        st.append(i)

#dp[i]: 頂点iを終点とする最長のパスの長さ
dp = [0]*n
while len(st):
    go = st.pop()
    for e in edge[go]:
        to[e] -= 1
        if to[e] == 0:
            st.append(e)
        dp[e] = max(dp[e],dp[go]+1)
print(max(dp))


Measured memory_bytes: 22704
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    cin >>n;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    ll q;
    cin >> q;
    vector<ll> com(q), b(q), e(q);
    rep(i,0,q) cin >> com[i] >> b[i] >> e[i];

    rep(i,0,q) 
    {
        //cout << i << ' ' << com[i] << endl;
        switch(com[i])
        {
            case (0):
            {
                //cout << 0 << endl;
                ll _min(LL_MAX); 
                rep(j,b[i],e[i])
                    _min = min(a[j], _min);

                cout << _min << endl;

                break;
            }
            case (1):
            {
                //cout << 1 << endl;
                ll _max(-LL_MAX); 
                rep(j,b[i],e[i])
                    _max = max(a[j], _max);

                cout << _max << endl;

                break;
            }
            default:
                break;
        }
    }

    return 0;
}



Measured memory_bytes: 3160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		if (a + b >= a * b && a + b >= a - b) {
			System.out.println(a + b);
		} else if (a * b >= a + b && a * b >= a - b) {
			System.out.println(a * b);
		} else {
			System.out.println(a - b);
		}
	}
}


Measured memory_bytes: 21588
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

score=sum(B)
for a,b in zip(A,A[1:]):
    if b==a+1:
        score+=C[a-1]

print(score)

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC target ("avx,tune=native")

#include<bits/stdc++.h>
using namespace std;
const int maxn=3010;
int mod;
void plusle(int &a,int b){
    a+=b;if(a>=mod)a-=mod; return;
}
void minun(int &a,int b){
    a-=b; if(a<0)a+=mod; return;
}
int add(int a,int b) {
  a+=b;
  return a>=mod?a-mod:a;
}
int sub(int a,int b) {
  a-=b;
  return a<0?a+mod:a;
}
int mul(int a,int b) {
  return (int)((long long)a*b%mod);
}
int power(int a,int b) {
  int res=1;
  while (b>0) {
    if (b&1) {
      res=mul(res,a);
    }
    a=mul(a,a);
    b>>=1;
  }
  return res;
}
int inv(int x){
    return power(x,mod-2);
}
vector<int> mul(vector<int> p,int j){
    ///c[0]+(c[1]*x)+(c[2]*(x^2)+...)c[n-1]*(x^(n-1))
    ///(x-j)
    int n=(int)p.size();
    vector<int> s(n+1,0);
    for(int i=0;i<n;i++){
        plusle(s[i+1],p[i]);
    }
    for(int i=0;i<n;i++){
        plusle(s[i],mul(p[i],j));
    }
    return s;
}
vector<int> d( vector<int> p,int j){
    ///c[0]+c[1]*x+...+c[n-1]*(x^(n-1))
    ///x-j
    int n=(int)p.size();
    vector<int> s(n-1,0);
    for(int i=n-1;i>0;i--){
        plusle(p[i-1],mul(j,p[i]));
        s[i-1]=p[i];
    }
    return s;
}
int get(vector<int> g,int x){
    int res=0;
    int now=1;
    for(int i=0;i<(int)g.size();i++){
        plusle(res,mul(g[i],now));
        now=mul(now,x);
    }
    return res;
}
int a[maxn];

int main(){
    int p;
    scanf("%d",&p);
    mod=p;
    for(int i=0;i<p;i++){
        scanf("%d",&a[i]);
    }
    vector<int> t={0,1};
    for(int i=1;i<p;i++){
        t=mul(t,i);
    }
    vector<int> aa(p,0);
    for(int i=0;i<p;i++){
        if(a[i]==0)continue;
        vector<int> s=d(t,i);
        int cur=get(s,i);
        cur=inv(cur);
        for(int i=0;i<(int)s.size();i++){
            plusle(aa[i],mul(s[i],cur));
        }
    }
    for(int i:aa){
        printf("%d ",i);
    }
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using E = tuple<ll, int, ll>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9 + 7;

ll dp[1000][1000];
ll s[100010];

int main(void){
  int n;
  cin >> n;
  for(int i = 0;i < n;++i){
    cin >> s[i];
  }
  ll res = 0;
  for(int d = 1;d <= n-1;++d){
    ll calc = 0;
    for(int k = 1;d < (n-1) - k*d;++k){
      calc += s[(n-1) - k*d];
      calc += s[k*d];
      if((n-1) % d == 0 && (n-1)/d <= 2*k){
        continue;
      }
      res = max(res,calc);
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1024
/*
 * Author Name: Sourab Hossain
 * Email: cpsourab@gmail.com
 */

#include <bits/stdc++.h>

using namespace std;

#define PI acos(-1)
#define DEGREE(radian) (radian * (180 / PI))
#define RADIAN(degree) ((degree * PI) / 180)

int dr[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int dc[] = {-1, +1, +0, +0, +1, +1, -1, -1};

int main(int argc, char const *argv[])
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);

    int n;

    scanf("%d", &n);
    int data, cnt = 0;

    for(int i = 0; i < n; i++) {
        scanf("%d", &data);

        if(data != i + 1) {
            cnt++;
        }
    }

    if(cnt < 3) {
        puts("YES");
    } else {
        puts("NO");
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility> // pair
#include <algorithm> // swap
using namespace std;

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()

template<typename T> void debug(vector<T> v) {
  bool f = false; cout << "[";
  for(auto i : v) { if (f) cout << ", "; f = true; cout << i; }
  cout << "]\n";
}
template<typename T> void debug(vector<vector<T>> v) {
  cout << "[\n";
  for(auto i : v) { cout << "  "; debug(i); }
  cout << "]\n";
}

signed main() {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> connections;
  rep(i, m) {
    int k;
    cin >> k;
    vector<int> ss;
    rep(j, k) {
      int s;
      cin >> s;
      ss.push_back(s - 1);
    }
    connections.push_back(ss);
  }

  vector<int> expects;
  rep(i, m) {
    int expect;
    cin >> expect;
    expects.push_back(expect);
  }

  int patterns = 0;
  rep(i, 1 << n) {
    bool correct = true;
    rep(j, connections.size()) {
      auto sw = connections[j];
      int ons = 0;
      for(auto s : sw) {
        ons += (i>>s)&1;
      }
      if(expects[j] != ons%2) correct = false;
    }
    if(correct) patterns++;
  }
  cout << patterns;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> vect(N);
    for(int i = 0; i < N; i++){
        cin >> vect[i];
    }
    sort(vect.begin(),vect.end());
    int count = 0;
    for(int i = 0;i < N; i++){
        for(int j = i+1; j < N; j++){
            if(vect[i] < vect[j]) {
                for (int k = j+1; k < N;k++){
                    if(vect[j] < vect[k] && vect[i] + vect[j] > vect[k]){
                        count += 1;
                    }
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<cstring>

const int N=15;

char s[N][N];
int n,m;

bool vis[N];

struct judger
{
	char s[N],t[N],ds[N],dt[N];
	bool set(int p,int x)
	{
		ds[p]=s[x],dt[p]=t[x];

		int q=m-p+1;
		if(vis[q] && ds[p]!=dt[q])return 0;
		if(vis[q] && ds[q]!=dt[p])return 0;
		return 1;
	}
}d[N];

bool check(int p,int x)
{
	for(int i=1;i<=(n+1)/2;i++)
		if(!d[i].set(p,x))return 0;
	return 1;
}

bool used[N];
bool dfs(int p=1)
{
	for(int i=1;i<=m;i++)
		if(!used[i] && check(p,i))
		{
			used[i]=vis[p]=1;

			if(p==m/2+1)return 1;

			int nxt;
			if(p*2<=m)nxt=m-p+1;
			else nxt=m-p+2;
			if(dfs(nxt))return 1;

			used[i]=vis[p]=0;
		}
	return 0;
}

inline bool judge()
{
	return dfs();
}

bool ans;

bool mat[N];
void Dfs(int p=1,int cur=1)
{
	if(ans)return;

	if(p>n)
	{
		if(cur-1!=(n+1)/2)return;
		ans|=judge();
		return;
	}

	if(mat[p]){Dfs(p+1,cur);return;}

	for(int q=1;q<=n;q++)
		if(!mat[q])
		{
			mat[p]=mat[q]=1;
			for(int i=1;i<=m;i++)
				d[cur].s[i]=s[p][i],d[cur].t[i]=s[q][i];
			Dfs(p+1,cur+1);
			mat[p]=mat[q]=0;
		}
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	ans=0,Dfs();
	printf("%s\n",ans?"YES":"NO");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(v) v.begin(), v.end()
vector<int> graf[100001];
vector<pair<pair<int, int>, int>> gvec;
int gv, gk;
string gs, gst;
long long dp[100001];
long long whatdo(int root) {
  long long ans = 0;
  if (dp[root] != -1)
    return dp[root];
  for (int i = 0; i < graf[root].size(); i++) {
    ans = max(ans, whatdo(graf[root][i]) + 1);
  }

  return dp[root] = ans;
}

void solve() {
  //----------------------VARs---------------------------------------------
  char car, car2;
  string s, st;
  long long n = 0, a = 0, b = 0, c = 0, e, d = 0, m = 0, t = 0, q = 0, r = 0,
            l = 0, middle = 0, count = 0, add = 0, k, ans = 0, temp = 0, rootsa,
            save = 0, bigg = 0, save2 = 0, counter = 0, counter2 = 0, sum = 0,
            x, y;
  bool flag = false, flag2;

  //-------- --------------VARs--------------------------------------------
  vector<int> vec;
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    graf[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) {
    ans = max(ans, whatdo(i));
  }
  cout << ans;
}
int main() {
#ifndef ONLINE_JUDGE
  system("clear");
  freopen("Test0.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cin.tie(0);

  cout << fixed << setprecision(10);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 11912
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        for(int i = a; i <= b; i++){
            if(i % k == 0){
                System.out.println("OK");
                System.exit(0);
            }
        }
        System.out.println("NG");
    }
}

Measured memory_bytes: 27224
#include <iostream>
#include <cstdio>
using namespace std;

long long n, k, a[200005], cycle[200005], len, ans, p = 1;

long long jump(int n) {
    int pt = 1;
    for (int i = 1; i <= n; ++i) {
        pt = a[pt];
    }
    return pt;
}

int main() {
    scanf("%lld%lld", &n, &k);
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", a + i);
    }
    if (k <= n) {
        printf("%lld\n", jump(k));
        return 0;
    }
    for (int i = 1; i <= k; ++i) {
        if (cycle[p] != 0) {
            len = i - cycle[p];
            ans = jump(cycle[p] - 1 + (k - cycle[p] + 1) % len);
            break;
        }
        cycle[p] = i;
        p = a[p];
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 6936
from _collections import deque

n,m=map(int,input().split())
f=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    f[a].append(b)
    f[b].append(a)
g=[0]*(n+1)
p=[0]*(n+1)
for i in range(1,n+1):
    if p[i]==0:
        p[i]=i
        data=[i]
        data=deque(data)
        while len(data)>0:
            pos=data.popleft()
            p[pos]=i
            for j in f[pos]:
                if p[j]==0:
                    data.append(j)
            f[pos]=[]
for i in range(n):
    g[p[i+1]]+=1
print(max(g))



Measured memory_bytes: 46392
#include <bits/stdc++.h>
using namespace std;
typedef int64_t i64;

int main()
{
  int year,month,day;
  char c1,c2;
  cin >> year >> c1 >> month >> c2 >> day;
  
  if(month <= 4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 1;
        for(int i = 0; i < n/2; i++) ans = ans * 2 % 1_000_000_007;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            a[x]++;
        }
        boolean able = true;
        for(int i = n-1; i > 0; i -= 2){
            if(a[i] != 2){
                able = false;
                break;
            }
        }
        if(n % 2 != 0 && a[0] != 1) able = false;

        if(able) System.out.println(ans);
        else System.out.println(0);
        sc.close();
    }

}


Measured memory_bytes: 49964