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

using namespace std;

const int maxn=2e5;
const long long INF = 1e18;

int n;
int A[maxn+5];

long long my_abs(long long x)
{
	return (x>0)?x:-x;
}

void solve()
{
	long long sum=0;
	long long ans=INF;
	
	for (int i=1;i<=n;++i)
	{
		scanf("%d",&A[i]);
		sum=sum+A[i];
	}
	
	long long cnt=0;
	for (int i=1;i<=n-1;++i)
	{
		cnt=cnt+A[i];
		ans=min(ans,my_abs(sum-2*cnt));
	}
	printf("%lld\n",ans);
}

int main(void)
{
	#ifdef ex
	freopen ("std.in","r",stdin);
	#endif
	
	while (scanf("%d",&n)==1)
	{
		solve();
	}
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
	int a,b,c,tmp;
	scanf("%d %d %d",&a,&b,&c);
	if(a > b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	if(b > c)
	{
		tmp = b;
		b = c;
		c = tmp;
	}
	if(a > b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 596
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] walls = new char[h][w];

        for (int i = 0; i < h; i++){
            String str = sc.next();
            char[]  row = str.toCharArray();
            walls[i] = row;
        }

        int[][] lefts = new int[h][w];
        int[][] rights = new int[h][w];
        int[][] ups = new int[h][w];
        int[][] downs = new int[h][w];

        int maxHeightIndex = h - 1;
        int maxWidthIndex = w - 1;

        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++){
                if (walls[i][j] == '#'){
                    lefts[i][j] = 0;
                    ups[i][j] = 0;
                }else {
                    if (i == 0){
                        ups[i][j] = 1;
                    }else {
                        ups[i][j] = ups[i - 1][j] + 1;
                    }

                    if (j == 0){
                        lefts[i][j] = 1;
                    }else {
                        lefts[i][j] = lefts[i][j - 1] + 1;
                    }
                }

                if (walls[maxHeightIndex - i][maxWidthIndex - j] == '#'){
                    downs[maxHeightIndex - i][maxWidthIndex - j] = 0;
                    rights[maxHeightIndex - i][maxWidthIndex - j] = 0;
                }else {
                    if (i == 0){
                        downs[maxHeightIndex - i][maxWidthIndex - j] = 1;
                    }else {
                        downs[maxHeightIndex - i][maxWidthIndex - j] = downs[maxHeightIndex - (i - 1)][maxWidthIndex - j] + 1;
                    }

                    if (j == 0){
                        rights[maxHeightIndex - i][maxWidthIndex - j] = 1;
                    }else {
                        rights[maxHeightIndex - i][maxWidthIndex - j] = rights[maxHeightIndex - i][maxWidthIndex - (j - 1)] + 1;
                    }

                }

            }
        }

        int max = 0;
        int candidate = 0;

        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++){
                candidate = lefts[i][j] + rights[i][j] + ups[i][j] + downs[i][j] - 3;
                if (candidate > max){
                    max = candidate;
                }
            }
        }

        System.out.println(max);
    }

}

Measured memory_bytes: 142212
#include<bits/stdc++.h>
using namespace std;
pair<long long,long long> a[100000];
long long n,m,c,r;
int main()
{
	cin>>n>>m;
	for (int i=0;i<n;i++)
	  scanf("%I64d%I64d",&a[i].first,&a[i].second);
	sort(a,a+n);
	int i=0;
	while(c+a[i].second<m)
	{
		r+=a[i].first*a[i].second;
		c+=a[i++].second;
	}
	cout<<r+(m-c)*a[i].first<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  ll x,k,d;
  cin >> x >> k >> d;
  x = abs(x);
  ll a = x/d;
  ll ans = x - a * d;
  if (a >= k) {
    cout << x-d*k << endl;
  }
  else {
    ll rem = k-a;
    if (rem%2 == 0) cout << ans << endl;
    else {
      /*ll now = abs(ans-d);
      ans = min(ans, now);
      cout << ans << endl;*/
      cout << abs(ans-d) << endl;
    }
  }
  return 0;
}

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

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<int> A(N), B(N);
	std::vector<std::pair<int, int>> num(N + 1);
	for (int i{}; i <= N; i++)
		num[i].second = i;
	num.reserve(2 * N);
	for (auto& e: A)
	{
		scanf("%d", &e);
		num[e].first++;
	}
	for (auto& e: B)
	{
		scanf("%d", &e);
		num[e].first++;
	}
	std::sort(num.rbegin(), num.rend());
	if (num.front().first > N)
	{
		puts("No");
		return 0;
	}
	puts("Yes");
	std::reverse(B.begin(), B.end());
	
	int change{};
	for (int i{}; i < N; i++)
	{
		if (A[i] != B[i]) continue;
		while (A[change] == A[i] || B[change] == A[i])
			change++;
		std::swap(B[i], B[change]);
		change++;
	}
	for (int i{}; i < N; i++)
		printf("%d%c", B[i], i + 1 == N? '\n': ' ');

	return 0;
}

