akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = input()
b = input()
c = input()
cnt = 0
for i in range(n):
    if a[i]==b[i] and b[i]==c[i]:
        cnt = cnt
    elif a[i]==b[i] or b[i]==c[i] or c[i]==a[i]:
        cnt += 1
    else:
        cnt += 2
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int dp[100005][4];
int n;
int a[100005],b[100005],c[100005];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
	}
	for(int i=1;i<=n;i++){
		dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i];
		dp[i][2]=max(dp[i-1][1],dp[i-1][3])+b[i];
		dp[i][3]=max(dp[i-1][1],dp[i-1][2])+c[i];
	}
	printf("%d\n",max(dp[n][1],max(dp[n][2],dp[n][3])));

	return 0;
}

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

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

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

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

ll w, h, n, s[100001], result = INF;

signed main() {
  rep(i, 100001) s[i] = 0;
	cin >> w >> h >> n;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    s[y] = max(s[y], x);
  }
  dep(i, h - 2, 0) s[i] = max(s[i], s[i + 1]);
  rep(i, h) result = min(result, s[i + 1] + i);
  cout << result << endl;
	return 0;
}


Measured memory_bytes: 4008
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    a=int(input())
    print(n*n-a)
main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
	ll A, B, K;
	cin >> A >> B >> K;
	if(A>0) {
		if(A>K) {
			A = A - K;
			K = 0;
		} else {
			K = K - A;
			A = 0;
		}
		//cout << A << ' ' << B  << ' ' << K << endl;
	}
		if(B>0) {
			if(B>K) {
				B -= K;
				K = 0;
			} else {
				K -= B;
				B = 0;
			}
		}

	cout << A << ' ' << B << endl;
		
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;cin>>A>>B;
  vector<int> a(20);
  a.at(0)=1;
  for(int i=1;i<20;i++){
    a.at(i)=a.at(i-1)+A-1;
  }
  
  int ans;
  for(int i=0;i<20;i++){
    if(a.at(i)>=B){
      ans=i;
      break;
    }
  }
  cout<<ans<<endl;
}



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

vector <int> vec;

long long calc(){
	long long res = 0; 
	for(int i = 0; i < vec.size(); i++){
		res += vec[i];
	}
	return res; 
}

void solution(string s){
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '<')
			vec[i+1] = vec[i] + 1; // Since <, next has to be greater
  }

	for(int i = s.size()-1; i >= 0; i--){
		if(s[i] == '>')
			vec[i] = max(vec[i], vec[i+1]+1);
	}

	cout << calc() << endl;
}

int main(){
	string s;
	cin >> s;

	// Set everything in the vector to 0
	for(int i = 0; i < s.size()+1; i++)
		vec.push_back(0);

	solution(s);
}

Measured memory_bytes: 5804
#include "bits/stdc++.h"

#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

int N, M;
int k;
vector<bitset<10>> S(10);
vector<int> p(10);

int a_count(int a, int p, bitset<10> b)
{
   bitset<10> N(a);
   if ((N & b).count() % 2 == p)
   {
      return 1;
   }
   return 0;
}

void Main()
{
   int s;
   cin >> N >> M;
   for (int i = 0; i < 10; i++)
   {
      S[i].reset();
   }
   for (int i = 0; i < M; i++)
   {
      cin >> k;
      for (int j = 0; j < k; j++)
      {
         cin >> s;
         S[i].flip(s - 1);
      }
   }
   for (int i = 0; i < M; i++)
      cin >> p[i];
   int count = 0;
   int sum;
   for (int a = 0; a < (2 << (N - 1)); a++)
   {
      sum = 0;
      for (int i = 0; i < M; i++)
      {
         sum += a_count(a, p[i], S[i]);
      }
      if (sum == M)
         count++;
   }
   cout << count << endl;
}

