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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return(gcd(b, a % b));
    }
}


int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    ll a;
    a = x / d;
    if (abs(a) >= k) {
        if (x < 0) {
            x += k * d;
        }
        else {
            x -= k * d;
        }
        cout << abs(x) << endl;
        return 0;
    }
    else {
        ll b, c;
        if (x < 0) {
            x += abs(a) * d;
            c = abs(x + d);
        }
        else {
            x -= a * d;
            c = abs(x - d);
        }
        a = abs(a);
        b = abs(x);
        if ((k - a) % 2 == 0) {
            cout << abs(b) << endl;
            return 0;
        }
        else {
            cout << abs(c) << endl;
            return 0;
        }
    }
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=100100100;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a>=k)cout<<k<<endl;
    if(a<k and a+b>=k)cout<<a<<endl;
    if(a+b<k)cout<<(a+(k-a-b)*(-1))<<endl;
return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#define ll long long
#define ull unsigned long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;

int a[1000000];

int main(){
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	ll sum=0;
	for(int i=0;i<n;i++){
		sum+=a[i]-1;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, S: int):
    if S == 10 ** 9:
        print(" ".join([str(S) for _ in range(K)] + ["1" for _ in range(N - K)]))
    else:
        print(" ".join([str(S) for _ in range(K)] + [str(S + 1) for _ in range(N - K)]))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 11272
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
bool valid(ll n,ll k,vector<ll>&v,vector<ll>&f,ll mid)
{
    ll opr=0;
    for(ll i=0;i<n;i++)
    {
        ll x=v[i]*f[i];
        if(x>mid)
        {
            ll z=floor(mid/(1.0*f[i]));
            opr+=fabs(v[i]-z);
        }
    }
    if(opr<=k)
    {
        return true;
    }
    return false;
}
ll bsearch(ll n,ll k,vector<ll>&v,vector<ll>&f,ll s,ll e)
{
    ll ans=-1;
    while(s<=e)
    {
        ll mid=(s+e)/2;
        if(valid(n,k,v,f,mid))
        {
            ans=mid;
            e=mid-1;
        }else
        {
            s=mid+1;
        }
    }
    return ans;
}
int main()
{
fast;
ll n,k;
cin>>n>>k;
vector<ll>v,f;
for(ll i=0;i<n;i++)
{
    ll a;
    cin>>a;
    v.pb(a);
}
for(ll i=0;i<n;i++)
{
    ll a;
    cin>>a;
    f.pb(a);
}
sort(v.begin(),v.end());
sort(f.begin(),f.end(),greater<ll>());
ll mx=0;
for(ll i=0;i<n;i++)
{
    mx=max(mx,v[i]*f[i]);
}
ll ans=bsearch(n,k,v,f,0,mx);
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 4848
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main() {
	double a[1010];
	double b[1010];
	int n;
	double m = 0;
	double ans = 0;
	int i, j;
	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%lf", &a[i]);
	}
	for (i = 0; i < n; i++) {
		scanf("%lf", &b[i]);
	}
	for (i = 1; i < 4; i++) {
		m = 0;
		for (j = 0; j < n; j++) {
			m += pow(abs(a[j] - b[j]), i);
		}
		printf("%lf\n", pow(m, 1.0 / (double)i));
	}
	m = 0;
	for (i = 0; i < n; i++) {
		m = fmax(m, abs(a[i] - b[i]));
	}
	printf("%lf\n", m);

	return 0;
}


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

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

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int oddcount = 0;
        int evencount = 0;
        int n = s.length();
        for(int i=0;i<n;i++){
        	if(i%2==0){
        		if(s.charAt(i)=='0'){
        			oddcount++;
        		}
        		else{
        			evencount++;
        		}
        	}
        	else{
        		if(s.charAt(i)=='0'){
        			evencount++;
        		}
        		else{
        			oddcount++;
        		}
        	}
        }

        System.out.println(Math.min(oddcount, evencount));
    }
}

Measured memory_bytes: 24228
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	int X,A;
	scanf("%d %d",&X,&A);

	if(X < A){

		printf("0\n");
	}else{

		printf("10\n");
	}

	return 0;
}


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

using ll = long long int;