Measured memory_bytes: 8008
<?php
fscanf(STDIN, "%d" ,$n);
fscanf(STDIN, "%d" ,$k);
$double = 0;
$sum    = 0;
$ans    = 1;
for ($i=0;$i<$n;$i++) {
	$double = $ans * 2;
	$sum    = $ans + $k;
	if ($double < $sum) {
		$ans = $double;
	}else {
		$ans = $sum;
	}
}
echo $ans;

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  vector<vector<int>> V;
  vector<int> v1;
  vector<int> v2;
  vector<int> v3;
  vector<int> v4;
  V.push_back(v1);
  V.push_back(v2);
  V.push_back(v3);
  V.push_back(v4);

  rep(i, 3) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }

  for (vector<int> v : V) {
    if (v.size() >= 3) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a[] = sc.next().split("");
        List<String> alist = new ArrayList<>();
        for(int i = 0;i < a.length;i++){
         alist.add(a[i]);
        }
      
        String b[] = sc.next().split("");
        List<String> blist = new ArrayList<>();
        for(int i = 0;i < b.length;i++){
         blist.add(b[i]);
        }
        String c[] = sc.next().split("");
        List<String> clist = new ArrayList<>();
        for(int i = 0;i < c.length;i++){
         clist.add(c[i]);
        }
      
      
        String check = "a";
      
       try{
          while(true){
          if(check.equals("a")){
            check = (String)alist.get(0);
            alist.remove(0);
          }else if(check.equals("b")){
            check = (String)blist.get(0);
            blist.remove(0);
          }else if(check.equals("c")){
            check = (String)clist.get(0);
            clist.remove(0);
          }
          }
        }catch(Exception e){
          
          System.out.println(check.toUpperCase());
        }
        
      
    }
}

Measured memory_bytes: 35892
#[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 ( 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 , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ 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" ) } ; }

