akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Set<Character> set = new HashSet<Character>();
    int N = sc.nextInt();
    for(int i = 0; i < N; i++) {
      String s = sc.next();
      char c = s.charAt(0);
      set.add(c);
    }
    System.out.println(set.size() == 3 ? "Three" : "Four");
  }
}

Measured memory_bytes: 22740
#include <stdio.h>

int main(void)
{
    int dice[7],q,i,fr,bt,ri;
    for(i=1;i<=6;i++)
    {
        scanf("%d",&dice[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
        scanf("%d %d",&bt,&fr);
        if(bt==dice[1])
        {
            if(fr==dice[2]) ri=dice[3];
            else if(fr==dice[3]) ri=dice[5];
            else if(fr==dice[4]) ri=dice[2];
            else if(fr==dice[5]) ri=dice[4];
            printf("%d\n",ri);
        }

        else if(bt==dice[2])
        {
            if(fr==dice[1]) ri=dice[4];
            else if(fr==dice[3]) ri=dice[1];
            else if(fr==dice[4]) ri=dice[6];
            else if(fr==dice[6]) ri=dice[3];
            printf("%d\n",ri);
        }

        else if(bt==dice[3])
        {
            if(fr==dice[1]) ri=dice[2];
            else if(fr==dice[2]) ri=dice[6];
            else if(fr==dice[5]) ri=dice[1];
            else if(fr==dice[6]) ri=dice[5];
            printf("%d\n",ri);
        }

        else if(bt==dice[4])
        {
            if(fr==dice[1]) ri=dice[5];
            else if(fr==dice[2]) ri=dice[1];
            else if(fr==dice[5]) ri=dice[6];
            else if(fr==dice[6]) ri=dice[2];
            printf("%d\n",ri);
        }

        else if(bt==dice[5])
        {
            if(fr==dice[1]) ri=dice[3];
            else if(fr==dice[3]) ri=dice[6];
            else if(fr==dice[4]) ri=dice[1];
            else if(fr==dice[6]) ri=dice[4];
            printf("%d\n",ri);
        }

        else if(bt==dice[6])
        {
            if(fr==dice[2]) ri=dice[4];
            else if(fr==dice[3]) ri=dice[2];
            else if(fr==dice[4]) ri=dice[5];
            else if(fr==dice[5]) ri=dice[3];
            printf("%d\n",ri);
        }

    }
    return 0;
}




Measured memory_bytes: 2056
<?php

while ($stdin = fgets(STDIN)) {
    $line[] = trim($stdin);
}
foreach ($line as $key => $value) {
    $data[] = explode(' ', $value);
}

foreach ($data as &$line) {
    $line = array_map(function($val) { return (int)$val; }, $line);
}

$N = $data[0][0];
$X = $data[0][1];
$L = $data[1];

$num = 0;
$bounds = [0];
foreach ($L as $smallL) {
    $num += $smallL;
    $bounds[] = $num;
}

$bounds = array_filter($bounds, function($num) use ($X) {
    return $num <= $X;
});

printf('%d', count($bounds));

?>


Measured memory_bytes: 4856
#include <iostream>

using namespace std;

int main()
{
	int n, k, q;
	int a[100000];
	int p[100001] = {};
	
	cin >> n >> k >> q;
	for (int i = 0; i < q; i++) {
		cin >> a[i];
		p[a[i]]++;
	}
	
	int qk = q - k;
	for (int i = 1; i <= n; i++)
		if (p[i] > qk) cout << "Yes\n";
		else cout << "No\n";
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int H,A;
    cin >> H >> A;
    cout <<(H+A-1)/A<< "\n";
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

vector<int> a;

int main(void){
  int n;
  cin >> n;
  a.resize(n);
  multiset<int> s;
  rep(i, n){
    cin >> a[i];
  }
  for(int i  = n - 1; i >= 0 ; --i){
    auto x = s.upper_bound(a[i]);
    if (x != s.end()){
      s.erase(x);
    }
    s.insert(a[i]);
  }

  cout << s.size() << endl;
  return 0;
}



Measured memory_bytes: 5376
#include <stdio.h>
int main(void){
    // Here your code !
    int a,b;
    scanf("%d %d", &a, &b);
    if(a>b){
        printf("a > b\n");
        return 0;
    }
    if(a == b){
        printf("a == b\n");
        return 0;
    }
    printf("a < b\n");
    return 0;
}


Measured memory_bytes: 580
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7; 

fn main(){
    let n: usize = read();
    let b: Vec<usize> = (0..n-1).map(|_| read()).collect();
    let mut ans = b[0];
    for i in 1..n - 1{
        ans += min(b[i - 1], b[i]);
    }
    ans += *b.last().unwrap();
    println!("{}", ans);
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int main ()
{
	long long k;
	cin >> k;
	int i = 0;
	long long x = 100;
	while (k > x) {
		x += (x/100);
		i++;
	}
	cout << i << endl;
	return 0;
}


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

int N, Y;

int main()
{
    int num_1k = -1, num_5k = -1, num_10k = -1;

    cin >> N >> Y;
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= N - i; j++)
            if (i * 1000 + j * 5000 + (N - i - j) * 10000 == Y)
            {
                num_1k = i;
                num_5k = j;
                num_10k = N - i - j;
                break;
            }
    }

    printf("%d %d %d\n", num_10k, num_5k, num_1k);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
  char s[100000]={};
  
  scanf("%s",s);
  
  int l=strlen(s);
  int i;
  
  for(i=0;i<l;i+=2)
  {
    printf("%c",s[i]);
  }
  
  return 0;
}

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

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

    int n, a;
    cin >> n >> a;

    for (int i = 0; i < 2000; i++) {
        if (i * 500 > n) continue;
        int k = n - i * 500;
        if (k <= a) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  string s; cin >> s;
  sort(s.begin(),s.end());
  if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int count(ll x){
    if(x/10 < 10){
        if(x%10==9)return x/10+9;
        else return max((ll)9, x/10-1+9);
    }
    if(x%10!=9)x=x/10-1;
    else x/=10;
    return 9 + count(x);
}
int main(){
    ll n;
    cin >> n;
    if(n < 10)cout << n;
    else cout << count(n);
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n = int(input())
ans = 0
for i in range(1, n+1,2):
    if len(make_divisors(i)) == 8:
        ans += 1

print(ans)
    

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define prvp(a) for(auto x : a) cout << "{" << x.ff << ',' << x.ss << "}";cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(int a, int b){return (int)((long long) a * b % mod);}
inline int modexpo(int a, int b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(int a, int b){ return mul(a, modexpo(b, mod - 2));}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  ll h, n, i, sum = 0;
  cin >> h >> n;
  for(i = 0; i < n; i++){
    ll c; cin >> c; sum += c;
  }
  if(h <= sum){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }
}

int main(){
  fastio

  pre();

  int t = 1;
  // cin >> t;
  while(t--){
    solve();
  }

  ktj();
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
#include <cmath>
#include <string>
#define mp make_pair
#define pb push_back

using namespace std;

const int MAX = 1e5 + 5;

int main() 
{
	int n;
	scanf("%d", &n);
	int a[MAX], dp[MAX];
	long long sum = 0;
	a[0] = 0;
	a[n+1] = 0;
	for (int i = 1; i<=n; ++i) {
		scanf("%d", &a[i]);
		sum += abs(a[i] - a[i-1]);
	}
	sum += abs(a[n]);
	for (int i = 1; i<=n; ++i) {
		dp[i] = abs(a[i+1] - a[i-1]) - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]);
		printf("%lld\n", sum + 1ll*dp[i]);
	}
	return 0;
}

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

int main()
{
	int n;
	while(scanf("%d", &n), n)
	{
		double m = 0;
		double a = 0;
		double s[1024];

		for(int i = 0; i < n; ++i)
		{
			scanf("%lf", &s[i]);
			m += s[i];
		}
		m /= n;

		for(int i = 0; i < n; ++i)
		{
			a += pow(s[i] - m, 2);
		}
		printf("%.8f\n", sqrt(a / n));
	}
	return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
//vvi(n, vector<int>(m, -1))
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a) (a).begin(), (a).end()

int main(){
	int i, j, k, l, h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	int dx[] = {1, 0, -1, 0};
	int dy[] = {0, 1, 0, -1};
	rep(i, h){
		rep(j, w){
			if(s[i][j] == '.') continue;
			bool flag = false;
			rep(k, 4){
				int nx = j+dx[k];
				int ny = i+dy[k];
				if(nx >= 0  &&
						nx < w 	&&
						ny >= 0  &&
						ny < h 	&&
						s[ny][nx] == '#') flag = true;
			}
			if(!flag){
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
a,b,c = map(int,input().split())
ans = 9999
ans = min(ans, abs(a-b) + abs(b-c), abs(a-c) + abs(c-b))
ans = min(ans, abs(b-a) + abs(a-c), abs(b-c) + abs(c-a))
ans = min(ans, abs(c-a) + abs(a-b), abs(c-b) + abs(b-a))
print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int []a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		
		System.out.println(a[n-1]);
	
	}
}


Measured memory_bytes: 23124
import sys
from string import ascii_lowercase as AL
input = sys.stdin.readline


def main():
    S = input().rstrip()

    if len(S) < 26:
        for a in AL:
            if a not in S:
                ans = S + a
                break
    else:
        i = 25
        while True:
            if i == 0:
                ans = -1
                break
            if S[i-1] > S[i]:
                i -= 1
            else:
                idx = AL.index(S[i-1])
                while True:
                    idx += 1
                    if AL[idx] in S[i:]:
                        next_al = AL[idx]
                        break
                ans = S[:i-1] + next_al
                break
    print(ans)


if __name__ == "__main__":
    main()


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

public class Main{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int K = Integer.parseInt(sc.next());
        int X = Integer.parseInt(sc.next());
        if(K * 500 >= X) System.out.println("Yes");
        else System.out.println("No");
	}


static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public boolean ready() throws IOException {return br.ready();}

		public double nextDouble(String x)
		{

			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}


	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define ll long long
using namespace std;
template<class T>inline void read(T &res){
	char c;T flag=1;
	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
	while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
#define MAX 1000000//求MAX范围内的素数
long long su[MAX],cnt;
bool isprime[MAX];
void prime()
{
    cnt=1;
    memset(isprime,1,sizeof(isprime));//初始化认为所有数都为素数
    isprime[0]=isprime[1]=0;//0和1不是素数
    for(long long i=2;i<=MAX;i++)
    {
        if(isprime[i])
            su[cnt++]=i;//保存素数i
        for(long long j=1;j<cnt&&su[j]*i<MAX;j++)
        {
            isprime[su[j]*i]=0;//筛掉小于等于i的素数和i的积构成的合数
        }
    }
}
int main()
{
	prime();
    int a[]={0,1,3,6,10,15,21,28,36,45,55};
    ll n,ans=0;
    cin>>n;
    for(int i=1;;i++)
    {
    	if(i<cnt&&su[i]*su[i]>n)
    		break;
        if(n%su[i]==0)
        {
            int c=0;
            while(n%su[i]==0)
                n/=su[i],c++;
            //cout<<c<<endl;
            ans+=upper_bound(a,a+11,c)-a-1;
        }
    }
    if(n!=1)
        ans++;
    cout<<ans<<endl;
    return 0;
}

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

int main(){
	string S;
	cin >> S;
	string a = S.substr(0,3);
	int b = stoi(a);
	int c = abs(b-753);
	for (int i = 0; i < S.size()-2; i++){
		string A = S.substr(i,3);
		int B = stoi(A);
		int C = abs(B-753);
		c = min(c,C);
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
imos = 0
ruisekiwa = [0 for _ in range(n)]
ruisekiwa[0] = a[0]
for i in range(1, n):
	ruisekiwa[i] = ruisekiwa[i-1] + a[i]

# minus
imos = 0
minusans = 0
for i in range(n):
	targ = ruisekiwa[i] + imos
	if i % 2 == 0:
		if targ >= 0:
			imos -= targ+1
			minusans += targ+1
	else:
		if targ <= 0:
			imos += 1-targ
			minusans += 1-targ

# plus
imos = 0
plusans = 0
for i in range(n):
	targ = ruisekiwa[i] + imos
	if i % 2 == 1:
		if targ >= 0:
			imos -= targ+1
			plusans += targ+1
	else:
		if targ <= 0:
			imos += 1-targ
			plusans += 1-targ

print(min(minusans, plusans))

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

#include <iostream>
#include <vector>
// #include <map>
// #include <string>
// #include <algorithm>
// #include <numeric>
// #include <limits>

using namespace std;

int main() {
	int n, taro = 0, hanako = 0;
	string t, h;
	cin >> n;
	for (int i = 0; i < n; i++) {
		bool flag = false;
		cin >> t >> h;
		for (unsigned int j = 0; j < min(t.size(), h.size()); j++) {
			if (t[j] < h[j]) {
				hanako += 3;
				flag = true;
				break;
			} else if (h[j] < t[j]) {
				taro += 3;
				flag = true;
				break;
			}
		}
		if (!flag) {
			if (t.size() < h.size()) {
				hanako += 3;
			} else if (h.size() < t.size()) {
				taro += 3;
			} else {
				taro += 1;
				hanako += 1;
			}
		}
	}
	cout << taro << " " << hanako << endl;
	// std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
string c;
int dp[200005][4];

int main()
{
//	freopen("input.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin>>c;
	int n=c.size();
	int res=0;
	for(int i=0;i<=n;i++)
	{
		dp[i][1]=-inf;
		dp[i][2]=-inf;
		dp[i][3]=-inf;
	}
	dp[1][1]=1;
	dp[2][2]=1;
	dp[3][3]=1;
	for(int i=1;i<n;i++)
	{
		for(int k=1;k<=3;k++)
		{
			for(int to=1;to<=3;to++)
			{
				if((k!=to) && dp[i+to][to]<dp[i][k]+1) dp[i+to][to]=dp[i][k]+1;
			}
		}
		if(i-1>=0 && c.substr(i-1,1)!=c.substr(i,1) && dp[i+1][1]<dp[i][1]+1) dp[i+1][1]=dp[i][1]+1;
		if(i-2>=0 && c.substr(i-2,2)!=c.substr(i,2) && dp[i+2][2]<dp[i][2]+1) dp[i+2][1]=dp[i][2]+1;
		if(i-3>=0 && c.substr(i-3,3)!=c.substr(i,3) && dp[i+3][3]<dp[i][3]+1) dp[i+3][1]=dp[i][2]+1;
	}
	cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<endl;
	return 0;
}

Measured memory_bytes: 3732
n = gets.to_i
k = gets.to_i
x = gets.split.map(&:to_i)
count = 0
for i in 0..x.length - 1
  if (x[i] - k).abs <= (x[i] - 0).abs
    count += (x[i] - k).abs
  else
    count += (x[i] - 0).abs
  end
end
puts count*2

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int A,B,C,D,R,L;

  cin >> A >> B >> C >> D ;

  L = A + B;
  R = C + D;
  
  if(L>R){
    cout << "Left" << endl;
  } else if(L<R){
    cout << "Right" << endl;
  } else if(L==R){
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n, d = inpl()
s_d = d * d
ans = 0
for i in range(n):
    x, y = inpl()
    if x * x + y * y <= s_d:
        ans += 1
print(ans)


Measured memory_bytes: 69668
#include<iostream>
#include<vector>

using namespace std;

int main(void){
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i = 0; i < N; i++) cin >> v[i];
  int s = 0;
  for(int i = 0; i < N; i++){
    s = v[s] - 1;
    if(s == 1){
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 640
N, M = map(int, input().split())
X = list(map(int, input().split()))

ans = 0

if N < M:
    Y = sorted(X)
    sections = sorted([Y[i] - Y[i - 1] for i in range(1, M)])
    for i in range(M - N):
        ans += sections[i]

print(ans)


Measured memory_bytes: 13968
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int X = sc.nextInt();
        
        int A[] = new int[D];
        for(int i = 0; i < N; i++) {
            int d = sc.nextInt();
            int r = 0;
            while( r * d < D ) {
                A[r * d]++;
                r++;
            }
        }
        
        int sum = X;
        for(int i = 0; i < D; i++) {
            sum += A[i];
        }
        
        System.out.println( sum );
    }
}


Measured memory_bytes: 35936
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
int main()
{
    ll n;
    cin>>n;
    ll val=n/2;
    if(n%2==0)
    {
        val--;
    }
    cout<<val<<'\n';
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	list := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&list[i])
	}

	total := 0
	for i := 0; i < m; i++ {
		total += list[i]
	}
	if n < total {
		fmt.Println(-1)
	} else {
		fmt.Println(n - total)
	}

}


Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Linq;

namespace Joyeuse
{
	class Program
	{
		#region Reserve
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static long cln(long D = -1){
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return long.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			var Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static int[] cins() { return cins(' '); }
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		static string read() { return Console.ReadLine(); }
		#endregion
		
		static void Main(string[] args) {
			var I = cins();
			int N = I[0],M=I[1];
			var arrive = new HashSet<int>();
			var depart = new HashSet<int>();
			for(int i=0;i<M;i++){
				I=cins();
				if(I[0]==1)arrive.Add(I[1]);
				if(I[1]==1)arrive.Add(I[0]);
				if(I[0]==N)depart.Add(I[1]);
				if(I[1]==N)depart.Add(I[0]);
			}
			bool res = arrive.Intersect(depart).Any();
			print(res?"POSSIBLE":"IMPOSSIBLE");
		}
	}
}

Measured memory_bytes: 29348
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	LL s;
	cin >> s;
	LL a = (LL)ceil(sqrt(s));
	LL r = a * a - s;
	cout << "0 0 1 " << a << " " << a << " " << r << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, a[N];
int main()
{
	cin >> n;
	int flag = 1;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] % 2 == 1)
		continue;
		if (a[i] % 3 == 0 || a[i] % 5 == 0)
		continue;
		flag = 0;
	}
	if (flag)
	cout << "APPROVED\n";
	else
	cout << "DENIED\n";
	
}

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

res = True
pre_t, pre_x, pre_y = 0, 0, 0
for _ in range(N):
    t, x, y = map(int, input().split())
    tmp = (t - pre_t) - abs(x - pre_x) - abs(y - pre_y)
    if tmp < 0 or tmp % 2 == 1:
        res = False
        break
    pre_t = t
    pre_x = x
    pre_y = y
    
print('Yes' if res else 'No')


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int n,k;
	cin>>n>>k;
	if(n%2&&k<=n/2+1)cout<<"YES"<<endl;
	else if(n%2==0&&k<=n/2)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}
	

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

const double pi = 3.141592653589;
int main()
{
  int a, b;
  char op;

  while (true) {
    cin >> a >> op >> b;
    switch (op) {
      case '+':
        cout << a + b << endl;
        break;
      case '-':
        cout << a - b << endl;
        break;
      case '*':
        cout << a * b << endl;
        break;
      case '/':
        cout << a / b << endl;
        break;
      case '?':
        return 0;
        break;
      default:
        break;
    }
  }
  return 0;
}


Measured memory_bytes: 3080
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int n; readV(n);
  int[] p; readC(n, p);

  writeln(p.sum - p.reduce!max/2);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

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

using namespace std;

typedef unsigned int uint;
typedef long long ll;

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

char toChar(int i){
  if(i<10) return i+'0';
  return 'A'+(i-10);
}

int main(){
  int n; cin>>n;
  while(n --> 0){
    int m; cin>>m;
    vector<string> str(m);
    vector<int> step(m);
    REP(i,m){
      cin>>str[i];
      for(int j = 2; j<=(str[i].size()/2); j++){
        if((str[i].size()/2) % j != 0) continue;
        bool flag = true;
        REP(k,str[i].size()/2){
          //printf("test: %c %c\n",str[i][k*2],str[i][k*2+1]);
          if(k % j == 0) continue;
          if(str[i][k*2] == '0' && str[i][k*2+1] == '0')
            continue;
          flag = false;
          break;
        }
        if(flag){
          string tmp;
          REP(k,str[i].size()/2){
            if(k % j == 0){
              tmp += str[i][k*2];
              tmp += str[i][k*2+1];
            }
          }
          str[i] = tmp;
          j--;
          //cout << "tmp:" << tmp << endl;
          //cout << "size:" << tmp.size() << endl;
        }
      }
    }
    int len = 1;
    REP(i,m){
      int tmp = str[i].size()/2;
      len = len * tmp / gcd(len, tmp);
      if(len > 1024) break;
    }
    if(len > 1024){
      puts("Too complex.");
      continue;
    }
    REP(i,m){
      step[i] = len / (str[i].size()/2);
    }
    char buff[len*2 + 1];
    buff[len*2] = '\0';
    REP(i, len){
      int fst = 0;
      int scd = 0;
      REP(j,m){
        if(i % step[j] == 0){
          //cout << str[j][(i/step[j])*2] << endl;
          //cout << str[j][(i/step[j])*2+1] << endl;
          fst |= str[j][(i/step[j])*2] - '0';
          scd |= str[j][(i/step[j])*2 + 1] - '0';
        }
      }
      buff[i*2] = toChar(fst);
      buff[i*2+1] = toChar(scd);
    }
    puts(buff);
  }
  return 0;
}

Measured memory_bytes: 924
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
typedef pair<int, int> P;
const int MAX_N = 1000000000;
const int MAX_L = 100000000;
const int MAX_SQRT_B = 10000;
const int INF = 1000000000;
typedef int64_t ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int N;
int A[100005];
int B[100005];

int main() {
	cin >> N;
	rep(i, N + 1) {
		cin >> A[i];
	}
	rep(i, N) {
		cin >> B[i];
	}

	ll ans = 0;
	ll V;
	rep(i, N) {
		V = min(A[i], B[i]);
		A[i] -= V;
		B[i] -= V;
		ans += V;

		V = min(A[i + 1], B[i]);
		A[i + 1] -= V;
		ans += V;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4356
#include <bits/stdc++.h>
#define ok 5000099
using namespace std;
using ll = long long int;
ll x, t, k;
void inp()
{
    cin >> k >> x >> t;
}
void process()
{
    if (k <= x) cout << t;
    else if (k%x == 0) cout << ll((k/x)*t);
    else cout << ll(((k/x)+1)*t);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("test.inp","r", stdin);
    inp();
    process();
    return 0;
}



Measured memory_bytes: 3600
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

#define SENTINEL 1000000000

int count=0;

void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  int *L,*R;
  n1=mid-left;
  n2=right-mid;
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));
  for(i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }
  for(j=0;j<=n2-1;j++){
    R[j]=A[mid+j];
  }
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
   if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      count++;
    }
    else{
      A[k]=R[j];
      j++;
      count++;
    }
  }
  free(L);
  free(R);
}

void mergeSort(int A[],int left,int right){
  int i,mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}


int main(){

  int n,i;
  int a[222222];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    a[i] -= (i+1);
  }
  mergeSort(a,0,n);
  long b = a[n/2];
  if(n%2==0) b = (a[n/2-1] + a[n/2])/2;
  
  long sad=0;

  for(i=0;i<n;i++){
    sad += abs(a[i]-b);
  }

  printf("%ld\n",sad);
  
  

  return 0;
}


Measured memory_bytes: 1908
def p(u):
 if u+1:print(s,u,end=s);p(T[u]);p(T[u+N])
def i(u):
 if u+1:i(T[u]);print(s,u,end=s);i(T[u+N])
def o(u):
 if u+1:o(T[u]);o(T[u+N]);print(s,u,end=s)
s=''
N=int(input())
Z=[0]*N
T=Z+Z
for _ in Z:
 a,b,c=map(int,input().split())
 T[a],T[a+N]=b,c
r=(set(range(N))-set(T)).pop()
print('Preorder');p(r)
print('\nInorder');i(r)
print('\nPostorder');o(r)
print()


Measured memory_bytes: 5624
#include <iostream>
#include<string>
#include<stack>
#include <cstdlib>

using namespace std;

int main()
{
    stack<int> mystack;
    string in;
    while( cin >> in) {
        if(in == "+") {
            int x = mystack.top();
            mystack.pop();
            int y = mystack.top();
            mystack.pop();
            int z = x + y;
            mystack.push(z);
        }
        else if(in == "-") {
            int x = mystack.top();
            mystack.pop();
            int y = mystack.top();
            mystack.pop();
            int z = y-x;
            mystack.push(z);

        }else if(in == "*") {
            int x = mystack.top();
            mystack.pop();
            int y = mystack.top();
            mystack.pop();
            int z = x * y;
            mystack.push(z);

        }else {
            mystack.push(atoi(in.c_str()));
        }
        //cout << in <<endl;
    }
    cout << mystack.top() << endl;
    return 0;
}

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

const ll MOD = 1e9+7;

map<ll,ll> pnum;
void prime_factor(ll n){
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      pnum[i]++;
      n /= i;
    }
  }
  if(n != 1) pnum[n]++;
}


