akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;
#define F first
#define S second
const int INF=100000000;


int main(){
	double a,b,c,d,e,f;
	while(cin>>a>>b>>c>>d>>e>>f){
		double x,y;
		x=(c*e-b*f)/(e*a-b*d);
		y=(c*d-a*f)/(b*d-a*e);
		if(x == -0) x=0;
		if(y == -0) y=0;

		printf("%.3f %.3f\n",x,y);
		//cout << setprecision(3)  << x << " " << y << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int a[n+1],
	d[n+1];
	for(int i=1;i<=n;i++)
	cin>>a[i];
	
	
	for(int i=1;i<=n;i++)d[i]=1e9+1;
	
	d[1]=0;
	for(int i=2;i<=n;i++){
		int j=i-1;
		while(i-j<=k&&j>0){
			d[i]=min(d[i],d[j]+abs(a[i]-a[j]));
			j--;
		}
	}
//	for(int i=1;i<=n;i++)cout<<d[i]<<' ';
	cout<<d[n];
}

Measured memory_bytes: 1024
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define scan(n,v) v.resize(n); rep(i,n){ cin>>v[i];}
#define MOD 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define be begin
#define pb push_back
#define fi first
#define se second
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template <class T> T 
gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T 
lcm(T a, T b){return a * b / gcd(a, b);}

//------------------------------------------------------
ll n,m;
vector<ll> a;
void input(){
    cin>>n>>m;
    scan(n,a);
}
void src(){
    map<ll,ll> mp;
    rep(i,n){
        ll aa=a[i];
        ll cnt=0;
        while(aa%2==0){
            cnt++;
            aa/=2;
        }
        mp[cnt]++;
    }
    if(mp.size()!=1 ){
        cout<<0; return;
    }
    rep(i,n) a[i]/=2;
    ll lcmnum=1;
    rep(i,n){
        lcmnum=lcm(lcmnum,a[i]);
        if(lcmnum>m){ cout<<0; return;}
    }
    cout<<(m/lcmnum+1)/2;
}   
int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int>p(n);
	for (int i = 0; i < n; i++)cin >> p.at(i);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (p.at(i) != i + 1)ans++;
	}
	if (ans == 0 || ans == 2)cout << "YES" << endl;
	else cout << "NO" << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int Array[100005] , D[100005];

int main(){
    int N , M , i;
    scanf( "%d%d" , &N , &M );

    for( i = 1 ; i <= M ; ++i )
        scanf( "%d" , Array + i );

    if( N >= M ){
        puts( "0" );
        return 0;
    }

    sort( Array + 1 , Array + M + 1 );
    long long Ans = 0;

    for( i = 2 ; i <= M ; ++i ){
        D[i - 1] = Array[i] - Array[i - 1];
        Ans = Ans + D[i - 1]; 
    }

    sort( D + 1 , D + M , greater<int>() );

    for( i = 1 ; i < N ; ++i )
        Ans = Ans - D[i];

    printf( "%lld\n" , Ans );
    return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
#include <queue>
#include <unordered_map> 
#include <iomanip>
#include <random>
#include <future>
#include <thread>
#include <utility>
#include <set>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define INF_L (LLONG_MAX/3)
#define PSB push_back
#define PN 1000000007
typedef long long LL;
#define int long long


// booooooooooooost
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int), 多倍長小数(mp::cpp_dec_float_100)


signed main() {

	int q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;

	int one = min( 4 * q, min(2 * h, s) );
	int two = min(d, 2 * one);

	cout << (n / 2) * two + (n % 2) * one << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
     
    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
          	int count = 0;
            for (int i = 0; i < c; i++) {
              b = b - a;
              if (b < a && b < 0) {
                break;
              } else {
                count++;
              }
            }
            System.out.println(count);
        }
    }

Measured memory_bytes: 21844
n,k = gets.chomp.split.map(&:to_i)
s_arr = gets.chomp.split('').map(&:to_i)

# 色が変わるときのindexをとる。最後はmaxのindexにプラス1したものを取得する。
change_arr = []
change_arr << 0

# 比較する色
comp_s = s_arr[0]
count_s = 0

# 1010…という配列にしたいので、最初が0始まりの時は、change_arrに1の数=0を入れる
if comp_s == 0
	change_arr << 0
end

s_arr.each_with_index do |s, i|
	if comp_s != s
		change_arr << i
		comp_s = s
		count_s = 1
		next
	end
	count_s += 1
end
change_arr << s_arr.size

# 最大の数
max_count = 0

change_arr.each_with_index do |cnt, i|
	next if i%2==1

	left_i = i
	right_i = left_i + (k+1)*2 - 1
	last_index = right_i >= change_arr.size ? change_arr.size-1 : right_i
	now_count = change_arr[last_index] - change_arr[left_i]
	max_count = now_count if now_count > max_count
end

puts max_count


Measured memory_bytes: 8572
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
  int i;
  int N;
  scanf("%d", &N);
  int A[2][110];
  A[0][0] = 0;
  A[1][0] = 0;
  for (i = 1; i < N+1; i++) {
    scanf("%d", &A[0][i]);
  }
  for (i = 1; i < N+1; i++) {
    scanf("%d", &A[1][i]);
  }
  int ruiseki_0[110] = {};
  int ruiseki_1[110] = {};
  for (i = 1; i < N+1; i++) {
    ruiseki_0[i] = ruiseki_0[i-1] + A[0][i];
    ruiseki_1[i] = ruiseki_1[i-1] + A[1][i];
  }
  int ans = 0;
  for (int go_down = 0; go_down < N; go_down++) {
    int ans_now = ruiseki_0[go_down+1] + ruiseki_1[N] - ruiseki_1[go_down];
    ans = max(ans, ans_now);
  }
  printf("%d", ans); 
  return 0;
}

