akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
#define MOD 1000000007

int main(int argc, char const *argv[]) {
  string s;
  long long k;
  int i=0;
  std::cin >> s >>k;

  if(k==1 || s.size()<=1)std::cout << s[0] << endl;

  else{
    while(s[i]=='1'){
      i++;
    }

    if(i<k) std::cout << s[i] << endl;
    else std::cout << "1" << endl; 
  }


  return 0;
}


Measured memory_bytes: 256
from itertools import combinations
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(20000000)

n, m, q = map(int, input().split())
abcd = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    abcd.append([a-1, b-1, c, d])

def dfs(A, depth, max_a):
    if depth == n:
        score = 0
        for a, b, c, d in abcd:
            if A[b] - A[a] == c:
                score += d
        return score
    ans = 0
    for i in range(max_a, m+1):
        ans = max(ans, dfs(A + [i], depth+1, i))
    return ans

ans = dfs([1], 1, 1)
print(ans)



Measured memory_bytes: 70644
#include<stdio.h>

int main (void)
{
int a,b;
int x,y,n;
scanf("%d%d",&a,&b);
n=0;

for(x=1;x<a;x++){

        for(y=1;y<=12;y++){

                if(x==y)n++;
                }}
if(a==b||a<b){n++;}
printf("%d\n",n);


return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main(){
	
	string s, t;
	cin >> s >> t;
	REP(i, s.size()) {
		if (s[i] != t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define PII pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int maxn = 510;
const int maxm = 250100;
int maz[maxn][maxn];
int H, W, tot;
PII st[maxm], ed[maxm];
void pt(){
    cout<<"-----------------------\tbegin"<<endl;
    for (int i=1;i<=H;i++){
        for (int j=1;j<=W;j++) cout<<maz[i][j]<<"\t";
        cout<<endl;
    }
    cout<<"-----------------------\tend"<<endl;
}

void work(){
    for (int i=1;i<=H;i++)
        for (int j=1;j<=W;j++){
            scanf("%d",&maz[i][j]);
    }
//    pt();
    tot = 0;
    for (int i=1;i<=H;i++)
        for (int j=1;j<W;j++) if (maz[i][j] & 1){
            st[tot] = mp(i,j);
            ed[tot] = mp(i,j+1);
            tot++;
            maz[i][j+1]++;
            maz[i][j]--;
        }
    for (int i=1;i<H;i++) if (maz[i][W] & 1){
        st[tot] = mp(i,W);
        ed[tot] = mp(i+1,W);
        tot++;
        maz[i+1][W]++;
        maz[i][W]--;
    }
//    pt();
    printf("%d\n",tot);
    for (int i=0;i<tot;i++) printf("%d %d %d %d\n",st[i].fi, st[i].se, ed[i].fi, ed[i].se);
}
int main(){
    while (~scanf("%d%d",&H,&W)) work();
    return 0;
}


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

a = []
for i in range(n):
    num = int(input())
    for j in range(num):
        x, y = map(int, input().split())
        a.append([i, x - 1, y])

m = 0

for i in range(1, 2**n):
    se = format(i, 'b').zfill(n)
    flg = True
    for j in a:
        if se[j[0]] == "1":
            if int(se[j[1]]) ^ j[2] == 1:
                flg = False
                break
    if flg is True:
        m = max([m, se.count("1")])
 
print(m)

Measured memory_bytes: 3064
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int B = 31;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int x[N], y[N], p[N];

bool check(int xx, int yy, int pp){
    return (abs(xx) + abs(yy) <= p[pp+1]-1);
}
 
signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n;  cin >> n;
    int sum = -1;
    for(int i = 1; i <= n; i++){
        cin >> x[i] >> y[i];
        int p = abs((x[i] + y[i]) % 2);
        if(sum == -1)
            sum = p;
        else if(sum != p)
            return cout << -1, 0;
    }
    if(sum == 0){
        cout << B+1 << endl;
        cout << 1 << " ";
    }
    else
        cout << B << endl;
    p[0] = 1;
    cout << 1 << " ";
    for(int i = 1; i < B; i++){
        p[i] = (p[i-1] << 1);   
        cout << p[i] << " "; 
    }
    p[B] = p[B-1] << 1;
    cout << endl;
    for(int i = 1; i <= n; i++){
        vector<char> s(B, 'c');
        if(sum == 0){
            if(check(x[i] - 1, y[i], B-1)){
                x[i] -= 1;
                cout << 'R';
            }
            else if(check(x[i] + 1, y[i], B-1)){
                x[i] += 1;
                cout << 'L';
            }
            else if(check(x[i], y[i] - 1, B-1)){
                y[i] -= 1;
                cout << 'U';
            }
            else if(check(x[i], y[i] + 1, B-1)){
                y[i] += 1;
                cout << 'D';
            }
        }
        //cout << x[i] << " " << y[i] << endl;
        for(int b = B-1; b >= 0; b--){
            if(check(x[i] - p[b], y[i], b-1)){
                x[i] -= p[b];
                s[b] = 'R';
            }
            else if(check(x[i] + p[b], y[i], b-1)){
                x[i] += p[b];
                s[b] = 'L';
            }
            else if(check(x[i], y[i] - p[b], b-1)){
                y[i] -= p[b];
                s[b] = 'U';
            }
            else if(check(x[i], y[i] + p[b], b-1)){
                y[i] += p[b];
                s[b] = 'D';
            }
            //cout << x[i] << " " << y[i] << endl;
        }
        for(int b = 0; b <= B-1; b++)
            cout << s[b];
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
N, M = map(int, input().split())
A = list(map(int, input().split()))

sum_A = sum(A)

bool_list = []

for i in range(len(A)):
    if A[i] >= (sum_A / (4*M)):
        bool_list.append("T")

    else:
        continue


if bool_list.count("T") >= M:
    print("Yes")

else:
    print("No")



Measured memory_bytes: 3060
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = long long;
// using ll = boost::multiprecision::int128_t;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;


int main() {
  ll a; ld b; cin >> a >> b;
  ll ans = a * round(b * 100) / 100;

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3756
use proconio::input;

fn main() {
    input! {
        a: i64,
        v: i64,
        b: i64,
        w: i64,
        t: i64,
    }

    let distance_between_a_and_b = (a - b).abs();
    let speed_diference_between_a_and_b = v - w;
    let ans = if speed_diference_between_a_and_b * t >= distance_between_a_and_b {
        "YES"
    } else {
        "NO"
    };

    println!("{}", ans);
}


Measured memory_bytes: 2152
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e5;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<62);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
const ll N=26;
ll solve(ll D,vii &A,vi &C,vi &S){
    vi last(N,-1);
    ll a=0;
    rep(i,0,D){
        ll memo; memo=S[i];
        ll X=i-last[memo]-1;
        a-=X*(X+1)/2*C[memo];
        last[memo]=i;
        a+=A[i][memo];
    }
    rep(i,0,N){
        ll X=D-last[i]-1;
        a-=X*(X+1)/2*C[i];
    }
    return a;
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    srand((unsigned)time(NULL));
    ll D; cin>>D;
    rep(i,0,100) rand();
    vi C(N);
    rep(i,0,N) cin>>C[i];
    vii A(D,vi(N));
    rep(i,0,D){
        rep(j,0,N) cin>>A[i][j];
    }
    vi last(N,-1);
    vi ans(D);
    rep(i,0,D){
        ll max=0,memo=0;
        rep(j,0,N){
            if(max<A[i][j]+(i-last[j])*C[j]){
                max=A[i][j]+(i-last[j])*C[j];
                memo=j;
            }
        }
        last[memo]=i;
        ans[i]=memo;
    }
    ll max=solve(D,A,C,ans);
    ll cnt=0;
    while(cnt<=150000000){
        ll X=rand()%D,Y=rand()%N;
        if(ans[X]==Y) continue;
        ll old=ans[X];
        ans[X]=Y;
        ll sum=solve(D,A,C,ans);
        if(max<sum){
            max=sum;
        }
        else{
            ans[X]=old;
        }
        cnt+=D+N;
    }
    rep(i,0,D) cout<<ans[i]+1<<endl;
}


Measured memory_bytes: 3756
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int[] a = new int[2];
		while(true) {
			for(int i = 0; i<2; i++) {
				 a[i] = sc.nextInt();
			}
		  Arrays.sort(a);

		 if(a[0]==0 && a[1] ==0)break;
		 System.out.println(a[0] +" " + a[1]);

		}


    }

}


Measured memory_bytes: 36084
import math

A,B,H,M = map(int,input().split())
theta1 = (30*H)+(0.5*M)
theta2 = 6*M

theta = min(abs(theta1-theta2),360-abs(theta1-theta2))
X = math.sqrt((A**2)+(B**2)-(2*A*B*math.cos(math.radians(theta))))

print(X)

Measured memory_bytes: 80172
#include<stdio.h>

int main()
{
	int ans = 0;
	int i;
	int j;

	for (i = 1; i <= 9; i++)
	{
		for (j = 1; j <= 9; j++)
		{
			ans = i*j;
			printf("%dx%d=%d\n", i, j, ans);

		}
	}

	return 0;
}
	

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define vec vector<ll>
#define ms multiset<ll>
#define f(i,x,n) for(int i=x;i<n;i++)
#define int long long
#define mod 998244353
#define endl "\n"
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int32_t main()
{
    fastio();
    int r;
    cin>>r;
    cout<<3*r*r;
     
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;

class Program
{
    static void Main()
    {
        var ar = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var H = ar[0];
        var W = ar[1];
        var K = ar[2];
        var itemAry = new char[H, W];
        var ans = 0;
        //データ取得
        for (int i = 0; i < H; i++)
        {
            var items = Console.ReadLine().ToCharArray();
            for (int j = 0; j < W; j++) itemAry[i, j] = items[j];
        }
        //全行全列について、塗りつぶしの組み合わせをbit全探索
        //i,j==1のbitを塗りつぶしとする
        for (int i = 0; i < (1 << H); i++)
        {
            for (int j = 0; j < (1 << W); j++)
            {
                var count = 0;
                //今の塗りつぶし状態が条件に合うか走査
                for (int k = 0; k < H; k++)
                {
                    //i行が塗りつぶされている
                    if (((i >> k) & 1) == 1) continue;
                    for (int l = 0; l < W; l++)
                    {
                        if (((j >> l) & 1) == 1) continue;
                        //塗りつぶされておらず、黒
                        if (itemAry[k, l] == '#') count++;
                    }
                }
                if (count == K) ans++;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28236
# frozen_string_literal: true

# Generated by AtcoderGreedy on 2018-05-06
# ARC081 D
# Your code here

$N = gets.chomp.to_i
$S = []
$S << gets.chomp.split('')
$S << gets.chomp.split('')

$cursor = 0
$res = 1

$prev_type = nil

if $N > 1 && $S[0][0] == $S[0][1]
  $res *= 6
  $prev_type = :yoko
  $cursor += 2

elsif $S[0][0] == $S[1][0]
  $res *= 3
  $prev_type = :tate
  $cursor += 1
end

while $cursor < $N

  if $S[0][$cursor] == $S[1][$cursor]
    $res *= if $prev_type == :yoko
              1
            else
              2
            end
    $prev_type = :tate
    $res %= 1_000_000_007
    $cursor += 1
  else
    $res *= if $prev_type == :yoko
              3
            else
              2
            end
    $prev_type = :yoko
    $res %= 1_000_000_007
    $cursor += 2
  end
end
puts $res


Measured memory_bytes: 1788
use std::io::*;
use std::str::*;

// const MOD: i32 = 1000000007;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let a: usize = read().unwrap();
    let b: usize = read().unwrap();
    let x: usize = read().unwrap();

    if a > x {
        println!("NO");
        return;
    }

    if a + b >= x {
        println!("YES");
        return;
    }
    println!("NO");
}


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

#define ll long long

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

	int n;
	string s;
	cin >> n >> s;

	int a[3][n];
	a[0][n - 1] = s[n - 1] == 'R';
	a[1][n - 1] = s[n - 1] == 'G';
	a[2][n - 1] = s[n - 1] == 'B';
	for (int i = n - 2; i >= 0; --i) {
		if (s[i] == 'R') {
			a[0][i] = a[0][i + 1] + 1;
			a[1][i] = a[1][i + 1];
			a[2][i] = a[2][i + 1];
		} else if (s[i] == 'G') {
			a[0][i] = a[0][i + 1];
			a[1][i] = a[1][i + 1] + 1;
			a[2][i] = a[2][i + 1];
		} else if (s[i] == 'B') {
			a[0][i] = a[0][i + 1];
			a[1][i] = a[1][i + 1];
			a[2][i] = a[2][i + 1] + 1;
		}
	}

	ll cnt = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n - 1; ++j) {
			if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
				cnt += a[2][j + 1];
				if (s[j + (j - i)] == 'B') --cnt;
			} else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) {
				cnt += a[1][j + 1];
				if (s[j + (j - i)] == 'G') --cnt;
			} else if ((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G')) {
				cnt += a[0][j + 1];
				if (s[j + (j - i)] == 'R') --cnt;
			}
		}
	}
	cout << cnt;
}


Measured memory_bytes: 3660
#-----combination計算部分------
def cmb(n, r):
    #if ( r<0 or r>n ):
    #    return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6*2+2
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

#入力
r1,c1,r2,c2 = map(int, input().split())

def g(r,c):
    gsum = 0
    for i in range(1,r+2):
        gsum += cmb(i+c,c)
    return gsum
'''
sum = 0
for r in range(r1,r2+1):
    for c in range(c1,c2+1):
        sum += cmb(r+c,r)
print(sum % mod)
'''
sum2 = g(r2,c2) - g(r1-1,c2) - g(r2,c1-1) + g(r1-1,c1-1)
print(sum2 % mod)

Measured memory_bytes: 132908
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i < en; i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)

#define int long long
int32_t main(){ fast;
	
	int n, k; cin>>n>>k;
	if(n % k == 0){
		cout<<0;
	}
	else{
		int up = (n / k + 1) * k;
//		cout<<abs(up - (n % k))<<endl;
		cout<<min(up - n, n % k)<<endl;
	}
}


Measured memory_bytes: 256
# include <stdio.h>
int main(void){
    int k,a,b,i;
    scanf("%d",&k);
    scanf("%d %d",&a,&b);
    for(i=0;i<1000;i++){
        if(i*k>b){
            printf("NG");
            return 0;
        }else if(i*k>=a && i*k<=b){
            printf("OK");
            return 0;
        }
    }
}


Measured memory_bytes: 1732
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#define ll long long int
#define N 100005
using namespace std;
vector<int> k[3];
ll dp[3][N];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<3;i++){
        for(int j=0;j<n;j++){
            int x;
            cin>>x;
            k[i].push_back(x);
        }
        sort(k[i].begin(),k[i].end());
    }
    dp[0][0]=1;
    for(int i=1;i<n;i++)
        dp[0][i]=dp[0][i-1]+1;

    for(int i=1;i<3;i++){
        for(int j=0;j<n;j++){
            int x=lower_bound(k[i-1].begin(),k[i-1].end(),k[i][j])-k[i-1].begin();
            dp[i][j]+=dp[i-1][x-1];
        }
        for(int t=1;t<n;t++)
            dp[i][t]+=dp[i][t-1];
    }
    cout<<dp[2][n-1]<<endl;
    return 0;
}

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

