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

using namespace std;

using ll = int;
constexpr ll mod = 1e9 + 7;

class FenwickTree2D
{
    // 2次元(M*N) 1-indexed BIT
    int M, N;
    // bit[x][y] = v[i][j] (Lx < i <= x, Ly < j <= y)
    // Lx = x - (x & -x), Ly = y - (x & -y)
    std::vector<std::vector<ll>> bit;

public:
    FenwickTree2D(int _m, int _n) : M(_m), N(_n), bit(M + 1, std::vector<ll>(N + 1, 0)) {}
    // v[a][b] += w
    void add(int a, int b, ll w)
    {
        for (int x = a; x <= M; x += x & -x)
            for (int y = b; y <= N; y += y & -y)
            {
                bit[x][y] += w;
                if (bit[x][y] >= mod)
                    bit[x][y] -= mod;
            }
    }
    // O(logM logN)
    ll sum(int a, int b)
    {
        ll ret = 0;
        for (int x = a; x > 0; x -= x & -x)
            for (int y = b; y > 0; y -= y & -y)
            {
                ret += bit[x][y];
                if (ret >= mod)
                    ret -= mod;
            }
        return ret;
    }
    // (i,j) (a <= i <= c,b <= j <= d) の長方形領域内の和
    ll sum(int a, int b, int c, int d)
    {
        ll ret = sum(c, d);
        ret = ret - sum(c, b - 1);
        if (ret < 0)
            ret += mod;
        ret = ret - sum(a - 1, d);
        if (ret < 0)
            ret += mod;
        ret += sum(a - 1, b - 1);
        if (ret >= mod)
            ret -= mod;
        return ret;
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    FenwickTree2D dp(n + 2, m + 2);
    dp.add(1, 1, 1);
    vector<int> s(n + 1, 0), t(m + 1, 0);
    for (int i = 1; i <= n; i++)
        cin >> s[i];
    for (int i = 1; i <= m; i++)
        cin >> t[i];
    ll ret = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (s[i] != t[j])
                continue;
            dp.add(i + 1, j + 1, dp.sum(1, 1, i, j));
            ret += dp.sum(i + 1, j + 1, i + 1, j + 1);
            if (ret >= mod)
                ret -= mod;
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 16000
s = int(input())
a = [s]
for i in range(2, 1000001):
    current = a[-1]
    if current % 2:
        a.append(3 * current + 1)
    else:
        a.append(current // 2)
    if a[-1] in a[:-1]:
        print(i)
        exit()


Measured memory_bytes: 2940
import math
a,b,C = map(float,input().split(' '))
S = a*b*math.sin(math.radians(C)) / 2.0
c = math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(C)))
h = 2*S/a
print(S)
print(a+b+c)
print(h)




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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    string s;
    cin >> s;
    int cnt = 0;
    for(auto c : s){
        if(c == 'p')++cnt;
    }
    ppp(s.size()/2-cnt);


    return 0;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  long long n;
  long long m;
  const long long max_n = 1e5;
  long long a[max_n + 1];
  pair<long long, long long> ope[max_n + 1];

  cin >> n >> m;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int j = 0; j < m; j++){
    cin >> ope[j].second >> ope[j].first;
  }
  sort(a, a+n);
  sort(ope, ope+m, greater<>());

  long long sum = 0;
  long long i = 0;
  long long f = 0;
  long long last_c = 0;
  for(int j = 0; j < m; j++){
    long long b, c;
    b = ope[j].second;
    c = ope[j].first;

    f = i + b - 1;
    if(f >= n) f = n - 1;
    // if(f < 0) break;

    if(a[f] < c) {
      sum += (f - i + 1) * c;
      i += b;
    }else{
      last_c = c;
      break;
    }

    if(f == n - 1) break;
  }

  for(int j = i; j < n; j++){
    if(a[j] < last_c) sum += last_c;
    else sum += a[j];
  }

  cout << sum << endl;

  return 0;
}

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

