akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan Mishra
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CStep solver = new CStep();
        solver.solve(1, in, out);
        out.close();
    }

    static class CStep {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            int[] a = new int[n];

            for (int i = 0; i < n; i++)
                a[i] = in.readInt();

            int[] dp = new int[n];
            dp[0] = a[0];

            for (int i = 1; i < n; i++)
                dp[i] = Math.max(a[i], dp[i - 1]);

//        System.out.println(Arrays.toString(dp));

            long ans = 0;
            for (int i = 0; i < n; i++)
                ans += Math.abs(dp[i] - a[i]);

            System.out.println(ans);

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 35508
n,d = map(int,input().split())
l=[]
for _ in range(n):
    x,y=map(int,input().split())
    l.append(((x**2)+(y**2))**(0.5))
l.sort()
c=0
for i in l:
    if i>d:
        break
    else:
        c+=1
print(c)

Measured memory_bytes: 90160
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
struct ModCombination {
    int Size;
    ll Mod;
    vl fact;
    vl inv_fact;

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

    ll inv(ll num) {
        return pow(num, Mod - 2);
    }

    void init(const int SIZE, const int MOD){
        Size = SIZE;
        Mod = MOD;

        fact = vl(Size);
        fact[0] = 1;
        FOR (i,1,Size) {
            fact[i] = fact[i - 1] * i % Mod;
        }

        inv_fact = vl(Size);
        inv_fact[0] = 1;
        inv_fact[Size-1] = inv(fact[Size-1]);
        for (int i = Size - 1; i > 0; i--) {
            inv_fact[i - 1] = inv_fact[i] * i % Mod;
        }
    }

    ModCombination(){}

    ModCombination(const int SIZE, const int MOD) {
        init(Size, Mod);
    }

    ll C(ll n, ll r) {
        if (n < 0 || r < 0 || n < r) return 0;
        return fact[n] * inv_fact[r] % Mod * inv_fact[n - r] % Mod;
    }

    ll P(ll n, ll r) {
        if (n < 0 || r < 0 || n < r) return 0;
        return fact[n] * inv_fact[n - r] % Mod;
    }
};
#endif

const ll MOD = 1e9 + 7;
int N, K;
vvi es;
vb vis;
ll ans;
ModCombination mc;

void dfs(int x, int px) {
    if (px == -1) ans *= K * mc.P(K - 1, es[x].size());    
    else ans *= mc.P(K - 2, es[x].size() - 1);
    ans %= MOD;

    vis[x] = true;

    for(int nx : es[x]) {
        if (vis[nx] || nx==px) continue;

        dfs(nx, x);
    }
}

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

    cin >> N >> K;
    vi A(N - 1), B(N - 1);
    REP(i, N - 1) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    es = vvi(N);
    REP(i,N-1){
        es[A[i]].push_back(B[i]);
        es[B[i]].push_back(A[i]);
    }

    vis = vb(N, false);
    ans = 1;
    mc.init(K, MOD);
    dfs(0, -1);

    cout << ans << endl;

    return 0;
}

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

using namespace std;

const int MAXN = 1e7 + 10;

int n, T, k, m;

int a[MAXN], dp[MAXN];

string s, t;

