akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("in", "r", stdin),freopen("out", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int n, W;
int c[110], g[110];
ll dp[100][100001];
ll f(int i, int w){
    if(w < 0)return -1e15;
    if(i == n)
        return 0;
    ll &ans = dp[i][w];
    if(ans != -1)return ans;
    return ans = max(f(i + 1, w), f(i + 1, w - c[i]) + g[i]);
} 
int main(){
    //FL;
    FIN;
    cin >> n >> W;
    fore(i, 0, n)cin >> c[i] >> g[i];
    cls(dp, -1);
    cout << f(0, W) << '\n';
    EjecuteTime;
    return 0;
}       

Measured memory_bytes: 81880
#include<iostream>
#define ll long long int

using namespace std;

ll oddcnt(ll A,ll B)
{
    ll n = B-A+1;
    ll ans;

    if(n%4 == 0)
    {
        ans = A^(B-2);
        ans = ans^(B-1);
        ans = ans^B;
    }
    else if(n%4 == 1)
    {
        ans = A;
    }
    else if(n%4 == 2)
    {
        ans = A^B;
    }
    else
    {
        ans = A^(B-1);
        ans = ans^B;
    }

    return ans;
}

ll evencnt(ll A,ll B)
{
    ll n = B-A+1;
    ll ans;

    if(n%4 == 0)
    {
        ans = 0;
    }
    else if(n%4 == 1)
    {
        ans  = B;
    }
    else if(n%4 == 2)
    {
        ans = 1;
    }
    else
    {
        ans = 1^B;
    }

    return ans;
}


int main()
{
    ll A,B;

    cin>>A>>B;

    if(A%2)
        cout<<oddcnt(A,B);
    else
        cout<<evencnt(A,B);

    return 0;
}


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

using namespace std;

int main(){
  long long a, b, n, mx=0;
  cin >> a >> b >> n;
  if(b==1){
    cout << 0 << endl;
    return 0;
  }
  for(int i=1;i*b-1<=n;i++){
    long long t = i*b-1;
    mx = max(mx, (a*t/b) - a*(t/b));
  }
  long long t = n;
  mx = max(mx, (a*t/b) - a*(t/b));
  cout << mx << endl;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < N; X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair

using namespace std;

int main(){

    //距離が2と指定されているので、ダイクストラなど使わず
    //1から出ている島のmapとnへ行く島の集合を求めて確認する
    //O(N logN)のはず

    int n,m;
    cin >> n >> m;

    map<int,int> from1;
    map<int,int> ton;

    rep(i,m){
        int from,to;
        cin >> from >> to;

        if(from == 1) from1[to] = 1;
        if(to == n)   ton[from] = 1;
    }

    bool ans = false;

    for(auto i = from1.begin(); i != from1.end(); i++){
        int relay = i->first;

        if(ton[relay] == 1){
            ans = true;
            break;
        }
    }

    cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;

    return 0;
}

Measured memory_bytes: 14336
import collections as cl
import sys
input = sys.stdin.readline

N = int(input().strip())
S_list = [input().strip() for _ in range(N)]
# print(S_list)
c = cl.Counter(S_list)
# print(c)
max_num = max(c.values())

max_list = sorted([kv[0] for kv in c.items() if kv[1] == max_num])
print(*max_list)

Measured memory_bytes: 35940
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace A_ABC169
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            WriteLine(s[0]*s[1]);
        }
    }
}


Measured memory_bytes: 28016
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef long long int64;

int FastCalc(int num,int exp,int64 add,int64& result){
  for(int i=0;i<exp;i++){
    if(num>=5){
      num=(num-5)*2+1;
      result+=add*2;
      add/=2;
    }else{
      num=num*2;
      result+=add;
      add/=2;
    }
  }
  return num;
}

int GreedyCalc(vector<int>& vec,int64& result){
  int left=vec.front();
  for(int i=1;i<vec.size();i++){
    if(left+vec[i]<=9){
      result++;
      left=left+vec[i];
    }else{
      result+=2;
      int sum=left+vec[i];
      left=(sum/10)+sum%10;
      assert(left<=9);
    }
  }
  return left;
}

