akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll              long long int
#define int             ll
#define ff              first
#define ss              second
#define pb              emplace_back
#define mpair           make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define sbits(x)      __builtin_popcountll(x)
#define zbits(x)      __builtin_popcountlliltin_ctzll(x)
#define w(t)            int t;cin>>t;while(t--)
#define uset            unordered_set
#define dor(i, a, b)    for(int i =(a);i<=(b);i++)
#define mem(a,val)      memset((a),(val),sizeof((a))); 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
    template <typename Arg1>
     void __f(const char* name,Arg1&& arg1){
        cout<<name<<" : "<<arg1<<std::endl;
     }
     template <typename Arg1, typename... Args>
     void __f(const char* names,Arg1&& arg1,Args&&... args){
        const char* comma = strchr(names+1 ,',');
        cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
     }
#else
#define trace(...)
#endif
/*     
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
*/
double pi = 2.0*acos(0);
void fast(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed<<setprecision(10);}
int max2(int a,int b){ if(a>b) return a;return b;}
int min2(int a,int b){ if(a<b)return a;return b;}
int max3(int a,int b,int c){ return max2(a,max2(b,c));}
int min3(int a,int b,int c){ return min2(a,min2(b,c));}

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



void solve()
{
  int n;
  cin>>n;
  bool check = true;
  int x;
  for(int  i = 0;i<n;i++)
  {
    cin>>x;
    if(x%2==0 && x%3!=0 && x%5!=0)
      check = false;
  } 
  if(check)
  cout<<"APPROVED"<<endl;
  else
  cout<<"DENIED"<<endl; 
}