int main(){
	string s;cin>>s;
	if(s=="A")puts("T");
	if(s=="T")puts("A");
	if(s=="G")puts("C");
	if(s=="C")puts("G");
}

Measured memory_bytes: 256
#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {for(auto x : v) cout << x << ' '; cout << endl;}
#define printn(v, n) {for(int _i = 0; _i < n; _i++) cout << *(v + _i) << ' '; cout << endl;}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
 
const int MAXN = 1e3 + 20;

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

    int n;
    long long a[MAXN];
    cin >> n;

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

    return 0;
}











Measured memory_bytes: 256
N = gets.to_i
A = gets.chomp.split.map(&:to_i).sort
ans = A[0]

(1..N-1).each do |i|
  ans *= A[i]
  break if ans > 10**18 || ans ==0
end

if ans > 10**18
  puts -1
else
  puts ans
end
 


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

int main(){
  int n, k; cin >> n >> k;
  
  int x=1;
   for(int i=0; i<n; i++)
  x = min(x+k, 2*x);
  
  cout << x << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;
    vector<ll> a(N);
    Rep (i, N) cin >> a[i];

    ll ans = 0;
    Rep (i, N-1) {
        if (a[i] == a[i+1]) {
            ans++;
            a[i+1] = 1000;
            // cout << i << "\n";
        }
    }

    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define FOR(s,e,i) for (int i = s; i <= e; ++i)

int N;
ll ct[26];
ll sum = 0;

void d(int x, int len, ll count){	//pos, remaining length
	if (1 == len){
		count = (count * ct[x])%MOD;
		sum = (sum + count) % MOD;
		return;
	}
	FOR(x+1,27-len,i){
		if (ct[i]) d(i,len-1,(count*ct[x])%MOD);
	}
}

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;	cin.ignore();
	char ch;
	FOR(1,N,i){
		cin >> ch;
		ct[(int)(ch-'a')]++;
	}
	//FOR(0,25,i) cout << ct[i] << " "; cout << '\n';
	FOR(1,26,i)	//length
	FOR(0,26-i,j)	//starting point
		d(j,i,1);
	cout << sum%MOD << '\n';
	return 0;
}

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