#define rep(i, N) for(int i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	int N, M; cin >> N >> M;
	vector<int> x(M), y(M);
	rep(i, M) {
		cin >> x[i] >> y[i];
		x[i]--;
		y[i]--;
	}

	vector<int> num(N, 1);
	vector<bool> red(N, false);
	red[0] = true;

	rep(i, M) {
		num[x[i]]--;
		num[y[i]]++;
		if (red[x[i]])red[y[i]] = true;
		if (num[x[i]] == 0)red[x[i]] = false;
	}

	int ans = 0;
	rep(i, N) {
		if (red[i])ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4468
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    char str[1001],p[1001],t[8],tmp;
    int q,a,b,i,j,k;
    scanf("%s%d",str,&q);
    for(i=0;i<q;i++){
        scanf("%s%d%d",t,&a,&b);
        if(strcmp(t,"print")==0){
            for(j=a;j<=b;j++)printf("%c",str[j]);
            puts("");
        }
        else if(strcmp(t,"reverse")==0){
            for(j=a;j<b;j++){
                for(k=b;k>j;k--){
                    tmp=str[k-1];
                    str[k-1]=str[k];
                    str[k]=tmp;
                }
            }
        }
        else{
            scanf("%s",p);
            j=a;
            k=0;
            while(j<=b){
                str[j]=p[k];
                j++;
                k++;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2148
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define MAX 1010
#define INF 1e9
typedef pair<int,int> pii;

struct edge{ int to,cost; };
vector<edge> G[MAX],G2[15];

int N,M,K,PP,n;
int s[6],t[6];
int d[MAX][MAX];
int d2[15][15];
int dp[1<<15][15];

/*
int rec(int S,int v){
  if(dp[S][v] >= 0){
    return dp[S][v];
  }
  if(S == (1<<n)-1){
    return dp[S][v] = 0;
  }
  int res = INF;
  for(int u = 0 ; u < n ; u++){
    if(!(S >> u & 1)){
      if(u <= K){
	res = min(res,rec(S|1<<u,u)+d2[v][u]);
      }else{
	if(S >> (u-K)){
	 res = min(res,rec(S|1<<u,u)+d2[v][u]);
	}else{
	  //res = min(res,rec(S,u)+d2[v][u]);
	}
      }
    }
  }
  return dp[S][v] = res;
}
*/

struct P{
  int d,v,S;
  P(){}
  P(int d,int v,int S):d(d),v(v),S(S) {}
  bool operator > (const P &p)const{
    if(d != p.d){
      return d > p.d;
    }
  }
};

int dijkstra2(){
  priority_queue<P,vector<P>,greater<P> > Q;
  Q.push(P(0,0,0));
  dp[0][0] = 0;
  while(!Q.empty()){
    P p = Q.top(); Q.pop();
    int v = p.v;
    int S = p.S;
    if(dp[S][v] < p.d){ continue; }
    if(S == (1<<n)-1){ return dp[S][v]; }
    for(int i = 0 ; i < n ; i++){
      if(!(S >> i & 1)){
	int nS = (S | (1<<i));
	if(i <= K){
	  if(dp[S][v]+d2[v][i] < dp[nS][i]){
	    dp[nS][i] = dp[S][v]+d2[v][i];
	    Q.push(P(dp[nS][i],i,nS));
	  }
	}else{
	  if((S >> (i-K) & 1)){
	    if(dp[S][v]+d2[v][i] < dp[nS][i]){
	      dp[nS][i] = dp[S][v]+d2[v][i];
	      Q.push(P(dp[nS][i],i,nS));
	    }
	  }else{
	    if(dp[S][v]+d2[v][i] < dp[S][i]){
	      dp[S][i] = dp[S][v]+d2[v][i];
	      Q.push(P(dp[S][i],i,S));
	    }
	  }
	}
      }
    }
  }
  return INF;
}

void dijkstra(int s){
  for(int i = 0 ; i < MAX ; i++){
    d[s][i] = INF;
  }
  priority_queue<pii,vector<pii>,greater<pii> > Q;
  Q.push(pii(0,s)); d[s][s] = 0;
  while(!Q.empty()){
    pii p = Q.top(); Q.pop();
    int v = p.second;
    if(d[s][v] < p.first){ continue; }
    for(int i = 0 ; i < G[v].size() ; i++){
      edge e = G[v][i];
      if(d[s][v] + e.cost < d[s][e.to]){
	d[s][e.to] = d[s][v]+e.cost;
	Q.push(pii(d[s][e.to],e.to));
      }
    }
  }
}

int main(){
  cin >> N >> M >> K >> PP; PP--;
  for(int i = 0 ; i < M ; i++){
    int a,b,c;
    cin >> a >> b >> c; a--; b--;
    G[a].push_back((edge){b,c});
    G[b].push_back((edge){a,c});
  }
  for(int i = 0 ; i < K ; i++){
    cin >> s[i] >> t[i];
    s[i]--; t[i]--;
  }
  for(int i = 0 ; i < N ; i++){
    dijkstra(i);
  }
 
  int idx[15];
  idx[0] = PP;
  for(int i = 1 ; i <= K ; i++){
    idx[i] = s[i-1]; idx[i+K] = t[i-1];
  }
  
  for(int i = 0 ; i <= 2*K ; i++){
    for(int j = 0 ; j <= 2*K ; j++){
      d2[i][j] = d[idx[i]][idx[j]];
    }
  }
  n = 2*K+1;
  for(int i = 0 ; i < (1<<n) ; i++){
    for(int j = 0 ; j < n ; j++){
      dp[i][j] = INF;
    }
  }
  int res = dijkstra2();
  if(res == INF){
    cout << "Cannot deliver" << endl;
  }else{
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 5872
n=int(input())
h=list(map(int,input().split()))
sum=0
flag=False
for i in range(max(h)+1):
    for j in range(n):
        if(h[j]>0):
            flag=True
            h[j]-=1
        elif(flag):
            sum+=1
            flag=False
    if(flag):
        sum+=1
    flag=False
print(sum)

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

int a[200005], b[200005], t[200005];

int main() {
  int n;
  cin >> n;
  for (int ni = 0; ni < n; ni++) {
    cin >> a[ni];
  }
  for (int ni = 0; ni < n; ni++) {
    cin >> b[ni];
  }
  int ans = 0;
  int bitmask = 0;
  for (int i = 0; i <= 28; i++) {
    bitmask |= (1 << i);
    int ti = 0;
    for (int ni = 0; ni < n; ni++) {
      if ((a[ni] & (1 << i)) == 0) {
        t[ti++] = a[ni];
      }
    }
    for (int ni = 0; ni < n; ni++) {
      if ((a[ni] & (1 << i)) > 0) {
        t[ti++] = a[ni];
      }
    }
    memcpy(a, t, sizeof(a));
    ti = 0;
    for (int ni = 0; ni < n; ni++) {
      if ((b[ni] & (1 << i)) == 0) {
        t[ti++] = b[ni];
      }
    }
    for (int ni = 0; ni < n; ni++) {
      if ((b[ni] & (1 << i)) > 0) {
        t[ti++] = b[ni];
      }
    }
    memcpy(b, t, sizeof(b));
    int al = 0, ar = 0;
    int bit = 0;
    for (int ni = n - 1; ni >= 0; ni--) {
      while (al < n && (a[al] & bitmask) + (b[ni] & bitmask) < (1 << i)) al++;
      while (ar < n && (a[ar] & bitmask) + (b[ni] & bitmask) < (1 << (i + 1))) ar++;
      bit += (ar - al);
      bit %= 2;
    }
    al = 0, ar = 0;
    for (int ni = n - 1; ni >= 0; ni--) {
      while (al < n && (a[al] & bitmask) + (b[ni] & bitmask) < (1 << (i + 1)) + (1 << i)) al++;
      while (ar < n && (a[ar] & bitmask) + (b[ni] & bitmask) < (1 << (i + 2))) ar++;
      bit += (ar - al);
      bit %= 2;
    }
    ans |= (bit << i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <math.h>

int main(void)
{
	long int n, ans;
	scanf("%ld", &n);
	for (int i = (int)sqrt(n); i > 0; i--)
	{
		if (n % i == 0)
		{
			ans = (long int)log10((double)(n/i)) + 1;
			printf("%ld", ans);
			break;
		}
	}
	return 0;
}

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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

signed main() {
  int N;
  cin >> N;
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    mp[d]++;
  }
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int t;
    cin >> t;
    if (mp[t]) {
      mp[t]--;
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }

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


Measured memory_bytes: 12928
//BISMILLAHIR RAHMANIR RAHIM
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#define     ll          long long 
#define     MP          make_pair
#define     MT          make_tuple 
#define     endl        '\n'
#define     iscanf(a)   scanf("%d",&a)
#define     llscanf(a)  scanf("%lld",&a)
#define     inlp(n)     for(i=n-1;i>=0;i--)
#define     f0(i,n)     for(i=0;i<n;i++)
#define     f1(i,n)     for(i=1;i<=n;++i)
#define     f01(i,n)    for(i=1;i<n;i++)
#define     PB          push_back
#define     IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     inout       freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define     mset(arr,n) memset(arr,n,sizeof(arr))
#define     vci         vector<int>
#define     test        int t;cin>>t;while(t--)
ll gcd(ll a,ll b){ while(b^=a^=b^=a%=b); return a;}

ll comp(ll a,ll b){
	if(a>b)return a;
	return b;
}

int main(){
	IOS;
	int n,i,k;
	cin>>n;
	int v[n];
	f0(i,n)cin>>v[i];
	int ans=0;
	sort(v,v+n);
	f0(i,n){
		for(k=i+1;k<n;++k){
		for(int j=k+1;j<n;++j){
			if(v[i]==v[j] || v[j]==v[k] || v[i]==v[k])continue;
			
			if(v[i]+v[k]>v[j] && v[j]+v[k]>v[i] && v[i]+v[j]>v[k])++ans;
			else break;
		}
	       }
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3576
#include <stdio.h>

int main(void)
{
    int r;
    scanf("%d", &r);

    if (r >= 0 && r <= 4208)
    {
        if (r < 1200)
        {
            printf("ABC\n");
        }
        else if (r < 2800)
        {
            printf("ARC\n");
        }
        else
        {
            printf("AGC\n");
        }
    }
    return (0);
}


Measured memory_bytes: 128
import java.io.*;
import java.util.Scanner;
public class Main{ 
  public static void main(String[]args){ 
    Scanner sc = new Scanner(System.in);
    while(true){
      int n = sc.nextInt();
      int r = sc.nextInt();
      if(n==0 && r==0){
        break;
      }
      int [] s = new int[100];
      int [] s2 = new int[100];
      int [] p = new int[100];
      int [] c = new int[100];
      int h,i,j,k;
      for(i=0;i<n;i++){
        s[i]=n-i;
      }
      for(j=0;j<r;j++){
        for(h=0;h<n;h++){
          s2[h]=s[h];
        }
        p[j]=sc.nextInt();
        c[j]=sc.nextInt();
        for(k=0;k<p[j]+c[j]-1;k++){
          if(k<c[j]){
            s[k]=s2[k+p[j]-1];
          }
          if(k>=c[j]){
            s[k]=s2[k-c[j]];
          }
        }
      }
      System.out.printf("%d\n",s[0]);
    }
  }
}    

Measured memory_bytes: 39284
#include<stdio.h>

int main(){
	long long int a[10000], n, i, sum=0, max, min;
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%lld", &a[i]);
	}
	
	max = a[0];
	min = a[0];
	
	for(i=1;i<n;i++){
		if(max < a[i]){
			max = a[i];
		}
	}
	
	for(i=1;i<n;i++){
		if(min > a[i]){
			min = a[i];
		}
	}
	
	for(i=0;i<n;i++){
		sum = sum + a[i];
	}
	
	printf("%lld %lld %lld\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 676
let cs, a_s = Array.(make 100001 0, init (read_int ()) @@ fun _ -> Scanf.scanf " %d" (+) 0)
let _ = Array.(iter (fun a -> cs.(a) <- cs.(a) + 1) a_s; List.(length @@ sort_uniq (-) @@ to_list a_s) - (fold_left (fun s c -> s + if c > 0 then 1 - c mod 2 else 0) 0 cs) mod 2) |> Printf.printf "%d\n"

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

using namespace std;

typedef long long ll;

int main() {
    int N;
    int A[100];

    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    ll money = 1000;
    ll stock = 0;
    for (int i = 1; i <= N;) {
        int k = i;
        if (stock == 0) {
            for (; k < N; k++) {
                if (A[k] < A[k+1]) {
                    break;
                }
            }
            if (k == N) {
                break;
            }
            stock = money / A[k];
            money %= A[k];
        } else {
            for (; k < N; k++) {
                if (A[k] > A[k+1]) {
                    break;
                }
            }
            money += stock * A[k];
            stock = 0;
        }
        i = k + 1;
    }
    cout << money << endl;

    /*
    int m = 1000;
    int s = 0;

    for (int i = 1; i <= N;) {
        int k = i;
        for (; k < N; k++) {
            if (s > 0 && A[k] > A[k+1]) {
                break;
            }
            if (s == 0 && A[k] < A[k+1]) {
                break;
            }
        }
        if (s > 0) {
            m += s * A[k];
            s = 0;
        } else {
            if (k < N) {
                s = m / A[k];
                m %= A[k];
            }
        }
        i = k+1;
    }

    cout << m << endl;
    */
}

Measured memory_bytes: 3584
import java.util.*;
import java.io.*;

public class Main {


	public static void main(String[] args) {
		Main ans = new Main();
		System.out.println(ans.solve());
	}

	private long solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int [] array = new int[N+1];

		for(int i=1;i<=N;i++){
			array[i] = sc.nextInt();
		}		 
		long [][] dp = new long[N+1][N+1];
 		long [][] sum = preProcess(array, N);
 		return solve(sum, 1, N, dp);
	}

	private long solve(long [][]sum, int i, int j, long[][] dp) {
		if (i==j) return 0;
		if (dp[i][j] != 0) return dp[i][j];

		long bestCost = (long) (1e15);
		for(int k=i;k<=j-1;k++) {
			long cost = sum[i][j] + solve(sum, i, k, dp) + solve(sum, k+1, j, dp);
			bestCost = Math.min(bestCost, cost);
		}
		dp[i][j] = bestCost;
		return bestCost;
	}

	private long [][] preProcess(int[]array, int N) {		 
		long [][] sum = new long[N+1][N+1];
		for(int i=1;i<=N;i++){
			for(int j=i;j<=N;j++){
				sum[i][j] = array[j] + ((i==j) ? 0 : sum[i][j-1]);
			}
		}
		return sum;
	}
}

Measured memory_bytes: 40044
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int N, P[200000], a[200000];

int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> P[i];
		a[P[i]-1] = i;
	}

	int ans = INT_MAX;
	for(int i=0; i<N; i++){
		int tmp = N-1;
		while(a[i] < a[i+1]){
			i++;
			tmp--;
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
package main
import "fmt"
func main(){
    var inS int
    hms:=[]int{3600,60,1}
    hmsCount:=[]int{0,0,0}
    fmt.Scan(&inS)
    
    for i:=0;i<3;i++{
        for{
            if tmp:=inS-hms[i];tmp>=0{
                inS-=hms[i]
                hmsCount[i]++
            }else{
                break
            }
        }
    }
    
    
    
    fmt.Printf("%d:%d:%d\n",hmsCount[0],hmsCount[1],hmsCount[2])
    
}



Measured memory_bytes: 1124
N,Y=map(int,input().split())

L=[-1,-1,-1]
for i in range(0,min(Y//10000,N)+1):
  for j in range(0,N-i+1):
    if i*10000+j*5000+(N-i-j)*1000==Y:
      L=[i,j,N-i-j]
      break

print(*L)

Measured memory_bytes: 3060
#include <cstdio>
#include<cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int x,y,m,i;
int main()
{
    string c;
    cin>>c;
    for(;i<c.length();++i)
	    if(x<=y)
	    {
	        x++;
	        if(c[i]=='p')m--;
	    }
	    else
	    {
	        y++;
	        if(c[i]=='g')m++;
	    }
    printf("%d\n",m);
    return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        int C = sc.nextInt();

        int[] B = new int[M];
        for(int i = 0; i < M; i++){
            B[i] = sc.nextInt();
        }
        
        int ans = 0;
        for(int i = 0; i < N; i++){
            int sum = C;
            for(int j = 0; j < M; j++){
                int A = sc.nextInt();
                sum += A * B[j];
            }
            if ( sum > 0 ) ans++;
        }
        
        System.out.println(ans);
    }
}


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

typedef long long ll;

const int maxn = 1e5 + 5;

int n, ans;
char a[maxn];

int main()
{
    scanf("%s", a + 1);
    n = strlen(a + 1);
    for(int i = 1; i <= n; i++)
	if(a[i] != a[i - 1])
	    ans++;
    printf("%d\n", ans - 1);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N, D; cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  REP(i, N) REP(j, D) cin >> X[i][j];

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i+1; j < N; ++j) {
      ll sum = 0;

      for (int k = 0; k < D; ++k) {
        sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
      }

      double tmp = sqrt(sum);
      if (ceil(tmp) == floor(tmp)) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	vector<int> C(N);

	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		--A[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> B[i];
	}
	for (int i = 0; i < N - 1; ++i) {
		cin >> C[i];
	}

	int s = 0;
	for (int i = 0; i < N; ++i) {
		s += B[A[i]];
		if (i != 0 && A[i - 1] == A[i] - 1) {
			s += C[A[i - 1]];
		}
	}
	cout << s << endl;
	//system("PAUSE");
}

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

int main() {
  
  int N, K; cin >> N >> K; int64_t ans = 0;
  
  vector<int64_t> vec(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  for (int i = 0; i < N - K; i++) {
    ans += vec.at(i);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define int long long
#define endl '\n'

const int N = 100005;
int n, a[N], b[N], c[N], ans;
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1 ; i <= n ; i ++){
		cin >> a[i];
	}
	for(int i = 1 ; i <= n ; i ++)
		cin >> b[i];
	for(int i = 1 ; i < n ; i ++)
		cin >> c[i];
	int ans = 0;
	for(int i = 1 ; i <= n ; i ++){
		ans += b[a[i]];
		if(i < n){
			if(a[i] == a[i + 1] - 1){
				ans += c[a[i]];
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#include<stdio.h>
int p[200005], cnt[200005];
int root(int n)
{
	if (p[n] != n)
		p[n] = root(p[n]);
	return p[n];
}
void uni(int a, int b)
{
	a = root(a);
	b = root(b);
	if (a != b)
	{
		p[a] = b;
		cnt[b] += cnt[a];
	}
	return;
}
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	int a[200005], b[200005];
	for (i = 0; i < m; i++)
	{
		scanf("%d %d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
	}
	for (i = 0; i < n; i++)
	{
		p[i] = i;
		cnt[i] = 1;
	}
	for (i = 0; i < m; i++)
		uni(a[i], b[i]);
	int ans = 0;
	for (i = 0; i < n; i++)
		if (ans < cnt[root(i)])
			ans = cnt[root(i)];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 11024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

ll hoge(ll i,ll j){
    if(i==0){
        return 1;
    }
    if(j==1){
        return 0;
    }
    if(j==pow(2,i+1)-1){
        return pow(2,i);
    }
    if(j==pow(2,i+2)-3){
        return pow(2,i+1)-1;
    }
    if(j<pow(2,i+1)-1){
        return hoge(i-1,j-1);
    }
    return pow(2,i)+hoge(i-1,j-(pow(2,i+1)-1));
    
}

int main(){
    ll n,x;cin>>n>>x;
    ll ans=hoge(n,x);
    cout<<ans<<endl;
    
    
    return 0;
}




Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn
  destinations <- U.replicateM n $ do
    [t,x,y] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (t,x,y)
  let check (t1,x1,y1) (t2,x2,y2) = let dt = t2 - t1
                                        dx = abs (x1 - x2) + abs (y1 - y2)
                                    in dt >= dx && even (dt - dx)
  let result = U.all (uncurry check) $ U.zip (U.cons (0,0,0) destinations) destinations
  putStrLn $ if result then "Yes" else "No"


Measured memory_bytes: 5884
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e6+69, INF=2e9+6969;

int qq;
ll t[10][10], h,w,licz[10];

int main()
{
	ll n = 10;
	scanf("%lld%lld", &h, &w);
	for(ll i=0;i<n;++i) for(ll j=0;j<n;++j) scanf("%lld", &t[i][j]);
	for(ll i=0;i<n;++i)
	{
		for(ll j=0;j<n;++j)
		{
			for(ll g=0;g<n;++g)
			{
				t[j][g]=min(t[j][g],t[j][i] + t[i][g]);
			}
		}
	}
	
	ll ans=0;
	for(ll i=0;i<h;++i)
	{
		for(ll j=0;j<w;++j)
		{
			ll x;
			scanf("%lld", &x);
			if(x==-1) continue;
			ans+=t[x][1];
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <map>
#include <iterator>
#include <queue>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for (int i=(a-1);i>=(b);--i)
#define rrep(i,n) rrepd(i,n,0)
#define PI 3.14159265
typedef long long ll;
typedef pair<int, int> P;


int main(int argc, const char * argv[]) {
  // x1, x2を座標圧縮し、座標圧縮した際の幅を返す 
  int n;
  cin >> n;
  if (n % 2 == 1){
    cout << "No" << endl;
    return 0;
  }
  int tmp_n = n / 2;
  string s;
  cin >> s;
  rep(i, tmp_n){
    if (s[i] != s[i+tmp_n]){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include<queue>
using namespace std;
int n;
int head;
int p[100100],a[100100];
int find(int l,int r,int x)
{
    if(x<=p[l])  return -1;
    int mid;
    while(l<=r)
    {
        if(l==r)  return l;
        if(l==r-1)
        {
            if(x>p[l] && x<=p[r])  return l;
            return r;
        }
        mid=l+r>>1;
        if(p[mid]>=x)  r=mid-1;
        else    l=mid;
    }
    return mid;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)  scanf("%d",&a[i]);
    int tot=100050;
    head=tot;
    p[head]=a[1];
    for(int i=2;i<=n;i++)
    {
        int k=find(head,tot,a[i]);
        if(k>0)  p[k]=a[i];
        else  p[--head]=a[i];
    }
    cout<<tot-head+1<<endl;
    return 0;
}

Measured memory_bytes: 4356
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def f(n):
    r = 2
    ret = 1
    for i in range(n, n-r, -1):
        ret *= i
    for i in range(1, r+1):
        ret //= i
    return ret * 2 + n


class Bisect:
    def __init__(self, func):
        self.__func = func

    def bisect_left(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if self.__func(mid) < x:
                lo = mid+1
            else:
                hi = mid
        return lo

    def bisect_right(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if x < self.__func(mid):
                hi = mid
            else:
                lo = mid+1
        return lo

@mt
def slv(N, M, A):
    A.sort(reverse=True)
    print(A)
    b = Bisect(f)

    i = b.bisect_left(M, 1, N)
    if f(i) != M:
        i -= 1
    l = f(i)

    ans = 0
    for j in range(i):
        ans += A[j] * 2
        ans += A[j] * (i-1)

    rem = M - l
    print(i, l, rem)
    j = 0
    while rem != 0:
        ans += A[j] + A[i]
        rem -= 1
        if rem == 0:
            break
        ans += A[j] + A[i]
        rem -= 1
        if rem == 0:
            break
        j += 1


    return ans

import numpy as np
@mt
def slv2(N, M, A):
    C = Counter(A)
    L = 1 << (max(A).bit_length() + 1)
    B = [C[i] for i in range(L)]
    D = np.fft.rfft(B)
    D *= D
    E = list(map(int, np.round(np.fft.irfft(D).real)))
    ans = 0
    c = 0
    i = L - 1
    while c != M:
        n = E[i]
        if c + n > M:
            n = M-c
        c += n
        ans += i * n
        i -= 1
        assert i != -1

    return ans

def main():
    N, M = read_int_n()
    A = read_int_n()
    print(slv2(N, M,A))

    # N = 10**5
    # M = random.randint(1, N**2)
    # A = [random.randint(1, 10**5) for _ in range(N)]
    # print(slv(N, M, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 46644
#include <stdio.h>

int main(void) {
    int sum = 0;
    int r, g, b;
    scanf("%d %d %d", &r, &g, &b);
    sum = sum * 10 + r;
    sum = sum * 10 + g;
    sum = sum * 10 + b;
    if (!(sum % 4))
        printf("YES");
    else
        printf("NO");
    return 0;
}

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

using ll = long long; using pll = pair<int, int>;
using ld = long double; using pii = pair<int, int>;
using dbl = long double; using vll = vector<int>;
#define pb emplace_back
#define push emplace
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define len(a) (int) a.size()
#define reset(a, val) memset(a, val, sizeof(a))
#define endl '\n'
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O2") // Ofast or O2
#pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,
//              popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS


const ll mod = 1e9 + 7, inf = 2e18, ninf = -2e18;

ll takemod(ll a, ll mod = mod)
{	return ((a % mod) + mod) % mod; }


const int K = 1e5 + 10, N = 110;
int dp[N][K];


signed main(){
	int n, k;
	cin >> n >> k;
	int a[n + 1];
	for(int i = 1; i <=n; i++){
		cin >> a[i];
	}


	for(int i = 0; i <= k; i++){
		dp[0][i] = 1; 
	}
	for(int i = 1; i <= n; i++){
		int b[k];
		for(int j = 0; j <= k; j++){
			b[j] = takemod(dp[i-1][j]);
			if(j - a[i]  - 1>= 0)
				b[j] -= dp[i - 1][ j - a[i] - 1];
				b[j] = takemod(b[j]);
		}
		dp[i][0] = b[0];
		for(int j = 1; j<= k; j++){
			dp[i][j] = takemod(dp[i][j - 1] +  b[j]);
		}
	}
	cout << takemod(dp[n][k] - dp[n][k - 1]);
}

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

int main()
{
    int k;
    cin >> k;
    vector<ll> a;
    for(int i=1;i<=9;++i)a.push_back(i);
    while(1){
        if(k<=a.size()){
            cout << a[k-1] << endl;
            return 0;
        }else{
            k-=a.size();
            vector<ll> old;
            swap(old,a);
            for(ll x : old){
                for(int i=-1;i<=1;++i){
                    int d=x%10+i;
                    if(d<0 || d>9){
                        continue;
                    }
                    ll nx=x*10+d;
                    a.push_back(nx);
                }
            }
        }

    }
}

Measured memory_bytes: 1712
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            (long N, long M) = Slice2<long>();
            var ai = new long[N];
            var bi = new long[N];
            var ci = new long[M];
            var di = new long[M];
            for (var i = 0; i < N; ++i)
                (ai[i], bi[i]) = Slice2<long>();
            for (var i = 0; i < M; ++i)
                (ci[i], di[i]) = Slice2<long>();

            for (var i = 0; i < N; ++i)
            {
                var min = long.MaxValue / 2;
                var pos = -1;
                for (var j = 0; j < M; ++j)
                {
                    var t = Abs(ai[i] - ci[j]) + Abs(bi[i] - di[j]);
                    if (t < min)
                    {
                        min = t;
                        pos = j;
                    }
                }
                WriteLine(pos + 1);
            }
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27240
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	int t;
	cin>>t;
	for(int l = 0; l < t; l++){
		int n,k;
		cin>>n>>k;
		vector<int> homes;
		for(int i = 0; i < n; i++){
			int p;
			cin>>p;
			homes.push_back(p);
		}
		if(homes.size()<=k){
			cout<<0<<endl;
			continue;
		}
		sort(homes.begin(),homes.end());
		vector<int> roads;
		int sumL=0;
		for(int i = 1; i < homes.size(); i++){
			int length=homes[i]-homes[i-1];
			roads.push_back(length);
			sumL+=length;
		}
		sort(roads.begin(),roads.end(),greater<int>());
		int rid=0;
		for(int i = 0; i < k-1; i++){
			rid+=roads[i];
		}
		cout<<sumL-rid<<endl;
	}

	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;

const int MAXN = 1500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 18;
const double EPS = 1e-9;
const double PI = 3.1415926535;

char grid[MAXN][MAXN];
ll dp[MAXN][MAXN];

ll add(ll a, ll b) {
    return (a + b) % MOD;
}

int main() {
    int H, W;

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

    dp[0][0] = 1;
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++) {
            if(grid[i][j] == '#')
                continue;
            if(i > 0)
                dp[i][j] = add(dp[i][j], dp[i - 1][j]);
            if(j > 0)
                dp[i][j] = add(dp[i][j], dp[i][j - 1]);
        }

    cout << dp[H - 1][W - 1] << endl;

    return 0;
}


Measured memory_bytes: 15232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  cin >> N;
  const long long MOD = 1000000007;
  long long ans10=1, ans9=1, ans8=1;
  for (int i = 0; i < N; i++) {
    ans8 = (ans8 * 8) % MOD;
    ans9 = (ans9 * 9) % MOD;
    ans10 = (ans10 * 10) % MOD;
  }
  
  long long ans = ans10;
  ans = (ans - ans9) % MOD;
  ans = (ans - ans9) % MOD;
  ans = (ans + ans8) % MOD;
  ans = (ans + MOD) % MOD;
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, alice = 0, bob = 0;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++)
    {
        if (i % 2 == 0)
        {
            alice += a[i];
        }
        else
        {
            bob += a[i];
        }
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 3608
import fractions

gcd = fractions.gcd
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
ryuho = 0

if n == 2:
  print(max(a[0],a[1]))
  exit()

ans = gcd(a[0],a[1])
ryuho = a[2]

if ans < gcd(a[1],a[2]):
  ans = gcd(a[1],a[2])
  ryuho = a[0]

if ans < gcd(a[0],a[2]):
  ans = gcd(a[0],a[2])
  ryuho = a[1]

if n == 3:
  print(ans)
  exit()

for i in range(3,n):
  temp1 = gcd(ans,a[i])
  temp2 = gcd(ans,ryuho)
  if temp1 > temp2:
    ans = temp1
  else:
    ans = temp2
    ryuho = a[i]

print(ans)

Measured memory_bytes: 16164
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
s=[[]for i in range(N)]
print("Yes")
for i in range(M):
    a,b=map(lambda x: int(x)-1,input().split())
    s[a].append(b)
    s[b].append(a)
l=[-1]*N
b=[0]
while b:
    a=[]
    for i in b:
        for j in s[i]:
            if l[j]==-1:
                l[j]=i+1
                a.append(j)
    b=a
print(*l[1:],sep="\n")

Measured memory_bytes: 94732
#include <bits/stdc++.h>
using namespace std;
int a[2][8] = {{2,10,3,9,4,8,6,12}, {6,2,10,3,9,4,8,12}};

int main() {
    int N;
    cin >> N;
    if(N == 3) {
        cout << "2 5 63" << endl;
        return 0;
    } else {
        for(int i=0; i<N; ++i) {
            cout << a[N % 2][i % 8] + 12 * (i / 8) << (i == N - 1 ? '\n' : ' ');
        }
    }
}

Measured memory_bytes: 384
n = int(input())
dishes = []
for i in range(n):
    ai,bi = map(int,input().split())
    dishes.append((ai,bi,ai+bi))
dishes.sort(key = lambda x:x[2],reverse = True)
A = 0
B = 0
for i in range(n):
    if i % 2 == 0:
        A += dishes[i][0]
    else:
        B += dishes[i][1]
print(A-B)

Measured memory_bytes: 63832
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	int N;
	cin>>N;
	
	string S;
	cin>>S;
	
	int ans=  0;
	
	for(int i=0;i<S.size()-2;i++){
		if(S.substr(i,3)=="ABC")ans++;
	}
	
	cout<<ans<<endl;
	
    return 0;
}


Measured memory_bytes: 256
import itertools
import functools
import math

def OK():
    N = int(input())

    sum = 0
    cnt = 0
    for i in range(1,N+1):
        for j in range(1,N+1):
            chk = math.gcd(i,j)
            for k in range(1,N+1):
                sum += math.gcd(chk,k)

    print(sum)

OK()


Measured memory_bytes: 9580
def abc_exp(a,b,c):
	print(str(a) + ' ' + str(b) + ' ' + str(c) )
	
def exchange(a,b,remain):
	#if remain >= int(a * 2): 
	#	b = b + int(a / 4) * 8
	#	a = a % 4
	while True:
		if remain >= 4 and a - 4 >= 0:
			b = b + 8
			a = a - 4
			remain = remain - 4
		else: 
			break
	return a,b
	

N,Y = map(int,input().split())

a = int(Y/10000)
b = int((Y - a * 10000)/5000)
c = int((Y - a * 10000 - b * 5000)/1000)

max_bills = int(Y/1000)

if (max_bills < N) or (N < a + b + c):
	print('-1 -1 -1')
	
elif (N == max_bills):
	print('0 0 ' + str(max_bills))
	
elif (N == a + b + c):
	abc_exp(a,b,c)

else:
	remain = N - a - b - c
	if remain % 4 == 0:
		a,b = exchange(a,b,remain)
		remain = N - a - b - c
		if not b - remain/4 < 0:
			b = b - int(remain / 4)
			c = c + int(remain / 4) * 5
			abc_exp(a,b,c)
	
	else:
		a = a - (remain % 4)
		b = b + 2 * (remain % 4)
		a , b = exchange(a,b,remain)
		remain = N - a - b - c
		if b - remain/4 >= 0:
			b = b - int(remain / 4)
			c = c + int(remain / 4) * 5
			abc_exp(a,b,c)
		
		else:
			print('-1 -1 -1')

Measured memory_bytes: 3064
import sys
readline = sys.stdin.readline

N = int(readline().strip())
A = list(map(int, readline().split()))
L = 10**9 + 7

ans = 0
a = A[N-1]
for i in range(N-2, -1, -1):
  ans += A[i]*a
  ans %= L
  a += A[i]

print(ans)

Measured memory_bytes: 31464
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n;
  string s[10];
  s[0] = "0111111";
  s[1] = "0000110";
  s[2] = "1011011";
  s[3] = "1001111";
  s[4] = "1100110";
  s[5] = "1101101";
  s[6] = "1111101";
  s[7] = "0100111";
  s[8] = "1111111";
  s[9] = "1101111";

  bool bi[10][7];
  REP(i,10)
    REP(j,7) 
      bi[i][j] = (s[i][j] == '1');
  while(cin >>n, n!=-1) {
    int a;
    bool prev[7] = {};
    REP(i,n) {
      cin >> a;
      REP(i,7) {
        cout << (bi[a][i] xor prev[i]);
        prev[i] = bi[a][i];
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[100000] = {0};
    
    for (int i = 0; i < n; ++i) {
        int aa; cin >> aa;
        if ((n % 2 == 0 && aa % 2 == 0) || (n % 2 != 0 && aa % 2 != 0)) {
            cout << 0 << endl;
            return 0;
        }
        //n - 1 - 2 * key = aa
        int key = (n - 1 - aa) / 2;
        a[key]++;
        if (key != n - 1 - key) a[n - 1 - key]++;
    }
    long long ans = 1;
    if (n % 2 != 0 && a[n / 2] % 2 == 0) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < (n % 2 != 0 ? n / 2 + 1 : n / 2); ++i) {
        if (a[i]) {
            ans *= a[i];
            ans %= (long long)1e9 + 7;
        }
        if (i < n / 2 && a[i] % 2 != 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 105;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, m, k, P, dp[MAXN][MAXN][MAXN][2];
int binom[MAXN][MAXN], coef[MAXN][MAXN][MAXN][2];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
int power(int x, int y) {
	if (y == 0) return 1;
	int tmp = power(x, y / 2);
	if (y % 2 == 0) return 1ll * tmp * tmp % P;
	else return 1ll * tmp * tmp % P * x % P;
}
int main() {
	read(n), read(m), read(k), read(P), dp[1][0][0][0] = 1;
	for (int i = 0; i <= max(n, m); i++) {
		binom[i][0] = 1;
		for (int j = 1; j <= i; j++)
			binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j]) % P;
	}
	for (int t = 1; t <= k; t++)
	for (int i = 0; i <= m; i++) {
		for (int j = 0; j <= n; j++) {
			int tmp = (power(t, m - i) - power(t - 1, m - i) + P) % P;
			tmp = 1ll * tmp * power(k - t + 1, i) % P;
			coef[t][i][j][0] = power(tmp, j);
		}
	}
	for (int t = 1; t <= k; t++)
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			int tmp = (power(k - t + 1, i) - power(k - t, i) + P) % P;
			tmp = 1ll * tmp * power(t, n - i) % P;
			coef[t][i][j][1] = power(tmp, j);
		}
	}
	for (int t = 1; t <= k; t++) {
		for (int i = 0; i <= n; i++)
		for (int j = 0; j <= m; j++) {
			int tmp = dp[t][i][j][0];
			for (int k = 0; i + k <= n; k++)
				update(dp[t][i + k][j][1], 1ll * tmp * binom[n - i][k] % P * coef[t][j][k][0] % P);
			tmp = dp[t][i][j][1];
			for (int k = 0; j + k <= m; k++)
				update(dp[t + 1][i][j + k][0], 1ll * tmp * binom[m - j][k] % P * coef[t][i][k][1] % P);
		}
	}
	writeln(dp[k + 1][n][m][0]);
	return 0;
}

Measured memory_bytes: 18048
n = gets.to_i

case 
when n >= 64
  puts 64
when 32 <= n && n < 64
  puts 32
when 16 <= n && n < 32
  puts 16
when 8 <= n && n < 16
  puts 8
when 4 <= n && n < 8
  puts 4
when 2 <= n && n < 4
  puts 2
when 1 <= n && n < 2
  puts 1
end

Measured memory_bytes: 1788
#include<iostream>

using namespace std;

int main(void)
{
  int a,b,c,d; cin>>a>>b>>c>>d;
  
  for(;;){
    c-=b; if(c<=0){puts("Yes"); return 0;}
    a-=d; if(a<=0){puts("No");  return 0;}
  }
  
  return 0;
}

Measured memory_bytes: 3636