akhauriyash/Code-Regression huggingface dataset:
import qualified Data.ByteString.Char8 as B

readInt :: B.ByteString -> Int
readInt = maybe undefined fst . B.readInt

readInts :: B.ByteString -> [Int]
readInts = map readInt . B.words

main = do
  getLine
  as <- readInts <$> B.getLine
  print (invisible 0 0 maxBound as)

invisible acc _ _ [] = acc
invisible acc dmax amin (a:as)
  | a < amin = invisible acc dmax a as
  | a - amin > dmax = invisible 1 (a - amin) amin as
  | a - amin == dmax = invisible (acc + 1) dmax amin as
  | otherwise = invisible acc dmax amin as

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

int main(int argc, char **argv)
{
    int N;
    std::cin >> N;

    std::vector<int> A(N);
    for(int i = 0; i < N; i++){
        std::cin >> A.at(i);
    }

    int num = 1;
    int a = A.at(0);
    int diff = 0;
    for(int i = 1; i < N; i++){
        int nd = A.at(i) - a;
        a = A.at(i);
        if(nd == 0 || diff == 0 || (nd < 0 && diff < 0) || (nd > 0 && diff > 0)){
            if(nd != 0){
                diff = nd;
            }
        }else{
            num++; // new seriese
            diff = 0;
        }
    }
    std::cout << num << std::endl;
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#define debug(x) cerr << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const Double PI  = 3.141592653589793238463;
const Int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

V solve(Int n, V& as){
    V bs(n);
    for(Int i = 0; i < n; i++){
        bs[as[i] - 1] = i + 1;
    }
    return bs;
}


int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    Int n;
    cin >> n;
    V as(n);
    cin >> as;
    V bs = solve(n, as);
    cout << bs[0];
    for(Int i = 1; i < n; i++){
        cout << " " << bs[i];
    }
    cout << "\n";

    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define int long long

// int comb(int n, int k) {
//   int m = 1;
//   if(n < 2 * k) { k = n - k; }
//   FOR(i, 1, k + 1) { m = (m * (n - i + 1) / i) % MOD; }
//   return m;
// }
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  COMinit();
  int N, K;
  cin >> N >> K;
  FOR(i, 1, K + 1) {
    int ans = 1;
    int b = K;
    b -= i;
    ans *= COM(b + i - 1, i - 1);
    int r = N - K;
    r -= i - 1;
    if(r < 0) {
      cout << 0 << endl;
      continue;
    }
    ans = (ans * COM(r + i, i)) % MOD;
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

int a[200005];

const int md = 1000000007;

int mul(int x, int y) {
	return (long long)x * y % md;
}

int power(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) {
			ans = mul(ans, x);
		}
		x = mul(x, x);
		y >>= 1;
	}
	return ans;
}

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		a[x]++;
	}
	if (n & 1) {
		int v = n - 1;
		for (int i = v; i > 0; i -= 2) {
			if (a[i] != 2) {
				puts("0");
				return 0;
			}
		}
		if (a[0] != 1) {
			puts("0");
			return 0;
		}
		printf("%d\n", power(2, (n / 2)));
	} else {
		int v = n - 1;
		for (int i = v; i > 0; i -= 2) {
			if (a[i] != 2) {
				puts("0");
				return 0;
			}
		}
		printf("%d\n", power(2, (n / 2)));
	}
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
vector<ll> adj[200001];
ll seg[800005], lazy[800005];
ll merge(ll a, ll b)
{
	return a + b;
}
void update(ll pos, ll l, ll r, ll l1, ll r1, ll val)
{
	if(l > r)
		return;
	if(lazy[pos])
	{
		seg[pos] += (r - l + 1) * lazy[pos];
		if(l != r)
		{
			lazy[2*pos+1] += lazy[pos];
			lazy[2*pos+2] += lazy[pos];
		}
		lazy[pos] = 0;
	}
	if(r1 < l || l1 > r)
		return;
	if(l1 <= l && r <= r1)
	{
		seg[pos] += (r - l + 1) * val;
		if(l != r)
		{
			lazy[2*pos+1] += val;
			lazy[2*pos+2] += val;
		}
		return;
	}
	ll mid = (l + r)/2;
	update(2*pos+1, l, mid, l1, r1, val);
	update(2*pos+2, mid+1, r, l1, r1, val);
	seg[pos] = merge(seg[2*pos+1], seg[2*pos+2]);
	return;
}
ll query(ll pos, ll l, ll r, ll l1, ll r1)
{
	if(l > r || r1 < l || l1 > r)
		return 0;
	if(lazy[pos])
	{
		seg[pos] += (r - l + 1) * lazy[pos];
		if(l != r)
		{
			lazy[2*pos+1] += lazy[pos];
			lazy[2*pos+2] += lazy[pos];
		}
		lazy[pos] = 0;
	}
	if(l1 <= l && r <= r1)
		return seg[pos];
	ll mid = (l + r)/2;
	return merge(query(2*pos+1, l, mid, l1, r1), query(2*pos+2, mid+1, r, l1, r1));
}
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, i, a, b, j, k;
    cin >> n;
    ll ans[n], sum = 0;
    for(i = 0; i < n - 1; i++) {
    	cin >> a >> b;
    	a--, b--;
    	if(a < b) {
    		swap(a, b);
    	}
    	adj[a].pb(b);
    }
    for(i = 0; i < n; i++) {
    	ans[i] = 0;
    	sort(all(adj[i]));
    	ll prev = 0;
    	ll s = adj[i].size();
    	for(j = 0; j < s; j++) {
    		ll rem = s - j;
    		ll sub = rem - 1;
    		update(0, 0, n - 1, prev, adj[i][j], -sub);
    		prev = adj[i][j] + 1;
    	}
    	update(0, 0, n - 1, prev, i, 1);
    	sum += query(0, 0, n - 1, 0, i);
    }
    cout << sum << "\n";
}

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