int LenCalc(int num,int64 amount,int64& result){
  vector<int> vec_len;
  while(amount>1){
    int exp=0;
    int64 add=1;
    while(amount>=add*2){
      exp++;
      add*=2;
    }
    add/=2;
    vec_len.push_back(FastCalc(num,exp,add,result));
    amount-=add*2;
  }
  if(amount==1){

    vec_len.push_back(num);
  }
  return GreedyCalc(vec_len,result);
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int m;
  cin>>m;
  vector<pair<int64,int64>> num;
  for(int i=0;i<m;i++){
    int64 d,c;
    cin>>d>>c;
    num.push_back(make_pair(d,c));
  }
  int offset=m;
  for(int i=0;i<=9;i++){
    num.push_back(make_pair(i,0));
  }

  vector<int> last_vec;

  int64 result=0;
  for(int i=0;i<m;i++){
    last_vec.push_back(LenCalc(num[i].first,num[i].second,result));
  }
  GreedyCalc(last_vec,result);
  cout<<result<<endl;



  return 0;
}

Measured memory_bytes: 6384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6+5;
const ll N = 1e3+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;

int main(){
    ll n,m;
    ll sum=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        ll x;
        cin>>x;
        sum+=x;
    }
    if(sum>n) cout<<"-1"<<endl;
    else cout<<n-sum<<endl;
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define imod(a , n) (a % n + n ) % n ;
#define int long long
const double eps = 1e-9 , PI = acos(-1) ;
const int N = 1e3 + 3 , oo = 1e9 , M = 30;

set<int>s ;
int32_t main(){
    int n , x , a ;
    cin >> x >> n ;
    while (n--){
        cin >>a ;
        s.insert(a);
    }
    for(int z = 0 ; 1 ; z++){
       if(!s.count(x - z) && !s.count(x + z)){
        cout << x - z ;return 0 ;
       }
       if(!s.count(x - z)){
        cout << x - z ;
        return 0 ;
       }
       if(!s.count(x + z)){
        cout << x + z ;
        return 0;
       }
    }

    return 0;
}


Measured memory_bytes: 3600
list = list(map(int,input().split()))

x=list[0]
a=list[1]
b=list[2]

if a>x:
    s=a-x
else:
    s=x-a

if b>x:
    t=b-x
else:
    t=x-b
    
if s<t:
    print('A')
else:
    print('B')

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

void init() {

}

int h[30];

void solve() {
	string w; cin >> w;
	for (char c: w) {
		++h[c-'a'];
	}
	for (int i = 'a'; i <= 'z'; ++i) {
		if (h[i-'a']&1) {
			puts("No");
			return;
		}
	}
	puts("Yes");
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>

#define MAX_H 50

using namespace std;

string S[MAX_H];

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    cin >> S[i];
  }

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (S[i][j] == '.') {
        int cnt = 0;
        for (int _i = max(0, i - 1); _i < min(H, i + 2); ++_i) {
          for (int _j = max(0, j - 1); _j < min(W, j + 2); ++_j) {
            if (S[_i][_j] == '#') {
              ++cnt;
            }
          }
        }
        S[i][j] = cnt + '0';
      }
    }
  }
  for (int i = 0; i < H; ++i) {
    printf("%s\n", S[i].c_str());
  }
}

Measured memory_bytes: 3104
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums=new int[(int)Math.pow(2,(int)(Math.log(n)/Math.log(2))+1)];
        for(int i=0;i<n;i++){
            nums[i]=sc.nextInt();
        }
        for(int i=0;i<(int)(Math.log(nums.length)/Math.log(2));i++){
            for(int j=0;j<nums.length/Math.pow(2,i+1);j++){
                nums[(int)Math.pow(2,i+1)*j]=gcm(nums[(int)Math.pow(2,i+1)*j],nums[(int)Math.pow(2,i+1)*j+(int)Math.pow(2,i)]);
                nums[(int)Math.pow(2,i+1)*j+(int)Math.pow(2,i)]=0;
            }
        }
        System.out.println(nums[0]);
    }

    private static int gcm(int n, int m) {
        int tmp;
        while (true) {
            if (n == 0) {
                return m;
            }else if(m==0){
                return n;
            }
            tmp = n;
            n = m;
            m = tmp;
            n = n % m;
            

        }

    }
}