#define maxn 400010
#define LL long long
#define inf 10000000000
#define mod 1000000007
#define pi 3.14159265359
using namespace std;
int dx[24] = { 1,0,-1,0 ,2,0,-2,0 ,-1,-1,-2,-2 ,1,1,2,2    ,-1,-1,-2,-2 ,1,1,2,2 };
int dy[24] = { 0,1,0,-1 ,0,2,0,-2 ,-1,-2,-1,-2 ,-1,-2,-1,-2,1,2,1,2     ,1,2,1,2  };


LL n, m, k;
LL arr[maxn];
LL arr2[maxn];
//int visit[maxn];
//int cache[maxn];
//int c[maxn];
//int g[maxn];
//int dfsnum = 0;
//vector<vector<int>>rvi;
//vector<vector<int>>scc;
//vector<pair<int, int>>ett;
//stack<int>st;
//bool flg = 1;
//LL s, d;
//
//int findp(int a) {
//	if (c[a] <0)return a;
//	return c[a] = findp(c[a]);
//}
//void unionp(int a, int b) {
//	a = findp(a);
//	b = findp(b);
//
//	if (a != b) {
//		c[a] += c[b];
//		c[b] = a;
//	}
//
//}
//LL power(LL x, LL y) {
//	LL ret = 1;
//	while (y > 0) {
//		if (y % 2) {
//			ret *= x;
//			ret %= mod;
//		}
//		x *= x;
//		x %= mod;
//		y /= 2;
//	}
//	return ret;
//}
//void dfs2(int v) {
//	cache[v] = 1;
//	scc.back().push_back(v);
//	for (int nv : rvi[v]) {
//		if (cache[nv])continue;
//		dfs2(nv);
//	}
//
//}
//LL fac(LL n) {
//	if (n == 1) return 1;        
//	return (n * fac(n - 1) - power(2,n-1) )%mod;
//}
//int fac2(LL n) {
//	LL res, i;
//	if (n == 1)return n;
//	res = n;
//	for (int i = n - 1; i > 0; --i) {
//		res *= i;
//		res %= mod;
//	}
//	return res;
//}

