akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Comparator;

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

    static class ERedAndGreenApples {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int x = in.nextInt();
            int y = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();

            int[] p = new int[a];
            int[] q = new int[b];
            int[] r = new int[c];

            for (int i = 0; i < a; i++) {
                p[i] = in.nextInt();
            }
            for (int i = 0; i < b; i++) {
                q[i] = in.nextInt();
            }
            for (int i = 0; i < c; i++) {
                r[i] = in.nextInt();
            }

            Arrays.sort(p);
            Arrays.sort(q);
            Arrays.sort(r);
            PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder());
            for (int i = 0; i < x; i++) {
                pq.add(p[p.length - 1 - i]);
            }
            for (int i = 0; i < y; i++) {
                pq.add(q[q.length - 1 - i]);
            }
            for (int i = 0; i < c; i++) {
                pq.add(r[i]);
            }

            long res = 0;
            for (int i = 0; i < x + y; i++) res += pq.poll();

            out.println(res);
        }

    }
}



Measured memory_bytes: 93112
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;

  vector<P> vp;
  REP(i, n) {
    int t, d;
    cin >> t >> d;
    vp.push_back(P(d, t));
  }

  sort(vp.begin(), vp.end(), greater<P>());

  vector<bool> used(n + 1, false);
  priority_queue<int, vector<int>, greater<int>> que;

  ll kind = 0;
  ll sum = 0, ans = 0;
  REP(i, k) {
    sum += (ll)vp[i].first;
    if(!used[vp[i].second]) {
      used[vp[i].second] = true;
      kind++;
    } else {
      que.push(vp[i].first);
    }
  }

  ans = max(ans, kind * kind + sum);
  int j = k;

  while(!que.empty()) {
    sum -= que.top(); que.pop();
    while(j < n) {
      if(!used[vp[j].second]) {
        used[vp[j].second] = true;
        kind++;
        sum += (ll)vp[j].first;
        ans = max(ans, kind * kind + sum);
        break;
      }
      j++;
    }
    if(j >= n) break;
  }

  cout << ans << endl;
}


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

using namespace std;

typedef long long int llint;

llint K;
llint N, M;

int main() {
	cin >> N >> M >> K;
	vector<llint> A(N + 1);
	A[0] = 0;

	llint ans = 0;
	llint now = 0;
	llint a_num = 0;//Ａを何冊目まで読むか
	bool flag = false;//読むのを中止
	for (int i = 1; i < N + 1; i++) {
		cin >> A[i];
		if (now + A[i] <= K && !flag) {
			now += A[i];
			a_num++;
			//cout << "A" << a_num << " " << now << endl;
		}
		else {
			flag = true;
		}
	}
	ans = a_num;

	llint next = ans;
	for (int i = 0; i < M; i++) {
		llint B;
		cin >> B;
		now += B;
		if (now <= K) {
			next++;
		}
		//cout << "B" << next << " " << now << endl;
		if(now > K) {
			while (now > K && a_num > 0) {
				now -= A[a_num];
				a_num--;
				next--;
				//cout << "B" << next << " " << now << endl;
			}
			if (now <= K) { next++; }
		}

		ans = max(ans, next);
	}
	cout << ans << endl;
}


Measured memory_bytes: 4816
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
j = -1
for i in A:
    if i == j+1:
        ans += C[j-1]
    ans += B[i-1]
    j =  i
print(ans)

Measured memory_bytes: 38256
function Main(input) {
 const a = input.trim().split(' ').map(n=>parseInt(n));
 const result = Math.ceil(a[2]/a[1]) <= Math.ceil(a[0]/a[3]);
 console.log(result?'Yes':'No')
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29492
/*g++ main.cpp -o main.out*/
/*./main.out*/
/*std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);*/

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

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(n,a) memset(n,a,sizeof(n));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

int a[100005];

int main()
{
    int n;
    cin>>n;
    rep(i,n)cin>>a[i];
    int mx=0,tmp=0;
    rer(i,1,n-1)
    {
        if(a[i]>a[i-1])
        {
            mx=max(mx,tmp);
            tmp=0;
        }
        else if(a[i]<=a[i-1])
        {
            tmp++;
        }
    }
    mx=max(mx,tmp);
    cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 640
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n;
    R(n);
    VI a(n);
    REP(i,n)R(a[i]);
    sort(ALL(a));
    W(a[n/2]-a[n/2-1]);
    return 0;
}


Measured memory_bytes: 640
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    int k;
    cin >> k;
    ll res = 0;
    rep(a, 1, k+1)
        rep(b, 1, k+1)
            rep(c, 1, k+1)
            {
                int now = __gcd(a, b);
                res += __gcd(now, c);
            }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
	
}