signed main(void)
{
      fast();
     // w(t)
      solve();

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define in insert
#define rep(i,a,b) for(int i = a ; i < b ; i++)
#define repr(i,a,b) for(int i = b ; i > a ; i--)

signed main(){
    fast;
    string s;
    cin >> s;
    if(s[0]=='7' || s[1]=='7' || s[2]=='7'){
        cout << "Yes" << endl; return 0;
    }
    cout << "No";
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(void){
    int n,a=0;
    cin>>n;
    vector<int> vec(n);
    rep(i,0,n)cin>>vec[i];
    sort(vec.begin(),vec.end());
    rep(i,0,n)a+=vec[n-1-i]*(1-(i&1)*2);
cout<<a;
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;

int main() {
    int a,b,c;cin>>a>>b>>c;
    int mx=max({a,b,c});
    mx*=3;
    int sum=a+b+c;
    int ans=0;
    while(mx>sum){
        ans++;
        sum+=2;
    }
    while(sum%3!=0){
        ans++;
        sum+=2;
    }
    cout <<ans <<endl;
}

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

int main()
{
	int n, m = 0;
	int p[20];

	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> p[i];

	for (int i = 1; i < n - 1; i++) {
		if ((p[i] > p[i - 1] && p[i] < p[i + 1]) ||
			p[i] < p[i - 1] && p[i] > p[i + 1])
			m++;
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include <vector>
#define re(i,n) for(int i = 0; i < n; i++)

int main() {
	int n;
	cin >> n;
	long long a[80];
	re(i, n) cin >> a[i];
	long long k = 0;
	long long kane = 1000;
	
	if (a[1] >= a[0]) {
		k += kane / a[0];
		kane -= a[0] * k;
	}
	//cout << 0 << " " << kane << endl;

	for (int i = 1; i < n - 1; i++) {
		if (a[i] <= a[i - 1] && a[i] <= a[i + 1] && kane > a[i]) {
			k += kane / a[i];
			kane -= a[i] * (kane / a[i]);
		}
		else if (a[i] >= a[i - 1] && a[i] >= a[i + 1]) {
			kane += a[i] * k;
			k = 0;
		}
		//cout << i << " " << kane << endl;
	}
	
	kane += a[n - 1] * k;

	cout << kane << endl;

	return 0;
}

Measured memory_bytes: 3600
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000000ll
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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


    ll x;
    cin>>x;
    ll ans;
    for(int i = -200; i<=200; i++){
        for(int j = -200; j<=200; j++){
           ans = pow(i,5) - pow(j,5);
           if(ans == x){
               cout<<i<<' '<<j<<endl;
               return 0;
           } 
        }
    }
}

Measured memory_bytes: 4076
#include<bits/stdc++.h>
using namespace std;
int main()
{int n;
 cin>>n;
 int h[n];
 for(int i=0;i<n;i++)
   cin>>h[i];
 int  dp[n];
 dp[0]=0;
 dp[1]=abs(h[1]-h[0]);
 for(int i=2;i<n;i++)
   dp[i]=min((dp[i-1]+abs(h[i]-h[i-1])),dp[i-2]+abs(h[i]-h[i-2]));
   //for(int i=0;i<n;i++)
   //cout<<dp[i]<<" ";
   //cout<<endl;
 cout<<dp[n-1];
 return 0;
}

Measured memory_bytes: 1024
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0
n=I()
a=n//500
n-=a*500
b=n//5

ans=a*1000+b*5

print(ans)

Measured memory_bytes: 39276
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

int n, m, r;
vector<vector<int>> g;
vector<int> ans;
vector<bool> vis;

void dfs(int u) {
    if (vis[u]) return;
    vis[u] = true;
    for (int v : g[u]) {
        dfs(v);
    }
    for (int v : g[u]) {
        if (ans[v] == 0) {
            ans[v] = u;
        }
    }
}

int main() {
    cin >> n >> m;
    g.resize(n + 1);
    vector<int> cnt(n + 1);
    for (int i = 0; i < n + m - 1; ++i) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        cnt[b]++;
    }
    for (int u = 1; u <= n; ++u) {
        if (cnt[u] == 0) {
            assert(r == 0);
            r = u;
        }
    }
    ans.resize(n + 1);
    vis.resize(n + 1);
    dfs(r);
    for (int u = 1; u <= n; ++u) {
        cout << ans[u] << '\n';
    }
    return 0;
}


Measured memory_bytes: 11776
#include <iostream>
#include <vector>
int main(){
  int n; std::cin >> n;
  std::vector< int > b(n - 1);
  for (auto & x : b) std::cin >> x;
  long long ret = 0;
  ret += b.front();
  for (auto i = 0; i < n - 2; i++)
    { ret += std::min(b.at(i), b.at(i + 1)); }
  ret += b.back();
  std::cout << ret << std::endl;
}

Measured memory_bytes: 256
s=input()
k=int(input())
ss=[]
for i in range(len(s)):
	ss.append(ord(s[i])-ord("a"))
i=0
while k>0:
	if i==len(s)-1:
		ss[i]=(k+ss[i])%26
		break
	elif k>=26-ss[i] and ss[i]!=0:
		k-=(26-ss[i])
		ss[i]=0
	i+=1
ans=""
for i in range(len(s)):
	ans+=chr(ord("a")+ss[i])
print(ans)


Measured memory_bytes: 4212
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>

#define INF 1 << 30
#define MOD 1000000007
#define PI 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

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

int main() { 
        ll a, b, c;
        cin >> a >> b >> c;
        ll ans;
        if (a & 1 && b & 1 && c & 1) {
                ans = min(a * b, min(b * c, c * a));
        } else {
                ans = 0;
        }
        D(ans);
        return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];
    sort(a, a+N);
    int ans = 0;
    while(a[N-1] >= N) {
       int cnt = a[N-1]/N;
       a[N-1] -= cnt * N;
       rep(i, N-1) a[i] += cnt;
       sort(a, a+N);
        ans += cnt;
    }
    cout << ans << endl;
    



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long
#define MOD 1000000007

int ans(int n){
  int ret = 1;
  for(int i=0; i<n; i++){
    ret *= 2;
    ret %= MOD;
  }
  return ret;
}

int main(){
  int N;
  cin >> N;
  vector<int> A;
  for(int i=0; i<N; i++){
    int in;
    cin >> in;
    A.push_back(in);
  }
  sort(A.begin(), A.end());
  bool ok = true;
  for(int i=0; i<N; i++){
    if(N % 2 == 0){
      if(i == 0 || i == 1){
	if(A[i] != 1){
	  ok = false;
	  break;
	}
      } else {
	if(A[i] != 2 * (i / 2) + 1){
	  ok = false;
	  break;
	}
      }
    } else {
      if(i == 0){
	if(A[i] != 0){
	  ok = false;
	  break;
	}
      } else {
	if(A[i] != 2 * ((i + 1) / 2)){
	  ok = false;
	  break;
	}
      }
    }
  }
  if(ok)
    cout << ans(N/2) << endl;
  else
    cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define cases() ll t;cin>>t;while(t--)
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 1e5+5;
const ll INF = 1e18;
const ll MOD = 1e9+7;

int main()
{
    int x;
    cin >> x;
    cout << (x^1);
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int INF = 1e9;
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

void solve() {
    int N, M;
    cin >> N >> M;
    vector<int> dp(1 << N, INF);
    dp[0] = 0;
    rep(i, 0, M) {
        int a, b;
        cin >> a >> b;
        int t = 0;
        while(b--) {
            int c; cin >> c; c--;
            t |= 1 << c;
        }
        rep(mask, 0, 1 << N) if(dp[mask] != INF) {
            chmin(dp[mask | t], dp[mask] + a);
        }
    }
    int ans = dp[(1 << N) - 1];
    if(ans == INF) ans = -1;
    cout << ans << '\n';
}

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


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

int main(){
  	int memox= 0,memoy= 0;
  	string s;
  	cin >> s;
  	bool flag[4] = {false,false,false,false};
  
  	rep(i,0,s.size()){
      switch(s[i]){
        case 'W':
          flag[0] = true;
          break;
        case 'E':
          flag[1] = true;
          break;
        case 'N':
          flag[2] = true;
          break;
        case 'S':
          flag[3] = true;
          break;
      }
    }
  
  	cout << (((flag[0] == flag[1]) && (flag[2] == flag[3]))?"Yes":"No") << endl;
	return 0; 
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define A first
#define B second

using namespace std;

typedef pair<int,int> P;

int main(void){
	
	int n,k,dp[102][4][3];
	
	cin >> n >> k;
	
	vector<P>v(k);
	
	for(int i=0;i<k;i++)
		cin >> v[i].A >> v[i].B;
	
	sort(v.begin(),v.end());
	
	for(int i=0;i<101;i++)
		for(int j=0;j<4;j++)
			for(int k=0;k<3;k++)
				dp[i][j][k]=0;
	
		for(int i=1;i<4;i++)dp[1][i][1]=1;
	
	int p=0;
	
	for(int i=1;i<=n;i++){
		for(int k=1;k<4;k++){
			for(int l=1;l<3;l++){
					
				if(i==v[p].A){
					if(v[p].B==k && l<2)dp[i+1][k][l+1]+=dp[i][v[p].B][l]%10000;
					else if(v[p].B!=k)dp[i+1][k][1]+=dp[i][v[p].B][l]%10000;
					continue;
				}
					
				for(int j=1;j<4;j++){
					if(j==k && l<2)dp[i+1][k][l+1]+=dp[i][j][l]%10000;
					else if(j!=k)dp[i+1][k][1]+=dp[i][j][l]%10000;
				}
			}
		}
		if(v[p].A==i)p++;
	}
	
	int ans=0;
	
	if(n==v[p-1].A){
		for(int j=1;j<3;j++){
			ans+=dp[n][v[p-1].B][j];
			ans%=10000;
		}
	}
	else {
		for(int i=1;i<4;i++){
			for(int j=1;j<3;j++){
				ans+=dp[n][i][j];
				ans%=10000;
			}
		}
	}
	
	cout << ans << endl;
	
return 0;
}

Measured memory_bytes: 1204
N, M = [int(i) for i in input().split()]

dp = [0] * (N + 1)
dp[0] = 1
b = 1
f = False
for _ in range(M):
    a = int(input())
    if a - b == 1:
        f = True
        break
    dp[a] = -1
    b = a

if f:
    ans = 0
elif len(dp) == 2:
    if dp[1] == -1:
        ans = 0
    else:
        ans = 1
else:
    MOD = 10**9 + 7
    
    if dp[1] != -1:
        dp[1] = 1
    for i in range(2, N + 1):
        if dp[i] != -1:
            s = 0 if dp[i-2] == -1 else (dp[i-2] % MOD)
            p = 0 if dp[i-1] == -1 else (dp[i-1] % MOD)
            dp[i] = s + p
            ans = dp[-1] % MOD
print(ans)

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

int main(){
  long n, xmin, xmax, xsum, x;
  xsum = 0;
  xmin = 1000001;
  xmax = -1000001;
  cin >> n;
  for(int i=0; i < n; i++ ){
    cin >> x;
    xmax = max(x,xmax);
    xmin = min(x,xmin);
    xsum += x;
  }
  cout << xmin << ' ' << xmax << ' ' << xsum << endl;
  return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

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

  int k, n; cin >> k >> n;
  vi a(n);
  rep(i, n) cin >> a[i];

  vi b;
  rep(i, n-1) b.eb(a[i+1] - a[i]);
  
  b.eb(a[0] + (k - a[n-1]));
  cout << k - *max_element(all(b)) << endl;

  return (0);
}


Measured memory_bytes: 5068
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    vector<ll> A(N);

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A[i] = a - (i + 1);
    }
    sort(A.begin(),A.end());
    ll b = A[N / 2];

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += abs(A[i] - b);
    }
    
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
#coding: utf-8

import bisect

n = int(input())
a = [int(n) for n in input().split()]
b = [int(n) for n in input().split()]
c = [int(n) for n in input().split()]

a.sort()
b.sort()
c.sort()

ba = []
baccum = []
tmp = 0
for bb in b:
    ba.append(bisect.bisect_right(a, bb-1))
    tmp += ba[-1]
    baccum.append(tmp) 

cb = []
for cc in c:
    cb.append(bisect.bisect_right(b, cc-1))

ret = 0
for cc in cb:
    if cc == 0:
        continue
    ret += baccum[cc-1] 

print(ret)



Measured memory_bytes: 34600
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

typedef struct data
{
  double L, a, b;
} Data;

int main()
{
  int N, M;
  cin >> N >> M;
  Data d[N];
  for(int i = 0; i < N; i++)
    cin >> d[i].L >> d[i].a >> d[i].b;
  double r[N+1][N+1];
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      r[i][j] = pow(d[i].L-d[j].L,2)+pow(d[i].a-d[j].a,2)+pow(d[i].b-d[j].b,2);
    }
  }
  double ans = 0.0;
  for(int s = 0; s < (1<<N); s++){
    vector<int> n;
    for(int i = 0; i < N; i++){
      if(s & (1<<i)){
        n.push_back(i);
      }
    }
    if((int)n.size() != M) continue;
    double x = 0.0;
    for(int i = 0; i < (int)n.size(); i++){
      for(int j = i+1; j < (int)n.size(); j++){
        x += r[n[i]][n[j]];
      }
    }
    ans = max(ans,x);
  }
  printf("%.6lf\n",ans);
}

Measured memory_bytes: 1272
#include <stdio.h>

int main(void)
{
	int A, B, C;
	int five = 0, seven = 0;

	scanf("%d%d%d", &A, &B, &C);

	if (A == 5)
		five++;
	if (A == 7)
		seven++;
	if (B == 5)
		five++;
	if (B == 7)
		seven++;
	if (C == 5)
		five++;
	if (C == 7)
		seven++;

	if (five == 2 && seven == 1)
		printf("YES\n");
	else
		printf("NO\n");

	return 0;
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <vector>

class DPreparingBoxes {
public:
    void solve(std::istream& in, std::ostream& out) {
        long long n;
        std::vector<int> ans, a(200020), b(200020);
        in >> n;
        for(int i = 0; i < n; i++){
            in >> a[i];
        }
        for(int i = n-1; i >= 0; i--){
            int count = 0;
            for(int j = 2*(i+1); j <= n; j += (i+1)){
                count += b[j-1];
            }
            if((count % 2) != a[i]){
                b[i] = 1;
                ans.push_back(i+1);
            }
        }
        out << ans.size() << std::endl;
        for(auto i : ans){
            out << i << " ";
        }
        out << std::endl;
    }
};


int main() {
    DPreparingBoxes solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

int main() {
  string s;
  cin>>s;
  if(s.at(0)==s.at(1)&&s.at(1)==s.at(2)&&s.at(2)==s.at(0)){cout<<"No";}
  else{cout<<"Yes";}
  
  return 0;
  
}


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

#define SEG_LEN (1<<18)

int seg[SEG_LEN*2];

void add(int i,int x){
    i+=SEG_LEN;
    seg[i] +=x;
    while(1){
        i/=2;
        if(i==0) break;
        seg[i] = seg[i*2]+seg[i*2+1];
    }
}

int sum(int l,int r){
    l+=SEG_LEN;
    r+=SEG_LEN;
    int ans = 0;
    while(l<r){
        if(l&1){
            ans+=seg[l];
            l++;
        }
        l/=2;
        if(r&1){
            ans+=seg[r-1];
            r--;
        }
        r/=2;
    }
    return ans;
}

int main(){
    int n,q;cin >> n >> q;
    for(int i=0;i<q;i++){
        int cmd;cin >> cmd;
        if(cmd==0){
            int i,x;cin >> i >> x;
            add(i,x);
        }else{
            int l,r;cin >> l >> r;
            cout << sum(l,r+1) << endl;
        }
    }
}



Measured memory_bytes: 3864
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(vecto) vecto.begin(),vecto.end()
typedef long long ll;

int main(){
    string s, t;
    cin >> s >> t;
    if(s.size()>t.size()){
        char k = s.at(s.size()-1);
        s.pop_back();
    string pass;
    rep(i,s.size()){
        pass = pass + s.at(i) + t.at(i);
    }
    cout << pass + k << endl;
    }
    else{
        string pass;
        rep(i, s.size())
        {
            pass = pass + s.at(i) + t.at(i);
        }
        cout << pass  << endl;
    }
}

Measured memory_bytes: 256
package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	f := func(n, k int, do func([]int)) {
		a := make([]int, k)
		do(a)
		for {
			i := k - 1
			for ; i >= 0; i-- {
				if a[i] != n-1 {
					break
				}
			}
			if i == -1 {
				return
			}
			a[i]++
			for j := i + 1; j < k; j++ {
				a[j] = a[i]
			}
			do(a)
		}
	}

	var n, m, q, ans int
	Fscan(in, &n, &m, &q)
	qs := make([][4]int, q)
	for i := range qs {
		for j := range qs[i] {
			Fscan(in, &qs[i][j])
		}
	}
	f(m, n, func(a []int) {
		c := 0
		for _, q := range qs {
			if a[q[1]-1]-a[q[0]-1] == q[2] {
				c += q[3]
			}
		}
		if c > ans {
			ans = c
		}
	})
	Fprint(_w, ans)
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 1856
input = readline
x = []
input.split(" ").each do |s|
  case s
  when "+"
    a = x.pop
    b = x.pop
    x.push(a + b)
  when "-"
    a = x.pop
    b = x.pop
    x.push(b - a)
  when "*"
    a = x.pop
    b = x.pop
    x.push(a * b)
  else
    x.push s.to_i
  end
end
p x.pop


Measured memory_bytes: 6876
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=1e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                    cerr<<#x<<": "<<x<<endl
#define trace2(x, y)                 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)                 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)             cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)         cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

ll n;
ll h[M];
ll a[M][4];
ll cache[M][4];
ll k;

ll dp(ll x, ll prev){
    if(x>n) return 0;
    ll &ans=cache[x][prev];
    if(ans!=-1) return ans;
    ans=0;
    for(ll i=1; i<=3; i++){
        if(i==prev) continue;
        ans=max(ans,dp(x+1,i)+a[x][i]);
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    mst(cache,-1);
    rep(i,1,n+1){
        rep(j,1,4){
            cin >> a[i][j];
        }
    }
    ll answer=dp(1,0);
    cout << answer;
    return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 10624
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
#define max 100000
using namespace std;
ll l = 1000000007;

int main()
{
	float t, x;
	cin >> t >> x;

	cout << t / x << endl;
}



Measured memory_bytes: 256
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define endl '\n'
#define rtl rt<<1
#define rtr rt<<1|1
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define maxx(a, b) (a > b ? a : b)
#define minn(a, b) (a < b ? a : b)
#define zero(a) memset(a, 0, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define _test printf("==================================================\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> P2;
const double pi = acos(-1.0);
const double eps = 1e-7;
const ll MOD =  1000000007LL;
const int INF = 0x3f3f3f3f;
const int _NAN = -0x3f3f3f3f;
const double EULC = 0.5772156649015328;
const int NIL = -1;
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
const int maxn = 1e3+10;
ll num, ans;
void dfs(ll x, int n3, int n5, int n7) {
    if (x>num) return;
    if (x<=num && n3>=1 && n5>=1 && n7>=1) ++ans;
    dfs(x*10+3, n3+1, n5, n7);
    dfs(x*10+5, n3, n5+1, n7);
    dfs(x*10+7, n3, n5, n7+1);
}
int main(void) {
    while(~scanf("%lld", &num)) {
        ans = 0;
        dfs(0, 0, 0, 0);
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
int main(){

	char a[21];
	int i;

	scanf("%s",a);
	for(i=0;a[i]!='\0';i++);
	if(i>0) i--;
	for(;i>=0;i--) std::cout << a[i];
	std::cout<<std::endl;
	
		return 0;
		}

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

int main()
{
  int N;
  int M;
  vector<int> A;
  cin >> N >> M;
  for (int i = 0; i < M; ++i)
  {
    int x;
    cin >> x;
    A.push_back(x);
  }
  int a = accumulate(A.begin(), A.end(), 0);
  cout << max(-1, N - a) << endl;
}

Measured memory_bytes: 3736
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

#define MAX_V 102

struct edge { int to, cap, rev; };

vector<edge> G[MAX_V];	// ??°???????????£??\???????????¨???
int level[MAX_V];	// s??????????????¢
int iter[MAX_V];	// ???????????§??????????????£??????

// from??????to??????????????????cap???????????°?????????????????????
void add_edge(int from, int to, int cap)
{
	G[from].push_back(edge{ to, cap, (int)G[to].size() });
	G[to].push_back(edge{ from, 0, (int)G[from].size() - 1 });
}

// s????????????????????¢???BFS??§?¨????
void bfs(int s) {
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for (int i = 0; i < G[v].size(); i++) {
			edge &e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v, int t, int f) {
	if (v == t)return f;
	for (int &i = iter[v]; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	while (true) {
		bfs(s);
		if (level[t] < 0)return flow;
		memset(iter, 0, sizeof(iter));
		int f;
		while ((f = dfs(s, t, INF)) > 0) {
			flow += f;
		}
	}
}

int main() {
	int V, E;
	cin >> V >> E;
	rep(i, E) {
		int u, v, c;
		cin >> u >> v >> c;
		add_edge(u, v, c);
	}
	cout << max_flow(0, V - 1) << endl;

	return 0;
}

Measured memory_bytes: 3136
program abc071b
  implicit none
  integer i
  character(26),parameter :: alphabet = 'abcdefghijklmnopqrstuvwxyz'
  character(100000) s

  read *, s
  i = verify(alphabet, s)
  if (i == 0) then
     print '(a)', 'None'
  else
     print '(a)', alphabet(i:i)
  end if
end program abc071b


Measured memory_bytes: 700
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define INF (1<<29)
int dp[10000][10000] = { {INF} };
int main()
{
	string s1, s2; cin >> s1 >> s2;
	int s1sz = s1.size(), s2sz = s2.size();
	for (int i = 0; i <= s1sz; ++i) {
		for (int j = 0; j <= s2sz; ++j) {
			if (i == 0) {
				dp[0][j] = j;
				continue;
			}
			else if (j == 0) {
				dp[i][0] = i;
				continue;
			}
			else {
				dp[i][j] = min(dp[i - 1][j - 1] + (s1[i - 1] != s2[j - 1]), min(dp[i - 1][j] + 1, dp[i][j - 1] + 1));
			}
		}
	}
	cout << dp[s1sz][s2sz] << endl;
}

Measured memory_bytes: 9064
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define rep(i,n) for(unsigned int i = 0;i <  n;i++)

int main() {
	int n, k;
	cin >> n >> k;
	if (n%k == 0)cout << 0 << endl;
	else cout << 1 << endl;
	return(0);
}


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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0);
#define inf 1e18 +5;
ll solve(ll no_of_items,ll knap_cap, vector<ll>val,vector<ll>wt,ll sum_val)
{
    ll dp[sum_val+1][no_of_items+1];



    for(ll row=0;row<=sum_val;row++)
        dp[row][0]=inf;
    for(ll col=0;col<=no_of_items;col++)
        dp[0][col]=0;


     ll ans= -1;
    for(ll i=1;i<= sum_val;i++)
    {
        for(ll j=1;j<=no_of_items;j++)
        {

            if(i>=val[j-1])
            {
                dp[i][j]= min(dp[i-val[j-1]][j-1]+wt[j-1],dp[i][j-1]);
            }
            else
            {
               dp[i][j]=dp[i][j-1];
            }

            if(dp[i][j]<=knap_cap )
            {
               /* watch(dp[i][j]);
                watch(knap_cap);
                watch(i);
                watch(ans);*/
                 ans=max(ans,i);
            }


        }


    }




    return ans;

}

int main()
{

	ll no_of_items,knap_cap;

	 cin>>no_of_items>>knap_cap;

	 vector<ll>val(no_of_items);
	 vector<ll>wt(no_of_items);

	 ll sum_val=0;

	 f(i,0,no_of_items)
	 {
	     cin>>wt[i]>>val[i];
	     sum_val+=val[i];
	 }

	ll ans=solve(no_of_items,knap_cap,val,wt,sum_val);

	cout<<ans<<"\n";

	return 0;
}













Measured memory_bytes: 79104
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  while (true) {
    int h, w; cin >> h >> w;
    if (h == 0 && w == 0) break;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
	if (i != 0 && i != h-1 && j != 0 && j != w-1) {
	  cout << '.';
	} else {
	  cout << '#';
	}
      }
      cout << endl;
    }
      cout << endl;
  }
  return 0;
  
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
 
#define ll long long
#define loop(a) loopi(i,a)
#define loopi(i,a) for(int i=0; i<a; i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
 
using namespace std;
 
const int mod=1e9+7;
const int maxn=100005;
 
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	string s;
	cin >> s;
	if(s[0]=='M') cout << 6 << "\n";
	else if(s[0]=='T'){
		if(s[1]=='U') cout << 5 << "\n";
		else cout << 3 << "\n";
	} 
	else if(s[0]=='W') cout << 4 << "\n";
	else if(s[0]=='F') cout << 2 << "\n";
	else if(s[0]=='S'){
		if(s[1]=='U') cout << 7 << "\n";
		else cout << 1 << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
(locally (declare (optimize (debug 0) (safety 0) (space 0) (speed 3)))
  (let* ((N (read))
         (member-number (make-array N :initial-element 0 :element-type 'fixnum)))
    (declare (type fixnum N))
    (dotimes (x (- N 1))
      (let ((tmp (read)))
        (declare (type fixnum tmp))
        (incf (aref member-number (- tmp 1)))))
    (loop for i below N
          do (print (aref member-number i)))
    (fresh-line)))

Measured memory_bytes: 78480
#include<bits/stdc++.h>
using namespace std;
#define ll  unsigned long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define wi while
#define vl vector<ll>
#define vi vector<int>
#define map map<char,ll>
#define endl "\n"
const int mxN = 200001;
const ll INF = 1e18L + 5;
ll dp[402][402];
//dp[i][j] contains the answer of range i to j
ll a[402];
ll sum(int l,int r)
{
    ll s = 0;
    for(int i=l;i<=r;++i)
    {
        s += a[i];
    }
    return s;
}
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    
    ll n;
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
    }
    for(int l=n;l>0;--l)
    {
        for(int r=l;r<=n;++r)
        {
            if(l==r)
            {
                dp[l][r] = 0;
            }
            else
            {
                dp[l][r] = INF;
                ll s = sum(l,r);
                for(int i=l;i<=r-1;++i)
                {
                    dp[l][r] = min(dp[l][r],dp[l][i]+dp[i+1][r]+s);
                }
            }
        }
    }
    cout<<dp[1][n]<<endl;



    
    return 0;

}


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

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

  vector<pair<long long, long long> > v(n);
  for(int i=0; i < n; i++) {
    long long a, b; cin >> a >> b;
    v[i] = make_pair(b, a);
  }
  sort(v.begin(), v.end());

  bool ok = true;
  int current = 0;
  for(int i=0; i < n; i++) {
    current += v[i].second;
    if(current > v[i].first){ok = false; break;}
  }

  cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
using namespace std; 
typedef long long ll;
const int N  = 200010;
ll t[N];
int main(){
    int n,T;
    cin >> n >> T;
    for (int i = 0; i < n; i ++ ){
        cin >> t[i];
    }

    ll sum = 0;
    for (int i = 1; i < n; i ++ ){
        if(t[i] - t[i-1] >= T){
        	sum =sum+ T;
		}else{
			sum =sum+ (t[i]-t[i-1]);
		} 
    }
    cout << sum+T << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <climits>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;
int Ld[110];
int dat[110][110];
int main(){
	while(1){
	int N,M,L,K,A,H;
	cin>>N>>M>>L>>K>>A>>H;
	if(N==0 && M==0 && L==0){
		break;
	}
	for(int i=0;i<N;i++){
		Ld[i]=0;
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			dat[i][j]=415411;
		}
	}
	Ld[A]=1;
	Ld[H]=1;
	for(int i=0;i<L;i++){
		int h;
		cin>>h;
		Ld[h]=1;
	}
	for(int i=0;i<K;i++){
		int a,b,l;
		cin>>a>>b>>l;
		dat[a][b]=l;
		dat[b][a]=l;
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			for(int k=0;k<N;k++){
				dat[j][k]=min(dat[j][i]+dat[i][k],dat[j][k]);
			}
		}
	}

	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(Ld[i]==0 || Ld[i]==0 || dat[i][j]>M){
				dat[i][j]=415411;
			}
		}
	}

	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			for(int k=0;k<N;k++){
				dat[j][k]=min(dat[j][i]+dat[i][k],dat[j][k]);
			}
		}
	}

	if(dat[A][H]>=415411){
		cout<<"Help!"<<endl;
	}
	else{
		cout<<dat[A][H]+max(0,dat[A][H]-M)<<endl;
	}
	}






	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef long long lint;

const long mod = 1e9 + 7;

long powmod(long x, long n){
  long ret = 1;
  while(n > 0){
    if(n&1) ret *= x, ret %= mod, n -= 1;
    else x *= x, x %= mod, n >>= 1;
  }
  return ret;
}

vector<long> fact;
vector<long> revfact;

void setfact(int n){
  fact.resize(n+1); revfact.resize(n+1);
  fact[0] = 1;
  rep(i, n) fact[i+1] = fact[i] * (i+1) % mod;
  
  revfact[n] = powmod(fact[n], mod-2);
  for(int i=n-1; i>=0; i--) revfact[i] = revfact[i+1] * (i+1) % mod;
}

long getC(int n, int r){
  return fact[n] * revfact[r] % mod * revfact[n-r] % mod;
}

int main(){
    long n, m, k; cin >> n >> m >> k;
    setfact(n*m);
    long ans = 0;
    rep(i, m) ans = (ans + n*n%mod*(m-i)%mod*i%mod) % mod;
    rep(i, n) ans = (ans + m*m%mod*(n-i)%mod*i%mod) % mod;
    cout << ans * getC(n*m-2, k-2) % mod;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i=0;i<N;i++) {
			A[i]=sc.nextInt();
		}
		sc.close();
		
		int[] L = new int[N+1];
		int[] R = new int[N+1];
		
		int temp = 0;
		for (int i=0;i<N;i++) {
			temp+=A[i];
			L[i+1]=temp;
		}
		temp = 0;
		for (int i=N-1;i>-1;i--) {
			temp+=A[i];
			R[i+1]=temp;
		}
		int ans = 10000000;
		for (int i=0;i<N;i++) {
			ans = Math.min(ans, Math.abs(L[i]-R[i+1]));
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 22740
import java.util.*;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int A = sc.nextInt();
      int B = sc.nextInt();
      int C = sc.nextInt();
      int X = sc.nextInt();
      int Y = sc.nextInt();

      int cost = Integer.MAX_VALUE;
      // ABセット（C*2）の枚数に基づいてA,Bの枚数を求める。
      for (int i = 0; i <= 100000; i++) {
        int tmp = i * (2 * C) + Math.max(0, X - i) * A + Math.max(0, Y - i) * B;
        cost = Math.min(tmp, cost);
      }

      System.out.println(cost);
    }
  }
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int h,w,x,y;
  int ans;
  cin>>h>>w>>x>>y;
  ans=h-x;
  ans*=w-y;
  cout<<ans<<"\n";
  return 0;
}

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

int main()
{
    string al;
    cin >> al;
    for(int i=0,len=al.size(); i < len; ++i) {
        if ('D' <= al[i] && al[i] <= 'Z') al[i]-=3;
        else al[i] += 23;
    }
    
    cout << al << endl;

    return 0;
}

Measured memory_bytes: 1180
N,K,S=map(int,input().split())

if S!=10**9:
    ANS=[10**9 for i in range(N)]
    for i in range(K):
        ANS[i]=S
else:
    ANS=[10**9-1 for i in range(N)]
    for i in range(K):
        ANS[i]=S
print(*ANS)

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;


lli dp[100001][3]; // i日に j を選択した時の最大の幸福度。(jが0,1,2のときにそれぞれa,b,cを選んでいる)

inline int next(int x) {
    return (x + 1) % 3;
}

inline int nexxt(int x) {
    return (x + 2) % 3;
}

int main() {
    lli n;
    cin1(n);
    lli x[n+1][3];
    REPE(i,1,n) {
        REP(j,0,3) {
            cin >> x[i][j];
        }
    }
    x[0][0] = x[0][1] = x[0][2] = 0;

    REPE(i,1,n) {
        REP(j,0,3) {
            dp[i][j] = max(dp[i-1][next(j)], dp[i-1][nexxt(j)]) + x[i][j];
        }
    }
    lli ans = 0;
    REP(i,0,3) {
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <random>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    int n; cin >> n;
    int p[n]; rep(i,n) cin >> p[i];
    // swap1回で修正できるのはたかだか2個の数字
    // p[i] != i+1 の数が2個(最低)なら，それをswapできる
    // p[i] != i+1 の数が3個以上なら，NO
    int cnt = 0;
    rep(i,n-1) {
        if (p[i] != i+1) cnt++;
    }
    if (cnt <= 2)
    {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define ll long long
using namespace std;
int main(){
  	ll n, d;
  	cin >> n >> d;
  	ll ans = n / (2 * d + 1);
  	if(n % ( 2 * d + 1) != 0) ans++;
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256