Measured memory_bytes: 49684
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	

	int a,b,c;
	cin >> a>>b>>c;
	string s = "No";
	if (a+b+c==2*max(a,max(b,c))) {
		s = "Yes";
	}
	cout << s<< endl;
	
}


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

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))


using namespace std;


typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef pair<int,vi> iv;
typedef pair<LL,LL> pLL; 
typedef long double LD;


int main(){
	string s;
	cin>>s;
	vb present(26,false);
	for(auto c:s) present[(int)(c-'a')] = true;
	for(int i = 0; i < 26; ++i){
		if(!present[i]){
		 	cout<< char(i + (int)'a')<<endl;
		 	return 0;
		}
	}
	cout<<"None"<<endl;
	return 0;
}

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

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

ll gcd(ll a, ll b) { for (; b; a %= b, swap(a, b)); return a; }

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

	ll d, t, s; cin >> d >> t >> s;
	if (d <= t * s) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,n,s) for(int i=(int)(s);i<(int)(n);++i)
#define RREP(i,n,s) for(int i=(int)(s);i>=(int)(n);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

int dir[] = {1,0,-1,0,1};
int main() {
    int H,W;cin>>H>>W;
    string s[H];
    REP(i,H) cin>>s[i];

    bool f = true;
    REP(i,H) REP(j,W) {
        if(s[i][j] == '.') continue;
        bool b = false;
        REP(k,4) {
            int Y = i+dir[k], X = j+dir[k+1];
            if(Y<H && Y>=0 && X<W && X>=0) {
                if(s[Y][X] == '#') {
                    b = true;
                    break;
                }
            }
        }
        if(!b) {f = false; break;}
    }

    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {
  int h,w; cin>>h>>w;
  vector<vector<char>> m(h, vector<char>(w));
  rep(i, h) rep(j, w) cin>>m[i][j];

  rep(i, 2*h) {
    int tmp = i/2;
    rep(j, w) {
      printf("%c", m[tmp][j]);
    }
    printf("\n");
  }
}


Measured memory_bytes: 256
import Control.Monad
import Data.List

main :: IO ()
main = readLn >>= main'
    where
        main' n
            | n == 0 = return ()
            | otherwise = replicateM n readLn >>= print . solve n . sort >> main

solve :: Int -> [Int] -> Int
solve n = (`div` (n - 2)) . sum . tail . init 


Measured memory_bytes: 4056
A = list(map(int,input().split() ) )
total = 0

def findSumofDigits(n):
  sum = 0
  while n > 0:
    sum += n%10
    n /= 10
    n = int(n)
  return int(sum)

for i in range(1,int(A[0]+1)):
  temp = findSumofDigits(i)
  if (A[1] <= temp) and (temp <= A[2]):
    total += i
print(int(total))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;

int main() {
    ios::sync_with_stdio(false);
    cout.tie(0), cin.tie(0);
    int x;
    cin >> x;
    if (x == 0) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        long b = sc.nextLong();
        long n = sc.nextLong();
        long x = Math.min(b - 1, n);

        System.out.println(x * a / b);
    }
}

Measured memory_bytes: 35568
#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>;

const int INF = 1001001001;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    rep(i,n) {
      cin >> c[i];
      rep(j,m) cin >> a[i][j];
    }
    int ans = INF;
    rep(is,1<<n) {
      vector<int> algo(m);
      int cost = 0;
      rep(i,n) {
        if (is>>i&1) {
          rep(j,m) algo[j] += a[i][j];
          cost += c[i];
        }
      }
      bool t = true;
      rep(i,m) {
        if (algo[i] < x) t = false;
      }
      if (t) ans = min(ans, cost);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
pair<bool,int>p[100000];
int n,m,x,y,ans=0;
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        if(i)p[i].first=false;
        else p[i].first=true;
        p[i].second=1;
    }
    for(int i=0;i<m;i++){
        cin>>x>>y;
        if(p[x-1].first)p[y-1].first=true;
        p[x-1].second--;
        p[y-1].second++;
        if(!p[x-1].second)p[x-1].first=false;
    }
    for(int i=0;i<n;i++)if(p[i].first)ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

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

	int N, D; cin >> N >> D;
	if (N % (2 * D + 1) == 0) cout << N / (2 * D + 1) << endl;
	else cout << N / (2 * D + 1) + 1 << endl;


	return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        var input = MyUtil.ReadlongArray();

        var r = input[0];
        var g = input[1];
        var b = input[2];
        var target = input[3];

        int count = 0;

        for (long i = 0; i <= target; i++)
        {
            long r_count = r * i;
            for (long j = 0; j <= target; j++)
            {
                long g_count = j * g;
                var def = target - (r_count + g_count);
                if (def >= 0 && def % b == 0)
                {
                    ++count;
                }
            }
        }

        WriteLine(count);
        ReadKey();
    }
}
static class MyUtil
{
    public static long[] ReadlongArray()
    {
        return ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
    }