int main()
{
	ll a,b,c;
	string S,T;
	cin>>a>>b>>c;
	if(c<=a)cout<<a-c<<" "<<b;
	else cout<<0<<" "<<(a+b-c>0?a+b-c:0);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

constexpr int64_t MOD = 1'000'000'007;
constexpr int     MAX =       200'005;

int64_t 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;
    }
}

// 二項係数計算
int64_t 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;
}

int main(void) {
    int64_t H, W, A, B;
    cin >> H >> W >> A >> B;
    COMinit();

    int64_t ans = 0;
    for(int i=0; i<H-A; i++) {
        ans += COM(B-1+i, i) * COM(H-i+W-B-2, W-B-1);
        ans %= MOD;
    }

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


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

using namespace std;

int main(void)
{
    string n;
    int i;
    
    cin >> n;

    for(i=0; i<=2; i++){
        if(n[i] == '1'){
            cout << 9;
        }
        else{
            cout << 1;
        }
    }
    cout << endl;

    return 0;
}

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

using namespace std;

int main(void){
    string s;
    int n;

    cin >> n >> s;
    /*
    int ren_cnt = 0;
    vector<int> ren_list(n,0);
    vector<int> ren_bwcnt(n,0);

    int black_cnt = 0;
    for(int i=1; i<s.length(); i++){
        if(s.at(i-1)=='#')
            black_cnt++;

        if(s.at(i-1)=='#' && s.at(i)=='.'){
            ans+=black_cnt;
            black_cnt = 0;
        }
        
        if(s.at(i-1) != s.at(i)){
            ren_list[ren_cnt]=i;
            ren_cnt++;
        }
    }

    if(ren_cnt >= 3){
        for(int i=0; i<ren_cnt; i++){
            if(i < 2)
                ren_bwcnt[i] = ren_list[i]-(i>=1)?ren_list[i-1]:0;
            else
                ren_bwcnt[i] = ren_list[i]-ren_list[i-1]+ren_bwcnt[i-2];
        }
        
        int bk_cnt, w_cnt;
        bool first_bk = (s[0] == '#');
        if(s.back() == '#'){
            bk_cnt = ren_bwcnt[ren_cnt-1];
            w_cnt  = ren_bwcnt[ren_cnt-2];
        }else{
            w_cnt  = ren_bwcnt[ren_cnt-1];
            bk_cnt = ren_bwcnt[ren_cnt-2];
        }
        int min_chg = bk_cnt+w_cnt;
        for(int i=1; i<ren_cnt-1; i++){
            int b,w;
            if(first_bk){
                w=ren_bwcnt[i];
                b=ren_bwcnt[i-1];
            }
        }
    }

    if(ans > s.length()/2){
        if(s.back() == '#'){
            if(ren_cnt >= 2){
                ans = s.length() - ans - (ren_list[ren_cnt-1] - ren_list[ren_cnt-2]);
            }else{
                ans = s.length() - ans;
            }
        }else{
            ans = s.length() - ans;
        }
    }
    */

   int b_cnt, w_cnt;
   b_cnt = w_cnt = 0;
    vector<int> b_list(n+1,0);
    vector<int> w_list(n+1,0);

    for(int i=0; i<s.length(); i++){
        if(s[i] == '#'){
            b_cnt++;
        }else if(s[i] == '.'){
            w_cnt++;
        }
        b_list[i+1] = b_cnt;
        w_list[i+1] = w_cnt;
    }
    
    int min_rev = n;
    for(int l=0; l<=s.length(); l++){
        int rev = b_list[l] + (w_cnt - w_list[l]);
        min_rev = min(min_rev, rev);
    }

    if(n/2 < min_rev){
        min_rev = n-min_rev;
    }


    cout << min_rev << endl;
}

Measured memory_bytes: 2172
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    nw = -1
    ret = 0
    for i, a in enumerate(A):
        if i<a or nw+1<a:
            print(-1)
            exit()
        elif i == 0:
            nw = 0
            continue
        elif nw+1==a:
            nw += 1
            continue
        else:
            ret += nw
            nw = a
    ret += a
#            print(i,ret)
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 16948
n, m, x, y = map(int, input().split())
xs = sorted(list(map(int, input().split())))
ys = sorted(list(map(int, input().split())))

for z in range(-114, 114):
    if x < z <= y and xs[n - 1] < z <= ys[0]:
        print("No ", end = "")
        break

print("War")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MOD 998244353
using namespace std;

#define rep(i, a, b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= int(b); --i)
#define trav(it, v) for(auto &it : (v))
#define all(v) (v).begin(), (v).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define sz(x) (int)(x).size()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

ll dp[4005][4005];
ll sum[2005];

int main(){
	ios::sync_with_stdio(0);
    int N;
    string S;
    cin >> S;
    N = sz(S);
    rep(i,0,N) {
        sum[i+1] = sum[i] + (S[i] - '0');
    }
    dp[0][0] = 1;
    rep(i,0,2*N) {
        rep(j,0,2*N+1) {
            if (j > i)
                continue;
            if (i < N && j > sum[i])
                continue;
            if (i < N && i-j > 2*i-sum[i])
                continue;
            dp[i][j] %= MOD;
            dp[i+1][j] += dp[i][j];
            dp[i+1][j+1] += dp[i][j];
        }
    }
    dp[2*N][sum[N]] %= MOD;
    cout << dp[2*N][sum[N]] << endl;
}

Measured memory_bytes: 123776
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        for(int i = 1;i <= 10000;i++){
            int x = sc.nextInt();
            System.out.println("Case" + " " + i + ":" + " " + x);
            if(x == 0){
                break;
            }
        }
    }
}