const int MOD = 1e9 + 7;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    if (n == 2)
        return cout << abs(a[1] - a[0]), 0;

    dp[n - 1] = 0;
    dp[n - 2] = abs(a[n - 1] - a[n - 2]);
    for (int i = n - 3; i >= 0; i--)
        dp[i] = min(dp[i + 1] + abs(a[i] - a[i + 1]), dp[i + 2] + abs(a[i] - a[i + 2]));
    
    cout << dp[0] << endl;
}


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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i<n; i ++) cin >> a[i];
    int count = 0;
    for(int i = 0; i < n; i ++) {
        int minj = i;
        for(int j = i; j < n; j ++) {
            if(a[j] < a[minj]) minj = j;
        }
        if(i != minj) count ++;
        swap(a[i], a[minj]);
    }
    for(int i = 0; i < n; i ++) {
        if(i==n-1) cout << a[i] << endl;
        else cout << a[i] << " ";
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3084
def generator(x, a): # xの倍数でaより大きいもののうちの最小値
    if x >= a:
        y = x
    else:
        tmp = a // x + 1
        if a % x == 0:
            tmp -= 1
        y = x * tmp

    return y


def main():
    a, b, x = map(int, input().split())
    minimum = generator(x, a)

    if minimum > b:
        count = 0
    else:
        count = (b - minimum) // x + 1

    if a == 0:
        count += 1

    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9016
from collections import deque

N,M = map(int,input().split())

List = [ list(map(int,input().split())) for i in range(M)]

dict = { i:[] for i in range(1,N+1)}

for i in range(M):
  a = List[i][0]
  b = List[i][1]
  
  dict[a].append(b)
  dict[b].append(a)


kouho = deque([1])
sumi = [-1 for i in range(N+1)]

while len(kouho) > 0:
  a = kouho.popleft()
  sumi.append(a)

  for t in dict[a]:
    if sumi[t] != -1:
      continue
    else:
      kouho.append(t)
      sumi[t] = a
          
ck = 0

for i in range(2,N+1):
  if sumi[i] == -1:
    ck=1
    
if ck == 1:
  print("No")
else:
  print("Yes")
  
  for i in range(2,N+1):
    print(sumi[i])

Measured memory_bytes: 66044
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int N, L;
    cin >> N >> L;

    int b;
    int best = 1e9;
    int total = 0;
    for (int i=1; i<=N; ++i) {
        int t = L + i - 1;
        int a = abs(t);
        if (best > a) {
            best = a;
            b = t;
        }
        total += t;
    }
    print(total - b);
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val H, W = sc.nextInt
    val S = Array.fill(H)(sc.next)
    val left = Array.ofDim[Int](H, W)
    val right = Array.ofDim[Int](H, W)
    val up = Array.ofDim[Int](H, W)
    val down = Array.ofDim[Int](H, W)

    for (h <- 0 until H) {
      var count = 0
      for (w <- 0 until W) {
        if (S(h)(w) == '#') {
          count = 0
        } else {
          count += 1
        }
        left(h)(w) = count
      }
    }

    for (h <- H - 1 to 0 by -1) {
      var count = 0
      for (w <- W - 1 to 0 by -1) {
        if (S(h)(w) == '#') {
          count = 0
        } else {
          count += 1
        }
        right(h)(w) = count
      }
    }

    for (w <- 0 until W) {
      var count = 0
      for (h <- 0 until H) {
        if (S(h)(w) == '#') {
          count = 0
        } else {
          count += 1
        }
        down(h)(w) = count
      }
    }

    for (w <- W - 1 to 0 by -1) {
      var count = 0
      for (h <- H - 1 to 0 by -1) {
        if (S(h)(w) == '#') {
          count = 0
        } else {
          count += 1
        }
        up(h)(w) = count
      }
    }

    var result = 0
    for (h <- 0 until H) {
      for (w <- 0 until W) {
        val light = left(h)(w) + right(h)(w) + up(h)(w) + down(h)(w) - 3
        if (result < light) {
          result = light
        }
      }
    }
    println(result)
  }
}

Measured memory_bytes: 124484
import sys
import math
n,m = map(int, sys.stdin.readline().split())

def combinations_count(n, r):
    if n-r < 0: return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

print(combinations_count(n, 2)+combinations_count(m,2))


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


ll gcd(ll a, ll b)
{
	ll c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int main() {
	ll K;
	cin >> K;

	cout << K / 2 * ((K + 1) / 2);
	cin >> K;
	return 0;



}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<cmath>
#include<cstdlib>
#define int long long
using namespace std;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	int A = 0;
	int B = 0;
	for(int i = 0;i < N;i++) {
		if(vec.at(i) % 2 == 0) {
			A++;
		}
		else {
			B++;
		}
	}
	if(B % 2 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 1024
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto A = RDR.ARR;
	auto B = new long[](N+1);
	foreach (i; 0..N)
	{
		B[i+1] = B[i] + A[i];
	}
	
	long[long] set;
	foreach (i; 0..N+1)
	{
		++set[B[i]];
	}

	long ans;
	foreach (i; 0..N+1)
	{
		ans += set[B[i]] - 1;
	}

	writeln(ans/2);
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 25228
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#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;
int main()
{
  int n,p; cin >> n >> p;
  string s;cin >> s;
  if(p==2||p==5){
    vector<vector<ll>> dp(n+1,vector<ll>(p,0));
    ll res = 0;
    rep(i,n){
      int c = s[i] - '0';
      dp[i+1][c%p]++;
      rep(j,p){
	if(j==0) res += dp[i][j];
	dp[i+1][(j*10+c)%p] += dp[i][j];
      }
    }
    cout << res+dp[n][0] << "\n";
  }
  else{
    ll x = 1;
    map<ll,ll> mp;
    ll sum = 0;
    mp[0]++;
    for(int i=n-1;i>=0;i--){
      ll c = s[i] - '0';
      sum = (sum+(c*x)%p)%p;
      mp[sum]++;
      x = (x*10)%p;
    }
    ll res = 0;
    for(auto m:mp){
      res += (m.second-1)*m.second/2;
    }
    cout << res << "\n";
  }
  return 0;
}


Measured memory_bytes: 14468
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var buffer = Console.ReadLine().Split();
            int num = 1;
            foreach (var v in buffer)
            {
                if (v == "0") Console.WriteLine(num);
                num++;
            }
        }
    }
}


