akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    int n, m;
    cin >> n >> m;
    
    int s, mc = m;
    while (s * s <= m) s++;
    
    int k = 1, p[15], q[15];
    for (int i = 1; i <= 13; i++) p[i] = -1;
    
    for (int i = 2; i <= s; i++) {
        if (m % i == 0) {
            p[k] = i;
            q[k] = 1;
            m /= i;
            while (m % i == 0) {
                q[k]++;
                m /= i;
            }
            k++;
        }
    }
    if (s * s != mc && m > s) {
        p[k] = m;
        q[k] = 1;
    }
    else k--;
    
    int a[500000];
    int l = 0;
    for (int i1 = 0; i1 <= q[1]; i1++){
    for (int i2 = 0; i2 <= q[2]; i2++){
    for (int i3 = 0; i3 <= q[3]; i3++){
    for (int i4 = 0; i4 <= q[4]; i4++){
    for (int i5 = 0; i5 <= q[5]; i5++){
    for (int i6 = 0; i6 <= q[6]; i6++){
    for (int i7 = 0; i7 <= q[7]; i7++){
    for (int i8 = 0; i8 <= q[8]; i8++){
    for (int i9 = 0; i9 <= q[9]; i9++){
    for (int i10 = 0; i10 <= q[10]; i10++){
    for (int i11 = 0; i11 <= q[11]; i11++){
        a[l] = pow(p[1], i1);
        if (p[2] != -1) a[l] *= pow(p[2], i2);
        if (p[3] != -1) a[l] *= pow(p[3], i3);
        if (p[4] != -1) a[l] *= pow(p[4], i4);
        if (p[5] != -1) a[l] *= pow(p[5], i5);
        if (p[6] != -1) a[l] *= pow(p[6], i6);
        if (p[7] != -1) a[l] *= pow(p[7], i7);
        if (p[8] != -1) a[l] *= pow(p[8], i8);
        if (p[9] != -1) a[l] *= pow(p[9], i9);
        if (p[10] != -1) a[l] *= pow(p[10], i10);
        if (p[11] != -1) a[l] *= pow(p[11], i11);
        l++;
    }}}}}}}}}}}
    
    sort(a, a + l);
        
    int ans;
    for (int i = l - 1; i >= 0; i--) {
        if (n <= mc / a[i]) {
            ans = a[i];
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
s = []
c = []

ans = ['0' for i in range(n)]
f = True
for i in range(m):
    ss,cc = map(int,input().split())
    for l,o in enumerate(s):
        if s[l] == ss and c[l] != cc:
            f = False
    if ss == 1 and cc == 0 and n != 1:
        f = False
    s.append(ss)
    c.append(cc)

for i,o in enumerate(s):
    ans[o-1] = str(c[i])

if ans[0] == str(0) and n!=1:
    ans[0] = str(1)

if f == False:
    print('-1')
else:
    print(''.join(ans))

Measured memory_bytes: 3064
#include <stdio.h>
#include<string.h>
char s[205];
int l,m,h,i;
void rev(int r,int l)
{
	char x;
	for(;r<l;r++,l--)
	{
		x=s[r];s[r]=s[l];s[l]=x;
	}
}
int main()
{
	for(;scanf("%s",s),s[0]!='-';)
	{
		l=strlen(s)-1;
		scanf("%d",&m);
		for(i=0;i<m;i++)
		{
			scanf("%d\n",&h);
			rev(0,h-1);
			rev(h,l);
			rev(0,l);
		}
		puts(s);
	}
	return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
#include <math.h>

main()
{
int h,w;
while(1){
	scanf("%d %d",&h,&w);
	if((h|w)==0)break;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			printf("%c",(j+i)%2?'.':'#');
		}
		printf("\n");
	}
	printf("\n");
}
}


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

int main() {
    ll n;
    cin >> n;
    ll a[1000000] = {0};
    rep(i, 3 * n) {
        cin >> a[i];
    }
    sort(a, a + 3 * n, greater<int>());
    ll sum = 0;
    ll count = 0;
    for (int i = 0; i < 3 * n; i++) {
        if (i % 2 == 1) {
            sum += a[i];
            count++;
            if (count == n) break;
        }
    }
    cout << sum << endl;
}

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    vector<int> abc(3);
    rep(i, 3) cin >> abc[i];
    sort(abc.begin(), abc.end());
    bool b = abc[0] == abc[2];
    cout << (b ? "Yes" : "No") << endl;
}


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

using namespace std;
using ll = long long;


int main()
{
	string s; cin >> s;
	int n = s.size();
	int cur = 0;
	for(auto i : s) cur += i - '0';
	cout << max( (s.front() - '1') + 9 * (n - 1), cur) << endl;
}