Measured memory_bytes: 41572
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int a[5], k;
    for(int i = 0; i < 5; ++i)
        cin >> a[i];
    cin >> k;
    bool ok = true;
    for(int i = 0; i < 5; ++i) 
        for(int j = 0; j < i; ++j) 
            ok &= abs(a[j] - a[i]) <= k;
    cout << (ok ? "Yay!" : ":(") << endl;
}

Measured memory_bytes: 256
import java.text.*
fun main(a: Array<String>) {
  val v = readLine()!!.toDouble()
  println(DecimalFormat("#################").format((2.0.pow(floor(log2(v) + 1)) - 1)))
}

fun log2(d: Double) = Math.log(d)/Math.log(2.0)
fun Double.pow(a: Double) = Math.pow(this, a)
fun floor(d: Double) = Math.floor(d)

Measured memory_bytes: 31768
n = int(input())
x = list(map(int, input().split()))

l = min(x)
r = max(x)

ans = 10000000000

for i in range(l, r+1):
    ansi = 0
    for a in x:
        ansi += abs(a - i) ** 2
    ans = min(ans, ansi)

print(ans)



Measured memory_bytes: 3060
n = int(input())
a = (11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381, 1451)
[print(i,end = " ") for i in a[:n-1]]
print(a[n-1])

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<list>

using namespace std;

int main()
{
	int n, a[100001], c[100001] = {0}, d = 0,ans;

	cin >> n;
	
	ans = n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		c[a[i]]++;
		
	}

	for (int i = 0; i < 100000; i++)
	{
		if(c[i] > 1) d += (c[i] - 1);
	}
	if (d % 2 == 0) ans -= d;
	else ans -= (d + 1);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
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; }