//最大公約数を求める
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/gcd(a,b)*b;
}

//素数判定
template<class T>
bool isPrime(T n){
    if(n < 2) return false;
    for(T i = 2; i*i < n; ++i) if(n % i == 0) return false;
    return true;
}

//素因数分解


//関数名：pow
//概要：modつき指数関数
//第一引数a：指数の底
//第二引数b：指数
//第三引数mod：法となる値
//戻り値：a^b(m mod)
template<class T>
T pow(T a, int b){
    if(b == 0) return 1;
    if(b%2){
        T ret = pow(a,(b-1)/2); 
        return ret*ret*a;
    }else{
        T ret = pow(a,b/2);
        return ret*ret;
    }
}

template<class T>
T pow(long long a, long long b, T mod){
    if(b == 0) return 1;
    if(b % 2 == 0){
        T d = pow(a,b/2,mod);
        return (d*d)%mod;
    }else return a%mod*pow(a,b-1,mod)%mod;
}

//関数名：comb
//概要：二項係数
//第一引数n：組み合わせの全体
//第二引数r：何個取り出すか
//第三引数mod：法となる値
//戻り値：nCr(m mod)
template<class T>
T comb(T n, T r){
    if(r > n) return 0;
    if(n == r || r == 0) return 1;
    T ret = 1;
    for(T i = 1; i <= r; ++i){
        ret *= n--;
        ret /= i;
    }
    return ret;
}