Measured memory_bytes: 25820
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin >> a[i];

    sort(a.begin(), a.end());
    
    int maxx = 0;
    for(int x=a.front();x<=a.back();x++){
        auto lb = lower_bound(a.begin(), a.end(), x-1);
        auto ub = upper_bound(a.begin(), a.end(), x+1);
        int d = distance(lb, ub);
        maxx = max(maxx, d);
    }
    cout << maxx << endl;

    return 0;
}



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

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

int main() {
    int q, l, r;
    cin >> q;
    int a[100010] = {0};
    for(int i = 1; i < 100002; ++i) {
        if(is_prime(i) && (is_prime((i+1)/2))) a[i]++;
        a[i+1] += a[i];
        /*if(i < 20) {
            cout << i << " " << a[i] << '\n';
        }*/
    }
    for(int i = 0; i < q; ++i) {
        cin >> l >> r;
        cout << a[r] - a[l-1] << '\n';
    }

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 923372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;

int N;
VI G[1 << 18];
int V[1 << 18];
int W[1 << 18];
int dp[1 << 9][100010];

int solve(int now, int L) {
	if (now < (1 << 9)) return dp[now][L];
	
	int pa = (now + 1) / 2;
	pa--;
	int res = -INF;
	chmax(res, solve(pa, L));
	if (L - W[now] >= 0)chmax(res, solve(pa, L - W[now]) + V[now]);
	return res;
}


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

	cin >> N;
	
	REP(i, N) cin >> V[i] >> W[i];

	eREP(i, 100000)if (i >= W[0])dp[0][i] = V[0];
	FOR(i,1, min(N, 1 << 9)) {
		int pa = (i + 1) / 2;
		pa--;
		//cout << i << " " << pa << endl;
		eREP(j, 100000) {
			if (j != 0)chmax(dp[i][j], dp[i][j - 1]);
			if (j - W[i] >= 0 && i != 0) {		
				chmax(dp[i][j], dp[pa][j - W[i]] + V[i]);
			}
			if (i != 0)chmax(dp[i][j], dp[pa][j]);
		}
	}
	int Q; cin >> Q;
	while (Q--) {
		int v, L; cin >> v >> L;
		v--;
		cout << solve(v, L) << endl;

	}

	return 0;
}



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