void solve()
{
    ll n, a, b; cin >> n >> a >> b;
    ll cnt = n / (a + b);
    n -= (a + b) * cnt;
    ll ans = a * cnt;
    assert(n >= 0);
    if(n <= a)
    {
        ans += n;
    }
    else
    {
        ans += a;
    }
    
    cout << ans << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define ll long long
//#define file
using namespace std;

int d[250001],n,i,j,k,l,l1,l2,x,y,t;
ll a[501][501],mx,s;
map<ll,bool> mp;
bool bz[1000001];

ll gcd(ll x,ll y) {ll r=x%y; while (r) x=y,y=r,r=x%y; return y;}
ll lcm(ll x,ll y) {ll s=gcd(x,y);return (x/s)*(y/s)*s;}

int main()
{
	#ifdef file
	freopen("agc027d.in","r",stdin);
	freopen("agc027d.out","w",stdout);
	#endif
	
	scanf("%d",&n),s=((n+1)/2)*((n+1)/2);
	i=2;
	while (t<s)
	{
		if (!bz[i] && !bz[i*2]) d[++t]=i,bz[i]=bz[i*2]=1;
		++i;
	}
	l1=0,l2=t+1;
	fo(i,1,n)
	{
		fo(j,1,n)
		if ((i&1) && (j&1))
		{
			if (((i+j)/2)&1)
			{
				++l1;
				a[i][j]=d[l1];
				if (i<n && j<n)
				a[i+1][j+1]=d[l1]*2;
			}
			else
			{
				--l2;
				a[i][j]=d[l2];
				if (i<n && j<n)
				a[i+1][j+1]=d[l2]*2;
			}
		}
	}
	fo(i,1,n) fo(j,1,n) if (a[i][j]) mp[a[i][j]]=1;
	
	mx=0;
	fo(i,1,n)
	{
		fo(j,1,n)
		if (!a[i][j])
		{
			a[i][j]=1;
			if (i>1) a[i][j]=lcm(a[i][j],a[i-1][j]);
			if (i<n) a[i][j]=lcm(a[i][j],a[i+1][j]);
			if (j>1) a[i][j]=lcm(a[i][j],a[i][j-1]);
			if (j<n) a[i][j]=lcm(a[i][j],a[i][j+1]);
			
			s=a[i][j],++a[i][j];
			while (mp[a[i][j]]) a[i][j]+=s;
			mp[a[i][j]]=1;
			mx=max(mx,a[i][j]);
		}
	}
	fo(i,1,n)
	{
		fo(j,1,n)
		printf("%lld ",a[i][j]);
		printf("\n");
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

Measured memory_bytes: 21852
import java.util.Scanner;
public class Main { 
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
      	int N = reader.nextInt();
      	int[] prices = new int[N];
        prices[0] = reader.nextInt();
      	int max = 0;
      	for (int i = 1; i < N;i++) {
        	prices[i] = reader.nextInt();
          	if (prices[i] > prices[max]) {
            	max = i;
            }
        }
      prices[max] /= 2;
      int result = 0;
      for (int j = 0; j < N;j++) {
        result += prices[j];
        	
        } 
      System.out.print(result);
		
    }
}

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

int main(){

    ll n;
    cin >> n ;
    int ans=0;
    ll m = 100;
    while (m < n)
    {
        ans ++;
        m = m + m*0.01;
    }
    cout << ans << endl;
    
    return 0;
}





Measured memory_bytes: 3632
char*z,a[2][204];n,m,i,p;main(c){for(;m=scanf("%d %[^\n] %[^\n]",&n,a,a+1)*n;printf(m>n?"NA\n":"%d\n",m))for(i=2;i--;m=c)for(c=p=0;z=p+p+a[c+i&1],c<m&&*z>49|n+~p;)p+=p<n&*z<50?*z-49|z[2]-49?++c,2:1:-1;}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define foru(a,b,c) for(int a=b;a<=c;++a)
#define int long long
using namespace std;

int n,k,a[100100],b[100100],c[1000100];
int h[100100][3];

main()
{
    cin >> n;
    foru(i,1,n)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    foru(i,1,n)
    {
        foru(j,0,2)
        {
            foru(k,0,2)
            {
                if(k==j) continue;
                if(k==0)
                {
                    h[i][j]=max(h[i][j],h[i-1][k]+a[i]);
                }
                else if(k==1)
                {
                    h[i][j]=max(h[i][j],h[i-1][k]+b[i]);
                }
                else h[i][j]=max(h[i][j],h[i-1][k]+c[i]);
            }
        }
    }
    int kq=0;
    foru(i,0,2)
    {
        kq=max(kq,h[n][i]);
    }
    cout <<kq;
}

Measured memory_bytes: 7936
n = int(input())

dp = [10 ** 6] * (n+1)

dp[0] = 0

for i in range(n+1):
    for j in range(n):
        if i + 6 ** j > n:
            break
        dp[i + 6 ** j] = min(dp[i + 6 ** j], dp[i] + 1)
        if not i + 9 ** j > n:
            dp[i + 9 ** j] = min(dp[i + 9 ** j], dp[i] + 1)

print(dp[n])


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

int d[30][30];
int cm[500][500];

int solve(int n, int c) {
  vector<vector<int>> dest(3);
  for(int i=0;i<3;i++) {
    dest[i] = vector<int>(c, 0);
  }

  for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) {
      dest[(i+1 + j+1) % 3][cm[i][j]-1] += 1;
    }
  }
  int res = numeric_limits<int>::max();
  for(int i=0;i<c-2;i++) {
    for(int j=i+1;j<c-1;j++) {
      for(int k=j+1;k<c;k++) {
	int cost = 0;
	for(int l=0;l<c;l++) {
	  cost += dest[0][l] * d[l][i];
	  cost += dest[1][l] * d[l][j];
	  cost += dest[2][l] * d[l][k];
	}
	res = min(cost, res);

	cost = 0;
	for(int l=0;l<c;l++) {
	  cost += dest[0][l] * d[l][i];
	  cost += dest[1][l] * d[l][k];
	  cost += dest[2][l] * d[l][j];
	}
	res = min(cost, res);

	cost = 0;
	for(int l=0;l<c;l++) {
	  cost += dest[0][l] * d[l][j];
	  cost += dest[1][l] * d[l][k];
	  cost += dest[2][l] * d[l][i];
	}
	res = min(cost, res);

	cost = 0;
	for(int l=0;l<c;l++) {
	  cost += dest[0][l] * d[l][j];
	  cost += dest[1][l] * d[l][i];
	  cost += dest[2][l] * d[l][k];
	}
	res = min(cost, res);

	cost = 0;
	for(int l=0;l<c;l++) {
	  cost += dest[0][l] * d[l][k];
	  cost += dest[1][l] * d[l][i];
	  cost += dest[2][l] * d[l][j];
	}
	res = min(cost, res);

	cost = 0;
	for(int l=0;l<c;l++) {
	  cost += dest[0][l] * d[l][k];
	  cost += dest[1][l] * d[l][j];
	  cost += dest[2][l] * d[l][i];
	}
	res = min(cost, res);
      }
    }
  }

  return res;
}
int main() {
  int n, c;
  cin >> n >> c;
  for(int i=0;i<c;i++) {
    for(int j=0;j<c;j++) {
      cin >>  d[i][j];
    }
  }
  for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) {
      cin >> cm[i][j];
    }
  }
  cout << solve(n, c);
}

