akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
using namespace std;

#define ILLEGAL puts("0"), exit(0)

const int MAXN = 100000;
const int MOD = int(1E9) + 7;
const int INV2 = (MOD + 1) / 2;

int pow_mod(int b, int p) {
	int ret = 1;
	for(int i=p;i;i>>=1,b=1LL*b*b%MOD)
		if( i & 1 ) ret = 1LL*ret*b%MOD;
	return ret;
}

int fct[MAXN + 5], ifct[MAXN + 5], f[MAXN + 5];
int comb(int n, int m) {
	return 1LL*fct[n]*ifct[m]%MOD*ifct[n-m]%MOD;
}
void init() {
	fct[0] = 1;
	for(int i=1;i<=MAXN;i++)
		fct[i] = 1LL*fct[i-1]*i%MOD;
	ifct[MAXN] = pow_mod(fct[MAXN], MOD - 2);
	for(int i=MAXN-1;i>=0;i--)
		ifct[i] = 1LL*ifct[i+1]*(i+1)%MOD;
	f[0] = 1;
	for(int i=2;i<=MAXN;i+=2)
		f[i] = 1LL*comb(i, 2)*f[i-2]%MOD*pow_mod(i/2, MOD-2)%MOD;
}

int a[MAXN + 5], N;
bool tag[MAXN + 5], vis[MAXN + 5];
int cnt[MAXN + 5], b[MAXN + 5], ind[MAXN + 5];