Measured memory_bytes: 256
Option Strict On
Public Class Main
    Public Shared Sub Main(ByVal args() As String)
        Dim H, N As Integer
        Dim arr(2) As String
        arr = Split(Console.ReadLine())
        H = Integer.Parse(arr(0)) : N = Integer.Parse(arr(1))
        Dim A() As Integer = Array.ConvertAll(Of String, Integer) _
            (Split(Console.ReadLine()), AddressOf Integer.Parse)
        Dim accum As Integer = 0
        For Each Ai As Integer In A
            accum += Ai
        Next
        Console.WriteLine(If(accum < H, "No", "Yes"))
    End Sub
End Class


Measured memory_bytes: 27616
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long p = sc.nextLong();
        int m = (int) Math.ceil(Math.sqrt(p));
        long ans = 1;
        for (int i = 2; i < m; i++) {
            int cnt = 0;
            while(p % i == 0){
                cnt++;
                p /= i;
            }
            if(n <= cnt){
                ans *= Math.pow(i, (cnt / n));
            }
        }
        if(1 < p) ans *= Math.pow(p, (1 / n));
        System.out.println(ans);
        sc.close();

    }

}


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

using namespace std;

int main(void){
	int N;
	vector<int> L;
	
	cin >> N;
	
	L.resize(N * 2);
	
	for(int i = 0; i < N * 2; ++i){
		cin >> L[i];
	}
	
	sort(L.begin(), L.end());
	
	int ans = 0;
	for(int i = 0; i < L.size(); i += 2){
		ans += min(L[i], L[i + 1]);
	}
	
	cout << ans << endl;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    cout << max({a+a-1, b+b-1, a+b});
    return 0;
}
                

Measured memory_bytes: 256
n = gets.chomp.to_i
xy = []
n.times do |i|
  xy[i] = gets.chomp.split.map(&:to_f)
end