    /// <summary>
    /// <see cref="IEnumerable{T}"/>の各要素を並べてコンソールに出力します。各要素の間には半角スペースが一つ入ります。
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="ts"></param>
    public static void WriteToConsole<T>(this IEnumerable<T> ts)
    {
        StringBuilder stringBuilder = new StringBuilder();
        foreach (T t in ts)
        {
            stringBuilder.Append(t.ToString());
            stringBuilder.Append(" ");
        }
        stringBuilder.Remove(stringBuilder.Length - 1, 1);
        Console.WriteLine(stringBuilder.ToString());
    }
}


Measured memory_bytes: 11348
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        for (int i = 0, lastT = 0, lastX = 0, lastY = 0; i < n; i++) {
            int t = scanner.nextInt(), x = scanner.nextInt(), y = scanner.nextInt();

            int distance = Math.abs(x - lastX) + Math.abs(y - lastY);
            int j = distance - (t - lastT);
            if (j >= 1 || j % 2 == -1) {
                System.out.println("No");
                return;
            }

            lastT = t;
            lastX = x;
            lastY = y;
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 87192
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define pb(z) push_back(z)
#define ff first
#define ss second
#define pi(a,b) make_pair(a,b)
#define pii pair<ll,ll>
#define T int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define input(v,n) vector<int>v;for(int i=0;i<n;i++){int x;cin>>x;v.push_back(x);}
#define debugg(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;


const int inf    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 1e9+7;
const int mx     = 2e5+5;
//vector<int>v;
//for(int i=0; i<n; i++)
//{
//    int x;
//    cin>>x;
//    v.push_back(x);
//}


int main()
{
    IOS
    vector<ll>a,b,c;
    map<int,int>mp;
    int n,k;
    cin>>n;
    int cnt1=0,cnt2=0;
    rep(i,0,n-1)
    {
        ll t,x,y;
        cin>>t;
        b.pb(t);
    }
    ll sum=b[0]+b[n-2];
    rep(i,0,n-2)
    {
        sum+=min(b[i],b[i+1]);

    }
    cout<<sum<<endl;

}



Measured memory_bytes: 3648
n = gets.chomp.to_i
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)
bs.unshift(0)
bs.push(0)
ans = 0
(n + 1).times do |i|
  if bs[i] >= as[i]
    ans += as[i]
    bs[i] -= as[i]
    as[i] = 0
  else
    ans += bs[i]
    as[i] -= bs[i]
    bs[i] = 0
  end
  if bs[i + 1] >= as[i]
    ans += as[i]
    bs[i + 1] -= as[i]
    as[i] = 0
  else
    ans += bs[i + 1]
    as[i] -= bs[i + 1]
    bs[i + 1] = 0
  end
end
puts ans

Measured memory_bytes: 15884
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