int main()
{
   std::cin.tie(nullptr);
   std::ios_base::sync_with_stdio(false);
   std::cout << std::fixed << std::setprecision(15);
   Main();
   return 0;
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};
vector<int> v(3);
void solve() {
	int lb = max({ v[0],v[1],v[2] });
	int sum = v[0] + v[1] + v[2];
	lb += (lb*3-sum) % 2;
	cout << (3*lb - sum) / 2 << endl;
}
int main() {
	while (cin >> v[0] >> v[1] >> v[2]) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int a,b,c;
string s,t,u;

main(){
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		string tmp;
		for(int j=i;j<s.size()+i;j++)tmp+=s[j%s.size()];
		if(tmp==t){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mx(a,b) (a>b?a:b)
#define N 200001
using namespace std;
struct knf{int k,f;}a[N];
int n,h,cmp(knf,knf),p,q,ans;
int main()
{
	scanf("%d%d",&n,&h),n*=2;
	for(int i=1;i<=n;i+=2)
		scanf("%d%d",&p,&q),
		a[i].k=p,a[i].f=0,
		a[i+1].k=q,a[i+1].f=1;
	sort(a+1,a+n+1,cmp);
	for(int i=1;h>0;i++)
		if(a[i].f)h-=a[i].k,ans++;
		else ans+=(h-1)/a[i].k+1,h=0;
	printf("%d\n",ans),exit(0);
}
int cmp(knf o,knf u)
{return o.k>u.k;}

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

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

int main() {
  int N;
  long long K,ans,c,g;
    cin>>N>>K;
  long long a[N+1],b[N+1],d[N+1];
  for(int i=1;i<N+1;i++){
    cin>>a[i];
    d[i]=0;
  }
  b[1]=1;
  d[1]=1;
  
  for(int i=2;i<N+1;i++){
    b[i]=a[b[i-1]];
      if(d[b[i]]==0){
        d[b[i]]=1;
      }
    
    else{
      c=i-1; 
      break;
    }
  }
   for(int i=1;i<N+1;i++){
     if(b[i]==b[c+1]){
       g=i-1;
       break;
     }
   }
  if(c>K){
    cout<<b[K+1]<<endl;
    return 0;
  }
    K-=g;
  K%=(c-g);
    
  cout<<b[K+g+1]<<endl;
}


Measured memory_bytes: 8088
from bisect import *
def solve():
  ans = 0
  N, D, A = map(int, input().split())
  B = [list(map(int, input().split())) for _ in range(N)]
  B.sort()
  lasts = [0]*(N+1)
  now = 0
  for i,((x,h),l) in enumerate(zip(B,lasts)):
    now -= l
    atack = max(0,-(-(h-now)//A))
    ans += atack
    damage = atack*A
    now += damage
    last = x+2*D
    ind = bisect_right(B,[last+1,0])
    lasts[ind] += damage
  return ans
print(solve())

Measured memory_bytes: 109500
a = list(map(int, input().split()))
b = list(map(int, input().split()))

summer_vacation = a[0]
homework = a[1]
homework_for_days = sum(b)

if homework_for_days > summer_vacation:
    print(-1)
else:
    result = summer_vacation - homework_for_days
    print(result)

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

int main(void)
{
	char S[15];
	int lenS, i, x, ans = 1000;

	scanf("%s", S);
	for (lenS = 0; S[lenS] != '\0'; lenS++);//文字列の長さ
	for (i = 0; i <= lenS - 3; i++) {
		x = (S[i] - '0') * 100 + (S[i + 1] - '0') * 10 + S[i + 2] - '0';
		if (ans > abs(753-x)) {
			ans = abs(753-x);
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,X;
	while(cin>>N>>X) {
		VI A(N);
		REP(i, N) cin>>A[i];
		sort(ALL(A));
		ll ans=0;
		REP(i, N) {
			if(i<N-1) {
				if(A[i]<=X) {X-=A[i];ans++;}
			} else {
				if(A[i]==X) {X-=A[i];ans++;}
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

typedef long long ll ;
typedef double db;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define sf(a)		 scanf("%d",&a)
#define sfl(a)		scanf("%lld",&a)
#define sff(a,b)	 scanf("%d %d",&a,&b)
#define sffl(a,b)	scanf("%lld %lld",&a,&b)
#define pb(a)         push_back(a)
#define loop0(i,n)          for(int i=0;i<n;i++)
#define loop1(i,n)          for(int i=1;i<=n;i++)
#define loopab(a,b)       for(int i=a;i<=b;i++)
//#define gcd(a, b)     __gcd(a, b)
//#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)     cout<<"Case "<<z<<": "<<x<<"\n"
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
ll gcd(ll a,ll b){
	while(b){
		ll r = a%b;
		a = b;
		b = r;
		}
	return a;
	}
ll lcm(ll a, ll b){
	return (a*b)/(gcd(a,b));
	}
ll ok_google(ll b, ll c,ll d){
	ll l = b/(lcm(c,d));
	return (b - (((b/c)-l)+ ((b/d)-l) + l));
	}
int main()
{
	ll a,b,c,d,l,ans;
	cin>>a>>b>>c>>d;
//	let our google work :3
	ans = ok_google(b,c,d) - ok_google(a-1,c,d);
	cout<<ans<<nw;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long r,c;
    cin>>r>>c;
    string s[r+2];
    for(int i=0;i<=c;i++)
        s[0].push_back('s');
    for(int i=1;i<=r;i++)
    {
        cin>>s[i];
        s[i]='#'+s[i];
    }
    long long a[r+2][c+2]={};

    for(int i=0;i<r+1;i++)
        for(int j=0;j<c+1;j++)
        a[i][j]=LLONG_MAX;

    if(s[1][1]=='#')
        a[1][1]=1;
    else a[1][1]=0;
    for(int i=1;i<=r;i++)
    {
        for(int j=1;j<=c;j++)
        {
            if(i==1 && j==1)
                continue;
            else if(s[i][j]=='.')
            {
                a[i][j]=min(a[i-1][j],a[i][j-1]);
            }
            else
            {
                if(s[i-1][j]=='#')
                    a[i][j]=a[i-1][j];
                if(s[i][j-1]=='#')
                    a[i][j]=min(a[i][j],a[i][j-1]);
                if(s[i][j-1]=='.')
                    a[i][j]=min(a[i][j-1]+1,a[i][j]);
                if(s[i-1][j]=='.')
                    a[i][j]=min(a[i][j],a[i-1][j]+1);
            }
        }
    }
    cout<<a[r][c]<<endl;
    return 0;
}


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

const int MOD = (int)1e9+7;

class Union_Find_size{
public:
	vector<int> Parent;

	//コンストラクタ
	Union_Find_size(int N){
		Parent=vector<int>(N,-1);
	}

	//木の根を求める
	int root(int x){
		//x（自分）が親ならxを返す
		if(Parent.at(x)<0)	return x;
		//経路圧縮しながら return する
		return Parent.at(x)=root(Parent.at(x));
	}

	//xの属する木の要素数を調べる
	int size(int x){
		return -Parent.at(root(x));
	}

	//xとyが同じ集合に属するかを判定する
	bool same(int x,int y){
		return root(x)==root(y);
	}

	//xとyの属する集合を併合する
	void unite(int x,int y){
		x=root(x);
		y=root(y);
		if(x==y)	return;

		if(size(x)<size(y))	swap(x,y);
		Parent.at(x)+=Parent.at(y);
		Parent.at(y)=x;
	}
};

int main(){
	int N,M;
	cin >> N >> M;
	vector<int> p(N);
	for(int i=0;i<N;i++)	cin >> p.at(i);
	vector<int> x(M),y(M);
	for(int i=0;i<M;i++){
		cin >> x.at(i) >> y.at(i);
		x.at(i)--;
		y.at(i)--;
	}

	Union_Find_size uni(N);
	for(int i=0;i<M;i++){
		uni.unite(x.at(i),y.at(i));
	}
	int ans=0;
	for(int i=0;i<N;i++){
		if(uni.same(p.at(i)-1,i))	ans++;
	}
	cout << ans << endl;
	
	return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int A, B, X;
    cin >> A >> B >> X;
    if (0 <= X - A && X - A <= B)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>){
    // val (K, N) = readLine()!!.split(" ").map(String::toInt)
    val S = readLine()!!

    if (S[2] == S[3] && S[4] == S[5]){
        println("Yes")
    } else{
        println("No")
    }

}

Measured memory_bytes: 31748
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s[0] == 'S')cout << "Cloudy" << endl;
  else if(s[0] == 'C')cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#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<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
const long long Mod=1e9+7;
struct node
{
	long long x,y;
};
int n,h[110];
long long pw(long long x,long long y)
{
	long long res=1;
	while (y)
	{
		if (y&1)
		{
			res=res*x%Mod;
		}
		y>>=1;
		x=x*x%Mod;
	}
	return res;
}
node work(int l,int r,int lim)
{
	node res;
	if (l==r)
	{
		res.x=0;
		res.y=pw(2,h[l]-lim);
		return res;
	}
	int mn=l;
	for (int i=l+1;i<=r;i++)
	{
		if (h[i]<h[mn])
		{
			mn=i;
		}
	}
	node x,y;
	if (mn==l)
	{
		y=work(mn+1,r,h[mn]);
		res.x=(y.x+y.y)*2%Mod;
		res.y=y.y*pw(2,h[mn]-lim)%Mod;
	}
	else if (mn==r)
	{
		x=work(l,mn-1,h[mn]);
		res.x=(x.x+x.y)*2%Mod;
		res.y=x.y*pw(2,h[mn]-lim)%Mod;
	}
	else
	{
		x=work(l,mn-1,h[mn]);
		y=work(mn+1,r,h[mn]);
		res.x=(x.x*y.x%Mod*2%Mod+x.x*y.y%Mod*4%Mod+x.y*y.x%Mod*4%Mod+x.y*y.y%Mod*6%Mod)%Mod;
		res.y=x.y*y.y%Mod*pw(2,h[mn]-lim)%Mod;
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&h[i]);
	}
	long long ans;
	node res=work(1,n,0);
	ans=(res.x+res.y)%Mod;
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,n) for(int i=(1);i<(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    string s;
    cin>>s;
    int n=s.size();
    cout<<s[0]<<n-2<<s[n-1]<<'\n';

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();++i){
    if(s.substr(i,5)=="dream"){
      i+=4;
      if(s.substr(i+1,2)=="er"&&s[i+3]!='a')i+=2;
    }
    else if(s.substr(i,5)=="erase"){
      i+=4;
      if(s[i+1]=='r')i++;
    }
    else return cout<<"NO",0;
  }
  cout<<"YES";
}

Measured memory_bytes: 512
/**
 * Title: D - Face Produces Unhappiness
 * Url: https://atcoder.jp/contests/abc140/tasks/abc140_d
 * 
 * 方針：一番左の人の向きの人を最大化する
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int N, K;
string S;

int main() {
    cin >> N >> K;
    cin >> S;

    vector<pair<char, int>> dic;

    char target;
    int cnt = 0;
    for(int i=0; i<N; i++) {
        if(i==0) {
            target = S[i];
            cnt++;
        } else {
            if(S[i]==target) {
                cnt++;
            } else {
                dic.push_back(make_pair(target, cnt));
                target = S[i];
                cnt = 1;
            }
        }
    }
    dic.push_back(make_pair(target, cnt));
    if(dic.size()==1) {
        cout << dic[0].second - 1 << endl;
        return 0;
    }

    // for(auto di:dic) {
    //     cout << "(" << di.first << "," << di.second << ")" << endl;
    // }

    int counter = 0;
    target = dic[0].first;
    // cout << target << endl;
    for(int i=0; i<dic.size(); i++) {
        if(i==0) continue;
        if(counter>=K) break;
        if(dic[i].first!=target) {
            dic[i].first = target;
            counter++;
        }
    }
    // for(auto di:dic) {
    //     cout << "(" << di.first << "," << di.second << ")" << endl;
    // }
    ll ans = 0;
    int tmp_ans = dic[0].second;
    for(int i=1; i<dic.size(); i++) {
        if(dic[i].first != dic[i-1].first) {
            ans += tmp_ans - 1;
            tmp_ans = dic[i].second;
            if(i==dic.size()-1) {
                ans += tmp_ans - 1;
            }
        } else {
            tmp_ans += dic[i].second;
            if(i==dic.size()-1) {
                ans += tmp_ans - 1;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
typedef long long ll;

int main(){
  int a,b;
  cin >> a >> b;
  cout << 6-a-b << endl;
}


Measured memory_bytes: 256
use std::io::stdin;
fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let x:Vec<char> = st.trim().chars().collect();
    if (&x[2]==&x[3]) && (&x[4]==&x[5]) {
        println!("Yes");
    } else {
        println!("No")
    }
}

Measured memory_bytes: 2076
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <limits.h>
#include <math.h>

int main(int argc, char *argv[])
{
    int a, p;
    int ans;

    scanf("%d %d", &a, &p);

    p += a * 3;
    ans = p / 2;

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
n,TIME = list(map(int, input().split()))

x = 0
num = 1
costs = []

while num <= n:
    cost, time = list(map(int, input().split()))
    num += 1
    if TIME - time >= 0:
        costs.append(cost)

if len(costs) != 0:
    output = min(costs)
else:
    output = "TLE"
print(output)


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

int n,A[50];

int solve(int i, int m){
    if (m == 0){return true;}
    if(i >= n){return false;}
    int res = solve(i+1,m)||solve(i+1,m-A[i]);
    return res;
}

int main(){
    int i,q,m;
    scanf("%d",&n);
    for(i = 0;i<n;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&q);
    for (i = 0;i<q;i++){
        scanf("%d",&m);
        if (solve(0,m)){printf("yes\n");}
        else printf("no\n");
    }
    return 0;
}

Measured memory_bytes: 3148
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()
    n = len(s)

    for i in range(1, n):
        if s[i - 1] == s[i]:
            print(i, i + 1)
            exit()

    for j in range(2, n):
        if s[j - 2] == s[j]:
            print(j - 1, j + 1)
            exit()

    print(-1, -1)


if __name__ == '__main__':
    resolve()


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

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

    vector<int> x(N), y(N), h(N);
    for (int i = 0; i < N; i++)
    {
        cin >> x[i] >> y[i] >> h[i];
    }

    int MAX = 100;
    for (int posY = 0; posY <= MAX; posY++)
    {
        for (int posX = 0; posX <= MAX; posX++)
        {
            int needH = -1;

            for (int i = 0; i < N; i++)
            {
                if (h[i] > 0)
                {
                    int tmp = h[i] + abs(posY - y[i]) + abs(posX - x[i]);
                    if (needH == -1)
                    {
                        needH = tmp;
                    }
                    else
                    {
                        if (needH != tmp)
                        {
                            needH = -2;
                            break;
                        }
                    }
                }
            }
            if (needH == -2)
                continue;
            for (int i = 0; i < N; i++)
            {
                if (h[i] == 0)
                {
                    int dist = abs(posY - y[i]) + abs(posX - x[i]);
                    if (needH > dist)
                    {
                        needH = -2;
                        break;
                    }
                }
            }
            if (needH == -2)
                continue;

            cout << posX << " " << posY << " " << needH << endl;
            return 0;
        }
    }
    return 0;
}

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

using namespace std;

#define ll long long 
#define IOS ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define SIZE 100005

int main()
{
    int a, b;
    cin>> a >>b;
    if(b < a) swap(a,b);
    if(a==1 && b == 2) cout << 3 << endl;
    else if(a==1 && b==3) cout << 2 << endl;
    else cout<< 1 << endl;	
	return 0;
}



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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll M1,D1,M2,D2;
    cin >> M1 >> D1;
    cin >> M2 >> D2;
    SANKOU(M1 != M2,1,0);
}

Measured memory_bytes: 3476
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
int a[maxn] , book[maxn];
int  main(){
 //   ios::sync_with_stdio(false);
    int n ; cin >> n;
    for (int i = 1 ; i < n ; i++) cin >> a[i] , book[a[i]]++;
    for (int i = 1 ; i <= n ; i++)
        cout << book[i] << endl;
    return 0;
}


Measured memory_bytes: 5148
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int64_t get_int(void) {
  int64_t num;
  scanf("%lld", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int64_t *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%lld", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 100000
#define INF (int64_t)(1e+14)

int main(void) {
    int num, qs;
    get_int2(&num, &qs);

    static int64_t arr[NUM_MAX+1];
    fget_array(arr, num);
    arr[num] = INF; // guard
    int i;
    for(i = 0; i < qs; i++) {
        int64_t q = get_int();
        int64_t sum = 0;
        int64_t cnt = 0;
        int right = 0;
        int left;
        for(left = 0; left < num+1; left++) {
            // sum is always sum <= q
            for(; right < num+1; right++) {
                if(sum > q) break;
                sum += arr[right];
            }
#ifdef DEBUG
            printf("[%d, %d)\n", left, right);
#endif
            cnt += (right - left - 1);
            sum -= arr[left];
        }
        printf("%lld\n", cnt);
    }
    return 0;
}


Measured memory_bytes: 2560
#include <cstdio>

inline void swap(int array[], int a, int b){
	int c = array[a];
	array[a] = array[b];
	array[b] = c;
}

int main(){
	int array[50];
	int w,n,a,b;

	for(int i=0 ; i<50 ; i++){
		array[i] = i;
	}
	
	scanf("%d", &w);
	scanf("%d", &n);
	for(int i=0 ; i<n ; i++){
		scanf("%d,%d", &a, &b);
		swap( array , a , b );
	}
	for(int i=1 ; i<=w ; i++){
		printf("%d\n", array[i]);
	}
}

Measured memory_bytes: 2728
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		//入力された二つの数字を変数に格納
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a > b){
			System.out.println("a > b");
		}else if(a < b){
			System.out.println("a < b");
		}else if(a == b){
			System.out.println("a == b");
		}else{
			System.out.println("error");
		}
		
	}
}



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

int main() {
  
 int a, b; 
  cin >> a >> b ;

 int ans = max(a,b) - min(a,b) ;
  
  if ( ans%2 == 0 )
  	cout << max(a,b) - ans/2 << endl;
  else
    cout << "IMPOSSIBLE" << endl ;
 }

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

int n;
map<int,int> A;
vector<int> B;

int main(){
	cin >> n;

	for(int i=0;i<n;i++){
		int x;
		cin >> x;
		A[x]++;
		if(A[x]==2){
			B.push_back(x);
			A[x]=0;
		}
	}

	sort(B.begin(),B.end());
	reverse(B.begin(),B.end());

	if(B.size()>1)	cout << (long long)B[0]*B[1] << endl;
	else	cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>


using namespace std;

using ll = long long int;
using lln = long long unsigned;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()
const long MOD = pow(10, 9) + 7;

char alfa[] = { 'A','B' ,'C','D' ,'E' ,'F' ,'G' ,'H' ,'I' ,'J' ,'K' ,'L' ,'M' ,'N' ,'O' ,'P' ,'Q' ,'R' ,'S' ,'T' ,'U' ,'V' ,'W' ,'X' ,'Y','Z' };

inline void finish() {
	cout << -1 << endl;
	exit(0);
}

unsigned GetDigit(double num) {
	return log10(num) + 1;
}

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

class Mod {
public:
	static inline ll Add(ll a, ll b) {
		return (a + b) % MOD;
	}

	static inline ll Sub(ll a, ll b) {
		ll ans = (a - b) % MOD;
		return (ans < 0) ? (ans + MOD) : ans;
	}

	static inline ll Mul(ll a, ll b) {
		return (a * b) % MOD;
	}

	static inline ll Div(ll a, ll b) {
		return (a % MOD) * modinv(b, MOD) % MOD;
	}
};



template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (ll i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

void Main();
inline void DebugMain() {
	while (true) {
		Main();
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	bool debug = false;
	if (debug) {
		cout << "\x1b[41m" << "Debug Mode " << endl;
	}
	(debug) ? DebugMain() : Main();
	return 0;
}

int parmitation(ll N) {
	ll ans = 1;
	for (ll i = 1; i <= N; i++) {
		ans *= i;
	}

	return ans;
}

int SemiCommonMultiple(ll A, ll ANum, ll B, ll BNum, ll diff, ll max) {
	ll calc;
	calc = diff + B * BNum - A * ANum;

	if (diff + B * BNum > max) {
		return 0;
	}
	else {
		if (calc < 0) {
			SemiCommonMultiple(A, ANum, B, ++BNum, diff, max);
		}
		else if (calc > 0) {
			SemiCommonMultiple(A, ++ANum, B, BNum, diff, max);
		}
		else {
			return A * (ANum + 0.5);
		}
	}
}

inline void Main() {
	ll X, Y, N, M, K;
	vector<bool> A;
	vector<ll> B;
	ll M1 = 1, D1 = 0, M2 = 1, D2 = 0;
	ll ans, temp;
	ll sum = 0, WAcount = 0,ACcount =0, a = 0;
	double avg = 0.0;
	string S;
	string T;
	string Ans = "";
	bool b[8];
	bool flag = false;


	cin >> M >> X;


	cout << (int)(((double)(M)/X) + 0.999999999999);
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        int zero = 0;
        int one = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '0') {
                zero++;
            }else {
                one++;
            }
        }
        int ans = one + zero;
        if (zero < one) {
            ans += zero- one;
        } else {
            ans +=one - zero;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 26288
fun main(args : Array<String>) {
    val n = readLine()!!.toLong()
    val capacities = Array(5,{readLine()!!.toLong()})
    
    val bottoleneck = capacities.min()!!;
    val a = (n / bottoleneck) + if(n % bottoleneck != 0L){1}else{0} + 4;
    
    println(a)
}

Measured memory_bytes: 34200
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define F first
#define S second
const int N = 1e5 + 5;
ll sz[N], rep[N];
ll tot = 0;
ll findu(ll u)
{
    return (rep[u] == u) ? u : rep[u] = findu(rep[u]);
}
void join(ll a, ll b)
{
    a = findu(a);
    b = findu(b);
    if(a == b)
        return;
    if(sz[a] < sz[b])
        swap(a, b);
    ll x = sz[a];
    ll y = sz[b];
    sz[a] += sz[b];
    rep[b] = rep[a];
    if(tot)
        tot -= (((x * (x - 1))/2) + ((y * (y - 1))/2));
    tot += (sz[a] * (sz[a] - 1)/2);
}
int main()
{
    Hello
    ll n, m;
    cin >> n >> m;
    fill(sz, sz + n + 1, 1);
    iota(rep, rep + n + 1, 0);
    pair<ll, ll> pr[m + 5];
    vector <ll> v;
    ll ans = (n * (n - 1)/2);
    for(int i = 0; i < m; i++)
        cin >> pr[i].F >> pr[i].S;
    for(int i = m - 1; i >= 0; i--)
    {
        v.push_back(ans - tot);
        join(pr[i].F, pr[i].S);
    }
    for(int i = v.size() - 1; i >= 0; i--)
        cout << v[i] << endl;
    return 0;
}

Measured memory_bytes: 5364
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb1 push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 2e5 + 10;


//initialization here
//
ll dp[55][55][3000]; //i番目までのカードからj枚使って総和をkにできる総数
//
//initialization finish


// your function is here
//



//
// your function finished



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

	// your code is here
	//
	int n,k; cin >> n >> k;

	if (n == 1) Print(k);
	else Print(k*(int)pow(k - 1, n - 1));

	//
	// your code finished

	return 0;
}

Measured memory_bytes: 384
#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];
    }

    sort (A.begin(), A.end());
    reverse (A.begin(), A.end());
    long long sum = 0;
    for (int i = 1; i < N; i++) {
        sum += A[i / 2];
    }
    cout << sum << endl;
}

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

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

    string s;
    cin >> s;
    long long k;
    cin >> k;

    for(int i = 0; i < min(k, (long long)s.size()); i++){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }

    cout << '1' << endl;

    return 0;
}

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

int main(){
  string s,t,u;
  cin >> s >> t >> u;
  int x,y,z;
  x = s.size();
  y = t.size();
  z = u.size();
  int i = 0;
  int j = 0;
  int k = 0;
  char ans = s[0];
  while(1){
    if(ans == 'a'){
      if(i == x){
        puts("A");
        return 0;
      }
      else{
        ans = s[i];
        ++i;
      }
    }
    if(ans == 'b'){
      if(j == y){
        puts("B");
        return 0;
      }
      else{
        ans = t[j];
        ++j;
      }
    }
    if(ans == 'c'){
      if(k == z){
        puts("C");
        return 0;
      }
      else{
        ans = u[k];
        ++k;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}

 


int32_t main()
{
    IOS
     
           
 
    
        int n,m;
        cin>>n>>m;
        int a[n];
        for(int i=0;i<n;++i)
            cin>>a[i];
        sort(a,a+n);
        vector<pair<int,int>>v;
        for(int i=0;i<m;++i)
        {
            int x,y;
            cin>>x>>y;
            v.push_back({y,x});
        }
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        int te=0;
        for(int i=0;i<m;++i)
        {
            for(int j=0;j<v[i].second;++j)
            {
                if(te==n)
                    break;
                if(a[te]<=v[i].first)
                {
                    a[te]=v[i].first;
                    te++;
                }
                else
                {
                    break;
                }
            }
        }
        int sum=0;
        for(int i=0;i<n;++i)
            sum+=a[i];
        cout<<sum;
}

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

int main() {
  int N,A,t=2,i,j,k=0,l=33;
  cin >> N;
  for(i=0;i<N;i++){
    cin >> A;
    for(j=0;j<30;j++){
      if(A%t != 0){
        break;
      }
      t=t*2;
      k++;
    }
    if(k<l){
      l=k;
    }
    t=2;
    k=0;
  }
  cout << l <<endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

int main(){
    int A,B;
    cin >> A >> B;
    int ans;
    if (A <= 5)
    {
        ans = 0;   
    }
    else if (6<=A && A  <= 12)
    {
        ans = B/2;
    }
    else if (A > 12)
    {
        ans = B;
    }
    cout << ans; 
    return 0;
    
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n, m;
const int maxN = 5005;
const int maxP = 205;
int a[maxN];
int b[maxN][maxP];
ll c[maxN][maxN];
const int INF = (int)1e9 + 10;
int l[maxN], r[maxN];
ll pref[maxN];
void add(int l1, int r1, int l2, int r2, int val) {
    c[l1][l2] += val;
    c[r1 + 1][l2] -= val;
    c[l1][r2 + 1] -= val;
    c[r1 + 1][r2 + 1] += val;
}
void solve(int who) {
   vector < pair < int, int > > st;
   st.emplace_back(make_pair(INF, 0));
   for (int j = 1; j <= n; j++) {
       while (st.back().first < b[j][who]) st.pop_back();
       l[j] = st.back().second + 1;
       st.emplace_back(b[j][who], j);
   }
   st.clear();
   st.emplace_back(make_pair(INF, n + 1));
   for (int j = n; j >= 1; j--) {
       while (st.back().first <= b[j][who]) st.pop_back();
       r[j] = st.back().second - 1;
       st.emplace_back(b[j][who], j);
   }
   for (int i = 1; i <= n; i++) {
       add(l[i], i, i, r[i], b[i][who]);
   }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= n - 1; i++) {
        cin >> a[i];
        pref[i + 1] = a[i] + pref[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> b[i][j];
        }
    }
    for (int i = 1; i <= m; i++) {
        solve(i);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            c[i][j] += c[i][j - 1];
        }
        for (int j = 1; j <= n; j++) {
            c[i][j] += c[i - 1][j];
        }
    }
    ll best = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            best = max(best, c[i][j] + pref[i] - pref[j]);
        }
    }
    cout << best << endl;
    return 0;
}

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

typedef long long ll;

using namespace std;

ll MAX = 1e9+1;
const int MOD = 1e9 + 7;

void solve() {
    int n, k;
    cin >> n >> k;

    vector<int> a(n+1);
    for (int i = 0; i < n; i++) {
        cin >> a[i+1];
    }

    vector< vector<int> > dp(n+1, vector<int>(k+1, 0));
    // dp[i][j] ~ ways to distribute j candies to first i children
    // dp[i][j] = sum dp[i-1][j-k] for k = 0 to a[i]

    // initially, we can distribute 0 candies to any # of kids in 1 way
    for (int i = 0; i <= n; i++) {
        dp[i][0] = 1;
    }

    int presum = 0;
    vector<int> pref(k+1);
    for (int i = 1; i <= n; i++) {
        presum += a[i];
        pref[0] = dp[i-1][0];

        for (int j = 1; j <= k; j++) {
            pref[j] = (pref[j-1] + dp[i-1][j]) % MOD;
        }
        for (int j = 1; j <= min(presum,k); j++) {
            int adjust = (j - a[i] - 1 < 0 ? 0 : pref[j-a[i]-1]);
            dp[i][j] = (pref[j] - adjust) % MOD;

            //int l = j - a[i] - 1;
            //dp[i][j] = (dp[i][j-1] + dp[i-1][j] - (l < 0 ? 0 : dp[i-1][l])) % MOD;
        }
    }

    //for (int i = 0; i <= n; i++) {
    //    for (int j = 0; j <= k; j++) {
    //        cout << dp[i][j] << " ";
    //    }
    //    cout << endl;
    //}
    
    cout.precision(20);
    int ans = dp[n][k];
    if (ans < 0) ans += MOD;
    cout << ans << endl;
}


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





Measured memory_bytes: 40192