sum = 0.0
(0..(n-2)).each do |i|
  ((i+1)..(n-1)).each do |j|
    sum += ((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)**0.5
  end
end

ans = sum * 2 / n

puts(ans)

Measured memory_bytes: 1916
#include <stdio.h>

int main(){
	int n;
	int num=0;
	int i;

	scanf("%d",&n);
	for(i=3; i<=n; i++){
		if(i%3==0)
			printf(" %d",i);
		else {
			num = i;
			while(1){
				if(num == 0)
					break;
				if(num%10 == 3){
					printf(" %d",i);
					break;
				} else {
					num = num/10;
				}
			}
		}
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 600
_n, m = gets.chomp.split(' ').map(&:to_i)
list = gets.chomp.split(' ').map(&:to_i)

hash = { 0 => 1 }

sum = 0
list.each do |x|
  sum += x
  key = sum % m
  if hash.key?(key)
    hash[key] += 1
  else
    hash[key] = 1
  end
end

cnt = 0
hash.each do |key, value|
  next if value <= 1
  cnt += value * (value - 1) / 2
end

puts cnt


Measured memory_bytes: 12676
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
#define SIZE 100005
vector< int > graph[SIZE];
vector< pair< int , int > > ans;
vector< int > vis(SIZE,0);
vector< int > low(SIZE,0);
vector< int > tin(SIZE , 0);

int timer;
void dfs(int u , int p = -1){
	vis[u] = true;
	tin[u] = low[u] = timer++;
	int children = 0;
	for(auto it : graph[u]){
			if(it == p) continue;
			if(vis[it] == 1)
				low[u] = min(low[u] , tin[it]);
			else{
				dfs(it , u);
				low[u] = min(low[u] , low[it]);
				if(low[it] > tin[u])
					it > u ? ans.push_back({u, it}) : ans.push_back({it,u});
				children++;
			}
	}
}
int main(){
	dhoom;
	int n , m;
	cin >> n >> m;
	for(int i = 0 ; i < m ; i++){
		int x , y ;
		cin >> x >> y;
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	for(int i = 0 ; i < n ; i++){
			if(!vis[i])
				dfs(i);
	}
	sort(ans.begin() , ans.end());
	ans.erase(unique(ans.begin() , ans.end()), ans.end());
	for(int i = 0 ; i < (int) ans.size() ; i++)	
		cout << ans[i].first<< " " << ans[i].second << endl;
    return 0;
}




Measured memory_bytes: 7724
import math
N,H=map(int,input().split())
swords = [list(map(int,input().split())) for x in range(N)]
actions = []
for sword in swords:
  actions.append([sword[0],pow(10,9)])
  actions.append([sword[1],1])
actions.sort(key=lambda x:x[0],reverse=True)
count = 0
for action in actions:
  if action[0]*action[1] < H:
    H -= action[0]*action[1]
    count += action[1]
  else:
    count += int(math.ceil(H/action[0]))
    break
print(count)

Measured memory_bytes: 47976
#include <cstdio>

long long qpow(long long a, long long n) {
    long long res = 1;
    for (; n; n >>= 1, a *= a) if (n & 1) res *= a;
    return res;
}

int main() {
    long long n, p;
    scanf("%lld %lld", &n, &p);

    long long ans = 1;
    for (int i = 2; 1ll * i * i <= p; i++) if (p % i == 0) {
        int cnt = 0;
        while (p % i == 0) {
            ++cnt;
            p /= i;
        }
        ans *= qpow(i, cnt / n);
    }
    if (p > 1 && n == 1) ans *= p;

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

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

long long md(pair<long long,long long> x,pair<long long,long long> y){
    return max(x.first,y.first)-min(x.first,y.first)+max(x.second,y.second)-min(x.second,y.second);
}

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> vec(M),stair(N);
    for(int i=0;i<M;i++){
        cin >> vec[i];
    }
    for(int i=0;i<M;i++){
        stair[vec[i]]=1;
    }
    for(int i=1;i<M;i++){
        if(vec[i]-vec[i-1]==1){
            cout << 0 << endl;
            return 0;
        }
    }
    vector<int> ans(N+1);
    ans[0]=1;
    ans[1]=1;
    for(int i=2;i<N+1;i++){
        ans[i]=ans[i-1]+ans[i-2];
        if(stair[i-1]==1)
        ans[i]-=ans[i-1];
        if(stair[i-2]==1)
        ans[i]-=ans[i-2];
        ans[i]%=1000000007;
    }
    cout << ans[N] << endl;
}

Measured memory_bytes: 1280
#include <string>
#include <iostream>
using namespace std;
int a, b;
void rec(string s, int x, int y) {
	if(a == x && b == y) { cout << s << endl; return; }
	if((x < 4 || y < 4) && (x == 5 || y == 5)) return;
	if(x + y > 9) return;
	rec(s + "A", x + 1, y);
	rec(s + "B", x, y + 1);
}
int main() {
	scanf("%d%d", &a, &b);
	rec("", 0, 0);
}

Measured memory_bytes: 3268
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        int h, w;
        cin >> h >> w;
        char a[h][w];
        rep(i, h) rep(j, w) cin >> a[i][j];
        for (int i = -1; i < h + 1; ++i) {
            for (int j = -1; j < w + 1; ++j) {
                if (i == -1 || i == h || j == -1 || j == w) cout << '#';
                else cout << a[i][j];
            }
            printf("\n");
        }

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  double ave = 0;
  rep(i, n) {
    cin >> a[i];
    ave += a[i];
  }
  ave /= n;
  int ans = 0;
  rep(i, n) {
    if (abs(ave-a[i]) < abs(ave-a[ans]))
      ans = i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    int e=0;
    int f=0;
    int week=0;
    int g=0;
    cin>>a>>b>>c;
    if(c<=a*7+b){
        e=c/a;
        f=c%a;
        if(c>=a*7){
            cout<<7<<endl;
        }else{
            if(f==0){
             cout<<e<<endl;
            }else{
             g=e+1;
             cout<<g<<endl;
            }
        }    
    }else{
        week=c/(a*7+b);
        d=c%(a*7+b);
        e=d/a;
        f=d%a;
        if(d>=a*7){
            cout<<week*7+7<<endl;
        }else{
            if(f==0){
             g=week*7+e;
             cout<<g<<endl;
            }else{
             g=week*7+e+1;
             cout<<g<<endl;
            }
        }    
    }
}



Measured memory_bytes: 3116
k,n=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
d=[0]*a.size

a.size.times do |i|
    if i==0
        d[i]=a[i] + k-a[-1]
    else
        d[i]=a[i] - a[i-1]
    end
end

p d.inject(:+)-d.max

Measured memory_bytes: 16900
import math
n, m = map(int, input().split())
false_count = [1]*n
ans_false_count = [0]*n
ans_success_count = [0]*n

for i in range(m):
    p, s = input().split()
    p = int(p)
    s = str(s)

    if s=='WA':
        false_count[p-1] = int(false_count[p-1]*2)
    else:
        ans_false_count[p-1] += int(false_count[p-1])
        ans_success_count[p-1] = 1
        false_count[p-1] = 0

for j in range(n):
    if ans_false_count [j] != 0:
        ans_false_count[j] = math.log(ans_false_count[j],2)

new_ans_false_count = ans_false_count
print(sum(ans_success_count), int(sum(new_ans_false_count)))    

Measured memory_bytes: 7796
use std::io;

macro_rules! read {
    () => {
        {
            let mut line = String::new();
            io::stdin().read_line(&mut line).unwrap();
            line
        }
    };
}

fn split(s: &String) -> std::str::SplitWhitespace {
    s.trim().split_whitespace()
}

fn main() {
    let mut line = read!();
    let mut line = split(&mut line);
    let n: usize = line.next().unwrap().parse().unwrap();
    let m: usize = line.next().unwrap().parse().unwrap();
    let c: i32 = line.next().unwrap().parse().unwrap();
    let mut b: Vec<i32> = Vec::new();
    let mut line = read!();
    let mut line = split(&mut line);
    for i in 0..m {
        b.push(line.next().unwrap().parse().unwrap());
    }
    let mut a: Vec<Vec<i32>> = Vec::new();
    for i in 0..n {
        let mut line = read!();
        let mut line = split(&mut line);
        a.push(Vec::new());
        for j in 0..m {
            a[i].push(line.next().unwrap().parse().unwrap());
        }
    }

    let mut ans = 0;
    for i in 0..n {
        let mut s = c;
        for j in 0..m {
            s += a[i][j]*b[j];
        }
        if s > 0 { ans+= 1; }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <functional>
#include <set>
#include <vector>
#include <array>
#include <cmath>
#include <queue>

#define r(i, v, n) for(int i = v; i < n; i++)
#define re(i, v, n) for(int i = v; i <= n; i++)
#define rr(e, v) for(auto&& (e) : (v))

using namespace std;
using ll = long long;
using ul = unsigned long;

int main() {
    ios_base::sync_with_stdio(false);

    int a, p;
    cin >> a >> p;

    p += (a * 3);
    int r = p / 2;
    cout << r ;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

vector<int> vi[200001];
int main(){
    int n,m,a,b;
    cin>>n>>m;
    rep(i,m){
        cin>>a>>b;
        vi[a-1].pb(b-1);
        vi[b-1].pb(a-1);
    }
    rep(i,vi[0].size()){
        if(find(vi[vi[0][i]].begin(),vi[vi[0][i]].end(),n-1)!=vi[vi[0][i]].end()){
            cout<<"POSSIBLE"<<endl;return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 12016
from itertools import count
from math import factorial, fabs
from collections import Counter
N = int(input())

mod = 10**9 + 7

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

factors = prime_factors(factorial(N))
r = 1
for v in Counter(factors).values():
    r *= v + 1

print(r % mod)


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num1 = sc.nextInt();
		int num2 = sc.nextInt();
		int num3 = sc.nextInt();
		if(num1 == num2 && num1 != num3) {
			System.out.println("Yes");
		}else if(num1 == num3 && num1 != num2){
			System.out.println("Yes");
		}else if(num2 == num3 && num2 != num1) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

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

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(a<=0 && 0<=b){
        cout << "Zero";
    }else if(a<0&&(b-a)%2==0){
        cout << "Negative";
    }else{
        cout << "Positive";
    }
}

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

using namespace std;
#define ll long long

int main() {
vector<ll> v;
ll a,b,c;
cin>>a>>b>>c;
v.push_back(a);
v.push_back(b);
v.push_back(c);
if(a%2==0||b%2==0||c%2==0)
{
    cout<<0;
}
else
{
    sort(v.begin(),v.end());
    cout<<v[0]*v[1];
}


}

Measured memory_bytes: 3628
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define INFTY 1 << 21

ll gcd(ll a, ll b) {
  ll c;
  if (a < b) swap(a, b);
  while (a % b) {
    c = a % b;
    a = b;
    b = c;
  }
  return b;
}

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;

  ll total = B - A + 1;
  ll divC, divD, divCD;
  divC = B / C - (A - 1) / C;
  divD = B / D - (A - 1) / D;
  divCD = B / (C * D / gcd(C, D)) - (A - 1) / (C * D / gcd(C, D));
  cout << total - (divC + divD - divCD) << endl;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        long[] B = new long[n-1];
        Arrays.setAll(B, i -> Integer.parseInt(sc.next()));
        ans += B[0] + B[n - 2];
        for(int i = 1; i < n - 1; i++) ans += Math.min(B[i - 1], B[i]);
        System.out.println(ans);
    }
}


Measured memory_bytes: 27988
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
typedef long long int ll;
typedef int512_t llt;
using namespace std;
#define  ios ios_base::sync_with_stdio(false);
#define max 1000000000;


//#define mod 1000000007;
ll a[1000000],h[1000000];
ll bexp(ll a,ll b){
    if(b==0)
        return 1;
    if(b==1)
        return a;
    else if(b%2==0)
        return ((bexp(2,b/2)%1000000007)*(bexp(2,b/2))%1000000007);

    else return ((bexp(2,b-1)%1000000007)*2);
}

long long compute_hash(string const& s) {
    const int p = 31;
    const int m = static_cast<const int>(1e9 + 9);
    long long hash_value = 0;
    long long p_pow = 1;
    for (char c : s) {
        hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
        p_pow = (p_pow * p) % m;
    }
    return hash_value;
}
ll hsh(string &s){
    ll tmp=0;
    for (char i : s) {
        if(i =='a')
            tmp+=69991;
        if(i =='e')
            tmp+=231;
        if(i =='i')
            tmp+=62;
        if(i =='o')
            tmp+=297;
        if(i =='u')
            tmp+=57456;
    }
    return  tmp;
}
void init(ll *h){
    for(int i=0;i<1000000;i++){
        h[i]=0;
    }
}
ll f(ll n){
    if(n%2==0)
        return n/2;
    else return (3*n)+1;
}
void comp(ll s,ll *a){
    a[1]=s;
    for(int i=2;i<1000000;i++){
        a[i]=f(a[i-1]);
    }
}
ll check(ll *a,ll *h){
    for(int i=1;i<1000000;i++){
        if(h[a[i]]!=1)
            h[a[i]]++;
        else return i;
    }
}
int main() {
    ios
    ll t;
   // cin >> t;
   // while (t--) {
    ll n;
    ll s;
    init(h);
    cin>>s;
    comp(s,a);
    ll cnt=check(a,h);
    cout<<cnt<<endl;
   // }
}


Measured memory_bytes: 15872
def f(c):
    if c == "#":
        ret = 1
    else:
        ret = 0

    return ret


h, w = map(int, input().split())
s = [list(map(f, "#" * (w + 1)))]
for _ in range(h):
    s.append([1] + list(map(f, input())))
INF = 100 * 100

dp = [[[INF] * 2 for _ in range(w + 1)] for _ in range(h + 1)]
dp[1][1][s[1][1]] = s[1][1]

for i, (row_u, row) in enumerate(zip(s, s[1:]), 1):
    for j, (el, eu, e) in enumerate(zip(row, row_u[1:], row[1:]), 1):
        dp[i][j][e] = min(dp[i][j][e], dp[i-1][j][eu] + (eu + e) % 2, dp[i][j-1][el] + (el + e) % 2)

ans = dp[h][w][s[h][w]]
ans = (ans + 1) // 2
print(ans)


Measured memory_bytes: 4084
#include<bits/stdc++.h>
// iteration and input/output stream
#define rep(i,a,b) for(int i = int(a);i<=int(b);i++)
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define printarr(x) rep(i,0,x.size()-1) cout<<x[i]<<" "; cout<<endl;
#define all(v) v.begin(),v.end()
 
#define si(x) int x; scanf("%d", &x)
#define sll(x) ll x; scanf("%lld", &x)
#define pi(x) printf("%d", x)
#define pll(x) printf("%lld", x)
#define nl printf("\n")
#define tr(cont,it) \
for(decltype(cont.begin()) it = cont.begin(); it!= cont.end() ; it++)
 
#define endl "\n"
#define tc() int t; cin >> t ; while (t--)
//STL shortcuts
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define MP make_pair
 
// Error detection
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
using namespace std;
 
typedef long long int ll; // 64 bit integer
typedef unsigned long long int  ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;
 
inline void smax(int &x , int y) { x = max(x , y) ; }
inline void smin(int &x , int y) { x = min(x , y) ; }
 
#define MOD 1000000007
#define inf 4000000000000000000LL
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);

vi dp;
vi h;

int f(int i)
{
    if(dp[i]!=-1)
    {
        return dp[i];
    }
    else
    {
        if(i==0)
        {
            return dp[i] = 0;
        }
        else if(i==1)
        {
            return dp[i] = f(i-1)+abs(h[i]-h[i-1]);
        }
        else
        {
            return dp[i] = min(f(i-2) + abs(h[i]-h[i-2]),f(i-1)+abs(h[i]-h[i-1]));
        }
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("err.txt","w",stderr);
    #endif
    SYNC
    int n;
    cin>>n;
    h.resize(n);
    for (int i = 0; i < n; i++)
    {
        cin>>h[i];
    }
    dp.resize(n,-1);
    cout<<f(n-1);
    return 0;
}

Measured memory_bytes: 8676
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
  ll ans=1;
  for(int i=1;i<=n;i++)
       ans*=a;
    return ans;
}

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

 ll a,b;
 cin>>a>>b;
 cout<<a*b<<endl;

return 0;
}



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

int main()
{
  int n;
  vector<int> arr;

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

  int swap_cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = n-1; j > i; j--) {
      if (arr[j] < arr[j-1]) {
        swap(arr[j], arr[j-1]);
        swap_cnt++;
      }
    }
  }

  for (int i = 0; i < n; i++)
    cout << arr[i] << (i==n-1?'\n':' ');
  cout << swap_cnt << endl;

  return EXIT_SUCCESS;
}




Measured memory_bytes: 3160
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
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)++)
typedef long long ll;
typedef pair<int,ll> edge;
vector<ll> depth;
vector<vector<edge> > G;

void dfs(int v,int p,ll d){
    depth[v] = d;
    for(auto &e :G[v]){
        if(e.first==p)continue;
        dfs(e.first,v,d+e.second);
    }
}

int main(){
    int n;
    cin >> n;
    depth.resize(n);
    G.resize(n);
    rep(i,n-1){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        G[a].push_back(make_pair(b,c));
        G[b].push_back(make_pair(a,c));
    }
    int q,k;
    cin >> q >> k;
    k--;
    dfs(k,-1,0);
    rep(i,q){
        int x,y;
        cin >> x >> y;
        x--,y--;
        cout << depth[x]+depth[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 14336
n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]
l.sort(key=lambda x:x[1])

s = 0
ind = len(l)
for i in range(len(l)):
    s += l[i][0]
    if (s > l[i][1]):
        ind = i
        break
 
if (ind == len(l)):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 41176
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = Integer.parseInt(sc.next());
			if (n == 0) break;
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = Integer.parseInt(sc.next());
			Arrays.sort(a);
			int ans = Integer.MAX_VALUE;
			for (int i = 1; i < n; i++)
				ans = Math.min(ans, a[i] - a[i - 1]);
			System.out.println(ans);
		}
	}
}


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll y;
  string e;
  cin >> e >> y;
  if(e == "0") {
    if(1989 <= y) {
      e = "H";
      y-= 1988;
    } else if(1926 <= y) {
      e = "S";
      y-= 1925;
    } else if(1912 <= y) {
      e = "T";
     y-= 1911;
    } else {
      e = "M";
      y-= 1867;
    }
  } else if(e == "4") {
    e = "";
    y += 1988;
  } else if(e == "3") {
    e = "";
    y += 1925;
  } else if(e == "2") {
    e = "";
    y += 1911;
  } else if(e == "1") {
    e = "";
    y += 1867;
  }
  cout << e << y << endl;
	return 0;
}


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