int main() {
	init(), scanf("%d", &N);
	for(int i=1;i<=N;i++)
		scanf("%d", &a[i]), ind[a[i]]++;
	for(int i=1;i<=N;i++)
		if( ind[i] >= 3 ) ILLEGAL;
	for(int i=1;i<=N;i++) {
		if( ind[i] == 2 ) {
			if( tag[i] ) continue;
			int p = i;
			while( !vis[p] )
				vis[p] = true, p = a[p];
			if( p != i ) ILLEGAL;
			p = i;
			do {
				tag[p] = true, p = a[p];
			}while( p != i );
		}
	}
	for(int i=1;i<=N;i++) {
		if( ind[i] == 0 ) {
			int t = 0, p = i;
			while( !tag[p] )
				vis[p] = true, t++, p = a[p];
			b[p] = t;
		}
	}
	int ans = 1;
	for(int i=1;i<=N;i++) {
		if( b[i] ) {
			int t = 0, p = i;
			do {
				t++, p = a[p];
			}while( !b[p] );
			if( t < b[p] ) ILLEGAL;
			else if( t > b[p] ) ans = 2LL*ans%MOD;
		}
	}
	for(int i=1;i<=N;i++) {
		if( !vis[i] ) {
			int t = 0, p = i;
			do {
				vis[p] = true, t++, p = a[p];
			}while( !vis[p] );
			cnt[t]++;
		}
	}
	for(int i=1;i<=N;i++) {
		int del = 0;
		for(int j=0;j<=cnt[i];j+=2) {
			int tmp = 1;
			tmp = 1LL*tmp*comb(cnt[i], j)%MOD*f[j]%MOD*pow_mod(i, j/2)%MOD;
			if( (i & 1) && i != 1 ) {
				tmp = 1LL*tmp*pow_mod(2, cnt[i] - j)%MOD;
			}
			del = (del + tmp) % MOD;
		}
		ans = 1LL*ans*del%MOD;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
short dp[3001][3001];
void printLCS(string &s,string &t) {
  int sp=0,tp=0;
  while(sp < s.size() and tp < t.size()) {
    if (s[sp] == t[tp]) {
      cout << s[sp];
      sp++;
      tp++;
    } else {
      if (dp[sp][tp] == dp[sp][tp+1]) {
        tp++;
      } else {
        sp++;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  string s,t;
  cin >> s >> t;
  memset(dp,0,sizeof dp[0][0] * 3001 * 3001);
  for(int i=s.size()-1;i>=0;i--) {
    for(int j=t.size()-1;j>=0;j--) {
      if (s[i] == t[j]) {
        dp[i][j] = 1 + dp[i+1][j+1];
      } else {
        dp[i][j] = max(dp[i+1][j],dp[i][j+1]);
      }
    }
  }
  printLCS(s,t);
  return 0;
}

Measured memory_bytes: 17920
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	t := make(MyInts, 5)
	for i := range t {
		t[i] = nextInt()
	}
	sort.Sort(t)

	a := filterA(t)
	b := filterB(t)
	ans := sum(a)
	for i := len(b) - 1; i > 0; i-- {
		ans += b[i] + (10 - b[i]%10)
	}
	if len(b) > 0 {
		ans += b[0]
	}
	puts(ans)
	wt.Flush()
}

type MyInts []int

func (m MyInts) Len() int {
	return len(m)
}

func (m MyInts) Less(i, j int) bool {
	return m[i]%10 < m[j]%10
}

func (m MyInts) Swap(i, j int) {
	m[i], m[j] = m[j], m[i]
}

func filterA(m MyInts) []int {
	ret := make([]int, 0)
	for i := range m {
		if m[i]%10 == 0 {
			ret = append(ret, m[i])
		}
	}
	return ret
}

func filterB(m MyInts) []int {
	ret := make([]int, 0)
	for i := range m {
		if m[i]%10 != 0 {
			ret = append(ret, m[i])
		}
	}
	return ret
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func sum(a []int) int {
	ret := 0
	for _, v := range a {
		ret += v
	}
	return ret
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int a, b, i;

int main(){
  FAST_IO

  cin >> a >> b;
  i = b - a;

  cout << i * (i + 1) / 2 - b << '\n';
  return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
cd = []
for _ in range(m):
    c, d = (int(x) for x in input().split())
    cd.append([c, d])

for a,b in ab:
    ans = 10000000000000000000000
    for k,c in enumerate(cd):
        memo = abs(a-c[0])+abs(b-c[1])
        if memo<ans:
            ans=memo
            ansnum=k
    print(ansnum+1)

Measured memory_bytes: 39280
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	int n,m,r;
	cin>>n>>m>>r;
	vector<int> rr(r);
	for(int i=0;i<r;i++){
		cin>>rr[i];
		rr[i]--;
	}
	vector<vector<int> > g(n, vector<int>(n,inf));
	for(int i=0;i<m;i++){
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		g[a][b] = c;
		g[b][a] = c;
	}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
		    for(int j=0;j<n;j++){
				g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
		    }	   
		}
	}

	int res = inf;
	sort(rr.begin(),rr.end());
	do{
		int tmp = 0;
		for(int i=1;i<r;i++){	
		    tmp += g[ rr[i-1] ] [ rr[i] ];
		}
		res = min(res,tmp);
	}while(next_permutation(rr.begin(),rr.end()) );
	cout<<res<<endl;
	/*for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cout<<g[i][j]<<' ';
		}
		cout<<endl;
	}*/

	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){


  int i,j,p,n,b,f,r,v;
  int a[4][3][10]={};
  
  scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d %d %d %d",&b,&f,&r,&v);
      a[b-1][f-1][r-1]=a[b-1][f-1][r-1]+v;
    }
    for(i=0;i<4;i++){
      for(j=0;j<3;j++){
    for(p=0;p<10;p++){
      printf(" %d",a[i][j][p]);
    }
    printf("%c",'\n');
      }
    if(i!=3)
      printf("####################\n");
       
    }
    return 0;
}   




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

int main(){
    ll N;
    cin >> N;
    
    ll n = N;
  
    string s;
    while(true){
        ll x;
        char ch;
        n--;
        x = n%26 + 97;
        //cout << (char) x;
        ch = (char) x;
        s = s + ch;
        n /=26;
        if(n==0) break;
    }//cout << endl;
    
    //cout << s << endl;
    
    ll z = s.size()-1;
    for(ll i=z; i>=0; i--){
        cout << (char)s[i];
    }cout << endl;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
vector<int> graph[100001];
int dp[100001];
int len(int u)
{
    if(dp[u] != -1)
        return dp[u];
    bool leaf = 1;
    int ans = 0;
    for(auto child: graph[u])
    {
        leaf = 0;
        ans = max(ans,len(child));
    }

    return dp[u] = leaf? 0 : 1+ ans;

}
int main()
{
    int n,m,u,v;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>u>>v;
        graph[u].push_back(v);
    }

    int ans = 0;
    memset(dp, -1 ,sizeof dp);
    for(int i=1;i<=n;i++)
    {
        ans = max(ans,len(i));
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
	int AB=inputValue();
	int BC=inputValue();
	output(AB*BC/2,0);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> p(n), c(n);
    rep(i,n) {
        cin >> p[i];
        p[i]--;
    }
    rep(i,n) cin >> c[i];
    ll ans=-10e10;
    rep(i,n) {
        int v=i;
        ll cycle_sum=0;
        int cycle_cnt=0;
        while(true) {
            cycle_cnt++;
            cycle_sum+=c[v];
            v=p[v];
            if(v==i) break;
        }
        ll path=0;
        int cnt=0;
        while(true) {
            cnt++;
            path+=c[v];
            if(cnt>k) break;
            int num=(k-cnt)/cycle_cnt;
            ll score=path+max(0ll,cycle_sum)*num;
            if(ans<score) ans=score;
            v=p[v];
            if(i==v) break;
        } 
    }
    cout << ans << endl;
}


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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

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

  long n;
  vector<long> a;
  vector<long> b;
  cin >> n;
  rep(i, 0, n) {
    long a0;
    cin >> a0;
    a.pb(a0);
  }
  rep(i, 0, n - 1) {
    long b0;
    cin >> b0;
    b.pb(b0);
  }

  long ans = 0;
  rep(i, 0, n - 1) {
    long sum = min(a[i], b[i]);
    a[i] -= sum;
    b[i] -= sum;
    ans += sum;
    if (b[i]) {
      long sum2 = min(b[i], a[i + 1]);
      a[i + 1] -= sum2;
      b[i] -= sum2;
      ans += sum2;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2548
# https://atcoder.jp/contests/abc077/tasks/arc084_a

import itertools
import collections
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort()
    B.sort()
    C.sort()

    ans = 0

    for b in B:
        i = bisect.bisect_left(A, b)
        j = bisect.bisect_right(C, b)

        ans += i * (N - j)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 23712
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int n,a,i,j,k,x,cnt;
	while(1){
		cin>>n>>x;
		if(n==0&&x==0) break;
		cnt=0;
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				for(k=1;k<=n;k++){
					a=i+j+k;
					if(a==x&&i!=j&&i!=k&&j!=k){
						cnt=cnt+1;
					}
				}
			}
		}
		cnt=cnt/6;
		cout<<cnt<<endl;
	}
	
	return 0;
}



Measured memory_bytes: 3100
MOD = (10**9 + 7)

     
line = [int(s) for s in input().split()]
     
N, M = line[0], line[1]
     
b = [0]*(N+1)
for i in range(M):
    step_num = int(input().split()[0])
    b[step_num] = 1
        
        
dp = [0]*(N+1)
dp[0] = 1
if b[1] == 1:
    dp[1] = 0
else:
    dp[1] = 1
     
for i in range(2, N+1):
    if b[i] == 1:
        dp[i] = 0
    else:
        dp[i] = (dp[i-1]+dp[i-2])%MOD
print(dp[N])

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

#define int long long

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 305;
int dis[N][N], f[N][N];

signed main()
{
	int n = read();
	int m = read();
	int L = read();
	
	memset(dis, 0x3f, sizeof(dis));
	memset(f, 0x3f, sizeof(f));
	for (int i = 1; i <= m; ++i)
	{
		int u = read();
		int v = read();
		int w = read();
		dis[u][v] = dis[v][u] = w;
	}
	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
	
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (dis[i][j] <= L) f[i][j] = 1;
	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
	
	int q = read();
	for (int i = 1; i <= q; ++i)
	{
		int u = read();
		int v = read();
		int ans = f[u][v] - 1;
		if (ans + 1 == dis[0][0]) puts("-1");
			else printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2048
n,m = map(int,input().split())
AB = []
ans = [-1] * (n) #####

edge = [[] for _ in range(n)] #edge[i] := 頂点iから伸びてる辺の行き先のリスト #####

for i in range(m):
    a,b = map(int,input().split())
    a-=1; b-=1 #####
    edge[a].append(b)    
    edge[b].append(a)    
    
import collections
que = collections.deque()
que.append(0) #####
    
while que:
    x = que.popleft()
    
    for to in edge[x]:
        a = x
        b = to
        
        if ans[b] == -1: #####
            ans[b] = x + 1 #####
            que.append(b)
            
print("Yes")
print(*ans[1:],sep="\n")


Measured memory_bytes: 97704
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif



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

    string S; cin >> S;
    int N = S.size();

    stack<char> st;
    st.push(S[0]);
    FOR(i,1,N) {
        if (st.size()>0 && st.top()=='0' && S[i]=='1') {
            st.pop();
        } else {
            st.push(S[i]);
        }
    }

    stack<char> st2;
    while(st.size()>0) {
        if (st2.size()>0 && st2.top() != st.top()) {
            st2.pop(); st.pop();
        } else {
            st2.push(st.top());
            st.pop();
        }
    }

    int ans = N - st2.size();    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
void main() {
	auto ip = readAs!(long[]), N = ip[0], M = ip[1];
	ulong res;
	if(N*2 <= M) {
		res += N;
		M = M - N*2;
		N = 0;
		res += M/4;
	} else {
		auto tmp = M/2;

		res += tmp;

	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

using namespace std;
typedef long long ll;
ll ans,n,k,a[maxn],b[maxn],s,t,x[maxn],y[maxn],z[maxn],w[maxn],C;

int main()
{
    cin >> n >> C;
    for (int i=1;i<=n;i++) scanf("%lld%lld",&a[i],&b[i]); a[n+1]=C;
    for (int i=1;i<=n;i++)
    {
        s+=b[i]-(a[i]-a[i-1]);
        t+=b[i]-(a[i]-a[i-1])*2;
        ans=max(ans,s);
        x[i]=max(x[i-1],s); y[i]=max(y[i-1],t);
    }
    s=0; t=0;
    for (int i=n;i>=1;i--)
    {
        s+=b[i]-(a[i+1]-a[i]);
        t+=b[i]-(a[i+1]-a[i])*2;
        ans=max(ans,s);
        z[i]=max(z[i+1],s); w[i]=max(w[i+1],t);
    }
    for (int i=1;i<n;i++) ans=max(ans,max(y[i]+z[i+1],x[i]+w[i+1]));
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>


using namespace std;



#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)


#define V 1000


int v[101];
int w[101];

int dp[1001][10001];

int N;
int W;

int dfs(int i,int j){


	if(i == N){
		return 0;
	}
	else if(j < w[i]){
		return dfs(i+1,j);
	}
	else if(dp[i][j] != -1){
		return dp[i][j];
	}
	else{

		return dp[i][j] = max(dfs(i+1,j),dfs(i+1,j-w[i]) + v[i]);
	}
}


int main(){

	memset(dp,-1,sizeof(dp));


	cin >> N >> W;

	REP(i,N){
		cin >> v[i] >> w[i];
	}

	cout << dfs(0,W) << endl;

	return 0;

}

Measured memory_bytes: 40276
def vacation():
    N = int(input())
    d = list(input().split() for _ in range(N))

    happiness=list()

    if N==1:
        return max(d[0])

    for i in range(N):
        day = list()
        if i == 0:
            for c in range(3):
                day.append(int(d[0][c]))
        else:
            for c in range(3):
                tmp = list()
                for bc in range(3):
                    if c != bc:
                        tmp.append(int(happiness[i-1][bc])+int(d[i][c]))
                day.append(max(tmp))

        happiness.append(day)
    return max(happiness[-1])


if __name__ == "__main__":
    print(vacation())

Measured memory_bytes: 59008
def solve():
    N = int(input())
    L = list(map(int,input().split()))


    ans = 0
    for i in range(N):
        for j in range(i,N):
            for k in range(j,N):
                if L[i] == L[j] or L[j] == L[k] or L[i] == L[k]:
                    continue

                if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[i] + L[k] > L[j]:
                    ans += 1 

    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 67968
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T &a, T b) {if (a < b) {a = b;return 1;}return 0;}
template<class T> inline bool chmin(T &a, T b) {if (a > b) {a = b;return 1;}return 0;}

int main() {
  int n;
  cin >> n;
  ll total = 0;
  for (int i = 1; i < n+1; i++) {
    total += (n + i -1) / i -1;
  }
  cout << total << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 1e5 + 5;
int mem[N][4];
void init() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 4; j++) {
            mem[i][j] = -1;
        }
    }
}
int arr[N][3];
int findshortest(int i , int last) {
    if (i == n)
        return 0;
    if (mem[i][last] != -1) {
        return mem[i][last];
    }
    if (last == 3) {
        int choice1 = findshortest(i + 1 , 0) + arr[i][0];
        int choice2 = findshortest(i + 1 , 1) + arr[i][1];
        int choice3 = findshortest(i + 1 , 2) + arr[i][2];
        mem[i][last] = max(choice1, max(choice2 , choice3)); 
        return mem[i][last];
    }
  
    if (last == 0) {
        int choice1 = findshortest(i + 1 , 1) + arr[i][1];
        int choice2 = findshortest(i + 1 , 2) + arr[i][2];
        return mem[i][last] = max(choice1 , choice2);
    }
    if (last == 1) {
        int choice1 = findshortest(i + 1 , 0) + arr[i][0];
        int choice2 = findshortest(i + 1 , 2) + arr[i][2];
        return mem[i][last] = max(choice1 , choice2);
    }
    int choice1 = findshortest(i + 1 ,0) + arr[i][0];
    int choice2 = findshortest(i + 1 , 1) + arr[i][1];
    return max(choice1 , choice2);
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    init();
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> arr[i][j];
        }
    }
    cout << findshortest(0 , 3);
}

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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    ll s = 0;
    vector<int> a(n);
    for(auto &x : a)
        cin >> x, s+=x;
    s/=n;
    ll ans =0, ans2 =0;
    for(auto x : a)
        ans += (x-s)*(x-s);
    ++s;
    for(auto x : a)
        ans2 += (x-s)*(x-s);
    cout << min(ans, ans2);
    return 0;
}


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

ll fastpower (ll b , ll p){
    ll k= p%2 ? b : 1 ;
    return p==0 ? 1 : k*(fastpower(b*b,p/2));
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	cout<<(n*n*n)+(n*n)+n;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100001
#define w 1000000007
 
int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for(auto &l :L) cin >> l;
    int d = 0;
    int i = 0;
    for(auto &l :L){
        d += l;
        i++;
        if(d > X){
            cout << i << endl;
            return 0;
        }
    }
    i++;
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

typedef struct{
  int x;
  int y;
} point;

int smaller(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

int count(point s,point g){
  if((s.x>g.x)&&(s.y>g.y)){
    return count(g,s);
  }
  else if((s.x<g.x)&&(s.y<g.y)){
    int tlt=smaller(g.x-s.x,g.y-s.y);
    point ns={s.x+tlt,s.y+tlt};
    return tlt+count(ns,g);
  }
  else{
    return abs(s.x-g.x)+abs(s.y-g.y);
  }
}

void doit(int w,int h,int n){
  point st;
  point gl;
  int i;
  int ans=0;
  scanf("%d %d",&st.x,&st.y);
  for(i=1;i<n;i++){
    scanf("%d %d",&gl.x,&gl.y);
    ans+=count(st,gl);
    st=gl;
  }
  printf("%d\n",ans);
}

int main(){
  int w,h;
  int n;
  scanf("%d %d %d",&w,&h,&n);
  doit(w,h,n);
  return 0;
}

Measured memory_bytes: 596
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int main(){
	int n,m;
	cin>>n>>m;
	vvi in(n,vi(m));
	rep(i,n)rep(j,m)cin>>in[i][j];
	
	int t=0;
	vvi out;
	int px=-1,py=-1;
	rep(i,n)rep(_,m){
		int j;
		if(i%2==0)j=_;
		else j=m-1-_;
		if(t)out.pb({px+1,py+1,i+1,j+1});
		t=(t+in[i][j])%2;
		px=i,py=j;
	}
	
	cout<<out.size()<<endl;
	rep(i,out.size())cout<<out[i][0]<<" "<<out[i][1]<<" "<<out[i][2]<<" "<<out[i][3]<<endl;
}







Measured memory_bytes: 10288
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 1;										/* デバッグプリント 提出時は0 */
int main()
{
	int		a,b,c,ans = 0;
	
	scanf("%d %d %d", &a, &b, &c);

	ans = c / (a*7+b) * 7;
	if (c % (a*7+b) > a*7) ans += 7;
	else{
		ans += (c % (a*7+b))/a;
		if ((c % (a*7+b))%a!=0) ans++;
	}
	
	printf("%d\n",ans);


	return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    ll X;
    cin >> X;
    ll A, B;
    for(ll i = -150; i <= 150; i++){
        for(ll j = -150; j <= 150; j++){
            if (pow(i, 5) - pow(j, 5) == X){
                cout << i << " " << j << endl;
                return 0;
            }
            
        }
    }


    return 0;
}

Measured memory_bytes: 4112
d = []
while True:
    try:
        lst = list(input().split())
        for i in lst:
            if i == '+':
                num = d.pop()
                d[-1] = d[-1] + num
            
            elif i == '-':
                num = d.pop()
                d[-1] = d[-1] - num

            elif i == '*':
                num = d.pop()
                d[-1] = d[-1] * num

            elif i == '/':
                num = d.pop()
                d[-1] = d[-1] / num

            else:
                d.append(int(i))

        print(d.pop())

    except EOFError:
        break


Measured memory_bytes: 5612
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(unused_macros)]
macro_rules! vec_md {
    ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) };
    ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] };
    ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] };
}