int main(void){

  char S[4];
  scanf("%s", S);

  char tmp;

  int len = strlen(S);

  if(len == 3){
    tmp = S[0];
    S[0] = S[2];
    S[2] = tmp;
  }

  printf("%s\n", S);

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	while (true) {
		int n; cin >> n;
		if (n == 0)break;

		VI a(n);
		rep(i, n)cin >> a[i];
		SORT(a);
		int ans = INT_MAX;
		rep(i, n - 1) {
			int x = a[i + 1] - a[i];
			if (ans > x)ans = x;
		}
		cout << ans << endl;
	}
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll L,R;
ll mo=1000000007;
ll dp[2][2][2][63];

ll hoge(int d,int S,int LT,int RT) {
	if(d==-1) return S==1;
	if(dp[S][LT][RT][d]>=0) return dp[S][LT][RT][d];
	
	ll ret=0;
	
	int a,b;
	FOR(a,2) FOR(b,2) {
		if(a==0 && LT && (L&(1LL<<d))>0) continue;
		if(b==1 && RT && (R&(1LL<<d))==0) continue;
		if(a>b) continue;
		if(S==0 && a!=b) continue;
		int NLT=LT&&(((L>>d)&1)==a);
		int NRT=RT&&(((R>>d)&1)==b);
		int NS=S || (a==1 && b==1);
		ret+=hoge(d-1,NS,NLT,NRT);
	}
	
	return dp[S][LT][RT][d]=ret%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>L>>R;
	MINUS(dp);
	cout<<hoge(61,0,1,1)<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INTINF = 1<<30;
const int MOD = 1000000007;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    map<ll, ll> nums;
    ll sum = 0;
    nums[sum]++;
    for (int i = 0; i < n; ++i) {
        sum += a[i];
        nums[sum % m]++;
  }
  ll ans = 0;
  for (auto it = nums.begin(); it != nums.end(); ++it) {
    ans += it->second * (it->second - 1) / 2;
  }
  cout << ans << endl;
}

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

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rrep(i, a, b) for (int i = int(a) - 1; i >= b; i--)
#define sz(x) (int)(x).size()

using namespace std;
using ll = long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int a = 0, b = 0;
  for (int i = 0; i < sz(s); i++) {
    if (s[i] == 'A') {
      a++;
    } else {
      b++;
    }
  }
  if (a * b == 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T &a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T &a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T a) { return 1ll * a * a; }
template <class T> void compress(T &a){
  sort(all(a)); a.resize(unique(all(a)) - a.begin());  
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const int INF = 1e9;
const int MOD = 1e9+7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

const int N = 3e3+1;
db p[N], dp[N][N];

int main()
{
  fastio;
  int n; cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i];
  dp[1][1] = p[1]; dp[1][0] = 1.00 - p[1];
  for (int i = 2; i <= n; i++){
    for (int j = 0; j <= i; j++){
      dp[i][j] += dp[i - 1][j] * (1.00 - p[i]);
      if (j > 0) dp[i][j] += dp[i - 1][j - 1] * p[i];
    }
  }
  db ans = 0;
  for (int i = 0; i <= n; i++) if (i > n - i) ans += dp[n][i];
  cout << fixed << setprecision(10) << ans;
  return 0;
}

Measured memory_bytes: 49880
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

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

  vector<int> v(n);
  for (auto &x : v) cin >> x;

  vector<int> dp(k + 1);
  dp[0] = 0;

  for (int i = 1; i <= k; ++i) {
    for (const auto &a : v) {
      if (i >= a and dp[i - a] == 0) {
        dp[i] = 1;
        break;
      }
    }
  }

  cout << (dp[k] ? "First" : "Second") << endl;

  return 0;
}


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

int main(){

    int n,t; cin>>n;
    t=n;
    int r=0;
    while(t){
        int d=t%10;
        r=r*10+d;
        t/=10;
    }

    if(r==n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,-1,1,-1,1}; 
const int mod = 1e9+7;
const ll N = 2e5+5;


void solve(){
	string s;
	cin>>s;
	int n=sz(s);
	vector<int>dp(n+1);
	dp[0]=1;
	for(int i=0;i<n;++i){
		if(!dp[i])continue;
		if(i+5<=n && s.substr(i,5)=="dream")dp[i+5]=1;
		if(i+7<=n && s.substr(i,7)=="dreamer")dp[i+7]=1;
		if(i+5<=n && s.substr(i,5)=="erase")dp[i+5]=1;
		if(i+6<=n && s.substr(i,6)=="eraser")dp[i+6]=1;
	}
	cout<<(dp[n]?"YES":"NO");
}

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

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

int main()
{
    int W, a, b;
    cin >> W >> a >> b;
    if (b < a)
        swap(a, b);
    if (b <= a + W)
        cout << 0 << endl;
    else
        cout << b - (a + W) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int sum=0;
		for(int i=0;i<3;i++){ 
			sum += scan.nextInt();
		}
		if(sum>=22) System.out.println("bust");
		else System.out.println("win");
	}
}

Measured memory_bytes: 25172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder.ABC
{
	class QuestionC
	{
		public static void Main(string[] args)
		{
			var nk = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
			var n = nk[0];
			var k = nk[1];

			var a = Console.ReadLine().Split(" ").Select(x => long.Parse(x)).ToArray();

			var temp = new List<long>();
			for(int i = 0; i < k; i++) {
				temp.Add(a[i]);
			}

			for (int i = k; i < n; i++){
				if(temp[i - k] < a[i]) {
					Console.WriteLine("Yes");
				} else {
					Console.WriteLine("No");
				}

				temp.Add(a[i]);
			}
		}
	}
}


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