int n,s, a[2005], d[2005][2005][2];
int ab(int p) {return p > 0 ? p : -p;}
int f(int p, int q, int w) {
	int i, mx;
	if (d[p][q][w] != -1) return d[p][q][w];
	mx = max(p, q);
	if (mx== n + 1) return ab(a[p] - a[q]);
	if (w == 0) {
		if (p == 0) return d[p][q][w] = f(mx + 1, q, 0);
		else return d[p][q][w] = max(f(mx + 1, q, 0), f(p, mx + 1, 1));
	} else return d[p][q][w] = min(f(mx + 1, q, 0), f(p, mx + 1, 1));
}
int main()
{
	int i;
	cin >> n >> a[0] >> a[1];
	for (i = 2; i < n + 2; i++) {
		scanf ("%d", &a[i]);
	}
	memset(d, -1, sizeof(d));
	cout << f(0, 1, 0);
    return 0;
}



Measured memory_bytes: 31744
/*---------------------------------- NEVER GIVE UP --------------------------------------------*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pii;
typedef tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug1(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl

const ll modd=1e9+7;
const ll inf=1e18;

ll poww(ll a,ll b){
  ll ans=1;
  while(b){
    if(b&1LL) ans=(ans*a);
    a=(a*a);
    b=b>>1LL;
  }
  return ans;
}

/*    
         -> mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
         -> cout<<"Case #"<<casee<<": "<<ans<<endl; // for google kickstart

*/

