akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];

	int sum = 0;
	rep(i,n) {
		sum += a[i];
	}

	std::vector<int> factors;
	for(int i=1;i*i<=sum;i++) {
		if(sum%i==0) {
			factors.emplace_back(i);
			factors.emplace_back(sum/i);
		}
	}
	std::sort(all(factors),std::greater<int>());
	for(int i:factors) {
		std::vector<int> b(n);
		rep(j,n) b[j] = a[j]%i;
		std::sort(all(b));
		std::vector<int> d(n);
		std::vector<int> p(n);
		{
			int accum;
			accum = 0;
			rep(j,n) {
				accum += b[j];
				d[j] = accum;
			}
			accum = 0;
			rep(j,n) {
				accum += i-b[j];
				p[j] = accum;
			}
		}
		rep(j,n) {
			if(d[j] == p[n-1] - p[j]) {
				if(d[j]<=k) {
					print(i);
					return 0;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
ans :: [[String]] -> [Double]
ans (["0"]:_) = []
ans (n:v:is) =
  let l = read (n!!0) :: Double
      i = map read v :: [Double]
      a = (sum i) / l
      s = foldl (\s d -> s + (d-a)*(d-a) ) 0 i
      o = sqrt $ s / l
  in
    o:(ans is)

main = do
  c <- getContents
  let i = map words $ lines c
      o = ans i
  mapM_ print o

Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>

using namespace std;

//int main() {
//	long long n;
//	while (~scanf("%lld", &n)) {
//		printf("%lld\n", n * (n + 1) / 2); 
//	}
//	return 0;
//}

int main() {
	char ch = getchar();
	if (ch >= 'a') puts("a");
	else puts("A");
	return 0;	
}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
int main(){
   int a=0,b=0,ans=0;
   char op;
   scanf("%d %c%d",&a,&op,&b);
   if(op=='+'){
		ans=a+b;
     printf("%d",ans);
       
   } 
   if(op=='-'){
		ans=a-b;
     printf("%d",ans);
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=100010;
int n;
LL a[maxn],b[maxn];
map<LL,int> hs;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		LL x;
		scanf("%lld",&x);
		for(LL j=2;j*j*j<=x;++j){
			while(x%(j*j*j)==0)x/=j*j*j;
		}
		a[i]=x;
		hs[x]++;
		LL y=1;
		for(LL j=2;j*j*j<=x;++j){
			if(x%j==0){
				y*=(x%(j*j))==0?j:j*j;
			}
			while(x%j==0)x/=j;
		}
		if((LL)sqrt(x)*(LL)sqrt(x)==x)y*=(LL)sqrt(x);
		else y*=x*x;
		b[i]=y;
	}
	int ans=0;
	if(hs[1]>0)ans++,hs[1]=0;
	for(int i=1;i<=n;++i)ans+=max(hs[a[i]],hs[b[i]]),hs[a[i]]=0,hs[b[i]]=0;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定

#define ll long long int
#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時

using namespace std;

double PI = 3.141592653589793; //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a,b);
}

//degree → radian
ll chg_DegRad(ll deg) {
	return deg * PI / 180.0;
}

//radian → degree
ll chg_RadDeg(ll rad) {
	return rad * 180.0 / PI;
}

//提出コード↓

ll a, b, k;



int main() {
	
	cin >> a >> b >> k;
	if (a >= k)  a = a - k;
	else {
		k = k - a;
		a = 0;
		if (b >= k) b = b - k;
		else b = 0;
	}
	cout << a << ' ' << b << endl;



	return 0;
}





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

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define lp(start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}
ll cn[100007];
ll sum;
int main()
{
	fastio
	ll n;
	cin >> n;
	ll arr[n+1];
	for(ll i=1;i<=n;i++){
		cin >> arr[i];
		sum+=arr[i];
		cn[arr[i]]++;
	}

	ll q;
	cin >> q;
	while(q--)
	{
		ll b,c;
		cin >> b >> c;
		ll bc = cn[b];
		cn[b]=0;
		cn[c]+=bc;
		sum += (bc*(c-b));

		cout << sum << endl;
	}
	return 0;	
}


Measured memory_bytes: 5168
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 1e5 + 10;
vector<int> g[MAX_N];
int dp[MAX_N], used[MAX_N];
int ret = 0;

void dfs(int x) {
    if(used[x]) {return;}
    used[x] = true;
    for(auto it : g[x]) {
        dfs(it);
        chkmax(dp[x], dp[it] + 1);
    }
    chkmax(ret, dp[x]);
}

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i ++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
    }
    for(int i = 1; i <= n; i ++) {
        dfs(i);
    }
    cout << ret;
    return 0;
}




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

int main() {
int N;
cin >> N;
vector<int64_t> vec;
 vec.push_back(2);
 vec.push_back(1);

for(int i=2; i<N+1; i++){
 vec.push_back(vec.at(i-1)+vec.at(i-2));
}
cout <<  vec.at(N) <<endl;
}

Measured memory_bytes: 256
class PriorityQueue
  #?????????
  def initialize
    @queue = Array.new
  end

  #???????????????????´??????????
  def top
    @queue[0]
  end

  #???????????????????´??????????????????????????´??????????
  def pop
    top = @queue[0]
    n = @queue.size - 1

  end

  #?????§?????´??°
  def max_heap_fy(i)
    l = 2 * i
    r = 2 * i + 1
    if l<= @queue.size && @queue[l] > @queue[i] then largest = l
    else largest = i end
    largest = r if r <= @queue.size && @queue[r] > @queue[largest]
    if largest != i then
      @queue[i],@queue[largest] = @queue[largest],@queue[i]
      max_heap_fy(largest)
    end
  end
end


def max_heap_fy(i)
  l = 2 * i
  r = 2 * i + 1
  if l<= @h && @que[l] > @que[i] then largest = l
  else largest = i end
  largest = r if r <= @h && @que[r] > @que[largest]
  if largest != i then
    @que[i],@que[largest] = @que[largest],@que[i]
    max_heap_fy(largest)
  end
end

@h = gets.to_i
@que = gets.split.map(&:to_i)
@que.insert(0,-114514)
(@h / 2).downto(1)do |i|
  max_heap_fy(i)
end
puts " #{@que[1..@que.size - 1].join(" ")}"


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

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> ans(3);
    bool det = true;
    for(int i = 0; i < 3; i++)ans.at(i) = -1;
    for(int i = 0; i < m; i++){
        int buf_s,buf_c;
        cin >> buf_s >> buf_c;
        buf_s--;
        if(ans.at(buf_s) == -1){
            ans.at(buf_s) = buf_c;
        }else{
            if(ans.at(buf_s) != buf_c)det = false;
        }
    }
    if(n != 1 && ans.at(0) == 0)det = false;
    if(n == 2 && ans.at(2) != -1)det =false;
    if(n == 1 && ans.at(2) != -1)det =false;
    if(n == 1 && ans.at(1) != -1)det =false;
    if(det){
        if(ans.at(0) == -1 && n != 1)ans.at(0) = 1;
        if(ans.at(0) == -1 && n == 1)ans.at(0) = 0;
        if(ans.at(1) == -1)ans.at(1) = 0;
        if(ans.at(2) == -1)ans.at(2) = 0;
        for(int i = 0; i < n; i++){
            cout << ans.at(i);
        }
        cout << endl;
    }else{
        cout << -1 << endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    int a, b, c, k; cin >> a >> b >> c >> k;
    ll ans = 0;
    if(k <= a) {
        ans = k;
    } else {
        if(k <= a+b) {
            ans = a;
        } else {
            ans = a - (k-a-b);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
N, H = map(int, input().split())
A = []
B = []

for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

mxA = max(A)
B.sort(reverse=True)

ans = 0
for b in B:
    if b <= mxA or H <= 0:
        break
    H -= b
    ans += 1

if H > 0:
    ans += -(-H // mxA)

print(ans)


Measured memory_bytes: 11268
# author:  Taichicchi
# created: 27.09.2020 23:15:22

import sys

N = int(input())

s = [int(input()) for _ in range(N)]

ls = []

for i in range(N):
    if s[i] % 10 != 0:
        ls.append(s[i])

ls.sort()

base = sum(s)

if base % 10 != 0:
    print(base)
    exit()

if ls:
    print(base - ls[0])
else:
    print(0)


Measured memory_bytes: 9072
process.stdin.resume();
process.stdin.setEncoding('utf8');

var input_lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  input_lines.push(parseInt(line));
});

reader.on('close', () => {
  //console.log(input_lines);
  var a = input_lines[0];
  //console.log(input_lines);
  console.log(a + (a*a) + (a*a*a));

});


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

int main() {
    int N, x = 0, maxx = 0;
    string S;

    cin >> N >> S;

    for (int i = 0; i < N; i++) {
        if (S[i] == 'I') {
            x++;
        } else {
            maxx = max(maxx, x);
            x--;
        }
    }
    maxx = max(maxx, x);
    cout << maxx << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define retrun return
#define cpnst const
typedef long long ll;
ll p,n;
ll C[3333][3333],S2[3333][3333];
ll F[3333];
ll qpow(ll x,ll y,ll m){ll r=1;for(;y;y>>=1,(x*=x)%=m)if(y&1)(r*=x)%=m;return r;}

int main()
{
	register int i,ii;
	scanf("%lld%lld",&n,&p),S2[0][0]=1;
	for(i=0;i<=3005;i++)C[i][0]=C[i][i]=1;
	for(i=1;i<=3005;i++)
		for(ii=1;ii<=3005;ii++)
			C[i][ii]=(C[i-1][ii-1]+C[i-1][ii])%p,S2[i][ii]=(S2[i-1][ii-1]+ii*S2[i-1][ii])%p;
	for(i=0;i<=n;i++)
	{
		ll pw2=1,qw2=qpow(2,n-i,p);
		for(ii=0;ii<=i;ii++,(pw2*=qw2)%=p)(F[i]+=S2[i+1][ii+1]*pw2)%=p;
		F[i]=F[i]*C[n][i]%p*qpow(2,qpow(2,n-i,p-1),p)%p;
	}ll ans=0;
	for(i=0;i<=n;i++)ans+=p+((i&1)?-1:1)*F[i];
	printf("%lld\n",ans%p);
}
/*
Just go for it.
*/

Measured memory_bytes: 158192
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 2005;

int n;
int dp[MAXN][MAXN];
int prec[2][2][MAXN][MAXN];
pi a[MAXN + MAXN];
int loc[2][MAXN];

int f(int x, int y){
	if(x + y == 2 * n) return 0;
	if(~dp[x][y]) return dp[x][y];
	int ret = 1e9;
	if(x + 1 <= n){
		ret = min(ret, f(x + 1, y) + prec[0][0][x+1][x] + prec[0][1][x+1][y]);
	}
	if(y + 1 <= n){
		ret = min(ret, f(x, y + 1) + prec[1][0][y+1][x] + prec[1][1][y+1][y]);
	}
	return dp[x][y] = ret;
}

char buf[5];

int main(){
	memset(dp, -1, sizeof(dp));
	scanf("%d",&n);
	for(int i=1; i<=2*n; i++){
		cin >> buf >> a[i].second;
		if(*buf == 'B') a[i].first = 1;
		loc[a[i].first][a[i].second] = i;
	}
	for(int i=0; i<2; i++){
		for(int j=0; j<2; j++){
			for(int k=1; k<=n; k++){
				int cnt = 0;
				for(int l=1; l<=n; l++){
					if(loc[j][l] > loc[i][k]) cnt++;
					prec[i][j][k][l] = cnt;
				}
			}
		}
	}
	cout << f(0, 0) << endl;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
#define ri register int
using namespace std;
int main()
{
	string str;
	cin>>str;
	string tmp=str;
	reverse(tmp.begin(),tmp.end());
	for(int i=0; i<tmp.size(); i++)
	{
		switch(tmp[i])
		{
			case 'b':
			{
				tmp[i]='d';
				break;
			}
			case 'd':
			{
				tmp[i]='b';
				break;
			}
			case 'p':
			{
				tmp[i]='q';
				break;
			}
			case 'q':
			{
				tmp[i]='p';
				break;
			}
		}
	}
	return 0&(int)printf("%s",tmp==str?"Yes":"No");
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

#define OPERAND 100

int sum[OPERAND];
int x, y;
int k = 0;

void push(int i) {
  sum[k] = i;
  k++;
}

int pop() {
  k--;
  return sum[k];
}

int main(void) {
  int z;
  char in[OPERAND];

  while(scanf("%s", in) != EOF) {
    if(in[0] == ' ') {
      ;
    }
    else if(in[0] == '+') {
      x = pop();
      y = pop();
      z = x + y;
      push(z);
    }
    else if(in[0] == '-') {
      x = pop();
      y = pop();
      z = y - x;
      push(z);
    }
    else if(in[0] == '*') {
      x = pop();
      y = pop();
      z = x * y;
      push(z);
    }
    else if(in[0] == '/') {
      x = pop();
      y = pop();
      z = x / y;
      push(z);
    }

    else {
      z = atoi(in);
      push(z);
    }
  }

  printf("%d\n",sum[0]);

  return 0;
}



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

int main() {
  int N,M,C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for(int i = 0; i < M; i++){
  cin >> B.at(i);
  }
  vector<vector<int>> A(N, vector<int>(M));
  for(int i = 0; i < N; i++){
  for(int j = 0; j < M; j++){
  cin >> A.at(i).at(j);
  }
  }
  int ans = 0;
  for(int i = 0; i < N; i++){
  int a = 0;
  for(int j = 0; j < M; j++){
  a += A.at(i).at(j)*B.at(j);
  }
  if(a > (-1 * C)){
  ans += 1;
  }
  }
  cout << ans;
}

Measured memory_bytes: 256
import math
from fractions import Fraction
N = int(input())

ta = [0] * N
ao = [0] * N

for i in range(N):
    t, a = map(int, input().split())
    if i == 0:
        ta[i] = t
        ao[i] = a
    else:
        tmp = max(math.ceil(Fraction(ta[i-1],t)), math.ceil(Fraction(ao[i-1],a)))
        ta[i] = t*tmp
        ao[i] = a*tmp

print(ta[-1]+ao[-1])


Measured memory_bytes: 5600
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <ctime>
#include <queue>
#include <sstream>
#include <utility>
#include <bitset>

using namespace std;

#define MP make_pair 
#define PB push_back 
#define INF (1000000007) 
#define eps 1e-8

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

int n;
int a[200005];

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

Measured memory_bytes: 2944
S=input()[::-1]
ans=0
#支払う枚数
array = list(map(int, S))
L=len(array)
for i,n in enumerate(array):
    if n< 5 :
        ans+=n
    elif n > 5:
        ans+= 10-n
        if i <L-1:
            array[i+1] +=1
        else:
            ans +=1
    else:
        ans+=5
        if i < L-1:
            if array[i+1] >=5:
                array[i+1] +=1
                
print( ans)


Measured memory_bytes: 15588
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#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)
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> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll a, b;
        cin >> a >> b;
        if (a * b <= 0) cout << "Zero" << endl;
        else {
            if (a > 0 && b > 0) cout << "Positive" << endl;
            else {
                cout << ((b - a + 1) % 2 == 0 ? "Positive" : "Negative") << endl;
            }
        }


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
N = int(input())

isDouble = []

for i in range(N):
    temp = [int(j) for j in input().split(" ")]
    if temp[0] == temp[1]:
        isDouble.append(1)
    else:
        isDouble.append(0)

cnt = 0
flg = False

for i in range(len(isDouble)):
    if isDouble[i] == 0:
        cnt = 0
    else:
        cnt += isDouble[i]
    if cnt == 3:
        flg = True
        break

if flg:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*DP使ったほうがよくない？？WOWWOW*/

ll A,B,C,D; 

ll solve(ll x){
    ll y;
    y=(B-A+1)/x;
    if((B-A+1)%x!=0){
        y++;
    }
    if(A%x!=0){
        y--;
        if((B-A)%x+A%x>=x){
            y++;
        }
    }
    return y;
}

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

int main(){
    cin>>A>>B>>C>>D;
    cout<<(B-A+1)-solve(C)-solve(D)+solve(C*D/gcd(C,D))<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int flg=0,data[10];
	
	while(scanf("%d",&data[flg])!=EOF){
	
		if(data[flg]==0){
			printf("%d\n",data[flg-1]);
			flg=flg-1;
		}
		else if(data[flg]!=0){
			flg++;
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
#include <math.h>
#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

int int_pow(int x, int n){
    int ans = 1;
    while(n>0){
        if((n&1)==1){
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

int n;
vector<int> honest(20);
vector<vector<int>> y(20, vector<int>(20));

int main() {
    int tmp_x;
    int tmp_y;
    int max_ans=0;

    int a;
    cin >> n;
    for(int i=0; i<20; i++){
        for(int j=0; j<20; j++){
            y[i][j]=-1;
        }
    }
    for(int i=0; i<n; i++){
        cin >> a;
        for(int j=0; j<a; j++){
            cin >> tmp_x >> tmp_y;
            tmp_x--;
            tmp_y;
            y[i][tmp_x]=tmp_y;
        }
    }

    int num_list=int_pow(2,n);
    int ans;
    int tmp_i;
    bool is_true;
    for(int i=0; i<num_list; i++){
        ans=0;
        tmp_i=i;
        is_true=true;
        for(int j=0; j<n; j++){
            honest[j] = tmp_i%2;
            tmp_i /= 2;
            ans += honest[j];
        }
        for(int j=0; j<n; j++){
            if(honest[j]==0)continue;
            for(int k=0; k<n; k++){
                if(j==k)continue;
                if((y[j][k]==1 && honest[k]==0) || (y[j][k]==0 && honest[k]==1)){
                    is_true=false;
                    break;
                }
            }
            if(is_true==false)break;
        }
        if(is_true){
            if(max_ans<ans){
                max_ans=ans;
            }
        }
    }
    cout << max_ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
import math
def tax(N):
    x = N / 1.08
    if math.floor(math.floor(x) * 1.08) == N:
        print(math.floor(x))
    elif math.floor(math.ceil(x) * 1.08) == N:
        print(math.ceil(x))
    else:
        print(':(')
tax(N)

Measured memory_bytes: 3060
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      long a = sc.nextLong();
      long b = sc.nextLong();
      long k = sc.nextLong();


      if (a<k) {
        System.out.print(0);
        System.out.print(" ");
        if (b-(k-a)<0) {
          System.out.print(0);
          System.out.println();
          System.exit(0);
        }else{
          System.out.print(b-(k-a));
          System.out.println();
          System.exit(0);
        }
      }else{
        System.out.print(a-k);
        System.out.print(" ");
        System.out.print(b);
        System.out.println();
      }

    }
}


Measured memory_bytes: 21844
#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: 2024
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;
ll a[101][101];
ll c[26];
int main() {
	ll h, w; cin >> h >> w;
	rep(i, 0, h)rep(j, 0, w) {
		char x; cin >> x;
		a[i][j] = x;
		c[x - 'a']++;
	}
	ll p[4] = {};
	rep(i, 0, 26) {
		p[c[i] % 4]++;
	}

	if (!(h & 1) && !(w & 1)) {
		cout << ((p[1] == 0 && p[3] == 0 && p[2] == 0) ? "Yes" : "No") << endl;
		return 0;
	}
	else if (!(h & 1) || !(w & 1)) {
		if (!(h & 1))swap(h, w);

		if (p[1] == 0 && p[3] == 0 && p[2] <= w / 2) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		return 0;
	}
	else {
		if ((p[1] == 1 && p[3] == 0 && p[2] <= (h - 1) / 2 + (w - 1) / 2 )|| 
		 (p[1] == 0 && p[3] == 1 && p[2] <= (h - 1) / 2 + (w - 1) / 2) ){
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		return 0;
	}
	return 0;
}

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

using namespace std;

int main()
{

    int v;
    int z=0;
    cin>>v;
    int a[v];
    for(int m=0;m<v;m++){
        cin>>a[m];
    }
    sort(a,a+v);

    for(int r=0;r<v;r++){
        if(a[r]!=a[r+1]){
            z++;
        }

    }
    cout<<z;
    return 0;
}


Measured memory_bytes: 256
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/

int dp[401][401];
signed main() {
	EmiliaMyWife

	for(int i = 0; i < 401; i++)
		for(int j = 0; j < 401; j++)
			dp[i][j] = INF;
	dp[0][0] = 0;
	int n, a, b, ans = INF;
	cin >> n >> a >> b;
	for(int i = 0, x, y, c; i < n; i++) {
		cin >> x >> y>> c;
		for(int j = 400; j >= x; j--) {
			for(int k = 400; k>= y; k--) {
				dp[j][k] = min(dp[j][k], dp[j-x][k-y]+c);
			}
		}
	}
	for(int i = 1; max(i*a, i*b) <= 400; i++)
		ans = min(ans, dp[i*a][i*b]);
	if(ans == INF)
		ans = -1;
	cout << ans;

	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)

int main() {
	ll a, b,ans;
	in(a);
	in(b);
	ans = (b - 1) / (a - 1);
	if ((b - 1) % (a - 1) > 0) {
		ans++;
	}
	outn(ans);
	return 0;
}

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

int main(){ 
  int a, b;
  cin >> a >> b;
  string s1, s2;
  for (int i = 0; i < b; i++) s1 += a + '0';
  for (int i = 0; i < a; i++) s2 += b + '0';
  cout << min(s1, s2) << endl;
  return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <cstdio>
#include <utility>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

int array[4][3][10];

int main() {
  
  int n;
  
  cin>>n;
  
  for(int i=0; i<n; i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    array[a-1][b-1][c-1]+=d;
    }
    
   for(int i=0; i<4; i++){
       for(int j=0; j<3; j++){
           for(int k=0; k<10; k++){
             cout<<" "<<array[i][j][k];
        }
             cout<<endl;
      }
      if(i==3){ 
        continue;
      }cout<<"####################"<<endl;
    }
    
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
//#define int long long
pair<int,int> kk(int t[][500],int s[][500],int i,int j,int h,int w){
    pair<int ,int> d =make_pair(0,0);
    pair<int , int>addd;
    
        t[i][j]=0;

        if(i>0&&s[i][j]!=s[i-1][j]&&t[i-1][j]==-1){
            addd=kk(t,s,i-1,j,h,w);
            d.first += addd.first;
            d.second +=addd.second;    
        }
        if(j>0&&s[i][j]!=s[i][j-1]&&t[i][j-1]==-1){
            addd =kk(t,s,i,j-1,h,w);
        d.first += addd.first;
            d.second +=addd.second;    
        }    
        if(i<h&&s[i][j]!=s[i+1][j]&&t[i+1][j]==-1){
         
           addd=kk(t,s,i+1,j,h,w);
        d.first += addd.first;
            d.second +=addd.second;    
        
        }
        if(j<w&&s[i][j]!=s[i][j+1]&&t[i][j+1]==-1){

        addd=kk(t,s,i,j+1,h,w);
        d.first += addd.first;
            d.second +=addd.second;    
        
        }
       
    
    if(s[i][j]==1)d.first++;
    else d.second++;
    return d;
}

signed main(){
    int h,w;
    cin >>h >> w ;
    int s[h][500];
    int t[h][500];
    string l;
    for(int i=0;i<h;i++){
        cin >> l;
        for(int j=0;j<w;j++){
            if(l[j]=='#')s[i][j]=1;
            else s[i][j]=0;
            t[i][j]=-1;
        }
        
    }
    pair<int,int>d;
    long long ans=0;
    for(int i=0;i<h;i++){
        
        for(int j=0;j<w;j++){
           if(t[i][j]==-1){
               d= kk(t,s,i,j,h,w);
            ans+= long(d.first)*long(d.second);
           }
        }
    }

    cout << ans;



    return 0;
}

Measured memory_bytes: 21760
<?php
fscanf(STDIN,"%d %d", $d, $n);

switch ($d) {
  case '0':
    if($n == 100) {
      echo "101\n";
    } else {
      echo "$n\n";
    }
    break;
  case '1':
    if($n == 100) {
      echo "10100\n";
    } else {
      $ans = $n * 100;
      echo "$ans\n";
    }
    break;
  default:
    if($n == 100) {
      echo "1010000\n";
    } else {
      $ans = $n * 10000;
      echo "$ans\n";
    }
    break;
}

?>


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

int main(){
    string S;
    cin >> S;
    cout << count(S.begin(),S.end(),'1') << endl;
    return 0;
}


Measured memory_bytes: 256
m,d=[int(j) for j in input().split()]
if d<=21:
    print(0)
    exit()
ans=0
for i in range(1,m+1):
    for j in range(22,d+1):
        d1=int(str(j)[1])
        d2=int(str(j)[0])
        if i==d1*d2 and d1>=2 and d2>=2:
            ans+=1
print(ans)





Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if(a+b>=c?cout<<"Yes":cout<<"No");
system("pause");
return 0;
}

Measured memory_bytes: 504
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int a,b;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//構造体降順
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.b;   /* b を基準とする */
  int tmp2 = test2.b;
  return tmp2 - tmp1;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    int N;
    scanf("%d",&N);
    data shun[N];
    rep(i,N){
        shun[i].a=i;
        scanf("%d",&shun[i].b);
    }
    qsort(shun,N,sizeof(data),comp);
    rep(i,N){
        int cnt=0;
        while(1){
            if(i!=shun[cnt].a){
                printf("%d\n",shun[cnt].b);
                break;
            }else{
                cnt++;
            }
        }
    }
}



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

int N, A, B, C;
vector<int> h(8);

int dfs(int i, int a, int b, int c) {
    if (i == N) {
        if (a != 0 && b != 0 && c != 0) {
            return abs(A - a) + abs(B - b) + abs(C - c);
        } else {
            return 1e9;
        }
    }

    int res = 1e9;
    res = dfs(i + 1, a, b, c);
    res = min(res, dfs(i + 1, a + h[i], b, c) + (a != 0 ? 10 : 0));
    res = min(res, dfs(i + 1, a, b + h[i], c) + (b != 0 ? 10 : 0));
    res = min(res, dfs(i + 1, a, b, c + h[i]) + (c != 0 ? 10 : 0));

    return res;
}

int main() {
    cin >> N;
    cin >> A >> B >> C;
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    cout << dfs(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
#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 alpha_to_int(char a) {
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    return alpha.find(a);
}

char int_to_alpha(int i) {
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    return alpha.at(i);
}

int main() {
    string s;
    cin >> s;
    int cnt[26] = {0};
    rep(i,s.size()) {
        cnt[alpha_to_int(s[i])]++;
    }
    rep(i,26) {
        if (cnt[i] == 0) {
            cout << int_to_alpha(i) << endl;
            return 0;    
        }
    }
    cout << "None" << endl;
}

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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

int main(){
    int x,y;
    cin >> x >> y;
    cout << x + y/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>

#include <bitset>

#include <tuple>

#include <cstdint>

#include <cstdio>

#include <cctype>

#include <assert.h>

#include <stdlib.h>

#include <stdio.h>

#include <cassert>

#include <cfloat>

#include <climits>

#include <cmath>

#include <complex>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <limits>

#include <map>

#include <memory>

#include <queue>

#include <random>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>

#include <math.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
}


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

void solve(vector<vector<int> > &v,int x,int y,int c,int w,int h){
  if(x<1||y<1||w<x||h<y)return;
  if(v[y][x]!=c)return;
  v[y][x]=6;
  solve(v,x+1,y,c,w,h);
  solve(v,x-1,y,c,w,h);
  solve(v,x,y-1,c,w,h);
  solve(v,x,y+1,c,w,h);
}

int main(void){
  int w,h;
  while(cin>>w>>h,w||h){
    int xs,ys,xg,yg,n;
    vector<vector<int> > field(101);
    for(int i=0;i<101;++i)field[i].resize(101);
    cin>>xs>>ys>>xg>>yg>>n;
    for(int i=0,c,d,x,y;i<n;++i){
      cin>>c>>d>>x>>y;
      if(d){
        for(int j=y;j<y+4;++j)
          for(int k=x;k<x+2;++k)
            field[j][k]=c;
      }else{
        for(int j=y;j<y+2;++j)
          for(int k=x;k<x+4;++k)
            field[j][k]=c;
      }
    }
    solve(field,xs,ys,field[ys][xs],w,h);
    //for(int i=1;i<=h;++i){for(int j=1;j<=w;++j) cerr<<field[i][j]<<" ";cerr<<endl;}
    cout<<((field[yg][xg]==6)?"OK":"NG")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1252
def binaryarray_to_int(a):
    res = 0
    for x in a:
        res = (res << 1) + x
    return res

def count_bits(x):
    res = 0
    while x > 0:
        res += (x & 1)
        x = x >> 1
    return res


def solve():
    N = int(input())

    F = [
        binaryarray_to_int(
            [int(x) for x in input().split()]
        )
        for _ in range(N)
    ]

    P = [
        [int(x) for x in input().split()]
        for _ in range(N)
    ]

    # simulate all patterns
    ans = -float("inf")
    for mask in range(1, 1024):
        p = 0
        for i in range(N):
            bit = mask & F[i]
            c = count_bits(bit)
            p += P[i][c]
        ans = max(ans, p)

    return ans


print(solve())

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/

int main()
{
	ll NN;
	ll h, n, w;
	bool flug = false;
	cin >> NN;
	for (h = 1; h <= 3500; h++) {
		for (n = 1; n <= 3500; n++) {
			ll bunbo = (4 * h*n - NN*(n + h));
			if (bunbo > 0) {
				if ((NN*h*n) % bunbo == 0) {
					w = (NN*h*n) / (4 * h*n - NN*(n + h));
					flug = true;
					break;
				}
			}
		}
		if (flug) break;
	}

	cout << h << " " << n << " " << w;

	return 0;
}

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

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin >> s;
    ll ans = 0;
    ll cnt = 0;
    for(int i = 0; i < SZ(s); i++){
        if(s[i] == 'W'){
            ans += i - cnt;
            cnt++;
        }
    }
    cout << ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
int main(){
    int n;cin>>n;
    vector<int>prime(0),elem(101);
    REP(i,2,98){
        bool f=1;
        REP(j,2,sqrt(i)+1)if(i!=j&&i%j==0)f=0;
        if(f)prime.push_back(i);
    }
    REP(i,1,n+1){
        int j=i;
        int k=0;
        while(j>1){
            int counter=0;
            while(j%prime[k]==0){
                j/=prime[k];
                counter++;
            }
            elem[prime[k]]+=counter;
            k++;
        }
    }
    int c74=0,c24=0,c14=0,c4=0,c2=0;
    rep(i,101){
        if(elem[i]>=74)c74++;
        if(elem[i]>=24)c24++;
        if(elem[i]>=14)c14++;
        if(elem[i]>=4)c4++;
        if(elem[i]>=2)c2++;
    }
    int ans=c74+c24*(c2-1)+c14*(c4-1)+(c4*(c4-1)*(c2-2))/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/**  I'm Klaus, NicKlaus :v **/
using namespace std;
#define ms(a,v) memset(a,v,sizeof a)
#define ll long long
#define LOG2(X) ((unsigned) (8*sizeof(int) - __builtin_clz((X)) - 1))
ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }
ll lcm(ll x, ll y){return x*(y/gcd(x,y));}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	#ifdef LOCAL_JUDGE
		//freopen("in_out/in.txt", "rt", stdin);
		//freopen("int_out/out.txt", "wt", stdout);
	#endif
	int n;
	cin>>n;
	vector<int> a(n,100000000);
	for(int i=0; i<n-1; i++) cin>>a[i];
	int ans = 0;
	for(int i=0; i<n; i++){
		if(!i) ans += a[0];
		else{
			ans += min(a[i],a[i-1]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import string
alpha = string.ascii_lowercase

n = int(input())

ans = []
while (n):
    res = (n % 26)
    # print("n % 26: ", n % 26)
    # print("letra: ", alpha[res-1])
    # print(" n // 26: ", n // 26)
    ans.append(alpha[res-1])
    if (n <= 26):
        break
    if n % 26:
        n = n // 26
    else:
        n = n // 26
        n = n - 1


# print(ans)
ans = ans[::-1]
print("".join(ans))

# 1 -> 26
# 2 -> 26 * 26 + 26
# 3 -> 26 * 26 * 26


Measured memory_bytes: 9964
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
// #define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(12);const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};

const int N=666;
vector<int> g[N];
double f[N];
int n,m;
double calc(int s,int t){
    f[n]=0;
    for(int i=n-1;i>=1;--i){
        double sum=0;
        int cnt=0;
        for(int j:g[i]){
            if(i==s&&j==t)continue;
            sum+=f[j];
            cnt++;
        }
        f[i]=sum/cnt+1;
    }
    return f[1];
}
int32_t main(){
    cin>>n>>m;
    forn(i,m){
        int a,b;
        cin>>a>>b;
        g[a].pb(b);
    }
    vector<pii> ban;
    f[n]=0;
    for(int i=n-1;i>=1;--i){
        double sum=0;
        int cnt=0;
        double mx=0;int wx=0;
        for(int j:g[i]){
            if(f[j]>mx){
                mx=f[j];
                wx=j;
            }
            sum+=f[j];
            cnt++;
        }
        if(wx)ban.pb(i,wx);
        f[i]=sum/cnt+1;
    }
    double ans=f[1];
    for(pii p:ban)upn(ans,calc(p.f,p.s));
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>


using namespace std;


int r(int g, int x) {
	if (x > g)swap(x, g);
	if (x==0)return g;
	int t = g;
	g = x;
	x = t%x;
	
	
	r(g, x);
}


int main() {

	
	int n,k;
	cin >> n>>k;
	int g = 0, d = -1;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		g = r(g, x);
		d = max(d, x);
		
	}
	if (k <= d&&k%g == 0)cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	
		return 0;

}




Measured memory_bytes: 256
x = int(input())

import math



def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while(1):
    if(is_prime(x)):
        print(x)
        break
    x += 1
    


Measured memory_bytes: 2940
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        for(int i=0; i<n; i++) {
            set.add(sc.nextInt());
        }
        if(set.size() == n) System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 69400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 200005;
const long long MOD = 1000000007;
const long long MODMOD = 998244353;
const double PI = acos(-1);

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

int main() {
  string s;
  cin >> s;
  if(s == "AAA" || s == "BBB") cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const ll mod = 1e9+7;
 
ll f(ll b, ll n){
    if(n < b) return n;
    return f(b, floor(n/b)) + (n % b);
}
 
int main()
{
    ll n,s;
    cin >> n >> s;
 
    if(s == n){
        cout << n+1 << endl;
        return 0;
    }
 
    for(ll b = 2; b <= sqrt(n); b++){
        if(f(b, n) == s){
            cout << b << endl;
            return 0;
        }
    }
 
    for(ll p = sqrt(n); p > 0; p--){
        ll b = ((n-s)/p) + 1;
        if(1 < b && f(b,n) == s){
            cout << b << endl;
            return 0;
        }
    }
 
    cout << -1 << endl;
    return 0;
}
 

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,st[110000]={},i,j;
  char c,nn;
  i=0;
  while(scanf(" %c",&c)!=-1){
    if('0'<=c&&c<='9'){
      n=c-'0';
      while(1){
	scanf("%c",&nn);
	if(nn==' ')break;
	n*=10;
	n+=(nn-'0');
      }
      st[i]=n;
      i++;
    }else {
      if(c=='+'){
	st[i-2]=st[i-1]+st[i-2];
      }else if(c=='-'){
	st[i-2]=st[i-2]-st[i-1];
      }else if(c=='*'){
	st[i-2]=st[i-1]*st[i-2];
      }
      i--;

    }

  }

  printf("%d\n",st[0]);
  return 0;
}

Measured memory_bytes: 3136