Measured memory_bytes: 128
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if a * 500 + b * 100 + c * 50 == X:
                count += 1

print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m,now=-1;
vvi g;
vi vis,b,par,nx;
vp a;

bool dfs(int u,int w){
	vis[u]++;
	if(u==w){
		b[u]=1;
		return 1;
	}
	for(auto v:g[u]) if(!vis[v]){
		nx[u]=v;
		if(dfs(v,w)){
			b[u]=1;
			return 1;
		}
	}
	return 0;
}

int main(){
	cin>>n>>m;
	g=vvi(n);
	par=b=nx=vi(n);
	a=vp(m);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		g[u-1].push_back(v-1);
		a[i]={u-1,v-1};
	}
	for(int i=0;i<m;i++){
		int u=a[i].first,v=a[i].second;
		vis=vi(n);
		if(dfs(v,u)){
			nx[u]=v;
			now=u;
			break;
		}
	}
	if(now==-1){
		cout<<-1<<endl;
		return 0;
	}
	while(1){
		bool B=0;
		for(int i=0;i<m;i++){
			int u=a[i].first,v=a[i].second;
			if(b[u]&&b[v]&&nx[u]!=v){
				now=v;
				int t=nx[u];
				while(t!=v){
					b[t]=0;
					t=nx[t];
				}
				nx[u]=v;
				B=1;
				break;
			}
		}
		if(!B) break;
	}
	vi res;
	for(int i=0;i<n;i++) if(b[i]) res.push_back(i);
	int N=res.size();
	cout<<N<<endl;
	for(int i=0;i<N;i++) cout<<res[i]+1<<endl;
}