/*-----------------------------------------------------------------------------------------------*/

vector <pii> points;
set <pii> point_set;
ll n;

ll check(ll x){
  for(ll i=0;i<(ll)points.size();i++){
    for(ll j=i+1;j<(ll)points.size();j++){
      ll p=points[j].fi-points[i].fi;
      ll q=points[j].se-points[i].se;
      ll ans=0;
      for(ll k=0;k<points.size();k++){
        if( point_set.count({points[k].fi-p,points[k].se-q}) == 1 ) ans++;
      }
      if(ans >= x) return 1;
    }
  }
  return 0;
}

int main(){
   fastt;
   
   cin>>n;

   for(ll i=1;i<=n;i++){
      ll x,y;
      cin>>x>>y;
      points.pb({x,y});
      point_set.insert({x,y});
   }

   sort(points.begin(),points.end());

   ll lo=0,hi=n;

   while(lo < hi){
     ll mid=(lo+hi)/2;
     if(check(mid)){
        if(lo == mid){
          if(check(lo+1)) lo++;
          break;
        }
        lo=mid;
     }
     else
        hi=mid;
   }

   cout<<(n-lo)<<endl;
 
   return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

string s;
int n, k;
int a[100], b[100], c[100];
string ans;

signed main() {
    cin >> s;
    bool is_easy = true;
    for (int i = 0; i < s.size(); i++) {
        if ((i % 2) == 0) {
            // odd
            if(s[i] == 'L') {
                is_easy = false;
            }
        } else {
            if(s[i] == 'R') {
                is_easy = false;
            }
        }
    }

    ans = is_easy? "Yes":"No";
    cout << ans << endl;
}


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

int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<int> A(N);
  vector<int> F(N);
  rep(i,N) cin >> A[i];
  rep(i,N) cin >> F[i];
  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());
  ll l = -1, r = 1e12;
  while(l+1 < r) {
    ll c = (l+r)/2;
    ll sum = 0;
    rep(i,N) {
      sum += max(0ll, A[i] - c/F[i]);
    }
    if (sum <= K) r = c;
    else l = c;
  }
  cout << r << endl;
}

