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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}

#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

void err(vector<string>::iterator it) {}

template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> inline T tabs(T a) { return (a > 0) ? a : -a; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	string s;

	cin >> s;
	cout << s.substr(0, 4) << " " << s.substr(4) << endl;

	return 0;
}


Measured memory_bytes: 764
import java.util.Scanner;
public class Main {

		public static void main(String[] args) {
			Scanner scan = new Scanner(System.in);
			int d,n;
			d=scan.nextInt();
			n=scan.nextInt();

			int cnt=0;
			for(int i=1;;i++) {
				if(func(i)==d) {
					cnt++;
					if(cnt==n) {
						System.out.println(i);
						break;
					}
				}
			}
		}

		static int func(int x) {
			if(x%100!=0)return 0;
			return func(x/100)+1;
		}
}

Measured memory_bytes: 23764
# 写経
# https://atcoder.jp/contests/arc092/submissions/5244389

from bisect import bisect_left

INF = float('inf')

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

def calc_bit(k):
    # これ以上の桁は不要
    mod = 1 << (k + 1)
    amod = [a & (mod - 1) for a in A]
    bmod = [b & (mod - 1) for b in B]
    amod.sort()
    bmod.sort()
    ret = 0

    # bmod + amod のうち k ビット目が 1 となる数
    # => (1 << k) 以上 (2 << k) 未満または (3 << k) 以上 (4 << k) 未満
    # しゃくとる
    b01 = bisect_left(bmod, (1 << k) - amod[0])
    b10 = bisect_left(bmod, (2 << k) - amod[0])
    b11 = bisect_left(bmod, (3 << k) - amod[0])
    for a in range(len(amod)):
        while b01 - 1 >= 0 and bmod[b01 - 1] >= (1 << k) - amod[a]:
            b01 -= 1
        while b10 - 1 >= 0 and bmod[b10 - 1] >= (2 << k) - amod[a]:
            b10 -= 1
        while b11 - 1 >= 0 and bmod[b11 - 1] >= (3 << k) - amod[a]:
            b11 -= 1
        # (1 << k) 以上 (2 << k) 未満
        ret += b10 - b01
        # (3 << k) 以上 (4 << k) 未満
        ret += N - b11

    return ret % 2


ans = 0
for i in range(30):
    ans += calc_bit(i) * (1<<i)
print(ans)


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SORT(v, n) sort(v, v+n);
#define SSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if((abs(a-b)<=d && abs(b-c)<=d) || abs(a-c)<=d) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	

}


Measured memory_bytes: 256
/*  Name: Abu Hurayra
    Handle: HurayraIIT
    Institute: IIT_JU   */
    
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef string S;
typedef double D;
typedef vector<int> vi;
typedef stack<int> si;
typedef queue<int> qi;
typedef priority_queue<int> pqi;
typedef pair<int,int> pi;

#define pi acos(-1.0)
#define PSB push_back
#define PPB pop_back
#define REP(i,a,b) for(i=a;i<=b;i++)

int main()
{
    
    int a,b;
    cin >> a >> b ;
    if(a>8 || b>8) cout << ":(\n";
    else cout << "Yay!\n";
	
	
	
	return 0;
}

Measured memory_bytes: 256
N,M=gets.split.map(&:to_i)
as=Array.new(N+1,false)
M.times do
  as[gets.to_i]=true
end
dp=Array.new(N+1,0)
dp[0]=1
dp[1]=as[1] ? 0 : 1
for i in 2..N
  dp[i]+=dp[i-2] if !as[i-2]
  dp[i]+=dp[i-1] if !as[i-1]
  dp[i]%=1000000007
end
puts dp[N]

Measured memory_bytes: 3580
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		int[][] A = new int[2][N];
		
		for(int i = 0 ; i < 2 * N ; i ++){
			if(i < N){
				A[0][i] = sc.nextInt();
			}else {
				A[1][i - N] = sc.nextInt();
			}
//			System.out.printf(" A[ %d ][ %d ] = %d \n" , (i < N) ? 0:1 ,(i < N) ? i: i - N,
//			(i < N) ? A[0][i] : A[1][i - N]  );
		}
		
		int maxCandies = 0;
		
		
		for(int i = 0 ; i < N ; i++){
			int sum_i = 0;
			for(int j = 0 ; j < N ; j++){
				if(j < i ){
					sum_i = sum_i + A[0][j];
				}else if(j == i){
					sum_i = sum_i + A[0][j] + A[1][j] ;
				}else {
					sum_i = sum_i + A[1][j];
				}
			}
			if(maxCandies < sum_i){
				maxCandies = sum_i;
			}
		}
		
		System.out.println(maxCandies);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; cin >> N;
  vector<pair<double, string>> MY(N);
  for (int i=0;i<N;i++){
    cin >> MY.at(i).first >> MY.at(i).second;
  }
  for (int i=0;i<N;i++){
    if(MY.at(i).second=="BTC"){ MY.at(i).first*=380000.0;}
  }
  double total=0;
  for(int i=0;i<N;i++){
    total+=MY.at(i).first;
  }
  cout << fixed << setprecision(6);
  cout << total << endl;
}





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

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <climits>