fn main() {
    input! {
        n: usize,
        p: [f64;n]
    }

    let mut dp = vec_md![0f64;n+1;n+1];
    dp[0][0] = 1f64;
    for i in 0..dp.len() {
        for j in 0..dp[0].len() {
            if i+1<dp.len() && j+1<dp[0].len() {
                dp[i+1][j+1] += dp[i][j] * p[i];
            }
            if i+1<dp.len() {
                dp[i+1][j] += dp[i][j] * (1f64 - p[i]);
            }
        }
    }

    let mut sum = 0f64;
    for i in ((n + 1) / 2)..n+1 {
        sum += dp[n][i];
    }
    println!("{}", sum);
}

Measured memory_bytes: 90492
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
int n;
cin>>n;
string s;
cin>>s;
i64 ans=0;
forn(i,n)
{
  char r=s[i],g='*',b='*';
  int gg=0,bb=0;
  fore(j,i+1,n-1)
  {
if(s[j]!=r)
{
if(g=='*'||g==s[j])
{
  g=s[j];
  gg++;
}
else
{
  bb++;
}

  }
    }
    // cout<<gg<<" "<<bb;

    ans+=1ll*gg*bb;

}
for(int i=1;i<=n;i++)
{
  forn(j,n)
  {
if(j+2*i>=n)break;
if(s[j]!=s[j+i]&&s[j+i]!=s[j+2*i]&&s[j]!=s[j+2*i])ans--;
    }
}

