akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b;cin>>a>>b;
  if(b%a==0)cout<<a+b<<endl;
  else cout<<b-a<<endl;
  return 0;
}


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

int h, n;
int a;

int main()
{
    scanf("%d%d", &h, &n);
    while (n--)
    {
        scanf("%d", &a);
        h -= a;
    }
    if (h > 0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


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

int main() {
  std::string n; std::cin >> n;
  long long sum = 0;
  for (std::string::iterator itr = n.begin(); itr != n.end(); ++itr)
    sum += (*itr-'0');
  
  if (sum % 9 == 0) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  
  return 0;
}

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

int n,ans;
int a[20];
int x[20][20],y[20][20];

bool valid(int msk){
    for(int i=0;i<n;i++){
        if(!((msk>>i)&1))continue;
        for(int j=0;j<a[i];j++){
            if(((msk>>x[i][j])&1)!=y[i][j])return false;
        }
    }
    return true;
}

int main(){

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

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<a[i];j++){
            cin>>x[i][j]>>y[i][j];
            x[i][j]--;
        }
    }
    for(int s=0;s<(1<<n);s++){
        if(valid(s))ans=max(ans,__builtin_popcount(s));
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,m,c;
  cin>>n>>m>>c;
  int b[20];
  for(int i=0;i<m;++i)
	cin>>b[i];
  int ans=0;
  
  for(int i=0;i<n;++i){
	int x=c;
	for(int j=0;j<m;++j){
	  int in;cin>>in;
	  x+=in*b[j];
	}
	if(x>0)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define dbug(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}


int main(){

  int N;
  vector<int> a;
  int cost;

  cin >>N;

  int ai;

  rep(i,N){

  cin>>ai;
  a.emplace_back(ai);
}
  int ave=0;

  rep(i,N){
    ave+=a[i];
  }
  ave=ave/N;

  int one=0;

  rep(i,N){
    one+=pow((a[i]-ave),2);
  }

  int two=0;

  rep(i,N){
    two+=pow((a[i]-(ave+1)),2);
  }


  cout << min(one,two) <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
 
int main(){
	FIO
	
	string s;cin >> s;
	deque<char> dq;
	forn(i, s.size())dq.pb(s[i]);
	bool rev = false;
	int q;cin >> q;
	while(q--){
		int t;cin >> t;
		if(t == 1)rev ^= 1;
		else{
			int f;cin >> f;
			char c;cin >> c;
			if(rev){
				if(f == 1)dq.pb(c);
				else dq.push_front(c);
			}
			else {
				if(f == 1)dq.push_front(c);
				else dq.pb(c);
			}
		}
	}
	string ans;
	while(!dq.empty()){
		ans += dq.front();
		dq.pop_front();
	}
	if(rev)reverse(ans.begin(), ans.end());
	cout << ans;
	return 0;
}

Measured memory_bytes: 1368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
typedef tuple<ll,int,int,int,int,int,int,int>T;
#define PI 3.14159265358979
const int MAX = 510000;
const int MOD = 1000000007;
//この設定だとn<10^7が限界。maxの0を一個増やせば100msかかるが一桁増やせる。
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int N;
  cin>>N;
  priority_queue<P,vector<P>,greater<P>>Blue;
  priority_queue<P,vector<P>,greater<P>>Red;
  //Red入力
  rep(i,N){
    int a,b;
    cin>>a>>b;
    Red.push(P(a,b));
  }
  //Blue
  rep(i,N){
    int a,b;
    cin>>a>>b;
    Blue.push(P(a,b));
  }
  ll ans=0;
  priority_queue<P>yred;
  rep(i,N){
    auto bl=Blue.top();Blue.pop();
    int flag=0;
    while(flag==0){
      if(Red.empty()){break;}
      auto re=Red.top();
      if(re.first<bl.first){
        Red.pop();
        //yで並べるため入れ替え
        auto g=P(re.second,re.first);
        yred.push(g);
      }
      else{break;}
    }
    queue<P>memo;
    while(!yred.empty()){
      auto t=yred.top();
      if(t.second<bl.first&&t.first<bl.second){
        yred.pop();ans++;
       break;
      }
      else{memo.push(t);yred.pop();}
    }
    while(!memo.empty()){
      auto t=memo.front();memo.pop();
      yred.push(t);
    }
  }
  cout<<ans;
} 


Measured memory_bytes: 256
import sys
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False

def ddprint(x):
  if DBG:
    print(x)

a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n = inn()
n = n%26
b = a[n:] + a[:n]
ddprint(b)
s = input().strip()
for i in range(len(s)):
    for j in range(26):
        if s[i]==a[j]:
            printn(b[j])
            break
print("")


Measured memory_bytes: 40048
#include<iostream>
#include<string>
using namespace std;
int main(void){
  string a, b, c;
  cin >> a >> b >> c;
  char d, e, f;
  d = a[0] - 32;
  e = b[0] - 32;
  f = c[0] - 32;
  cout << d << e << f <<endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
import itertools
import time
N = int(input())
S = (input())
# start = time.time()
r_index_lis, g_index_lis, b_index_lis = [], [], []
for i, s in enumerate(S):
    if s == 'R':
        r_index_lis.append(i)
    elif s == 'G':
        g_index_lis.append(i)
    else:
        b_index_lis.append(i)
count = len(r_index_lis)*len(g_index_lis)*len(b_index_lis)
# print(time.time() - start)
# exit()

# for r in r_index_lis:
#     for g in g_index_lis:
#         diff = r - g
#         # count += len(b_index_lis)
#         if(min(r, g) - diff >= 0):
#             if S[min(r, g) - diff] == 'B':
#                 count -= 1
#         if(max(r, g) + diff < N):
#             if S[max(r, g) + diff] == 'B':
#                 count -= 1
#         if (r+g) % 2 == 0:
#             if S[int((r+g)/2)] == 'B':
#                 count -= 1

for i in range(N):
    for j in range(i+1, N):
        k = 2*j - i
        if k < N and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            count -= 1


print(count)


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

using namespace std;

int main() {

	long  h,n;

	cin >> h >> n;

	long a;
	for (long i = 1; i <= n; i++) {

		cin >> a;
		h -= a;
		if (h <= 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}

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

int main(){
  vector<int> S(100005,2);
  for(int i=0; i<100005; i++){
    char a='!';
    cin >> a;
    if(a=='0'){
      S[i]=0;
    }
    else if(a=='1'){
      S[i]=1;
    }
    else{
      S.pop_back();
    }
  }
  int N=S.size();
  
  vector<int> K;
  int i=0;
  while(i<N){
    K.push_back(0);
    if(S.at(i)==0){
      while(i<N&&S[i]==0){
        K[K.size()-1]++;
        i++;
      }
    }
    else if(S.at(i)==1){
      while(i<N&&S[i]==1){
        K[K.size()-1]++;
        i++;
      }
    }
  }
  K.push_back(-1);
  
  int ans=0;
  while(i!=0){
    i=0;
    for(int j=0; j<K.size()-1; j++){
      if(K[j]==0&&K[j+1]==0){
        K.erase(K.begin()+j);
        K.erase(K.begin()+j);
        i=1;
      }
      else if(K[j]>0&&K[j+1]>0){
        if(K[j]>K[j+1]){
          N=K[j+1];
        }
        else{
          N=K[j];
        }
        K[j]-=N;
        K[j+1]-=N;
        ans+=2*N;
        i=1;
      }
    }
  }
  
  cout << ans << endl;
  
}

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

int MOD=1000000007;

int main() {
  int M,D,ans=0;
  cin >> M >>D;
  for(int i=1; i<=M; i++){
    for(int j=10; j<=D; j++){
      if(i==(j/10)*(j%10) && j/10>=2 && j%10>=2){
        ans +=1;
      }
    }
  }
  cout << ans << endl;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
// const ll INF = 1e18;
const int INF = 1010101010;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  int ans = INF;
  for (int i = 0; i <= N - K; i++) {
    int dist;
    if (0 <= x[i]) {
      dist = x[i + K - 1];
    } else if (x[i + K - 1] <= 0) {
      dist = -x[i];
    } else {
      dist = x[i + K - 1] - x[i] + min(abs(x[i]), abs(x[i + K - 1]));
    }
    dump(x[i], x[i + K - 1], dist);
    ans = min(ans, dist);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using P = pair<int, int>;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  rep(_, q) {
    int n;
    cin >> n;
    priority_queue<P> l, r;
    ll ans = 0;
    rep(i, n) {
      int k, a, b;
      cin >> k >> a >> b;
      ans += min(a, b);
      if (a > b)
        l.emplace(k-1, a-b);
      else
        r.emplace(n-k-1, b-a);
    }
    priority_queue<int> que;
    for (int i = (int)l.size()-1; i >= 0; i--) {
      while (!l.empty() && l.top().first >= i) {
        que.push(l.top().second);
        l.pop();
      }
      if (!que.empty()) {
        ans += que.top();
        que.pop();
      }
    }
    que = priority_queue<int>();
    for (int i = (int)r.size()-1; i >= 0; i--) {
      while (!r.empty() && r.top().first >= i) {
        que.push(r.top().second);
        r.pop();
      }
      if (!que.empty()) {
        ans += que.top();
        que.pop();
      }
    }
    cout << ans << '\n';
  }
  return 0;
}

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

int main() {
  long long int a[3];
  for (int i = 0; i<3; i++) cin >> a[i];
  sort (a, a+3);
  if (!(a[0]%2==0||a[1]%2==0||a[2]%2==0))
    cout << a[0]*a[1] << endl;
  else 
    cout << "0" << endl;
  return 0;
}
    


Measured memory_bytes: 256
const main = stdin => {
  const input = stdin.trim().split('\n')
  const [A, B, C] = stdin.trim().split(' ').map(x => parseInt(x))
  A + B + C >= 22 ? console.log('bust') : console.log('win')
}

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


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

int measure(vector<vector<int>> &data,int i,int time)
{
    if(i == N-1)
    {
        return time;
    }
    
    
    int t;
    if(data[i][1] > time)
    {
        t = data[i][1]  + data[i][0];
    }
    else
    {
        if(time%data[i][2] == 0)
        {
            t = time + data[i][0];
        }
        else
        {
            t = time + (data[i][2] - time%data[i][2]) + data[i][0];
        }
    }
    
    t = measure(data,i+1,t);
    
    return t;
}


int main()
{
    
    cin >> N;
    
    vector<vector<int>> data(N,vector<int>(3));
    for(int i = 0;i<N-1;i++)
    {
        for(int j = 0;j<3;j++)
        {
            cin >> data[i][j];
        }
    }
    
    for(int i = 0;i<N;i++)
    {
        int ans;
        ans = measure(data,i,0);
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int count1,count2,i,j,b;
	char a[100];
	scanf("%s",a);
	count1=0;
	count2=0;
	b=strlen(a);
	for(i=0;i<b;i++)
	{
		if(a[i]=='C') 
		{
			count1+=i;
			for(j=count1+1;j<b;j++)
			{
			    if(a[j]=='F')
			    {
			    	count2+=j;
			    }
			}
			break;
		}
	}
	if(count1<count2)printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		long a = nl();
		double aa = a;
		long b = nl();
		double bb = b;
		long n = nl();

		long x = 0l;
		if (n >= b - 1) {
			x = b - 1;
		} else {
			x = n;
		}
		double xx = x;

		long siki = (long) (aa * xx / bb) - a * (long) (xx / bb);

		out(siki);

	}

	public static int count(String search, String text) {
		int nsearch = search.length();
		int ntext = text.length();
		int count = 0;

		for (int i = 0; i <= ntext - nsearch + 1; i++) {
			for (int j = i + nsearch - 1; j < ntext; j++) {
				if (search.equals(text.substring(i, j + 1))) {
					count++;
				}
			}
		}

		return count;
	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

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

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

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static int max(int a, int b) {
		return Math.max(a, b);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}


Measured memory_bytes: 35804
#include <bits/stdc++.h>
#define i64 long long
#define all(x) x.begin(), x.end()
#define LB(x,v) lower_bound(all(x),v) - x.begin()
using namespace std;

int main() {
	// your code goes here
	int n,val,maxVal = 0,avg; cin>>n;
	i64 sum = 0;
	vector<int>d(n);
	for(int i=0;i<n;i++) {
		cin>>d[i];
		sum+=d[i];
		//d.push_back(val);
		maxVal = max(maxVal,d[i]);
	}
	sort(all(d));
	//for(int i=0;i<n;i++) printf("%d ",d[i]);
	//printf("%d\n",(int)(sum/(i64)n));
	
	int cnt = 0;
	for(val=d[n/2-1]; val<=d[n/2]; val++){
		int idx = LB(d,val);
		if(d[idx] < val) idx++;
		idx = min(idx,n-1);
		if(idx > 0){
			if(d[idx-1] == val) idx--;
		}
		idx = max(0,idx);
		if(idx == n-idx) cnt++;
		//printf("val : %d , idx : %d,  n-idx : %d,  d[idx] : %d\n",val,  idx, n-idx, d[idx]);
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9
#define MAX_N 200001

using namespace std;

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

int a[MAX_N], b[MAX_N];
int sorted_b[29][MAX_N];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> b[i];
    }
    
    int MOD = 1;
    for (int k = 0; k < 29; ++k) {
        MOD *= 2;
        for (int i = 0; i < N; ++i) {
            sorted_b[k][i] = b[i] % MOD;
        }
        sort(sorted_b[k], sorted_b[k] + N);
    }

    MOD = 1;
    int ans = 0;
    for (int k = 0; k < 29; ++k) {
        MOD *= 2;
        int num = 0;
        for (int i = 0; i < N; ++i) {
            int tmp_a = a[i] % MOD;
            int u = MOD - 1 - tmp_a, l = MOD / 2 - tmp_a;
            if (l >= 0) {
                num = (num + int(upper_bound(sorted_b[k], sorted_b[k] + N, u)
                           - lower_bound(sorted_b[k], sorted_b[k] + N, l))) % 2;
            } else {
                int ub = int(upper_bound(sorted_b[k], sorted_b[k] + N, u)
                             - sorted_b[k]);
                int lb = int(sorted_b[k] + N
                             - lower_bound(sorted_b[k], sorted_b[k] + N, l + MOD));
                num = (num + (ub + lb)) % 2;
            }
        }
        if (num == 1) {
            ans += MOD / 2;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 24576
#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        tank = []
        while par[x] >= 0:
            tank.append(x)
            x = par[x]
        for elt in tank:
            par[elt] = x
        return x
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

n,m = map(int, input().split())
par = [-1] * n
for i in range(m):
  a,b = map(int,input().split())
  unite(a-1,b-1)

ans = set([])
for i in range(n):
  ans.add(find(i))
print(len(ans)-1)

Measured memory_bytes: 18172
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    for(auto& x: a) cin >> x;

    Vvec<ll> dp(N+1, vector<ll>(N+1));
    for(int l=N-1; l>=0; l--){
        for(int i=0; i<=l; i++){
            int j = l - i;
            // cout << i << " " << j << endl;
            if(l%2==0){
                dp[i][j] = max(dp[i+1][j] + a[i], dp[i][j+1] + a[N-j-1]);
            }
            else{
                dp[i][j] = min(dp[i+1][j] - a[i], dp[i][j+1] - a[N-j-1]);
            }
        }
    }

    cout << dp[0][0] << endl;
    // for(int i=0; i<=N; i++) debug(dp[i]);
}

Measured memory_bytes: 70784
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	A := ReadInts(N)
	y := 1000
	c := 0
	for i := 0; i < N; i++ {
		if i <= N-2 && A[i] < A[i+1] {
			c += y / A[i]
			y = y % A[i]
		}
		if i == N-1 || A[i] > A[i+1] {
			y += c * A[i]
			c = 0
		}
	}
	fmt.Println(y)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1848
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
char b[2100];
char c[210];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%s",b+i);
	int n=0;
	while(1){
		sprintf(c,"%d",n);
		int t=strlen(c);
		bool dame=false;
		for(int i=0;i+t<=a;i++){
			bool ok=true;
			for(int j=0;j<t;j++)if(b[i+j]!=c[j])ok=false;
			if(ok){dame=true;break;}
		}
		if(!dame){
			printf("%d\n",n);return 0;
		}
		n++;
	}
}

Measured memory_bytes: 1040
n, y = map(int, input().split())
y /= 1000

a = [0]*3
#a[0], y = divmod(y,10)
a[1], a[2] = divmod(y, 5)
ans = [-1]*3

while sum(a)!=n:
    if n-sum(a) >= 4:
        tmp = (n-sum(a))//4
        a[1] -= tmp
        a[2] += tmp*5
    elif n-sum(a) <= -1:
        tmp = sum(a)-n
        a[1] -= tmp*2
        a[0] += tmp
    else:
        tmp = n-sum(a)
        a[1] -= (4-tmp)*2+1
        a[2] += 5
        a[0] += 4-tmp
    if a[1]<0:break
else: ans = a
ans = list(map(int, ans))
print(*ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v){os << " [" << i++ << "]" << x; if (i % 5 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 5 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll A, B, C, D;
  std::cin >> A >> B >> C >> D;

  ll L = A + B;
  ll R = C + D;
  if (L > R) print("Left");
  else if (L < R) print("Right");
  else print("Balanced");

  return 0;
}


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

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] A=new int[n];
        for(int i=0;i<n;i++)A[i]=sc.nextInt();
        int q=sc.nextInt();
        int[] m=new int[q];
        for(int i=0;i<q;i++)m[i]=sc.nextInt();
        boolean[][][] dp=new boolean[q][n+10][2010];
        Arrays.sort(A);
        for(int i=0;i<q;i++)dp[i][0][0]=true;
        //mの要素分
        for(int i=0;i<q;i++){
            //dp使用
            for(int j=0;j<n;j++){
                for(int k=0;k<=m[i];k++){
                    dp[i][j+1][k]|=dp[i][j][k];
                    if(k>=A[j])dp[i][j+1][k]|=dp[i][j][k-A[j]];
                }
            }
            if(dp[i][n][m[i]])System.out.println("yes");
            else System.out.println("no");
        }
        sc.close();
    }
}


Measured memory_bytes: 39364
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
  string s;
  cin>>s;
  string step1="";
  for(int i=0;i<s.length();i++){
    if(s[i]==s[i+1]){
       step1+=s[i];
       if(s[i+1]=='0'){
         step1+="1";
       }else{
         step1+="0";
       }
    }else{
      step1+=s[i];
    }
  }
  string step2="";
  for(int i=0;i<s.length();i++){
    if(step1[i]==step1[i+1]){
       step2+=step1[i];
       if(step1[i+1]=='0'){
         step2+="1";
       }else{
         step2+="0";
       }
    }else{
      step2+=step1[i];

    }
  }
  int ans = 0;
  for(int i=0;i<s.length();i++){
    if(step2[i]!=s[i]){
        ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
#define MAX 40
int distance(int start,int key);
int solve(int l,int r);

int n,pos=0,cout = 0;
int P[MAX],I[MAX],A[MAX];
 
int distance(int start,int key){
  int i,count=0;
  for(i=start;i<MAX;i++){
    if(I[i]!=key)
      count++;
    else break;
  }
  return count;
}
   
int solve(int l,int r){
  int root,d;
  if(l-r>=0)return -1;
  root=P[pos];
  pos++;
  d=distance(0,root);
  if(d>n)return -1;
  solve(l, d);
  solve(d+1, r);
  A[cout++]=root;
  return 0;
}
 
int main(){
  int k,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&k);
    P[i]=k;
  }
  for(i=0;i<n;i++){
      scanf("%d",&k);
      I[i]=k;
  }
  solve(0,n);

  for(i=0;i<n;i++){
    if(i<n-1)printf("%d ",A[i]);
    else printf("%d\n",A[i]);
  }
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
typedef priority_queue<int,vector<int>,greater<int> > small_heap;
typedef priority_queue<int> big_heap;

int main()
{
    ll H;scanf("%lld",&H);
    int cnt=0;
    while(H)
    {
        H/=2;
        cnt++;
    }

    ll ans=1ll<<cnt;
    cout<<ans-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string A;
  cin >> A;
  if(A == "a" || A == "i" || A == "u" || A == "e" || A == "o" ){
    cout << "vowel";
  } else {
    cout << "consonant";
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#define F(n) for(int i=0;i<n;i++)
using namespace std;
int main(void){
int n,k,t,u,v,l;
cin>>n>>k>>t>>u>>v>>l;
int ma=t*v*(k+1);
int a=t*v;
int rest=0;
int temp,acc=0;
vector<bool> d(l,false);
F(n){
	cin>>temp;
	d[temp]=true;
}
F(l){
	if(d[i]){
		rest+=a;
	}
	if(rest>ma){
		rest=ma;
	}
	if(rest!=0){
acc++;
rest--;
	}
	
}
double time=(double)acc/v+(double)(l-acc)/u;
printf("%0.7f\n",time);


	return 0;
}

Measured memory_bytes: 3232
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	string w;

	cin >> w;
	vector<int> chars(26, 0);
	for (char c : w) {
		chars[c - 'a']++;
	}

	for (auto e : chars) {
		if (e % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
n , m = map(int,input().split())
a = []
b = []
for i in range(n):
    a.append(list(input()))
for i in range(m):
    b.append(list(input()))
p = 1
for i in range(n-m+1):
    for j in range(n-m+1):
        if p == 1:
            p = 0
        elif p == 0:
            break
        for k in range(m):
            if p == 1:
                break
            for l in range(m):
                if b[k][l] != a[k+j][l+i]:
                    p = 1
                    break
if p == 0:
    print("Yes")
elif p == 1:
    print("No")

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    string a;
    cin >> a;
    stack<char> s;
    rep(i, a.length())
    {
        if (a[i] == '0')
        {
            s.push('0');
        }
        else if (a[i] == '1')
        {
            s.push('1');
        }
        else if (a[i] == 'B')
        {
            if (!s.empty())
            {
                s.pop();
            }
        }
    }
    stack<char> s2;
    while (s.size() != 0)
    {
        char temp = s.top();
        s2.push(temp);
        s.pop();
    }
    while (s2.size() != 0)
    {
        cout<<s2.top();
        s2.pop();
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>
#define rep(i,beg,end) for(int i=(beg);i<(end);i++)
typedef long long LL;
using namespace std;

int dp[3005][3005]={};
pair<int,int> las[3005][3005]={};
int v[3005][3005];
int main(){
	string a,b;
	cin>>a>>b;
	if(a.length()>b.length())
		swap(a,b);
	int ans=0;
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			las[i][j]=make_pair(i,j);
			v[i][j]=-1;
			if(i-1>=0&&j==0)
				dp[i][j]=dp[i-1][j],las[i][j]=las[i-1][j],v[i][j]=v[i-1][j];
			else if(i==0&&j-1>=0)
				dp[i][j]=dp[i][j-1],las[i][j]=las[i][j-1],v[i][j]=v[i][j-1];
			else if(i-1>=0&&j-1>=0){
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
				if(dp[i-1][j]>dp[i][j-1])
					las[i][j]=las[i-1][j],v[i][j]=v[i-1][j];
				else
					las[i][j]=las[i][j-1],v[i][j]=v[i][j-1];
			}
			if(i-1>=0&&j-1>=0){
				if(a[i]==b[j]){
					if(dp[i-1][j-1]+1>dp[i][j])
						las[i][j]=make_pair(i-1,j-1),v[i][j]=a[i];
					dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
				}
			}else if(a[i]==b[j]){
				if(1>dp[i][j])
					las[i][j]=make_pair(i,j),v[i][j]=a[i];
				dp[i][j]=max(dp[i][j],1);
			}
			//cout<<dp[i][j]<<" ";
			//cout<<las[i][j].first<<","<<las[i][j].second<<" ";
			ans=max(ans,dp[i][j]);
		}
		//cout<<endl;
	}
	//cout<<ans<<endl;
	int cnt=0;
	string tmp;
	for(int i=a.length()-1,j=b.length()-1;;){
		if(cnt==ans)break;
		cnt++;
		tmp+=v[i][j];
		//cout<<char(v[i][j]);
		int ni=las[i][j].first;
		int nj=las[i][j].second;
		i=ni,j=nj;
	}
	for(int i=tmp.length()-1;i>=0;i--){
		cout<<tmp[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 141312
import numpy as np
import cmath
N, D = map(int,input().split())
zas = []
for i in range(0,N):
    za = input().split()
    zai = [int(s) for s in za]
    zai = np.array(zai)
    zas.append(zai)

count = 0
for j in range(0,N-1):
    for k in range(j+1,N):
        zad = zas[j]-zas[k]
        za2 = zad*zad
        zasq = (np.sum(za2))**0.5
        if(zasq.is_integer()):
            count = count + 1

print(count)

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

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T> inline bool chkmax(T &x, const T &y){ return y > x ? x = y, 1 : 0; }
template <typename T> inline bool chkmin(T &x, const T &y){ return y < x ? x = y, 1 : 0; }

#ifdef ONLINE_JUDGE
#define debug(...) ;
#else
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define DEBUG
#endif

//---------------------------------------------------------head----------------------------------------------------

int n;
LL mn = linf;
LL ans;

int main()
{
	scf(n);
	while(n--)
	{
		LL x; scf(x);
		ans += x;
		if(x % 10 != 0) chkmin(mn, x);
	}
	if(ans % 10 == 0) ans -= mn;
	chkmax(ans, 0ll);
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    string n;
    cin >> n;
    int sum=0;
    for(char i : n){
        sum+=(int)(i-48);
    }

    if ((sum%9)==0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

const int boundx = 1010, boundy = 10000;
ll dp[boundx][boundy];
ll v[boundx];
ll c[boundx];

int main(){
	int n, m; cin >> n >> m;
	for( int i = 0; i < m; ++i ){
		int a, b; cin >> a >> b;
		v[i] = a;
		for( int j = 0; j < b; ++j ){
			int k; cin >> k; --k;
			c[i] |= (1<<k);
		}
	}
	/*
	for( int i = 0; i < m; ++i ){
		cout << "cond of " << i << ": " << c[i] << endl;
	}
	*/
	for( int i = 0; i < boundx; ++i ){
		for( int j = 0; j < boundy; ++j ){
			dp[i][j] = inf;
		}
	}
	// 何も選んでなくてもすべての宝箱が開いていない状態
	dp[0][0] = 0;
	for( int i = 0; i < m; ++i ){
		for( int cond = 0; cond < (1<<n); ++cond ){
			dp[i+1][cond] = min(dp[i][cond], dp[i+1][cond]);
			dp[i+1][cond|c[i]] = min( dp[i+1][cond|c[i]], v[i]+dp[i][cond] );
		}
	}
	int ans = dp[m][(1<<n)-1];
	if( ans == inf ) cout << -1 << endl;
	else cout << ans << endl;
}

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

const int MXN = 1e5 + 5;
int n;
int h[MXN];
int dp[MXN];

int Dp(int idx) {
    if(idx == n - 1) return 0; // caso base
    if(dp[idx] != -1) return dp[idx]; // caso dp
    int ans = Dp(idx + 1) + abs(h[idx] - h[idx + 1]);
    if(idx + 2 < n) ans = min(ans, Dp(idx + 2) + abs(h[idx] - h[idx + 2])); 
    return dp[idx] = ans; // guardar
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    // memset(dp, -1, sizeof dp);
    // cout << Dp(0) << endl;
    for(int i = n - 2; i >= 0; i--) {
        dp[i] = dp[i + 1] + abs(h[i] - h[i + 1]);
        if(i + 2 < n) dp[i] = min(dp[i], dp[i + 2] + abs(h[i] - h[i + 2]));
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 4328
n = int(input())
p_list = [int(input()) for _ in range(n)]

q_dict = {0:0}
for i in range(n):
    q_dict[p_list[i]] = i
length = 0
ans = 1
for i in range(1, n+1):
    if q_dict[i] > q_dict[i-1]:
        length += 1
        if length > ans:
            ans = length
    else:
        length = 1
print(n - ans)


Measured memory_bytes: 34976
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
using namespace std;

#define ll long long
//#define int long long
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

#define dump(x)  cerr << #x << " = " << (x) << endl; 
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 


typedef pair<int, int> P;
struct Point{
	int x, y;
};
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = {1,0,-1,0};


int N, M, X, Y;
int x[101], y[101];

int main(){

	cin >> N >> M >> X >> Y;

	for (int i = 0; i < N; i++){ cin >> x[i]; }
	for (int i = 0; i < M; i++){ cin >> y[i]; }

	for (int Z = X + 1; Z < Y; Z++){
		bool flag = true;
		for (int i = 0; i < N; i++) if (x[i] >= Z) flag &= false;
		for (int i = 0; i < M; i++) if (y[i] < Z) flag &= false;

		if (flag){ cout << "No War"; return 0; }
	}

	cout << "War";

	return 0;
}

Measured memory_bytes: 256
import math

x=int(input())

if x==2:
    print(2)
    exit()

x=x//2*2+1
i=x
while 1:
    flag=True
    for j in range(2,int(i**0.5)+1):
        if i%j==0:
            flag=False
            break
    if flag:
        break
    i+=1

print(i)


Measured memory_bytes: 9284
/**
*    author:  yuya1234
*    created: 10.07.2020 11:39:54
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

  ll k,a,b;
  cin>>k>>a>>b;

  ll sum=1,kt;
  kt=k;
  if(b-a>2)
  {
    kt-=a-1;
    sum+=a-1;
    if(kt%2==0)sum+=(kt/2)*(b-a);
    else
    {
      sum+=(kt/2)*(b-a);
      sum++;
    }
  }
  else
  {
    sum=1+k;
  }

  cout<<sum<<endl;

  return 0;
}

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

#define ll                 long long
#define ull                unsigned long long
#define pii                pair<int, int>
#define pll                pair<ll, ll>
#define mp                 make_pair
#define ff                 first
#define ss                 second
#define sz(x)              (int) x.size()
#define all(v)             v.begin(), v.end()
#define fill(a, b)         memset(a, b, sizeof(a))
#define endl               '\n'

template <typename T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <typename T> inline void smax(T &a, T b) {a = a > b ? a : b;}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}

template <typename T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l); }

const int mod = (int) 1e9 + 7;

inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll) a * b % mod;}

const int inf = (int) 2e9 + 5;
const ll  Inf = (ll) 2e18 + 5;
const int N   = (int) 2e5 + 5;



int solve() {
   int n; Int(n);
   int ok = 1;
   for(int i = 1; i <= n; i++) {
      int x ; Int(x);
      if(x & 1) continue;
      if(x % 3 == 0 or x % 5 == 0) continue;
      ok = 0;
   }
   ok ? puts("APPROVED") : puts("DENIED");
    return 0;
}

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int test = 1, tc = 0;
    //Int(test);
    //cin >> test;
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    int sum=0;
    rep(i,n-1){
        sum+=abs(p[i]-p[i+1]);
    }
    sum+=abs(p[0]); sum+=abs(p[n-1]);
    if(p[0]*(p[1]-p[0])>=0){
        cout<<sum<<endl;
    }else{
        cout<<sum-2*min(abs(p[0]), abs(p[1]-p[0]))<<endl;
    }
    for(int i=1; i<n-1; ++i){
        if((p[i-1]-p[i])*(p[i]-p[i+1])>=0){
            cout<<sum<<endl;
        }else{
            cout<<sum-2*min(abs(p[i-1]-p[i]), abs(p[i]-p[i+1]))<<endl;
        }
    }
    if((p[n-2]-p[n-1])*p[n-1]>=0){
        cout<<sum<<endl;
    }else{
        cout<<sum-2*min(abs(p[n-2]-p[n-1]), abs(p[n-1]))<<endl;
    }
    return 0;
}

Measured memory_bytes: 3780
import sys
input = sys.stdin.readline

# from collections import deque

def linput(_t=int, cnv=list):
    return cnv(map(_t, input().split()))

def gcd(n,m):
    while m: n,m = m, n%m
    return n

def lcm(n,m): return n*m//gcd(n,m)

def main():
    # N = int(input())
    # vA = [int(input()) for _ in [0,]*N]
    A,B,C = linput()
    medN, medD, poiD = A,B,C

    res = 0

    med = A+B
    deli= B+C

    # poison delicious
    if med+1 >= poiD:
        res = deli
    else:
        res = med+1 + B
        # Tak can endup with poison

    print(res)
    # print("No Yes".split()[res])

main()


Measured memory_bytes: 9092
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print("F")
    elif m+f >= 80:
        print("A")
    elif m+f >= 65:
        print("B")
    elif m+f >= 50:
        print("C")
    elif m+f >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")


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

int main() {
  double d,t,s;
  cin >> d >> t >> s;
  if(d/s <= t) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  
  cout << (a.at(a.size() - 1) == b.at(0) and b.at(b.size() - 1) == c.at(0) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main(){
  int x,y;cin>>x>>y;
  int res0,res1,res2,res3;
  res0=res1=res2=res3=1e9+100;
  if(x==-y)res0=1;
  else if(x<=y)res0=y-x;

  if(-x<=y)res1=1+y+x;
  if(x<=-y)res2=1-y-x;
  if(-x<=-y)res3=2-y+x;
  cout<<min({res0,res1,res2,res3})<<endl;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  if (n%2 != 0) {
    cout << 0 << endl;
    return 0;
  }

  sort(a.begin(), a.end());

  int middle = (n)/2;
  int result = a.at(middle) - a.at(middle-1);
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

ll n, t, e;
ll x[100009];

ll dp[100009];

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

    cin >> n >> e >> t;
    rep(i, n) cin >> x[i + 1];

    fill(ALL(dp), inf);
    dp[0] = 0;
    int j = 0;
    ll mn = inf;
    FOR(i, 1, n + 1) {
        while(t <= 2 * (x[i] - x[j + 1])) {
            chmin(mn, dp[j] - 2 * x[j + 1]);
            j++;
        }
        chmin(dp[i], dp[j] + t);
        chmin(dp[i], 2 * x[i] + mn);
    }

    cout << dp[n] + e << endl;

    return 0;
}

Measured memory_bytes: 5216
#include<iostream>
#include<algorithm>
using namespace std;
#define ENDL "\n"

int N, M;
int x[100000];
int d[100000];

int main(){
  cin >> N >> M;
  for(int i=0;i<M;i++){
    scanf("%d", &x[i]);
  }
  sort(x, x+M);
  //
  for(int i=0;i<M-1;i++){
    d[i] = x[i+1]-x[i];
  }
  sort(d, d+M-1);
  long ans = 0;
  for(int i=0;i<M-N;i++){
    ans += d[i];
  }
  cout << ans << ENDL;
  //
  return 0;
}


Measured memory_bytes: 1024
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
# stdin = open("sample.txt")


MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr


    
def main():
    n = int(stdin.readline().rstrip())
    a_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    a = sorted(a_kari,reverse=True)
    ans = 0
    
    for i in range(n-1):
        if i == 0:
            ans += a[0]
        else:
            ans += a[(i+1)//2]
    print(ans)

main()

Measured memory_bytes: 50204
MOD = 10 ** 9 + 7
N = gets.to_i
A = gets.split.map(&:to_i)
bits = Array.new(60, 0)
A.each do |v|
  60.times do |i|
    bits[i] += 1 if v[i] > 0
  end
end
puts 60.times.inject(0){|s,i| (s + (1 << i) * (bits[i] * (N - bits[i]))) % MOD}

Measured memory_bytes: 36868