akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
using namespace std;
int n;
bool flag=1;
long long sum=0,m=1e18;
int main()
{
	ios_base::sync_with_stdio(0);
	for (cin>>n;n--;)
	{
		long long x,y;
		cin>>x>>y;
		sum+=x;
		flag&=(x==y);
		if (x>y) m=min(m,y);
	}
	if (flag) cout<<"0\n";
	else cout<<sum-m<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1 << 60);

int N, K;
int d[10];

bool ok(int x){

	while(x > 0){
		int dd = x % 10;
		if(d[dd] == 0) return false;
		x /= 10;
	}
	return true;
}

int main() {
	cin >> N >> K;
	rep(i, 10) d[i] = 1;
	rep(i, K) {
		int h; cin >> h; d[h] = 0;
	}

	for(int x = N; x <= 99999; x++){
		if(ok(x)) {
			cout << x << endl; break;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//arc064_c Boxes and Candies
// 隣り合う値がx以下
// 左から見ていって、右側を削ればよいのでは 右が０なら左を削る
int main(){
  ll N ,X,res;
  cin >> N >> X;

  ll a[N];

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

  ll kesu;
  ll cnt = 0;

  for(ll i = 0; i < N-1; ++i)
  {
    if(a[i] + a[i+1] > X)
    {
      kesu = a[i] + a[i+1] - X;
      if(a[i+1] < kesu)
      {
        a[i+1] = 0;
        //a[i]は使わないので修正しない
      }
      else
      {
        a[i+1] -= kesu; 
      }
      cnt += kesu;
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1024
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()
        {
            var N = Sarray()[0];
            var ai = Sarray();
            WriteLine(ai.Sum() - N);
        }
 
        static long Mod = 998244353;
        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: 28836
import java.util.*;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);

        // 整数の入力
        int n = sc.nextInt();
        int t = sc.nextInt();
        int ans = 1001;

        for(int i = 0; i < n; i++) {
            int c = sc.nextInt();
            if (sc.nextInt() <= t && c < ans) {
                ans = c;
            }
        }

        // 出力
        System.out.println(ans == 1001 ? "TLE" : ans);
    }
}


Measured memory_bytes: 21588
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	if n >= 30 {

		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1776
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){
    if(a < b) swap(a,b);
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

int main(){

    ll N, M;
    cin >> N >> M;

    string s, t;
    cin >> s;
    cin >> t;

    bool DEBAG = false;
    ll len = lcm(N, M);
    if(DEBAG) cout << len << endl;

    ll n = len / N;
    ll m = len / M;
    ll step = lcm(n, m);

    for(ll i = 0; i < len; i+= step){
        if(s[i/n] != t[i/m]  ){
            cout << -1 << endl;
            return 0;
        }
    }


    cout << len << endl;

}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){
  int a, b;
  scanf("%d %d", &a, &b);
  
  if(a >= 13){
    printf("%d", b);
  }else if(a>=6 && a<=12){
    printf("%d", b/2);
  }else{
    printf("%d", 0);
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  int max = 0;
  int total = 0;
  int tmp;
  for(int i = 0;i < n ;i++){
     cin >> tmp;
     if(max <= tmp){
       total += max;
       max = tmp;
     }
     else total += tmp;
  }
  if(max < total) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 10000000000000007LL
#define ll long long
using namespace std;
vector<int> nex[214514];
int used[214514];
signed main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		int k;
		cin>>k;
		for(int j=0;j<k;j++){
			int x;
			cin>>x;
			nex[i].pb(100000+x);
			nex[100000+x].pb(i);
		}
	}
	queue<int> que;
	que.push(0);
	used[0] = 1;
	while(!que.empty()){
		int cur = que.front();que.pop();
		for(int i=0;i<nex[cur].size();i++){
			int nx = nex[cur][i];
			if( used[nx] == 0){
				used[nx] = 1;
				que.push(nx);
			}
		}
	}
	for(int i=0;i<n;i++){
		if(used[i] == 0){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 10740
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

struct UnionFind{
private:
    vector<int> par;

public:
    UnionFind(int n=0): par(n,-1){ }

    int find(int x){
        if(par[x]<0) return x;
        else return par[x] = find(par[x]);
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }

    bool unite(int x, int y){
        x = find(x); y = find(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[find(x)];
    }

    int count_group(){
        int c = 0;
        rep(i,par.size()){
            if(par[i]<0) c++; 
        }
        return c;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x,y;
    cin >> x >> y;
    UnionFind uf(12);
    uf.unite(0,2);
    uf.unite(0,4);
    uf.unite(0,6);
    uf.unite(0,7);
    uf.unite(0,9);
    uf.unite(0,11);
    uf.unite(3,5);
    uf.unite(3,8);
    uf.unite(3,10);
    if(uf.same(x-1,y-1)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    debug(2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    int x; cin >> x;
    vector<int> dp(x + 1, 0);
    dp[0] = 1;
    for (int i = 0; i <= x; i++) {
        if (i + 100 <= x) dp[i + 100] += dp[i];
        if (i + 101 <= x) dp[i + 101] += dp[i];
        if (i + 102 <= x) dp[i + 102] += dp[i];
        if (i + 103 <= x) dp[i + 103] += dp[i];
        if (i + 104 <= x) dp[i + 104] += dp[i];
        if (i + 105 <= x) dp[i + 105] += dp[i];
    }
    cout << (bool)dp[x] << endl;
}

Measured memory_bytes: 640
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()

co = sum(a)
su = 0
for i in range(n):
    su += a[i]
    if su >=co/2:
        k,l = i-1,i
        break
print(min(abs(2*su-co),abs(co-2*(su-a[l]))))

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

using namespace std;

int main(){
  int a,b,c,d,train,bus;
  cin >> a >> b >> c >> d;
  
  if(a<b)train = a;
  else train = b;

  if(c<d)bus=c;
  else bus = d;
  
  cout << bus + train << endl;
}


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

struct Tree{
    int val = -1;
    Tree *L = NULL, *R = NULL;
};

Tree* build(int &pos, string s){
    Tree* tree = new Tree;
    if(pos==s.npos || s[pos] == ')'){
        pos++;
        return tree;
    }
    else if(s[pos] == '('){
        pos++;
        tree->L = build(pos, s);
    }
    if(s[pos] == '['){
        int val = 0;
        while(s[++pos] != ']'){
            val *= 10;
            val += s[pos]-'0';
        }
        tree->val = val;
        pos+=2;
        tree->R = build(pos, s);
    }
    pos++;
    return tree;
}

Tree* merge(Tree *a, Tree *b){
    Tree *tree = new Tree;
    if(a->val != -1 && b->val != -1){
        tree->val = a->val + b->val;
        if(a->L != NULL && b->L != NULL){
            tree->L = merge(a->L, b->L);
        }
        if(a->R != NULL && b->R != NULL){
            tree->R = merge(a->R, b->R);
        }
    }
    return tree;
}

string dfs(Tree *tree){
    string res = "";
    if(tree->val != -1){
        res.push_back('(');
        if(tree->L != NULL){
        res += dfs(tree->L);
        }
        res.push_back(')');
    
        res.push_back('[');
        res += to_string(tree->val);
        res.push_back(']');
    
        res.push_back('(');
        if(tree->R != NULL){
            res += dfs(tree->R);
        }
        res.push_back(')');
    }
    return res;
}

int main() {
    string A, B;
    cin >> A >> B;
    Tree *a, *b, *c;
    int pos = 0;
    a = build(pos, A);
    pos = 0;
    b = build(pos, B);

    c = merge(a, b);

    string ans = dfs(c);

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



Measured memory_bytes: 3408
#include <bits/stdc++.h>
using namespace std;
using sint = int64_t;

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

template<class T> vector<T> read_vector(sint n) {
	vector<T> vs;
	for (sint i = 0; i < n; ++i) {
		vs.push_back(read<T>());
	}
	return vs;
}

inline void write() {
}

template<class T> void write(T const& t) {
	cout << t;
}

template<class T> void write(vector<T> const& ts) {
	if (ts.size() > 0) {
		cout << ts[0];
	}
	for (size_t i = 1; i < ts.size(); ++i) {
		cout << ' ' << ts[i];
	}
}

template<class T, class... Args> void write(T const& t, Args const&... args) {
	cout << t << ' ';
	write(args...);
}

template<class... Args> void writeln(Args const&... args) {
	write(args...);
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin .exceptions(ios_base::badbit | ios_base::failbit);
	cout.exceptions(ios_base::badbit | ios_base::failbit);
	cin .tie(nullptr);
	cout.tie(nullptr);
	cout.precision(16);
	void run();
	run();
	return 0;
}

void run() {
	auto const N = read<sint>();
	auto const S = read<string>();
	auto const T = read<string>();
	string r;
	for (sint i = 0; i < N; ++i) {
		r += S[i];
		r += T[i];
	}
	writeln(r);
}

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

int main()
{
	int D1, D2, M1, M2;
  	cin >> M1 >> D1 >> M2 >> D2;
  
 	if(M1 != M2)cout << 1 << endl;
  	else cout << 0 << endl;
  	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  all-algorithm
//
//  Created by JAEYONG BAE on 11/01/2020.
//  Copyright © 2020 JAEYONG BAE. All rights reserved.
//

#include <iostream>

using namespace std;

int K,X;

int main(int argc, const char * argv[]) {

    cin>>K>>X;
    
    if(500*K < X)
        cout<<"No\n";
    else
        cout<<"Yes\n";
    
    return 0;
}


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

#define ll long long
#define ld long double
#define xx first
#define yy second
#define vi vector<int>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()

#define MAX 400005

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

    vector<ll> a(5);

    ll ans =0;
    for(int i = 0;i<5;i++)
    {
        cin >> a[i];

        if(a[i] == 0)
            ans = i+1;
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <tuple>
#include <cassert>
#include <bitset>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a + b > a - b && a + b > a * b) cout << a + b << endl;
    else if(a - b > a * b) cout << a - b << endl;
    else cout << a * b << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin>>n;
  vector<int> v;
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    v.push_back(tmp);
  }
  sort(v.begin(),v.end());
  cout<<v[n-1]-v[0]<<endl;
  return 0;
}


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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = int64_t;
using ld = double;
const ld EPS = 1e-9;
//const ll MOD = 924844033;
const ld PI = 3.141592653589793;
const int maxn = 300001;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

vector<array<int, 4>> quer;
vector<int> vals;
int n, m;
int ans = 0;

void dfs(int i) {
    if (i == n + 1) {
        int cur = 0;
        for (auto &x:quer) {
            if (vals[x[1]] - vals[x[0]] == x[2]) {
                cur += x[3];
            }
        }
        ans = max(ans, cur);
        return;
    }
    for (int e = vals[i - 1]; e <= m; ++e) {
        vals[i] = e;
        dfs(i + 1);
    }
}

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    fast_io();
    cout.precision(6);
    cout << fixed;
    auto start = chrono::steady_clock::now();
    int q;
    cin >> n >> m >> q;
    quer.resize(q);
    for (int i = 0; i < q; ++i) {
        for (int e = 0; e < 4; ++e) {
            cin >> quer[i][e];
        }
    }
    vals.resize(n + 1);
    vals[0] = 1;
    dfs(1);
    cout << ans;
    auto end = chrono::steady_clock::now();

    debug("time", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);

}



Measured memory_bytes: 3660
#include <iostream>

using namespace std;

typedef long long ll;

int main(void)
{
    ll N;
    ll A[100000];
    cin >> N;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll p = 0;
    ll min = A[0] < 0 ? A[0] * -1 : A[0];
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        if (A[i] < 0) {
            p = 1 - p;
            A[i] = A[i] * -1;
        }
        min = min < A[i] ? min : A[i];
        ans += A[i];
    }
    if (p == 1) {
        ans -= min * 2;
    }
    cout << ans << endl;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll ans;
vector<vector<ll> > vv(60000);

bool check(ll n){
	ll nn=n;
	ll c3=0;
	ll c5=0;
	ll c7=0;
	while(1){
		if(nn%10==3) c3=1;
		if(nn%10==5) c5=1;
		if(nn%10==7) c7=1;
	   nn/=10;	
		if(nn==0) break;
	}
	if(c3&&c5&&c7) return true;
	else return false;
}

int main(){

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

cin>>N;

vv[0].pb(3);
vv[0].pb(5);
vv[0].pb(7);

for(ll i=1; i<=10; i++){
	for(ll j=0; j<vv[i-1].size(); j++){
		ll add1=3*pow(10,i)+vv[i-1][j];
		ll add2=5*pow(10,i)+vv[i-1][j];
		ll add3=7*pow(10,i)+vv[i-1][j];
		vv[i].pb(add1);
		vv[i].pb(add2);
		vv[i].pb(add3);
	}
}

for(ll i=2; i<=10; i++){
	for(ll j=0; j<vv[i].size(); j++){
		if(vv[i][j]<=N){
			if(check(vv[i][j])) ans++;
		}
	}
}

cout<<ans<<endl;

}
	

  

Measured memory_bytes: 4852
#include<iostream>
#include<cstdio>
#define ll long long
#define maxn 400040
#define re register
using namespace std;
const int mo=1000000007;

int n,a[maxn],b[maxn],c[maxn];
ll f[4040][4040],ans,p[maxn];

inline int ksm(int x,int y)
{
	int ans=1;
	while(y)
	{
		if(y&1) ans=(ll)ans*x%mo;
		x=(ll)x*x%mo;
		y>>=1;
	}
	return ans;
}

int main()
{
	scanf("%d",&n); int m=0;

	for(re int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		m=max(m,max(a[i],b[i]));
	}
	for(re int i=1;i<=n;i++)f[m+a[i]][m+b[i]]++;

	c[0]=p[0]=1;
	for(re int i=1;i<=m*4;i++) c[i]=(ll)c[i-1]*i%mo,p[i]=ksm(c[i],mo-2)%mo;

	for(re int i=m*2;i>=0;i--)
		for(re int j=m*2;j>=0;j--)
			f[i][j]=(f[i][j]+f[i+1][j]+f[i][j+1])%mo;

	for(re int i=1;i<=n;i++) ans=(ans+f[m-a[i]][m-b[i]])%mo;
	for(re int i=1;i<=n;i++) ans=(ans-(ll)c[a[i]*2+b[i]*2]*p[a[i]*2]%mo*p[b[i]*2]%mo)%mo;

	ans=(ans*ksm(2,mo-2))%mo;

	printf("%lld\n",(ans+mo)%mo);
}

Measured memory_bytes: 133376
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 20


int main() {
	char a[N];
	f(i, N)a[i] = 0;
	char b[N];
	f(i, N)b[i] = 0;
	int n, k;
	vector<int>pr;
	vector<int>pb;
	char c[400];
	f(i, 400)c[i] = 0;
	long long x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	int l = 1;
	int r = n+1;
	int m;
	printf("?");
	f(i, n)printf(" %d", i+1);
	printf("\n");
	fflush(stdout);
	scanf("%s", b);
	while ((l + 1) < r) {
		m = (l + r) / 2;
		printf("?");
		f(i, n)printf(" %d", m + i);
		printf("\n");
		fflush(stdout);
		f(i, N)a[i] = 0;
		scanf("%s", a);
		if (a[0] == b[0])l = m;
		else r = m;
	}
	f(i, 2 * n) {
		if (((i + 1) < r) || ((i + 1) > (l + n-1))) {
			printf("?");
			printf(" %d", i + 1);
			f(j, n-1)printf(" %d", r + j);
			printf("\n");
			fflush(stdout);
			f(i, N)a[i] = 0;
			scanf("%s", a);
			c[i] = a[0];
			if (a[0] == 'R') {
				if (pr.size() < ((n - 1) / 2))pr.push_back(i + 1);
			}
			else {
				if (pb.size() < ((n - 1) / 2))pb.push_back(i + 1);
			}
		}
	}
	f(i, 2 * n) {
		if (((i + 1) > l) && ((i + 1) < (l + n))) {
			printf("?");
			printf(" %d", i + 1);
			f(j, pr.size())printf(" %d", pr[j]);
			f(j, pb.size())printf(" %d", pb[j]);
			printf("\n");
			fflush(stdout);
			f(i, N)a[i] = 0;
			scanf("%s", a);
			c[i] = a[0];
		}
	}
	printf("! %s\n", c);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 724
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
Int gcd(Int a, Int b) {
    Int M = max(a, b);
    Int m = min(a, b);
    while (true) {
        Int r = M % m;
        if (r == 0) break;
        M = m;
        m = r;
    }
    return m;
}
int main() {
    int n, k;
    cin >> n >> k;
    if (n == 1) {
        Int a;
        cin >> a;
        puts(a == k ? "POSSIBLE" : "IMPOSSIBLE");
        return 0;
    }
    Int g;
    auto v = vector<Int>(0);
    rep(i, n) {
        Int a;
        cin >> a;
        v.PB(a);
        if (i == 1) {
            g = gcd(v[0], a);
        } else if (i >= 2) {
            g = gcd(g, a);
        }
    }
    sort(ALL(v), greater<Int>());
    auto m = v[0];
    puts(k <= m && (m - k) % g == 0 ? "POSSIBLE" : "IMPOSSIBLE");
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int64 N, K;
int64 ptoi(int64 y, int64 x) {
  return y * N + x;
}

PLL itop(int64 p) {
  return PLL(p / N, p % N);
}

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

  cin >> N >> K;

  mcf_graph<int64, int64> mcf(N*N+2*N+2);
  vector<string> res(N, string(N, '.'));
  int64 S = N*N+2*N, G = N*N+2*N+1;
  int64 br = N*N, bc = N*N+N;

  auto A = make_v<int64>(N, N);
  REP(i, N) {
    REP(j, N) cin >> A[i][j];
  }

  REP(i, N) {
    mcf.add_edge(S, br+i, K, 0);
    mcf.add_edge(bc+i, G, K, 0);
    REP(j, N) {
      mcf.add_edge(br+i, bc+j, 1, INF-A[i][j]);
    }
  }
  mcf.add_edge(S, G, 2*N*K, INF);
  PLL ret = mcf.flow(S, G, N*K);

  cout << ret.fs * INF - ret.sc << endl;

  for (auto &e : mcf.edges()) {
    if (e.flow == 1 && 0 <= e.from - br && e.from - br < N && 0 <= e.to - bc && e.to - bc < N) {
      res[e.from - br][e.to - bc] = 'X';
    }
  }
  REP(i, N) cout << res[i] << endl;
}


Measured memory_bytes: 3940
#include<iostream>
#include<cstdio>
#include<ctype.h>
#include<cstring> 
using namespace std;
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
char c[17],a[17];
int main(){
	scanf("%s",c+1);int l=strlen(c+1),p=0;
	for(int i=1;i<=l;++i){
		a[++p]=c[i];
		if(c[i]=='B')p=max(0,p-2);
	}
	for(int i=1;i<=p;++i)printf("%c",a[i]);
	return 0;
}

Measured memory_bytes: 256
a,b,c = gets.chomp.split.map(&:to_i)
@cnt = 0
def max(a,b,c)
  max = [a,b,c].max
  [a,b,c].each do |i|
    @cnt += (max - i)/2
  end
end

if a%2 == b%2 && b%2 == c%2
   max(a,b,c)
else
  @cnt += 1
  if a%2 == b%2
    a += 1
    b += 1
    max(a,b,c)
  elsif b%2 == c%2
    b += 1
    c += 1
    max(a,b,c)
  else
    c += 1
    a += 1
    max(a,b,c)
  end
end
puts @cnt


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int N;
lint x;
vector<int> a;

int main()
{
    cin >> N >> x;
    a.resize(N);
    REP(i, N) cin >> a[i];
    sort(a.begin(), a.end());
    int ans = 0;
    lint accum = 0;
    REP(i, N) if (accum + a[i]<= x)
    {
        accum += a[i];
        ans++;
    }
    if (ans == N)
    {
        if (accum == x) cout << ans << endl;
        else cout << ans - 1 << endl;
    }
    else cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
ab = []
cd = []
ans = 0
item = set()

for _ in range(n):
    a,b = map(int,input().split())
    ab.append((a,b))

for _ in range(n):                                                                                                               
    c,d = map(int,input().split())
    cd.append((c,d))

cd.sort()

for i in cd:
    c,d = i
    li = []
    for j in ab:
        a,b = j
        if a < c and b < d:
            li.append((a,b))
    li.sort(key=lambda x:(x[1]*(-1),x[0]))
    for k in li:
        if k not in item:
            ans += 1
            item.add(k)
            break

print(ans)

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

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

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  ll N, K;
  scanf("%lld %lld", &N, &K);

  string str;
  cin >> str;

  ll k = K - 1;

  str[k] = 'a' + (str[k] - 'A');

  cout << (str) << endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll n, W;
  cin >> n >> W;
  vll w(n), v(n);
  rep(i, n) {
    cin >> w[i] >> v[i];
  }

  vll dp(100110, INF);
  dp[0] = 0;
  rep(i, n) {
    for (int j = 100001; j >= 0; j--) {
      if (j - v[i] >= 0) {
        chmin(dp[j], dp[j - v[i]] + w[i]);
      }
    }
  }

  ll ans = 0;
  rep(i, 100001) {
    if (dp[i] <= W) {
      ans = i;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<ctype.h>
char z[]="abcdefghijkimnopqrstuvwxyz";
char x[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
char s[1201];
int i;
int n;
gets(s);
n=strlen(s);
for(i=0;i<n;i++){
	
	if(strchr(z,s[i])){
		
		printf("%c",toupper(s[i]));
		
		
		
	}else if(strchr(x,s[i])){
		
		
		printf("%c",tolower(s[i]));
		
		
	}else{
		
		printf("%c",s[i]);
		
		
	}
	
	
	
	
	
	
	
}
printf("\n");
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int N, T;
    cin >> N >> T;
    valarray<int> table(T);
    rep(i, N){
        int l, r; cin >> l >> r;
        table[l]++;
        table[r]--;
    }
    for(int i = 0; i < T-1; i++) table[i+1] += table[i];
    cout << table.max() << endl;
}



Measured memory_bytes: 3120
N=int(input())

ans=[]
for i in range(1,N//2*2+1):
    for j in range(i+1,N//2*2+1):
        if j==N//2*2-i+1:
            continue
        else:
            ans.append([i,j])
if N%2==1:
    for i in range(1,N):
        ans.append([i,N])

print(len(ans))
for item in ans:
    print(*item)


Measured memory_bytes: 4124
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
inline ll read()
{
	char s;
	ll k=0,base=1;
	while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if(s==EOF)exit(0);
	if(s=='-')base=-1,s=getchar();
	while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
	return k*base;
}
ll find(ll x,ll y)
{
	if (y>=x) return y+1; else return y;
}
ll q,x,y;
bool check(ll s)
{
	ll d=s/2;
	for (ll i=d-200;i<=d+200;i++)
	{
		if (i>0&&i<=s)
		{
			if (find(x,i)*find(y,s-i+1)>=x*y) return 0;
		}
	} 
	return 1;
} 
int main()
{
	q=read();
	while (q--)
	{
		x=read();y=read();
		ll l=0,r=2e9,ans=0;
		while(l<r)
		{
			ll mid=(l+r+1)/2;
			if (check(mid)) l=mid; else r=mid-1;
		}
		printf("%lld\n",l);
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long x = Long.parseLong(sc.next());
        long[] y = new long[n];
        long[] dif = new long[n];
        for(int i=0; i<n; i++) {
            y[i] = Long.parseLong(sc.next());
            dif[i] = zettai(x, y[i]);
        }
        
        long ans;
        if(n == 1) {
            ans = dif[0];
        }else {
            ans = saiyaku(dif[0], dif[1]);
            for(int i=2; i<n; i++) {
                if(ans > saiyaku(dif[i], dif[i-1])) {
                    ans = saiyaku(dif[i], dif[i-1]);
                }
            }
        }
        System.out.println(ans);
        
    }
    
    static long zettai(long a, long b) {
        if(a <= b) return b-a;
        else return a-b;
    }
    
    static long saiyaku(long a, long b) {
        if(a < b) {
            return saiyaku(b, a);
        }else {
            long w = b;
            if(b == 0) {
                return a;
            }else {
                b = a % b;
                a = w;
                return saiyaku(a, b);
            }
        }
    }
}


Measured memory_bytes: 47888
import collections
n=int(input())
A=list(map(int,input().split()))
x=0
lst=[]
for i in range(n):
    x+=A[i]
    lst.append(x)
c=collections.Counter(lst)

 
def conv(n,m):
    if n==m or m==0:
        return 1
    else:
        return conv(n-1,m-1)+conv(n-1,m)
ans=0
for k in c.keys():
    if c[k]==1:
        if k==0:
            ans+=1
        else:
            continue
    elif k==0:
        ans+=c[k]+int(c[k]*(c[k]-1)/2)
    else:
        ans+=int(c[k]*(c[k]-1)/2)
print(ans)
    

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

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
using namespace std;
const ll mod = 1e9 + 7;



//ll fact[1000001]; ll inv[1000001];
//ll primes[100007];
//ll arr[1000007];
//ll modPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//
//	ll halfpow = modPower(b, p / 2);
//	ll toReturn = (halfpow * halfpow) % mod;
//	if (p % 2)
//		toReturn = (toReturn * b) % mod;
//
//	return toReturn;
//}
//
//ll fastPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//	ll ans = fastPower(b, p / 2);
//	ans = (ans * ans);
//	if (p % 2 != 0)
//		ans = (ans * b);
//	return ans;
//}
//ll GcdRecursive(ll a, ll b) {
//	if (b == 0) return a;
//	return GcdRecursive(b, a % b);
//}
//ll modLCM(ll a, ll b) {
//	ll val = GcdRecursive(a, b);
//	ll tmp = ((a % mod) * (b % mod)) % mod;
//	ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
//	return finalVal;
//
//}
//ll LCM(ll a, ll b) {
//	return (a * b) / GcdRecursive(a, b);
//}
//void move1step(ll& a, ll& b, ll q) { // a and b by reference
//	ll c = a - q * b;
//	a = b;
//	b = c;
//}
//ll GcdIterative(ll a, ll b) {
//	while (b) move1step(a, b, a / b);
//	return a;
//}
//
//void pre(ll n) {
//
//	fact[0] = 1;
//	inv[0] = 1;
//
//	for (ll i = 1; i <= n; i++) {
//		fact[i] = (i * fact[i - 1]) % mod;
//		inv[i] = modPower(fact[i], mod - 2);
//		arr[i] = modPower(i, mod - 2);
//	}
//}
//
//ll npr(ll n, ll r) {
//	return ((fact[n] * inv[n - r]) % mod);
//}
//
//ll ncr(ll n, ll r) {
//	return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
//}
//
//void sieve(ll val) {
//	memset(primes, 1, sizeof primes);
//	primes[0] = primes[1] = false;
//	for (int i = 2; i <= val; i++) {
//		if (primes[i]) {
//			for (int j = i * i; j <= val; j += i) {
//				primes[j] = 0;
//			}
//		}
//	}
//
//}











int main()
{
    MohamedMotaz;
    
    ll a, b;
    cin >> a >> b;
    vector<ll> v;
    f(i, 0, a) {
        ll x; cin >> x; v.push_back(x);
    }
    if (b >= a) return cout << 1, 0;
    ll c = 0;
    while (a > 1) {
        c++;
        a -= b;
        a++;
    }
    cout << c << endl;
}








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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main( int argc, char *argv[] ) {
	int res = 0;
	int n, a;
	cin >> n;
	for ( int i = 0 ; i < n ; i++ ){
		cin >> a;
		res += a-1;
	}
	cout << res << "\n";

	return 0;
}


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


int main(){
    int x,y;
    cin >> x >> y;
    int ans = 0;
    if(x==1) ans += 300000;
    if(x==2) ans += 200000;
    if(x==3) ans += 100000;
    if(y==1) ans += 300000;
    if(y==2) ans += 200000;
    if(y==3) ans += 100000;
    if(x==1 && y==1) ans += 400000;
    cout << ans << endl;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  long long N, K, Q;
  cin >> N >> K >> Q;
  vector<long long> A(Q);
  for (int i = 0; i < Q; i++)
  {
    int a;
    cin >> a;
    a--;
    A[i] = a;
  }
  vector<long long> B(N);
  for (int i = 0; i < Q; i++)
  {
    B[A[i]]++;
  }
  for (int i = 0; i < N; i++)
  {
    if (K - Q + B[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}


Measured memory_bytes: 2176
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__



void solve(void){
  
  int K, X;
  cin >> K >> X;
 
  for(int i=-K+1+X; i<K+X-1; i++){
    cout << i << " ";
  }
  cout << K+X-1 << endl;

  return;
   
}

#define TESTCASES	1

int main(int argc, const char * argv[]) {

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

  	REP(i,TESTCASES){
    	solve();
    } 
  
    return 0;
}



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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    vector<int> a(n);
    for (auto &&x : a) cin >> x;

    ll dp[2][n + 1][n + 1];
    for (int size = 1; size <= n; ++size) {
        for (int l = 0; l + size <= n; ++l) {
            if (size == 1) {
                dp[0][l][l] = a[l];
                dp[1][l][l] = -a[l];
            }
            else {
                int r = l + size - 1;
                // 太郎君 maximize
                dp[0][l][r] = max(dp[1][l + 1][r] + a[l],
                                  dp[1][l][r - 1] + a[r]);
                // 次郎君 minimize
                dp[1][l][r] = min(dp[0][l + 1][r] - a[l],
                                  dp[0][l][r - 1] - a[r]);

            }
        }
    }

    cout << dp[0][0][n - 1] << endl;

    return 0;
}


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

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const deque<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}

int main() {
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

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

    sort(A.begin(), A.end());
    // cout << A << endl;

    // 差が最大となるのは /\/\/ or \/\/\/ のように大小交互に並ぶ場合
    // 例えば/\/の場合、差の合計は
    // (b-a)+(b-c)+(d-c) = -a+2b-2c+d となる
    
    // 数列と係数をソートしたものの各項の積の和をw型とm型で比較する

    // 係数の数列
    vector<int> cf_m(N);
    vector<int> cf_w(N);

    for (int i = 0; i < N; i++) {
        if (i%2==0) {
            // 偶数番目
            if(i == 0 || i == N-1) {
                cf_m[i] = -1;
                cf_w[i] = +1;
            } else {
                cf_m[i] = -2;
                cf_w[i] = +2;
            }
        } else {
            // 奇数番目
            if (i == N-1) {
                cf_m[i] = +1;
                cf_w[i] = -1;
            } else {
                cf_m[i] = +2;
                cf_w[i] = -2;
            }
        }
    }
    sort(cf_m.begin(), cf_m.end());
    sort(cf_w.begin(), cf_w.end());
    // cout << cf_m << endl;
    // cout << cf_w << endl;

    long sum_m = 0, sum_w = 0;
    for(int i = 0; i < N; i++) {
        sum_m += A[i] * cf_m[i];
        sum_w += A[i] * cf_w[i];
    }
    cout << max(sum_m, sum_w) << endl;
}


Measured memory_bytes: 1536
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <complex>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i, a, b) for(LL i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-6;
const LL INF = 1e9;
const LL LINF = 8e18;
const LL mod = 1e9 + 7;
const LL MAX = 1e4 + 7;

char ye[26];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	string s;
	cin >> s;
	//FOR(i, 0, 26)
		//s += ('z' - i);
	//swap(s[24], s[25]);
	int n = SZ(s);
	//cout << s << endl;
	if (n == 26)
	{
		int last = -1;
		FOR(i, 0, n - 1)
			if (s[i] <= s[i + 1])
			{
				last = i;
				break;
			}

		if (last == -1)
		{
			cout << -1;
			return 0;
		}

		FOR(i, 0, n)
		{
			bool ok = 1;
			FOR(j, i + 1, n - 1)
				if (s[j] < s[j + 1])
					ok = 0;

			if (!ok)
			{
				cout << s[i];
				ye[s[i] - 'a'] = 1;
				continue;
			}

			for(char j = s[i] + 1; j <= 'z'; ++j)
				if (ye[j - 'a'] == 0)
				{
					cout << j;
					break;
				}

			break;
		}
	}
	else
	{
		FOR(i, 0, n)
			ye[s[i] - 'a'] = 1;
		cout << s;
		FOR(i, 0, 26)
			if (ye[i] == 0)
			{
				cout << (char)(i + 'a');
				break;
			}
	}

	cin >> n;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
is_ok = 0
for i in A:
  if i % 2 == 0:
    if i % 3 != 0 and i % 5 !=0:
      is_ok=1
      break
if is_ok == 0:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060
n = int(input())
a = []
for i in range(n):
    a += [int(input())]
a.sort()
n2 = n // 2

if n % 2:
    ans1 = (sum(a[n2 + 1:]) - sum(a[:n2 + 1])) * 2 + a[n2] + a[n2 - 1]
    ans2 = (sum(a[n2:]) - sum(a[:n2])) * 2 - a[n2] - a[n2 + 1]
    ans = max(ans1, ans2)
else:
    ans = (sum(a[n2:]) - sum(a[:n2])) * 2 - a[n2] + a[n2 - 1]

print(ans)


Measured memory_bytes: 7388
#インプットdataの格納
n, k = map(int, input().split())
n_list = list()
for i in range(n):
    n_list.append(int(input()))

#data処理
left = 0
right = 100000*10000
while (right - left) > 1:
    mid = (left + right) // 2

    i = 0
    for j in range(k):
        weight = 0
        while i < n:
            if (weight + n_list[i]) > mid:
                break
            else:
                weight += n_list[i]
                i += 1

    if i >= n:
        right = mid
    else:
        left = mid
        
#結果表示
print(right)



Measured memory_bytes: 9548
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define P pair<int, int>
#define PP pair<P, P>
#define mk make_pair
#define fi first
#define se second
#define V vector<int>
#define VV vector<V>
#define pb push_back

using namespace std;
typedef long long ll;

int main() {
    string S, T;
    cin >> S >> T;

    int res = 0;
    rep(i, 3) {
        if(S[i] == T[i]) res++;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int desc(const void *a,const void *b){
    return *(long long*)b-*(long long*)a;
}
int main(void){
    int n,m,m1=0,m2=0,i,a;
    scanf("%d%d",&n,&m);
    long long x[n],min=1000000001;
    for(i=0;i<n;i++) scanf("%lld",&x[i]);
    qsort(x,n,sizeof(x[0]),desc);
    for(i=0;i<n-m+1;i++){
        if(min>x[i]-x[i+m-1]) min=x[i]-x[i+m-1];
    }
    printf("%lld",min);
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<lld> vll;
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define srt(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define mod 1000000007
#define pi 3.1415926535
lld a,b,c,d,e,f,g,h,i,j,k=0,l=0,m=1,n=1,o,q=0,r=0,u,v,w,x,y,z,s,t,p=0;
lld temp=0,ans=0;
double f1,f2,f3,f4,f5,f6;
char c2,c3,c4,c5,c6;
vll v11;
pair<lld,lld>p1,p2,p3;
map<lld,lld>mv;bool a12[200005],a13[200005];
bool b11[500006],c11[500006];lld a11[500006];
lld gcd(lld a, lld b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
}
void dfs(lld i,vector<lld>vg[])
{
    if(b11[i]==true)    return;
    v11.pb(i);
    p++;
    b11[i]=true;
    for(auto x11:vg[i])
    {
        if(b11[x11]==false)
        {
            dfs(x11,vg);
        }
    }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  t=1;
  //cin>>t;
  while(t--)
  {
    string s3,s1,s2;
    cin>>a>>b>>c;
    //lld p1,q1,a1,b1,c1,d1;
    //lld a1[n+1]={0},b1[n],c1[n+1];vector<lld>vg[n+1];
    map<lld,lld>m1,m2;queue<lld>q2;vll v1,v2;
    //rep(i,0,n)  cin>>a1[i];
    p=0;
    if((b*c)>=a)    cout<<"Yes";
    else    cout<<"No";
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3660