akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;

int n, a[100000];
int types;

int main(void){
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a, a + n);
  int c = 0;
  for(int i = 0; i < n; i++){
    if(c != a[i]){
      types++;
      c = a[i];
    }
  }
  if((n - types) % 2 == 0){
    cout << types << endl;
  }
  else{
    cout << types - 1 << endl;
  }
}


Measured memory_bytes: 640
const input = require("fs").readFileSync("/dev/stdin", "utf8")

const lines = input.split('\n')
let S = lines[0].trim() - 0

const mod = 1000000007
const map = Array(S).fill().map(_ => Array(S).fill(1))

for (let i = 1; i < S; i++) {
    for (let j = 1; j < S; j++) {
        map[i][j] = (map[i - 1][j] + map[i][j - 1]) % mod
    }
}

let sum = 0
const l = Math.floor(S / 3)
for (let i = 0; i < l; i++) {
    sum += map[i][S - (i + 1) * 3]
}

console.log(sum % mod)


Measured memory_bytes: 94892
#include<stdio.h>
int main(void){
    int N,i;
    double x,ans=0;
    char u[4];
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%lf",&x);
        scanf("%s",u);
        if(u[0]=='B'){
            x*=380000.0;
        }
        ans+=x;
    }
    printf("%lf\n",ans);
    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string S; cin >> S;
	if (S.find('A') == string::npos || S.find('B') == string::npos) {
		cout << "No" << '\n';
	} else {
		cout << "Yes" << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
import sys

s = input()

f = True
ac = 'keyence'
i = 0
j = 0

while i < len(s):
    if j == len(ac):
        break
    if s[i] == ac[j] and f:
        i += 1
        j += 1
    elif f:
        k = 1
        l = 1
        while abs(l) < len(ac) - j + 1:
            if s[len(s) - k] == ac[len(ac) - l]:
                k += 1
                l += 1
            else:
                print('NO')
                sys.exit()
        break
    else:
        print('NO')
        sys.exit()

print('YES')



Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
	string s;
  	cin >> s;
  	
  	int ans;
  	if(s == "SUN") ans =7;
  else if(s == "MON") ans =6;
  else if(s == "TUE") ans =5;
  else if(s == "WED") ans =4;
  else if(s == "THU") ans =3;
  else if(s == "FRI") ans =2;
  else if(s == "SAT") ans =1;
  
  cout<< ans << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include <cstdio>
#include<cstring>
#include<string>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
using ll = long long;

//cout << fixed << setprecision(10);
int searchint(string s, int suuji, int k, int n) {

	for (int i = k;i < n;i++) {
		if (s[i] - '0' == suuji) {
			return i;
		}

	}return -1;

}

int main() {
	int n;
	string s;
	cin >> n >> s;

	int fir[10], sec[10], thi[10];
	int ans=0;

	for (int j1 = 0;j1 < 10;j1++) {

		fir[j1] = searchint(s, j1, 0, n);
		sec[j1] = fir[j1];
		thi[j1] = fir[j1];
	}
	int seca, thia;

	for (int j1 = 0;j1 < 10;j1++) {
		if (fir[j1] == -1)continue;
		else {
			for (int j2 = 0; j2 < 10;j2++) {
				if (sec[j1] == -1)continue;
				else if (sec[j2] > fir[j1]) {
					for (int j3 = 0; j3 < 10;j3++) {
						if (thi[j3] == -1)continue;
						else if (thi[j3] > sec[j2]) { ans++; }
						else {
							thia = searchint(s, j3, sec[j2] + 1, n);
							if (thia == -1)continue;
							else { ans++; }
						}
					}
				}
				else {
					seca = searchint(s, j2, fir[j1] + 1, n);
					if (seca == -1)continue;
					else {
						for (int j3 = 0; j3 < 10;j3++) {
							if (thi[j3] == -1)continue;
							else if (thi[j3] > seca) { ans++; }
							else {
								thia = searchint(s, j3, seca + 1, n);
								if (thia == -1)continue;
								else { ans++; }
							}
						}
					}
				}
			}
		}
	}

	printf("%d",ans);
	//cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
import Data.Array.Unboxed
import Data.Array.IO
import Control.Monad

type Memo = IOUArray (Int,Int) Int
type Grid = UArray (Int,Int) Char

solve :: Grid -> Memo ->  IO ()
solve grid memo = do
    let (_,(maxh,maxw)) = bounds grid
    forM_ [1..maxh] $ \i -> 
        forM_ [1..maxw] $ \j -> do
            curr <- readArray memo (i,j)
            forM_ [(i+1,j),(i,j+1)] $ \n@(ny,nx) ->
                when (ny <= maxh && nx <= maxw) $ do
                    let g = grid ! n
                    rd <- readArray memo n
                    when (g == '.') $ writeArray memo n $ (curr+rd) `rem` (10^9+7)

main = do
    [h,w] <- map read . words <$> getLine :: IO [Int]
    str <- concat <$> replicateM h getLine :: IO String
    let grid = listArray ((1,1),(h,w)) str :: Grid
    memo <- newArray ((1,1),(h,w)) 0 :: IO Memo
    writeArray memo (1,1) 1
    solve grid memo
    readArray memo (h,w) >>= print

Measured memory_bytes: 61820
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

#define mod 1000000007
const int NMAX = 21;

int can[NMAX][NMAX];
int dp[1 << NMAX];
int nrb[1 << NMAX];

void add(int & a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
}

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            scanf("%d", &can[i][j]);

    for (int i = 0; i < (1 << n) / 2; i++)
        nrb[2 * i] = nrb[i], nrb[2 * i + 1] = 1 + nrb[i];

    dp[0] = 1;
    for (int mask = 1; mask < (1 << n); mask++) {
        int man = nrb[mask] - 1;
        for (int j = 0; j < n; j++)
            if ((mask & (1 << j)) && can[man][j])
                add(dp[mask], dp[mask ^ (1 << j)]);
    }

    cout << dp[(1 << n) - 1] << '\n';

    return 0;
}


Measured memory_bytes: 16640
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		int[] a = new int[4];
		for(int i=0; i<4; i++){
			a[i] = Character.getNumericValue(n.charAt(i));
		}
		String t = "=7";
		if(a[0]+a[1]+a[2]+a[3]==7)t = a[0] + "+" + a[1] + "+" + a[2] + "+" + a[3] + t;
		else if(a[0]+a[1]+a[2]-a[3]==7)t = a[0] + "+" + a[1] + "+" + a[2] + "-" + a[3] + t;
		else if(a[0]+a[1]-a[2]+a[3]==7)t = a[0] + "+" + a[1] + "-" + a[2] + "+" + a[3] + t;
		else if(a[0]-a[1]+a[2]+a[3]==7)t = a[0] + "-" + a[1] + "+" + a[2] + "+" + a[3] + t;
		else if(a[0]+a[1]-a[2]-a[3]==7)t = a[0] + "+" + a[1] + "-" + a[2] + "-" + a[3] + t;
		else if(a[0]-a[1]+a[2]-a[3]==7)t = a[0] + "-" + a[1] + "+" + a[2] + "-" + a[3] + t;
		else if(a[0]-a[1]-a[2]+a[3]==7)t = a[0] + "-" + a[1] + "-" + a[2] + "+" + a[3] + t;
		else if(a[0]-a[1]-a[2]-a[3]==7)t = a[0] + "-" + a[1] + "-" + a[2] + "-" + a[3] + t;
		System.out.println(t);
	}
}