Measured memory_bytes: 4616
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int N;
vector<long long> a;

void solve() {
    map<long long, long long> ma;
    for (int i = 0; i < N; ++i) ma[a[i]]++;
    long long res = 0;
    for (auto it : ma) res += it.second * (it.second - 1) / 2;
    for (int i = 0; i < N; ++i) {
        long long val = ma[a[i]];
        long long before = val * (val - 1) / 2;
        long long after = (val - 1) * (val - 2) / 2;
        cout << res + after - before << endl;
    }
}

int main() {
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    solve();
}

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

int main(){
   int n,k;cin >> n >> k;
   int count=0;
   for(int i=1;i<=n;i+=2){
      count++;
   }
   if(count < k){
      cout << "NO";
   }else{
      cout << "YES";
   }
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const int INF = 1LL<<30;

int N,D[50];
int cnt[13],vis[24];

int count(){
    int mi=101010;
    rep(i,24){
        rep(j,24){
            if(vis[i] && vis[j] && i!=j){
                int d1=abs(i-j);
                int d2=24-d1;
                int d=min(d1,d2);
                mi=min(mi,d);
            }
        }
    }

    return mi;
}

int main() {
    cin>>N;
    rep(i,N) cin>>D[i];

    rep(i,N) cnt[D[i]]++;

    if(cnt[0]){
        cout<<0<<endl;
        return 0;
    }

    vis[0]=1;
    vector<int> v;
    for(int i=1;i<12;i++){
        if(cnt[i]==1) v.push_back(i);
        else if(cnt[i]==2) vis[i]=vis[24-i]=1;
        else if(2<cnt[i]){
            cout<<0<<endl;
            return 0;
        }
    }
    if(cnt[12]==1) vis[12]=1;
    else if(2<=cnt[12]){
        cout<<0<<endl;
        return 0;
    }

    int M=v.size();
    if(M==0){
        cout<<count()<<endl;
        return 0;
    }

    int ans=0;
    rep(msk,1<<M){
        rep(i,M){
            if(msk & (1<<i)) vis[v[i]]=1,vis[24-v[i]]=0;
            else vis[v[i]]=0,vis[24-v[i]]=1;
        }
        ans=max(ans,count());
    }

    cout<<ans<<endl;
}

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

using namespace std;

#define PROBLEM "D"
#define TESTC ""

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)
typedef pair<int, int> P;
#define F first
#define S second
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define LL long long