int a[100005];
int rlt[105][105];
int main(){
	int h, w, n;
	cin >> h >> w >> n;
	for(int i = 0; i < n; i ++) cin >> a[i];
	int cur = 0, cnt = 0;
	for(int i = 0; i < h; i ++){
		if(i % 2 == 0){
			for(int j = 0; j < w; j ++){
				rlt[i][j] = cur;
				a[cur] --;
				if(a[cur] == 0) cur ++; 
			}
		}
		else {
			for(int j = w - 1; j  >= 0; j --){
				rlt[i][j] = cur;
				a[cur] --;
				if(a[cur] == 0) cur ++; 
			}
		}
	}
	for(int i = 0; i < h; i ++){
		for(int j = 0; j < w; j ++){
			cout << rlt[i][j] + 1 << " \n"[j == w - 1];
		}
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;

int main() {
  int N;
  cin>>N;
  vector<int>H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  int MIN=0;
  for(int i=0;i<N;i++){
   if(MIN<H[i]){H[i]--;MIN=H[i];}
   if(MIN>H[i]){cout<<"No"<<endl;return 0;}
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using ll = long long;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using ld = long double;
using ui = unsigned int;
using ull = unsigned long long;
using ui128 = __uint128_t;
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define lc ind<<1
#define rc ind<<1|1
const int MN = 1e5 + 2, LOG = 17, INF = 1e8;
char s[MN];
int main () { 
	scanf ("%s",s+1);
	int n = strlen(s+1);
	stack<char> st;
	st.push(s[1]);
	for (int i = 2; i < n; i++) {
		if (s[i+1] != st.top()) {
			while ((int)st.size() > 1 && s[i+1] != st.top()) st.pop();
		}
		else st.push(s[i]);
	}
	printf ((n - (int)st.size())&1 ? "Second\n" : "First\n");
    return 0;
}
//aga

//a c b


Measured memory_bytes: 3900
import sys

input = sys.stdin.readline


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

    ans = 0
    for i in range(N - 2):
        a = L[i]
        for j in range(i + 1, N - 1):
            b = L[j]
            for k in range(j + 1, N):
                c = L[k]
                if not ((a != b) and (b != c) and (c != a)): continue
                if not ((a + b > c) and (b + c > a) and (c + a > b)): continue
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9192
#include <iostream>
using namespace std;
int main()
{
	int l;
	int a;
	int b;
	int c;
	int d;
	cin >> l;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	int e = a / c;
	int f = b / d;
	int g;
	int h;
	if (e*c == a)
	{
		g = e;
	}
	else
	{
		g = e + 1;
	}
	if (f*d == b)
	{
		h = f;
	}
	else
	{
		h = f + 1;
	}
	if (g < f)
	{
		cout << l - h<< endl;
	}
	else
	{
		cout << l - g << endl;
	}


	return 0;
}

Measured memory_bytes: 1160
/* 
	بسم الله الرحمن الرحیم

	(; طلا یک جهانی
*/

#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 200 * 1000 + 5;
int dp[MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	for (int i = n - 1; ~i; i--)
		if (s[i] == 'A') {
			int j = i + 1;
			for (; j < n - 1 && s[j] == 'B' && s[j + 1] == 'C'; j += 2, dp[i]++);
			if (s[j] == 'A')
				dp[i] += dp[j];
		}
	long long ans = 0;
	for (int i = 0; i < n; i++)
		ans += dp[i];
	cout << ans;
}


Measured memory_bytes: 1300
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int a,b;
while(cin>>a>>b){
int sum=a+b;
int c=0;
for(;sum!=0;){
sum/=10;
c++;
}
cout << c << endl;
c=0;
}
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			cout << v[i][j] << "   ";
		}
		cout << endl;
	}
}




int main(){
	int N;
	cin >> N;
	vector<ll> a(N);
	const int NUM = 30;
	vector<bool> bin(30, 0);
	for(int i=0; i<N; i++){
		cin >> a[i];
		bitset<NUM> bit(a[i]);
		for(int i=0; i<NUM; i++){
			if(bit[i] == 1){
				if(bin[i] == true) bin[i] = false;
				else bin[i] = true;
			}
		

		}

	}


	for(int i=0; i<N; i++){
		vector<bool> vec = bin;
		bitset<NUM> bit(a[i]);
		for(int i=0; i<NUM; i++){
			if(bit[i] == 1){
				if(vec[i] == true) vec[i] = false;
				else vec[i] = true;
			}
		}
		ll ans = 0;
		for(int i=0; i<NUM; i++){
			if(vec[i]==true) ans += pow(2, i);
		}
		cout << ans << endl;

	}
	
	
	

	
}


Measured memory_bytes: 4936
import collections
S = input()
v = sorted(collections.Counter(S).values())

if len(S) == 1:
    print('YES')
    exit()

if len(S) == 2:
    if S[0] != S[1]:
        print('YES')
        exit()
    else:
        print('NO')
        exit()

if len(v) <= 2 or v[2]-v[1] > 1 or v[2]-v[0] > 1:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 39280
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
  b[i]=a[i]-(i+1)
b.sort()
if n%2==1:
  ans=b[(n-1)//2]
  an=0
  for i in range(n):
    an+=abs(a[i]-ans-i-1)
  print(an)
else:
  ans=(b[n//2]+b[n//2-1])//2
  an=0
  for i in range(n):
    an+=abs(a[i]-ans-i-1)
  print(an)


Measured memory_bytes: 26180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
#define enld endl
int main(){
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    c*=2;
    bool flag=(x>y)?true:false;
    if(a+b>=c){
        ll add=min(x,y)*c;
        add+=flag?abs(x-y)*a:abs(x-y)*b;
        ll comp=max(x,y)*c;
        if(add<comp)cout<<add<<endl;
        else cout<<comp<<endl;
    }
    else{
        cout<<x*a+y*b<<endl;
    }
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())


t = 0
while (a % 2 == 0 and b % 2 == 0 and c % 2 == 0):
    if a == b == c:
        t = -1
        break
    else:
        a, b, c = b // 2 + c // 2, a // 2 + c // 2, a // 2 + b // 2
        t += 1
print(t)

Measured memory_bytes: 38256
# # Educational DP Contest C
N = int(input())
abc = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * 3 for _ in range(N)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]

for i in range(1, N):
    dp[i][0] = max(dp[i-1][1] + abc[i][0], dp[i-1][2] + abc[i][0])
    dp[i][1] = max(dp[i-1][0] + abc[i][1], dp[i-1][2] + abc[i][1])
    dp[i][2] = max(dp[i-1][0] + abc[i][2], dp[i-1][1] + abc[i][2])

print(max(dp[N-1]))

Measured memory_bytes: 47368
M, K = map(int, input().split())

if K >= 2**M:
    print(-1)
elif M == 0:
    if K == 0:
        print(0,0)
    else:
        print(-1)
elif M == 1:
    if K >= 1:
        print(-1)
    else:
        print(0,0,1,1)
else:
    li = [i for i in range(2**M) if i != K]
    ans = li + [K] + list(reversed(li)) + [K]
    print(*ans)


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

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
typedef long long ll;
typedef pair<int,int> pii;

const int MOD=1000000007; //10^9+7

int main() {
    int ans;
    string s;
    cin>>s;
    if(s=="SUN"){
        ans=7;
    }else if(s=="MON"){
        ans=6;
    }else if(s=="TUE"){
        ans=5;
    }else if(s=="WED"){
        ans=4;
    }else if(s=="THU"){
        ans=3;
    }else if(s=="FRI"){
        ans=2;
    }else if(s=="SAT"){
        ans=1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n, m = gets.chomp.split(' ').map(&:to_i)
accept_finishes = Hash.new(false)
penalty_counts = Hash.new(0)
m.times do
  submit = gets.chomp.split(' ')
  next if accept_finishes[submit[0]]
  if submit[1] == 'AC'
    accept_finishes[submit[0]] = true
  else
    penalty_counts[submit[0]] += 1
  end
end

accept_count, penalty_count = 0, 0
(1..n).each do |i|
  key = i.to_s
  if accept_finishes[key]
    accept_count += 1
    penalty_count += penalty_counts[key]
  end
end
puts "#{accept_count} #{penalty_count}"

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

int main(){
  int N; string s; cin >> N >> s;
  int counter = 0, need_left = 0;
  for( int i = 0; i < N; i++ ){
    if( counter == 0 ){
      if( s[i] == ')' ) need_left++;
      else counter++;
    }
    else{
      if( s[i] == ')' ) counter--;
      else counter++;
    }
  }
  int x = count(s.begin(), s.end(), '(');
  int need_right = 2 * x + need_left - N;
  for( int i = 0; i < need_left; i++ ) cout << '(';
  cout << s;
  for( int i = 0; i < need_right; i++ ) cout << ')';
  cout << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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 (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,h;
    cin>>n>>h;
    Vec a(n);
    Vec b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    ll ans=0;
    sort(rALL(a));
    sort(rALL(b));
    ll mx = a[0];

    rep(i,n){
        if(b[i]>=mx){
            h -= b[i];
            ans ++;
        }
        if(h<=0){
            break;
        }
    }
    if(h>0){
        ans += (h+mx-1)/mx;
    }

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

//セグメント木
// ref:https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
template <typename Mnd>
struct segment_tree {
    int n;
    vector<Mnd> data;
    function<Mnd(Mnd, Mnd)> op;
    Mnd e;
    //サイズだけ指定して初期化
    segment_tree(int sz, function<Mnd(Mnd, Mnd)> f, Mnd a) {
        e = a;
        op = f;
        n = 1;
        while (n < sz) n *= 2;
        data.assign(n * 2, e);
    }
    // vectorで要素を指定して初期化
    segment_tree(vector<Mnd> v, function<Mnd(Mnd, Mnd)> f, Mnd a) {
        e = a;
        op = f;
        n = 1;
        while (n < (int)v.size()) n *= 2;
        data.assign(n * 2, e);
        for (int i = 0; i < (int)v.size(); i++) {
            *this[i] = v[i];
        }
    }
    //参照渡しなので代入とかcoutもできる
    Mnd& operator[](const int& k) {
        return data[k + n];
    }
    //木を構築 O(n)
    void build() {
        for (int i = n - 1; i > 0; i--) {
            data[i] = op(data[2 * i], data[2 * i + 1]);
        }
    }
    //更新しつつ木を再構築 O(log n)
    void update(int k, Mnd x) {
        *this[k] = x;
        k = (k + n) / 2;
        while (k > 0) {
            data[k] = f(data[2 * k], data[2 * k + 1]);
        }
    }
    //[a,b)でのクエリに答える　O(log n)
    Mnd query(int a, int b) const {
        Mnd l = e, r = e;
        for (a += n, b += n; a < b; a /= 2, b /= 2) {
            if (a % 2 == 1) l = op(l, data[a++]);
            if (b % 2 == 1) r = op(r, data[--b]);
        }
        return op(l, r);
    }
};

//最大公倍数の計算(ユークリッドの互除法)
long long int gcd(long long int a, long long int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    int n;
    cin >> n;
    segment_tree<int> seg(n, gcd, 0);
    for (int i = 0; i < n; i++) {
        cin >> seg[i];
    }
    seg.build();
    // i:抜くやつ
    int ans = 1;
    for (int i = 0; i < n; i++) {
        int left = seg.query(0, i);
        int right = seg.query(i + 1, n);
        ans = max((lint)ans, gcd(left, right));
    }
    cout << ans << endl;
}

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

int main() {
    long long num,k;
    long long tmp1, tmp2;
    long long Min = 0;

    cin >> num >> k;
    //vector<long long> vec(num,0);
    vector<long long> d(num,0);

    for(int i =0; i < num; i++) cin >> d.at(i);

    for(int i = 0; i < k; i++){
        vector<long long> vec(num+1,0);
        for(int j = 0; j < num; j++){
            tmp1 = max(Min,(j+1) - d.at(j)-1);
            tmp2 = min(num,(j+1) + d.at(j));

            vec.at(tmp1)++;
            vec.at(tmp2)--;
        }

        for(int j = 0; j < num; j++){
            vec.at(j+1) += vec.at(j);
        }
        vec.pop_back();

        if(d == vec) break;

        d = vec;
    }

    for(int i = 0; i < num; i++){
        cout << d.at(i) << " ";
    }
}

Measured memory_bytes: 6416
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = b;
		int sum = b;
		for(int i = 1; i < a; i++){
		    int cost = b + i;
		    sum += cost;
		    if(post(ans) > post(cost)){
		        ans = cost;
		    }
		}
		System.out.println(sum - ans);
	}
	
	public static int post(int a){
	    if(a < 0){
	        return -a;
	    }else{
	        return a;
	    }
	}
}

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

using namespace std;


using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  string S;
  cin >> S;
  for(int i = 0; i + 1 < S.size(); i += 2) {
    if(S[i] == 'h' && S[i + 1] == 'i') continue;
    cout << "No\n";
    return 0;
  }
  if(S.size() & 1) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
}

Measured memory_bytes: 256
n=int(input())
ans=[0]*(n+1)
for x in range(1,105):
  for y in range(1,105):
    for z in range(1,105):
      t=x*x+y*y+z*z+x*y+y*z+z*x
      if t<=n:
        ans[t]+=1
for i in range(1,n+1):
  print(ans[i])

Measured memory_bytes: 73708
#include<bits/stdc++.h>
namespace my_std{
	using namespace std;
	#define Rint register int
	#define FOR(i,a,b) for(register int i=(a);i<=(b);++i)
	#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
	#define GO(x,i,v) for(register int i=p[x].head,v;i;i=e[i].link)
	#define PII pair<int,int>
	#define MP make_pair
	typedef long long LL;
	typedef double DB;
	inline int read(){
		char c=getchar();int ans=0,f=1;
		while(c>'9'||c<'0'){ f^=(c=='-'); c=getchar(); }
		for(;c<='9'&&c>='0';c=getchar()) ans=ans*10+(c^48); return f?ans:-ans;
	}
	const int mod = 1e9 + 7;
	inline void inc(int &x,const int &y){ x+=y; if(x>=mod) x-=mod; }
	inline int ksm(int x,LL y){ int res=1; for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) res=1ll*res*x%mod; return res; }
	#define FILE(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
}
using namespace my_std;

int n,a[25],b[25],ans;

int main(){
	n=read();
	FOR(i,1,n) a[i] = read();
	FOR(i,1,n){
		b[i] = a[i] - read();
		if(b[i]>0) ans+=b[i];
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int c1, c5, c10, c50, c100, c500;
	int sum;
	
	scanf("%d %d %d %d %d %d", &c1, &c5, &c10, &c50, &c100, &c500);
	
	sum = c1 + (c5 * 5) + (c10 * 10) + (c50 * 50) + (c100 * 100)+ (c500 * 500);
	
	if (sum / 1000 > 0){
		printf("1\n");
	}
	else {
		printf("0\n");
	}
	
	return (0);
}

Measured memory_bytes: 584
#include <iostream>
#include <cmath>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


const int SIZE = 100000;
int N, A[SIZE];

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i];

  int m = 1;
  long cnt = 0;

  REP(i, 0, N) {
    if(A[i] > m) {
      cnt += (A[i] - 1) / m;
      A[i] = max(m - 1, 1);
    }
    if(A[i] == m) {
      m++;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 640
string=input()
q=int(input())
for i in range(q):
    lst=input().split()
    order=lst[0]
    if order=='reverse':
        a=int(lst[1])
        b=int(lst[2])
        extraction=''
        for l in range(a,b+1):
            letter=string[l]
            extraction+=letter
        oppose=extraction[::-1]
        lst=list(string)
        lst[a:b+1]=oppose
        string="".join(lst)
    if order=='replace':
        a=int(lst[1])
        b=int(lst[2])
        p=lst[3]
        move=p
        lst=list(string)
        lst[a:b+1]=move
        string="".join(lst)
    if order=='print':
        a=int(lst[1])
        b=int(lst[2])
        extraction=''
        for o in range(a,b+1):
            letter=string[o]
            extraction+=letter
        print(extraction)


Measured memory_bytes: 5628
#include <stdio.h>

int main(void) {
	int gTime;		/*目標時間*/
	int sCount;		/*勉強回数*/
	int time_FT[2];	/*n回目の勉強時間の範囲*/
	int sumT;		/*勉強時間の合計*/
	int i;			/*for文制御用*/
	
	for(;;) {
		sumT = 0;
		
		scanf("%d", &gTime);
		if(gTime == 0)		break;
		scanf("%d", &sCount);
		
		for(i = 0; i < sCount; i++) {
			scanf("%d %d", &time_FT[0], &time_FT[1]);
			sumT += ( time_FT[1] - time_FT[0] );
		}
		
		if(sumT >= gTime)
			puts("OK");
		else
			printf("%d\n", gTime - sumT);
	}
	return 0;
}

Measured memory_bytes: 612
a,b,k=map(int,input().split())

for i in range(k):
  if(i%2==0):
    if(a%2==1):
      a-=1
    b=b+a//2
    a=a//2
  else:
    if(b%2==1):
      b-=1
    a=a+b//2
    b=b//2

print(a,end=" ")
print(b)

Measured memory_bytes: 3060