akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var sortedA = A.OrderBy(x => x).ToArray();

        var minusIndex = sortedA.LowerBound(0);

        if (minusIndex % 2 == 0)
        {
            for (int i = 0; i < minusIndex; i++)
                sortedA[i] *= -1;
        }
        else
        {
            if(minusIndex < N && Math.Abs(sortedA[minusIndex - 1]) > sortedA[minusIndex])
            {
                for (int i = 0; i < minusIndex + 1; i++)
                    sortedA[i] *= -1;
            }
            else
            {
                for (int i = 0; i < minusIndex - 1; i++)
                    sortedA[i] *= -1;
            }
        }

        var ans = sortedA.Sum(x => (long)x);

        WriteLine(ans);
    }
}
static class BinarySearchExtensions
{
    public static int LowerBound<T>(this List<T> list, T item, bool isDescending = false) where T : IComparable<T> =>
        ~list.BinarySearch(item, new LowerAndUpperBoundCompare<T>(true, isDescending));
    public static int UpperBound<T>(this List<T> list, T item, bool isDescending = false) where T : IComparable<T> =>
        ~list.BinarySearch(item, new LowerAndUpperBoundCompare<T>(false, isDescending));

    public static int LowerBound<T>(this T[] array, T item, bool isDescending = false) where T : IComparable<T> =>
        ~Array.BinarySearch(array, item, new LowerAndUpperBoundCompare<T>(true, isDescending));
    public static int UpperBound<T>(this T[] array, T item, bool isDescending = false) where T : IComparable<T> =>
        ~Array.BinarySearch(array, item, new LowerAndUpperBoundCompare<T>(false, isDescending));

    private class LowerAndUpperBoundCompare<T> : IComparer<T> where T : IComparable<T>
    {
        public LowerAndUpperBoundCompare(bool isLowerBound, bool isDescending) =>
            (this.isLowerBound, this.isDescending) = (isLowerBound, isDescending);

        private readonly bool isLowerBound, isDescending;

        public int Compare(T x, T y) => Predicate(x, y) ? 1 : -1;

        private bool Predicate(T x, T y)
        {
            var compareResult = x.CompareTo(y);
            return (isDescending ? (compareResult < 0) : (compareResult > 0)) || (isLowerBound && (compareResult == 0));
        }
    }
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define upper(n,m) (n+m-1)/m
#define rounding(n) (int)((double)n+0.5)

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define ALL(a) a.begin(),a.end()

#define coutALL(i,a) {int i=0;for(int e:a) cout<<(i++?" ":"")<<e; cout<<endl;}
#define coutYN(a) cout<<(a?"Yes":"No")<<endl;
#define coutyn(a) cout<<(a?"yes":"no")<<endl;

#define deb cout<<"debug"<<endl
#define debn(n) cout<<"debug: "<<n<<endl

const int INF=INT_MAX;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
//const int dx[]={0,1,0,-1},dy[]={-1,0,1,0};
const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using namespace std;

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

int ans;

void merge(vector <int> &A,int left,int mid,int right){

  int n1=mid-left;
  int n2=right-mid;
  int L[n1], R[n2];

  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i = 0;i<n2;i++) R[i] = A[mid + i];

  L[n1] = INF;
  R[n2] = INF;

  for(int i=0,j=0,k=left;k<right;k++){

    ans++;

    if(L[i]<=R[j]){

      A[k] = L[i];
      i = i + 1;

    }

    else {

      A[k] = R[j];
      j = j + 1;

    }

  }

}

void mergeSort(vector <int> &A,int left,int right){

  if(left+1 < right){

    int mid = (left + right)/2;

    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);

  }

}

signed main(){

  int n;
  cin>>n;

  vector <int> a(n);
  REP(i,n) cin>>a[i];

  mergeSort(a,0,n);

  coutALL(i,a);

  cout<<ans<<endl;

  return 0;

}