cout<<ans;



    return 0;
  }


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

int main()
{
  int A,B,C,K;
  cin >> A >> B >> C;
  cin >> K;

  int max;

  if(A > B){
    if(A > C){
      max = A;
    } else{
      max = C;
    }
  } else {
    if(B > C){
      max = B;
    } else{
      max = C;
    }
  }
  int l = 1;

  for(int i = 0;i < K;i++){
    l = l*2;
  }

  int sum = A + B + C + max*(l-1);

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x);
#define PUT(x) cout << x << endl
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

int main(void)
{
	int n;
	cin >> n;
	char arr[100];

	FOR(i, n)
		cin >> arr[i];

	sort(arr,arr+n);
	cout << ((unique(arr, arr + n) - arr == 3) ? "Three" : "Four")  << endl;

	return 0;
}



Measured memory_bytes: 256
M=10**9+7
Tinv=(M+1)/2
n,*as=$<.read.split.map &:to_i
s1=as.reduce(0){|s,a| (s+a)%M }
s2=as.reduce(0){|s,a| (s+a*a)%M }
puts (s1*s1-s2)*Tinv%M

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


int main() {
  string s;
  cin>>s;
  int n=s.size();
  for(int i=0;i<n-1;i++){
    string  t=s.substr(i,2);
    if(t[0]==t[1]){
      cout<<i+1<<" "<<i+2<<endl;
      return 0;
    }
  }

  for(int i=0;i<n-2;i++){
    string  t=s.substr(i,3);
    if(t[0]==t[1]||t[1]==t[2]||t[2]==t[0]){
      cout<<i+1<<" "<<i+3<<endl;
      return 0;
    }
  }

cout<<-1<<" "<<-1<<endl;

}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define inf 1e9+3
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	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] = inf;
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j <= i + k; j++){
			if(j < n)
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 4368
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
map<string,string>ma;
set<int > s;
multiset<string> :: iterator it;

deque <char> q ;
ll ar [55100];
int main()
{
    fast;
     int n,k,x,y;
     cin>>n>>k>>x>>y;
     int ans= 0;
     for(int i=0;i<n;i++)
     {
         if(k)
         {
             ans+=(x);
             k--;
         }
         else
            ans+=y;
     }
     cout<<ans<<endl;

}




Measured memory_bytes: 256
public class Main{
    public static void main(String[] args){
	java.util.Scanner sc = new java.util.Scanner(System.in);
	int S = sc.nextInt();

	int h = S/3600;
	int m = S%3600/60;
	int s = S%3600%60;
	System.out.println(h+":"+m+":"+s);	
    }
}



Measured memory_bytes: 26276
#include<bits/stdc++.h>
using namespace std; 
int a,b,c,d,e,ans,x;
int main(){
    cin>>a>>b>>c>>d>>e;
    ans+=a+b+c+d+e;
    if(a%10!=0) ans+=10-a%10,x=max(10-a%10,x);
    if(b%10!=0) ans+=10-b%10,x=max(10-b%10,x);
    if(c%10!=0) ans+=10-c%10,x=max(10-c%10,x);
    if(d%10!=0) ans+=10-d%10,x=max(10-d%10,x);
    if(e%10!=0) ans+=10-e%10,x=max(10-e%10,x);
    cout<<ans-x;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define fo(n) for(int i = 0;i < int(n);i++)
#define foo(a,b) for(int i = int(a);i <= int(b);i++)
#define mk make_pair
#define pb push_back
#define MAXN 3000
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define fastio ios_base:: sync_with_stdio(false)

ll dp[MAXN][MAXN];
vector<ll> arr(MAXN);

ll sol(int l,int r){
	if(l > r) return 0;


	if(dp[l][r] != -1) return dp[l][r];

	ll lf = arr[l] + min(sol(l+2,r),sol(l+1,r-1));
	ll rf = arr[r] + min(sol(l+1,r-1),sol(l,r-2));

	dp[l][r] = max(lf,rf);
	return dp[l][r];
}


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

	fo(n) cin >> arr[i];

	memset(dp,-1,sizeof(dp));
	ll ans = sol(0,n-1);

	ll sum = 0;
	fo(n) sum += arr[i];

	cout << 2*ans - sum << endl; 

	return 0;
 }	

Measured memory_bytes: 70784
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll quickmod(ll a,ll b,ll c)
{
    ll res=1;
    while(b)
    {
        if(b&1) res=res*a%c;
        a=a*a%c;
        b>>=1;
    }
    return res;
}
bool flag=0;
int cnt[100100];
int main()
{
    int n;
    cin>>n;
    int x;
    if(n%2)
    {
        cnt[0]=1;
        for(int i=0;i<n;i++)
        {
            cin>>x;
            if(flag)continue;
            if(x>n||x%2||(++cnt[x/2])>2){flag=1;continue;}
        }
        if(flag)cout<<0<<endl;
        else cout<<quickmod(2,n/2,mod)<<endl;
    }else
    {
        for(int i=0;i<n;i++)
        {
            cin>>x;
            if(flag)continue;
            if(x>=n||!(x%2)||(++cnt[x/2])>2){flag=1;continue;}
        }
        if(flag)cout<<0<<endl;
        else cout<<quickmod(2,n/2,mod)<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
n=int(input())
if n==0:
    print(0)
    exit()
ans=''
for i in range(50):
    if n%(2**(i+1))!=0:
        n-=(-2)**i
        ans='1'+ans
    else:
        ans='0'+ans
    if n==0:
        break
if ans[0]!='0':
    print(ans)
else:
    print(ans[1:])


Measured memory_bytes: 62000
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	cout << "Christmas";
	while (n++ < 25) cout << " Eve";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
using namespace std;
template <class data_t>
class dice{
	int comp_dice_spin(dice<data_t> d2);
public:
	vector<data_t> field;
	dice(vector<data_t> v);
	void roll(char ch);
	data_t top(){return field[0];}
	int comp_dice_type(dice<data_t> d2);
	int comp_dice(dice<data_t> d2);
	void levorotation_spin(){roll('W');roll('N');roll('E');}
};
template <class data_t>
dice<data_t>::dice(vector<data_t> v){
	typename vector<data_t>::iterator vi = v.begin();
	while(vi!=v.end()){
		field.push_back(*vi);
		vi++;
	}
}
template <class data_t>
void dice<data_t>::roll(char ch){
	data_t tmp;
	switch(ch){
		case 'E':
			tmp = field[0];
			field[0] = field[3];
			field[3] = field[5];
			field[5] = field[2];
			field[2] = tmp;
			break;
		case 'N':
			tmp = field[0];
			field[0] = field[1];
			field[1] = field[5];
			field[5] = field[4];
			field[4] = tmp;
			break;
		case 'S':
			tmp = field[0];
			field[0] = field[4];
			field[4] = field[5];
			field[5] = field[1];
			field[1] = tmp;
			break;
		case 'W':
			tmp = field[0];
			field[0] = field[2];
			field[2] = field[5];
			field[5] = field[3];
			field[3] = tmp;
			break;
	}
	return;
}
template <class data_t>
int dice<data_t>::comp_dice(dice<data_t> d2){
	int c;
	for(c=0;c<6;c++){
		if(field[c] != d2.field[c]){
			return field[c] - d2.field[c];
		}
	}
	return 0;
}
template <class data_t>
int dice<data_t>::comp_dice_type(dice<data_t> d2){
	if(comp_dice_spin(d2) == 0)return 0;
	roll('N');
	if(comp_dice_spin(d2) == 0)return 0;
	roll('E');
	if(comp_dice_spin(d2) == 0)return 0;
	roll('E');
	if(comp_dice_spin(d2) == 0)return 0;
	roll('E');
	if(comp_dice_spin(d2) == 0)return 0;
	roll('N');
	if(comp_dice_spin(d2) == 0)return 0;
	return -1;
}
template <class data_t>
int dice<data_t>::comp_dice_spin(dice<data_t> d2){
	int i;
	for(i=0;i<4;i++){
		if(comp_dice(d2) == 0)
			return 0;
		levorotation_spin();
	}
	return -1;
}
int main(){
	vector<int> v(6);
	cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4]>> v[5];
	dice<int> d1(v);
	cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4]>> v[5];
	dice<int> d2(v);
	if(d1.comp_dice_type(d2) == 0){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin >> a >> b;
	if(a%3==0 || b%3==0 || (a+b)%3==0){
		cout << "Possible" << endl;
	}
	else{
		cout << "Impossible" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    string s, t; cin>>s>>t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    if(s<t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{




	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		String S = sc.next();
		StringBuilder sb = new StringBuilder(S);
		while(true){

			if(sb.length() == 0){					//文字数が0で完了
				System.out.println("YES");
				return;
			}

			if(sb.length() < 5){					//文字数が5以下はありえない
				System.out.println("NO");
				return;
			}

			if(sb.length() >= 7){
				if(sb.substring(sb.length()-7,sb.length()).equals("dreamer")){
				//	System.out.println("dreamer");
					sb.delete(sb.length()-7,sb.length());
					continue;

				}
			}
			if(sb.length() >= 6){
				if(sb.substring(sb.length()-6,sb.length()).equals("eraser")){
				//	System.out.println("eraser");
					sb.delete(sb.length()-6,sb.length());
					continue;
				}
			}
			if(sb.length() >= 5){
				if(sb.substring(sb.length()-5,sb.length()).equals("dream")){
					sb.delete(sb.length()-5,sb.length());
					continue;
				}else if(sb.substring(sb.length()-5,sb.length()).equals("erase")){
					sb.delete(sb.length()-5,sb.length());
					continue;
				}
			}

			System.out.println("NO");
			return;


		}

	}
}

class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 28512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int X = scan.nextInt();
        int N = scan.nextInt();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < N; i++) {
            set.add(scan.nextInt());
        }
        int diff = Integer.MAX_VALUE;
        int ans = -1;
        for (int i = 0; i <= 101; i++) {
            if (set.contains(i)) {
                continue;
            }
            int t = Math.abs(i - X);
            if (t < diff) {
                ans = i;
                diff = t;
            }
        }
        System.out.println(ans);
    }
}


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

int main(){
    int n,x; cin>>n>>x;
    vector<int> l(n);
    for(int i=0;i<n;i++) cin>>l[i];
    int t[n+1]; t[0]=0;
    for(int i=1;i<n+1;i++){
        t[i]=t[i-1]+l[i-1];
    }
    int ans=n+1;
    //for(int i=0;i<n+1;i++) cout<<t[i]<<endl;
    for(int i=0;i<n+1;i++){
        if(t[i]>x){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

#define MAX 10000
int main(void)
{
  int a[MAX];
  int i,j;

  for(i=0;i<MAX;i++)
    {
      scanf("%d",&a[i]);
      if(a[i]==0)
	break;
    }
  for(j=0;j<i;j++)
    {
      printf("Case %d: %d\n",j+1,a[j]);
    }
}



Measured memory_bytes: 2024
import math
inf = input().split()  #ABHM
theta = (int(inf[2])-int(inf[3])*11/60)*math.pi/6
print((float(inf[0])**2 + float(inf[1])**2 - 2*float(inf[0])*float(inf[1])*math.cos(theta))**(1/2))

Measured memory_bytes: 9516
#include <stdio.h>

int main() {
    char s[4];
    
    scanf("%s", s);
    int a = 0;
    for (int i = 0; i < 3; ++i){
        if (s[i] == '7')
            a = 1;
    }
    if (a == 0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 1660