akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){
  int n,h;
  cin>>n>>h;
  vpii v1(n);
  rep(i,0,n) cin>>v1[i].f>>v1[i].s;
  int mx=-1,idx=-1,mx1=-1;
  rep(i,0,n){
    if(mx<v1[i].f) mx=v1[i].f,idx=i;
    else if(mx==v1[i].f && v1[idx].s>v1[i].s) idx=i;
  }
  mx1=v1[idx].s;
  vector<int> sol;
  rep(i,0,n) if(i!=idx && v1[i].s>mx) sol.pb(v1[i].s);
  sort(all(sol),greater<int>());
  int j=0,cnt=0;
  while(h>0){
    if(j<sol.size()) h-=sol[j++];
    else {
      int rem=(h+mx-1)/mx,rem1 = (h-mx1+mx-1)/mx + 1;
      cnt+= min(rem,rem1);
      break;
    }
    cnt++;
  }
  cout<<cnt<<endl;
}

int main(){
    optimizeIO();
    int r=1;
    {solve();}
}


Measured memory_bytes: 9268
#include<bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define vi vector<int>
#define pb push_back
using namespace std;
#define int long long
const int N=305;
int n,m,l,dist[N][N],ans[N][N];
bool visit[N];
vector<pii>v[N];
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m>>l;
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)dist[i][j]=1e18,ans[i][j]=1e18;
	for(int i=0;i<m;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		v[a].pb(mp(b,c));
		v[b].pb(mp(a,c));
		dist[a][b]=c;
		dist[b][a]=c;
	}
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(dist[i][j]<=l)
			{
				ans[i][j]=1;
			}
		}
	}
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				ans[i][j]=min(ans[i][j],ans[i][k]+ans[k][j]);
			}
		}
	}
	int Q;
	cin>>Q;
	while(Q--)
	{
		int x,y;
		cin>>x>>y;
		x--,y--;
		if(ans[x][y]==1e18)cout<<"-1\n";
		else cout<<ans[x][y]-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

bool done[114514];
int dist[114514];
bool flag=true; 

void dfs(int now, vector<vector<pair<int,int>>> &edge) {
	rep(i,edge[now].size()) {
		int next = edge[now][i].first;
		int len = edge[now][i].second;
		if(done[next]) {
			if(dist[next] != dist[now] + len)flag=false;
		} else {
			done[next] = true;
			dist[next] = dist[now] + len;
			dfs(next, edge);
		}
	}
}
 
int main() {
	SS(int,N,M);
	vector<vector<pair<int,int>>> edge(N+1);
	rep(i,M) {
		SS(int,l,r,d);
		edge[l].push_back({r, d});
		edge[r].push_back({l, -d});
	}
	for(int i=1;i<=N;i++) {
		if(!done[i]) {
			done[i] = true;
			dfs(i, edge);
		}
	}
	Yes(flag);
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int n, k, t = 0, u = 0, a = 0;
  scanf("%d %d", &n, &k);
  string s;
  cin >> s;
  v1i p;
  rep(i, n+1){
    if(i == n){
      if(s[i-1] == '1') p.push_back(u);
      else{
        p.push_back(t);
        p.push_back(0);
      }
      break;
    }
    if(s[i] == '1'){
      if(t > 0 || i == 0) p.push_back(t);
      t = 0;
      ++u;
    }
    else{
      if(u > 0) p.push_back(u);
      u = 0;
      ++t;
    }
  }
  vector<pii> v; t = 0;
  rep(i, p.size()/2){
    if(i == 0 && p[0] > 0) v.push_back({0, 0});
    v.push_back({t+p[i*2], t+p[i*2]+p[i*2+1]});
    t += p[i*2]+p[i*2+1];
  }
  k = min(k, (int)v.size()-1);
  rep(i, v.size()-k) a = max(a, v[k+i].se-v[i].fi);
  printf("%d\n", a);
  return 0;
}


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

using namespace std;

int N,M;
long long   from[2010], to[2010];
long long   cost[2010];
long long   dist[1100];
long long   const INF = 1e18;
//bellmanford
bool bellmanford(){
  fill(dist,dist+1100,INF);
  dist[0] = 0;
  for(int k = 0; k < 2*N ; k++){  //node nums
    for(int i = 0; i < M; i++){   // edge nums
      if(dist[from[i]] < INF && dist[to[i]] > dist[from[i]] + cost[i] ){
        dist[to[i]] = dist[from[i]] + cost[i];
        if(k >= N && to[i] == N-1) return  true;
      }
    }
  }
  return false;
}
//main()-----------------------------
int main(){
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    cin >> from[i] >> to[i] >> cost[i];
    from[i] --; to[i] --;
    cost[i] = -cost[i];
  }

  bool infFlag = bellmanford();

  if(infFlag) cout << "inf" << endl;
  else        cout << -dist[N-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#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++)


int main() {
  int mod=1000000007;
  long n,k;
  cin >> n>>k;
  long ans=0;
  rep2(i,k,n+2){
    ans=(ans+i*(2*n-2*i+2)/2+1)%mod;
  }
  
    cout<<ans<<endl;
  
  
  
}







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

int main(){
  int N;
  cin >> N;
  int R;
  int C[9]={};
  for (int i=0;i<N;i++){
    cin >> R;
    C[R>=3200?8:R/400]++;
  }
  int ans=0;
  for (int i=0;i<8;i++){
    ans+=C[i]>0?1:0;
  }
  cout << (ans==0?1:ans) << " " << ans+C[8] << endl; 
}


Measured memory_bytes: 256
def solve(A, B, C):
    ans = 0
    while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
        ans += 1
        pA, pB, pC = A, B, C
        A, B, C = B // 2 + C // 2, A // 2 + C // 2, A // 2 + B // 2
        if pA == A and pB == B and pC == C:
            return -1
    return ans


if __name__ == "__main__":
    A, B, C = tuple(map(int, input().split(" ")))
    print(solve(A, B, C))


Measured memory_bytes: 3060
MODE = "stdio"
#require 'matrix'
#include Math
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = '5
  1 5 7 10 21
  4
  2 4 17 8'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end

n = line[0].to_i
a = line[1].split(" ").map(&:to_i)
q = line[2].to_i
m = line[3].split(" ").map(&:to_i)
 
def solve(i, m, a)
  return true if m == 0
  return false if i >= a.length
  return solve(i+1, m, a) || solve(i+1, m-a[i], a)
end
 
m.each do |mi|
  if solve(0, mi, a)
    puts "yes"
  else
    puts "no"
  end
end

Measured memory_bytes: 8632
// Shell Sort
#include <stdio.h>

int cnt;
int len;
int g[101];

void shellSort(int a[], int n){
    int i, j, h, x=1;
    len = cnt = 0;
    for(i=0; x<=n; i++){
        g[i] = x;
        x = x*3+1;
        len++;
    }
    for(h=len-1; h>=0; h--){
        for(i=g[h]; i<n; i++){
            int key = a[i];
            j = i-g[h];
            while(j >= 0 && a[j] > key){
                cnt++;
                a[j+g[h]] = a[j];
                j -= g[h];
            }
            a[j+g[h]]=key;
        }
    }   
}

int main(void){
    int n;
    int a[1000001];
    scanf("%d", &n);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    shellSort(a, n);
    printf("%d\n", len);
    for(int i=len-1; i>=0; i--){
        printf("%d", g[i]);
        if(i) printf(" ");
    }
    printf("\n%d\n", cnt);
    for(int i=0; i<n; i++) printf("%d\n", a[i]);
    return 0;    
}


Measured memory_bytes: 5616
#include <stdio.h>
#include <stdlib.h>
#define N 100



void Matrix(int *p, int (*m)[N], int n){
  
  int i, j, k, l;
  int a, b;
  
  for(i=1; i<=n; i++)
    m[i][i]=0;
  for(j=2; j<=n; j++){
    for(i=1; i<=n-j+1;i++){
      k = i + j-1;
      m[i][k]=10000000;
      for(l=i; l <= k - 1;l++){
	a=m[i][k];
	b=m[i][l]+m[l+1][k]+p[i-1]*p[l]*p[k];
	if(b<a){
	  m[i][k]=b;
	}
      }
    }
  }
  printf("%d\n", m[1][n]);
}


int main(void){
  int i, j, k, n;
  int p[N], m[N][N];
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d %d", &p[i], &p[i+1]);
  }
  Matrix(p, m, n);
  return 0;
}

Measured memory_bytes: 636
k,u,v=`dd`.scan(/-?\d+/).map &:to_i;x,y,*s=u.abs,v.abs;d=x+y;x,y=y,x if f=x>y;(k+1)*d%2==1&&(p -1;exit);m=(d-1)/k+1;n=d<k ?2:m+(d-m*k)%2;a=d==k ?x:(d-n*k)/2;b=k-a.abs;d%2-d/k==1&&(s=[[0,-k]];a=b=(d-k)/2);n.times{s<<[a,b];t=[x-a,k].min;a+=t;b+=k-t};p s.size;s.each{|a,b|f&&(a,b=b,a);puts [a*(u<=>0.1),b*(v<=>0.1)]*?\s}

Measured memory_bytes: 20864
package main

import (
	"fmt"
)

func main() {
	var a int
	var b int
	var c int
	var d int
	var e int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)
	fmt.Scan(&e)
	var maxDiff int
	var maxDiffIndex int
	list := []int{a, b, c, d, e}
	for i, l := range list {
		f := calculateDiff(l)
		if i == 0 {
			maxDiff = f
		} else {
			if maxDiff < f {
				maxDiff = f
				maxDiffIndex = i
			}
		}
	}
	var time int
	for i, l := range list {
		if i == maxDiffIndex {
			continue
		}
		time += l
		if time%10 != 0 {
			temp := 10 - time%10
			time += temp
		}
	}
	fmt.Println(time + list[maxDiffIndex])
}