int main()
{
	#ifdef DBG
	freopen(PROBLEM TESTC ".in", "r", stdin);
	freopen(PROBLEM ".out", "w", stdout);
	#endif

	int n,m;
	while(cin >> n >> m)
	{
		priority_queue<int> pq;
		for(int i = 0,tmp ; i < n && cin >> tmp; i++)
			pq.push(tmp);
		for(int j = 0,tmp; j < m; j++)
			tmp = pq.top()/2,pq.pop(),pq.push(tmp);
		LL ans = 0;
		while(!pq.empty())
			ans += pq.top(),pq.pop(); 
		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define MN 100000
char a[MN+5],b[MN+5];
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int main()
{
	int n,m,i,g;long long ans;
	scanf("%d%d%s%s",&n,&m,a,b);
	g=gcd(n,m);ans=1LL*n*m/g;
	for(i=0;i<g;++i)if(a[i*n/g]!=b[i*m/g])break;
	printf("%lld",i<g?-1:ans);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N 500009
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
int main(void)
{
    //freopen("in.txt","r",stdin);

    double r,ans;
    cin>>r;
    ans=2*PI*r;
    cout<<ans<<endl;

    //main();
    return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <map>
#include <climits>
#include <bitset>

#define ll long long
const ll INF = 1 << 29;
const ll MOD = 1e9 + 7;

int main()
{
    int N;
    ll Z, W;
    std::cin >> N >> Z >> W;

    std::vector<ll> A(N);
    for (auto i=0; i<N; ++i)
        std::cin >> A[i];

    if (N == 1)
        std::cout << std::abs(A[N-1] - W) << std::endl;
    else
        std::cout << std::max(std::abs(A[N-1] - W), std::abs(A[N-2] - A[N - 1])) << std::endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    double l;cin>>l;
    double r=l/3;
    double v=r*r*r;
    cout<<fixed<<setprecision(12)<<v<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
 
int calcScore(vector<int> &plan, vector<int> &c, vector<vector<int>> &s) {
	int D = 365;
	int score = 0;
	vector<int> last(26, -1);
	for (int i = 0; i < D; i++) {
		score += s[i][plan[i]];
		last[plan[i]] = i;
		for (int j = 0; j < 26; j++) {
			score -= c[j] * (i - last[j]);
		}
	}
	return score;
}
 
int main() {
	int D;
	cin >> D;
	vector<int> c(26);
	for (int i = 0; i < 26; i++)cin >> c[i];
	vector<vector<int>> s(365,vector<int>(26,0));
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++)cin >> s[i][j];
	}
	
	vector<int> plan(365, 0);
	for (int i = 0; i < 365; i++) {
		plan[i] = i % 26;
	}
	int sc = calcScore(plan, c, s);
 
	for (int n = 0; n < 300000; n++) {
		if (rand() % 10 < 3) {
			int i = rand() % 365, j = rand() % 26, old = plan[i];
			plan[i] = j;
			int nsc = calcScore(plan, c, s);
			if (nsc > sc) {
				sc = nsc;
			}
			else {
				plan[i] = old;
			}
		}
		else {
			int k = rand() % 5;
			int i = rand() % (365 - k), j = i + k;
			swap(plan[i], plan[j]);
			int nsc = calcScore(plan, c, s);
			if (nsc > sc) {
				sc = nsc;
			}
			else {
				swap(plan[i], plan[j]);
			}
		}
	}
 
	for (int i = 0; i < 365; i++) {
		cout << plan[i] + 1 << endl;
	}
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int M;
    cin >> M;
    cout << 48-M << endl;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	map<int, int> mp;
	int ans = 1;
	for(int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		if(mp.count(x)) {
			ans = 0;
		}
		mp[x] = 1;
	}
	if(ans) {
		cout << "YES" << '\n';
	} else {
		cout << "NO" << '\n';
	}
	return 0;
}


Measured memory_bytes: 10296
#define lp(i,n) for(int i=0;i<n;i++)
#define pau system("pause")
#include<bits/stdc++.h>

using namespace std;
int main() {
  char b;
  cin>>b;
  if(b=='A')
    cout<<"T"<<endl;
  else if(b=='T')
    cout<<"A"<<endl;
  else if(b=='G')
    cout<<"C"<<endl;
  else if(b='C')
    cout<<"G"<<endl;
  
}


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

int main() {
    // メインプログラムここから
    int n;
    cin>>n;
    int a;
    a=n/1000;
    int b;
    b=(n-1000*a)/100;
    int c;
    c=(n-1000*a-100*b)/10;
    int d;
    d=n-1000*a-100*b-10*d;
    if(a==b&&b==c){
    cout<<"Yes"<<endl;
    }
    else if(a==b&&b==d){
    cout<<"Yes"<<endl;
    }
    else if(b==c&&c==d){
    cout<<"Yes"<<endl;
    }
     else if(b==c&&c==d){
    cout<<"Yes"<<endl;
    }
    else{
    cout<<"No"<<endl;
    }
    // ここまで
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
        par[x]+=par[y];
        par[y]=x;
       return true;
   }

   bool same(int x,int y){
       return find(x)==find(y);
   }
   int size(int x){
       return -par[find(x)];
   }
};

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    UnionFind uf(100010);
    int N,M; cin >> N >> M;
    rep(i,M){
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        uf.unite(a,b);
    }
    int ans=0;
    rep(i,N){
        if(uf.find(i)==i) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1152
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func init() {
	scanner.Split(bufio.ScanWords)
}

func ScanInt() (ret int) {
	var err error
	if scanner.Scan() {
		txt := scanner.Text()
		if ret, err = strconv.Atoi(txt); err != nil {
			_, _ = fmt.Fprintf(os.Stderr, err.Error())
		}
	}
	return
}

type Pair struct{ A, B int }

func main() {
	n, m := ScanInt(), ScanInt()

	pairs := make([]Pair, n)
	for i := 0; i < n; i++ {
		pairs[i].A, pairs[i].B = ScanInt(), ScanInt()
	}
	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i].A < pairs[j].A
	})

	money := 0
	for i := 0; i < n; i++ {
		if m-pairs[i].B <= 0 {
			money += m * pairs[i].A
			break
		} else {
			money += pairs[i].A * pairs[i].B
			m -= pairs[i].B
		}
	}
	fmt.Println(money)
}


Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
int n;
int t[100010], a[100010];
int yama[100010]={};
int T, A, F;
ll ans;
int main()
{
	cin >> n;
	cin >> t[0];
	yama[0]=t[0];
	repp(i, 1, n)
	{
		cin >> t[i];
		if(t[i]>t[i-1])
		{
			yama[i]=t[i];
		}
	}
	cin >> a[0];
	repp(i, 1, n)
	{
		cin >> a[i];
		if(a[i]<a[i-1])
		{
			yama[i-1]=a[i-1];
		}
	}
	yama[n-1]=a[n-1];
	T=yama[0];
	A=yama[n-1];
	F=0;
	if((T!=t[0])||(A!=a[n-1]))
	{
		F=1;
	}
	repp(i, 1, n)
	{
		T=max(T, yama[i]);
		A=max(A, yama[n-1-i]);
		if((T!=t[i])||(A!=a[n-1-i]))
		{
			F=1;
		}
	}
	if(F==1)
	{
		cout << 0 << endl;
	}
	else
	{
		ans=1;
		rep(i, n)
		{
			if(yama[i]==0)
			{
				ans= (ans * min(a[i], t[i]))% MOD;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cstring>
using namespace std;

const int MAXN = 200010;
bool box[MAXN], target[MAXN];
int main() {
	memset(box, 0, sizeof(box));
	int n;
	cin>>n;
	for (int i=1; i<=n; i++)
		cin>>target[i];
	for (int i=n; i>n/2; i--)
		box[i] = target[i];
	for (int i=n/2; i>0; i--) {
		int sum = 0;
		for (int multi=1; multi*i<=n; multi++)
			sum += box[i*multi];
		sum %= 2;
		box[i] = sum^target[i];
	}
	int ans = 0;
	for (int i=1; i<=n; i++)
		ans += box[i];
	cout<<ans<<endl;
	for (int i=1; i<=n; i++)
		if (box[i])
			cout<<i<<" ";
	cout<<endl;
	return 0;
}

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

using namespace std;

string s , t;

int main()
{
    cin >> s >> t;
    int n = s.size() , nr = 0;
    for(int i = 0 ; i < n ; i ++)
        if(s[i] != t[i])
            nr ++;
    cout << nr << '\n';
    return 0;
}


Measured memory_bytes: 3792
from heapq import heappush, heappop
from operator import itemgetter
N, K = map(int, input().split())
a = []
aa = []
for i in range(N):
    ta,tb = map(int, input().split())
    a.append(ta)
    aa.append(tb)
a = sorted(a)
aa.append(0)
aa.sort()
b = max(a)
n = K//b+1
res = 0

while K>0:
    t = aa.pop()
    if t > b:
        K -= t
        res+=1
    else:
        res +=-(-K//b)
        K = 0
        break
print(res)

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

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const int inf = 1e9 + 7;
const int mod = 1e9 + 7;

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

inline int mul(int a, int b) {
  return (a * (ll) b) % mod;
}

inline int pw(int x, int n) {
  int res = 1;
  while (n > 0) {
    if (n % 2) {
      res = mul(res, x);
      n--; 
    } else {
      x = mul(x, x);
      n /= 2;
    }
  }
  return res;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> h(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector <int> dp(n + 1, inf);
  dp[0] = 0;
  for (int i = 0; i + 1 < n; i++) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
  }
  cout << dp[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

A = list(map(int, input().split()))
A.sort()

count = 0

# 奇数なので偶数にあわせる
if (A[1]-A[0])%2 == 1:
    A[0] += 1
    A[2] += 1
    count += 1

# 偶数ルート
count += (A[1]-A[0])//2
count += (A[2]-A[1])

print(count)

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

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

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, a;

	cin >> n;

	ll ans = 0;
	ll m = INF;
	ll cnt = 0;
	bool flag = false;

	REP(i, n) {
		cin >> a;
		ans += abs(a);
		if (a < 0) {
			cnt++;
		}
		if (a == 0) {
			flag = true;
		}
		else {
			m = min(m, abs(a));
		}
	}
	
	if (cnt % 2 && !flag) {
		ans -= 2 * m;
	}

	cout << ans << endl;
}

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll ans = 0;
    for (int i=1; i<N; ++i) {
        if (A[i-1] > A[i]) {
            ans += A[i-1] - A[i];
            A[i] = A[i-1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4832
import math
from functools import reduce

k = int(input())
ans = 0

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for a in range(1, k+1):
    for b in range(a+1, k+1):
        ans += math.gcd(a,b) * 6
        for c in range(b+1, k+1):
            ans += gcd(a,b,c) * 6

print(ans + k * (k + 1) // 2)

Measured memory_bytes: 9632
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))


def solve():
    k = ri()
    a, b = rl()
    for i in range(k, 1001, k):
        if a <= i <= b:
            print ("OK")
            return
    print ("NG")







mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 65156
// ABC171.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

using namespace std;

int main()
{
	char input;

	cin >> input;

	if (input >= 65 && input <= 90) {
		cout << 'A';
	}

	if (input >= 97 && input <= 122) {
		cout << 'a';
	}

	return 0;
}


Measured memory_bytes: 3024
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
ll in(){ ll x; cin >> x; return x; }
vector<ll> in(size_t n){ vector<ll> v(n); each(x, v) cin >> x; return v; }
/* ]]] */

#define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
#define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

int n;
int a[500000];
int b[3];

int dfs(int x, int y, int s){
  if ((b[1] != x || b[2] != y) && s == 0) return 0;
  int res = 0;
  if (x > 0) chmax(res, 1 + dfs(x - 1, y, (s + 1) % 3));
  if (y > 0) chmax(res, 1 + dfs(x, y - 1, (s + 2) % 3));
  return res;
}

int main(){
  BEGIN_STACK_EXTEND(128 * 1024 * 1024);

  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) b[a[i] % 3]++;
  if (b[1] == 0 && b[2] == 0) cout << "1\n", exit(0);
  cout << b[0] + dfs(b[1], b[2], 0) << endl;

  END_STACK_EXTEND;
}

Measured memory_bytes: 28184
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int maxN = 1e5;

int readInt ()
{
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true)
    {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true;
    else result = ch-'0';
    while (true)
    {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
main() {
    int R = readInt(), G = readInt();
    cout << 2 * G - R;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <bitset>
#include <tuple>
#include <stack>
#include <utility>

using namespace std;
typedef long long ll;

int gcd(int a, int b){
    int A, B;
    if(a > b){
        A = a; B = b;
    }
    else{
        A = b; B = a;
    }
    if(a%b == 0) return b;
    else gcd(b, a%b);
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    int ans = A[0];
    for(int i=1; i<N; i++){
        ans = gcd(ans, A[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<complex>
using namespace std;

int main(){
  int n; cin >> n;
  vector<double> x(n), y(n);
  for(int i = 0; i < n; i++) cin >> x[i];
  for(int i = 0; i < n; i++) cin >> y[i];

  double a = 0, b = 0, c = 0, d = 0;
  for(int i = 0; i < n; i++){
    double now = abs(x[i] - y[i]);
    a += now;
    b += now * now;
    c += now * now * now;
    d = max(d, now);
  }
  b = sqrt(b);
  c = pow(c,1.0/3.0);
  printf("%.10f\n%.10f\n%.10f\n%.10f\n", a, b, c, d);
  return 0;
}



Measured memory_bytes: 3408
#include<iostream>
#include<vector>
using namespace std;
#define SIZE 1000000
int main(){
	vector<bool>bo(SIZE,false);
	for(int i=2;i<SIZE;i++){
		if(bo[i]==false){
			for(int j=i*2;j<SIZE;j+=i){
				bo[j]=true;
			}
		}
	}
	vector<int>ans(SIZE);

	for(int i=2;i<SIZE;i++){
		if(bo[i]==false){
			ans[i]=ans[i-1]+1;
		}
		else {
			ans[i]=ans[i-1];
		}
	}
	int n;
	while(cin>>n){
		cout<<ans[n]<<endl;
	}
	return 0;
}

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

long long int ans = 0;
long long int arr[10] = {1, 11, 112, 1124, 11248, 112496, 1124992, 11249984, 112499968, 1124999936};
char s[10];

int main(){
    scanf("%s", s);
    int le = strlen(s);
    for(int i = 0; i < le; i++){
        ans += arr[le - i - 1] * pow(2, i) * (s[i] - '0');
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512