Measured memory_bytes: 6796
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

    int N, M;
    cin >> N >> M;

    auto ab = make_vec<pair<ll, ll>>(N);
    REP(i, N) {
        ll a, b;
        cin >> a >> b;
        ab[i] = make_pair(a, b);
    }
    sort(ALL(ab));

    ll ans = 0;
    int count = 0;
    REP(i, N) {
        if (ab[i].second + count < M) {
            ans += ab[i].first * ab[i].second;
            count += ab[i].second;
        } else {
            int num = M - count;
            ans += ab[i].first * num;
            count += num;
            break;
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char a[15];
    int n,flag1=0,flag2=0,flag3=0;
    gets(a);
    n=strlen(a);
    if(a[0]=='A')
        flag1=1;
    for(int i=1;i<n;i++)
    {
        if(a[i]>='a'&&a[i]<='z')
            flag3++;
        if(a[i]=='C'&&i!=1&&i!=n-1)
            flag2++;
    }
    if(flag1==1&&flag2==1&&flag3==n-2)
        printf("AC");
    else
        printf("WA");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;

int main() {

	int N, X, T;
	cin >> N >> X >> T;

	int ans = (N + (X - 1)) / X;
	ans *= T;

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n,i;
    cin >> n;
    int a[n];
    for(i=0; i<n; i++){
        cin >> a[i];
    }
    for(i=1; i<=n; i++){
        int flag=0;
        if(a[i-1]==i){
            continue;
        }
        else{
            for(int j=0; j<n; j++){
                if(i==a[j]){
                    swap(a[j],a[i-1]);
                    flag=1;
                    break;
                }
            }
        }
        if(flag==1){
            break;
        }
    }
    int count=0,flag=0;
    for(i=1; i<=n;i++){
        if(a[i-1]!=i){
            flag=1;
            break;
        }
    }
    if(flag==0){
        cout<<"YES"<<'\n';
    }
    else{
        cout << "NO"<<'\n';
    }
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main(){
  string S;
  cin >> S;
  //入力終了
  
  int N = S.size();
  int constant_left_greater[N+1] = {0};
  int constant_right_less[N+1] = {0};
  int tmp = 0;

  //左に< が連続する回数を数える
  rep(i, N){
    if(S[i] == '<')
      tmp++;
    else
      tmp = 0;
    constant_left_greater[i+1] = tmp;
  }

  //右に> が連続する回数を数える
  tmp = 0;
  for(int i=N-1; i>=0; i--){
    if(S[i] == '>')
      tmp++;
    else
      tmp = 0;
    constant_right_less[i] = tmp;
  }


  //連続する< または> の数のうち大きい方を足していく
  long long ans = 0;
  rep(i, N+1){
    long long a = constant_left_greater[i];
    long long b = constant_right_less[i];
    ans += max(a, b);
  }

  //解答
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 7628
import java.util.*;

public class Main {

	List<Integer> next;
	List<Long> c;

	static long depth[];

	static Main edge[];

	public Main(List<Integer> next, List<Long> c, int count) {
		this.next = next;
		this.c = c;
	}

	public static void dfs(int v, int p, long d) {
		depth[v] = d;
		int n = edge[v].next.size();
		for (int i = 0; i < n; ++i) {
			int next = edge[v].next.get(i);
			if (next == 0)
				break;
			if (next == p)
				continue;
			long cost = edge[v].c.get(i);
			dfs(next, v, d + cost);
		}
	}

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

		int n, a, b, q, k, x, y;
		long c;
		n = sc.nextInt();
		edge = new Main[n + 1];
		depth = new long[n + 1];
		for (int i = 0; i <= n; ++i) {
			edge[i] = new Main(new ArrayList<Integer>(), new ArrayList<Long>(), 0);
		}
		for (int i = 0; i < n - 1; ++i) {
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextLong();
			edge[a].next.add(b);
			edge[a].c.add(c);
			edge[b].next.add(a);
			edge[b].c.add(c);
		}

		q = sc.nextInt();
		k = sc.nextInt();
		dfs(k, -1, 0);
		for (int i = 0; i < q; ++i) {
			x = sc.nextInt();
			y = sc.nextInt();
			long ans = depth[x] + depth[y];
			System.out.println(ans);
		}
		sc.close();
	}

}


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

void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B)
{
    vector<vector<ll>> baito(M);
    for (ll i = 0; i < N; i++) {
        // ○日後に報酬を得られるから、○日目までにやれば報酬を得られるに変更
        if (M - A[i] >= 0) {
            baito[M - A[i]].push_back(B[i]);
        }
    }

    priority_queue<ll> que;
    ll ans = 0;
    for (ll i = M - 1; i >= 0; i--) {
        for (auto reward : baito[i]) {
            que.push(reward);
        }

        if (!que.empty()) {
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
#pragma GCC diagnostic ignored "-Wunused-result"
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 7168
#include <stdio.h>

int		main(void)
{
	long a,b,k;
	scanf("%ld", &a);
	scanf("%ld", &b);
	scanf("%ld", &k);
	if ((a - k) >= 0)
		a -= k;
	else
	{
		k -= a;
		a = 0;
		if (b - k>= 0)
			b -= k;
		else
			b = 0;
	}
	printf("%ld %ld",a, b);
	return (0);
}


Measured memory_bytes: 128
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re


def main_chk():
    N = int(input())

    ans = 0
    for i in range(1,N+1):
        m = N // i
        ans += ( m + 1 ) * m * i / 2

    print(math.floor(ans))
main_chk()


Measured memory_bytes: 9884
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;}

int main(ll x)
{
    int n;cin >> n;string s;cin >> s;
    int ans=0;
    REP(i,n){
        FOR(j,i+ans+1,n){
            int size=min(j-i,n-j);
            REP(k,size){
                if(s[i+k]==s[j+k]){
                    continue;
                }
                else{
                    size=k;
                    break;
                }
            }
            chmax(ans,size);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

vector<ll>relation[20], money(20, 1);

int main() {
	int a;
	cin >> a;
	int ans = 24 + (24 - a);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

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

  int a,b;cin>>a>>b;
  P(a*b - (a+b) + 1);
  return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int m1,m2,d1,d2;
	cin>>m1>>d1>>m2>>d2;
	cout<<(m1==m2?0:1)<<endl;
	return 0;
}

Measured memory_bytes: 256
void main()
{
    long n, m;
    rdVals(n, m);
    long[] a = new long[m], b = new long[m];
    foreach (i; 0 .. m)
    {
        rdVals(a[i], b[i]);
        --a[i], --b[i];
    }

    auto uf = UnionFind(n);
    long[] result = new long[m];
    result[$-1] = (n * (n - 1)) >> 1;
    foreach_reverse (i; 1 .. m)
    {
        result[i-1] = result[i];
        if (!uf.same(a[i], b[i]))
        {
            result[i-1] -= uf.size(a[i]) * uf.size(b[i]);
            uf.unite(a[i], b[i]);
        }
    }

    foreach (x; result)
    {
        x.writeln;
    }
}

struct UnionFind
{
    long[] par, cnt;

    this(long n)
    {
        par.length = n, cnt.length = n;
        foreach (i; 0 .. n)
        {
            par[i] = i;
        }
        cnt[] = 1L;
    }

    long root(long x)
    {
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    bool same(long x, long y)
    {
        return root(x) == root(y);
    }

    void unite(long x, long y)
    {
        x = root(x), y = root(y);
        if (x == y) return;
        if (cnt[x] > cnt[y]) swap(x, y);
        cnt[y] += cnt[x];
        par[x] = y;
    }

    long size(long x)
    {
        return cnt[root(x)];
    }
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 6268
#include<iostream>
#include<string>

using namespace std;
typedef long long ll;

int main() {
	string s;
	cin >> s;
	if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]))cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 210;

int N, K;
ll P;

ll dp[MAXN][MAXN];
ll choose[MAXN][MAXN];

ll res[MAXN];

ll rr[MAXN][MAXN];

ll gogo (int A, int B)
{
    if (B < A / 2) return 0;
    if (A == 1) return 1;
    if (B > A - 2) B = A - 2;

    int blo = (A - 1 - B);
    ll ans = 0;
    for (int k = blo; k <= B; k++)
    {
        for (int i = 0; i <= A + 1; i++)
            for (int j = 0; j <= A + 1; j++)
                rr[i][j] = 0;

        rr[0][k] = 1;
        for (int l = 1; l <= k; l++)
        {
            ll cc = rr[l-1][blo];
            for (int m = blo; m <= min (B, A - l - 1); m++)
            {
                cc += rr[l-1][m+1];
                cc %= P;
                rr[l][m] = cc;
            }
        }
        for (int l = blo; l <= B; l++)
        {
            ans += rr[k][l];
            ans %= P;
        }
    }
    //cout << A << " " << B << " " << ans << "\n";
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> K >> P;

    choose[0][0] = 1;
    for (int i = 1; i < MAXN; i++)
        for (int j = 0; j <= i; j++)
        {
            choose[i][j] = choose[i-1][j];
            if (j)
                choose[i][j] = (choose[i][j] + choose[i-1][j-1]) % P;
        }

    ll ans = 0;
    for (int i = 1; i <= N; i++)
    {
        // bottom cycle size
        ll v = gogo (i, K - (N - i));
        for (int j = 1; j <= N; j++)
            if (j != i)
                v = (v * j) % P;
        ans += v;
    }
    cout << ans % P << "\n";
}

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

int main(){
    string s;
    cin >> s;
    reverse(s.begin(),s.end());

    bool flag = true;
    int count = 0;
    while(count < s.size()){
        if(     s.substr(count, 5) == "maerd") count += 5;
        else if(s.substr(count, 5) == "esare") count += 5;
        else if(s.substr(count, 6) == "resare") count += 6;
        else if(s.substr(count, 7) == "remaerd") count += 7;
        else{
            flag = false;
            break;
        }
    }
    if(flag == true) cout << "YES" << endl;
    if(flag == false) cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

int main() {
int N, Q;
string S;
cin >> N >> Q >> S;
VP lr(Q); rep(i, 0, Q) scanf("%d %d", &lr[i].first, &lr[i].second);

// 累積和
VI acc(N+1, 0);
for (int i = 1; i < N+1; ++i){
    if (S.substr(i-1, 2) == "AC") acc[i+1] = acc[i] + 1;
    else acc[i+1] = acc[i];
}

rep(i, 0, Q){
    cout << acc[lr[i].second] - acc[lr[i].first] << "\n";
}

return 0;
}

// 境界，出力文字列 チェック
// int は ± 2*10⁹.
// map[]は対数時間．unordered_map[]は一定時間．


Measured memory_bytes: 2176
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int Q,c,a,n,cou;
    cin>>Q;
    for(int i=0;i<Q;i++){
    cou=0;
    cin>>c>>a>>n;
    while(c&&a&&n)cou++,c--,a--,n--;
    while(c>1&&a)cou++,c-=2,a--;
    while(c>2)cou++,c-=3;

    cout<<cou<<endl;
}
}

Measured memory_bytes: 1160
// Contest No.: ABC177
// Problem No.: A
// Solver:      Jinmin Goh
// Date:        20200829

#include <cstring>
#include <iostream>
#include <cstdlib>
#include <list>
#include <array>
#include <atomic>
#include <algorithm>
#include <deque>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
    int d, t, s;
    scanf("%d %d %d", &d, &t, &s);
    if((double)d / s <= t) {
        printf("Yes");
    }
    else {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 3820
//23
#include<iostream>

using namespace std;

int main(){
  int m;
  cin>>m;
  while(m--){
    int g[5][5];
    for(int y=0;y<5;y++){
      for(int x=0;x<5;x++){
	cin>>g[y][x];
      }
    }
    int ans=0;
    for(int l=0;l<5;l++){
      for(int r=l;r<5;r++){
	for(int t=0;t<5;t++){
	  for(int b=t;b<5;b++){
	    int f=1;
	    int c=0;
	    for(int y=l;y<=r;y++){
	      for(int x=t;x<=b;x++){
		f&=g[y][x];
		c++;
	      }
	    }
	    if(f&&ans<c){
	      ans=c;
	    }
	  }
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}
	      

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int dp[15][100001] = { 0 };

int main()
{
	int N, x6 = 6, x9 = 9, size = 0;
	vector<int> num;

	cin >> N;

	num.push_back(1);
	while (x6 <= N) {
		num.push_back(x6);
		x6 *= 6;
	}
	while (x9 <= N) {
		num.push_back(x9);
		x9 *= 9;
	}

	sort(num.begin(), num.end());
	size = num.size();

	rep(i, size) {
		repc(j, 1, N) {
			int d = 0;
			int cnt = 0;

			if (i == 0) {
				dp[i][j] = j;
				continue;
			}

			dp[i][j] = dp[i - 1][j];
			while (j - d >= 0 && cnt <= 9) {
				dp[i][j] = min(dp[i][j], d / num[i] + dp[i - 1][j - d]);
				d += num[i];
				cnt++;
			}
		}
	}

	cout << dp[size - 1][N] << endl;

	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main(void){
    short int a;
    short int b;
    short int c;
    cin >>a>>b>>c;
    if(a < b && b< c){
        cout <<"Yes"<<endl;
    }
    else {
        cout <<"No"<< endl;
    }
    
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int n,k;
  cin >> n >> k;
  int a[100];
  for(int i=0;i<n;i++) cin >> a[i];
  
  sort(a,a+n,greater<int>());
  int ans;
  for(int i=0;i<k;i++) ans += a[i];
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll X, K, D;
  cin >> X >> K >> D;
  X = abs(X);
  ll stop = min(K, X/D);
  K -= stop;
  X -= D*stop;
  ll ans = K%2 == 0 ? X : D-X;
  cout << ans << endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

int main() {
  int n, odd_cnt = 0;
  cin >> n;
  vi a(n);
  rep(i, n) {
    int a;
    cin >> a;
    if(a % 2)
      odd_cnt++;
  }
  cout << (odd_cnt % 2 ? "NO" : "YES") << endl;
}

Measured memory_bytes: 640
n, m = map(int, input().split())

x = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    x[a-1].append(b-1)

if x[0] == []:
    print("IMPOSSIBLE")
    exit()

for i in x[0]:
    for j in x[i]:
        if j == n-1:
            print("POSSIBLE")
            exit()

print("IMPOSSIBLE")

Measured memory_bytes: 29092
// inputに入力データ全体が入る
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var result = 0;
for (var a = 1; a <= input; a++) {
  for (var b = 1; b <= input; b++) {
    for (var c = 1; c <= input; c++) {
      // console.log(a + " " + b + " " + c);
      result += gcd(gcd(a, b), c);      
    }
  }
}
console.log(result);


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

Measured memory_bytes: 31880
def list_difference(list1, list2):
    result = list1.copy()
    for value in list2:
        if value in result:
            result.remove(value)

    return result

n = int(input())
list_S = [list(input()) for _ in range(n)]


ans = []
while True:
    a = set(list_S[0])
    for i in range(1, n):
        a = set("".join(list_S[i])) & a
        if len(a) == 0:
            break

    for i in range(n):
        list_S[i] = list_difference(list_S[i], list(a))


    if len(a) == 0:
        break

    a = list(a)
    for s in a:
        ans.append(s)

ans.sort()
print("".join(ans))

Measured memory_bytes: 3064
K=1024
N=331
R=range(K)
B=[1,2,4,8,16,32,64,128,256,512]
C=[0]*K
D=[[0 for i in range(N)]for j in R]

def init():
    global C,D
    for i in R:
        s=format(i,'b')
        n=s.count('1')
        C[i]=n
        if n==1:
            D[i][B.index(i)]=1
        else:
            for j in range(len(s)):
                if s[-j-1]=='1':
                    dp=n*j
                    i2=i-B[j]
                    for k in range(N-dp):
                        D[i][k+dp]+=D[i2][k]
    return

init()
while 1:
    try:
        n,s=map(int,raw_input().split())
        x=0
        if s<N:
            x=sum([D[i][s] for i in R if C[i]==n])
        print x
    except:
        break

Measured memory_bytes: 9336
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const double PI=acos(-1.0);

int main()
{
    int n;
    scanf("%d",&n);
    int sum=0;
    int x=n/500;
    n-=x*500;
    sum+=x*1000;
    x=n/5;
    sum+=x*5;
    printf("%d\n",sum);
    return 0;
}


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

int main() {
    int s;
    cin >> s;
    int f = s/100; int b = s%100;
    if(f>=1 && f <=12) {
        if(b>=1 && b <=12){
            cout << "AMBIGUOUS" << endl;
            return 0;
        }
        cout << "MMYY" << endl; return 0;
    }
    else{
        if(b>=1 && b <=12) {cout << "YYMM" << endl; return 0;}
        else {cout << "NA" << endl; return 0;}
    }
    
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;++i)
    {
        int now=0;
        for(int j=1;j<=i;++j)
        if(i%j==0)now++;
        if(now==8&&i%2==1)ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
const int M = 1e6 + 500;
int read(){
	int f=1,re=0;char ch;
	for(ch=getchar();!isdigit(ch)&&ch!='-';ch=getchar());
	if(ch=='-'){f=-1,ch=getchar();}
	for(;isdigit(ch);ch=getchar()) re=(re<<3)+(re<<1)+ch-'0';
	return re*f; 
}
int val[M];
int tot;
int ans[M];
int fir[M], nxt[M], to[M];
int siz[M];
int jie[M];
int c[M], d[M],dep[M];
void addedge(int x, int y) {
    nxt[++tot] = fir[x];
    fir[x] = tot;
    to[tot] = y;
    swap(x, y);
    nxt[++tot] = fir[x];
    fir[x] = tot;
    to[tot] = y;
}
int quick(int a, int b) {
    int ha = 1;
    while (b) {
        if (b & 1)
            ha = ha * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return ha;
}
int ni(int a) { return quick(a, mod - 2); }
int cata(int n, int m) {
    if (n < m)
        return 0;
    return c[n] * d[m] % mod * d[n - m] % mod;
}
void Dfs1(int x, int fa) {
    val[x] = 1;
    siz[x] = 1;
    for (int e = fir[x]; e; e = nxt[e]) {
        int y = to[e];
        if (y == fa)
            continue;
        Dfs1(y, x);
        siz[x] += siz[y];
        val[x] = val[x] * val[y] % mod;
    }
    val[x] = val[x] * c[siz[x] - 1] % mod;
    for (int e = fir[x]; e; e = nxt[e]) {
        int y = to[e];
        if (y == fa)
            continue;
        val[x] = val[x] * d[siz[y]] % mod;
    }
}
int n;
void Dfs2(int x, int fa, int value) {
    if (x == 1) {
        ans[x] = val[x];
        value = value * d[siz[x] - 1] % mod * val[x] % mod;
        for (int e = fir[x]; e; e = nxt[e]) {
            int y = to[e];
            Dfs2(y, x, value * c[siz[y]] % mod * (c[siz[x] - 1 - siz[y]]) % mod * ni(val[y]) % mod);
        }
    } else {
        ans[x] = val[x] * d[siz[x] - 1] % mod * d[n - siz[x]] % mod * c[n - 1] % mod * value % mod;
        value = value * val[x] % mod * d[siz[x] - 1] % mod * d[n - siz[x]] % mod;
        for (int e = fir[x]; e; e = nxt[e]) {
            int y = to[e];
            if (y == fa)
                continue;
            Dfs2(y, x, value * c[siz[y]] % mod * c[n - siz[y] - 1] % mod * ni(val[y]) % mod);
        }
    }
}
char s[10];
bool check(){
	if(s[1]==s[2]) return false;
	if(s[3]!=s[4]) return false;
	if(s[5]!=s[6]) return false;
	//if(s[3]==s[5]) return false;
	if(s[1]==s[3]) return false;
	if(s[1]==s[5]) return false;
	if(s[2]==s[3]) return false;
	if(s[2]==s[5]) return false;
	return true;
}
signed main() {
    n = read();
    c[0] = 1;
    for (int i = 1; i <= n; i++) c[i] = c[i - 1] * i % mod;
    d[1] = 1;
    d[0] = 1;
    for (int i = 2; i <= n; i++) d[i] = d[mod % i] * (mod - mod / i) % mod;
    for (int i = 1; i <= n; i++) d[i] = d[i - 1] * d[i] % mod;
    for (int i = 1; i < n; i++) {
        int x = read(), y = read();
        addedge(x, y);
    }
    Dfs1(1, 0);
    Dfs2(1, 0, 1);
    for (int i = 1; i <= n; i++) printf("%lld\n", ans[i]);
    return 0;
}

Measured memory_bytes: 36992
#include <iostream>

using namespace std;

int main() {
	int n;
	while (cin >> n&& n!=0) {
		int f[21][21] = {};

		for (int i = 0; i<n; i++) {
			int x, y;
			cin >> x >> y;
			f[y][x] = 1;
		}

		int x = 10, y = 10;
		int cnt = 0;

		int m;
		cin >> m;
		for (int i = 0; i<m; i++) {
			char dir;
			int step;
			cin >> dir >> step;
			while (step--) {
				if (dir == 'N') { y++; }
				else if (dir == 'S') { y--; }
				else if (dir == 'E') { x++; }
				else { x--; }

				if (f[y][x]) {
					f[y][x] = 0;
					cnt++;
				}
			}
		}

		if (cnt == n) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
using ll = long long;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
ll u18 = 1000000000000000000;
int main()
{
    
	string s, t;
  cin >> s >> t ;
	
	int ans = 0;
	for ( int i = 0; i < s.size(); i++ ){
		if ( s[i] != t[i] ){
			ans ++;
		}
	}

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


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

using namespace std;

int main(){
    int N,x,ans=0;
    vector<int> a(9,0);
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> x;
        for(int j=0;j<9;j++){
            if(j==8){
                if(j*400<=x){
                a[j]++;
                }
            }else{
                if(j*400<=x && x<400*(j+1)){
                a[j]++;
                }
            }
        }
    }

    for(int i=0;i<8;i++){
        if(0<a[i]){
            ans++;
        }
    }

    cout << max(ans,1) << ' ' <<  ans + a[8] << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

namespace SCC{
    void visit(const vector<vector<int>>&G,vector<int>&vs,vector<int>&used,int v){
        used[v]=true;
        for(auto u:G[v]){
            if(!used[u])visit(G,vs,used,u);
        }
        vs.push_back(v);
    }

    void visit2(const vector<vector<int>>&T,vector<int>&used,vector<int>&comp,vector<int>&vec,int k,int v){
        comp[v]=k;
        used[v]=true;
        vec.push_back(v);

        for(auto u:T[v]){
            if(!used[u])visit2(T,used,comp,vec,k,u);
        }
    }
    void decompose(const vector<vector<int>>&G,vector<vector<int>>&H,vector<int>&comp){
        vector<vector<int>>T(G.size());
        for(int i=0;i<G.size();i++){
            for(auto v:G[i]){
                T[v].push_back(i);
            }
        }
        comp.resize(G.size());

        vector<int>vs(G.size());
        vector<int>used(G.size());
        for(int i=0;i<G.size();i++){
            if(!used[i])visit(G,vs,used,i);
        }
        reverse(vs.begin(),vs.end());
        fill(used.begin(),used.end(),0);

        int K=0;
        vector<vector<int>>S;
        for(auto v:vs){
            if(!used[v]){
                S.push_back(vector<int>());
                visit2(T,used,comp,S.back(),K++,v);
            }
        }

        H.resize(K);
        fill(used.begin(),used.end(),0);
        for(int i=0;i<K;i++){
            for(auto v:S[i]){
                for(auto u:G[v]){
                    if(used[comp[u]]||comp[v]==comp[u])continue;
                    used[comp[u]]=true;
                    H[comp[v]].push_back(comp[u]);
                }
            }
            for(auto v:H[i])used[v]=false;
        }

    }
}

signed main(){
	int N,M;
	cin>>N>>M;
	vector<vint>G(N);
	rep(i,M){
		int a,b;cin>>a>>b;a--;b--;
		G[a].pb(b);
	}

	vector<vint>H;
	vint comp;
	SCC::decompose(G,H,comp);

	rep(i,N){
		bool f=false;
		rep(j,N){
			if(comp[i]!=comp[j])continue;
			if(f)cout<<" ";
			f=true;
			cout<<j+1;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 5584
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

const int limit = 200005;
using edge = struct {int to; long long cost;};

int n;
vector<edge> tree[limit];
vector<long long> dist;

void dfs(int v, long long d = 0, int p = -1){
    dist[v] = d;
    for(auto &e : tree[v]) {
        if(e.to == p) continue;
        dfs(e.to, d + e.cost, v);
    }
}

vector<long long> calcDist(int s){
    dist = vector<long long>(n);
    dfs(s);
    return dist;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int a, b, c;
        cin >> a >> b;
        a--, b--;
        c = 1;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }
    vector<ll> dist1 = calcDist(0);
    int src = 0;
    ll mxDist = 0;
    rep(i,n){
        if(dist1[i] > mxDist){
            mxDist = dist1[i];
            src = i;
        }
    }
    vector<ll> dist2 = calcDist(src);
    rep(i,n){
        chmax(mxDist, dist2[i]);
    }
    if(mxDist%3 != 1) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}

Measured memory_bytes: 31320
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
using namespace std;
typedef long long LL;

int main() {
	int t, i, j, k;
	int a, b, c ,d,F=0;
	char A[100];
	
	cin >> a >> b;

	
		c = -a + 2*b;

		
		cout << c << endl;
	return 0;
}

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

long gcd(long a, long b){
    long count=0;
    for(long i=22; i<=b; i++){
        long d1=i%10;
        long d10=i/10;
        if(d1*d10==a){
            if(d1>=2 && d10>=2){
                count++;
            }
        }
    }
    return count;
}


int main()
{
    int M,D;
    std::cin >> M >> D;
    long count=0;
    for(long i=4; i<=M; i++){
        count+=gcd(i,D);
    }
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=32e4;

int d[N],p[20][20],v[20][20];
ll c[N],ans;

ll cal(int d,ll c){
	ll a=0;
	if(d==0){
		ans+=c-1;
		return 0;
	}
	while(c){
		if(c%10){
			if(a)ans++;
			a=a+v[d][c%10];
			if(a>9){
				a=a%10+a/10;
				ans++;
			}
			ans+=p[d][c%10];
		}
		c/=10;
		ans+=c*p[d][10];
	}
	return a;
}
ll cal(ll d){
	while(d>9){
		d=d%10+d/10;
		ans++;
	}
	return d;
}
int main(){
	ios::sync_with_stdio(0);
	for(int j=1;j<=10;j++)p[0][j]=j-1;
	for(int i=1;i<10;i++){
		int x=i;
		for(int j=1;j<=10;j++){
			p[i][j]=p[i][j-1];
			while(x>9){
				x=x%10+x/10;
				p[i][j]++;
			}
			v[i][j]=x;
			x=x*10+i;
		}
	}
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>d[i]>>c[i];
		d[i]=cal(cal(d[i],c[i]));
	}
	for(int i=1;i<m;i++){
		d[i]+=d[i-1]*10;
		d[i]=cal(d[i]);
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

#pragma GCC optimize("O3")
static const auto __ = [] {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  return nullptr;
}();

int solve(const std::string& S) {
  int R {0};
  int B {0};
  for (char s : S) {
    R += s == '0';
    B += s == '1';
  }
  return 2 * min(R, B);
}

int main(int argc, char* argv[]) {
  string S;
  cin >> S;
  cout << solve(S) << '\n';
  return 0;
}

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

int main(void){
    int n, k;
    cin>>n>>k;
    int r, s, p;
    cin>>r>>s>>p;
    map<char, int> score;
    score['r']=p;
    score['s']=r;
    score['p']=s;
    string t;
    cin>>t;
    int ans=0;
    rep(i, n){
        ans+=score[t[i]];
    }
    rep(start, k){
        int i=start;
        while(i<n-k){
            if(t[i]==t[i+k]) {
                ans-=score[t[i]];
                t[i+k]='u';
            }
            i+=k;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  rep(i, (int)s.size()) {
    if (s[i] != t[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3928
def Traveling_and_Bus(a , b , c , d):

    return min(a , b) + min(c , d)

def main():
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    print(Traveling_and_Bus(a , b , c , d))

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
} 
int N,M;
int A[MAXN],s;
deque<int> dp;
vector<int> v;
void Solve() {
    read(N);
    for(int i = 1 ; i < N ; ++i) {
	read(A[i]);
	if(i >= 3) s += A[i];
    }
    for(int i = 0 ; i <= s ; ++i) dp.push_back(i);
    for(int i = 3 ; i < N ; ++i) {
	v.clear();
	for(int j = 1 ; j <= A[i] ; ++j) v.pb(dp[j]);
	for(auto t : v) dp.push_front(t);
	for(int j = 1 ; j <= A[i] ; ++j) dp.pop_back();
    }
    int x;
    read(M);
    for(int i = 1 ; i <= M ; ++i) {
	read(x);
	if(x >= s) {out(x - s + A[1] - A[2]);enter;}
	else {out(dp[x] + A[1] - A[2]);enter;}
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 14460
/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\n'
#define ff first
#define ss second
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\n';

using namespace std;

void solve(){
	int i,j;
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> v[i];
	}

	vector<int>dp(n,INT_MAX);
	dp[0]=0;
	for (int i = 1; i < n; ++i)
	{
		if(i-2>-1){
			dp[i]=abs(v[i]-v[i-2])+dp[i-2];
		}
		dp[i]=min(dp[i],dp[i-1]+abs(v[i]-v[i-1]));
	}

	printf("%d\n",dp[n-1]);
}


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


Measured memory_bytes: 3992
s = input()
a = 0
b = 0
if int(s[0]+s[1]) > 12 or int(s[0]+s[1]) == 0:
  a = 1
if int(s[2]+s[3]) > 12 or int(s[2]+s[3]) == 0:
  b = 1
if a == 0 and b == 0:
  print('AMBIGUOUS')
elif a == 1 and b == 0:
  print('YYMM')
elif a == 0 and b == 1:
  print('MMYY')
else:
  print('NA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#ifdef LOCAL
#define lout cout
#else
stringstream devnull;
#define lout devnull
#endif
#define AMULET \
  cin.tie(0);  \
  ios::sync_with_stdio(false);
#define rep1(n) rep(_, n)
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep3(i, f, n) for (int i = f; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> pi;
template <class C>
inline void vcin(C &c);
template <class C, class D>
inline void vcin(C &c, D &d);
template <class C>
inline void vcout(const C &c, const string separate = "\n");

int main()
{
  AMULET

  int n;
  cin >> n;
  vector<int> a(n);
  vcin(a);

  vector<ll> s(n + 1, 0);
  rep(i, n) s[i + 1] = s[i] + a[i];

  map<ll, ll> m;
  for (auto e : s)
  {
    m[e]++;
  }

  ll ans = 0;

  for (auto e : m)
  {
    auto n = e.second;
    ans += (n * (n - 1) / 2);
  }

  cout << ans << endl;

  return 0;
}

template <class C>
inline void vcin(C &c)
{
  for (auto &a : c)
  {
    cin >> a;
  }
}
template <class C, class D>
inline void vcin(C &c, D &d)
{
  for (auto it1 = c.begin(), it2 = d.begin(); it1 != c.end() && it2 != d.end(); it1++, it2++)
  {
    cin >> *it1 >> *it2;
  }
}
template <class C>
inline void vcout(const C &c, const string separate)
{
  for (auto it = c.begin(); it != c.end(); it++)
  {
    if (it != c.begin())
      cout << separate;
    cout << *it;
  }
}


Measured memory_bytes: 15104
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int X, Y;
    while (cin >> X >> Y, (X || Y)) {
        if (X < Y) swap(X, Y);
        int cnt = 0;
        while (Y != 0) {
            X = X % Y;
            swap(X, Y);
            cnt ++;
        }
        cout << X << " " << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include  <stdio.h>


int main(void)
{
   int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    
    if(a>=10 || b>=10 || c>=10|| a<=0||b<=0||b<=0)
       return 0;
    
    if((a == b && a != c)||(a == c && a != b)||(b == c && b != a))
    {
        printf("Yes");
    }
    
   
    
    else printf("No");
    
    
    
   
        
    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

// 整数スキャン（複数）
/*
int x;
scanf("%d",&x);
int y;
scanf("%d",&y);
int z;
scanf("%d",&y);

// n個の整数のスキャン
/*
ll a[n] = {};
rep(i,n){
    scanf("%lld",&a[i]);
}
*/

// 文字列スキャン
/*
string s;
cin >> s;
*/


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

    ll ans = 0;

    if(n%2==0){
        ans=n;
    }else{
        ans=n*2;
    }




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


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



int main() {
    
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    int last = n%10;
    
    if(last == 2 or last == 4 or last == 5 or last == 7 or last == 9){
        cout<<"hon";
    }
    else if(last == 1 or last == 0 or last == 6 or last == 8){
        cout<<"pon";
    }
    else if(last == 3){
        cout<<"bon";
    }
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    vector<int> p;
    int temp;
    for (int i = 0; i < a; i++) {
        cin >> temp;
        p.push_back(temp);
    }

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

    int ans = 0;
    for (int i = 0; i < b; i++) {
        ans += p[i];
    }
    cout << ans;


    return 0;
}

Measured memory_bytes: 3628