Measured memory_bytes: 22864
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<set>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

bool pr(int n) {
    int i=2;
    while (i*i<=n) {
        if (n%i==0) return false;
        i++;
    }
    return true;
}


int main(){
    bool b[1000000]={0};
    for (int i=0;i<1000000;i++) {
        b[i]=pr(i);
    }
    int n;
    b[0]=0,b[1]=0;
    while(scanf("%d",&n)!=EOF){
        int ans=0;
        for (int i=1;i<=n;i++){
            if (b[i]==true) ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 4188
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
int cal[MAXN];

ll mypow(ll n,ll m)
{
    ll res = 1;
    while(m){
        if(m&1)res = (res*n)%PMOD;
        n = (n*n)%PMOD;
        m>>=1;
    }
    return res;
}

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    for(int i=1;i<=n;i++)
        cin>>A[i];

    if(A[1]){
        cout<<"0\n";
        return 0;
    }

    for(int i=1;i<=n;i++){
        mx = max(mx,A[i]);
    }

    if(mx>=n){
        cout<<"0\n";
        return 0;
    }

    for(int i=1;i<=n;i++){
        cal[A[i]]++;
    }

    if(cal[0]>1){
        cout<<"0\n";
        return 0;
    }

    for(int i=0;i<=mx;i++){
        if(!cal[i]){
            cout<<"0\n";
            return 0;
        }
    }

    ll res = 1;

    for(int i=1;i<=mx;i++){
        res*=mypow(cal[i-1],cal[i]);
        res%=PMOD;
    }

    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int sides, widthsum, nextnum, total;

		for(;;){
			total = 0;
			sides = scanner.nextInt();
			int[] heightsum = new int[sides];
			if(sides == 0) break;
			for(int i = 0; i < sides; i++){
				widthsum = 0;
				for(int j = 0; j < sides; j++){
					nextnum = scanner.nextInt();
					widthsum += nextnum;
					heightsum[j] += nextnum;
					System.out.printf("%5d", nextnum);
				}
				total += widthsum;
				System.out.printf("%5d\n", widthsum);
			}
			for(int j = 0; j < sides; j++) System.out.printf("%5d", heightsum[j]);
			System.out.printf("%5d\n", total);
		}
	}

}

Measured memory_bytes: 13000
#inputの取得
n = int(input())
R = [0 for i in range(n)]
for i in range(n):
    R[i] = int(input())

#配列を逆順にする
R.reverse()

#最大値のindexを基点として、右方向と左方向に対して確認を行う。
j = R.index(max(R[0:n-1]))
i = R.index(min(R[j+1:n]))
str_max = R[j] - R[i]

#最大値index +1 が最終index以上の場合は右方向の検索を実施しない。
if j+1 >= n-1:
    pass
else:
    #右方向確認
    while 1:
        #前回の最大値より後の最大値のindexを取得（右方向）
        j = R.index(max(R[j+1:n-1])) + j + 1
    
        #最大値index +1 が最終index以上になったらbreak
        if j+1 >= n-1:
            break
        
        #直前に取得した最大値indexより後の最小値を取得
        i = R.index(min(R[j+1:n]))
        
        #最大値 - 最小値を算出
        tmp = R[j] - R[i]
        if str_max < tmp:
            str_max = tmp

#左方向確認
j = R.index(max(R[0:n-1]))
while 1:
    if j <= 0:
        break
    #前回の最大値より前の最大値のindexを取得（左方向）
    j = R.index(max(R[0:j]))
    i = R.index(min(R[j+1:n]))
    
    #最大値 - 最小値を算出
    tmp = R[j] - R[i]
    if str_max < tmp:
        str_max = tmp

print(str_max)




Measured memory_bytes: 14952
#include <cstdio>
#include <vector>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define NR 101000

int n;
vector<int> g[NR];
bool ans = true;

bool dfs(int x, int fa) {
	bool need = true;
	for (int v : g[x]) if (v != fa) {
		if (dfs(v, x)) {
			if (need) need = false;
			else ans = false;
		}
	}
	return need;
}

int main() {
	scanf("%d", &n);
	iter(i, n - 1) {
		int x, y;
		scanf("%d%d", &x, &y);
		g[x].push_back(y);
		g[y].push_back(x);
	}

	printf("%s\n", (dfs(1, 0) || !ans) ? "First" : "Second");
	return 0;
}

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

int main() {
    long long l, r, m, M, i, j;
    cin >> l >> r;

    long long ans = LLONG_MAX;

    for (i = l; i < min(r, l + 2019); i++) {
        for (j = i+1; j <= min(r, l+2019); j++) 
            ans = min(ans, (i*j)%2019);
    }   

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

Measured memory_bytes: 888
typedef long unsigned int size_t;
extern int printf (const char *__restrict __format, ...);
extern int scanf (const char *__restrict __format, ...) ;
extern int getchar (void);
extern int putchar (int __c);
int nextInt(){int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
char nextChar(){char f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
short int nextShort(){short f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
long long int nextLong(){long long int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
void println(){putchar(10);}
void print(char *f){while(*f){putchar(*f);f++;}}
void printInt(int f){char c[10];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
void printLong(long long int f){char c[19];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
typedef int (*__compar_fn_t) (const void *, const void *);
extern void *bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar)__attribute__ ((__nonnull__ (1, 2, 5))) ;
extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4)));
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int compare_char(const void *a, const void *b){return *(char*)a - *(char*)b;}
int compare_short(const void *a, const void *b){return *(short*)a - *(short*)b;}
int compare_long(const void *a, const void *b){if(*(long long int*)a - *(long long int*)b < 0){return -1;}else if(*(long long int*)a - *(long long int*)b > 0){return 1;}else{return 0;}}
extern double sqrt (double __x) __attribute__ ((__nothrow__ , __leaf__));
long long int x, t;
int main(){
 x = nextInt();
 t = (sqrt(x*8+1)-1)/2;
 if(t*(t+1)/2 >= x){
  printInt(t);
 }else{
  printInt(t+1);
 }
 println();
}


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

int main() {
    int N;
    long K;
    cin >> N >> K;
    vector <int> A(N);
    for(int i = 0;i < N; i++)
    {
        cin >> A[i];
    }
    
    int mono_count = 0;
    int reverse_count = 0;
    for(int i = 0;i < N; i++)
    {
        for(int j = i + 1;j < N;j++)
        {
            if(A[i] > A[j]) 
            {
                mono_count++;
            }
            if(A[i] < A[j])
            {
                reverse_count++;
            }
        }
    }
    long mod = pow(10, 9) + 7;
    long long wa = (long long)K * (K + 1);
    wa /= 2;
    wa %= mod;
    long long wa2 = (long long )K * (K - 1);
    wa2 /= 2;
    wa2 %= mod;
    long long ans = (wa * mono_count) % mod + (wa2 * reverse_count) % mod;

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

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <typeinfo>

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
//#define YES(ans) ans?cout<<"YES":cout<<"NO"

/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define all(x) (x).begin(),(x).end()
*/

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int nums[30], numt[30];
    REP(i,30){
        nums[i] = 0;
        numt[i] = 0;
    }
    REP(i, s.size())
    {
        nums[s[i] - 'a']++;
    }
    REP(i,t.size()){
        numt[t[i] - 'a']++;
    }
    sort(nums, nums + 26);
    sort(numt, numt + 26);
    bool ans = true;
    REP(i,26){
        if(nums[i]!=numt[i])
            ans = false;
    }
    if(ans)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 916
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, T; cin >> N >> T;
	vector<int>v(T + 10, 0);
	rep(i, 0, N) {
		int l, r; cin >> l >> r;
		v[l]++; v[r]--;
	}
	rep(i, 1, T + 1)v[i] += v[i - 1];
	cout << *max_element(v.begin(), v.begin() + T + 1) << endl;
	return 0;
}

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

int main()  {
    int n;
    cin >> n;
    vector<int> a(2 * n);
    for (int &it : a) cin >> it;
    sort(a.begin(), a.end());
    int sum = 0;
    for (int i = 1; i < 2 * n; i += 2) {
        sum += min(a[i - 1], a[i]);
    }
    cout << sum;
    return 0;
}


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

using namespace std;

int main(){
    int N;
    while(cin >> N){
        int res = 0;
        int a = 0, b = 0, ab = 0;
        for(int i=0;i<N;i++){
            string s; cin >> s;
            if(s[0] == 'B'){
                if(s.back() == 'A') ab++;
                else b++;
            } else if(s.back() == 'A') a++;
            for(int j=0;j+1<s.size();j++){
                if(s[j]=='A' && s[j+1]=='B') ++res;
            }
        }
        if(a > 0 || ab > 0){
            if(a > 0) --a;
            else --ab;
            res += ab;
            if(b > 0){
                res += 1;
                --b;
            }
            res += min(a, b);
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
ans = 10**5
for i in range(1,N):
    a = str(i)
    b = str(N - i)
    s = 0
    for j in range(len(a)):
        s += int(a[j])
    for j in range(len(b)):
        s += int(b[j])
    ans = min(s,ans)
print(ans)

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

using namespace std;

int main()
{
	int k, s, ans = 0;
	cin >> k >> s;
	
	for (int x=0; x<=k; ++x) {
		for (int y=0; y<=k; ++y) {
			int z = s - x - y;
			if (z <= k && z >=0) {
				ans++;
			}
		}
	}
	cout << ans;
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int x;
    int k = 1;
    
    cin >> x;
    
    while (true){
        if((360 * k) % x == 0){
            cout << 360 * k / x << endl;
            return 0;
        }
        k += 1;
    }

    return 0;
}

Measured memory_bytes: 3632
# https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_c
# WA

from collections import deque

n = int(input())
A = [int(input()) for _ in range(n)]
A.sort(reverse=True)

# edit ans
# n=9のとき
# (1) a1 > a2 < a3 > a4 < a5 > a6 < a7 > a8 < a9
# (2) a1 < a2 > a3 < a4 > a6 < a6 > a7 < a8 > a9

# (1)のとき
# (a1 - a2) + (a3 - a2) + (a3 - a4) + ...
# -> a1 1, a2 -2, a3 2, a4 -2, ..., a8 -2, a9 1
# => 2, 2, 2, 1, 1, -2, -2, -2, -2 が係数
# 
# (2)のとき
# -> a1 -1, a2 2, a3 -2, ... a8 2, a9 -1
# => 2, 2, 2, 2, -1, -1, -2, -2, -2 が係数
#
# (N)偶数のとき (N=10)
# => 2, 2, 2, 2, 1, -1, -2, -2, -2, -2

if n % 2 == 0:
    res = 0
    for i in range(n // 2 - 1):
        res += A[i] * 2
    res += A[n // 2 - 1]
    res -= A[n // 2]
    for i in range(n // 2 + 1, n):
        res -= A[i] * 2
    print(res)

else:
    # pattern 1
    res1 = 0
    for i in range(n // 2 - 1):
        res1 += A[i] * 2
    res1 += A[n // 2 - 1] + A[n // 2]
    for i in range(n // 2 + 1, n):
        res1 -= A[i] * 2

    # pattern 2
    res2 = 0
    for i in range(n // 2):
        res2 += A[i] * 2
    res2 -= (A[n // 2] + A[n // 2 + 1])
    for i in range(n // 2 + 2, n):
        res2 -= A[i] * 2
    print(max(res1, res2))

Measured memory_bytes: 51748
using System;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var p = new C();
            p.run();
        }
    }

    public class B
    {
        int N, M;
        int[] T, P, X;
        public B()
        {
            N = int.Parse(Console.ReadLine());
            T = new int[N+1];
            string[] s = Console.ReadLine().Split(' ');            
            for (int i=1; i<=N; i++) 
            {
                T[i] = int.Parse(s[i-1]);
            }
            M = int.Parse(Console.ReadLine());
            P = new int[M+1];
            X = new int[M+1];
            for (int i=1; i<=M; i++)
            {
                s = Console.ReadLine().Split(' ');
                P[i] = int.Parse(s[0]);
                X[i] = int.Parse(s[1]);
            }
        }

        public void run()
        {
            int sumT = 0;
            for (int i=1; i<=N; i++) 
            {
                sumT += T[i];
            }

            for (int i=1; i<=M; i++) 
            {
                int ans = sumT - T[P[i]] + X[i];
                System.Console.WriteLine(ans);
            }
        }
    }

    public class C
    {
        int n;
        int[] a;
        public C() 
        {
            n = int.Parse(System.Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            a = new int[n];
            for (int i=0; i<n; i++)
            {
                a[i] = int.Parse(s[i]);
            }
        }

        public void run() 
        {
            Array.Sort(a);    

            // valid check        
            // odd
            if (n%2 == 1) {
                if (a[0] != 0)
                {
                    System.Console.WriteLine("0");
                    return;
                }
                for (int i=1; i<n; i+=2)
                {
                    if (a[i] != i+1
                        || a[i+1] != i+1)
                        {
                            System.Console.WriteLine("0");
                            return;
                        }
                }
            } else { //even
                for (int i=0; i<n; i+=2)
                {
                    if (a[i] != i+1
                        || a[i+1] != i+1)
                        {
                            System.Console.WriteLine("0");
                            return;
                        }
                }
            }

            int m = n/2;
            ulong ans = 1;
            while (m>=32)
            {
                ans *= 4294967296;
                ans %= 1000*1000*1000+7;
                m -= 32;
            }
            ans *= (ulong)Math.Pow(2,m);
            ans %= 1000*1000*1000+7;
            System.Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 9816
N, M = map(int, input().split())
oks = [True]*(N+1)

for i in range(M):
    a = int(input())
    oks[a] = False

dp = [0]*(N+1)
dp[0] = 1

for now in range(N):
    for next in range(now+1, min(N, now+2)+1):
        if oks[next]:
            dp[next] += dp[now]
            dp[next] %= 10**9 + 7

print(dp[N])

Measured memory_bytes: 7700
#include<bits/stdc++.h>
#define ll long long int
#define st string
#define con continue
#define br break
#define rt return 0
#define fr first
#define sec second
using namespace std;
int main(){
//ll tc; cin>>tc; while(tc--){
ll n,m,mn=INT_MAX,i,x,j,a=0,t,k,b=-1,mx=-1,cnt=0,c=0; 
 st s,str; char strn;
cin>>n; //a=n; n-=1; 
ll ara[n+1],bra[n+1],taj[n+1];
memset(ara,0,sizeof(ara));
//for(i=1;i<=n;i++) cin>>ara[i]; 
  for(i=1;i<=9;i++)
   {  
     for(j=1;j<=9;j++)
      {
        if(i*j==n)
           {
            cout<<"Yes";
               rt;
             }
        }
      
      
   }      
  
        
     cout<<"No"<<endl;
    
 
    rt;
}

Measured memory_bytes: 3628
#include "iostream"
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int a,b,c;
  std::cin >> a >> b >> c;
  if(a<=c && c<=b) printf("Yes");
  else printf("No");
  return 0;
}


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

ans=0
st = [[] for _ in range(N+1)]
goal = [0 for _ in range(N+1)]

for _ in range(M):
    a,b = list(map(int,input().split()))
    st[a] += [b]
    goal[b] += 1

stack = []
for i in range(1,N+1):
    if goal[i]>0:
        ans+=1
        for x in stack:
            goal[x] -= 1
        stack=[]
    if len(st[i])>0:
        stack += st[i]

print(ans)

Measured memory_bytes: 25260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#define pb push_back
static ll dp[(ll)1e6+10][3];
const ll mod=1e9+7;
int main(void){
    ll n;
    cin>>n;
    dp[0][0]=1;
    dp[0][1]=0;
    dp[0][2]=0;
    rep(0,i,n){
        dp[i+1][0]=dp[i][0]*8%mod;
        dp[i+1][1]=(2*dp[i][0]+dp[i][1]*9)%mod;
        dp[i+1][2]=(dp[i][1]+dp[i][2]*10)%mod;
    }
    cout<<dp[n][2];
}

Measured memory_bytes: 26876
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    uint64_t A,_B; cin>>A;
    string B; cin>>B;

    _B=100*(B.at(0)-'0')+10*(B.at(2)-'0')+(B.at(3)-'0');

    uint64_t ans=A*_B/100;
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define MOD 1000000007

void Fast_IO(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	freopen("output.out","w",stdout);
	freopen("debug.out","w",stderr);
	#endif
}

ll freq[100006]={0};

int main(){
	Fast_IO();
	ll n,i,sum=0;
	cin>>n;
	ll a[n];
	for(i=0;i<n;i++){
		cin>>a[i];
		freq[a[i]]++;
		sum=sum+a[i];
	}
	ll q,b,c,x,y;
	cin>>q;
	for(i=0;i<q;i++){
		cin>>b>>c;
		x=c-b;
		y=freq[b];
		sum=sum+(x*y);
		cout<<sum<<'\n';
		freq[b]=0;
		freq[c]+=y;
	}
	return 0;
}

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

double pow(int a){
  double res = 1;
  for (int i = 0; i < a; i++) {
    res /= 2;
  }
  return res;
}

int main(int argc, char *argv[]){
  double d;
  while (std::cin >> d) {
    if(d < 0)break;
    int digit = 7;
    string ans;
    for (int i = digit; i >= 0; i--) {
      if(d >= (1<<i)){
        ans = ans + '1';
        d -= (1<<i);
      }else{
        ans = ans + '0';
      }
    }
    ans = ans + ".";
    for (int i = 1; i <= 4; i++) {
      if(d >= pow(i)){
        ans = ans + '1';
        d -= pow(i);
      }else{
        ans = ans + '0';
      }      
    }
    if(d == 0)std::cout << ans << std::endl;
    else std::cout << "NA" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    double a, b, x, ans;
    cin >> a >> b >> x;
    if(a*b*a/2 < x){
        if(x==a*a*b){
            ans = 0;
        }else if(a>b){
            double up = abs((2*x)/(a*a) - b);
            ans =  M_PI/2 - atan2(a, b-up);
        }else{
            double up = (2*x)/(a*a) - b;
            ans = M_PI/2 - atan2(a, b-up);
        }
    }else{
        if(a>b){
            double s = (2*x)/(a*b);
            ans = M_PI/2-atan2(s, b);
        }else{
            double s = (2*x)/(a*b);
            ans = atan2(b, s);
        }
    }
    ans *= 180.0/M_PI;
    cout << setprecision(20)<< ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import itertools
def input(): return sys.stdin.readline().strip()

mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

N, M = mi()
S = [None] * N
B = [li() for _ in range(M)]
P = li()

count = 2**N
for s in itertools.product((0,1), repeat=N):
  for i in range(M):
    if sum([s[si-1] for si in B[i][1:]]) % 2 != P[i]:
      count -= 1
      break

print(count)

Measured memory_bytes: 3064
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ll = long long;

constexpr int mod = 1000 * 1000 * 1000 + 7;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k % 2 == 0) cout << (a - b) << endl;
  else cout << (b + c - (a + c)) << endl;
  return 0;
}


Measured memory_bytes: 764
/*
17D8101031C 杉山　祥吾 ID:keisei334 C
*/

#include <stdio.h>

int main(void){
  int A,B,C,c=0,sum=0;

  scanf("%d %d %d",&A,&B,&C);
  while(C>sum){
    sum+=A;
    c++;
    if(c%7==0){
      sum+=B;
    }
  }

  printf("%d\n",c);
  
  return 0;
}

/*実行結果
3 0 10
4

1 2 10
8
*/


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
char t[5]="AGCT",s[101];
int main(void) {
    scanf("%s",s);
    int cnt=0,mx=0;
    for (int i=0;s[i];i++) {
        int flag=0;
        for (int j=0;j<4;j++) if (t[j]==s[i]) {
            cnt++;flag=1;
        }
        if (flag==0) {
            mx=max(mx,cnt);
            cnt=0;
        }
    }
    mx=max(mx,cnt);
    printf("%d\n",mx);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

int main()
{
    struct Point
    {
        int height{};
        char lean{};
    };
    std::string geo_signs;
    std::cin >> geo_signs;
    geo_signs.insert(0, 1, '_');
    std::vector<Point> geo_points(geo_signs.length());
    geo_points[0].lean = '_';
    for (auto i = 1; i < geo_signs.length(); ++i)
    {
        int adjuster{};
        char cc{geo_signs[i]}, pc{geo_signs[i - 1]};
        switch (cc)
        {
        case '_':
            adjuster = (pc == '\\') ? -1 : 0;
            break;
        case '\\':
            adjuster = (pc == '\\') ? -1 : 0;
            break;
        case '/':
            adjuster = (pc == '\\') ? 0 : 1;
            break;
        default:
            adjuster = 0;
            break;
        }
        geo_points[i].height = geo_points[i - 1].height + adjuster;
        geo_points[i].lean = cc;
    }

    std::vector<std::vector<Point>> lakes;
    for (auto first_it = geo_points.begin(); first_it != geo_points.end();)
    {
        auto second_it = (first_it->lean != '\\') ? geo_points.end() : std::find_if(first_it + 1, geo_points.end(), [first_it](Point &p) { return p.height == first_it->height; });
        if (second_it == geo_points.end())
        {
            ++first_it;
            continue;
        }
        lakes.emplace_back(first_it, second_it + 1);
        first_it = second_it + 1;
    }

    std::vector<int> lake_areas;
    for (auto it = lakes.begin(); it != lakes.end(); ++it)
    {
        auto mmpair{std::minmax_element(it->begin(), it->end(), [](Point &p1, Point &p2) { return p1.height < p2.height; })};
        int lake_height{mmpair.second->height - mmpair.first->height + 1};
        int lake_width{static_cast<int>(it->size())};
        double area{static_cast<double>(lake_height * lake_width)};
        for (auto i = it->begin(); i != it->end(); ++i)
        {
            area -= (i->height - mmpair.first->height + (i->lean == '_' ? 1 : 0.5));
        }
        lake_areas.push_back(static_cast<int>(area));
    }
    std::cout << std::accumulate(lake_areas.begin(), lake_areas.end(), 0) << std::endl;
    std::cout << lake_areas.size();
    for (auto area : lake_areas)
    {
        std::cout << " " << area;
    }
    std::cout << std::endl;
    return 0;
}



Measured memory_bytes: 3468
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

#define EPS (1e-7)
#define IINF ((int)1e9)

ll mod = 1000000007;  // 10^9 + 7

MY_NAMESPACE(testbed)

struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main()
{
	ll modval = 1000000007;  // 10^9 + 7

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

	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	vector<ll> pos, neg;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] < 0)
			neg.push_back(a[i]);
		else
			pos.push_back(a[i]);
	}

	bool neg_answer = false;
	if (pos.size() == 0)
		neg_answer = (k % 2 == 1);
	else if (n == k)
		neg_answer = (neg.size() % 2 == 1);

	mint res = 1;
	if (neg_answer) {
		sort(a.begin(), a.end(), [](ll x, ll y) -> bool {
			return abs(x) < abs(y);
			});
		for (int i = 0; i < k; i++)
		{
			res *= a[i];
		}
	}
	else
	{
		sort(pos.begin(), pos.end());    // the biggest at last
		sort(neg.rbegin(), neg.rend());  // the biggest abs(negative) at last

		if (k % 2 == 1)
		{
			res = pos.back(); pos.pop_back();
		}

		vector<ll> p;
		while (pos.size() > 1)
		{
			ll tmp = pos.back(); pos.pop_back();
			tmp *= pos.back(); pos.pop_back();
			p.push_back(tmp);
		}
		while (neg.size() > 1)
		{
			ll tmp = neg.back(); neg.pop_back();
			tmp *= neg.back(); neg.pop_back();
			p.push_back(tmp);
		}
		sort(p.rbegin(), p.rend());

		for (int i = 0; i < k / 2; i++)
		{
			res *= p[i];
		}
	}

	cout << res << "\n";
	return 0;
}
MY_NAMESPACE_

Measured memory_bytes: 8152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    ll n;
    cin>>n;
    vector<ll>v(n);
    rep(i,n){
    cin>>v[i];
    }
    sort(v.begin(),v.end());
    ll ans;
    ans=v[n-1]-v[0];
    cout<<ans<<endl;
}

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

namespace AtCoder.AtCoder_Begginer_Contest_159
{
    class C
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            int n = int.Parse(input1);

            double d = (double)n / 3;
            Console.WriteLine(d*d*d);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11220
import sys
from math import gcd

n = int(input())
a = list(map(int, input().split()))

b = gcd(a[0], a[1])
for i in range(2, n):
    b = gcd(b, a[i])
if b != 1:
    print('not coprime')
else:
    c = set()
    num = max(a)
    m = 1000000
    vals = [0]*(m+1)

    for i in range(2, m):
        if vals[i] != 0:
            continue
        j = 1
        while True:
            t = i*j
            if t > m:
                break
            if vals[t] == 0:
                vals[t] = i
            j += 1
    d = dict()
    for i in a:
        p = i
        while p != 1:
            if p in d:
                print("setwise coprime")
                sys.exit()
            d[p] = 1
            p = int(p/vals[p])
    print("pairwise coprime")


Measured memory_bytes: 127572
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;

int inf = (1 << 30);
int mod = 1e9;

int main(){

    int N;
    cin >> N;

    int ans = 1;
    for(int i = 1; pow(2, i) <= N; i++){
        ans = pow(2, i);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<list>
#include<string>
#include<unordered_set>


using namespace std;

int ctoi(char c) {

	switch (c)
	{
	case'0':
		return 0;
	case'1':
		return 1;
	case'2':
		return 2;
	case'3':
		return 3;
	case'4':
		return 4;
	case'5':
		return 5;
	case'6':
		return 6;
	case'7':
		return 7;
	case'8':
		return 8;
	case'9':
		return 9;
	default:
		break;
	};
}
using ull = unsigned long long;
using ll = long long;

struct grid {
	int h, w;
	int state;
	int warp_c;
};

int H, W;
int CH, CW;
int DH, DW;
vector<grid> g;

int index(int h, int w) {
	return h * W + w;
}

void paint(int sh, int sw, int v, unordered_set<int>& buf, unordered_set<int>& buf2) {
	if (buf.count(index(sh, sw)) > 0) buf.erase(index(sh, sw));
	if (g[index(sh, sw)].state == -1)g[index(sh, sw)].state = v;
	else return;

	for (int i = -2; i <= 2; ++i)for (int j = -2; j <= 2; ++j) {
		if (sh + i < 0 || sh + i >= H || sw + j < 0 || sw + j >= W) continue;
		if (g[index(sh + i, sw + j)].state == -1) buf2.insert(index(sh + i, sw + j));
	}

	if (sh - 1 >= 0 && g[index(sh - 1, sw)].state == -1) paint(sh - 1, sw, v, buf,buf2);
	if (sh + 1 < H && g[index(sh + 1, sw)].state == -1) paint(sh + 1, sw, v, buf, buf2);
	if (sw - 1 >= 0 && g[index(sh, sw - 1)].state == -1) paint(sh, sw - 1, v, buf, buf2);
	if (sw + 1 < W && g[index(sh, sw + 1)].state == -1) paint(sh, sw + 1, v, buf, buf2);
}

int main() {
	cin >> H >> W >> CH >> CW >> DH >> DW;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			char s;
			cin >> s;
			if (s == '#') g.emplace_back(grid{ i,j, -2, -2 });
			else g.emplace_back(grid{ i,j,-1,-1 });
		}
	}
	CH--;
	CW--;
	DH--;
	DW--;
	unordered_set<int> buf;
	int c = 0;
	int nexth = CH;
	int nextw = CW;
	do {
		unordered_set<int> buf2;
		
		do {
			paint(nexth, nextw, c, buf, buf2);
			if (buf.empty()) break;
			int a = *(buf.begin());
			nexth = a / W;
			nextw = a % W;
		}while (true);

		if (g[index(DH, DW)].state != -1) {
			cout << g[index(DH, DW)].state << endl;
			return 0;
		}

		if (buf2.empty()) break;

		buf = buf2;
		int aa = *(buf.begin());
		nexth = aa / W;
		nextw = aa % W;

		c++;
	} while (true);

	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 20040
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
#define FORi(N) for(ll i = 0; i < N; ++i)
#define FORj(N) for(ll j = 0; j < N; ++j)
#define FORk(N) for(ll k = 0; k < N; ++k)
//using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1 ,rr =1;
    for(ll i=0;i<k;++i) {
      r*=(n-i);
      rr*=(i+1);
      //r %= 1000000007;
      //rr %= 1000000007;
    }
    r/=rr;
    //r %= 1000000007;
    return r;
}
ll kyori(vector<ll>& y,vector<ll>& z,ll D){
  ll a=0;
  FORi(D){
    a+=pow((long long)(y[i]-z[i]),2);
  }
  ll b =  ((ll)pow((ll)sqrt(a),2)==a);
  if(b) return 1;
  return 0;
}
int main() {
  ll N;
  cin>>N;
  vector<ll> A(N),X(N);
  FORi(N){
    cin>>A[i];
  }
  ll a =0;
  ll b = A[0];
  ll aa = A[0];
  do{
    X[0]= (a+b)/2*2;
    //X[0] = aa*2;
    for(ll i=1;i<N;++i){
      X[i]=A[i-1]*2-X[i-1];
    }
    ll nn = A[N-1]-(X[N-1]/2+X[0]/2);
    //cout<<"_"<<nn<<endl;
    if(nn==0)break;
    //if(b-a<=1)break;
    if(nn<0){
      b=(b+a)/2-1;
    }else{
      a=(b+a)/2+1;
    }
	aa--;
  }while(aa>=0);
  FORi(N-1){
    cout<<X[i]<<" ";
  }
  cout<<X[N-1];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 2944
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Collections;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] hh = br.readLine().split(" ");
        int[] h = new int[n+1];
        
        for (int i = 1; i <= n; i++) {
            h[i] = Integer.parseInt(hh[i-1]);
        }
        
        int[] dp = new int[n+1];
        dp[0] = 0;
        dp[1] = 0;
        dp[2] = Math.abs(h[2]-h[1]);
        for (int i = 3; i <= n; i++) {
            dp[i] += Math.min(dp[i-1] + Math.abs(h[i]-h[i-1]), dp[i-2] + Math.abs(h[i]-h[i-2]));
        }
        System.out.println(dp[n]);
    }
    
    public static int counter(int n) {
        if (n == 0) return 0;
        return counter(n-1) + n;
    }

}



class Box {
    int w;
    int h;
    public Box(int w, int h) {
        this.w = w;
        this.h = h;
    }
}

class BoxComparator1 implements Comparator<Box>{
	public int compare(Box b1, Box b2) {
		return b1.w - b2.w;
	}
}

class BoxComparator2 implements Comparator<Box> {
    public int compare(Box b1, Box b2) {
        return b1.h - b2.h;
    }
}


Measured memory_bytes: 34516
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define ALL(a) a.begin(), a.end()
#define REP(i,a) for(ll i(0), _##i(a); i < _##i; ++i)
#define FOR(i,a,b) for(ll i(a), _##i(b); i <= _##i; ++i)
using namespace std;
using ll = long long;

void solve(){
    int n;
    cin >> n;
    int x, y;
    cin >> x >> y;
    vector<int> ans(n+1);

    auto dist = [&](int u, int v){
        return min({v - u, abs(u - x) + 1 + abs(v - y), abs(u - y) + 1 + abs(v - x)});
    };

    FOR(i,1,n){
        FOR(j,i+1,n){
            ++ans[dist(i, j)];
        }
    }
    FOR(i,1,n-1){
        cout << ans[i] << "\n";
    }
}

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

    int T = 1;
    //cin >> T;
    FOR(i,1,T){
        solve();
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int read()
{
	char ch=getchar();int f=0,x=1;
	while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();}
	return f*x;
}
int a[1000005],n;
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
	}
	int ans=0;
	for(int i=2;i<=n-1;i++)
	{
		if((a[i]>a[i-1]&&a[i]<a[i+1])||(a[i]<a[i-1]&&a[i]>a[i+1]))
		ans++;
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ちゃんとユニークな配列にする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int M;
  cin >> M;
  cout << (24 - M) + 24 << endl;
}


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

int main(void) {
    long long n,m,i,a,ans = 0;
    char s[100001],t[100001];
    scanf("%lld %lld",&n,&m);
    scanf("%s",s);
    scanf("%s",t);
    for (i = 1;i <= n && i <= m;i++) {
        if (n % i == 0 && m % i == 0) a = i;
    }
    for (i = 0;i < a;i++) {
        if (s[n / a * i] != t[m / a * i]) {
            printf("-1\n");
            exit(0);
        }
    }
    ans = n * m / a;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,k,a[N];
bool check(int x){
	int w=0;
	for(int i=0;i<n;i++)
		w+=(a[i]-1)/x;
	return w<=k;
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	int l=1,r=1e9;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid))r=mid-1;
		else l=mid+1;
	}
	printf("%d",l);
	return 0;
}

Measured memory_bytes: 4520
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;


int n, x, mem;

int main() {
	cin >> n >> x;
	if (x == 1 || x == 2 * n - 1)
		cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		mem = 2;
		lp(n - 2) {
			if (mem == x)mem++;
			cout << mem << endl;
			mem++;
		}
		cout << 1 << endl << x << endl << 2 * n - 1 << endl;
		lp(n - 2) {
			if (mem == x)mem++;
			cout << mem << endl;
			mem++;
		}
	}
	return 0;
}

Measured memory_bytes: 1536