using namespace std;

int main() {
    long long n,m;
    cin >> n >> m;
    long long nmax=-1;
    long long nmin=9999999999;
    for(long long i=0; i<m; i++) {
        long long l,r;
        cin >> l >> r;
        nmax = max(nmax, l);
        nmin = min(nmin, r);
    }

    long long ans = abs(nmin - nmax) + 1;
    if ( nmin < nmax ) {
        ans = 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 888
import sys
sys.setrecursionlimit(100000)

H, W = map(int, input().split())
S = [input() for _ in range(H)]
cost = [[0]*W for _ in range(H)]
cost[0][0] = 1 if S[0][0] == '#' else 0
for w in range(1,W):
  if S[0][w-1] == '.' and S[0][w] == '#':
    cost[0][w] = cost[0][w-1] + 1
  else:
    cost[0][w] = cost[0][w-1]
for h in range(1,H):
  if S[h-1][0] == '.' and S[h][0] == '#':
    cost[h][0] = cost[h-1][0] + 1
  else:
    cost[h][0] = cost[h-1][0]

for h in range(1,H):
  for w in range(1,W):
    if S[h-1][w] == '.' and S[h][w] == '#':
      ch = cost[h-1][w] + 1
    else:
      ch = cost[h-1][w]
    if S[h][w-1] == '.' and S[h][w] == '#':
      cw = cost[h][w-1] + 1
    else:
      cw = cost[h][w-1]
    cost[h][w] = min(ch, cw)

print(cost[-1][-1])

Measured memory_bytes: 3192
N = int(input())
S = [list(map(int, list(input()))) for _ in range(N)]

graph = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if S[i][j] == 1: graph[i].append(j)

from collections import deque

ans_tmp = 0
possible = True
for home in range(N):
    iswhite = [None] * N
    q = deque([(home, False, 0)])
    iswhite[home] = False
    while len(q) > 0:
        src, white, depth = q.popleft()
        # print("##", src, white, depth)
        if depth > ans_tmp:
            # home = src
            ans_tmp = depth
        #
        for dst in graph[src]:
            # print("###", dst, iswhite[dst])
            if iswhite[dst] == None:
                white_dst = (white != True)
                q.append((dst, white_dst, depth + 1))
                iswhite[dst] = white_dst
            elif white == iswhite[dst]:
                possible = False
                break
            else:
                continue
        #
        if possible == False:
            break
    
if possible:
    print(ans_tmp + 1)
else:
    # print("#", iswhite)
    print(-1)

Measured memory_bytes: 44380
function Main(input) {
  input = input.trim()
 input = input.split("\n").map(Number);
 var sum =0;
 if(input[0]>input[1]){
sum+=input[1]
 }else{
sum+=input[0]
 }
 if(input[2]>input[3]){
sum+=input[3]
 }else{
sum+=input[2]
 }
 console.log(sum)
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void print() { cout << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) { cout << x << " "; print(args...);}
void debug_out() { cout << "\n"; }
template <class T, class... Args> void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i,n) {
    if (a[i] == 0) continue;
    int amari = a[i] % 2;
    ans += a[i] / 2;
    if (i < n-1 && a[i+1] > 0) a[i+1] += amari; //次でペアを作る
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int N;
int C[500], S[500], F[500];
int res[500];

int main(int argc, char* argv[]) {
  cin >> N;
  for (int i = 0; i < N - 1; i++)
    cin >> C[i] >> S[i] >> F[i];

  for (int i = 0; i < N; i++) {
    int time = 0;
    for (int j = i; j < N - 1; j++) {
      if (time < S[j]) {
        time = S[j] + C[j];
      } else if (time % F[j] == 0) {
        time += C[j];
      } else {
        time += C[j] + F[j] - time % F[j];
      }
    }
    cout << time << endl;
  }

  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


import sys
import math

# 1整数
n = input()

ret = 0

atgc = ['A', 'T', 'G', 'C']
rr = 0
for c in n:
    if c in atgc:
        rr += 1
    else:
        ret = max(ret, rr)
        rr = 0
ret = max(ret, rr)
print(ret)


Measured memory_bytes: 3060
N, K = map(int, input().split())
ans = 0

for i in range(K, N + 2):
    m = 1 / 2 * (i - 1) * i 
    M = 1 / 2 * (N + N - i + 1) * i
    if M == m:
        ans += 1
    else:
        ans += (M - m + 1)

print(int(ans % (10 ** 9 + 7)))

Measured memory_bytes: 67480
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

inline ll read(){
	int x = 0, f = 1; char ch = getchar();
	while (ch>'9' || ch<'0'){ if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9'){ x = x * 10 + ch - '0'; ch = getchar(); }
	return x*f;
}

/***********************************************************/


int main() {
	
	int a, b;
	cin >> a >> b;
	int ans = 0;
	ans = max(ans, a + a - 1);
	ans = max(ans, b + b - 1);
	ans = max(ans, a + b);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
const int maxn=210;
long long fac[maxn],inv[maxn];
long long powd(long long x,long long y){
	long long res=1;
	while(y){
		if(y&1) res=res*x%md;
		x=x*x%md;
		y>>=1;
	}
	return res;
}
char str[maxn];
int stk[maxn],top;
int n,m;
bool check(int x){
	static bool vis[maxn];
	static int ps[maxn];
	for(int i=1;i<=m;i++)
		vis[i]=0;
	int p=0,cnt=0;
	for(int i=1;i<=m;i++){
		if(cnt>=top) break;
		if(str[i]=='r'){
			if(p<i) p=i;
			while(p<=m&&(vis[p]||str[p]=='r'))
				p++;
			if(p>m) return 0;
			cnt++;
			ps[cnt]=p;
			vis[i]=vis[p]=1;
		}
	}
	if(cnt!=top) return 0;
	cnt=0;
	for(int i=1;i<=m;i++){
		if(cnt>=x) break;
		if(str[i]=='r'&&!vis[i]){
			vis[i]=1;
			cnt++;
		}
	}
	if(cnt!=x) return 0;
	p=m;
	for(int i=top;i>=1;i--){
		cnt=0;
		while(p>=ps[i]&&cnt<stk[i]/2){
			if(!vis[p]) cnt++;
			p--;
		}
		if(cnt!=stk[i]/2) return 0;
	}
	return 1;
}
long long sum[maxn][maxn];
void solve(int res,long long val,int num){
	long long fas;
	int tot=0;
	for(int i=1;i<=top;i++) tot+=stk[i];
	for(int i=0;i<=res;i++){
		if(tot+top+i*2>n+1) break;
		if(!check(i)) break;
		fas=fac[num+i]*val%md*inv[i]%md;
		(sum[tot+top+i*2][top]+=fas)%=md;
//		printf("%d %d\n",tot+top+i*2,top);
	}
}
void dfs(int res,int las,long long val,int num){
	solve(res,val,num);
	res--;
	int ttp;
	for(int i=1;i<=res&&i<=las;i+=2){
		ttp=top;
		for(int j=1;res-i*j>=0;j++){
			stk[++top]=i;
			dfs(res-i*j,i-1,val*inv[j]%md,num+j);
		}
		top=ttp;
	}
}
long long C[maxn][maxn];
int main(){
//	freopen("F.in","r",stdin);
//	freopen("F.out","w",stdout);
	fac[0]=1;
	for(int i=1;i<=100;i++)
		fac[i]=fac[i-1]*i%md;
	inv[100]=powd(fac[100],md-2);
	for(int i=100;i>=1;i--)
		inv[i-1]=inv[i]*i%md;
	C[0][0]=C[1][0]=C[1][1]=1;
	for(int i=2;i<=100;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%md;
	}

	scanf("%d%d",&n,&m);
	scanf("%s",str+1);
	dfs(n+1,n,1,0);
	long long ans=0,st=0;
	for(int i=0;i<=n+1;i++){
		for(int j=0;j<=n+1;j++){
			if(!sum[i][j]) continue;
			st=0;
			for(int k=0;k<=j*2;k++){
				if(i+k<=n+1){
					ans=(ans+C[n+1][i+k]*C[j*2][k]%md*sum[i][j])%md;
					st+=C[n+1][i+k]*C[j*2][k]%md*sum[i][j];
				}
				else break;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
int n,m,a[200010],c[200010],x,y,ans=0,b[200010];
int main(){
	scanf("%d%d",&n,&m);
	ans=n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]),c[a[i]]++;
		if(a[i]-c[a[i]]>=0) b[a[i]-c[a[i]]]++;
		if(a[i]-c[a[i]]>=0&&b[a[i]-c[a[i]]]==1)ans--;
	}
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		if(a[x]-c[a[x]]>=0) b[a[x]-c[a[x]]]--;
		if(a[x]-c[a[x]]>=0&&b[a[x]-c[a[x]]]==0)ans++;
		c[a[x]]--;
		a[x]=y;
		c[a[x]]++;
		if(a[x]-c[a[x]]>=0) b[a[x]-c[a[x]]]++;
		if(a[x]-c[a[x]]>=0&&b[a[x]-c[a[x]]]==1)ans--;
		printf("%d\n",ans); 
	}
	return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][][] a = new int[4][3][10];
        for (int i = 0; i < n; i++) {
            int b = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            int v = sc.nextInt();
            a[b-1][f-1][r-1] += v;
        }
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 3; j++) {
                 for (int k = 0; k < 10; k++) {
                     System.out.print(" "+a[i][j][k]);
                 }
            System.out.println("");
            if(i < 3 && j == 2)
                System.out.println("####################");
            }
        }
    }
}

        
        


Measured memory_bytes: 29764
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    string S, T;
    cin>>S>>T;
    int A, B;
    cin>>A>>B;
    string U;
    cin>>U;
    if(U==S) A--;
    else B--;
    cout<<A<<sp<<B<<endl;
    return 0;
}


Measured memory_bytes: 256
let rec fix ~f x = f (fix ~f) x

let modulo = 1000000007
let (+@) a b = (a + b) mod modulo
let (-@) a b = (a - b + modulo) mod modulo
let ( *@) a b = (a * b) mod modulo
let rec ( **@) a n =
  if n = 0 then 1
  else if n mod 2 = 1 then a *@ a **@ (n-1)
  else let h = a **@ (n/2) in h *@ h
let modinv a = a **@ (modulo-2)
let (/@) a b = a *@ modinv b

let input () =
  Scanf.scanf "%d" @@ fun n ->
  let g = Array.init (n+1) (fun _ -> []) in
  for i = 1 to n-1 do
    Scanf.scanf " %d %d" @@ fun a b ->
    g.(a) <- b :: g.(a);
    g.(b) <- a :: g.(b);
  done;
  n, g

let () =
  let n, g = input () in
  let _, lvs =
    fix 1 0 [] ~f:(fun dfs u p lvs ->
      let lv, lvs =
       List.fold_left (fun (lv, lvs) v ->
          if v = p then (lv, lvs)
          else
            let c, lvs' = dfs v u lvs
            in (c :: lv, lvs')) ([], lvs) g.(u)
      in
      let cn = List.fold_left (+) 0 lv in
      let lv = n-1-cn :: lv in
      1 + cn, lv :: lvs)
  in
  List.fold_left (fun ans lv ->
    let b0 = List.fold_left (fun b0 l -> b0 /@ (2 **@ l)) 1 lv in
    let b1 = List.fold_left (fun b1 l ->
      b1 +@ b0 *@ (2 **@ l) *@ (1 -@ modinv (2 **@ l))) 0 lv in
    ans +@ (1 -@ b0 -@ b1) /@ 2) 0 lvs
  |> Printf.printf "%d\n"
    


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

int main(){
  int n; cin >> n;
  map<string, int> mp;
  long long ans = 0;
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    sort(s.begin(), s.end());
    ans += mp[s];
    mp[s]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11136
// dfsで全探索しようとしたが、
// 結末を予想すると最小距離テーブルが　N**2 のサイズであるし
// DFSにもコストがかかるからやめた
// そもそもX, Yがなければ答えが自明であるのでX, Yがあるときとないときで考えた
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using Graph = vector<vector<int>>;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

int N, X, Y;
vector<ll> A;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // Globalなvectorのリサイズ
  //A.resize(N);
  cin >> N >> X >> Y;
  map<int, int> m;
 
  // 高々2 * 10 **3 * 10 ** 3
  rep1(i, N) {
    for(int j=i+1; j <= N; j++) {
      // i -> j;
      // i -> X -> Y -> j;
      // i -> Y -> X -> j;
      // XYのルートを使ったほうが早いならそうする
      int d = min(j-i, min(abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X)));
      m[d]++;
    }
  }
  rep1(i, N-1) {
    cout << m[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scan_init()
	n := scanInt() % 1000
	if n != 0 {
		n = -(n-1000)
	}
	fmt.Println(n)
}

var sc = bufio.NewScanner(os.Stdin)

func scan_init() {
	sc.Split(bufio.ScanWords)
}
func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func scan() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1772
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, k, s = inintm()

ans = [str(s)]*k

if s != 10**9:
    for i in range(n-k):
        ans.append(str(s+1))
else:
    for i in range(n-k):
        ans.append(str(s-1))

print(" ".join(ans))

Measured memory_bytes: 73272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[10010];
vector<vector<ll>>b(102);
int main() {
	ll h,w,n;
	cin>>h>>w>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ll now=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			while(a[now]==0){
			now++;
			}
			b[i].push_back(now+1);
			a[now]--;
		}
	}
	for(int i=0;i<h;i++){
		if(i%2==0){
			for(int j=0;j<w;j++){
				cout << b[i][j]<< " ";
			}
		}
		else{
			for(int j=w-1;j>=0;j--){
				cout << b[i][j]<<" ";
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 512
N = int(input())
h = list(map(int, input().split()))

dp = [0] * N
dp[1] = abs(h[1] - h[0])
 
for i in range(2,N):
	dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])

Measured memory_bytes: 13980
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    
    int ans = 0;
    for(int i=A;i<=B;i++){
        
        if(i/10000==i%10 && i/1000%10==i/10%10){
            ans++;
        }
    }
    
    cout << ans << endl;
return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;
    cin>>n>>m;
    ll dp[10][10];
    rep(i,10){
        rep(j,10){
            cin>>dp[i][j];
        }
    }
    for (ll k = 0; k < 10; k++){       // 経由する頂点
      for (ll i = 0; i < 10; i++) {    // 始点
          if(dp[i][k]==INF) continue;
        for (ll j = 0; j < 10; j++) {  // 終点
          if(dp[k][j]==INF) continue;
          dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
        }
      }
    }
    ll sum=0;
    rep(i,n){
        rep(j,m){
            ll a;
            cin>>a;
            if(a==-1) continue;
            else sum+=dp[a][1];
        }
    }
    cout<<sum<<endl;
    return 0;
}

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

using namespace std;

int main(){
  
  long long n,k;
  cin>>n>>k;
  long long a[n];
  for(long long i=0;i<n;i++)
    cin>>a[i];
  
  long long dp[n];
  for(long long i=0;i<n;i++) dp[i]=10000000000;
  dp[0]=0;dp[1]=abs(a[1]-a[0]);
  for(long long i=2;i<n;i++)
    for(long long j=1;j<=k&&j<=i;j++)
    dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
  
  cout<<dp[n-1]<<endl;
  
 return 0; 
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int n,mx,x;
string s;
vector<int>v;
int main() {
	cin>>n>>s;
	for(int i=0;i<n;++i)
	{
		if(s[i]=='I')x++;
		else x--;
		v.push_back(x);
	}
	for(int i=0;i<v.size();++i)
	mx=max(mx,v[i]);
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n, m;
    cin >> n >> m;
    int mini=1e5+1, maxi=0;
    int cnt=0;
    for(int i=0; i<m; i++){
        int l, r;
        cin >> l >> r;
        mini = min(mini, r);
        maxi = max(maxi, l);
    }

    for(int i=maxi; i<=mini; i++){
        cnt++;
    }
    out(cnt);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{
    int n, m;
    
    cin >> n >> m;
    
    int a[n][m];
    int b[1][m];
    int c[1][m];
    
    int l1;
    int n1 = 0;
    int m1 = 0;
  	int flg = 0;
    while (cin >> l1) {
        if (flg == 0) {
          a[n1][m1] = l1;

          m1 += 1;
          if (m1 >= m) {
              n1 += 1;
              m1 = 0;
          }

          if (n1 == n) {
            m1 = 0;
            flg = 1;
          }
        } else {
          b[0][m1] = l1;
        	m1 += 1;
        }
    }
    
    for (int i = 0; i < n; i++) {
      	int sum = 0;
        for (int j = 0; j < m; j++) {
          	sum += a[i][j] * b[0][j];
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 3096
;; F - Surrounded Nodes

(defparameter *modulus* (+ (expt 10 9) 7))
(defparameter *2-inv* (/ (1+ *modulus*) 2)) ; 2^-1 (mod *modulus*)

(defun main ()
  (let* ((N (read))  ; 頂点数
         (tree (read-tree N)))
    (princ (solve N tree))
    (fresh-line)))

(defun solve (N tree)
  (let ((expt-2 (make-array N))
        (parent (make-array N :initial-element nil))
        (subtree-size (make-array N :initial-element nil))
        (sum-expt-2-subtree 0))
    ; 1, 2, 4, 8, ..., 2^(N - 1) をexpt-2に保存
    (loop for i below N for e = 1 then (mod (* e 2) *modulus*)
          do (setf (aref expt-2 i) e))
    (labels
      ((dfs (stack)
         (when stack
           (let* ((v (pop stack))
                  (p (aref parent v)) ; vの親
                  (size (aref subtree-size v))) ; vを根とする部分木の頂点数
             (if (aref subtree-size v)
               ; 帰りがけ
               (when p
                 (incf sum-expt-2-subtree (1- (aref expt-2 size)))
                 (incf sum-expt-2-subtree (1- (aref expt-2 (- N size))))
                 (incf (aref subtree-size p) size))
               ; 行きがけ
               (loop
                 initially (push v stack) ; 帰りがけ用に残す
                           (setf (aref subtree-size v) 1)
                 for next in (aref tree v) ; vの隣接頂点
                 unless (eql next (aref parent v)) ; 親以外
                   do (push next stack)
                      (setf (aref parent next) v))))
           (dfs stack))))
      ; sum-expt-2-subtree (2^(部分木の頂点数) - 1の総和) を計算
      (dfs (list 0))

      (loop repeat (1+ N)
            for e = (+ (* N (1- (aref expt-2 (1- N))))
                       (- *modulus* (mod sum-expt-2-subtree *modulus*)))
                then (mod (* e *2-inv*) *modulus*)
            finally (return e)))))

(defun read-tree (N)
  "N頂点の木をreadして作る. 頂点番号は0〜N-1"
  (let ((tree (make-array N))) ; 隣接リスト
    (loop for i below N do (setf (aref tree i) nil))
    (loop repeat (1- N)
      do (let ((a (read-fixnum))
               (b (read-fixnum)))
           (push (1- b) (aref tree (1- a)))
           (push (1- a) (aref tree (1- b)))))
    tree))

(defun read-fixnum (&optional (in *standard-input*))
  "readより速い非負整数専用read (整数間に空白または改行1個に限る)
   cf. https://qiita.com/sansaqua/items/0b6417cb541047e29da4"
  (loop with acc = 0
        for byte = (read-byte in)
        if (<= 48 byte 57)
          do (setf acc (+ (* acc 10) (- byte 48)))
        else return acc))

(main)


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

int main() {
  string str;
  cin >> str;
  for (int i = 0; i < str.size(); i++) {
    if (str.at(i) == '1') {
      cout << '9'; 
    }
    else {
     cout << '1';
    }
  }
}


Measured memory_bytes: 256
// Problem : F - Simplified Reversi
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)
#define int long long

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
    T f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 1;

int n, q;
int ans;
int h[N], l[N];
int maxh, maxl;

signed main()
{
    //File("");
    n = gi <int> (), q = gi <int> ();
    ans = (n - 2) * (n - 2);
    for (int i = 1; i < n; i+=1) h[i] = l[i] = n;
    maxh = maxl = n;
    while (q--)
    {
    	int op = gi <int> (), x = gi <int> ();
    	if (op == 1)
    	{
    		if (x < maxh)
    		{
    			for (int i = x; i <= maxh; i+=1) l[i] = maxl;
    			maxh = x;
    		}
    		ans -= l[x] - 2;
    	}
    	else
    	{
    		if (x < maxl)
    		{
    			for (int i = x; i <= maxl; i+=1) h[i] = maxh;
    			maxl = x;
    		}
    		ans -= h[x] - 2;
    	}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6644
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
const double EPS=1E-8;
typedef vector<double> vec;
typedef vector<vec> mat;
vec gauss_jordan(const mat& A,const vec& b){
  int n=A.size();
  mat B(n,vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      B[i][j]=A[i][j];
  for(int i=0;i<n;i++) B[i][n]=b[i];
  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i;j<n;j++) if(abs(B[j][i])>abs(B[pivot][i])) pivot=j;
    swap(B[i],B[pivot]);
    if(abs(B[i][i])<EPS) return vec();
    for(int j=i+1;j<=n;j++) B[i][j]/=B[i][i];
    for(int j=0;j<n;j++){
      if(i!=j){
		for(int k=i+1;k<=n;k++) B[j][k]-=B[j][i]*B[i][k];
      }
    }
  }
  vec x(n);
  for(int i=0;i<n;i++) x[i]=B[i][n];
  return x;
}
main(){
	int d;
	while(cin>>d,d){
		double a[d+3];
		mat A(d+3,vec(d+2));
		for(int i=0;i<d+3;i++)cin>>a[i];
		for(int i=0;i<d+3;i++){
			for(int j=0;j<d+1;j++){
				A[i][j]=pow(1.0*i,j);
			}
		}
		double eps = 1e-5;
		for(int i=0;i<d+3;i++){
			for(int j=i+1;j<d+3;j++){
				int cnt=0;
				vec ans(d+1);
				mat B(d+1,vec(d+1));
				for(int k=0,l=0;k<d+3;k++){
					if(k!=i&&k!=j){
						B[cnt]   = A[k];
						ans[cnt] = a[k];
						cnt++;
					}
				}
				vec v=gauss_jordan(B,ans);
				//cout<<v.size()<<endl;
				double res[2]={};
				for(int k=0;k<d+1;k++){
					res[0] += v[k]*A[i][k];
					res[1] += v[k]*A[j][k];
				}
				if(abs(res[0]-a[i])>eps&&abs(res[1]-a[j])<eps){
					cout<<i<<endl;
					goto L;
				}
				if(abs(res[1]-a[j])>eps&&abs(res[0]-a[i])<eps){
					cout<<j<<endl;
					goto L;
				}
			}
		}L:;
	}
}


Measured memory_bytes: 3180
#include<stdio.h>
#include<string.h>
#define N 1000000
#define LEN 14
#define NTL (-1)

char H[N][LEN];

int getChar(char ch){
  if(ch=='A')return 1;
  else if(ch=='C') return 2;
  else if(ch=='G')return 3;
  else if(ch=='T')return 4;
  else return 0;
}


long long getKey(char str[]){
  long long sum=0,a=1,i;
  for(i=0;i<strlen(str);i++){
    sum+=a*(getChar(str[i]));
    a*=5;
  }
  return sum;
}


int h1(int key){return key%N;}
int h2(int key){return 1+(key%(N-1));}

int find(char str[]){
  long long key,i,r;
  key=getKey(str);
  for(i=0; ;i++){
    r=(h1(key)+i*h2(key))%N;
    if(strcmp(H[r],str)==0)return 1;
    else if(strlen(H[r])== 0)return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%N;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i,n,h;
  char str[LEN],com[9];

  for(i=0;i<N;i++)H[i][0]='\0';
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%s %s", com, str);
    if(com[0]=='i') insert(str);
    else {
      if(find(str)){
	printf("yes\n");
      }
      else {
	printf("no\n");
      }
    }
  }
  return 0;
}
  



Measured memory_bytes: 15464
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
const int  mod = 1000000007;
struct mint{
    ll x;
    mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
    mint& operator+=(const mint a){//operatorは構造体同士の比較に用いられる
        if((x +=a.x)>=mod) x-=mod;
        return *this;//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){
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a){
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a){
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const{
        if(!t) return 1;
        mint a=pow(t>>1);
        a*=a;
        if(t&1) a*=*this;
        return a;
    }
    mint inv() const{
        return pow(mod-2);//逆元
    }
    mint&operator/=(const mint a) {
        return (*this)*=a.inv();
    }
    mint&operator/(const mint a) const{
    mint res(*this);
    return res/=a;
    }
};

int main(void){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i, n) cin>>v[i];
    vector<int> kind(n);
    mint ans = 1;
    kind[0] = 3;
    rep(i, n){
        int now = kind[v[i]];
        kind[v[i]]--;
        kind[v[i]+1]++;
        ans *= (ll)now;
    }
    cout<<ans.x<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define P pair<int,int>
#define PP pair<P,int>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int n,m;
    cin>>n>>m;
    vi vec(n);
    REP(i,n)cin>>vec[i];
    vi ma(n);
    ma[n-1]=vec[n-1];
    REPR(i,n-2){
        ma[i]=max(ma[i+1],vec[i]);
    }
    vi di(n);
    int k=0;
    REP(i,n){
        di[i]=ma[i]-vec[i];
        k=max(k,di[i]);
    }
    int ans=0;
    REP(i,n){
        if(di[i]==k){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
import java.math.BigDecimal;
import java.util.Scanner;

public class Main{
	public Main(){
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			BigDecimal bd = new BigDecimal("1");
			for(int i = sc.nextInt(); i > 1; i--){
				BigDecimal tmp = new BigDecimal(String.valueOf(i));
				bd = bd.multiply(tmp);
			}
			System.out.println(bd);
		}
	}
	
	public static void main(String[] args){
		Main test = new Main();
	}
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w)), b(h, vector<int>(w)), d(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a.at(i).at(j);
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> b.at(i).at(j);
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      d.at(i).at(j) = abs(a.at(i).at(j) - b.at(i).at(j));
    }
  }
  const int offset = 80 * 80;
  vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(160 * 80)));
  dp.at(0).at(0).at(offset + d.at(0).at(0)) = true;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < offset * 2; k++) {
        if (i > 0) {
          if (k >= d.at(i).at(j) && dp.at(i - 1).at(j).at(k - d.at(i).at(j))) {
            dp.at(i).at(j).at(k) = true;
            continue;
          }
          if (k + d.at(i).at(j) < offset * 2 && dp.at(i - 1).at(j).at(k + d.at(i).at(j))) {
            dp.at(i).at(j).at(k) = true;
            continue;
          }
        }
        if (j > 0) {
          if (k >= d.at(i).at(j) && dp.at(i).at(j - 1).at(k - d.at(i).at(j))) {
            dp.at(i).at(j).at(k) = true;
            continue;
          }
          if (k + d.at(i).at(j) < offset * 2 && dp.at(i).at(j - 1).at(k + d.at(i).at(j))) {
            dp.at(i).at(j).at(k) = true;
          }
        }
      }
    }
  }
  int ans = 1000000;
  for (int i = 0; i < offset * 2; i++) {
    if (dp.at(h - 1).at(w - 1).at(i)) ans = min(ans, abs(i - offset));
  }
  cout << ans << endl;
}


Measured memory_bytes: 12800
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }


char board[52][52];
int dx[] = { -1, 0,   1, -1, 1, -1, 0, 1 };
int dy[] = { -1, -1, -1,  0, 0,  1, 1, 1 };

int main() {
	int H, W;
	int i, j, k, l, num;
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; i++) {
		scanf("%s", board[i]);
	}
	//for (int i = 0; i < H; i++) {
	//	printf("%s\n", board[i]);
	//}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			num = 0;
			if (board[i][j] == '#') {
				continue;
			}
			else {
				for (int k = 0; k < 8; k++) {
					if (i + dx[k] < 0 || j + dy[k] < 0 || i + dx[k] >= H || j + dy[k] >= W) {
						continue;
					}
					else if (board[i + dx[k]][j + dy[k]] == '#') {
						num++;
					}
				}
			}
			board[i][j] = '0' + num;
		}
	}


	for (int i = 0; i < H; i++) {
		printf("%s\n", board[i]);
	}