fn main() {
    input! {
        k: u64, s: u64
    }

    let mut cnt = 0;
    for x in 0..s+1 {
        for y in 0..s+1-x {
            let z = s - (x + y);
            if x <= k && y <= k && z <= k {
                cnt += 1;
            }
        }
    }
    println!("{}", cnt);
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long long p10[20];
long long calc(int a,int b,int c,long long d){
	if(b>c){
		if(d==0)return 1;
		else return 0;
	}
	if(b==c){
		if(d==0)return 10;
		else return 0;
	}
	if(ABS(d)>=p10[c+1])return 0;
	long long ret=0;
	for(int i=-10;i<10;i++){
		int ks=10-ABS(i);
		if(b==0&&i>=0)ks--;
		ret+=calc(a,b+1,c-1,d-i*(p10[c]-p10[b]))*ks;
	}
	return ret;
}
int main(){
	p10[0]=1;
	for(int i=1;i<20;i++)p10[i]=p10[i-1]*10;
	int a;scanf("%d",&a);
	long long ret=0;
	for(int i=2;i<=18;i++){
		ret+=calc(i,0,i-1,a);
	//	printf("%d\n",ret);
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
	int s;
	cin >> s;
	int count = 1;
	if(s==2 || s==1){
		s=4;
		count = 1;
	}
	while(s!=4){
		if(s%2==0) s/=2;
		else s = 3*s + 1;
		++count;
	}
	cout << count+3 << endl;
}

Measured memory_bytes: 256
// AOJ 2473 Poor Computer
// 2018.2.1 bal4u

#include <stdio.h>
#include <string.h>

#define HSIZ 12007
long long hash[HSIZ+5], *hashend = hash + HSIZ;

int lookup(long long n)
{
	long long *p = hash + (int)(n % HSIZ);
	while (*p) {
		if (*p == n) return 0;
		if (++p == hashend) p = hash;
	}
	*p = n;
	return 1;
}

#define MAX 42

typedef struct { long long s; int k; } Q;
Q q[10000]; int top;

int lim;
long long goal;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int bitcount64(long long x)
{
	x = ((x & 0xAAAAAAAAAAAAAALL) >>  1) + (x & 0x55555555555555LL);
	x = ((x & 0xCCCCCCCCCCCCCCLL) >>  2) + (x & 0x33333333333333LL);
	x = ((x & 0xF0F0F0F0F0F0F0LL) >>  4) + (x & 0x0F0F0F0F0F0F0FLL);
	x = ((x & 0x00FF00FF00FF00LL) >>  8) + (x & 0xFF00FF00FF00FFLL);
	x = ((x & 0xFF0000FFFF0000LL) >> 16) + (x & 0x00FFFF0000FFFFLL);
	x = ((x & 0xFFFFFF00000000LL) >> 32) + (x & 0x000000FFFFFFFFLL);
	return (int)x;
}

int trailingZero(long long x)
{
#if 0
	int k = 0;
	while (!(x & 1)) k++, x >>= 1;
	return k;
#endif
	return bitcount64(~x & (x-1));
}

int check()
{
	int i, j, k, t;
	long long s, ss, s1, s2;

	memset(hash, 0, sizeof(hash));
	q[0].s = 2, q[0].k = 0, top = 1;
	while (top) {
		s = q[--top].s, k = q[top].k;

		if ((s & goal) == goal) return 1;
		if (k + bitcount64(goal & ~s) > lim) continue;

		for (s1 = s; s1; s1 &= s1-1) {
			i = trailingZero(s1);
			for (s2 = s; s2; s2 &= s2-1) {
				j = trailingZero(s2);

				t = i+j;
				if (t <= MAX && !((s >> t) & 1)) {
					if (lookup(ss = s | (1LL << t))) q[top].s = ss, q[top++].k = k+1;
				}

				t = i-j; if (t < 0) t = -t;
				if (t > 0 && !((s >> t) & 1)) {
					if (lookup(ss = s | (1LL << t))) q[top].s = ss, q[top++].k = k+1;
				}
			}

			while (i < MAX) {
				if (!((s >> i) & 1)) {
					if (lookup(ss = s | (1LL << i))) q[top].s = ss, q[top++].k = k+1;
				}
				i <<= 1;
			}
		}
	}
	return 0;
}

int main()
{
	int n;

	lim = n = in();
	while (n--) goal |= 1LL << in();
	while (!check()) lim++;
	printf("%d\n", lim);
	return 0;
}


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

vector<pair<int, char>> A;

int partition (int p, int r) {
  int x = A[r].first;
  int i = p - 1;
  for (int j = p; j < r; j++) {
    if (A[j].first <= x) {
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i + 1;
}

void quicksort(int p, int r) {
  if (p < r) {
    int q = partition(p, r);
    quicksort(p, q - 1);
    quicksort(q + 1, r);
  }
}

int main() {

  int n;
  cin >> n;

  A.resize(n);

  for (int i = 0; i < n; i++) {
    cin >> A[i].second >> A[i].first;
  }

  map<int, string> m1;
  map<int, string> m2;

  for (int i = 0; i < n; i++) {
    m1[A[i].first] += A[i].second;
  }

  quicksort(0, n - 1);

  for (int i = 0; i < n; i++) {
    m2[A[i].first] += A[i].second;
  }

  bool flg = true;

  for (int i = 0; i < n; i++) {
    if (m1[A[i].first] != m2[A[i].first]) {
      flg = false;
      break;
    }
  }

  if (flg) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  for (int i = 0; i < n; i++) {
    cout << A[i].second << " " << A[i].first << endl;
  }

  return 0;

}


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

#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define INF (1LL << 30)
#define pii pair<int, int>
#define MOD 1000000007
#define print(x) cout<<(x)<<endl
using namespace std;


int dif(int a, int b){
    if (a>b){
        return abs(a-b);
    }
    else return abs(b-a);
}

int cald(pii a, pii b){
    return dif(a.first,b.first)+dif(a.second,b.second);
}

pii pdif(pii a, pii b){
    return make_pair(dif(a.first,b.first),dif(a.second,b.second));
}

vector<pii> lst(90002);
//int A[301][301];
signed main()
{
    int H,W,D;
    cin>>H>>W>>D;


    int tmp;
    rep(i,H){
        rep(j,W){
            scanf("%d", &tmp);
            lst[tmp] = make_pair(dif(i,-1),dif(j,-1));
        }
    }

    int Q;
    cin>>Q;
    int l,r;


    vector<int> rs(90002);
    rep(i,90002){
        if (i-D >= 0)
        rs[i] = rs[i-D] + cald(lst[i],lst[i-D]);
    }


    rep(i,Q){
        scanf("%d%d",&l,&r);
        int ans = 0;
        int z = l;
        /*
        while(z != r){
            ans ;
            z += D;
        }
        */
       ans = rs[r] - rs[l];
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 2176
n = int(input())
L = [None]+list(input().split())
even = []
odd = []
if n % 2 == 0:
    for i in range(1,1+n):
        if i % 2 == 0:
            even.append(L[i])
        else:
            odd.append(L[i])
    ans = even[::-1] + odd
else:
    for i in range(1,1+n):
        if i % 2 == 0:
            even.append(L[i])
        else:
            odd.append(L[i])
    ans = odd[::-1] + even
for i in range(n):
    if i == n - 1:
        print(ans[i])
    else:
        print(ans[i],end=' ')

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

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, 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 ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

vector<ll> enum_divisors(ll N){
  vector<ll> res;
  for (ll i = 1; i * i <= N; ++i){
    if (N % i == 0) {
      res.push_back(i);
      //重複しない時
      if (N / i != i) res.push_back(N / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

int main(){
  int N; cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i += 2){
    vector<ll> vec = enum_divisors(i);
    if ((int)vec.size() == 8) ans++;
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

typedef pair<ll, ll> P;

ll DP[7100][7100][2];

int main(){
    ll N, T;
    cin >> N >> T;
    vector<P> AB(N);
    REP(i,N){
        ll a, b;
        cin >> a >> b;
        AB[i] = P(b, a);
    }

    //sort(AB.begin(), AB.end());

    REP(i,3100){
        REP(j,3100) {
            DP[i][j][0] = DP[i][j][1] = -1e16;
        }
    }
    DP[0][0][0] = 0;

    REP(i,N){
        auto p = AB[i];
        ll a = p.second;
        ll b = p.first;
        REP(j,3010){
            chmax(DP[i+1][j][0], DP[i][j][0]);
            chmax(DP[i+1][j+a][0], DP[i][j][0] + b);
            chmax(DP[i+1][j][1], DP[i][j][0] + b);

            chmax(DP[i+1][j][1], DP[i][j][1]);
            chmax(DP[i+1][j+a][1], DP[i][j][1] + b);
        }
    }

    ll ans = 0;
    REP(j,T){
        chmax(ans, DP[N][j][1]);
    }

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


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

void Main() {
    int H, W;
    cin >> H >> W;
    vector<string> c(H);
    for (auto& s : c) {
        cin >> s;
    }
    for (int i = 0; i < W + 2; i++) {
        cout << "#";
    }
    cout << endl;
    for (auto& s : c) {
        cout << "#" << s << "#" << endl;
    }
    for (int i = 0; i < W + 2; i++) {
        cout << "#";
    }
    cout << endl;
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <limits>
//#include "./libb/lib.hpp"

using namespace std;

int main()
{
    uint64_t xx;
    uint64_t yk = 100;
    uint64_t year = 0;
    uint64_t tempf = 0;
    cin >> xx;


    //cout << "xx is " << xx << endl;
    //year = year + tempf;
    //cout << "year is " << year << endl;
    //yk = 100 * (pow(1.01, year));

    while(yk < xx){
        yk += yk / 100;
        year++;
    }

    cout << year << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) repi(i, 0, n)
#define rep1(i, n) repi(i, 1, n + 1)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)

typedef long long ll;

int main()
{
    ll n, m;
    cin >> n >> m;
    if (n == 1) {
        cout << m << endl;
        return 0;
    }
    ll max = 1;
    for (ll i = 2; i < 1e9; i++) {
        ll r = m - i * (n - 1);
        if (r < i) break;
        if (r % i == 0) max = i;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
import math
import sys
n = int(input())
li = list(map(int, input().split()))
for i in li:
    if (i % 2 == 1):
        continue
    else:
        if (i % 3 != 0 and i % 5 != 0):
            print('DENIED')
            sys.exit()
print('APPROVED')

Measured memory_bytes: 3060
n = int(input())
b = list(map(int, input().split()))
ans = [0] * n
ans[0] = b[0]
ans[1] = b[0]
for i in range(1, n - 1):
    ans[i] = min(ans[i], b[i])
    ans[i + 1] = b[i]
print(sum(ans))


Measured memory_bytes: 3060
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 210000;

int n,K;
int q[maxn<<2],head,tail,flag;
char str[maxn];

int main()
{
	scanf("%d%d",&n,&K);
	scanf("%s",str);
	head=1,tail=n;
	for(int i=1;i<=n;i++) q[i]=str[i-1]=='A'?1:0;
	
	int now=0; flag=0;
	for(;now<=2*n;now++)
	{
		if(now==K) break;
		if(q[head]^flag) q[head]=flag;
		else flag=!flag,head++,q[++tail]=!flag;
	}
	if(now<K&&n%2)
	{
		if(q[head]^flag) ++now,q[head]=flag;
		if(now<K&&(K-now)%2) q[head]=!flag;
	}
	for(int i=head;i<=tail;i++) printf("%c",(q[i]^flag)?'A':'B');
	puts("");
	
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>

using ll = long long;


int main() {
    int N, M;
    std::cin >> N >> M;
    //i番目のスイッチのつけられる電球の番号
    std::vector<std::vector<int>> k(N);

    for (int i = 0; i < M; i++) {
        int p;
        std::cin >> p;

        for (int j = 0; j < p; j++) {
            int in;
            std::cin >> in;
            in--;
            k[in].emplace_back(i);
        }
    }


    std::vector<int> m(M);
    for (int i = 0; i < M; i++) {
        int p;
        std::cin >> p;
        if (p == 1) {
            m[i]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < (1 << N); i++) {
        std::vector<int> cm(m);
        for (int j = 0; j < N; j++) {
            int l = (i >> j) & 1;
            if (l == 0)continue;
            for (int i = 0; i < k[j].size(); i++) {
                cm[k[j][i]]++;
            }
        }
        bool flag = true;
        for (int j = 0; j < M; j++) {
            if (cm[j] % 2 == 1) {
                flag = false; break;
            }
        }
        if (flag) {
            ans++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc134/tasks/abc134_d
# よくわからん本当に緑diff?
# とりあえずエラトステネスの篩のように倍数を列挙する感じでほぼ愚直にやる
# N/2以上の整数に関しては即座に答えが決まる。
# 答えが決まった部分より下を引いていけば良いのでは？

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
A = [0] + read_ints()

B = [0] * (N + 1)
B[(N // 2) + 1:] = A[(N // 2) + 1:]


for i in range(N // 2, 0, -1):
    a = A[i]
    j = i + i
    while j < N + 1:
        a -= B[j]
        j += i
    B[i] = a % 2
# print(B)


print(sum(B))
for i, b in enumerate(B):
    if b:
        print(i, end=' ')


Measured memory_bytes: 65400
#include <bits/stdc++.h>
#define fi first
#define se second 
using namespace std;
using ll = long long;

constexpr int N = 15;
int n;
vector<vector<pair<int, int>>> test(N);


bool ok(int msk) {
  for(int i = 0; i < n; ++i) {
    if((1 << i) & msk) {
      bool fine = true;
      for(auto t : test[i]) {
        int j = ((1 << t.fi) & msk) > 0;
        fine &= j == t.se;
      }
      if(!fine) return false;
    }
  }
  return true;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int q;
    cin >> q;
    while(q--) {
      int x, y;
      cin >> x >> y;
      test[i].push_back({x - 1, y});
    }
  }

  int ans = 0;
  for(int msk = 0; msk < (1 << n); ++msk) {
    if(ok(msk)) {
      ans = max(ans, __builtin_popcount(msk));
    }
  }
  cout << ans << '\n';

}


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

using  namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> a;
    vector<int> b;
    vector<int> c;
    for(int i=0;i<n;i++){
        int in;
        cin>>in;
        a.push_back(in);
    }
        for(int i=0;i<n;i++){
        int in;
        cin>>in;
        b.push_back(in);
    }
        for(int i=0;i<n-1;i++){
        int in;
        cin>>in;
        c.push_back(in);
    }
        int sum=0;
        for(int i=0;i<n;i++){
        if(i>=1 && a[i]==a[i-1]+1){
            sum=sum+b[a[i]-1]+c[a[i-1]-1];
        }
        else{
            sum=sum+b[a[i]-1];
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
import math

A, B, H, M= map(float, input().split())

angle= (2* math.pi* H/ 12+ 2* math.pi/ 12* M/ 60)- 2* math.pi* M/ 60

C= A** 2+ B** 2- 2* A* B* math.cos(angle)

print(math.sqrt(C))

Measured memory_bytes: 9356
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

void solve()
{
	/*--------------------------*/

	const int mody = 2019;
	int L, R; cin >> L >> R;
	int ans = INF, f = 1;
	repi(i, L, R) {
		repi(j, i + 1, R + 1) {
			ans = min(ans, (i * j) % mody);
			if (!(ans)) {
				f = 0; break;
			} 
		}
		if (!(f)) break;
	}
	cout << ans << endl;

	/*--------------------------*/
}

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

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <functional>
using namespace std;

typedef long long ll;

int K;
priority_queue<ll, vector<ll>, greater<ll> > Q;

void input_init(void) {
	cin >> K;
	for (ll i = 1; i <= 9; ++i)
		Q.push(i);
}

ll solve(void) {
	ll val = -1;
	int cnt = 0;
	while (true) {
		val = Q.top();
		Q.pop();
		++cnt;
		if (cnt >= K)
			break;
		ll a = val % 10;
		for (int i = -1; i <= 1; ++i) {
			ll b = a + (ll)i;
			if (b >= (ll)0 && b <= (ll)9) {
				ll new_val = val * 10 + b;
				Q.push(new_val);
			}
		}
	}
	return val;
}

int main(void) {
	input_init();
	ll ans = solve();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 2420
#include<iostream>
using namespace std;
int gcd(int a, int b) {
  while(b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main () {
  int K;
  cin >> K;
  int ans = 0;
  for (int a = 1; a <= K; a ++) {
    for (int b = 1; b <= K; b ++) {
      for (int c = 1; c <= K; c ++) {
        ans += gcd(gcd(a, b), c);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 1e5 + 5;

int N;
LL A[MAXN];

void input()
{
    read(N);
    for (int i = 1; i <= N; ++i) {
        read(A[i]);
    }
}

void solve()
{
    std::sort(A + 1, A + N + 1);

    static LL S[MAXN];

    for (int i = 1; i <= N; ++i) {
        S[i] = S[i-1] + A[i];
    }
    for (int j = N; j >= 1; --j) {
        if (S[j-1] * 2 < A[j]) {
            printf("%d\n", N - j + 1);
            break;
        }
    }
}

int main()
{
#ifdef __DEBUG
    freopen("B.in", "r", stdin);
    freopen("B.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}

// 日暮苍山远，天寒白屋贫。
//     -- 刘长卿《逢雪宿芙蓉山主人》


Measured memory_bytes: 1792
#include <stdio.h>
#include <cmath>
#include <algorithm>

int main(){
	int n,tmp,count = 0,limit;
	scanf("%d",&n);

	for(int i = 0; i < n; i++)
	{
		scanf("%d",&tmp);
		limit = sqrt(tmp);
		for(int j = 2; j <= limit; j++){
			if(tmp%j==0){
				count++;
				break;
			}
		}
	}
	printf("%d\n",n-count);
}

Measured memory_bytes: 1028
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=5007;
const ll inf=1e18;

int n;
ll wl, wp;

int tab[nax];

ll dp[nax];

int main()
{
	scanf("%d%lld%lld", &n, &wp, &wl);
	for (int i=1; i<=n; i++)
		scanf("%d", &tab[i]);
	tab[n+1]=n+1;
	for (int i=1; i<=n+1; i++)
		dp[i]=inf;
	for (int i=0; i<=n; i++)
	{
		int naj=n+7;
		int mniej=0;
		for (int j=i+1; j<=n+1; j++)
		{
			if (tab[j]<tab[i])
				mniej++;
			if (tab[j]<naj && tab[j]>tab[i])
			{
				naj=tab[j];
				dp[j]=min(dp[j], dp[i]+(j-i-1-mniej)*wp+mniej*wl);
			}
			//~ debug() << i << " " << j << " " << mniej;
		}
	}
	debug() << range(dp, dp+2+n);
	
	
	printf("%lld\n", dp[n+1]);
	return 0;
}


Measured memory_bytes: 256
def main() -> None:
    S = [1 if s == "R" else -1 for s in input()]
    N = len(S)
    ans = [0] * N
    for i in range(N-1):
        if S[i] == 1 and S[i+1] == -1:
            left, right = i, i+1
            while left >= 0 and S[left] == 1:
                ans_idx = i if (i - left) % 2 == 0 else i+1
                ans[ans_idx] += 1
                left -= 1
            while right < N and S[right] == -1:
                ans_idx = i+1 if (right - i - 1) % 2 == 0 else i
                ans[ans_idx] += 1
                right += 1
    print(*ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7080
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int a, b, n;
    cin >> n >> a >> b;
    int memo = b, m = n;
    if(a + b > n + 1){
    	cout << -1 << endl;
    	return 0;
    }
    vector<int> ans;
    for(int i=n-a+1;i<=n;i++) ans.pb(i);
    b--;
    n -= a;
    while(n > 0){
    	if(n - a < b - 1){
    		if(n == b) while(n) ans.pb(n), n--;
    		else{
    			int num = max(1, n - a + 1);
    			int count = 1;
    			for(int i=num;i<=n;i++, count++){
    				ans.pb(i);
    				if(n - count == b){
    					while(n > 0) {
    						if(n == i) n = num - 1;
    						else ans.pb(n), n--;
    					}
    					break;
    				}
    			}
    			n -= a;
    			b--;
    		}
    	}
    	else{
    		int num = max(n - a + 1, 1);
    		for(int i=num;i<=n;i++) ans.pb(i);
    		n = num - 1; b--;
    	}
    }
    vector<int> x, y;
    for(int i=0;i<ans.size();i++){
    	int id = lower_bound(be(x), ans[i]) - x.begin();
    	if(id == x.size()) x.pb(ans[i]);
    	else x[id] = ans[i];
    	int le = -1, ri = y.size(), mid;
    	while(ri - le > 1){
    		mid = (ri + le) / 2;
    		if(y[mid] > ans[i]) le = mid;
    		else ri = mid;
    	}
    	if(ri == y.size()) y.pb(ans[i]);
    	else y[ri] = ans[i];
    }

    if(int(x.size()) != a || int(y.size()) != memo || int(ans.size()) != m) cout << -1;
    else for(auto& i: ans) cout << i << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 5616
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

i = 0
for key in t:
  left = 0
  right = len(s)
  while left < right:
    mid = (left + right) // 2
    if key == s[mid]:
      i += 1
      break
    elif key < s[mid]:
      right = mid
    else:
      left = mid + 1
print (i)


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

ll ceil(ll a, ll b) {
    if (b < 0) {
        a *= -1;
        b *= -1;
    }
    if (a >= 0) {
        return (a + b - 1) / b;
    } else {
        return a / b;
    }
}

ll floor(ll a, ll b) {
    if (b < 0) {
        a *= -1;
        b *= -1;
    }
    if (a < 0) {
        return (a - b + 1) / b;
    } else {
        return a / b;
    }
}

int main() {
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    ll low = -1e18 - 10, high = 1e18 + 10;
    while (high - low > 1) {
        ll mid = (high + low) / 2;
        ll cnt = 0;
        for (int i = 0; i < N; i++) {
            if (A[i] == 0 && mid >= 0) {
                cnt += N;
            } else if (A[i] > 0) {
                cnt += upper_bound(A.begin(), A.end(), floor(mid, A[i])) - A.begin();
            } else if (A[i] < 0) {
                cnt += A.end() - lower_bound(A.begin(), A.end(), ceil(mid, A[i]));
            }

            if (A[i] * A[i] <= mid) {
                cnt--;
            }
        }
        cnt /= 2;

        if (cnt < K) {
            low = mid;
        } else {
            high = mid;
        }
    }
    cout << high << endl;
}


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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int ans = INF;
	for(int i = 0; i <= max(x, y); ++i){
		int sum = 0;
		sum += i * 2 * c;
	
		sum += a * max(x - i, 0);
		sum += b * max(y - i, 0);
	ans = min(ans, sum);
	}
	cout <<ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if(n == 1){
        if(a == b)cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    if(a > b){
        cout << 0 << endl;
        return 0;
    }
    ll ans = (n - 1) * (b - a) + a - b + 1;
    cout << ans << endl;
    
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 6010
#define maxm 500010
#define inf 1000000007
//#define mod 998244353
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,mod,ans;
int f[maxn][maxn*2],inv[maxn];
void add(int &x,int y)
{
    x=(x+y>=mod)?(x+y-mod):(x+y);
}
int main()
{
    n=read();mod=read();n*=3;
    inv[0]=inv[1]=1;
    for(int i=2;i<=n;i++)  inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
    f[0][n]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=-i;j<=i;j++)
        {
            if(!f[i][j+n])  continue;
            add(f[i+1][j+n+1],1ll*f[i][j+n]*inv[i+1]%mod);
            add(f[i+2][j+n-1],1ll*f[i][j+n]*inv[i+2]%mod);
            add(f[i+3][j+n],1ll*f[i][j+n]*inv[i+3]%mod);
        }
    }
    for(int i=n;i<=2*n;i++)  add(ans,f[n][i]);
    for(int i=1;i<=n;i++)  ans=1ll*ans*i%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 280064
n = int(input())
A = []
B = []
C = []
for i in range(n):
    a,b,c = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    
dp = [[0 for i in range(3)] for j in range(n)]

dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

for i in range(1,n):
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+A[i]
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+B[i]
    dp[i][2] = max(dp[i-1][0],dp[i-1][1])+C[i]

print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))

Measured memory_bytes: 80344
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  while(true) {
    int a, b, d;
    cin >> a >> b >> d;
    if(!a) break;

    int ansi = LLINF, ansj = LLINF;
    REP(i, 500000) {
      // a*i + d = b*j
      if((a*i+d)%b == 0) {
        int j = (a*i+d)/b;
        if(i+j < ansi + ansj || (i+j == ansi+ansj && i*a+j*b < ansi*a+ansj*b)) {
          ansi = i, ansj = j;
        }
      }
      // a*i + b*j = d
      if(d>=a*i && (d-a*i)%b == 0) {
        int j = (d-a*i)/b;
        if(i+j < ansi + ansj || (i+j == ansi+ansj && i*a+j*b < ansi*a+ansj*b)) {
          ansi = i, ansj = j;
        }
      }
      // a*i = b*j + d
      if(a*i>=d && (a*i-d)%b == 0) {
        int j = (a*i-d)/b;
        if(i+j < ansi + ansj || (i+j == ansi+ansj && i*a+j*b < ansi*a+ansj*b)) {
          ansi = i, ansj = j;
        }
      }
    }
    assert(ansi!=LLINF);
    cout << ansi << " " << ansj << endl;
  }

  return 0;
}



Measured memory_bytes: 3028
module Main where

import Data.Functor

main :: IO ()
main = do
  { [x] <- getInts
  ; putInts [x^3]
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords. map show

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int,int> P;

int main(){
      //declare
      int w,h,n,solve=0;
      P cheese[9];
      int dx[] = {0,1,-1,0},dy[]={1,0,0,-1};
      queue<P> que;
      cin >> h>> w>> n;
      char d[1005][1005];
      int dis[1005][1005];

      //input
      for(int i=0;i<h;i++)
      {
            for(int j=0;j<w;j++)
            {
                  cin>>d[i][j];
                  if('1'<=d[i][j]&&'9'>=d[i][j])
                        cheese[d[i][j]-'0'] = make_pair(i,j);
                  else if(d[i][j]=='S')
                        cheese[0] = make_pair(i,j);
            }
      }
      //for(int i = 0;i<n;i++)cout<<"cheese:"<<cheese[i].first<<' '<<cheese[i].second<<endl;

      //solve
      for(int i=0;i<n;i++)
      {
            queue<P> que;
            for(int a=0;a<h;a++)for(int b=0;b<w;b++)dis[a][b]=-1;
            dis[cheese[i].first][cheese[i].second]=0;
            que.push(cheese[i]);
            while(!que.empty())
            {
                  P p = que.front();que.pop();
                  if(p == cheese[i+1])// judge whether distination
                  {
                        solve += dis[p.first][p.second];
                        break;
                  }
                  for(int j = 0;j < 4;j++)
                  {
                        int nx = p.first + dx[j];
                        int ny = p.second+ dy[j];
                        if(0<=nx&&nx<h&&0<=ny&&ny<w&&d[nx][ny]!='X'&&dis[nx][ny]==-1)
                        {
                              dis[nx][ny] = dis[p.first][p.second]+1;
                              que.push(make_pair(nx,ny));
                        }

                  }
            }
            /*
            cout << endl;
            for(int i = 0;i<h;i++)
            {
                  for(int j= 0;j<w;j++)
                        cout << dis[i][j] << ' ';
                  cout<<endl;
            }
            cout << endl;
            */

      }
      cout << solve << endl;
}

Measured memory_bytes: 6148
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    string S; cin >> S;
    reverse(S.begin(), S.end());
    string T[4] = {"dream", "dreamer", "erase", "eraser"};
    rep(i, 4) reverse(T[i].begin(), T[i].end());
    rep(i, S.size()) {
        bool isMake = false;
        rep(j, 4) {
            bool ok = true;
            rep(k, T[j].size()) {
                if(S[i + k] != T[j][k]) ok = false;
            }
            if(ok) {
                i += T[j].size() - 1;
                isMake = true;
                break;
            }
        }
        if(!isMake) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 512
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n;
    int k;
    cin >> n >> k;
    ld ans = 0;
    for(int i = 1; i <= n; i++){
        int num = i;
        int cnt = 0;
        while(num < k){
            num *= 2;
            cnt++;
        }
        ans += (1.0 / (ld)n) * pow(0.5, (ld)cnt);
    }
    cout << fixed << setprecision(15) << ans << endl;

}   

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, a, b, s[2100][2100], cnt[2100];
int main() {
	cin >> n >> a >> b;
	a--;
	b--;
	REP(i, 2100) REP(j, 2100) if(i != j)s[i][j] = INF;
	s[a][b] = 1;
	s[b][a] = 1;
	REP(i, n - 1) {
		FOR(j, i + 1, n) {
			s[i][j] = j - i;
			s[j][i] = j - i;
		}
	}
	REP(k, 3) REP(i, n)REP(j, n)s[i][j] = min(s[i][j], s[i][a] + s[b][j] + 1);
	REP(k, 3) REP(i, n)REP(j, n)s[i][j] = min(s[i][j], s[i][b] + s[a][j] + 1);
	REP(i, n - 1) {
		FOR(j, i + 1, n) {
			cnt[s[i][j]]++;
		}
	}
	REPO(i, n - 1) {
		cout << cnt[i] << endl;
	}
}


Measured memory_bytes: 34688