template<class T>
T comb(long long n,long long r,T mod){
    if(r > n) return 0;
    if(n == r || r == 0) return 1;
    long long fact1 = 1,fact2 = 1;
    for(long long i = n; i >= n-r+1; --i) fact1 = fact1*i%mod;
    for(long long i = r; i >= 1; --i) fact2 = fact2*i%mod;
    return fact1*pow(fact2,mod-2,mod)%mod;
}




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

    ll n; cin >> n;

    // 素因数列挙
    for(ll i = 2; i <= n; ++i) prime_factor(i);

    ll ans = 1LL;
    // 実計算
    for(auto i:pnum) ans = ans*(i.second + 1)%MOD;
    
    // 出力
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll h, a;
  cin >> h >> a;
  if (h%a == 0) {
    cout << h/a << endl;
  } else {
    cout << h/a+1 << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    int[][] a = new int[H][W];
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) a[i][j] = scanner.nextInt();

    StringBuilder sb = new StringBuilder();
    int cnt = 0;
    for (int n = 0; n < H * W - 1; n++) {
      int ci = ntoi(n, H, W);
      int cj = ntoj(n, H, W);
      int ni = ntoi(n + 1, H ,W);
      int nj = ntoj(n + 1, H, W);
      if (a[ci][cj] % 2 != 0) {
        a[ni][nj]++;
        cnt++;
        sb.append(String.format("%d %d %d %d\n", ci + 1, cj + 1, ni + 1, nj + 1));
      }
    }
    System.out.println(cnt);
    if (sb.length() > 0) System.out.print(sb.toString());
  }

  private static int ntoi(int n, int H, int W) {
    return n / W;
  }

  private static int ntoj(int n, int H, int W) {
    int i = n / W;
    if (i % 2 == 0) {
      return n % W;
    }
    int j = n % W;
    j = W - j - 1;
    return j;
  }
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