Measured memory_bytes: 1792
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a, s := nextInt(), nextLine()
	if a >= 3200 {
		fmt.Println(s)
	} else {
		fmt.Println("red")
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9+1
#define MOD 0
//#define int ll
using namespace std;
typedef vector<long long> vl;

//int gcd(int a,int b) {
//  if(b == 0) {
//    return b;
//  }
//  return gcd(b, a%b);
//}

signed main() {
  int n,ch=0;
  ll sum=0;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<ll> a(100050,INF);
  vector<ll> b(100050,INF);
  rep(i,n) {
    cin >> a[i];
    b[i] = a[i];
    a[i] = llabs(a[i]);
    sum+= a[i];
    if(a[i]==0) {
      ch=1;
    }
  }
  if(ch==1) {
    cout << sum << endl;
    return 0;
  } else {
    rep(i,n-1) {
      if(b[i]<0) {
        b[i+1]=b[i+1]*(-1);
      }
    }
  }
  if(b[n-1]>0) {
    cout << sum << endl;
  } else {
      sort(a.begin(),a.end());
      sum -= 2*a[0];
      cout << sum << endl;
  }
  return 0;
}



Measured memory_bytes: 1792
S = list(map(str, input()))
count1 = 0
count2 = 1
while count1+1 <= len(S):
    if S[count1] == 'L':
        print('No')
        break
    else: count1 +=2
else:
    while count2 < len(S):        
        if S[count2] == 'R':
            print('No')
            break
        else:
            count2 += 2
    else:
        print('Yes')

Measured memory_bytes: 3060
r,g,b,n = map(int,input().split(" "))
count = 0
for i in range(0,n+1,r):
    for j in range(0,n+1,g):
        if i + j <= n:
            if (n - (i + j)) % b == 0: 
                    count += 1
print(count)

Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
    int n,i;
    cin>>n;
    int a[n];
    int f=0;
    for(i=0;i<n;i++)
        cin>>a[i];
        for(i=0;i<n;i++){
    if(a[i]%2==0)
    {
        if(a[i]%3!=0&&a[i]%5!=0)
            {f=1;
            break;}
    }
        }
    if(f==0)
        cout<<"APPROVED";
    else
        cout<<"DENIED";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける

int g[15][15];
bool flag[1050000];
const int INF = 1001001001;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,-1,0,1 };