using namespace std;



int main() {
	int d, n;
	cin >> d >>n;

	int ans;

	if (n != 100) {
		ans = n * pow(100, d);
	}
	else {
		ans = n * pow(100, d)+1* pow(100, d);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3768
object Main extends App {
    val sc = new java.util.Scanner(System.in)

    var a = sc.nextInt
    var b = sc.nextInt
    var c = sc.nextInt
    val k = sc.nextInt

    var i = 0
    while(a >= b) {
        b *= 2
        i+=1
    }
    while(b >= c) {
        c *= 2
        i+=1
    }

    val ans = if (i <= k) "Yes" else "No"
    println(ans)
    
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	unordered_map<string, int> vote_count;
	set<string> max_votes;
	string vote;
	int max_vote = 0;
	for (int i = 0; i < n; ++i) {
		cin >> vote;
		if (vote_count.count(vote)) {
			vote_count[vote]++;
		}
		else vote_count[vote] = 1;
		max_vote = max(max_vote, vote_count[vote]);
	}
	for (auto x : vote_count) {
		if (x.second == max_vote)
			max_votes.insert(x.first);
	}
	for (auto x : max_votes) {
		cout << x << '\n';
	}
	return 0;
}

Measured memory_bytes: 33480
#include <iostream>
#include<map>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include<set>
#include<string>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<queue>
#include<stack>
#define ll long long
using namespace std;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);


int main() {
	ll n,k;  cin >> n>>k;
	ll* arr = new ll[n+1];
	for (int i = 1; i <= n; i++)
		cin >> arr[i];
	ll* dp = new ll[n+1];
	dp[1] = 0;
	for (ll i = 2; i <= n; i++)
	{
		ll mn = 1e18;
		for (int j=max(i-k,1LL) ; j < i; j++)
		   mn = min(mn, dp[j] + abs(arr[j] - arr[i]));
		dp[i] = mn;
	}
	cout << dp[n];
	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cstdio>
#define add(x, y) x = x+y<P?x+y:x+y-P
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 3e3+5, P = 1e9+7;
int n, m, f[2][N][N], ans;
int main()
{
    n = read(), m = read();
    for(int i = 1; i <= n; ++i) f[0][0][i] = 1; f[1][0][0] = 1;
    for(int i = 1; i <= m; ++i)
        for(int j = 0; j <= n; ++j)
            for(int k = 0; k < 2; ++k)
            {
                if(j) add(f[k|(j == 1)][i][j], f[k][i-1][j]), add(f[k|(j == 1)][i][j-1], f[k][i-1][j]);
                if(n-j) add(f[k][i][j+1], f[k][i-1][j]), add(f[k][i][j], f[k][i-1][j]);
            }
    for(int i = 0; i <= n; ++i) add(ans, f[1][m][i]);
    printf("%d\n", ans);
    return 0;
}

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

int main(){
    int n,k,q;
    cin >> n>>k>>q;
    vector<int> b(n, k-q);
    rep(i,q){
        int a;
        cin>>a;
        a--;
        b[a]++;
    }
    rep(i,n){
        if(b[i]>0) puts("Yes");
        else puts("No");
    }
    
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    ll cnt = K;
    ll ans = 0;

    // A
    if (cnt >= A) {
        ans += A;
        cnt -= A;
    } else {
        ans += cnt;
        cnt = 0;
    }

    // B
    if (cnt > 0) {
        cnt = max(0LL, cnt - B);
    }

    // C
    if (cnt > 0) {
        ans -= cnt;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> c( N );
	for( int i = 0; i < M; i++ ) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		c[a]++;
		c[b]++;
	}

	string ans = "YES";
	for( int i = 0; i < N; i++ ) {
		if( c[i] % 2 ) {
			ans = "NO";
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

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

    vector<int> t(N), x(N), y(N);
    for( int i = 0; i < N; ++i )
        cin >> t[i] >> x[i] >> y[i];

    int ct = 0, cx = 0, cy = 0;
    int dt, dx, dy;

    for( int i = 0; i < N; ++i ){
        dx = abs(x[i] - cx);
        dy = abs(y[i] - cy);
        dt = abs(t[i] - ct);

        if( dx + dy <= dt ){
            if( (dx+dy)%2 != dt%2 ){
                cout << "No" << endl;
                return 0;
            }
        } else {
            cout << "No" << endl;
            return 0;
        }

        ct = t[i];
        cx = x[i];
        cy = y[i];
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <stack>
#include <set>
#include <map>
#include <functional>
#include <array>

using namespace std;
struct LowLink {
	set<pair<int, int>> bridge;
	vector<int> articulation, ord, low;
	vector<bool> used;
	vector<vector<int>> g;
	int n, k = 0;
	LowLink(const vector<vector<int>> &g) : g(g) {
		n = g.size();
		ord.resize(n, 0);
		low.resize(n, 0);
		used.resize(n, false);
	}
	void dfs(int u, int prev) {

		used[u] = true;
		ord[u] = k++;
		low[u] = ord[u];
		bool is_articulation = false;
		int cnt = 0;
		for (auto v : g[u]) if (v != prev) {
			if (!used[v]) {
				cnt++;
				dfs(v, u);
				low[u] = min(low[u], low[v]);
				if (low[v] > ord[u]) {
					bridge.emplace(min(u, v), max(u, v));
				}
				if (prev != -1 && low[v] >= ord[u]) {
					is_articulation = true;
				}
			}
			else {
				low[u] = min(low[u], ord[v]);
			}
		}
		if (prev == -1 && cnt > 1) is_articulation = true;
		if (is_articulation) articulation.push_back(u);
	}
};
struct TwoEdgeConnectedComponent {
	int n;
	vector<vector<int>> g, tree;
	vector<int> cmp;
	TwoEdgeConnectedComponent(const vector<vector<int>> &g) : g(g) {
		n = (int)g.size();
		cmp.assign(n, -1);
	}
	void build() {
		LowLink lnk(g);
		for (int i = 0; n > i; i++) {
			if(lnk.used[i] == false)
				lnk.dfs(i, -1);
		}
		int k = 0;
		function<void(int, int)> dfs = [&](int u, int prev) {
			cmp[u] = k;
			for (auto v : g[u]) if (cmp[v] == -1 && lnk.bridge.count({ min(u, v), max(u, v) }) == 0) {
				dfs(v, u);
			}
		};
		for (int i = 0; i < n; i++) if (cmp[i] == -1) {
			dfs(i, -1);
			k++;
		}
		tree.resize(k);
		for (auto e : lnk.bridge) {
			tree[cmp[e.first]].push_back(cmp[e.second]);
			tree[cmp[e.second]].push_back(cmp[e.first]);
		}
	}
};

int main() {

	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n);

	for (int i = 0; m > i; i++) {
		int s, t;
		cin >> s >> t;
		g[s].push_back(t);
		g[t].push_back(s);
	}

	TwoEdgeConnectedComponent tecc(g);
	tecc.build();
	
	vector<int> sz(tecc.tree.size());
	vector<array<int, 2>> dp(tecc.tree.size());

	for (int i = 0; n > i; i++) {
		sz[tecc.cmp[i]]++;
	}

	function<void(int, int)> dfs = [&](int cur, int par){
		dp[cur][1] = sz[cur];
		for (auto itr : tecc.tree[cur]) {
			if (itr == par) continue;
			dfs(itr, cur);
			dp[cur][0] += max(dp[itr][0], dp[itr][1]);
			dp[cur][1] += dp[itr][0];
		}
	};

	int ans = 0;

	for (int i = 0; tecc.tree.size() > i; i++) {
		if (dp[i][1] == 0) {
			dfs(i, -1);
			ans += max(dp[i][0],dp[i][1]);
		}
	}

	cout << ans << endl;

	return 0;
}



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

int main()
{
    int n,k;
    cin >> n >> k;

    int ans =0;

    while(n >= 1)
    {
        n = n/k;
        ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int A,B,C,D,N,M;

int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  string in;
  cin >> in;
  int r = 0;
  int b = 0;
  for(int i = 0; i < N; i++) {
    if(in[i] == 'R') r++;
    else b++;
  }
  if(r > b) cout << "Yes";
  else cout << "No";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n,m,i,j,t;
  cin >> n;
  if(n%2==0){
    m=n*(n-2)/2;
    cout << m << endl;
    t=n+1;
    for(i=2;i<=n;i++)
      for(j=1;j<i;j++)
        if(i+j!=t)
          cout << j << " " << i << endl;
  }else{
    m=(n-1)*(n-1)/2;
    cout << m << endl;
    t=n;
    for(i=2;i<=n;i++)
      for(j=1;j<i;j++)
        if(i+j!=t)
          cout << j << " " << i << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    string s; cin >> s;
    bool judge = 0;
    if((s[0] == s[1] and s[1] == s[2]) or (s[1] == s[2] and s[2] == s[3])) judge = 1;
    cout << (judge ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

a.sort()

a_i = a[-1]
tmp = a_i / 2
a_j = a[0]
for j in range(n - 1):
    if abs(tmp - a[j]) < abs(tmp - a_j):
        a_j = a[j]

print(a_i, a_j)


Measured memory_bytes: 14428
a, b, x = map(int, input().split())

if a // 2 < b:
    num_a = x // 1000
    if x % 1000 == 0:
        print(a * num_a)
    elif a < b:
        print(a * (num_a + 1))
    elif x % 1000 > 500:
        print(a * (num_a + 1))
    else:
        print(a * num_a + b)
else:
    num_b = x // 500
    if x % 500 == 0:
        print(b * num_b)
    else:
        print(b * (num_b + 1))



Measured memory_bytes: 5596
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] d = new int[N];
		for(int i=0; i<N; i++)d[i] = sc.nextInt();

		Arrays.sort(d);
		int ans=0;

		for(int i=0; i<N-1; i++){
			if(d[i+1]!=d[i]){
				ans ++;
			}
		}
		ans++;
		System.out.print(ans);
	}	
}


Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>

int compare(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main(void)
{
    int num[3], i;
    for (i = 0; i < 3; ++i) scanf("%d", &num[i]);
    qsort(num, 3, sizeof(int), compare);
    printf("%d", num[0] * 10 + num[1] + num[2]);
    return 0;
}

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

def main():
    N = int(input())
    A = list(map(int, input().split()))

    for x in A:
        if x % 2 == 0:
            if (x % 3 == 0) or (x % 5 == 0):
                continue
            else:
                print('DENIED')
                quit()

    print('APPROVED')





if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
package main

import "fmt"

func main() {
  var N int
  fmt.Scan(&N)
  line1 := make([]int, N)
  line2 := make([]int, N)

  for i:= 0; i<N; i++{
    fmt.Scan(&line1[i])
  }
  for i:=0; i<N; i++{
    fmt.Scan(&line2[i])
  }
  // fmt.Println(line1)
  // fmt.Println(line2)
  result := 0
  sum := 0
  for i:=0; i<N; i++{ //i番目で下に降りる
    sum = 0
    for j:=0; j<=i; j++{
      sum += line1[j]
    }
    for k:=i; k<N; k++{
      sum += line2[k]
    }
    // fmt.Println(sum)
    if sum >= result{
        result = sum
    }
  }
  fmt.Println(result)
}


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

int main(){
  int n,ans,f;
  cin >> n;
  f = n/100;//first digit
  if (f*111 >= n){
    cout << f*111;
  }
  else {
    cout << (f+1)*111;
  }
  
  return 0;
}

Measured memory_bytes: 256
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n,k;cin >>n>>k;
    int res=min(n%k,k-(n%k));
    cout <<res<<endl;
}

















Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] sArr = Console.ReadLine().Split(' ');
            int n = int.Parse(sArr[0]);
            int m = int.Parse(sArr[1]);
            int[,] arrA = new int[n, m];

            for (int i = 0; i < n; i++)
            {
                int[] iArr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                for (int j = 0; j < iArr.Length; j++)
                {
                    arrA[i, j] = iArr[j];
                }
            }

            int[] vecB = new int[m];
            for (int i = 0; i < m; i++)
            {
                vecB[i] = int.Parse(Console.ReadLine());
            }

            for (int i = 0; i < n; i++)
            {
                int sum = 0;
                for (int j = 0; j < m; j++)
                {
                    sum += arrA[i, j] * vecB[j];
                }
                Console.WriteLine(sum);
            }

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9688
#include <cstdio>
#include <iostream>

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

using namespace std;

char c;

signed main(){
  cin >> c;
  
  switch(c){
  case 'a':
  case 'i':
  case 'u':
  case 'e':
  case 'o':
    cout << "vowel" << endl;
    break;
  default:
    cout << "consonant" << endl;
  }
  
  
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		var cnt = new long[N + 1];
		for(long i = 1; i <= N; i++)
		{
			for(long j = 1; i * j <= N; j++)
				cnt[i * j]++;
		}

		long ans = 0;
		for(long i = 1; i <= N; i++)
			ans += i * cnt[i];
			
		WriteLine(ans);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 105660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i,n) cin >> x[i] >> y[i];
  auto dist = [&](int i, int j) {
    double dx = x[i]-x[j];
    double dy = y[i]-y[j];
    return sqrt(dx*dx+dy*dy);
  };
  vector<int> p(n);
  rep(i,n) p[i] = i;
  double len = 0;
  int cnt = 0;
  do {
    rep(i,n-1) {
      len += dist(p[i],p[i+1]);
    }
    cnt++;
  } while (next_permutation(p.begin(), p.end()));
  double ans = len/cnt;
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 3852
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#define maxr 100005
#define maxn 300005
#define ll long long int 
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define gc() ((p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, maxr, stdin), p1 == p2)) ? EOF : *p1++)
using namespace std;

char buffer[maxr], *p1, *p2;
template <class T> void read(T& x){
	char ch = gc(); x = 0; bool f = 1;
	while (!('0' <= ch && ch <= '9') && ch != '-') ch = gc();
	if (ch == '-') f = 0, ch = gc();
	while ('0' <= ch && ch <= '9') x = (x << 1) + (x << 3) + ch - '0', ch = gc();
	if (!f) x = -x;
}

int n;
int a[maxn];
int main(){
	/*#ifndef ONLINE_JUDGE
		freopen("la.in", "r", stdin);
	#endif*/
	read(n);
	rep(i, 1, n) read(a[i]), a[i] -= i;
	sort(a + 1, a + 1 + n);
	int b = a[(n + 1) / 2];
	ll ans = 0;
	rep(i, 1, n) ans += abs(a[i] - b);
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int dp[1010][10100];

int main(){
  int h, n;
  cin >> h >> n;
  vector<int> weight(n);
  vector<int> value(n);
  for(int i = 0; i < n; ++i){
    cin >> weight[i] >> value[i];
  }

  fill((int*)dp, (int*)dp + sizeof(dp) / sizeof(int), INF);
  for(int i = 0; i <= n; ++i)dp[i][0] = 0;

  for(int i = 0; i < n; ++i){
    for(int j = 0; j <= h; ++j){
      if(j >= weight[i])dp[i + 1][j] = min(dp[i + 1][j - weight[i]] + value[i], dp[i][j]);
      else dp[i + 1][j] = min(dp[i + 1][0] + value[i], dp[i][j]);
    }
  }

  cout << dp[n][h] << endl;

  return 0;
}


Measured memory_bytes: 40192
#include<iostream>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  if(A<B){
    cout<<0<<endl;
  }
  else if(A/2<B){
    cout<<0<<endl;
  }
  else{
    cout<<A-2*B<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
s=input()
a=[]
for i in range(len(s)):
  if i%2==0:
    a.append('0')
  else:
    a.append('1')
b=[]
for j in range(len(s)):
  if j%2==0:
    b.append('1')
  else:
    b.append('0')
cnt=0
for k in range(len(s)):
  if s[k]!=a[k]:
    cnt+=1
ans=0
for l in range(len(s)):
  if s[l]!=b[l]:
    ans+=1
print(min(cnt,ans))


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

int main() {
    int A, B;

    cin >> A >> B;

    int cnt = 0;

    for (int i = A; i <= B; i++) {

        //int target = i;
        string target_s = to_string(i);
        //cout << "target_s: " << target_s <<  endl;

        int keta = target_s.size();
        int keta_han = keta / 2;

        //cout << "keta    : " << keta <<  endl;
        //cout << "keta_han: " << keta_han <<  endl;


        bool ok = true;

        for (int j = 0; j < keta_han; j++) {
            //cout << "t1: " << target_s[j] <<  endl;
            //cout << "t2: " << target_s[keta - j - 1]<<  endl;
            if(target_s[j] == target_s[keta - j - 1]){
            }
            else{
                ok = false;
            }

        }

        if(ok){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;

}





Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


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

int main(void) {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  a--;
  ll lcm=c*d/gcd(c, d);
  
  ll cnta=a-(a/c+a/d-a/lcm);
  ll cntb=b-(b/c+b/d-b/lcm);
  pt(cntb-cnta);
}












Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n,k;cin>>n>>k;
	vector<int> h(n);
	for(auto& x:h){
		cin>>x;
	}
	sort(h.begin(),h.end());
	int ans=-1;
	for(int i=0;i<n;i++){
		int temp=h[i+k-1]-h[i];
		if(ans>temp)ans=temp;
		if(ans==-1)ans=temp;
		if(i+k-1==n-1)break;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using ll=long long;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int inf = 1e9 + 10;
const int mod = 1e9 + 7;

inline ll mod_pow(ll a, ll x, ll m)
{
	if (x == 0) return 1;

	ll res = mod_pow(a, x / 2, m);

	res *= res;
	res %= m;

	if (x % 2) {
		res *= a;
		res %= m;
	}

	return res;
}

int counter[26];

signed main()
{
	int N; cin >> N;
	string S; cin >> S;

	int ans = 0;

	rep(i, N) {
		int c = S[i] - 'a';
		counter[c]++;
		int add = 1;

		rep(j, 26) {
			if (j == c) continue;
			add *= (counter[j] + 1);
			add %= mod;
		}

		ans += add;
		ans %= mod;
	}

	cout << ans << endl;
}



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

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

    vector<int64_t> ans(N+1);
    for (int i = 0; i <= N; ++i) {
        if(i == 0) {
            ans.at(i) = 2;
        }else if(i == 1) {
            ans.at(i) = 1;
        }else {
            ans.at(i) = ans.at(i - 1) + ans.at(i - 2);
        }
    }
    cout << ans.at(N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a;
	cin>>a;
	long long ar[a+1];
	ar[0]=0;
	for(int i=1;i<=a;i++){
		cin>>ar[i];
		ar[i]=ar[i]+ar[i-1];
	}
	long long mi=9999999999ll;
	for(int i=2;i<a;i++){
		mi=min(mi,abs(abs(ar[i]-ar[a])-ar[i]));
	}
	cout<<mi<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;



public class Main {
	public static class FastReader {
			BufferedReader br;
			StringTokenizer root;
			
	 
			public FastReader() {
				br = new BufferedReader(new InputStreamReader(System.in));
			}
	 
			String next() {
				while (root == null || !root.hasMoreTokens()) {
					try {
						root = new StringTokenizer(br.readLine());
					} catch (Exception addd) {
						addd.printStackTrace();
					}
				}
				return root.nextToken();
			}
	 
			int nextInt() {
				return Integer.parseInt(next());
			}
	 
			double nextDouble() {
				return Double.parseDouble(next());
			}
	 
			long nextLong() {
				return Long.parseLong(next());
			}
	 
			String nextLine() {
				String str = "";
				try {
					str = br.readLine();
				} catch (Exception addd) {
					addd.printStackTrace();
				}
				return str;
			}
		}
	 
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static FastReader sc = new FastReader();
 
	static int mod = (int)(1e9+7),MAX=(int)(1e5+10);
	static List<int[]>[] edges;
	
	public static void main(String[] args) throws IOException{
	
		int n = sc.nextInt();
		long[] a = new long[n];
		Map<Long,Integer> map = new HashMap<>();
		long ans = 0;
		for(int i=0;i<n;++i) {
			a[i] = sc.nextLong();
			ans+=a[i];
			add(map,a[i],1);
		}
		int q = sc.nextInt();
		while(q-->0) {
			long b = sc.nextLong();
			long c = sc.nextLong();
			int bf = map.getOrDefault(b, 0);
			if(bf > 0) {
			ans-=b*bf;
			ans+=c*bf;
			add(map,c,bf);
			map.remove(b);
		  }
			out.println(ans);
		}
	  out.close();
	}
	  static void add(Map<Long, Integer> map, long a,int val) {
			if(map.containsKey(a)) map.put(a, map.get(a)+val);
			else map.put(a, val);
			
		}
		 static void delete(Map<Integer, Integer> map, int i,int val) {
			if(map.containsKey(i)) {
				if(map.get(i) == val) map.remove(i);
				else map.put(i, map.get(i)-val);
			}
			
		}
}

Measured memory_bytes: 59248
#include <iostream>
using namespace std;
int main() {
   string name;
   cin >> name;
   if(name.size() == 2){
       for (int i = 0; i <2 ; ++i) {
           cout << name[i];
       }
   } else{
       for (int i = 2; i >= 0; --i) {
           cout << name[i];
       }
   }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
typedef long long LL;
const int MAXN = 2e6+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
signed main(){
#ifndef ONLINE_JUDGE
    //freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
#endif // ONLINE_JUDGE
	int a,b; cin>>a>>b; cout<<6-a-b<<endl;
    return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
h, w = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
nums = [[-1]*w for _ in range(h)]
s = [0, 0]
f = [0, 0]
di = 1
j = 0
k = -1

for i in range(n):
    a = A[i]
    i_ = i + 1
    while a:
        if 0 <= k+di and k+di< w:
            nums[j][k+di] = i_
            k += di
        else:
            di = -di
            j += 1
            nums[j][k] = i_
        a -= 1

for i in range(h):
    b = nums[i]
    print(*b)

Measured memory_bytes: 3920
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var N = input[0].map(e => parseInt(e, 10))[0];
    var M = input[0].map(e => parseInt(e, 10))[1];
    var ans = 0;
    var ary_ab, vec_pi, ab, ary_p, tmp;
    ary_ab = Array.from({ length: N }, () => []);
    vec_pi = [];
    ary_p = [];
    	
    for (var i = 1; i <= M; i++){
		ab = input[i].map(e => parseInt(e, 10));
		ary_ab[ab[0] - 1].push(ab[1]);
	      ary_ab[ab[1] - 1].push(ab[0]);
    }
    for (var i = 0; i < N; i++){
    	vec_pi.push(i + 1);
    }
	ary_p.push(vec_pi.slice());    
    for (var i = 1; i < kaijo(N - 1); i++) {
    	switch_loop:
    	for (var j = 2; j < N; j++){
			for (var k = 1; k < j; k++){
				if (vec_pi[N - j] < vec_pi[N - k]){
					tmp = vec_pi[N - j];
					vec_pi[N - j] = vec_pi[N-k];
					vec_pi[N - k] = tmp;
					vec_pi = vec_pi.slice(0, (N - j + 1)).concat(vec_pi.slice(N - j + 1).sort(compareFunc));
					ary_p.push(vec_pi.slice());
					break switch_loop; 
				}
			}
		}
	}
	for (var i = 0; i < ary_p.length; i++){
		vec_pi = ary_p[i];
		var j = 0
		pOrder_loop:
		for (j = 0; j < (N - 1); j++){
			if (ary_ab[vec_pi[j]- 1].indexOf(vec_pi[j + 1]) == -1) break pOrder_loop;
		}
		if (j == (N - 1)) ans++;
	}
  console.log(ans);
}
function kaijo(num){
    var ans = 1;
    for (var i = 2; i <= num; i++){
        ans *= i;
    } 
    return ans;    
}
function compareFunc(a, b) {
  return a - b;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 34488
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

int n, q;
int a[100100], m;
set<int> si;

int main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, 1 << n) {
		int s = 0;
		rep(j, n) {
			if (i&(1 << j))s += a[j];
		}
		si.insert(s);
	}
	cin >> q;
	rep(i, q) {
		int m;
		cin >> m;
		if (si.find(m) != si.end())cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

Measured memory_bytes: 3128
n,y=map(int,input().split())
for i in range(n+1):
    for r in range(n+1-i):
        x=n-r-i
        total = 10000*i+5000*r+1000*x
        if total==y and i+r+x==n:
            print(i,r,x)
            exit(0)
print(-1,-1,-1)
                

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

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

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int A[110],B[110];
int S1[110],S2[110];
int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&A[i]);
	}
	for(int i = 1;i <= n;i++){
		scanf("%d",&B[i]);
	}
	int ans = 0;
	for(int i = n;i >= 1;i--){
		S1[i] = S1[i + 1] + A[i];
		S2[i] = S2[i + 1] + B[i];
	}
	
	for(int j = 1;j <= n;j++){
		ans = max(ans,S1[1] - S1[j + 1] + S2[j]);
	}
	
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int h, w;
int c[10][10];
bool vis[10];
int solve( int idx ){
    if( idx == 1 ){
        return 0;
    }
    int mn = INT_MAX;
    for( int i = 0 ; i < 10 ; ++i ){
        if( vis[ i ] == false && idx != i ){
            vis[i] = true;
            mn = min( mn, solve( i )+c[idx][i] );
            vis[i] = false;
        }
    }
    return mn;
}

int main(){

    cin >> h >> w;

    for( int i = 0 ; i < 10 ; ++i ){
        for( int j = 0 ; j < 10 ; ++j ){
            cin >> c[i][j];
        }
    }
    int x, ans = 0;
    map<int,int>mp;
    for( int i = 0 ; i < h*w ; ++i ){
        cin >> x;
        if( x != -1 ){
            ++mp[x];
        }
    }
    for( auto it: mp ){
        ans+=solve( it.first )*it.second;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include "math.h"
using namespace std;

int main()
{
  std::string s;
  cin >> s;
  if (s.find("a") == std::string::npos) {
    cout << "No";
  } else if (s.find("b") == std::string::npos) {
    cout << "No";
  } else if (s.find("c") == std::string::npos) {
    cout << "No";
  } else {
    cout << "Yes";
  }
  return 0;
}


Measured memory_bytes: 256
// Author: Tyler Wang

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

template <class Fun>
class y_combinator_result {
 public:
  template <class T>
  explicit y_combinator_result(T&& fun) : fun_(std::forward<T>(fun)) {}

  template <class... Args>
  decltype(auto) operator()(Args&&... args) {
    return fun_(std::ref(*this), std::forward<Args>(args)...);
  }

 private:
  Fun fun_;
};

template <class Fun>
decltype(auto) y_combinator(Fun&& fun) {
  return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.precision(12);
  std::cerr.precision(12);
  std::mt19937 rng((std::uint_fast32_t)std::chrono::high_resolution_clock::now()
                       .time_since_epoch()
                       .count());
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  constexpr long long INF = 1e18;
  vector<vector<long long>> dp(n, vector<long long>(n, -INF));
  auto solve = y_combinator([&](auto self, int l, int r) -> long long {
    if (dp[l][r] != -INF) {
      return dp[l][r];
    }
    if (l == r) {
      return dp[l][r] = a[l];
    }
    return dp[l][r] = max(a[l] - self(l + 1, r), a[r] - self(l, r - 1));
  });
  cout << solve(0, n - 1) << '\n';
  return 0;
}

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

int main(){
	while(1){
		int x, y,t;
		cin >> x >> y;
		if(x == 0 && y == 0)break;
		if(x > y){
			t=x;
			x=y;
			y=t;
		}
		cout << x << " " << y << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
import fractions
A,B=map(int,input().split())
A,B=min(A,B),max(A,B)
g=fractions.gcd(A,B)
ans=1
for i in range(2,int(g**0.5+1)):
  if g%i==0:
    ans+=1
    while g%i==0:
      g/=i
    if g==1:
      break
if g!=1:
  ans+=1
print(ans)
    



Measured memory_bytes: 5044
var s:string;
b0,b1:boolean;
begin
        readln(s);
        b0:=false;
        b1:=false; 
        if ((s[1]='1') and (s[2]<='2')) or ((s[1]='0') and (s[2]>'0')) then b0:=true;
        if ((s[3]='1') and (s[4]<='2')) or ((s[3]='0') and (s[4]>'0')) then b1:=true;
        if b0 then begin
                if b1 then writeln('AMBIGUOUS') else writeln('MMYY')
        end else if b1 then writeln('YYMM') else writeln('NA');
end.

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

ll dp[100001][2];
ll ma=1e9+7;
vector<vector<int> >g;
int n;
ll dfs(int x,int p,int c){
int co=0;
if(dp[x][c]!=0)
    return dp[x][c];
dp[x][c]=1;
for(auto i:g[x]){

        if(i!=p){
            co++;
            if(c==0){
                dp[x][c]=(dp[x][c]*(dfs(i,x,0)+dfs(i,x,1)))%ma;
            }
            else{
                    dp[x][c]=(dp[x][c]*dfs(i,x,0))%ma;

            }


        }

}


return dp[x][c];

}



int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
g.resize(n+1);
memset(dp,0,sizeof(dp));
for(int i=0;i<n-1;i++){
    int x,y;
    cin>>x>>y;
    g[x].pb(y);
    g[y].pb(x);
}
cout<<(dfs(1,-1,0)+dfs(1,-1,1))%ma<<endl;




}


Measured memory_bytes: 17024
(* O(n log n) *)
let n, c, k = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let ts = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let rec loop acc i r m =
  if i >= n then acc
  else if m >= c || r < ts.(i) then loop (acc + 1) (i + 1) (ts.(i) + k) 1
  else loop acc (i + 1) r (m + 1)
let _ =
  Array.sort (-) ts;
  loop 1 1 (ts.(0) + k) 1 |> Printf.printf "%d\n"

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

int main(){
    
    int N;
    cin >> N;
    
    long long a[3*N];
    for(int i = 0; i < 3*N;i++)cin >> a[i];
    
    sort(a,a+3*N,greater<long long>());
    
    long long sum = 0;
    for(int i = 0; i < 2*N;i++){
        if(i%2==1){
            //cout << a[i] <<" ";
            sum += a[i];
        }
    }
    cout << sum <<endl;
    
    
}
    
    



Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  ll A,B,C;
  cin >> A >> B >> C;
  if ( A % 2 == 0 || B%2 == 0 || C % 2 == 0 ) {
    cout << 0 << endl;
    return 0;
  }

  if ( A <= B && C <= B ) {
    cout << A*C << endl;
  } else if ( B <= A && C <= A ) {
    cout << B*C << endl;
  } else if ( A <= C && B <= C ) {
    cout << A*B << endl;
  }
  return 0;
}


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

#define _u(i,a,b) for(int i=a;i<=b;++i)
#define _d(i,a,b) for(int i=a;i>=b;--i)
#define endl "\n"
#define ii pair<int,int>
#define fi first
#define se second
#define ll long long
#define FIO() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FI(task) freopen(task".inp","r",stdin)
#define FO(task) freopen(task".out","w",stdout)

using namespace std;

const int N = 1e5+7;
const int M = 1e9+7;

int a[N], f[N];
int n;

#define task "test"

int main(){
    FIO();
    //FI(task);
    ///FO(task);

    cin >> n ;
    _u(i,1,n) cin >> a[i]; f[0] = M;
    _u(i,2,n) f[i] = min(f[i-1] + abs(a[i-1]-a[i]), f[i-2] + abs(a[i-2]-a[i]));
    cout << f[n];
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  if(abs(c-a)<=d)cout<<"Yes"<<endl;
  else{
    if(abs(a-b)<=d&&abs(b-c)<=d)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string s;cin >> s;
	int cnt = 0;
	char a = s[0];
	rep(i, s.size()) {
		if (a == s[i])++cnt;
	}
	cout << (cnt == 3 ? "No" : "Yes") << "\n";
		
	return 0;
}

Measured memory_bytes: 256
L = [ "* = ****",
      "* =* ***",
      "* =** **",
      "* =*** *",
      "* =**** ",
      " *= ****",
      " *=* ***",
      " *=** **",
      " *=*** *",
      " *=**** " ]
c=0
while True:
    try:
        num = int(input())
    except EOFError:
        break

    if c > 0:
        print()
    c += 1

    str = "{:05}".format(num)
    s = [int(x) for x in list(str)]
    for i in range(len(L[0])):
        t = []
        for j in range(len(s)):
            t.append(L[s[j]][i])
        print("".join(t))




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

int main() {
  int x, y;
  char op;
  cin >> x >> op >> y;
  
  int result;
  if(op == '+') {
    result = x + y;
  }
  else {
   	result = x - y; 
  }
  
  cout << result << endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  

int main()
{
  int a[52] = {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};
int N;
cin >> N;

  cout << fixed << a[N-1] << endl;
	return 0;
}

Measured memory_bytes: 256
module ABC141

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public :: task_A

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_A

    ! variables for this <subroutine>
    character(len=10, kind=1) :: buffer

    ! STEP.01
    ! read out the given string
    read(unit=INPUT_UNIT, fmt='(A)') buffer

    ! STEP.02
    ! output the answer of this task
    if (trim(buffer) .eq. 'Sunny') then
      write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'Cloudy'
    else if (trim(buffer) .eq. 'Cloudy') then
      write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'Rainy'
    else
      write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'Sunny'
    end if

    ! STEP.END
    return

  end subroutine task_A

end module ABC141


program main

  ! <module>s to import
  use, non_intrinsic :: ABC141

  ! require all variables to be explicitly declared
  implicit none

  call task_A

end program main

Measured memory_bytes: 256