LL gcd(LL a, LL b) {
	while (b != 0) {
		LL r = a % b;
		a = b;
		b = r;
	}
	return a;
}


int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	//int t;   cin >> t; cin.ignore();
	int t = 1;
	for (int test_case = 0; test_case < t; ++test_case) {
		int flg = 0;
		LL ans1 = 0, ans2 = 0;
		string ans[2] = { "No","Yes" };
		string s1, s2 = "";
		cin >> n;
		for (int i = 0; i < n; ++i) {
			cin >> arr[i];
		}

		arr2[0] = arr[0];
		for (int i = 1; i < n; ++i) {
			arr2[i] = (arr[i] + arr2[i - 1])%mod;
		}
		for (int i = 0; i < n; ++i) {
			ans1 = (ans1%mod+((arr2[n-1] - arr2[i])*arr[i])%mod)%mod;
			if (ans1 < 0)ans1 += mod;
		}
		cout << ans1%mod;
		cout << '\n';

	}
	return 0;
}


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

int main(){
  int n;
  scanf("%d",&n);

  int ans=0;
  if(n%10==7 || (n%100)/10==7 || n/100==7){
    printf("Yes\n");}
  else{
    printf("No\n");}
  
  return 0;
}


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

using namespace std;

int main() {
	string S;
	long long int N, M;
	cin >> N >> M;
	if( M == N ) {
		cout << "Draw" << endl;
	} else if(M==1 || (M > N&&N!=1) ) {
		cout << "Bob" << endl;
	} else {
		cout << "Alice" << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int allSec;
	int hour , min , sec;
	scanf("%d" , &allSec);
	hour = allSec / 3600;
	allSec = allSec % 3600;
	min = allSec / 60;
	sec = allSec % 60;
	printf("%d:%d:%d\n" , hour , min , sec);
	return 0;
}

Measured memory_bytes: 592
# from math import gcd
# *ただし現時点(2019/12/06)でのatcoderはver.ひとつ前のpythonなので
from fractions import gcd
n = int(input())
ans = 1
for i in range(n):
    a = int(input())
    ans = a * ans // gcd(a, ans)
print(ans)

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

LL n, t;
LL snow;
LL sbefore = 0;
LL sum = 0;

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

  REP(i, n) {
    scanf("%lld",&snow);
    if (snow - sbefore >= t) sum += t;
    else sum += snow - sbefore;
    sbefore = snow;
  }
  sum += t;

  printf("%lld\n",sum);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
long long read()
{
	char ch=getchar();long long x=0,ff=1;
	while(ch<'0'||ch>'9') {if(ch=='-') ff=-ff;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*ff;
}
void write(long long aa)
{
	if(aa<0) putchar('-'),aa=-aa;
	if(aa>9) write(aa/10);
	putchar(aa%10+'0');
	return;
}
long long n;
long long bin[5],ans;
long long a[405][4],A[4],B[4];
unordered_map<long long,long long>mp;
long long gao(long long aa,long long bb)
{
	long long qwq=0;
	for(long long j=0;j<4;++j) qwq+=bin[j]*a[aa][(bb+j)%4];
	return qwq;
}
long long md(long long aa,long long bb,long long cc)
{
	a[n+1][0]=A[aa];a[n+1][1]=B[aa];
	a[n+1][2]=B[bb];a[n+1][3]=A[bb];
	long long tmp=mp[gao(n+1,0)];
	for(long long i=0;i<4;++i) mp[gao(n+1,i)]-=cc;
	return tmp;
}
void getans()
{
	ans+=1ll*md(0,1,1)*md(1,2,1)*md(2,3,1)*md(3,0,1);
	md(0,1,-1);md(1,2,-1);md(2,3,-1);md(3,0,-1);
	return;
}
int main()
{
	n=read();bin[0]=1;
	for(long long i=1;i<4;++i) bin[i]=bin[i-1]*1000;
	for(long long i=1;i<=n;++i) 
	{
		for(long long j=0;j<4;++j) a[i][j]=read();
		for(long long j=0;j<4;++j) mp[gao(i,j)]++;
	}
	for(long long i=1;i<=n;++i)
	{
		for(long long j=0;j<4;++j) mp[gao(i,j)]--,A[j]=a[i][j];
		for(long long j=i+1;j<=n;++j)
		{
			for(long long l=0;l<4;++l) mp[gao(j,l)]--;
			swap(a[j][0],a[j][1]);swap(a[j][2],a[j][3]);
			for(long long l=0;l<4;++l)
			{
				for(long long k=0;k<4;++k) B[k]=a[j][(k+l)%4];
				getans();
			}
			swap(a[j][0],a[j][1]);swap(a[j][2],a[j][3]);
			for(long long l=0;l<4;++l) mp[gao(j,l)]++;
		}
		for(long long j=0;j<4;++j) mp[gao(i,j)]++;
	}
	write(ans/3);
	return 0;
}

Measured memory_bytes: 239448
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// use std::io::{stdout, Write, BufWriter};
// use std::cmp::{max, min};

fn main() {
    input! {
        x_1: i32,
        y_1: i32,
        x_2: i32,
        y_2: i32,
    }
    println!("{} {} {} {}", y_1 + x_2 - y_2, -x_1 + x_2 + y_2, x_1 + y_1 - y_2, -x_1 + y_1 + x_2)
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 100
#define Pair pair<int,int>

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main(){
    ll n; cin >> n;
    ll a[n];
    map<ll,ll> mp;
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(mp[a[i]] == 0){
            mp[a[i]]++;
            sum++;
        } else {
            mp[a[i]]--;
            sum--;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 7296
#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 FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>bool chmax(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    string s;
    cin>>s;
    int n=sz(s);
    int ans=0;
    rep(i,n/2) {
        if(s[i]!=s[n-1-i]) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int n,i;
  long long l[3];
  l[0]=2;
  l[1]=1;
  scanf("%d",&n);
  for (i=0;i<n;i++) {
    l[2]=l[0]+l[1];
    l[0]=l[1];
    l[1]=l[2];
  }
  printf("%lld\n",l[0]);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}


signed main(){
  int n;cin>>n;
  int ans = 0, a = 0, b = 0, ab = 0;
  rep(i,n){
    string s;cin>>s;
    if(s[s.length()-1] == 'A' && s[0] == 'B')ab++;
    else{
      if(s[s.length()-1] == 'A')a++;
      if(s[0] == 'B')b++;
    }
    rep(j,s.length()-1){
      if(s[j] == 'A' && s[j+1] == 'B')ans++;
    }
  }
  if(a){
    a--;
    while(ab){
      ans++;ab--;
    }
    if(b){
      b--;ans++;
      while(a && b){
        a--;b--;ans++;
      }
      cout << ans << endl;
      return 0;      
    }else{
      cout << ans << endl;
      return 0;
    }
  }else if(ab){
    ab--;
    while(ab){
      ans++;ab--;
    }
    if(b){
      b--;ans++;
      while(a && b){
        a--;b--;ans++;
      }
      cout << ans << endl;
      return 0;      
    }else{
      cout << ans << endl;
      return 0;
    }
  }else{
      cout << ans << endl;
      return 0;
  }
}


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

int main(){
  long i, o, t, j, l, s, z;
  cin >> i >> o >> t >> j >> l >> s >> z;
  if(i>=1 && j>=1 && l>=1)cout << o+max(2*(i/2+j/2+l/2), 2*((i-1)/2+(j-1)/2+(l-1)/2)+3);
  else cout << (i/2)*2+o+(j/2)*2+(l/2)*2;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()

#define MAX_N 600
#define MAX_M 10100
int a[MAX_M];
int b[MAX_M];

int main() {
  while (true) {
    bool isMyfriend[MAX_N+1] = {false};
    bool isKnown[MAX_N+1] = {false};

    int n; cin >> n;
    int m; cin >> m;
    if (n == 0 && m == 0) break;

    // find friends
    rep(i, m) {
      cin >> a[i] >> b[i];
      // a < b
      if (a[i] == 1) {
        isMyfriend[b[i]-1] = true;
      }
    }
    // find friend's friends
    rep(i, m) {
      // a <-> b
      // count: 1 <-> x
      // count: _ <-> x
      rep(x, n) {
        if (isMyfriend[x] && ((a[i]-1)==x || (b[i]-1)==x)) {
          isKnown[a[i]-1] = true;
          isKnown[b[i]-1] = true;
        }
      }
    }

    int count = 0;
    for (int i=1; i<n; i++) {
      if (isMyfriend[i] || isKnown[i]) {
        // cout << "!" << i << endl; // DEBUG
        count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 1276
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try{
	    String st;
	    ArrayList<Double> num = new ArrayList<Double>();
	    while((st=sc.readLine())!=null)
		num.add(Double.valueOf(st));
	    double[] ini = new double[num.size()];
	    for(int i=0; i<ini.length; i++)
		ini[i] = num.get(i);
	    Arrays.sort(ini);
	    System.out.println(ini[ini.length-1]-ini[0]);
	}catch (Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 8828
N=int(input())
import copy
S=list(input())
F=[]
E=[]
L=[0 for i in range(10)]
for i in range(N):
    L[int(S[i])]=1
    F.append(copy.deepcopy(L))
#print(F)
RS=S[::-1]
L=[0 for i in range(10)]
for i in range(N):
    L[int(RS[i])]=1
    E.append(copy.deepcopy(L))
E=E[::-1]
D={}
for i in range(1,N-1):
    for f in range(10):
        if F[i-1][f]==1:
            for e in range(10):
                if E[i+1][e]==1:
                    if (f,S[i],e) not in D:
                        D[(f,S[i],e)]=1
print(len(D))
    
#print(E)

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

int main() {
  int a,b; cin >> a >> b;
  cout << max(0, a-b*2) << endl;;
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
def check():
  N = int(input())
  A = list(map(int, input().split()))
  if N%3 in [1,2]:
    if A!=[0]*N:
      return 'No'
    return 'Yes'
  c = Counter(A)
  if len(c)==1:
    if c[0]==0:
      return 'No'
    return 'Yes'
  if len(c)==2:
    if c[0]!=N//3:
      return 'No'
    return 'Yes'
  if len(c)==3:
    lis = []
    for k,v in c.items():
      if v!=N//3:
        return 'No'
      lis.append(k)
    if lis[0]^lis[1]==lis[2]:
      return 'Yes'
  return 'No'
print(check())

Measured memory_bytes: 20648
/*                          The four Truths of Life
                                  
                                    CKMKB
                                    PKMKB
                                  
                                    CKMKC
                                    PKMKC
*/


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define ye cout<<"YES";
#define no cout<<"NO";
#define ln cout<<"\n";
// cout<<"Case #"<<ts<<": “;
//priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;


using namespace std;

ll mod(ll x, ll m) {
    return (x%m + m)%m;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

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

	ll t = 1, r, n, a, d, c, b, x, y, sum, cnt, i, j, k, m, l, q, maxx, minn, temp, ans, flag, g, ts;
	ll mod = 1000000007;
	char ch, chh;
	double dans;
	string str, ttr;

//	cin >> t;


	for (ts = 1; ts <= t; ts++)
	{
		flag = 0; sum = 0; cnt = 0; ans = 0; k = 0; maxx = 0; minn = 0; a = 0; b = 0; temp = 0;

		cin >> str>>ttr;
	//	ll arr[n]; for (i = 0; i < n; i++) {cin >> arr[i];}

        for(i=0;i<str.size();i++)
        {
            if(str[i]!=ttr[i])
            {
                ans++;
            }
        }
        cout<<ans;

		ln
	}
	return 0;
}


Measured memory_bytes: 3808
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    long H;
    cin >> H;

    int cnt = 0;
    while (H > 1) {
        H = floor(H / 2);
        cnt++;
    }

    long ans = pow(2, cnt) * 2 - 1;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

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

    int mi = INT_MAX, ma = INT_MIN;
    REP(i, n){
        int tmp;
        cin >> tmp;
        ma = max(ma, tmp - mi);
        mi = min(mi, tmp);
    }
    cout << ma << endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pll = pair<ll, ll>;

#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair


template <typename T>
using vv = vector<vector<T>>;

const ll MX = 3010;

ll dp[4][MX][MX];
ll field[MX][MX];

void solve() {
    int n, m, k; cin >> n >> m >> k;
    for (int i = 0; i < k; i++) {
        ll a, b, c; cin >> a >> b >> c;
        field[a][b] = c;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            for (int cnt = 0; cnt <= 3; cnt++) {
                ll res = 0;
                res = max(res, dp[cnt][i][j - 1]);
                for (int z = 0; z <= 3; z++)
                    res = max(res, dp[z][i - 1][j]);
                if (cnt > 0 && field[i][j] > 0) {
                    res = max(res, dp[cnt - 1][i][j - 1] + field[i][j]);
                    for (int z = 0; z <= 3; z++)
                        res = max(res, dp[z][i - 1][j] + field[i][j]);
                }
                dp[cnt][i][j] = res;
            }
        }
    }

    ll res = 0;
    for (int i = 0; i <= 3; i++) res = max(res, dp[i][n][m]);
    cout << res;
}



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
}


Measured memory_bytes: 356044
import math

N, D = map(int, input().split())
X = []
cnt = 0
for i in range(N):
    X.append(list(map(int, input().split())))
for i in range(1, N):
    for j in range(i):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[j][k])**2
        for l in range(d+1):
            if l**2 == d:
                cnt += 1
                break
print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;

struct data{
	int x;
	int y;
};	

bool order(data a,data b){
	if(a.y==b.y)a.x<b.x;
	return a.y<b.y;
}

int main(){
	int n;
	while(scanf("%d",&n)==1,n){
		vector<data> table;
		for(int x=0;x<n;++x){
			data nv;
			scanf("%d %d",&nv.x,&nv.y);
			table.push_back(nv);
		}	
		sort(table.begin(),table.end(),order);
		int acum = 0;
		while(table.size()>0){
			acum += table[0].x;
			if(acum>table[0].y)break;
			table.erase(table.begin()+0);
		}
		if(table.size()==0){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}	
	}
	return 0;
}

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

using namespace std;

int main(void)
{
    vector<int> v;
    
    for(int i = 0;i < 3;i++)
    {
	int temp;
	cin>>temp;
	v.push_back(temp);
    }

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

    cout<<v[0]+v[1]<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD (long long)(1e9+7)
int main(){
	ll a[3],b[3];
	for(int i=0;i<3;i++)cin>>a[i]>>b[i];
	vector<int> cnt(4,0);
	for(int i=0;i<3;i++){
		cnt[a[i]-1]++;
		cnt[b[i]-1]++;
	}
	sort(cnt.begin(),cnt.end());
	if(cnt[0]==1&&cnt[1]==1&&cnt[2]==2&&cnt[3]==2){
		cout<<"YES"<<endl;
	}
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  int N;
  cin>>N>>S;
  if(N%2!=0){
    cout<<"No"<<endl;
    return 0;
  }
  int K=N/2;
  if(S.substr(0,K)==S.substr(K,K)){
  	cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

using namespace std;

void solve()
{
	int N, A, B, C, X;
	while(cin >> N >> A >> B >> C >> X)
	{
		if(!N && !A && !B && !C && !X)
		{
			break;
		}
		vector<int> Vec(N);
		for(int i = 0; i < N; ++i)
		{
			cin >> Vec[i];
		}
		int count = 0;
		for(int i = 0; i < N; ++i)
		{
			while(Vec[i] != X)
			{
				X = (A * X + B) % C;
				++count;
				if(count > 10000)
				{
					cout << -1 << endl;
					goto NEXT;
				}
			}
			X = (A * X + B) % C;
			++count;
		}
		cout << count - 1 << endl;
NEXT:
		;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 908
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int q;scanf("%d",&q);
	while(q--)
	{
		int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
		int k=(max(a,b)-1)/(min(a,b)+1)+1,n=a+b;
		int l=1,r=n+1;
		while(l<r)
		{
			int mid=(l+r)>>1;//mid A,mid+1 B
			int A=mid/(k+1)*k+mid%(k+1)+(n-mid-1)/(k+1);
			if(A>=a)r=mid;
			else l=mid+1;
		}
		int k1=l/(k+1)*(k+1)+1,k2=n-(n-l)/(k+1)*(k+1),A=a-((n-k2)/(k+1)+k1/(k+1)*k)+k1-1;
//		cout<<k1<<' '<<k2<<" "<<A<<" "<<l;
		for(int i=c;i<=min(k1-1,d);i++)if(i%(k+1))printf("A");else printf("B");
		if(d>=k1&&c<=k2)for(int i=max(k1,c);i<=min(k2,d);i++)if(i<=A)printf("A");else printf("B");
		for(int i=max(k2+1,c);i<=d;i++)if((n-i+1)%(k+1))printf("B");else printf("A");
		puts("");
	}
	return 0;
}//AAAAB.....AAAAB AABBB(这里至少有一个B) ABBBB.....ABBBB
//AABAABABBABBABBABB

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
const long long INF = 1e12;
int main() {
    ll s,w;
    cin >>s >> w;
    if(w>=s)cout <<"unsafe"<<endl;
    else cout << "safe"<<endl;
}

Measured memory_bytes: 3640
n,m=map(int,input().split())
ans=[]
ab=[list(map(int,input().split()))for _ in range(n)]
cd=[list(map(int,input().split()))for _ in range(m)]
for a,b in ab:
  anss=0
  mm=10**20
  for i in range(m):
    mmm=abs(a-cd[i][0])+abs(b-cd[i][1])
    if mm>mmm:
      anss=i+1
      mm=mmm
  ans.append(anss)
print(*ans)

Measured memory_bytes: 3188
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    long long n, k;
    cin >> n >> k;
    map<long long, long long> nums;
    FOR(i, 0, n) {
        long long a, b;
        cin >> a >> b;
        nums[a] += b;
    }
    long long cnt = 0;
    long long res = 0;
    for (auto t : nums) {
        cnt += t.second;
        if (cnt >= k) {
            res = t.first;
            break;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int x;

int main() {
	fastio; cin >> x;
	cout << 360/gcd(x, 360);
}


Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <sstream>

int main()
{
	int n; std::cin >> n;
	for (int i=0; i<n; i++) {
		int s; std::cin >> s;
		std::cout << "Case " << i+1 << ":" << std::endl;
		for (int j=0; j<10; j++) {
			s *= s;
			std::ostringstream oss;
			oss << std::setw(8) << std::setfill('0') << s;
			s = std::stoi(oss.str().substr(2,4));
			std::cout << s << std::endl;
		}
	}
	
	return 0;
}




Measured memory_bytes: 3148
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

int main() {
    string s;
    int k;
    cin >> s;
    cin >> k;
    int n = s.size();
    vector<string> v;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < min(i+k+1, n+1); j++) {
            string t = s.substr(i, j-i);
            v.emplace_back(t);
        }
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    cout << v[k-1] << endl;
    return 0;
}


Measured memory_bytes: 1660