void solve() {

}

int main() {
	int n;
	cin >> n;
	vector<ll>A(n);
	rep(i, n) {
		cin >> A[i];
	}
	ll ans = A[0];

	rep(i, n-1) {
		if (ans > A[i + 1]) {
			ll tmp = A[i + 1];
			A[i + 1] = ans;
			ans = tmp;
		}
		ll r = A[i + 1] % ans;
		while (r != 0) {
			A[i + 1] = ans;
			ans = r;
			r = A[i + 1] % ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  int n, k;
  cin >> n >> k;
  vi32 curr(n);
  cin >> curr;
  while (k--) {
    auto prev = curr;
    rep(i, n) curr[i] = 0;
    rep(i, n) {
      int d = prev[i];
      curr[max(0, i - d)] += 1;
      if (i + d + 1 < n) curr[i + d + 1] -= 1;
    }
    reps(i, n - 1) curr[i] += curr[i - 1];
    if (curr == prev) {
      break;
    }
  }
  cout << curr << endl;
}


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


using namespace std;

#define fastio() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


void go(){
	int a,b,c;cin>>a>>b>>c;
	int k;cin>>k;
	int s=a+b+c;
	int s1=s,s2=s,s3=s;
	int ans=0;
	while(k) {
		s1-=a, s1+=a*2;
		s2-=b, s2+=b*2;
		s3-=c, s3+=c*2;
		ans=max({s1,s2,s3});
		a*=2;
		b*=2;
		c*=2;
		k--;
	}
	cout << ans;
}
int main(){
   
   fastio();
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}




Measured memory_bytes: 3636
import math

def L(x1,y1,x2,y2):
  return math.sqrt((x1-x2)**2+(y1-y2)**2)

def S(a,b,c):
  s=(a+b+c)/2
  return math.sqrt(s*(s-a)*(s-b)*(s-c))

while True:
  try:
    x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
    a  = L(x1,y1,x2,y2)
    b  = L(x1,y1,x3,y3)
    c  = L(x2,y2,x3,y3)
    pa = L(x3,y3,xp,yp)
    pb = L(x2,y2,xp,yp)
    pc = L(x1,y1,xp,yp)
    if S(a,pb,pc)+S(b,pc,pa)+S(c,pa,pb)-S(a,b,c) > 0.0000001:
      print "NO"
    else:
      print "YES"
  except:
    break

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

#define N 9

void set(int *array,int n)
{
  for(int i=0;i<10;i++) *(array + i)=n;
}

int main()
{
  int n,i,j,mass[N][N],count[10];
  bool flag[N][N];
  cin>>n;
  while(n-->0){
    for(i=0;i<N;i++)for(j=0;j<N;j++){
      cin>>mass[i][j];
      flag[i][j]=0;
    }
    for(i=0;i<N;i++){
      set(count,0);
      for(j=0;j<N;j++)count[mass[i][j]]++;
      for(j=0;j<N;j++)if(count[mass[i][j]]>=2)flag[i][j]=true;
      set(count,0);
      for(j=0;j<N;j++)count[mass[j][i]]++;
      for(j=0;j<N;j++)if(count[mass[j][i]]>=2)flag[j][i]=true;
      set(count,0);
      int y=(i/3)*3;
      int x=(i%3)*3;
      for(j=0;j<N;j++)count[mass[y+j/3][x+j%3]]++;
      for(j=0;j<N;j++)if(count[mass[y+j/3][x+j%3]]>=2)flag[y+j/3][x+j%3]=true;
    }
    for(i=0;i<N;i++){
      for(j=0;j<N;j++){
	putchar(flag[i][j]?'*':' ');
	cout<<mass[i][j];
      }
      cout<<endl;
    }
    if(n>0)cout<<endl;
  }
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>

using namespace std;

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

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

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

    ll n;
    cin >> n;
    ll k = (ll) 1e9;
    cout << 0 << " " << 0 << " " << k << " " << 1 << " ";
    ll y = (n + k - 1) / k;
    ll x = k * y - n;
    cout << x << " " << y << endl;
}

Measured memory_bytes: 256
/**
 * Created by hiramekun at 20:58 on 2020-05-03.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll x;
    cin >> x;
    for (ll i = -1e3; i <= 1e3; ++i) {
        for (ll j = -1e3; j <= 1e3; ++j) {
            if (ll(pow(i, 5) - pow(j, 5)) == x) {
                cout << i << ' ' << j << '\n';
                return;
            }
        }
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 4096
# include <bits/stdc++.h>
# define int long long
# define endl "\n"
using namespace std;

void solve() {

	int n, k;
	cin >> n >> k;

	vector <int> arr(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr.begin(), arr.end());
	int Sum = 0;
	for (int i = 0; i < k; i++) {
		Sum += arr[i];
	}
	cout << Sum;
}

signed main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

# ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
# endif

	solve();

	return 0;
}

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

int main() {
	char c[3][3];

	for (int i = 0; i < 3; i++) {
		cin >> c[i];
	}
	for (int i = 0; i < 3; i++) {
		cout << c[i][i];
	}
	cout << endl;
	return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  const string s = " kstnhmyrw";
  const string b = "aiueo";
  const string t = "TLURD";

  string S; cin >> S;
  int N = S.size();
  rep(i, N / 2) {
    int d = S[2 * i] - '0';
    if(d == 0) d = 9; else d --;
    char m = S[2 * i + 1];
    if(d == 9) {
      if(m == 'T') cout << "wa";
      else if(m == 'U') cout << "nn";
      else cout << "wo";
    } else {
      if(d != 0) cout << s[d];
      cout << b[t.find(m)];
    }
  }

  puts("");
  
  return 0;
}

Measured memory_bytes: 3240
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a > b ){
        int tmp = a;
        a =b;
        b = tmp;
    }
    if(a > c){
        int tmp = a;
        a = c;
        c = tmp;
    }
    if(b > c){
        int tmp = b;
        b = c;
        c =tmp;
    }
    cout << a << " " << b << " "<< c << endl;    
}



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

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

  if (A.size()==B.size()){
    if (A>B){
      cout << "GREATER" << endl;
    }
    else if (A<B){
      cout << "LESS" << endl;
    }
    else {
      cout << "EQUAL" << endl;
    }
  }
  else {
    if (A.size()>B.size()){
      cout << "GREATER" << endl;
    }
    else {
      cout << "LESS" << endl;
    }
  }
}


Measured memory_bytes: 256