int main() {
    ll n ,m, ans = 0;
    cin >> n >> m;
    for(ll i=1;i*i<=m;i++){
        if(m%i == 0){
            if(m/i >= n){
                ans = max(ans, i);
            }
            if(i >= n){
                ans = max(ans, m/i);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cstring>
#include <inttypes.h>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

const int cap = 2e5 + 1;
// const int mod = 1e9 + 7;
int N;
int H[cap], A[cap];

int main() {
    scanf("%d", &N);
    for (int i = 1; i <= N; ++i)
        scanf(" %d", &H[i]);
    for (int i = 1; i <= N; ++i)
        scanf(" %d", &A[i]);
    
    H[0] = A[0] = 0;
    map<int, int64_t> dp = {{0, 0}};
    for (int i = 1; i <= N; ++i) {
        auto it = dp.upper_bound(H[i]);
        int64_t val = A[i] + prev(it)->second;

        auto right = it;
        while (right != dp.end() && right->second <= val)
            ++right;
        dp.erase(it, right);

        dp[H[i]] = val;
    }

    printf("%" PRId64 "\n", dp.rbegin()->second);
}





Measured memory_bytes: 14336
use std::cmp;

fn main(){
    let mut sc = Scanner::new();
    while let Ok(n) = sc.wrapped() {
        let mut a = vec![0i32; n];
        for e in a.iter_mut() {
            *e = sc.next();
        }

        let solve = || {
            let mut cnt = vec![0; n+1];
            let mut max = 0;
            for i in 0..n {
                cnt[a[i] as usize] += 1;
                max = cmp::max(max, a[i]);
            }
            for k in 0..max+1 {
                let c = cnt[k as usize];
                if k > (max + 1) / 2 {
                    if c < 2 { return false; }
                } else if k == (max + 1) / 2 {
                    if max%2 == 0 {
                        if c != 1 { return false; }
                    } else {
                        if c != 2 { return false; }
                    }
                } else {
                    if c > 0 { return false; }
                }
            }
            true
        };
        println!("{}", if solve() { "Possible" } else { "Impossible" })
    }
}

#[allow(dead_code)]
struct Scanner {
    token_buffer : Vec<String>,
    index : usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner{
        Scanner { token_buffer: vec![], index: 0 }
    }

    fn wrapped<T>(& mut self) -> Result<T,&str> where T: std::str::FromStr {
        let s = try!(self.fetch_token());
        let t = try!(s.parse::<T>().map_err(|_| "Parse error"));
        Ok(t)
    }
    fn next<T>(& mut self) -> T where T: std::str::FromStr {
        self.wrapped::<T>().unwrap()
    }

    fn fetch_token(&mut self) -> Result<&String,&str> {
        while self.index >= self.token_buffer.len() {
            let mut st = String::new();
            while st.trim() == "" {
                match std::io::stdin().read_line(&mut st) {
                    Ok(l) if l > 0 => continue,
                    Ok(_)  => return Err("End of file"),
                    Err(_) => return Err("Failed to read line"),
                }
            }
            self.token_buffer = st.split_whitespace()
                .map(|x| x.to_string())
                .collect();
            self.index = 0;
        }

        self.index += 1;
        Ok(&self.token_buffer[self.index - 1])
    }
}


Measured memory_bytes: 380
import sys

# sys.stdin = open('d1.in')


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


def read_str_list():
    return input().split()


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


def read_str():
    return input()


def main():
    n = read_int()
    p = read_int_list()
    res = 0
    for i in range(n):
        if p[i] == i + 1:
            res += 1
            if i + 1 < n:
                p[i], p[i + 1] = p[i + 1], p[i]
    print(res)


main()


Measured memory_bytes: 14252
import java.util.Scanner;

public class Main{	
	public static void main(String[] arts){
		Scanner sc = new Scanner(System.in);
		int b,f,r,v;
		int[][][] x;
		x = new int [4][3][10];  //棟　階　部屋
		int num = sc.nextInt();
		for(int i=0;i<num;i++){
			b = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			v = sc.nextInt();
			x[b-1][f-1][r-1]+=v;
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<10;k++){
						System.out.printf(" %d",x[i][j][k]);
				}
				System.out.println();
			}
			if(i!=3){
				for(int l=0;l<20;l++){
					System.out.print("#");
				}
				System.out.println();
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 29936
class HitBlow
  def check(a, b)
    hits = [a, b].transpose.select { |x, y| x == y }.flatten.uniq
    blows = a & b - hits
    [hits.size, blows.size]
  end
end

inputs = STDIN.read.split("\n")

loop do
  break if inputs.empty?
  a = inputs.shift.split.map(&:to_i)
  b = inputs.shift.split.map(&:to_i)
  result = HitBlow.new.check(a, b)
  printf "%s %s\n", result[0], result[1]
end

Measured memory_bytes: 8600
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    string S;
    cin >> S;
    int N = S.size();
    string S_1;
    string S_2;
    for(int i = 0; i < N; i++){
        if(i % 2) {
            S_1.push_back('0');
            S_2.push_back('1');
        }
        else {
            S_1.push_back('1');
            S_2.push_back('0');
        }
    }
    int one_n = 0, two_n = 0;
    for(int i = 0; i < N; i++){
        if(S[i] != S_1[i]) one_n++;
        if(S[i] != S_2[i]) two_n++;
    }
    cout << min(one_n, two_n) << endl;
}

Measured memory_bytes: 3964
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator

void solve() {
    string s; cin>>s;
    int n = stoi(s), sum = 0;
    for(int i=0;i<s.length();i++) {
        sum += s[i]-'0';
    }
    if(n%sum == 0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

int main() {
    solve();
    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 = sc.nextInt();
    int K = sc.nextInt();
    if (N % K == 0){
      System.out.println(0);
    }
    else{
      System.out.println(1);
    }
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a , b , c;
  cin>>a>>b>>c;
  if( ((a == b) && (a != c)) || ((c == b) && (a != c))  || ((a == c) && (b != c)))
    cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
import fs = require('fs');
if(process.argv[1].match(/Main.js$/)) { console.log(main(fs.readFileSync('/dev/stdin', 'utf8').trim().split(/[\r\n\t ]+/))); }

export function main(strings: string[]): string {
	const ret: any[] = [];
	const numbers = strings.map(Number);

	numbers.shift();
	const M = numbers.shift() as number;

	const shops: [number, number][] = [];

	for(let i=0; i<=numbers.length;) {
		if(numbers[i] == null || numbers[i+1] == null) {
			break;
		}
		shops.push([
			numbers[i],
			numbers[i+1],
		]);
		i += 2;
	}

	shops.sort((a, b) => a[0] - b[0]);

	let sum = 0;
	let m = 0;
	for(let shop of shops) {
		if(shop[1] + m > M) {
			sum += shop[0] * (M - m);
			break;
		} else {
			sum += shop[0] * shop[1];
			m += shop[1];
		}
	}

	ret.push(sum)
	return ret.join('\n') + '\n';
}

Measured memory_bytes: 57452
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int k;
    cin >> s >> k;
    vector<string> w;
    for(int i=1;i<=k;i++){
        for(int j=0;j<s.size();j++){
            w.push_back(s.substr(j,i));
        }
        if(i==s.size()){
            break;
        }
    }
    sort(w.begin(),w.end());
    unique(w.begin(),w.end());
    cout << w[k-1] << endl;


    return 0;
}

Measured memory_bytes: 1660
N = int(input())
A = list(map(int, input().split()))

cumsum = [0] * (N+1)
for i in range(N):
    cumsum[i+1] = cumsum[i] + A[i]

ans = float("inf")
for i in range(1, N):
    cand = abs(cumsum[i] - (cumsum[-1] - cumsum[i]))
    ans = min(ans, cand)

print(ans)

Measured memory_bytes: 24816
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b)
        printf("a > b\n");
    else if(a<b)
        printf("a < b\n");
    else if(a==b)
        printf("a == b\n");
        return 0;
}



Measured memory_bytes: 2040
#include<stdio.h>

int main(void) {
    int x, y;
    int tmp;
    scanf("%d %d", &x, &y);

    if(x > y) {
        printf("a > b\n");
    } else if ( y > x ) {
        printf("a < b\n");
    } else {
        printf("a == b\n");
    }

    return 0;
}

Measured memory_bytes: 580
from collections import defaultdict
N,M,*L = map(int, open(0).read().split())
MOD = 10**9+7
A = L[:N]
B = L[N:]
set_a = set(A)
set_b = set(B)
if len(set_a)!=len(A) or len(set_b)!=len(B):
  print(0)
  import sys
  sys.exit()
ls = []
sheet = [[0]*M for i in range(N)]
for i,a in enumerate(A):
  ls.append((a,i,0))
for i,b in enumerate(B):
  ls.append((b,i,1))
ls.sort(reverse=True)
for c,i,s in ls:
  if s==0:
    for j in range(M):
      sheet[i][j] = c
  else:
    for j in range(N):
      sheet[j][i] = c
dic = defaultdict(int)
for i in range(N):
  for j in range(M):
    dic[sheet[i][j]] += 1
p = 0
num = [0]*(N*M+1)
for i in range(N*M,0,-1):
  p += dic[i]
  if i in set_a and i in set_b:
    num[i] = 1
  elif dic[i]!=0:
    num[i] = dic[i]
  else:
    num[i] = p
  p -= 1

ans = 1
for c in num[1:]:
  ans *= c
  ans %= MOD
print(ans)

Measured memory_bytes: 141564
#include<cstdio>
int tl,xl,yl;
int t,x,y;
int abs(int x)
{
	return x>0?x:-x;
}
int main()
{
	int N,flag=1;
	scanf("%d",&N);
	for (int i=0;i<N;i++)
	{
		int mindis,timedif;
		scanf("%d %d %d",&t,&x,&y);
		mindis=abs(x-xl)+abs(y-yl);
		timedif=t-tl;
		if (timedif%2!=mindis%2||mindis>timedif)flag=0;
		tl=t,xl=x,yl=y;
	}
	if (flag)printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

#define st first
#define nd second
#define pb push_back

typedef long long   ll;
typedef double      db;
typedef long double ldb;

typedef pair <int, int> pii;
typedef pair <ll,  ll>  pll;
typedef pair <ll,  db>  pdb;
typedef pair <ldb, ldb> pldb;

template <typename T>
void   Debug (T begin, T end);
int    si    ();
ll     sl    ();
string ss    (int); 
db     sf    ();
ldb    slf   ();
void   pi    (int, char = '\n');
void   pl    (ll, char = '\n');
void   pf    (db, char = '\n');
void   plf   (ldb, char = '\n');
void   ps    (string, char = '\n');

ll russian(ll, ll, ll);
ll fast_power(ll, ll, ll);
ll slow_power(ll, ll, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);

const int INF  = 1e9;
const ll  LINF = 1e18;

int main()
{
    int n = si();
    pii A[n];
    for (int i = 0; i < n; ++i)
        A[i] = {si(), i + 1};
    sort(A, A + n);
    for (int i = 0; i < n; ++i)
        pi(A[i].nd, ' ');

    return 0;
}

template <typename T>
void Debug(T begin, T end)
{
    printf("\nDEBUG:\n");
    while (begin != end)
        printf("%d ", *begin),
        begin++;
    printf("\n\n");
}

template <typename T>
T scanf_t(string s)
{
    T a;
    scanf(s.c_str(), &a);
    return a;
}

template <typename T>
void printf_t(T a, string s, char end_l)
{
    s.push_back(end_l);
    printf(s.c_str(), a);
}

int si() { return scanf_t<int>("%d"); }
ll sl() { return scanf_t<ll>("%lld"); }
db sf() { return scanf_t<db>("%f"); }
ldb slf() { return scanf_t<ldb>("%Lf"); }

void pi(int a, char end_l) { printf_t<int>(a, "%d", end_l); }
void pl(ll a, char end_l) { printf_t<ll>(a, "%lld", end_l); }
void pf(db a, char end_l) { printf_t<db>(a, "%lf", end_l); }
void plf(ldb a, char end_l) { printf_t<ldb>(a, "%Lf", end_l); }

void ps(string a, char end_l)
{
    string s = "%s";
    s.push_back(end_l);
    printf(s.c_str(), a.c_str());
}

string ss(int NN)
{
    char T[NN];
    scanf("%s", T);
    return (string)T;
}

ll fast_power(ll a, ll k, ll m)
{
    ll r = 1LL;
    while (k)
    {
        if (k & 1LL)
            r = (r * a) % m;
        a = (a * a) % m;
        k >>= 1LL;
    }
    return r;
}

ll slow_power(ll a, ll k, ll m)
{
    ll r = 1LL;
    while (k)
    {
        if (k & 1LL)
            r = russian(r, a, m);
        a = russian(a, a, m);
        k >>= 1LL;
    }
    return r;
}

ll russian(ll a, ll k, ll m)
{
    ll r = 0LL;
    while (k)
    {
        if (k & 1LL)
            r = (r + a) % m;
        a = (a + a) % m;
        k >>= 1LL;
    }
    return r;
}

ll gcd(ll a, ll b)
{
    while (b)
        swap(a %= b, b);
    return a;
}

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


Measured memory_bytes: 1536
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

res = 0
for i in range(N):
    if A[i] >= B[i]:
        res += B[i]
    else:
        res += A[i]
        x = min(A[i+1], B[i]-A[i])
        A[i+1] -= x
        res += x

print(res)

Measured memory_bytes: 18624
import java.util.*;

class Main{
	public static void main(String[] args){
		   double t2=700;
		Scanner sc=new Scanner(System.in);
		     int N=sc.nextInt();
		     int T=sc.nextInt();
		     int A=sc.nextInt();
		     int res = 0;
     	     for(int i = 0; i < N; i++) {
     	     	int H = sc.nextInt();
		    	double t1=T-H*0.006-A;
               if(t1*t1<t2*t2){
                 t2=t1;
                 res = i + 1;
              }
		   }
		    System.out.print(res);
	}
}

Measured memory_bytes: 23636
#include<stdio.h>
int main(void)
{
    int n,i,sum=0,cnt=0;
    int a[100]={0},b[100]={0};

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        if(a[i]%2==0){
            b[i]=a[i];
            cnt++;
        } else {
            b[i]=7;
        }
    }
    for(i=0;i<n;i++){
        if(b[i]%3==0 || b[i]%5==0){
            sum++;
        }
    }
    if(sum==cnt){
        printf("APPROVED\n");
    } else {
        printf("DENIED\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <vector>
using namespace std;

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

  vector<int> p, q, r;
  for(int i = 0; i < A; ++i) {
    int x; cin >> x;
    p.push_back(x);
  }
  for(int i = 0; i < B; ++i) {
    int x; cin >> x;
    q.push_back(x);
  }
  for(int i = 0; i < C; ++i) {
    int x; cin >> x;
    r.push_back(x);
  }

  sort(p.begin(), p.end(), greater<int>());
  sort(q.begin(), q.end(), greater<int>());
  sort(r.begin(), r.end(), greater<int>());
  p.resize(X);
  q.resize(Y);

  copy(p.begin(), p.end(), back_inserter(r));
  copy(q.begin(), q.end(), back_inserter(r));

  sort(r.begin(), r.end(), greater<int>());
  r.resize(X+Y);

  cout << accumulate(r.begin(), r.end(), 0ll) << endl;
  
  return 0;
}


Measured memory_bytes: 3188
x, y = map(int, input().split())
a = [2]
b = [4, 6, 9, 11]
c = [1, 3, 5, 7, 8, 10, 12]
if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//#define int         int64_t
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;
int inf = 2e9, mod = 1e9 + 7;
int r,c,n;
bool onEdge(ii& p){
    return p.x == 0 || p.x == r || p.y == 0 || p.y == c;
}

ii see(ii& p){
    ii res;
    if(p.x == 0) res = {0, p.y};
    else if(p.x == r) res = {2, -p.y};
    else if(p.y == c) res = {1, p.x};
    else res = {3, -p.x};
    return res;
}

struct Ev{
    int val;
    ii cmp;
    Ev(int v, ii c) : val(v), cmp(c) {}
};

int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    cin >> r >> c >> n;
    ii a, b;
    vector<Ev> ev;
    for(int i=0;i<n;i++){
        cin >> a.first >> a.y >> b.x >> b.y;
        if(onEdge(a) && onEdge(b)){
            ev.push_back(Ev(i,see(a)));
            ev.push_back(Ev(i,see(b)));
        }
    }
    sort(all(ev), [](Ev &a, Ev &b){return a.cmp < b.cmp; });
    vi check(n, -1);
    int cur = 0;
    for(auto &e:ev){
        if(check[e.val] == -1) check[e.val] = cur++;
        else{
            if(check[e.val] != --cur) return cout << "NO"<<endl, 0;
        }
    }
    cout <<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const MOD = 1e9 + 7;
ll const oo = 8e18;
int const N = 2e5 + 100;
int const M = 1e6 + 100;

int n, m, r[110], c[110];
char g[110][110];

int main(){

   cin >> n >> m;
    for(int i = 0;i < n;++i){
        for(int j = 0;j < m;++j){
            cin >> g[i][j];
            if(g[i][j] == '#') r[i] = 1, c[j] = 1;
        }
    }

    for(int i = 0;i < n;++i){
        if(!r[i]) continue;
        for(int j = 0;j < m;++j){
            if(!c[j]) continue;
            cout << g[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
//string binary = bitset<32>(n).to_string();  
lli mod=1000000007;
lli power(lli x, lli y,lli p) 
{ 
    lli res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
lli modInverse(lli n, lli p) 
{ 
    return power(n, p-2, p); 
} 
lli ncr(lli n, lli r,lli p) 
{ 
   if (r==0) 
      return 1; 
    lli fac[n+1]; 
    fac[0] = 1; 
    for (lli i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
    	lli n,b;
   	cin>>n>>b;
   	lli r=n-b;
   	lli ans[b];
   	for(lli i=0;i<b;i++){
   		if(b-i>r+1){ans[i]=0;continue;}
   		if(i==0){ans[i]=(ncr(r+1,b-i,mod));continue;}
   		ans[i]=(ncr(r+1,b-i,mod)*ncr(b-1,b-i-1,mod))%mod;
   	}

   	reverse(ans,ans+b);
   	for(lli i=0;i<b;i++)cout<<ans[i]<<endl;




    return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n").map(Number);
var n=arr.shift();
var a=arr.shift();
var cnt=1;
var max=1;
var memo=0;
arr.forEach(v=>{
   if(a>v){
      if(memo == 1)cnt=2;
      else cnt++;
      memo=-1;
   }else if(a<v){
      if(memo == -1)cnt=2;
      else cnt++;      
      memo=1;
   }
   max=Math.max(max,cnt);
   a=v;
});
console.log(max);


Measured memory_bytes: 32764
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
       n:usize,
    }
    match n % 10 {
        2 | 4 | 5 | 7 | 9 => println!("hon"),
        0 | 1 | 6 | 8 => println!("pon"),
        _ => println!("bon"),
    }
}


Measured memory_bytes: 2172
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, k = map(int, input().split())

if k == 1:
    print(1)
    sys.exit(0)

if k <= n:
    ans = ((n - k) + 1) / n
    upper = k - 1
else:
    ans = 0
    upper = n
for i in range(1, upper + 1):
    tmp = 1 / n
    while i < k:
        tmp *= (1 / 2)
        i *= 2
    ans += tmp
print(ans)


Measured memory_bytes: 64920
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String s = sc.next();
		int k = sc.nextInt();


		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(k-1) != s.charAt(i)) {
				s = s.replace(s.charAt(i), '*');
			}
		}

		System.out.println(s);
	}

}

Measured memory_bytes: 21716
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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


struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

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


// ***************************************


int main(){

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

    UnionFind uf = UnionFind(N);

    REP(i, M){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        uf.merge(a, b);
    }

    set<ll> s;
    REP(i, N){
        s.insert(uf.root(i));
    }

    cout << s.size() - 1 << endl;

    return 0;
}


Measured memory_bytes: 7408
import math
N = int(input())
S = input()

# N = 39
# S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"

def calculate(n, s):
    arr = list(s)

    rNum = arr.count("R")
    gNum = arr.count("G")
    bNum = arr.count("B")

    sum = 0

    for step in range(1,math.ceil(n / 2) + 1):
        for i in range(n - 2*step):
            s = "".join([arr[i],arr[i+step],arr[i+step*2]])
            if s == "RGB" or s == "RBG" or s == "BGR" or s == "BRG" or s == "GBR" or s == "GRB":
                sum = sum + 1


    print(rNum*gNum*bNum - sum)



calculate(N, S)


Measured memory_bytes: 9116
n = int(input())

words = set()
w = ''
ok = True
for i in range(n):
  nw = input()
  if nw in words:
    ok = False
    break
  words.add(w)
  if w and w[-1] != nw[0]:
    ok = False
  w = nw

if ok:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
def resolve():
  N, M, K = map(int, input().split(" "))
  A = [int(x) for x in input().split(" ")]
  B = [int(x) for x in input().split(" ")]

  if A[0] > K and B[0] > K:
    print(0)
    return True 

  integraA = [0]
  for i in range(N):
    integraA.append(A[i] + integraA[i])

  integraB = [0]
  for i in range(M):
    integraB.append(B[i] + integraB[i])

  ans = 0
  B_index = M
  for A_index in range(N + 1):
    if integraA[A_index] > K:
      break

    # print(A_index, ":", B_index)
    # print(integraB[B_index], "<", K - integraA[A_index])
    while integraB[B_index] > K - integraA[A_index]:
      B_index -= 1
    ans = max(ans, A_index + B_index)
  print(ans)

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 141848
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		//キーボード入力メソッド
		Scanner sc = new Scanner(System.in);

		//入力
		int times = sc.nextInt();
		int[] ary = new int[times];
		for(int i=0; i<times; i++) {
			ary[i] = sc.nextInt();
		}

		//処理
		long max = ary[0];
		long min = ary[0];
		long sum = 0;

		for(int i=0; i<times; i++) {
			int v =ary[i];
			if(max > v) {
				max = v;
			}else if(min < v) {
				min = v;
			}
			sum = sum + v;
		}

		//出力
		System.out.println(max +" "+ min +" "+ sum);

	}

}



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

int main() {
  int K, S; cin >> K >> S;
  int ans = 0;
  rep(x, K + 1) {
    rep(y, K + 1) {
      if (S - x - y >= 0 && S - x - y <= K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    ll l,r; cin>>l>>r;

    if(r-l>3000){
        puts("0");
        return 0;
    }
    ll ans=1e9;
    for(int i=l;i<r;i++){
        for(int j=i+1;j<=r;j++){
            ans=min(ans,1ll*i*j%2019);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    struct VertexQ {
        bool operator<(const VertexQ &o) const {
            return c > o.c; // 逆
        }
        int i;
        ll c;
    };
    struct Vertex { int n; ll c; };
    struct Edge { int i, n, c; };
    Graph(int n, int m) : v(n, { -1 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j, int c) {
        e[m] = { j, v[i].n, c };
        v[i].n = m;
        m++;
    }
    void dijkstra(int i, int j) {
        for (int i = 0; i < n; i++) v[i].c = 1 << 30;
        priority_queue<VertexQ> q;
        q.push({ i, v[i].c = 0 });
        while (!q.empty()) {
            auto p = q.top(); q.pop();
            if (p.i == j) break;
            if (p.c > v[p.i].c) continue;
            for (int j = v[p.i].n; j >= 0; j = e[j].n) {
                Edge &o = e[j];
                ll c = p.c + o.c;
                if (c < v[o.i].c) q.push({ o.i, v[o.i].c = c });
            }
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

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

    int n, m;
    cin >> n >> m;

    Graph g(n * 3, m * 3);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        for (int j = 0; j < 3; j++) {
            g.add_edge(a * 3 + j, b * 3 + (j + 1) % 3, 1);
        }
    }

    int s, t;
    cin >> s >> t;
    s--; t--;

    int r = 1 << 30;
    for (int j = 0; j < 3; j++) {
        g.dijkstra(s * 3 + j, t * 3 + j);
        r = min(r, (int)g.v[t * 3 + j].c);
    }

    cout << (r == 1 << 30 ? -1 : r / 3) << endl;

    //普通に最短距離求めて3の倍数ならそれを3で割って出力すればいい
    //頂点の数を3倍にすればいいのでは？

    return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


#define MAX 10000
#define NIL -1

struct Node
{
	int parent, left, right;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d)
{
	if (u == NIL) return;
	D[u] = d;
	setDepth(T[u].left, d + 1);
	setDepth(T[u].right, d + 1);
}

int setHeight(int u)
{
	int h1 = 0, h2 = 0;
	if (T[u].left != NIL) h1 = setHeight(T[u].left) + 1;
	if (T[u].right != NIL) h2 = setHeight(T[u].right) + 1;
	return H[u] = max(h1, h2);
}

int getSibling(int u)
{
	if (T[u].parent == NIL) return NIL;
	if (T[T[u].parent].left != u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
	if (T[T[u].parent].right != u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
	return NIL;
}

void print(int u)
{
	printf("node %d: ", u);
	printf("parent = %d, ", T[u].parent);
	printf("sibling = %d, ", getSibling(u));
	int deg = 0;
	if (T[u].left != NIL) deg++;
	if (T[u].right != NIL) deg++;
	printf("degree = %d, ", deg);
	printf("depth = %d, ", D[u]);
	printf("height = %d, ", H[u]);
	
	if (T[u].parent == NIL)
	{
		printf("root\n");
	} else if (T[u].left == NIL && T[u].right == NIL) {
		printf("leaf\n");
	} else {
		printf("internal node\n");
	}
}


int main()
{
	int v, l, r, root = 0;
	
	scanf("%d", &n);
	REP(n) T[i].parent = NIL;
	REP(n)
	{
		scanf("%d %d %d", &v, &l, &r);
		T[v].left = l;
		T[v].right = r;
		if (l != NIL) T[l].parent = v;
		if (r != NIL) T[r].parent = v;
	}
	
	REP(n) if (T[i].parent == NIL) root = i;
	setDepth(root, 0);
	setHeight(root);
	REP(n) print(i);
	
	return 0;
}


void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}


double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 1204
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        bool[][] path = Enumerable.Repeat(0, 8).Select(_ => new bool[8]).ToArray();
        for (int i = 0; i < nm[1]; i++)
        {
            int[] ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            path[ab[0] - 1][ab[1] - 1] = true;
            path[ab[1] - 1][ab[0] - 1] = true;
        }
        int res = 0;
        int[] perm = Enumerable.Range(0, nm[0]).ToArray();
        do
        {
            //Console.WriteLine(string.Join(" ", perm));
            if (perm[0] != 0) break;
            for (int j = 0; j < nm[0] - 1; j++)
            {
                if (!path[perm[j]][perm[j + 1]])
                {
                    goto end;
                }
            }
            res++;
            end:;
        }
        while (NextPermutation(perm));
        Console.WriteLine(res);
    }

    public static void Swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }

    public static bool NextPermutation<T>(T[] array, int index, int length, Comparison<T> comp)
    {
        if (length <= 1) return false;
        for (int i = length - 1; i > 0; i--)
        {
            int k = i - 1;
            if (comp(array[k], array[i]) < 0)
            {
                int j = Array.FindLastIndex(array, delegate (T x) { return comp(array[k], x) < 0; });
                Swap(ref array[k], ref array[j]);
                Array.Reverse(array, i, length - i);
                return true;
            }
        }
        Array.Reverse(array, index, length);
        return false;
    }

    public static bool NextPermutation<T>(T[] array) where T : IComparable
    {
        return NextPermutation(array, 0, array.Length, Comparer<T>.Default.Compare);
    }
}


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

int main(){
  int K,S;cin>>K>>S;
  int ans=0;
  
  rep(X,K+1){
    rep(Y,K+1){
      int Z=S-X-Y;
      if(0<=Z && Z<=K) ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define vec vector<int,int> 
#define int long long 
#define pii pair<int,int>
int visited[100001];

//int ax,ay,bx,by,t_x0,t_y0;
int dp[3001][3001];
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ios_base& scientific (ios_base& str);
	
	int t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		int arr[n];
		int sum=0;
		rep(i,n){
			cin>>arr[i];
			sum+=arr[i];
		}
		//sort(arr,arr+n);
		for(int i=0;i<n;i++){
			dp[i][i]=arr[i];
		}
		for(int i=0;i<n-1;i++){
			dp[i][i+1]=max(arr[i],arr[i+1]);
		}
		int a=2;
		while(1){
			if(a>=n) break;
			for(int i=0;i<n-a;i++){
				int j=i+a;
				dp[i][i+a]=max(arr[i]+min(dp[i+2][j],dp[i+1][j-1]),arr[j]+min(dp[i+1][j-1],dp[i][j-2]));
			}
			a++;
		}
		cout<<(2*dp[0][n-1]-sum)<<endl;
	}
	//exit();
	return 0;
}


Measured memory_bytes: 70016
import java.util.*;

public class Main {

    

    public static void main(String[] atgs){

        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();

        int num = Integer.parseInt(input);
      	int count = 0;
        
        for(int i = 1; i <= num; i+=2){
            if(ishave(i))
                count++;
        }

        System.out.println(count);
    }

    private static boolean ishave(int n){
        int divisotCount = 0;
        for(int i = 1; i <= n; i++){
            if((n % i) == 0)
                divisotCount++;
        }

      	
        if(divisotCount == 8)
            return true;
        else return false;
    }
}

Measured memory_bytes: 21460
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 7/29/2018
 
 19:35-20:13 1WA
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=8000+1;
string S;
int XT,YT;
const string yes="Yes",no="No";
int dp1[MAX_N*2+10],dp2[MAX_N*2+10];
void solve() {
  VI X,Y;
  bool hr=true;
  int cur=0;
  REP(i,SZ(S)) {
    if(S[i]=='T') {
      (hr?X:Y).push_back(cur);
      cur=0;
      hr=!hr;
    } else {
      ++cur;
    }
  }
  (hr?X:Y).push_back(cur);
  
  int offset=MAX_N;
  
  bool xok=false;
  ZERO(dp1);
  if(SZ(X)==0) {
    xok=XT==0;
  } else {
    dp1[offset+X[0]]=true;
    FOR(i,1,SZ(X)) {
      ZERO(dp2);
      FORE(x,-MAX_N,MAX_N) if(dp1[offset+x]) {
        int dt=X[i];
        dp2[offset+x+dt]=1;
        dp2[offset+x-dt]=1;
      }
      swap(dp1,dp2);
    }
//    dump3(offset,offset+XT,dp1[offset+XT]);
    xok=dp1[offset+XT];
  }
  
  bool yok=false;
  ZERO(dp1);
  dp1[offset+0]=true;
  REP(i,SZ(Y)) {
    ZERO(dp2);
    FORE(y,-MAX_N,MAX_N) if(dp1[offset+y]) {
      int dt=Y[i];
      dp2[offset+y+dt]=1;
      dp2[offset+y-dt]=1;
    }
    swap(dp1,dp2);
  }
  yok=dp1[offset+YT];
//  dump3(offset,offset+YT,dp1[offset+YT]);
  
  cout<<(xok&&yok?yes:no)<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>S>>XT>>YT;
  solve();
  return 0;
}


Measured memory_bytes: 512
s=list(str(input()))
l=len(s)
t=list(reversed(s))
a=[]
if s==t:
  for i in range(0,int((l-1)/2)):
    if s[i]==s[int((l-1)/2-i)-1]:
      a.append(s[i])
  if len(a)==(l-1)/2:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 1e5 + 50;
int n; struct my{ int l, r; } t[N];
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d",&n); int L=0, R=1e9, mx=0;
	for(int i=1; i<=n; i++)
	scanf("%d%d",&t[i].l,&t[i].r),
	mx=max(mx,t[i].r-t[i].l+1),
	R=min(R,t[i].r),L=max(L,t[i].l);
	for(int i=1; i<=n; i++){
		int l=max(0,t[i].r-L+1),r=max(0,R-t[i].l+1);
		t[i]=(my){l, r}; 
	} sort(t+1,t+n+1,[](cs my &i, cs my &j){ return i.l < j.l; });
	int ans = max(R-L+1,0) + mx, mn = 1e9;
	for(int i=1; i<=n; i++)
	mn=min(mn, t[i].r), 
	ans = max(ans, mn+t[i+1].l);
	cout<<ans; return 0;
}

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

int main() {
  int N;
  cin >> N;

  deque<int> dq;
  ll sum = 0;
  rep(i,0,N-1) {
    ll a;
    cin >> a;
    dq.push_back(a);
    sum += a;
  }

  ll p = dq.front(); dq.pop_front();
  ll q = sum - p;

  ll ans = abs(p - q);
  while (dq.size() != 1)
  {
    ll tmp = dq.front(); dq.pop_front();
    p += tmp;
    q -= tmp;
    ans = min(ans, abs(p - q));
  }

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


Measured memory_bytes: 3992