#ifdef DEBUGF
	getch();
#endif
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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; }

bool isPrimeNumber(int x){
    for(int i = 2; i <= x/2; i++){
        if ((x % i) == 0) return false;
    }
    return true;
}

int main(){
    int x;
    cin >> x;
    while(true){
        if (isPrimeNumber(x))break;
        x++;
    }
    cout << x << endl;
}

Measured memory_bytes: 256
k,n = list(map(int, input().split()))
a = list(map(int, input().split()))
"""
ans = max(a) - min(a)
for i, num in enumerate(a):
    if num>(k/2):
        a[i] = num - k

print(min(ans,max(a) - min(a)))

min
abs(ai-bi)
abs(ai-(bi-k))
"""
def saitan(num1,num2,k):
    return min(abs(num1 - num2), abs(num1-(num2-k)))

bb = saitan(a[0], a[n-1], k)
for i in range(1,n):
    bb = max(bb, saitan(a[i], a[i-1], k))

print(k-bb)

Measured memory_bytes: 25840
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);

    int color[3] = {-1, -1, -1};
    long long ans = 1;

    for (int i = 0; i < N; i++) {
        int count = 0;
        for (int j = 0; j < 3; j++) {
            if (color[j] + 1 == A[i]) count++;
        }
        ans = ans * count % MOD;
        int c = 0;
        while (c < 3) {
            if (color[c] + 1 == A[i]) {
                color[c]++;
                c = 3;
            }
            c++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<tll,vector<tll>,greater<tll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  if(n%2==0){
    vvll dp(n+1,vll(2,-INF));
    dp[1][0]=a[0];
    dp[2][1]=a[1];
    rep(i,n)rep(j,2){
      if(dp[i][j]==-INF) continue;
      if(i+2<n+1){
        chmax(dp[i+2][j],dp[i][j]+a[i+1]);
      }
      if(j==0&&i+3<n+1){
        chmax(dp[i+3][j+1],dp[i][j]+a[i+2]);
      }
    }
    ll ans=max(dp[n-1][0],dp[n][1]);
    COUT(ans);
  }
  else{
    vvll dp(n+1,vll(3,-INF));
    dp[1][0]=a[0];
    dp[2][1]=a[1];
    dp[3][2]=a[2];
    rep(i,n)rep(j,3){
      if(dp[i][j]==-INF) continue;
      if(i+2<n+1){
        chmax(dp[i+2][j],dp[i][j]+a[i+1]);
      }
      if(j==0){
        if(i+3<n+1){
          chmax(dp[i+3][j+1],dp[i][j]+a[i+2]);
        }
        if(i+4<n+1){
          chmax(dp[i+4][j+2],dp[i][j]+a[i+3]);
        }
      }
      if(j==1){
        if(i+3<n+1){
          chmax(dp[i+3][j+1],dp[i][j]+a[i+2]);
        }
      }
    }
    ll ans=max(max(dp[n-2][0],dp[n-1][1]),dp[n][2]);
    COUT(ans);
  }
}


Measured memory_bytes: 15580
N,Y=map(int,input().split())
ans=[-1,-1,-1]
for i in range(N+1):
    for j in range(N-i+1):
        k=N-i-j
        if 10000*i+5000*j+1000*k==Y:
            ans=[i,j,k]
            break
print(ans[0],ans[1],ans[2])

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

// #define DEBUG

void printarray(int n, int a[], int target)
{
    for (int i = 0; i < n; i++)
    {
        if (i == target)
            cout << "[" << a[i] << "]";
        else
            cout << a[i];
        if (i != n - 1)
            cout << " ";
    }
    cout << endl;
}

int paritition(int a[], int left, int right, int n)
{
    int x = a[right];
    int y = a[right];
    int i = left - 1;
    for (int j = left; j < right; j++)
    {
        if (a[j] <= x)
        {
            i++;
            swap(a[i], a[j]);
        }
    }
    swap(a[i + 1], a[right]);
    return i + 1;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int target = paritition(a, 0, n - 1, n);
    printarray(n, a, target);

    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3484
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int A;
    int B;
    int C;
    int K;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = sc.nextInt();
        this.B = sc.nextInt();
        this.C = sc.nextInt();
        this.K = sc.nextInt();
    }
    
    private boolean solve() {
    	boolean judge = false;
    	
    	for (int i=1; i<=K; i++) {
    		if (A >= B) {
    			B = B * 2;
    		} else if (C <= B) {
    			C = C * 2;
    		}
    	}
    	
    	if (A < B && B < C) {
    		judge = true;
    	}
        
        return judge;
    }
    
    //出力
    public void show(boolean answer) {
    	if (answer) {
    		System.out.println("Yes");
    	} else {
    		System.out.println("No");
    	}
        
    }

}


Measured memory_bytes: 35368
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
    int k,s;
    cin >> k >> s;
    int cc = 0;
    rep(i, k+1)
    {
        rep(j,k+1){
            int z = s - i - j;
            if(z>=0 && z<=k){
                cc++;
            }
        }
    }
    cout << cc << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int count = 1;
        int sum = 0;
        
        while (n-- > 0) {
            int num = sc.nextInt();
            sum += num;
            if (sum <= x) {
                count++;
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 23764