void Main()
{
    int a,b,c;
    cin >> a >> b >> c;
    cout<<max(0, (c-(a-b))) <<endl;
}
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    string S,T;
    cin >>S>>T;
    
    N=S.size();
    if(S==T){
        cout<<"Yes"<<endl;
        return 0;
    }
    rep(i,N){
        S =  S[N-1]+S.substr(0,N-1);
        if(S==T){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    
    
    cout <<"No" << endl;


    return 0;
    

}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const ll INF = 1E+15;

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

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var l, r int
	fmt.Scan(&l, &r)
	if r - l > 2019 {
		fmt.Println(0)
		return
	}
	min := 2019
	for i := l; i < r; i++ {
		for j := i + 1; j <= r; j++ {
			cal := (i * j) % 2019
			if cal < min {
				min = cal
			}
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	long long int n;
	cin >> n;
	long long int MIN = n;
	for (long long int i = 1; i <= n / 2; i++) {
		long long int a = i;
		long long int b = n - a;
		long long int ans = 0;
		//cout << a << ' ' << b << ' ' << endl;
		while (a != 0) {
			ans += (a % 10);
			a /= 10;
		}
		while (b != 0) {
			ans += (b % 10);
			b /= 10;
			//cout << b << endl;
		}
		//cout << ans << endl;
		MIN = min(MIN, ans);
	}
	cout << MIN << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	int N, M;
	String S, T;
	long result = -1L;

	private Main() {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		M = Integer.parseInt(tokens[1]);
		if (N < M) {
			int temp = N;
			N = M;
			M = temp;
			T = in.nextLine();
			S = in.nextLine();
		} else {
			S = in.nextLine();
			T = in.nextLine();
		}
		in.close();
	}

	private void calc() {
		long saishouKoubai = saishouKoubai(N, M);
		if (N == M) {
			// 同じ長さ -> すべての要素が同じ
			result = N;
			for (int i = 0; i < N; ++i) {
				if (S.charAt(i) != T.charAt(i)) {
					result = -1;
					break;
				}
			}
		} else {
			int saidaiKouyaku = gcd(N, M);
			int sStep = N / saidaiKouyaku;
			int tStep = M / saidaiKouyaku;
			int sIndex = 0;
			int tIndex = 0;
			result = saishouKoubai;
			// System.out.println(S + ", " + T);
			for (int i = 0; i < saidaiKouyaku; ++i) {
				// System.out.println(sIndex + ", " + tIndex);
				if (S.charAt(sIndex) != T.charAt(tIndex)) {
					result = -1;
					break;
				}
				sIndex += sStep;
				tIndex += tStep;
			}
		}
		return;

	}

	private void show() {
		System.out.println(result);
	}

	private long saishouKoubai(int large, int little) {
		if (large < little) {
			return saishouKoubai(little, large);
		}
		int saidaiKouyaku = gcd(large, little);
		long result = (long)(little / saidaiKouyaku);
		result *= (long)large;
		return result;
	}

	private int gcd(int large, int little) {
		if (large < little) {
			return gcd(little, large);
		}
		if (large % little == 0) {
			return little;
		}
		return gcd(little, large % little);
	}

	public static void main(String[] args) {
		Main ins = new Main();
		ins.calc();
		ins.show();

	}

}

Measured memory_bytes: 26188
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
const int N = 3000300;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const int mod =    1e9+7;
ll n;
ll arr[1000000];
int main()
{ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n;
rep(i,1,n+1)
cin>>arr[i];
rep(i,1,n+1)
arr[i]+=arr[i-1];
bool b=false;
if(arr[n]%2)
b=true;
ll sum=0;
ll i=0;
ll ans=0;
bool x=false;
for( i=1;sum<=arr[n]/2&i<=n;i++)
{

sum=arr[i];
	//cout<<sum<<endl;
if(sum>=arr[n]/2)
break;}
cout<<abs(arr[i]-arr[i-1]-abs(arr[i-1]-arr[n]+arr[i]));



}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;

int main(){
  string S;
  cin >> S;
  string ans = "AC";
  if(S[0] != 'A') ans = "WA";
  int c = 0;
  for(size_t i = 2; i < S.length()-1; ++i){
    if(S[i] == 'C') ++c;
  }
  if(c != 1) ans = "WA";
  for(int i = 1; i < S.length(); ++i){
    if(S[i] != 'C' && S[i] < 'a' || S[i] > 'z'){
      ans = "WA";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
typedef long long ll;
ll n, k, c, lst;
bool flag;
string s;
ll cnt;
bool vis[200010];
stack<int> stk;
int main() {
	cin >> n >> k >> c;
	cin >> s;
	lst = -1;
	for (int i = 0; i < (int)(s.length()); i++) {
		if (s[i] == 'x' || lst >= i) continue;
		if (cnt >= k) {
			flag = 1;
			break;
		}
		lst = i + c;
		vis[i] = 1;
		cnt++;
	}
	if (flag) {
		return 0;
	}
	lst = s.length();
	for (int i = (int)s.length() - 1; i >= 0; i--) {
		if (s[i] == 'x' || lst <= i) continue;
		lst = i - c;
		if (vis[i]) {
			stk.push(i);
		}
	}
	while (!stk.empty()) {
		cout << stk.top() + 1 << endl;;
		stk.pop();
	}
	return 0;
}

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

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = false;

int main(){

    int n;
    cin >> n;

    vector< bitset<30> > bs(n);
    for(int i = 0; i < n; i++){
        ll tmp;
        cin >> tmp;
        bitset<30> b(tmp);
        bs[i] = b;
    }

    if(DEBUG){
        cout << "------------" << endl;
        for(int i = 0; i < n; i++){
            cout << bs[i] << endl;
        }
        cout << "------------" << endl;

    }


    if(n == 2){
        cout << bs[1].to_ulong() << endl;
        cout << bs[0].to_ulong() << endl;
        return 0;
    }

    bitset<30> b(0);
    for(int j = 1; j < n; j++){
        b ^= ( bs[ j ] ^ bs[0] ) ;
    }
    b ^= bs[0];
    cout << b.to_ulong() << endl;


    for(int i = 1; i < n; i++){
        b ^= (bs[i] ^ bs[i - 1] );
        cout << b.to_ulong() << endl;
    }



    return 0;
}

Measured memory_bytes: 4788
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
long long l;
int main(){
	ios::sync_with_stdio(0);
	cin>>l;
	l*=l*l;
	cout<<l/27ll<<".";
	l%=27;
	rep(i,12){
		l*=10;
		cout<<l/27;
		l%=27;
	}
	re 0;
}

Measured memory_bytes: 256