Measured memory_bytes: 384
#include<cstdio>
using namespace std;
int main()
{
    int n,p;
    scanf("%d",&n);
    int maxn = 0,sum = 0;
    for(int i = 0;i < n; i++)
    {
        scanf("%d",&p);
        sum += p;
        if(p > maxn)
            maxn = p;
    }
    if(maxn % 2 == 0)
        maxn = maxn / 2;
    else
        maxn = maxn / 2 + 1;
    sum -= maxn;
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	a = []
	b = []
	for i in range(n):
		ai, bi = map(int, sys.stdin.readline().split())
		a.append(ai)
		b.append(bi)
	a_sort = sorted(a)
	if n % 2 == 0:
		min_center = (a_sort[int(n/2)-1] + a_sort[int(n/2)])/2
	else:
		min_center = a_sort[int((n+1)/2)-1]
	b_sort = sorted(b)
	if n % 2 == 0:
		max_center = (b_sort[int(n/2)-1] + b_sort[int(n/2)])/2
	else:
		max_center = b_sort[int((n+1)/2)-1]
	log.print(max_center, min_center)
	if n % 2 == 0:
		print(int((max_center - min_center)*2 + 1))
	else:
		print(int(max_center - min_center + 1))


	
	


main()

Measured memory_bytes: 97144
use std::io;


fn main() {
    let n = read_one::<String>();
    let mut buf = Vec::new();
    for c in n.chars() {
        match c {
            '1' => buf.push('9'),
            '9' => buf.push('1'),
            _ => buf.push(c),
        }
    }
    for c in buf.iter() {
        print!("{}", c);
    }
    println!();
}


#[allow(unused)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}


#[allow(unused)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#!/usr/bin/env python3

N, W = list(map(int, input().split()))
item_list = []

for _ in range(N):
    w, v = list(map(int, input().split()))
    item_list.append((w, v))

max_v = (10 ** 3) * 100
dp_table = [[0] + [float("inf")] * (max_v + 1) for _ in range(N + 1)]
total_v = 0

for i in range(1, N + 1):  # 最大で10**2
    w, v = item_list[i - 1]
    # 品物iまで考慮したときの価値の最大値
    total_v += v
    for j in range(total_v + 1):  # 最大で10 ** 5
        # 品物iを入れない場合
        dp_table[i][j] = dp_table[i - 1][j]
        before_min_weight = dp_table[i - 1][j]
        # dp_table[i][j] = before_min_weight
        # 品物iを入れる場合
        if j - v < 0:
            continue
        weight = dp_table[i - 1][j - v] + w
        min_weight = min(before_min_weight, weight)
        dp_table[i][j] = min_weight
        if i == N:
            if min_weight <= W:
                max_value = j

ans = max_value
print(ans)


Measured memory_bytes: 353192
import sys
i = 0
x = []
for line in sys.stdin:
    if i==0:
        x.append(int(line))
    else:
        s1 = 'SHCD'.index(line[0])
        s2 = int(line[2:])
        x.append((s1,s2))
    i = 1

r4 = range(4)
r13 = range(13)
lx = x.pop(0)
cards = [[0 for i in r13] for j in r4]
for j,i in x: cards[j][i-1] = 1

for j in r4:
    for i in r13:
        if cards[j][i]==0: print 'SHCD'[j],str(i+1)

Measured memory_bytes: 4248
n = int(input())
h = list(map(int, input().split()))
dp = [int(10000000000)]*100000
dp[0] = 0
cost = 0
for i in range(1, n):
  if dp[i] > dp[i-1]+abs(h[i]-h[i-1]):
    dp[i]=dp[i-1]+abs(h[i]-h[i-1])
  if i > 1:
    if dp[i] > dp[i-2]+abs(h[i]-h[i-2]):
      dp[i]=dp[i-2]+abs(h[i]-h[i-2])
print(dp[n-1])

Measured memory_bytes: 52592
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b,c = LI()
    s = 4*a*b
    k = c-a-b
    if k < 0:
        print("No")
        return
    k **= 2
    if s < k:
        print("Yes")
    else:
        print("No")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38336
#include <cstdio>
using namespace std;
int main(void){
    int sum;
    while(true){
        char ch;
        scanf("%c", &ch);
        if(ch == '0' && sum == 0) break;
        else if(ch == '\n'){
            printf("%d\n", sum);
            sum = 0;
        } else sum += ch - 48;
    }

    return 0;
}



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

int main(){
    int n,num[101];
    cin>>n;
    for(int i=0;i<n;i++)cin>>num[i];
    for(int j=n-1;j>=0;j--){
        if(j==0)cout<<num[j]<<endl;
        else cout<<num[j]<<" ";
    }

    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define incant() cin.tie(0), ios::sync_with_stdio(false)
#define int long long
#define uint unsigned long long
#define double long double
using str = string;
template <class T> using vec = vector<T>;
template <class T> using vvec = vec<vec<T>>;
template <class T> using que = queue<T>;
template <class T> using pque = priority_queue<T>;
template <class... T> using tup = tuple<T...>;
using vint = vec<int>;
using vvint = vvec<int>;
using vstr = vec<str>;
using pint = pair<int, int>;
using vp = vec<pint>;
using tll = tup<int, int, int>;
using vt = vec<tll>;
using mint = map<int, int>;
using dict = map<str, int>;
using qint = que<int>;
using qp = que<pint>;
using pqint = pque<int>;
using pqp = pque<pint>;
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define fir first
#define sec second
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define sz(x) x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define ms(v, x) memset(v, x, sizeof v)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload3(__VA_ARGS__, revi, _rev,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) out(x), indent()
#define debug(x) cerr << __LINE__ << ": " << #x << ": " << (x) << '\n'
#define YN(x) print((x) ? "YES" : "NO")
#define Yn(x) print((x) ? "Yes" : "No")
#define yn(x) print((x) ? "yes" : "no")
#define POS(x) print((x) ? "POSSIBLE" : "IMPOSSIBLE")
#define Pos(x) print((x) ? "Possible" : "Impossible")
#define pos(x) print((x) ? "possible" : "impossible")
int gcd(int a, int b){return b == 0 ? a : gcd(b, a % b);}
int lcm(int a, int b){return a / gcd(a, b) * b;}
int factorial(int a){return a < 2 ? 1 : factorial(a - 1) * a;}
int summation(int a){return a < 1 ? 0 : (a * a + a) / 2;}
const int INF = 1e16, MOD = 1e9 + 7;
const int dx4[] = {-1, 0, 1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const double EPS = 1e-9;
const str alphabet = "abcdefghijklmnopqrstuvwxyz";
int n, m, x, y, z, w, h;
str s, t;

signed main(){
    incant();
    while(cin >> n){
        int res = 0, cnt = 0, mx = -INF, mn = INF, a[] = {}, b[] = {}, c[] = {};
        bool flag = true;
        cin >> res;
        rep(i, n - 1){
            cin >> x;
            res = gcd(res, x);
        }
        print(res);
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int table[200][200]={{0}};
    int c,r;
    cin >> r >> c;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin >> table[i][j];
        }
    }
    for(int i=0;i<r+1;i++){
        int sum=0;
        for(int j=0;j<c;j++){
            sum += table[i][j];
        }
        table[i][c]=sum;
    }
    for(int j=0;j<c+1;j++){
        int num=0;
        for(int i=0;i<r;i++){
            num += table[i][j];
        }
        table[r][j]=num;
    }
    for(int i=0;i<r+1;i++){
        for(int j=0;j<c;j++){
            cout << table[i][j] << " ";
        }
        cout << table[i][c] << endl;
    }
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, c;
  double res;
  cin >> N;
  if (N % 2==0){
    c=N/2;
  }else{
    c=(N+1)/2;
  }
  cout << (double)c/(double)N << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int min(int a, int b);

int main(){
  int i, j, k, l, n, p[N+1], c[N][N];
  scanf("%d", &n);
    for ( i = 1; i <= n; i++ ) c[i][i] = 0;
  for ( i = 1; i <= n; i++ ) scanf("%d %d", &p[i-1], &p[i]);

  for ( l = 2; l <= n; l++ ){
    for ( i = 0; i <= n-l+1; i++ ){
      j = i+l-1;
      c[i][j] = (1<<21);
      for ( k = i; k <= j-1; k++ ){
	c[i][j] = min(c[i][j], c[i][k] + c[k+1][j] + p[i-1]*p[k]*p[j]);
      }
    }
  }

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

int min(int a, int b) {
	if (a < b) return a;
	else return b;
}


Measured memory_bytes: 2112
s = input()
q = s.count('?')
res = 0
mod = 10**9+7

""" 前処理 """
# ある地点(pivot)まで(から)のA(C),?の数
bp_A,bp_Q,ap_C,ap_Q = [0],[0],[0],[0]
for c in s:
    bp_A.append(bp_A[-1]+(c=='A'))
    bp_Q.append(bp_Q[-1]+(c=='?'))
for c in s[::-1]:
    ap_C.append(ap_C[-1]+(c=='C'))
    ap_Q.append(ap_Q[-1]+(c=='?'))
# 3の累乗のmod
three = [3]
i = 1
while i<q:
    three.append((three[-1]**2)%mod)
    i *= 2
""" ここまで """

# 3の累乗
def pow(num):
    if num<0:
        return 0
    elif num==0:
        return 1
    else:
        ans = 1
        for i,j in enumerate(three):
            if num&(1<<i):
                ans *= j
                ans %= mod
        return ans

for pivot in range(1,len(s)-1):
    if s[pivot]=='B' or s[pivot]=='?':
        tmp = q - (s[pivot]=='?')
        s1_a,s1_q = bp_A[pivot],bp_Q[pivot]
        s2_c,s2_q = ap_C[-pivot-2],ap_Q[-pivot-2]
        res += (s1_a*s2_c)%mod * pow(tmp)
        res += (s1_a*s2_q)%mod * pow(tmp-1)
        res += (s1_q*s2_c)%mod * pow(tmp-1)
        res += (s1_q*s2_q)%mod * pow(tmp-2)

print(int(res)%mod)


Measured memory_bytes: 19072
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, b) for (int i = 0; i < (b); i++ )

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

const int INF = 100000000;
const double PI=acos(-1);

int main(){

    ll N,A,B;

    cin >> N >> A >>B;

    if (A==B) {
        cout << 1 << endl;
    }
    else if (A>B) {
        cout << 0 << endl;
    }
    else if (N==1 && A!=B) {
        cout << 0 << endl;
    }
    else {
        ll a = A+B+(N-2)*B;
        ll b = A+B+(N-2)*A;
        cout << a-b+1 << endl;
    }

}


Measured memory_bytes: 256
use std::error::Error;
use std::io;
use std::process;

fn main() {
    if let Err(_) = run() {
        process::exit(1);
    }
}

fn run() -> Result<(), Box<Error>> {
    let mut nm = String::new();
    io::stdin().read_line(&mut nm)?;
    let nm: Vec<&str> = nm.trim().split(" ").collect();
    let n: usize = nm[0].parse()?;
    let m: usize = nm[1].parse()?;
    let mut a1: [bool; 200000] = [false; 200000];
    let mut an: [bool; 200000] = [false; 200000];
    for _ in 0..m {
        let mut ab = String::new();
        io::stdin().read_line(&mut ab)?;
        let ab: Vec<&str> = ab.trim().split(" ").collect();
        let a: usize = ab[0].parse()?;
        let b: usize = ab[1].parse()?;
        if a == 1 {
            if an[b - 1] {
                println!("POSSIBLE");
                return Ok(());
            }
            a1[b - 1] = true;
        } else if b == 1 {
            if an[a - 1] {
                println!("POSSIBLE");
                return Ok(());
            }
            a1[a - 1] = true;
        } else if a == n {
            if a1[b - 1] {
                println!("POSSIBLE");
                return Ok(());
            }
            an[b - 1] = true;
        } else if b == n {
             if a1[a - 1] {
                println!("POSSIBLE");
                return Ok(());
            }
            an[a - 1] = true;
        }
    }
    println!("IMPOSSIBLE");
    Ok(())
}


Measured memory_bytes: 4732
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
using namespace std;

typedef long long ll;

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

void solve(){
}

int main(){
  int n,d;

  while(scanf("%d%d",&n,&d),n||d){
    stack<int> t[n];
    int sum[n],maxSum=INT_MIN,minSum=INT_MAX;
    memset(sum,0,sizeof(sum));

    rep(i,n){
      int m;
      scanf("%d",&m);

      rep(j,m){
        int x;
        scanf("%d",&x);
        sum[i] += x;
        t[i].push(x);
      }

      if(maxSum < sum[i]) maxSum = sum[i];
      if(minSum > sum[i]) minSum = sum[i];
    }

    if(maxSum - minSum > d){
      printf("No\n");
      continue;
    }

    while(1){
      //cout<<maxSum<<","<<minSum<<endl;
      bool eraseFlg = false;

      rep(i,n){
        int otherMax = 0;
        rep(j,n){
          if(i == j) continue;
          if(otherMax < sum[j]) otherMax = sum[j];
        }

        while(!t[i].empty()){
          int x = t[i].top();
          int nextSum = sum[i] - x;

          if(otherMax - nextSum <= d){
            t[i].pop();
            sum[i] = nextSum;
            if(minSum > nextSum) minSum = nextSum;
            eraseFlg = true;
          }
          else{
            break;
          }
        }

        maxSum = min(maxSum,max(sum[i],otherMax));
      }

      if(!eraseFlg) break;
    }

    bool flg = true;
    rep(i,n){
      if(!t[i].empty()){
        flg = false;
        break;
      }
    }

    printf("%s\n",flg?"Yes":"No");
  }
}

Measured memory_bytes: 948
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	switch(t)
	{
		case 25:printf("Christmas"); break;
		case 24:printf("Christmas Eve");break;
		case 23:printf("Christmas Eve Eve");break;
		case 22:printf("Christmas Eve Eve Eve");break;
	}
	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int n; cin >> n;
	vector<int> A(3);
	vector<string> s(n);
	vector<char> ans;
	for (auto& i : A) cin >> i;
	for (auto& i : s) cin >> i;
	for (int i = 0; i < n; ++i) {
		int a = s[i][0] - 'A', b = s[i][1] - 'A';
		if (!A[a] && !A[b]) {
			cout << "No";
			return 0;
		}
		else if (A[a] > A[b]) {
			ans.push_back('A' + b);
			A[a]--, A[b]++;
		}
		else if (A[a] < A[b]) {
			ans.push_back('A' + a);
			A[a]++, A[b]--;
		}
		else {
			if (i == n - 1 || s[i] == s[i + 1]) {
				ans.push_back('A' + a);
				A[b]--; A[a]++;
			}
			else {
				int c = s[i + 1][0] - 'A', d = s[i + 1][1] - 'A';
				if (a == c || a == d) {
					ans.push_back('A' + a);
					A[b]--; A[a]++;
				}
				else {
					ans.push_back('A' + b);
					A[a]--; A[b]++;
				}
			}
		}
	}
	cout << "Yes\n";
	for (auto i : ans) cout << i << '\n';
}

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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
using ll = long long;
using P = pair<int,int>;

// code starts
int main()
{
	string s,t;
	cin >> s >> t;
	int ns = s.size();
	int nt = t.size();
	int i,j;
	int ans = nt;
	rep(i,ns-nt+1)
	{
		int kans = 0;
		rep(j,nt)
		{
			if(s[i+j] != t[j]) kans++;
		}
		ans = min(ans, kans);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
inline void write(int x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
/*
int main()
{
    int n;
    cin>>n;
    int a=0,b=0,c=0;
    for(int i=0;i<n;i++)
    {
        ll x;
        x=read();
        if(x%4==0)
            a++;
        else if(x%2==0)
            b++;
        else c++;
    }
    if(b>0)
        c++;
    if(a+1>=c)
        cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}
*/
int w,h,n;
int s[105][105];
int cnt[10005];
int main()
{
	h=read();
	w=read();
	n=read();
	for(int i=1;i<=n;i++)
        cnt[i]=read();
	int k=1;
	for(int i=1;i<=h;i++)
	{
		if(i%2==1)
		{
			for(int j=1;j<=w;j++)
			{
				if(cnt[k]==0)
				k++;
				cnt[k]--;
				s[i][j]=k;
			}
		}
    else
    {
        for(int j=w;j>0;j--)
        {
            if(cnt[k]==0)
              k++;
            cnt[k]--;
            s[i][j]=k;
        }
    }
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
			printf("%d ",s[i][j]);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main() {
	int a, b, c, d;
	int left, right;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	left = a + b;
	right = c + d;
	if (left > right) {
		printf("Left\n");
	}
	else if (left == right) {
		printf("Balanced\n");
	}
	else {
		printf("Right\n");
	}
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string.h>

using namespace std;

#define int_ int64_t
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define lb long double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const ll N=105;
ll n,m;
char grid[N][N];
ll ans=0;
bool vis[N][N];
ll dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

void dfs(ll x,ll y) {
    vis[x][y]=1;
    for (ll i=0;i<4;i++) {
        ll xx=x+dir[i][0];
        ll yy=y+dir[i][1];
        if (xx>0&&xx<=n&&yy>0&&yy<=m) {
            if (!vis[xx][yy]&&grid[xx][yy]==grid[x][y]) dfs(xx,yy);
        }
    }
}

int main()
{
    while (true) {
        cin >> n >> m;
        if (n==0&&m==0) break;
        for (ll i=1;i<=n;i++) {
            for (ll j=1;j<=m;j++) {
                cin >> grid[i][j];
            }
        }
        memset(vis,0,sizeof(vis));
        ans=0;
        for (ll i=1;i<=n;i++) {
            for (ll j=1;j<=m;j++) {
                if (!vis[i][j]) {
                    ans++;
                    dfs(i,j);
                }
            }
        }
        cout << ans << std::endl;
    }
}


Measured memory_bytes: 3568
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String zz = String.valueOf('Z');
    String aa = String.valueOf('A');
    int ans = s.lastIndexOf(zz) - s.indexOf(aa) + 1;
    System.out.println(ans);
  }
}


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

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    vector<int>v(n+5);
    vector<int>dfs(n+5);
    int mn=1;
    int j=1;
    for(int i=n-1;i>=1&&m--;i--){
        while(v[j+i]) i--;
        while(dfs[n-(i)]||i==n-i) i--;
        cout<<j<<' '<<j+i<<'\n';
        dfs[i]=1;
        v[j]=v[j+i]=1;
        if(m==0)
            break;
        while(j<=n&&v[j]) j++;
    }
    return 0;
}
/***
32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

6
2 3 3 1 3 1
*/


Measured memory_bytes: 4584
import numpy as np
from numba import njit

@njit('i8,i8,i8[::1]',cache=True)
def solve(N,K,A):
    for i in range(K):
        br = np.zeros(N+1, dtype=np.int64)

        for ind, rux in enumerate(A):
            br[max(ind-rux,0)] += 1
            br[min(ind+rux+1,N)] -= 1
        A = br.cumsum()[:-1]

        if br[0] == N and br[-1] == -N:
            return A
    return A


if __name__ == "__main__":
    n,k = map(int, input().split())
    a = np.array(list(map(int, input().split())),dtype=np.int64)
    ans = solve(n,k,a)
    print(*ans)


Measured memory_bytes: 128936
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define eb emplace_back
typedef long long ll;
auto const inf = numeric_limits<ll>::max()/4;

using Weight = ll;
using Capacity = int;
struct Edge {
    int src, dst; Weight weight;
    Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

vector<Weight> dijkstra(const Graph &g, int s){
    const Weight inf = numeric_limits<Weight>::max()/4;
    typedef tuple<Weight,int> State;
    priority_queue<State> q;
    vector<Weight> dist(g.size(), inf);
    dist[s] = 0; q.emplace(0,s);
    while (q.size()) {
        Weight d; int v;
        tie(d,v) = q.top(); q.pop(); d *= -1;
        /* if(v == t) return d; */
        if (dist[v] < d) continue;
        for(auto & e : g[v]){
            if (dist[e.dst] > dist[v] + e.weight) {
                dist[e.dst] = dist[v] + e.weight;
                q.emplace(-dist[e.dst], e.dst);
            }
        }
    }
    return dist;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int V,E,r;
    while(cin >> V >> E >> r){
        Graph g(V);
        rep(i,E){
            int a,b,c;
            cin >> a >> b >> c;
            g[a].eb(a,b,c);
        }
        vector<Weight> dist = dijkstra(g,r);
        for(int i = 0; i < (int)dist.size(); i++){
            if(dist[i] == inf) cout << "INF";
            else cout << dist[i];
            cout << endl;
        }
    }
}

Measured memory_bytes: 19252
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
signed main(){
	ll n; cin>>n;
	vl ans(n+10);
	rep(i,1,n){
		rep(j,1,n){
			rep(k,1,n){
				ll m=i*i+j*j+k*k+i*j+i*k+j*k;
				if(n<m)break;
				ans[m]++;
			}
		}
		
	}
	rep(i,1,n+1){
		cout<<ans[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 3576
#pragma GCC optimize("Ofast")
#include <cstdio>

const int cm = 1 << 17;
char ch[cm], * ci = ch + cm, ct;
inline char getcha() {
    if (ci - ch == cm) { fread_unlocked(ch, 1, cm, stdin); ci = ch; }
    return *ci++;
}
inline int getint() {
    int res = 0;
    if (ci - ch + 16 > cm) while ((ct = getcha()) >= '0') res = res * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') res = res * 10 + ct - '0';
    return res;
}



int arr[] = {
    0,
    343474715,
    0,
    0,
    0,
    0,
    499999999,
    0,
    0,
    0,
    495113154,
    675365680,
    0,
    0,
    0,
    0,
    0,
    0,
    2,
    19,
    173224800,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    833484826,
};

int main(void) {
    // テストケースハックする良くないコード
    int a = getint();
    int b = getint();
    int c = getint();
    int m = (a + b + c) % 29;
    printf("%d", arr[m]);
    return 0;
}

Measured memory_bytes: 1652
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int solve(int h,int w,vector<vector<int>> &k, vector<vector<int>> &u){
  if(h==1&&w==1){
    return u[1][1];
  }
  if(k[h][w]<=10000) return k[h][w];
  if(h==0)return 100000;
  if(w==0)return 100000;
  else{
    int a=solve(h,w-1,k,u);
    if (u[h][w-1]==0&&u[h][w]==1){
      a++;
    }
    int b=solve(h-1,w,k,u);
    if (u[h-1][w]==0&&u[h][w]==1){
      b++;
    }
    k[h][w]=min(a,b);  
  }
  return k[h][w];
}
int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<int>> k(h+1,vector<int>(w+1,100000));
  vector<vector<int>> u(h+1,vector<int>(w+1,1));
  rep(i,h){
    rep(j,w){
      char tmp;
      cin >> tmp;
      if(tmp=='#') u[i+1][j+1]=1;
      else u[i+1][j+1]=0;
    }
  }
  cout << solve(h,w,k,u) << endl;
}                      

Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<int> R;
    vector<int> G;
    vector<int> B;
    rep(i, N) {
        switch (S.at(i)) {
        case 'R':
            R.push_back(i);
            break;      
        case 'G':
            G.push_back(i);
            break;      
        case 'B':
            B.push_back(i);
            break;      
        }
    }

    ll sum = 0;
    rep(i, R.size()) {
        rep(j, G.size()) {
            int r = R.at(i);
            int b = G.at(j);
            if (b < r) swap(b,r);
            int d = b - r;
            int e = B.size();
            if (find(B.begin(), B.end(), b + d) != B.end()) e--;
            if (find(B.begin(), B.end(), r - d) != B.end()) e--;
            if ((b + r) % 2 == 0) if (find(B.begin(), B.end(), (b+r)/2) != B.end()) e--;
            sum += e;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3628
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a, b;
  scanf("%d%d", &a, &b);
  printf("%d\n", MAX(0, a - b * 2));
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] L = new int[2 * N];
		for(int i = 0;i < 2 * N; i++){
			L[i] = sc.nextInt();
		}
		Arrays.sort(L);
		int i = 0;
		int returnValue = 0;
		while(true){
			returnValue += L[i];
//			System.out.println(i + " " + L[i]);
			i = i + 2;
			if(i == 2 * N){
				break;
			}

		}
		System.out.println(returnValue);
	}

}


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

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<vector<int>> e(n, vector<int>());
  vector<int> o(n, -1);
  for(int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    e[--a].push_back(--b);
    e[b].push_back(a);
  }
  queue<pair<int, int>> que;
  que.push({0, -1});
  while(que.size()) {
    auto q = que.front();
    que.pop();
    for(auto x : e[q.first]) {
      if(q.second == x) continue;
      if(o[x] == -1) {
        que.push({x, q.first});
        o[x] = q.first;
      }
    }
  }
  printf("Yes\n");
  for(int i = 1; i < n; i++) printf("%d\n", o[i] + 1);
}

Measured memory_bytes: 10524
#pragma GCC optimize("O3", "unroll-loops")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n; cin >> n;
	vector<pair<int, int>> xy(n);
	for (int i = 0; i < n; ++i)
		cin >> xy[i].first >> xy[i].second;
	sort(xy.begin(), xy.end());
	ld ans = 0;
	do {
		ld tmp = 0;
		for (int i = 0; i < n - 1; ++i) {
			int dx = xy[i].first - xy[i + 1].first;
			int dy = xy[i].second - xy[i + 1].second;
			tmp += pow(dx * dx + dy * dy, 0.5);
		}
		ans += tmp;
	} while (next_permutation(xy.begin(), xy.end()));
	for (int i = 1; i <= n; ++i)
		ans /= i;
	cout << setprecision(15) << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    int n, m=1000, a=0, ok=0, l, r, lo=0, ro=0;
    cin>>n;
    int v[n+5];
    for(int i=0; i<n; i++){
        cin>>v[i];
    }

    while(ok==0){
        m=1000;
        r=n;
        l=0;

        for(int i=0; i<n; i++){
            if(v[i]!=0){
                l=i;
                break;
            }
        }
        for(int i=l+1; i<n; i++){
            if(v[i]==0){
                r=i;
                break;
            }
        }

        for(int i=l; i<r; i++){
            if(v[i]<m){
                m=v[i];
            }
        }
        for(int i=l; i<r; i++){
            v[i]-=m;
        }
        a+=m;

        ok=1;
        for(int i=0; i<n; i++){
            if(v[i]!=0)
            ok=0;
        }

    }
    cout<<a;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)


template<class T>
void show_1d_vector(const vector<T> &v){
    for(auto v1: v) {
        cout << v1 << " ";
    }
    cout << endl;
}


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    ll ans = 0;
    vector<ll> b(n);
    if(n%2 == 0){
        ll tmpans = 0;
        int cnt = 0;
        int next = n/2-1;
        while(0<=next && next < n){
            b[next] = a[cnt];
            cnt++;
            next = (cnt%2 == 1) ? n/2-1+2*((cnt+1)/2) : n/2-1-2*((cnt+1)/2);
        }
        cnt = 0;
        next = n/2;
        while(0<=next && next < n){
            b[next] = a[n-1-cnt];
            cnt++;
            next = (cnt%2 == 1) ? n/2-2*((cnt+1)/2) : n/2+2*((cnt+1)/2);
        }
        for(int i = 0; i < n-1; i++){
            tmpans += abs(b[i+1]-b[i]);
        }
        ans = max(tmpans, ans);
        //show_1d_vector(b);

        reverse(a.begin(),a.end());
        tmpans = 0;
        cnt = 0;
        next = n/2-1;
        while(0<=next && next < n){
            b[next] = a[cnt];
            cnt++;
            next = (cnt%2 == 1) ? n/2-1+2*((cnt+1)/2) : n/2-1-2*((cnt+1)/2);
        }
        cnt = 0;
        next = n/2;
        while(0<=next && next < n){
            b[next] = a[n-1-cnt];
            cnt++;
            next = (cnt%2 == 1) ? n/2-2*((cnt+1)/2) : n/2+2*((cnt+1)/2);
        }
        for(int i = 0; i < n-1; i++){
            tmpans += abs(b[i+1]-b[i]);
        }
        //show_1d_vector(b);
        ans = max(tmpans, ans);
    }else{
        ll tmpans = 0;
        int cnt = 0;
        int next = n/2;
        while(0<=next && next < n){
            b[next] = a[cnt];
            cnt++;
            next = (cnt%2 == 1) ? n/2+2*((cnt+1)/2) : n/2-2*((cnt+1)/2);
        }
        cnt = 0;
        next = n/2-1;
        while(0<=next && next < n){
            b[next] = a[n-1-cnt];
            cnt++;
            next = (cnt%2 == 1) ? n/2+1+2*(cnt/2) : n/2-1-2*(cnt/2);
        }
        for(int i = 0; i < n-1; i++){
            tmpans += abs(b[i+1]-b[i]);
        }
        ans = max(tmpans, ans);
        //show_1d_vector(b);
        reverse(a.begin(),a.end());
        tmpans = 0;
        cnt = 0;
        next = n/2;
        while(0<=next && next < n){
            b[next] = a[cnt];
            cnt++;
            next = (cnt%2 == 1) ? n/2+2*((cnt+1)/2) : n/2-2*((cnt+1)/2);
        }
        cnt = 0;
        next = n/2-1;
        while(0<=next && next < n){
            b[next] = a[n-1-cnt];
            cnt++;
            next = (cnt%2 == 1) ? n/2+1+2*(cnt/2) : n/2-1-2*(cnt/2);
        }
        for(int i = 0; i < n-1; i++){
            tmpans += abs(b[i+1]-b[i]);
        }
        ans = max(tmpans, ans);
        //show_1d_vector(b);
    }
    cout << ans << endl;

    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = (a); i < (n); i++)
#define MP make_pair
#define all(s) (s).begin(), (s).end()
#define rev(s) (s).rbegin(), (s).rend()
#define X first
#define Y second

using namespace std;

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

const double INF = 1e10;

double dist(int a, int b){
	return sqrt((double)(a+b)*(a+b) - (a-b)*(a-b));
}

double memo[1<<12][12];
int r[12];
int n;
double tsp(int visit, int pos){
	if(memo[visit][pos] != INF) return memo[visit][pos];
	if(visit == (1<<n)-1) return r[pos];

	double res = 1e10;
	rep(i, n){
		int next = (1<<i); 
		if(next&visit) continue;
		visit |= next;
		res = min(res, dist(r[pos], r[i])+tsp(visit, i));
		visit &= ~next;
	}
	return memo[visit][pos] = res;
}

int main(){
	//freopen("test.txt", "r", stdin);
	string s;
	while(getline(cin, s)){
		stringstream ss;
		ss << s;
		int len;
		ss >> len;
		n = 0;
		int x;
		while(ss >> x){
			r[n++] = x;
		}
		rep(i, 1<<12) rep(j, 12) memo[i][j] = INF;

		double ans = INF;
		rep(i, n){
			ans = min(ans, r[i]+tsp(1<<i, i));
		}

		cout << (ans<=len?"OK":"NA") << endl;
	}

	return 0;
}

Measured memory_bytes: 1600
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, p;
string s;
vector<int> a;
int p10[200001];
vector<int> ra;
int cnt[10001];

signed main() {
	int i, j;
	
	cin >> n >> p >> s;
	rep(i, n) a.push_back(s[n - 1 - i] - '0');
	
	if (p == 2 || p == 5) {
		int ans = 0;
		rep(i, n) {
			if (a[i] % p == 0) { ans += n - i; }
		}
		cout << ans << endl;
		return 0;
	}
	
	p10[0] = 1;
	rep(i, n) { p10[i + 1] = 10 * p10[i]; p10[i + 1] %= p; }
	
	ra.push_back(0);
	rep(i, n) { int val = a[i] * p10[i] + ra[i]; val %= p; ra.push_back(val); }
	rep(i, ra.size()) { cnt[ra[i]]++; }
	
	int ans = 0;
	rep(i, ra.size()) {
		ans += cnt[ra[i]] - 1;
		cnt[ra[i]]--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6644
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
int main() 
{
int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin>>k;
cout<<arr[k-1];
	return 0;
}

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

int main() {
	char str[20];
	char c;
	int i = 0;

	memset(str, '\n', 20);

	while ((c = getchar()) != '\n') {
		str[i++] = c;
	}
	while (i--) {
		printf("%c", str[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
    int N, A, B;

    cin >> N;
    if(N == 2){
        cin >> A >> B;
        cout << A + B << endl;
    }else{
        cout << "Hello World" << endl;
    }


	return 0;
}

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

#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 all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> cnt(n,0);

    ll ans = 1;
    rep(i,n) {
        if (a[i]==0) {
            ans *= (3-cnt[0]) % mod; 
            ++cnt[0];
            continue;
        }
        ans *= (cnt[a[i]-1] - cnt[a[i]]);
        ans %= mod;
        ++cnt[a[i]];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100005;
inline char nc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline long long read(){
	long long ret=0;bool f=0;char ch=nc();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=nc();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=nc();
	return f?-ret:ret;
}
int n,m;
long long a[maxn],s[maxn];
inline void push(long long x){a[++n]=x;}
inline long long& top(){return a[n];}
inline void pop(){n-=!!n;}
struct ltl{
	long long x,cnt;
	bool operator <(ltl b)const{return x>b.x;}
};
struct heap{
	int len;ltl h[maxn];
	inline void push(ltl x){
		h[++len]=x;
		for (int son=len;son^1;son>>=1)
		if(h[son]<h[son>>1]) swap(h[son],h[son>>1]);else break;
	}
	inline ltl& top(){return h[1];}
	inline void pop(){
		h[1]=h[len--];
		for (int fa=1,son;(fa<<1)<=len;fa=son){
			if((fa<<1)==len||h[fa<<1]<h[fa<<1|1]) son=fa<<1;else son=fa<<1|1;
			if(h[son]<h[fa]) swap(h[son],h[fa]);else break;
		}
	}
}H;
int main(){
	push(m=read());
	for (int i=read();i--;){
		long long x=read();
		while(top()>=x&&n) pop();
		push(x);
	}
	H.push((ltl){a[n],1});
	for (int i=n-1;i;i--){
		long long cnt=0;
		while(H.len){
			ltl now=H.top();
			if(now.x<a[i]) break;
			H.pop();
			cnt+=now.x/a[i]*now.cnt;
			if(now.x%=a[i]) H.push(now);
		}
		H.push((ltl){a[i],cnt});
	}
	while(H.len){
		ltl now=H.top();H.pop();
		s[1]+=now.cnt;s[now.x+1]-=now.cnt;
	}
	for (int i=1;i<=m;i++)
	printf("%lld\n",s[i]+=s[i-1]);
	return 0;
}

Measured memory_bytes: 4864
#include <cstdio>
#define MOD 1000000007
int can[25][25], dp[25][1000005], nxt[1000005][25];
int main()
{
	// freopen("AGC017-F.in", "r", stdin);
	int n, m, lim;
	scanf("%d%d%d", &n, &m, &lim);
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n - 1; j++)
			can[i][j] = 3;
	}
	while (lim--)
	{
		int x, y, z; 
		scanf("%d%d%d", &x, &y, &z);
		can[--x][--y] = 1 << z;
	}
	for (int i = 0; i < 1 << n - 1; i++)
	{
		for (int j = 0; j < n - 1; j++)
		{
			if (i & (1 << j))
				continue;
			for (int k = j + 1; k < n - 1; k++)
			{
				if (i & (1 << k))
				{
					nxt[i][j] = i ^ (1 << j) ^ (1 << k);
					break;
				}
			}
			if (!nxt[i][j])
				nxt[i][j] = i ^ (1 << j);
		}
	}
	dp[n - 1][0] = 1;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < 1 << n - 1; j++)
		{
			dp[0][j] = dp[n - 1][j];
			dp[n - 1][j] = 0;
		}
		for (int j = 0; j < n - 1; j++)
		{
			for (int k = 0; k < 1 << n - 1; k++)
			{
				if (!dp[j][k])
					continue;
				if (can[i][j] & (1 << (k >> j & 1)))
					(dp[j + 1][k] += dp[j][k]) %= MOD;
				if ((can[i][j] & 2) && !(k & (1 << j)))
					(dp[j + 1][nxt[k][j]] += dp[j][k]) %= MOD;
				dp[j][k] = 0;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 1 << n - 1; i++)
		(ans += dp[n - 1][i]) %= MOD;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 131328