class Dinic {
public:
    Dinic(int nElement) {
        m_edges = vector< vector<Edge> >(nElement);
        m_level = vector<int>(nElement);
        m_iter = vector<int>(nElement);
    }
    void addEdge(int from, int to, int cap) {
        m_edges[from].push_back(Edge(to, cap, m_edges[to].size()));
        m_edges[to].push_back(Edge(from, 0, m_edges[from].size()-1));
    }
    int maxFlow(int s, int t) {
        int flow = 0;
        for (;;) {
            bfs(s);
            if (m_level[t] < 0) break;
            fill(m_iter.begin(), m_iter.end(), 0);
            int f = 0;
            while ((f = dfs(s, t, INF)) > 0) {
                flow += f;
            }
        }
        return flow;
    }
private:
    struct Edge {
        int to, cap, rev;
        Edge(int t, int c, int r):to(t),cap(c),rev(r){}
    };
    static const int INF = 1000000000;
    vector< vector<Edge> > m_edges;
    vector<int> m_level;
    vector<int> m_iter;
    void bfs(int s) {
        fill(m_level.begin(), m_level.end(), -1);
        m_level[s] = 0;
        queue<int> que;
        que.push(s);
        while (que.size() > 0) {
            int v = que.front(); que.pop();
            for (int i = 0; i < m_edges[v].size(); i++) {
                Edge& e = m_edges[v][i];
                if (e.cap > 0 && m_level[e.to] == -1) {
                    m_level[e.to] = m_level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }
    int dfs(int v, int t, int f) {
        if (v == t) return f;
        for (int& i = m_iter[v]; i < m_edges[v].size(); i++) {
            Edge& e = m_edges[v][i];
            if (e.cap > 0 && m_level[e.to] > m_level[v]) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    m_edges[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
};



using P = pair<int, int>;

int n;
vector<P> a;
vector<P> b;

int main(){
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        int y;
        cin >> x >> y;
        a.push_back(make_pair(x, y));
    }
    for (int i = 0; i < n; ++i) {
        int x;
        int y;
        cin >> x >> y;
        b.push_back(make_pair(x, y));
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    Dinic d = Dinic(2 * n + 2);
    for (int i = 0; i < n; ++i) { 
        for (int j = 0; j < n; ++j) {
            if (a[i].first < b[j].first && a[i].second < b[j].second) {
                d.addEdge(i + 1, j + n + 1, 1);
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        d.addEdge(0, i + 1, 1);
        d.addEdge(i + n + 1, 2 * n + 1, 1);
    }

    cout << d.maxFlow(0, 2 * n + 1) << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h> 
typedef long long ll;
using namespace std;
const ll mod =998244353; 
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int t,a,b,c; 
int main(){
	int i,j;
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    a=read(),b=read(),c=read();
    swap(a,b),swap(a,c);
    printf("%d %d %d",a,b,c);
}

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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, m, k;
    int ans = 0;
    cin >> n >> m >> k;
    bool a[n][m];
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            char x;
            cin >> x;
            a[i][j] = (x == '#');
        }
    }
    for(int i = 0; i < (1<<n); i++) {
        for(int j = 0; j < (1<<m); j++) {
            int black = 0;
            for(int row = 0; row < n; row++) {
                for(int col = 0; col < m; col++) {
                    if((i & (1 << row)) or (j & (1 << col))) {
                        continue;
                    }
                    black += a[row][col];
                }
            }
            if(black == k) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3656
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false); 
    
    string S; cin >> S;

    string t = S;
    regex re("BC");
    t = regex_replace(t, re, "D");
    int N = t.size();

    ll ans = 0;
    ll cnt = 0;
    REP(i,N) {
        if (t[i]=='A') {
            cnt++;
        } else if (t[i]=='D') {
            ans += cnt;
        } else {
            cnt = 0;
        }
    }
    
    cout << ans << endl;

    return 0;
}

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

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(0);    
    cin.tie(0);
    int n,k;
    cin>>n;
    int z=n%10;
    if(z==0 || z==1 ||z==6 || z==8)
    {
    	cout<<"pon";
    }
    else if(z==3)
    {
    	cout<<"bon";
    }
    else
    {
    	cout<<"hon";
    }
    
  }		


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

int main(){
  int n;
  cin>>n;
  cout<<(n+1)/2<<endl;
}


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

int ans(int* a, int* b , int n, int q)
{
	if(b[n] >= 0)
		return b[n] ;
	for(int i = 0 ; i < q ; i++)
	{
		if(a[i]>n)
        {
            b[n] = max(b[n] , 0);
			break;
        }
        b[n] = max(b[n] , ans(a,b,n-a[i],q)^1);
	}
	return b[n];
}
int main() 
{
	int q , n ;
	cin >> q >> n ;
	int a[q] ;
	for(int i = 0 ; i < n ; i++)
		cin >> a[i] ;
	int b[n+1] ;
    for(int i = 0 ; i <= n ; i++)
        b[i] = -1;
    b[0] = 0 ;
    int flag = ans(a,b,n,q);
    if(flag == 0)
        cout << "Second" << endl;
    else
        cout << "First" << endl;
	return 0;
}

Measured memory_bytes: 8448
//
// Created by Jorge Andrés Esguerra Alarcón on 11/28/18.
//

#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>

#include <unordered_map>
#include <unordered_set>
using namespace std;

//string s;
//getline(cin, s);

typedef long long ll; // comments that are mixed in with code
typedef pair<int, int> pii;
typedef unsigned long ull; // are aligned to the right like this
typedef vector<pii> vii;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef priority_queue<int> maxPq;
typedef priority_queue<ll, vector<ll>, greater<ll> > minPq;
typedef deque<int> dq;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define forVar(type, var, init, till, increment) for (type var = init; var < till; var += increment)
#define deb(x) cout << x << endl;
#define MAX 30
#define INF 100000000
// Best macro definition has well established parentheses
int n;
ll hi;
vector<ll> nums;
ll minDist [100010];
int main()
{
    cin >> n;
    nums.push_back(0);
    for (int i = 0; i < n; ++i)
    {
        cin >> hi; 
        nums.push_back(hi);
    }
    
    minDist[0] = minDist[1] = 0;
    minDist[2] = abs(nums[2]-nums[1]);
    minDist[3] = abs(nums[3]- nums[1]);

    for (int i = 4; i <= n; i++)
    {
        minDist[i] = min(minDist[i-1] + abs(nums[i] - nums[i-1]), minDist[i-2] + abs(nums[i] - nums[i-2]));
    }


    cout << minDist[n] << endl;


}

Measured memory_bytes: 1908
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 100100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

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

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

    int N;cin >> N;
    vector<long long> retu(N);
    for(int i = 0;i<N;i++) cin >> retu.at(i);
    vector<int> bitCount(32);
    for(int i = 0;i<N;i++){
        bitset<32> BIT(retu.at(i));
        for(int j = 0;j<32;j++){
            if(BIT.test(j)) bitCount.at(j)++;
        }
    }
    bool ok = true;
    for(int i = 0;i<32;i++){
        int need = N/3;
        if(bitCount.at(i) >= need*2 && (N-bitCount.at(i)) >= need || bitCount.at(i) == 0){
            //ok
        }
        else{
            ok = false;
        }
    }
    if(ok){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,x;cin >> a >> b >> x;
    if(a==0){
        cout << b/x+1 << endl;
    }
    else{
        cout << b/x-(a-1)/x << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
} 

int main () {

    string s; cin >>s;
    ll n = s.length()-1;

    ll res = 0;
    for (ll bit = 0; bit < (1<<n); bit++) {
        ll sum = 0;
        string t = "";
        t += s[0];
        for (ll i = 0; i < n; i++) {
            if (bit & (1<<i)) {
                sum += stoll(t);
                t = "";
                t += s[i+1];
            } else {
                t += s[i+1];
            }
        }
        sum += stoll(t);
        res += sum;
    }

    cout << res << endl;
    
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;

int main(void) {
    Int n, k;
    cin >> n >> k;
    vector<pair<Int, Int> > a(n);
    for (Int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(), a.end());
    Int sum = 0;
    for (Int i = 0; i < n; ++i) {
        if (sum + a[i].second >= k) {
            cout << a[i].first << endl;
            break;
        } else {
            sum += a[i].second;
        }
    }
    return 0;
}



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

#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))

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


void solve(std::string S){
    bool flag = true;
    flag &= S[0] == 'A';
    flag &= ('a' <= S[1] && S[1] <= 'z');
    flag &= ('a' <= S[S.size()-1] && S[S.size()-1] <= 'z');

    bool flag2 = false;
    REP2(i, 2, S.size() - 1) {
        if(S[i] == 'C' && !flag2) {
            flag2 = true;
            continue;
        }

        flag &= ('a' <= S[i] && S[i] <= 'z');
    }

    cout << (flag && flag2 ? "AC" : "WA") << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
 
typedef long long ll;

using namespace std;

const int mod=1e9+7;
const int INF=1<<25;
map<ll,ll> mp;

ll dp(ll k){
  if(EXIST(mp,k)) return mp[k];
  return mp[k]=(dp(k/2)+dp((k-1)/2)+dp(k/2-1))%mod;
}

int main(){
  ll N;
  cin >> N ;
  mp[0]=1;
  mp[1]=2;
  cout << dp(N) << endl;
  return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n  # 根のノードは限らないので注意

    def find(self, x):  # あるノードの親を探すためのメソッド
        if self.parents[x] < 0:  # 親の場合、要素の個数を負の値で保持している
            return x  # 自身が親であるということ
        else:
            self.parents[x] = self.find(self.parents[x])  # 再帰的に親を探しにいく
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)  # この変数xに格納されているものは必ず根のノード
        y = self.find(y)  # この変数yに格納されているものは必ず根のノード
        if x == y:
            return  # もし同じ親ならば何も起こらない

        if self.parents[x] > self.parents[y]:  # それぞれ、要素の個数が負で格納されている
            # yのグループの方が要素が多いの場合（yの方が値が小さいということは、負の世界では値が大きいため）
            x, y = y, x  # 必ずxの方が要素が多い状態にする

        self.parents[x] += self.parents[y]  # 負の値だが、これでいい
        self.parents[y] = x  # yは親ではなくなったため、新しい親であるxの値を正でもつ

    def size(self, x):
        return -self.parents[self.find(x)]  # 親まで辿ればグループの大きさが負で格納されているため、それにマイナスをつけてreturnする

    def same(self, x, y):
        return self.find(x) == self.find(y)  # 親が同じならTrueが返却される

    def members(self, x):  # この実装変じゃね？
        root = self.find(x)  # 親の値を取得する
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_counts(self):
        return len(self.roots())  # グループの数を返す

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}  # 親のノード番号をキーにして、子のノードを対応させた辞書を返す

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    uf.union(a, b)

ans = 0
for a in uf.roots():
    ans = max(ans, uf.size(a))
print(ans)


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

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

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


struct UnionFind{
    vector<ll> r;
    UnionFind(ll N){
        r = vector<ll>(N, -1);
    }

    ll root(ll x){
        if(r[x]<0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(ll x, ll y){
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(r[x]>r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    ll size(ll x){
        return -r[root(x)];
    }
};

int main(){

    ll n, m; cin >> n >> m;

    UnionFind UF(n);
    rep(i, m){
        ll a, b; cin >> a >> b;
        UF.unite(a-1, b-1);
    }

    ll ans = 0;
    rep(i, n){
        chmax(ans,UF.size(i));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4832
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
ll n,k,L,a[200005];
ll sum(ll x){
    ll res=0,s=0;
    int j=0;
    for(int i=0;i<n;i++){
        while(s<k&&j<n){
            if(a[j]<=x)s++;
            j++;
        }
        if(s==k)res+=(n-j+1);
        if(a[i]<=x)s--;
    }
    return res;
}
int main(void){
    cin>>n>>k>>L;
    for(int i=0;i<n;i++)cin>>a[i];
    ll l=0,r=n;
    while(r-l>1){
        ll m=(r+l)/2;
        if(sum(m)<L)l=m;
        else r=m;
    }
    cout<<r<<endl;
}



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

#define all(v) v.begin(), v.end()
#define mp make_pair
#define EPS (int)1e-9
#define PI acos(-1)
#define endl '\n'
#define pb push_back
#define fi first
#define se second

using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

const int mod = 1000000007;


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

	int ans;

	for(int i = 0; pow(2,i) <= n; i++)
		ans = pow(2,i);

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

Measured memory_bytes: 256
data = input().rstrip().split(" ")
a_hp = int(data[0])
a_attack = int(data[1])
b_hp = int(data[2])
b_attack = int(data[3])
a_times = 0
b_times = 0
while a_hp > 0:
    b_times += 1
    a_hp -= b_attack
while b_hp > 0:
    a_times += 1
    b_hp -= a_attack
if a_times <= b_times:
    print("Yes")
else:
    print("No")    

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

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef pair < ll , ll > pp;
const int mod = 1e9 + 7;
const int N   = 2e5 + 5;

vector < int > V[N];
int T[N],T2[N],W[N],A[N],n,i,j,x,y,t,t2,h,a;

main(){
    cin >> n;
    if(n == 2) { cout << "1 2"; return 0; }
    for(i=2;i<=n;i++){
        cin >> x >> y;
        V[x].pb(y); V[y].pb(x);
        W[x]++; W[y]++;
    }
    for(i=1;i<=n;i++){
        if(V[i].size() == 1) { W[i] = 0; W[ V[i][0] ]--; }
    }

    for(i=1;i<=n;i++)
        if(W[i] > 2){
            cout << -1;
            return 0;
        }

    for(i=1;i<=n;i++){
        if(W[i] == 1){
            x = i;
            for(; W[x] ; x = y){
                A[++a] = x;
                W[x] = 0;
                y = 0;
                for(j=0;j<V[x].size();j++)
                    if(W[ V[x][j] ])
                        y = V[x][j];
            }
            break;
        }
    }

    if(a == 0){
        for(i=1;i<=n;i++)
            if(V[i].size() > 1)
                A[++a] = i;
    }

    T[++t] = 1;
    for(i=1;i<=a;i++){
        x = A[i];
        x = j = V[x].size()-2;
        for(;j--; t++)
            T[t+1] = t+2;
        T[t+1] = t+1-x; t++;
    }

    T2[++t2] = 1;
    for(i=a; i ;i--){
        x = A[i];
        x = j = V[x].size()-2;
        for(;j--; t2++)
            T2[t2+1] = t2+2;
        T2[t2+1] = t2+1-x; t2++;
    }

    for(i=1;i<n;i++){
        if(h == -1) cout << T[i] << " ";
        if(h == 1) cout << T2[i] << " ";
        if(h == 0){
            if(T[i] == T2[i]) cout << T[i] << " ";
            if(T[i] < T2[i]) { h = -1; i--; }
            if(T2[i] < T[i]) { h = 1; i--; }
        }
    }

    cout << n << endl;
    return 0;
}

Measured memory_bytes: 10880
#include<cstdio>
using namespace std;
struct CARD{
	int n;char c;
}card[40];
void CardSwap(CARD &c1,CARD &c2){
	CARD temp=c2;c2=c1;c1=temp;
}
void CardCopy(CARD c1[],CARD c2[],int n){
	for(int i=0;i<n;i++){
		c1[i]=c2[i];
	}
}
void pr(CARD c[],int n,bool flag){
	int first=1;
	for(int i=0;i<n;i++){
		if(first)first=0;else putchar(' ');
		printf("%c%d",c[i].c,c[i].n);
	}
	printf("\n%stable\n",flag?"S":"Not s");
}
void BubbleSort(CARD card[],int N){
	int flag=1,i,j;
	for(i=0;flag;i++){
		flag=0;
		for(j=N-1;j>i;j--){
			if(card[j].n<card[j-1].n){
				CardSwap(card[j],card[j-1]);
				flag=1;
			}
		}
	}
	return;
}
void SelectSort(CARD card[],int N){
	int i,j,minj;
	for( i=0;i<N;i++){
		minj=i;
		for(j=i;j<N;j++){
			if(card[minj].n>card[j].n)minj=j;
		}
		if(minj!=i)CardSwap(card[minj],card[i]);
	}
	return;
}
int main(){
	int N;
	scanf("%d\n",&N);
	for(int i=0;i<N;i++){
		card[i].c=getchar();
		card[i].n=getchar()-'0';
		getchar();
	}
	CARD c1[40],c2[40];
	CardCopy(c1,card,N);
	CardCopy(c2,card,N);
	BubbleSort(c1,N);
	SelectSort(c2,N);
	bool flag=true;
	for(int i=0;i<N;i++){
		if(c1[i].n==c2[i].n&&c1[i].c==c2[i].c)continue;
		else {
			flag=false;break;
		}
	}
	pr(c1,N,true);
	pr(c2,N,flag);
}


Measured memory_bytes: 2680