func calculateDiff(a int) int {
	if a%10 == 0 {
		return 0
	}
	return 10 - a%10
}


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

count = 0

for i  in range(0, N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            box = [A[i], A[j], A[k]]
            if len(box) == len(set(box)):
            	if (A[i] + A[j] > A[k]) and (A[j] + A[k] > A[i]) and (A[i] + A[k] > A[j]):
                	count += 1

print(count)

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

int n, m;
int D[100005];
int U[200005];
int V[200005];
vector<int> edge[100005];
int col[100005];

int dfs(int x) {
    int ret = 1;
    for (int i : edge[x]) {
        if (col[i]) continue;
        if (D[i] != D[x]) continue;
        col[i] = 3 - col[x];
        ret += dfs(i);
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> D[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> U[i] >> V[i];
        edge[U[i]].push_back(V[i]);
        edge[V[i]].push_back(U[i]);
    }
    int prv = 2;
    for (int x = 1; x <= n; x++) {
        if (col[x]) continue;
        bool en = false;
        for (int i : edge[x]) {
            if (D[i] < D[x]) {
                en = true;
                break;
            }
        }
        prv = 3 - prv;
        col[x] = prv;
        if (dfs(x) == 1 && !en) {
            cout << -1;
            return 0;
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << "BW"[col[i] - 1];
    }
    cout << '\n';
    for (int i = 1; i <= m; i++) {
        int c1 = col[U[i]], c2 = col[V[i]];
        if (c1 == c2) {
            cout << max(1, abs(D[U[i]] - D[V[i]])) << '\n';
        }
        else {
            cout << max(D[U[i]], D[V[i]]) << '\n';
        }
    }
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int x,y,z;
	cin>>x>>y>>z;
	int temp;
	temp=x;
	x=y;
	y=temp;
	temp=x;
	x=z;
	z=temp;
	cout<<x<<" "<<y<<" "<<z;
}

Measured memory_bytes: 256
import math

a,b,h,m=list(map(int,input().split()))

minn=h*60+m

deg_l=6*minn
deg_s=0.5*minn

delta=5.5*minn

c2=a**2+b**2-2*a*b*math.cos(math.radians(delta))

# print(math.cos(math.radians(90)))
# print(c2)
c=math.sqrt(c2)
print(c)

Measured memory_bytes: 62388
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
string st;
bool a;
int main()
{
  cin>>st;
  for(int i=0;i<st.size();i++)
  {
    if(st[i]=='C')a=1;
    if(st[i]=='F')
    {
      if(a!=0)
      {
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
<?php
  $n = trim(fgets(STDIN));
  $h = explode(" ",trim(fgets(STDIN)));
  $count = 1;
  $max = $h[0];
  for($i=1; $i<$n; $i++){
    if($max <= $h[$i]){
      $max = $h[$i];
      $count++;
    }
  }
  echo $count."\n";

Measured memory_bytes: 4728
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	for(int b = 1; b <= n; b++){
		ans += (n/b) * max(0, b-k);
		ans += max(0, n%b - k + 1);
	}
	if(k == 0) ans -= n;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <climits> //max & min

#define int long long
#define pb push_back
#define  sample(n) for(int i=0;i<n;i++)
#define INS(v,n) for(int i=0;i<n;i++){cin >>v.at(i);}//vector 代入
#define ELM 100001 //問題によっては1000000001に変更
using namespace std;

//int Move(vector<int> v,int n){
//    int m[ELM] ={0};
//    for(int i=0; i<n; i++){
//        m[v[i]]++;
//    }
//    vector<int> s;
//    for (int i=0; i<n; i++) {
//        if (m[v[i]]!=0) {
//            cout<<m[v[i]]<<endl;
//            s.pb(m[v[i]]);
//        }
//    }
//    int move = *max_element(s.begin(), s.end());
//    return move;
//}
signed  main(){
    int A,B;
    cin >> A>>B;
    int ans = 0;
    sample(2){
        if(A>B){
            ans+=A;
            A--;
        }else{
            ans+=B;
            B--;
        }
    }
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;

int insertionSort(int A[],int N){
    for(int i=0;i<N;i++){
        int v = A[i];
        int j = i-1;
        while(j>=0&&A[j]>v){
            A[j+1] = A[j];
            j--;
            }
        A[j+1] = v;
        for(int k=0;k<N;k++){
            cout << A[k];
            if(k!=N-1) cout << " ";
        }
        if(i!=(N))cout << endl;
    }
    //return A;
}

int main(){
    int N;
    cin >> N;
    int A[N]; 
    for(int i=0;i<N;i++) cin >> A[i];
    //for(int i=0;i<N;i++){
    //    cout << A[i];
    //    if (i!=N-1)cout << " ";
    //} 
    //cout << endl;
    insertionSort(A,N);
}




Measured memory_bytes: 3092
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	char z[1000];
	int a,s[1000],d,f,g,h,j,i,k;
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		scanf("%s",z);
		d=0;
		for(i=0;i<=a;i++) s[i]=0;
		for(i=0;i<100;i++){
			if(z[i]=='S'){
				s[d]++;
				s[a]+=s[d];
				s[d]=0;
			}
			if(z[i]=='L'){
				s[d]+=s[a]+1;
				s[a]=0;
			}
			if(z[i]=='M') s[d]++;
			d++;
			if(d==a) d=0;
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(s[i]>s[j]){
					f=s[i];
					s[i]=s[j];
					s[j]=f;
				}
			}
		}
		for(i=0;i<=a;i++){
			printf("%d",s[i]);
			if(i!=a) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

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

int main(){
	int N, res = 0;
	cin >> N;
	int B[1000];
	for (int i = 0; i < N - 1; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			res += B[i];
		}else if(i == N-1){
			res += B[i - 1];
		}else{
			res += min(B[i - 1], B[i]);
		}
	}
	cout << res << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
string o;
string e;
/**********************************************/

int main(){
    cin >> o >> e;
    REP(i, e.size()){
        cout << o[i] << e[i];
    }
    if(o.size() - e.size() == 1){
        cout << o[o.size()-1];
    }

    cout << endl;
}


Measured memory_bytes: 256
a = []
for i in range(3):
    a.append(list(map(int, input().split())))
n = int(input())
b = []
for i in range(n):
    bi = int(input())
    for j in range(3):
        for k in range(3):
            if bi == a[j][k]:
                a[j][k] = 0

ans = 'No'
for i in range(3):
    if a[i][0]+a[i][1]+a[i][2] == 0 or a[0][i]+a[1][i]+a[2][i] == 0:
        ans = 'Yes'
if a[0][0]+a[1][1]+a[2][2] == 0 or a[0][2]+a[1][1]+a[2][0] == 0:
    ans = 'Yes'

print(ans)

Measured memory_bytes: 3064
H,W,D=map(int,input().split())
d=[[0,0] for i in range(H*W+1)]
d2=[0 for i in range(H*W+1)]
for j in range(H):
  a=[int(x) for x in input().split()]
  for k in range(W):
    d[a[k]]=[j+1,k+1]
for l in range(D+1,H*W+1):
  d2[l]=abs(d[l][0]-d[l-D][0])+abs(d[l][1]-d[l-D][1])
for m in range(D+1,H*W+1):
  d2[m]+=d2[m-D]
Q=int(input())
for i in range(Q):
  a,b=map(int,input().split())
  if a==b:
    print(0)
  else:
    ans=d2[b]-d2[a]
    print(ans)

Measured memory_bytes: 17680
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for n in range(N)]

cnt = 0
for a in A:
    calc = 0
    for m in range(M):
        calc += a[m] * B[m]
    if calc + C > 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 9124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <ccomplex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


// Modint
struct Mint {
	static const ll mod = (ll)(1e9 + 7);
	ll val;

	Mint() { val = 0; }
	Mint(ll a) { val = a; verify_value(); }

	void verify_value() {
		if (val >= mod) val %= mod;
		if (val < 0) val %= mod, val += mod;
	}

	Mint pow(ll p) const {
		Mint cur = Mint(val), ret = 1;
		while (p > 0) {
			if (p & 1) ret *= cur;
			cur *= cur;
			p >>= 1LL;
		}
		return ret;
	}
	Mint inv() const {
		if (val == 0) cerr << "WARNING: inv() is called with 0." << endl;
		return pow(mod - 2);
	}

	Mint operator+() const { return *this; }
	Mint operator-() const { return Mint(mod - val); }

	Mint operator+=(const Mint &a) {
		val += a.val;
		if (val >= mod) val -= mod;
		return Mint(val);
	}
	Mint operator*=(const Mint &a) {
		val *= a.val;
		if (val >= mod) val %= mod;
		return Mint(val);
	}
	Mint operator-=(const Mint &a) { return *this += -a; }
	Mint operator/=(const Mint &a) { return *this *= a.inv(); }

	Mint operator++() { return *this += Mint(1); }
	Mint operator--() { return *this -= Mint(1); }
	Mint operator++(int) {
		Mint ret = *this;
		++(*this);
		return ret;
	}
	Mint operator--(int) {
		Mint ret = *this;
		--(*this);
		return ret;
	}

	operator ll() const { return val; }
};

Mint operator+(const Mint &a, const Mint &b) {
	ll ret = a.val + b.val;
	if (ret >= Mint::mod) ret -= Mint::mod;
	return Mint(ret);
}
Mint operator*(const Mint &a, const Mint &b) {
	ll ret = a.val * b.val;
	if (ret >= Mint::mod) ret %= Mint::mod;
	return Mint(ret);
}
Mint operator-(const Mint &a, const Mint &b) { return a + (-b); }
Mint operator/(const Mint &a, const Mint &b) { return a * b.inv(); }

ostream &operator<<(ostream &out, const Mint &a) { return out << a.val; }
istream &operator>>(istream &in, Mint &a) {
	in >> a.val;
	a.verify_value();
	return in;
}

Mint pow(Mint a, int b) {
	return a.pow(b);
}


// Combinatorics
constexpr int MAX_N = 2000003;
Mint fact[MAX_N], inv[MAX_N];

void init_fact() {
	fact[0] = inv[0] = 1;
	for (ll i = 1; i < MAX_N; i++) {
		fact[i] = fact[i - 1] * Mint(i);
		inv[i] = fact[i].inv();
	}
}

// aCb
Mint C(int a, int b) {
	if (a < b) return 0;
	Mint res = fact[a];
	res *= inv[b];
	res *= inv[a - b];
	return res;
}

// aPb
Mint P(int a, int b) {
	if (a < b) return 0;
	return fact[a] * inv[a - b];
}

// aHb
Mint H(int a, int b) {
	if (b == 0) return 1;
	return C(a + b - 1, b);
}

int main() {
	int n, k; cin >> n >> k;
	init_fact();
	Mint ans = H(n, n);
	for (int i = 1; i < n - k; i++) {
		ans -= C(n, i) * H(i, n - i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 31488
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int x,a,b;
    cin >> x >> a >> b;
    int eat = b-a;
    if(eat>x) cout << "dangerous\n";
    else if(eat<=0) cout << "delicious\n";
    else cout << "safe\n";
    
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val a = nextInt()
    val s = next()
    println(if (a >= 3200) s else "red")
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 31812
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int p=1e9+7;
int n,a[110000],d,x;
long long f[110000],inv[110000];
inline int qpow(int x,int n){
	long long ans=1,a=x;
	while (n){
		if (n&1) ans=ans*a%p;
		a=a*a%p;
		n>>=1;
	}
	return ans;
}
inline int C(int n,int m){
	if (n<0) return 0;//n<=0!!!
	if (m>n) return 0;
	return f[n]*inv[m]%p*inv[n-m]%p;
}
int main(){
	scanf("%d",&n);
	f[0]=inv[0]=1;
	fo(i,1,n+1) f[i]=f[i-1]*i%p;
	inv[n+1]=qpow(f[n+1],p-2);
	fd(i,n,1) inv[i]=inv[i+1]*(i+1)%p;
	//fo(i,1,n+1) printf("%d\n",f[i]*inv[i]%p);
	fo(i,1,n+1){
		scanf("%d",&x);//x!!!
		if (!a[x]) a[x]=i;else d=i-a[x];
	}
	//printf("%d\n",n-d-1);
	fo(i,1,n+1){
		printf("%d\n",(C(n+1,i)-C(n-d,i-1)+p)%p);//n-d-1!!!
	}
	return 0;
}

Measured memory_bytes: 3072
using System;
public class Hello{
    public static void Main(){
        // Your code here!
        int n=int.Parse(System.Console.ReadLine());
        string[] line=System.Console.ReadLine().Split(' ');
        int d=int.Parse(line[0]),x=int.Parse(line[1]);
        int[] A=new int[n];
        int ans=x;
        for(int i=0;i<n;i++){
            A[i]=int.Parse(System.Console.ReadLine());
            ans+=(d-1)/A[i]+1;
        }
        System.Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
H, W, K = gets.chomp.split(" ").map(&:to_i)
S = []
ans = []
H.times{
  S << gets.chomp.split("")
  ans << Array.new(W, 0)
}

cnt = 1
(0...H).each{|i|
  (0...W).each{|j|
    if S[i][j] == '#' then
      ans[i][j] = cnt
      cnt += 1
    end
  }
}

(0...H).each{|i|
  wk = 0
  (0...W).each{|j|
    if ans[i][j] != 0 then
      wk = ans[i][j]
    else
      ans[i][j] = wk
    end
  }
  wk = 0
  (W-1).downto(0){|j|
    if ans[i][j] != 0 then
      wk = ans[i][j]
    else
      ans[i][j] = wk
    end
  }
}

(0...W).each{|j|
  wk = 0
  (0...H).each{|i|
    if ans[i][j] != 0 then
      wk = ans[i][j]
    else
      ans[i][j] = wk
    end
  }
  wk = 0
  (H-1).downto(0){|i|
    if ans[i][j] != 0 then
      wk = ans[i][j]
    else
      ans[i][j] = wk
    end
  }
}

(0...H).each{|i|
  (0...W).each{|j|
    printf("#{ans[i][j]} ")
  }
  printf("\n")
}


Measured memory_bytes: 10620
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n%2){
        cout << "No" << endl;
        return 0;
    }
    if(s.substr(0,n/2)==s.substr(n/2,n/2)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> ans;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        bool end = true;
        for(int j = a.size()-1; j >= 0; j--){
            if(a[j] == j+1){
                ans.push_back(a[j]);
                if(a.size() != 1) a.erase(a.begin()+j);
                //for(auto p:a) cout << p;
                //cout << endl;
                end = false;
                break;
            }
        }
        if(end) {
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(ans.begin(),ans.end());
    for(auto p:ans){
        cout << p << endl;
    }
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n);i++)
#define rep1(i,n) for(int i=1; i<(n); i++)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();
    set<int> s;
    rep(i, 3){
        int x;
        cin >> x;
        s.insert(x);
    }
    if(s.size() == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include<stdio.h>
#include <functional>
#include<algorithm>
#define PI 3.14159265
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define SZ(x) ((int)(x).size())

using namespace std;



int main() {
	int n,flag;
	int me = 0;
	ll mi, now;
	int w[25], v[25];
	while (1) {
		me = 0;
		cin >> n;
		if (n == 0) break;
		
		REP(i, n) {
			
			cin >> w[i] >> v[i];
		}
		REP (j,n) {
			mi = 100000000;
			REP(i, n) {
				if (v[i] >= 0) {
					if (mi > v[i]) {
						mi = v[i];
						now = i;
					}
				}
			}
			if (me + w[now] > v[now]) {
				cout << "No" << endl;
				flag = 0;
				break;
			}
			else {
				me = me + w[now];
				v[now] = -1;
				flag = 1;
			}

		}
		if (flag == 1) {
			cout << "Yes" << endl;
		}

	}
	return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  cin>>n;
  double a[n];
  for(ll i=0;i<n;i++)
    	cin>>a[i];
  sort(a,a+n);
  double sum = (a[0]+a[1])/2;
  for(ll i=2;i<n;i++)
    sum = (sum + a[i])/2;
  
  printf("%.9lf",sum);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> arr;
for(int i=0;i<n;i++)
{
    int x;
    cin>>x;
    arr.push_back(x);
}
for(int i=0;i<n;i++)
{
    int cur = arr[i];
    int j;
    for( j=i-1;arr[j]>cur && j>=0;j--)
    {
        arr[j+1]=arr[j];
    }
    arr[j+1]=cur;
    for(int k=0;k<n;k++)
    if(k!=n-1)
    cout<<arr[k]<<" ";
    else cout<<arr[k];
    cout<<endl;
}
}

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

int main(){
    string que;

    cin>>que;

    if(que[0]=='Y'&&que[1]=='A'&&que[2]=='K'&&que[3]=='I'){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

def gcd(a, b):
  if a > b:
    a, b = b, a
  while b % a:
    a, b = b % a, a
  return a

def main():
  n = int(input())
  As = list(map(int, input().split()))
  As.sort()
  min = 10**9 + 1
  num = As[0]
  for A in As[1:]:
    num = gcd(num, A)
  print(num)
  
if __name__=='__main__':
  main()



Measured memory_bytes: 14252
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

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

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int w[50],cnt=0,s,n;  
  
void solve(int a, int sum, int n){  
    if(sum==s && !n){  
        w[cnt]++;  
        return;  
    }  
    if(a==10 || !n)
		return;  
    solve(a+1, sum, n); 
    solve(a+1, sum+a, n-1);
}  
  
int main(){
	while(cin>>n>>s, n || s){  
        w[cnt]=0;    
        solve(0, 0, n);
		cnt++;
    }
	REP(i,cnt)
		cout<<w[i]<<"\n";
    return 0;  
}  

Measured memory_bytes: 1160
package main

import (
	"fmt"
)

func main() {
	var a int
	var s string
	fmt.Scanf("%d", &a)
	fmt.Scanf("%s", &s)
	if a >= 3200 {
		fmt.Printf("%s", s)
		return
	}

	fmt.Printf("%s", "red")
	return
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> b(n, 0);
  for(ll i = n; i > 0; i--) {
    int sum = 0;
    for(ll k = n / i * i; k > 0; k -= i) {
      if(i != k) {
        sum += b[k - 1];
      } else if(sum % 2 != a[k - 1]) {
        b[k - 1]++;
      }
    }
  }

  int m = 0;
  rep(i, n) if(b[i]) m++;
  printf("%d\n", m);
  rep(i, n) if(b[i]) printf("%d\n", i + 1);
}

Measured memory_bytes: 2432
if __name__ == '__main__':
	n = int(input())
	num = [int(i) for i in input().split()]
	
	# bubble sort
	flag = 1
	count = 0
	while flag != 0:
		flag = 0
		rev = list(range(1,n))
		rev.reverse()
		for j in rev:
			if num[j] < num[j-1]:
				tmp = num[j]
				num[j] = num[j-1]
				num[j-1] = tmp
				flag = 1
				count += 1
	for i in range(n):
		if i != n-1:
			print("%d" % (num[i]),end=" ")
		else:
			print("%d" % (num[i]))
	print(count)


Measured memory_bytes: 5612
from math import pi, ceil, floor
import numpy as np
from collections import defaultdict, deque, Counter
from operator import itemgetter
from bisect import bisect_left, bisect_right, insort_left, insort_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    a, b, c, d = map(int, input().split())
    T = ceil(c / b)
    A = ceil(a / d)
    if T <= A:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

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

using namespace std;

//Author: Ezio Sam

#define ll long long

#define pb push_back 

#define sp " "

int main()

{

	ll n, a, b, c;	

	string s;

	cin>>s;

    

    if(s=="ABC") cout<<"ARC"<<endl ;

    else if(s=="ARC") cout<<"ABC"<<endl ;

   return 0;

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(i,n) rep2(i,0,n)
using namespace std;
using ll = long long;
int a[1001][999];

using unweighted_graph = vector<vector<int>>;
bool visit_dag(int n, const unweighted_graph &g, vector<int> &mark, vector<int> &l){
    if(mark[n]==1)return false;
    else if(mark[n]==0){
        mark[n]=1;
        for(auto &m:g[n])if(!visit_dag(m,g,mark,l))return false;
        mark[n]=2;
        l.push_back(n);
    }
    return true;
}
vector<int> topological_sort(const unweighted_graph &g){
    vector<int> mark(g.size(),0),l; rep(i,g.size())if(mark[i]==0&&!visit_dag(i,g,mark,l))return {}; reverse(l.begin(),l.end()); return l; }
bool is_dag(const unweighted_graph &g){ return !topological_sort(g).empty(); }
unweighted_graph inverse(const unweighted_graph &g){
    unweighted_graph h(g.size()); rep(i,g.size())rep(j,g[i].size())h[g[i][j]].push_back(i); return h; }

int longest_path_dag(const unweighted_graph &g){
    auto l=topological_sort(g);
    if(l.empty())return -1;
    auto h=inverse(g);
    vector<int> dist(g.size(),1);
    rep(i,g.size())rep(j,h[l[i]].size())dist[l[i]]=max(dist[l[i]],1+dist[h[l[i]][j]]);
    return *max_element(dist.begin(),dist.end());
}
int f(int a,int b,int n){
    return (a<b)?(b*(b-1)/2+a-b):f(b,a,n);
}
int main(){
    int n;
    cin >> n;
    rep2(i,1,n+1)rep(j,n-1)cin >> a[i][j];
    unweighted_graph g(n*(n-1)/2);
    rep2(i,1,n+1)rep(j,n-2)g[f(i,a[i][j],n)].push_back(f(i,a[i][j+1],n));
    cout << longest_path_dag(g) << endl;
    return 0;
}

Measured memory_bytes: 62804
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N, i;

int main()
{
    cin >> N >> i;
    cout << N - i + 1 << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(){
    string s;
    cin >> s;
    int v1=0,v2=0;
    rep(i,s.size()){
        if(s[i]=='0')v1++;
        if(s[i]=='1')v2++;
    }

    cout << min(v1,v2)*2;
    return 0;
}

Measured memory_bytes: 3752
n, k = map(int, input().split())
s = [0]*(n+1)

for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for j in range(d):
        s[a[j]] += 1

s[0] += 1
print(s.count(0))
    

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i<n; i++) cin >> a[i];
    for(int i = 0; i < n; i ++) {
        if(i==n-1) cout << a[i] << endl;
        else cout << a[i] << " ";
    }
    for(int i = 1; i < n; i ++) {
        int v = a[i];
        int j = i-1;
        while (j>=0 && a[j]>v) {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        for(int i = 0; i < n; i ++) {
            if(i==n-1) cout << a[i] << endl;
            else cout << a[i] << " ";
        }
    }
}


Measured memory_bytes: 3124
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scanner()
	bs := make([]int, len(s))
	if string(s[0]) == "B" {
		bs[0] = 1
	}
	ans := 0
	for i := 1; i < len(s); i++ {
		if string(s[i]) == "B" {
			bs[i] = bs[i-1] + 1
		} else {
			ans += bs[i-1]
			bs[i] = bs[i-1]
		}
	}
	fmt.Println(ans)
}

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

int main(){
  long long N;
  cin >> N;
  vector<int> A(N);
  for (int i=0;i<N;i++) cin >> A[i];
  sort(A.begin(),A.end());
  long long ans=0;
  for(int i=0;i<N/2;i++){
    ans+=(*(A.end()-i-1)-*(A.begin()+i))*2;
  }
  if( (N%2==0) ){
    ans+=*(A.begin()+N/2-1)-*(A.begin()+N/2);
  }else{
    if(
      *(A.begin()+N/2-1)-*(A.begin()+N/2)>
      *(A.begin()+N/2)-*(A.begin()+N/2+1) ){
      ans+=*(A.begin()+N/2-1)-*(A.begin()+N/2);
    }else{
      ans+=*(A.begin()+N/2)-*(A.begin()+N/2+1);
    }
  }
  cout << ans << endl;
}
  

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

#define gcd(a,b)		__gcd(a,b)
#define lcm(a,b)		(a*b)/gcd(a,b)
#define ff              first
#define ss              second
#define int             long long
#define float			double
#define pb              emplace_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vc				vector<char>
#define vb				vector<bool>
#define vf				vector<float>
#define vs				vector<string>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int>>
#define hashmap         unordered_map
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             INT64_MAX
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(x)			x.begin(),x.end()
#define digits(x)		floor(log10(x))+1
#define FIO				ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

template<class T>
void printV(vector<T> a) {for (auto v : a)cout << v << " ";}
template<class T>
void readV(vector<T>& a) {int n = a.size(); for (int i = 0 ; i < n ; i++)cin >> a[i];}
template<class T>
void printA(T* a , int n) {for (int i = 0; i < n  ; i++)cout << a[i] << " ";}
template<class T>
void readA(T* a , int n) {for (int i = 0 ; i < n ; i++)cin >> a[i];}
auto clk = clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
void run_time() {cout << endl<<"Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;}

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

unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
unsigned long long nCrModPFermat(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    unsigned long long fac[n + 1]; 
    fac[0] = 1; 
    for (int i = 1; i <= n; i++) 
        fac[i] = (fac[i - 1] * i) % p; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 

int32_t main() {
	aryan_pandeya();
	FIO;


	int s;
	cin>>s;


	int ans = 0 ; 
	for(int i = 1 ; i<=s/3 ; i++){
		int v = nCrModPFermat(s-2*i-1,i-1,mod);
		ans = (ans+v)%mod;
	}
	cout<<ans;




	return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <map>
#include <algorithm>    
#include <vector>       
#include <set>
#include <utility>  
#include <cstring>
#include <stdio.h>
#include <limits.h>
#include <queue>
#include <algorithm> 
#define MAX_DOUBLE  40000000000.0 
#include <math.h> 
#include <unistd.h>

using namespace std;



long long min(long long a, long long b){
	if(a > b) return b;
	return a;
}

long long max(long long a, long long b){
	if(a < b) return b;
	return a;
}

long long res[500][500];

int main(){
	vector<long long> vec;
	vector<long long> sum;
	long long sum_now = 0;
	sum.push_back(sum_now);
	int n;
	cin>>n;
	for(int i =0; i<n; i++){
		int a;
		cin>>a;
		vec.push_back(a);
		sum_now += a;
		sum.push_back(sum_now);
	}
	
	for(int i = n-1; i>=0; i--){
		for(int j = i; j<n; j++){
//			cout<<"####"<<i<<" "<<j<<"    : ";
			if(i == j){
				res[i][j] = 0;
			}else{
				int dif = j-i;
				if(dif == 1){
					res[i][j] = vec[i] + vec[j];
				}else{
					res[i][j] = res[i+1][j] ;
					res[i][j] = min(res[i][j], res[i][j-1]);
					
					for(int z = 0; z<dif; z++){
						res[i][j] = min(res[i][j], res[i][i+z]+res[i+z+1][j]);
					}
					
					res[i][j] += sum[j+1] - sum[i];
				} 
			}
			
//			cout<<res[i][j]<<endl;
		}
	}	
	
//	for(int i = 0; i<n; i++){
//		for(int j = 0; j<n; j++){
//			cout<<res[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	
	cout<<(res[0][n-1]);
}


Measured memory_bytes: 1792
/*
 * atcoder/abc089/b.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
void solve();
int main() { solve(); return 0; }

#define ull unsigned long long
void solve() {
  int n,k; cin >> n >> k;
  int count = 1;
  while (n/k!=0) count++,n/=k;
  cout << count << endl;
}


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

int main(){
	int a, b, c, t, x, y, z;
	
	cin >> a >> b >> c;
	
	if ( a > b ){ x = a, a = b, b = x; }
	if ( b > c ){ y = b, b = c, c = y; }
	if ( a > b ){ z = a, a = b, b = z; }
	
	cout << a << " " << b << " " << c <<endl;
	return 0;
}


Measured memory_bytes: 3088
import java.util.Scanner;
import java.util.TreeMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;


public class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int  max = 1;
    TreeMap<String, Integer> tm = new TreeMap<String,Integer>();
    List<String>keyList =new ArrayList<String>();
     
	for(int i =0; i<N; i++){
      String s = sc.next();
        if(tm.containsKey(s) == true){
           int number = tm.get(s) + 1;  //該当キーの値を１増やす準備
           tm.replace(s, number);
           if(max < number) max = number;
        }else{
           tm.put(s, 1);
           keyList.add(s);
        }
    }
    
    Collections.sort(keyList);
    
    for(int i=0; i<keyList.size(); i++){
      String s = keyList.get(i);
      int number = tm.get(s);
      if(number == max)
        System.out.println(s);
    }
    
  }
}


Measured memory_bytes: 85348