akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;


int m;
 

vector<int> v[100001];
vector<LL> dp1(100001,-1);
vector<LL> dp2(100001,-1);

int dfs1(int u,int prev){
    LL ret = 1;
    for (int i = 0; i < v[u].size(); i++) {
        if(v[u][i]==prev) continue;
        ret = (ret*dfs1(v[u][i],u))%m;
    }
    return dp1[u] = ret + 1;
}

void dfs2(int u,int prev,LL ts){
    if(dp2[u]==-1){
        dp2[u] = 1;
        for (int i = 0; i < v[u].size(); i++) {
            if(v[u][i]==prev){
                dp2[u] = (dp2[u]*(ts+1))%m;
            }
            else{
                dp2[u] = (dp2[u]*dp1[v[u][i]])%m;
            }
        }
        dp2[u]++;
    }

    vector<LL> l(v[u].size()+1,1),r(v[u].size()+1,1);
    for (int i = 0; i < v[u].size(); i++) {
        l[i+1] = (l[i] * (v[u][i]==prev?(ts+1):dp1[v[u][i]]))%m;
    }
    for (int i = v[u].size(); i >= 1; i--) {
        r[i-1] = (r[i] * (v[u][i-1]==prev?(ts+1):dp1[v[u][i-1]]))%m;
    }
    for (int i = 0; i < v[u].size(); i++) {
        if(v[u][i]==prev) continue;
        dfs2(v[u][i],u,(l[i]*r[i+1])%m);
    }
}


int main(){
    int N;cin >> N >> m;
    for (int i = 0; i < N-1; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs1(0,0);
    dp2[0] = dp1[0];
    dfs2(0,0,0);
    for (int i = 0; i < N; i++) {
        cout << (dp2[i]+m-1)%m << endl;
    }
    return 0;
}


Measured memory_bytes: 18560
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
#define all(obj) obj.begin(), obj.end()
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);

using namespace std;

typedef unsigned long long ull;
typedef int long long ll;
constexpr ll bigNum = 1000000007;

signed main()
{
    fast;
    int N, M = 0;
    cin >> N >> M;
    vector<long long int> value(N);
    REP(i, N)
    cin >> value[i];
    int tmp = 0;
    int counter = M;
    while (counter > 0)
    {
        sort(all(value), std::greater<long long int>());
        tmp = value[0];
        for (int i = 0; i < N && value[i] >= tmp / 2; i++)
        {
            if (counter > 0)
            {
                value[i] /= 2;
                counter--;
            }
            else
            {
                break;
            }
        }
    }
    long long int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += value[i];
    }
    cout << ans;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <set>
#include <utility>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, n, a, ans = 0;
  scanf("%lld", &n);
  set< pair<ll, ll> > p, m;
  set< pair<ll, ll> >::iterator it, it2;
  pair<ll, ll> t;
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a);
    t = make_pair(i + a, 1);
    it = p.lower_bound(t);
    if(it != p.end() && (*it).first == i + a) 
      t.second = (*it).second + 1, p.erase(it);
    p.insert(t);
    t = make_pair(i - a, 1);
    it = m.lower_bound(t);
    if(it != m.end() && (*it).first == i - a) 
      t.second = (*it).second + 1, m.erase(it);
    m.insert(t);
  }
  for(it = p.begin(); it != p.end(); ++it) {
    it2 = m.lower_bound(make_pair((*it).first, 1));
    if(it2 != m.end() && (*it2).first == (*it).first) ans += (*it2).second * (*it).second;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 26328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
int lcm(int a, int b)
{
    return a / __gcd(a, b) * b;
} 
void solve()
{
    int n;
    cin >> n;
    if(n>=1800){
        cout << "1" << endl;
        return;
    }
    if (n >= 1600)
    {
        cout << "2" << endl;
        return;
    }
    if (n >= 1400)
    {
        cout << "3" << endl;
        return;
    }
    if (n >= 1200)
    {
        cout << "4" << endl;
        return;
    }
    if (n >= 1000)
    {
        cout << "5" << endl;
        return;
    }
    if (n >= 800)
    {
        cout << "6" << endl;
        return;
    }
    if (n >= 600)
    {
        cout << "7" << endl;
        return;
    }
    if (n >= 400)
    {
        cout << "8" << endl;
        return;
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll mx=INT_MAX;
ll mn=INT_MIN;

int main()
{
    string str1,str2;
    cin>>str1>>str2;
    ll n=str1.size();
    ll m=str2.size();
    ll dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    ll i,j;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(str1[i-1]==str2[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
                
            }
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string s="";
    if(dp[n][m]==0)
        cout<<""<<endl;
    else
    {
        i=n,j=m;
        while(i>0&&j>0)
        {
                if(dp[i][j]==(1+dp[i-1][j-1]) && str1[i-1]==str2[j-1])
                {
                    s+=str1[i-1];
                    i--;j--;
                }
                else if(dp[i-1][j] > dp[i][j-1])
                    i--;
                else
                    j--;
           
        }
    }
    reverse(s.begin(),s.end());
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j), ED = (k); i <= ED; ++i)
#define Rep(i, j, k) for(R int i = (j), ED = (k); i >= ED; --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 200011;
const ll INF = 5e16;

namespace IO {

    inline char gc() {
        static char buf[100000], *p1 = buf, *p2 = buf;
        return (p1 == p2) && (p2 = (p1 = buf) +
            fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
    }

    #define dd ch = getchar()
    inline ll read() {
        R ll x = 0; R int f = 0; R char dd;
        for (; !isdigit(ch); dd) f ^= (ch == '-');
        for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
        return f? -x: x;
    }
    #undef dd

    inline void write ( ll x ) {
        if (x < 0) x = -x, putchar('-');
        if (x > 9) write(x / 10); putchar(x % 10 | 48);
    }

    inline void wrn ( ll x ) { write(x), putchar(' '); }

    inline void wln ( ll x ) { write(x), putchar('\n'); }

    inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	ll n;
	double Ans, a[N];
	
	int main() {
		n = read();
		For ( i, 1, n ) a[i] = 1.0 / read(), Ans += a[i];
		Ans = 1.0 / Ans; return printf("%.12lf\n", Ans), 0;
	}
	
}

int main()
{
    return Cesare::main();
}

/*

*/







Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
	"sort"
)

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	m := sc.NextInt()

	// cost:limit
	mp := map[int][]int{}
	arr := []int{}

	for i := 0; i < n; i++ {
		a := sc.NextInt()
		b := sc.NextInt()
		mp[a] = append(mp[a], b)
		arr = append(arr, a)
	}
	sort.Ints(arr)
	ans := 0

	for i := 0; i < len(arr); i++ {
		cost := arr[i]
		limits := mp[cost][0]
		if limits <= m {
			m -= limits
			if len(mp[cost]) > 1 {
				mp[cost] = mp[cost][1:]
			}
			ans += cost * limits
			continue
		} else {
			ans += cost * m
			break
		}
	}
	fmt.Printf("%v\n", ans)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 14464
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>

using namespace std;

int main() {

	int N, A, B;
	cin >> N >> A >> B;

	//vector<int> vNum(N, 0);
	//for (int i = 0; i < vNum.size(); i++)
	//{
	//	cin >> vNum[i];
	//}

	int caseA = N * A;
	int caseB = B;


	cout << min(caseA, caseB) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 100100
#define MOD 1000000007
using namespace std;

int n, m, fct[30];
long long f1[MAX], f2[MAX];

int Factor(){
  int f = 0;
  for(int i = 2; i*i <= m; i+=2){
    int t;
    for(t = 0; m%i == 0; t++, m/=i);
    if(t) fct[f++] = t;
    if(i==2) i--;
  }
  if(m-1) fct[f++] = 1;
  return f;
}

void Setc(int n){
  f1[1] = 1;
  for(int i = 1; i <= n; i++) f1[i+1] = f1[i]*(i+1) % MOD;
  long long y = f1[n+1]; f2[n+1] = 1;
  for(int i = MOD-2; i; i/=2){
    if(i&1) f2[n+1] = f2[n+1] * y % MOD;
    y = y*y % MOD;
  }
  for(int i = n; i >= 0; i--) f2[i] = f2[i+1]*(i+1)%MOD;
}
 
int main(){
  long long ans = 1;
  scanf("%d%d", &n, &m);
  
  Setc(n+50);
  int f = Factor();

  for(int i = 0; i < f; i++){
    ans = ans * f1[n-1+fct[i]] % MOD * f2[n-1] % MOD * f2[fct[i]] % MOD;
  }
  printf("%lld\n", ans);
}

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

int main(){
  string s;
  cin >> s;
  if(s == "SUN"){
    cout << 7 << endl;
  }
  else if(s == "MON"){
    cout << 6 << endl;
  }
  else if(s == "TUE"){
    cout << 5 << endl;
  }
  else if(s == "WED"){
    cout << 4 << endl;
  }
  else if(s == "THU"){
    cout << 3 << endl;
  }
  else if(s == "FRI"){
    cout << 2 << endl;
  }
  else if(s == "SAT"){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
int n,f[1000005];
inline int read()
{
    int x=0,t=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-') t=-1,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return x*t;
}
int main()
{
	n=read();
	for(int i=0;i<n;i++) f[i]=read();
	for(int i=n-1;i>0;i--)
	{
		if(f[i]<f[i-1])
			f[i-1]--;
		if(f[i-1]==0||f[i-1]>f[i])
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

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

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

using namespace std;

const double INF = 1e50;


int main() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int n;
	cin >> n;
	vector<long long> x(n + 2), y(n + 2), r(n + 2);
	x[0] = x1, x[n + 1] = x2;
	y[0] = y1, y[n + 1] = y2;
	r[0] = 0, r[n + 1] = 0;

	IFOR(i, 1, n) {
		cin >> x[i] >> y[i] >> r[i];
	}
	vector<vector<double>> dist(n + 2, vector<double>(n + 2));
	FOR(i, 0, n + 2) {
		FOR(j, 0, n + 2) {
			dist[i][j] = max(0.0, sqrt((y[j] - y[i])*(y[j] - y[i]) + (x[j] - x[i]) * (x[j] - x[i])) - r[i] - r[j]);
		}
	}

	int pos = 0;
	priority_queue < pair<double, int>, vector < pair<double, int>>, greater<pair<double, int>>> pq;
	pq.push(make_pair(0.0, 0));

	vector<double> mindist(n + 2, INF);
	while (!pq.empty()) {
		auto t = pq.top();
		pq.pop();
		double cost = t.first;
		int node = t.second;
		if (mindist[node] < INF - 1)
			continue;
		mindist[node] = cost;
		if (node == n + 1)
			break;
		FOR(i, 0, n + 2) {
			if (i != node && dist[node][i] < INF - 1 && mindist[i] > INF/10.0) {
				pq.push(make_pair(cost + dist[node][i], i));
			}
		}
	}

	printf("%.14f\n", mindist[n + 1]);
	return 0;
}

Measured memory_bytes: 16500
#include <bits/stdc++.h>
#define x first
#define y second
#define y1 WHO_DEFINE_Y1_IN_HEADER
#define all(v) v.begin(), v.end()
using namespace std;

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin >> s;
	for(int i=0; i<s.size(); i++){
		if(i & 1){
			if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D') continue;
		}else{
			if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D') continue;
		}
		cout << "No"; return 0;
	}
	cout << "Yes";
}

Measured memory_bytes: 256
n,m=map(int,input().split())
x=list(map(int,input().split()))
if(m<=n):
    print(0)
    quit()
x.sort()
t=x[0]
ans=[]
for i in x[1:]:
    ans.append(i-t)
    t=i
ans.sort()
print(sum(ans[:m-n]))

Measured memory_bytes: 13968
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <string>
#include <bitset>
#include <cassert>
#include <queue>
#include <memory>

//#pragma comment(linker, "/STACK:16777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")

using namespace std;

//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define ull unsigned long long
//#define double long double
#define int ll
//#define int ull
//#define int short
//#define int unsigned short
//#define int unsigned int
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define hash hash228
#define get get228
const int SZ = 1e2 + 4;
const double EPS = 1e-7;
const int mod = 998244353;
const int hashpow = 127;
const int inf = 2e9;

#define kek cout << "kek"

string s;

void read() {
    cin >> s;
}

void solve() {
    int ans = 0;
    int cur = 0;
    for (int i = 0; i < (int) s.size() - 1; ++i) {
        if (s[i] == 'A') {
            ++cur;
        }
        else {
            if (s[i] == 'B' && s[i + 1] == 'C') {
                s[i] = s[i + 1] = 'A';
                s[i - cur] = 'B';
                s[i + 1 - cur] = 'C';
                ans += cur;
                ++i;
            }
            else {
                cur = 0;
            }
        }
    }
    cout << ans << "\n";
}

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

    //    int t;
    //    cin >> t;
    //    for (int i = 0; i < t; ++i) {
    read();
    solve();
    //    }

    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=600010,S=2000010;

int n,cnt,l[N],r[N],fa[N],len[N],sz[N],c[N][2];
ll a[S],b[S],p[N],q[N],np[N],nq[N];

bool dfs(int u,ll limit) {
	int x=c[u][0],y=c[u][1];
	if (!x) {
		l[u]=r[u]=++cnt;
		sz[u]=1;
		a[cnt]=b[cnt]=len[u];
		return 1;
	}
	if (dfs(x,limit)&&dfs(y,limit)) {
		if (sz[x]>sz[y]) swap(x,y);
		int tp=0;
		for (int i=l[x],j=l[y];i<=r[x];++i) {
			while (j<=r[y]&&b[i]+a[j]<=limit) ++j;
			if (j>l[y]) p[++tp]=a[i],q[tp]=b[j-1];
		}
		if (!tp) return 0;
		for (int i=tp+1;i<=(tp<<1);++i) {
			p[i]=q[tp-(i-tp)+1];
			q[i]=p[tp-(i-tp)+1];
		}
		int k=1;
		for (int i=1,j=tp+1;k<=(tp<<1);++k)
			if ((j>(tp<<1))||i<=tp&&p[i]<=p[j]) {
				np[k]=p[i];
				nq[k]=q[i++];
			} else {
				np[k]=p[j];
				nq[k]=q[j++];
			}
		l[u]=cnt+1;
		for (int i=1;i<=(tp<<1);++i)
			if (i==1||np[i]>a[cnt]&&nq[i]<b[cnt]) {
				a[++cnt]=np[i];
				b[cnt]=nq[i];
			} else if (np[i]==np[i-1]) b[cnt]=min(b[cnt],nq[i]);
		r[u]=cnt;
		sz[u]=r[u]-l[u]+1;
		for (int i=l[u];i<=r[u];++i) {a[i]+=len[u];b[i]+=len[u];}
	} else return 0;
	return 1;
}

inline bool check(ll x) {
	cnt=0;
	return dfs(1,x);
}

int main() {
	scanf("%d",&n);
	for (int i=2;i<=n;++i) {
		scanf("%d%d",&fa[i],&len[i]);
		c[fa[i]][c[fa[i]][0]>0]=i;
	}
	ll l=0,r=1e15,mid;
	while (l<=r) {
		mid=(l+r)>>1;
		if (check(mid)) r=mid-1; else l=mid+1;
	}
	printf("%lld\n",r+1);
}

Measured memory_bytes: 45824
#include<stdio.h>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
char in[20][20];
char ret[20];
int used[20];
int t[20];
int n;
int m;
set<pair<pair<int,int>,string> >S;
int calc(int a,string b,int c){
	if(S.count(make_pair(make_pair(a,c),b)))return 0;
	S.insert(make_pair(make_pair(a,c),b));
	if(a==n)return 1;
//	printf("%d %s %s\n",a,ret,b.c_str());
	for(int i=0;i<n;i++){
		if(used[i])continue;
		int at=0;
		bool ok=true;
		for(int j=0;j<n;j++)t[j]=0;
		for(int j=0;j<m;j++){
			if(t[in[i][j]-'A'])ok=false;
			while(n==at||(b[at]!='?'&&b[at]!=in[i][j])){
				if(at<n&&b[at]!='?')t[b[at]-'A']=1;
				if(at>=n){
					ok=false;break;
				}
				at++;
			}
			at++;
		}
		if(ok){
			used[i]=1;
			ret[a]='A'+i;
			string to="";
			for(int j=0;j<n;j++)t[j]=0;
			for(int j=0;j<m;j++){
				to+=in[i][m-1-j];
				t[in[i][m-1-j]-'A']=1;
			}
			for(int j=0;j<b.size();j++)if(b[j]!='?'&&!t[b[j]-'A']){
				to+=b[j];
			}
			for(int j=to.size();j<b.size();j++)to+='?';
			if(calc(a+1,to,c+(1<<i)))return 1;
			ret[a]=0;
			used[i]=0;
		}
	}
	return 0;
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	n=a;m=b;
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	string s="";
	for(int i=0;i<n;i++)s+="?";
	calc(0,s,0);
	printf("%s\n",ret);
}

Measured memory_bytes: 4100
n = int(input())
s = input()
b = [0]*n
w = [0]*n
if s[0] == "#":
    b[0] = 1
for i in range(1,n):
    if s[i]=="#":
        b[i] = b[i-1]+1
    else:
        b[i] = b[i-1]
if s[-1] == ".":
    w[-1] = 1
for i in range(n-2,-1,-1):
    if s[i]==".":
        w[i] = w[i+1]+1
    else:
        w[i] = w[i+1]
a = min(w[0],b[n-1])
for i in range(n-1):
    if a > b[i]+w[i+1]:
        a = b[i]+w[i+1]
print(a)

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

int main()
{
  int X,Y,A,B,C ;
  cin>>X>>Y>>A>>B>>C ;
  vector<int>p(A),q(B),r(C) ;
  for(int i=0;i<A;i++) cin>>p.at(i) ;
  sort(p.begin(),p.end()) ;
  reverse(p.begin(),p.end()) ;
  for(int i=0;i<B;i++) cin>>q.at(i) ;
  sort(q.begin(),q.end()) ;
  reverse(q.begin(),q.end()) ;
  for(int i=0;i<C;i++) cin>>r.at(i) ;
  sort(r.begin(),r.end()) ;
  reverse(r.begin(),r.end()) ;

  vector<int>ans(X+Y+C) ;
  for(int i=0;i<X;i++) ans.push_back(p.at(i)) ;
  for(int i=0;i<Y;i++) ans.push_back(q.at(i)) ;
  for(int i=0;i<C;i++) ans.push_back(r.at(i)) ;
  sort(ans.begin(),ans.end()) ;
  reverse(ans.begin(),ans.end()) ;
  
  int64_t sum=0 ;
  for(int i=0;i<X+Y;i++) sum+=ans.at(i) ;
  
  cout<<sum<<endl ;
  
  return 0 ;
}

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

int main() {
    ll h, n;
    cin >> h >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    if(accumulate(a.begin(), a.end(), 0) >= h) {
        cout << "Yes" << endl;
        return 0;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3708
a = []
for i in range(5):
    a.append(int(input()))
b = []
for i in a:
    if i%10:
        b.append(i)
c = min(b,key = lambda x:x%10) if len(b) else 0
ans = 0
for i in a:
    ans += i+(10-i%10) if i%10 else i
print(ans-(10-c%10) if len(b) else ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
    int H,W;
    scanf("%d %d",&H,&W);
    int nH,nW;
    scanf("%d %d",&nH,&nW);
    int ret;
    ret = H * W -(nH * W) - (nW * H) + nH * nW;
    printf("%d",ret);
    return 0;
}

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

int main() {

	string s; cin >> s;
	string ans = "";
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			ans += s[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    cout << ((S[0]=='7' || S[1]=='7' || S[2]=='7')? "Yes\n":"No\n");
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
     
    using namespace std;
     
    #define lp(i,n) for(int i = 0; i <n;i++)
    #define all(x) (x).begin(),(x).end()
    #define pb push_back
    #define MP make_pair
    #define SZ(v) ((int)((v).size()))
    typedef long long ll;
     
    const ll MOD = 1e9 + 7;
    const int OO = (int)1e6;
    const int N = (int)1e7;
     
    void init(){
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
     
    int main() {
    	#   ifdef LOCAL_PROJECT
            freopen("in.txt", "r", stdin);
        #   endif
        // int q;
        // scanf("%d",&q);
        // while (q--){
        //     ll n,k,a,b;
        //     scanf("%lld%lld%lld%lld",&k,&n,&a,&b);
        //     k-=a*n;
        //     if(k>0)printf("%d\n",n);
        //     else{
        //         k*=-1;
        //         ll diff = a-b;
        //         ll cant = (k+diff)/diff;
        //         if(cant>n)puts("-1");
        //         else printf("%lld\n",n-cant);
        //     }
        // }
        ll n;
        scanf("%lld",&n);
        printf("%lld",(n*(n-1))/2);
        
        return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define mod  1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll dp[2005];
ll recur(ll n){
    if(n==0)
    return 1;

    if(n<3)
        return 0;

    //cout<<n<<' ';

    if(dp[n]!=-1)
        return dp[n];

        dp[n]=recur(n-3);

        for(ll i=4; i<=n;i++){
            dp[n]+=recur(n-i);
            dp[n]%=mod;
        }
return dp[n];
}

int main(){
ll t;
t=1;
fast;
//cin>>t;

while(t--){
ll n;
cin>>n;
for(ll i=0; i<2005; i++)
    dp[i] = -1;

 recur(n);
if(n<3)
cout<<0<<endl;
else
 cout<<dp[n]<<endl;
}
return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 1; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n, m;
  cin >> n >> m;
  P((n - 1) * (m -1));

  return 0;
}

Measured memory_bytes: 256
/// DONOT COPY PASTA WITHOUT AUTHOR'S PERMISSION ///
 ///                   S S S                      ///
///                1 7 0 7 0 5 3                 ///

#include<bits/stdc++.h>
#include<string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <stdlib.h>
#include<string>
///STL
#define mp make_pair
#define ss second
#define ff first
#define pb push_back
#define ist insert
///ONLINE JUDGE
#define io ios_base::sync_with_stdio;cin.tie(0);cout.tie(0)
#define READ freopen("input.txt","r", stdin)
#define case(i) "Case "<<i++<<": "
#define nscase(i) "Case "<<i++<<":"
///c shortcuts
#define sns(s) scanf("%s",&s)
#define snc(c) scanf("%c",&c)
#define snd(a) scanf("%d",&a)
#define snl(a) scanf("%lld",&a)
#define snul(a) scanf("%ull",&a)
///Loops
#define mem(a,b) memset(a, b, sizeof(a))
#define rep(i,k,n) for(int i=k;i<n;i++)
#define rev(j,n,k) for(int j=n;j>=k;j--)
#define TC int tc;cin>>tc;while(tc--)

///GCD LCM
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a / __gcd(a, b) ) * b)

///CONSTANTS
#define PI 2*acos(0.0)
#define MAX 1000000000
#define inf 1e18

///functions
#define base(n,b) floor(log(n)/log(b))+1
#define onecnt(x) __builtin_popcount(x)
#define to_binary(n,b) bitset<b>(n).to_string()

#define endl '\n'
#define esc cout<<"\n"

/*------------------------------Graph Moves----------------------------*/
///const int fx[]= {+1,-1,+0,+0};
///const int fy[]= {+0,+0,+1,-1};
///const int fx[]= {+0,+0,+1,-1,-1,+1,-1,+1};  // Kings Move
///const int fy[]= {-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
///const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
///const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef std::map<long long,int> mli;
typedef std::map<long long,long long> mll;
typedef std::map<int,int> mii;

///PBDS
using namespace __gnu_pbds;
typedef tree<
ll,
null_type,//set to another type while using map
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

template <typename T>
std::string toString( T Number )
{
    std::ostringstream ss;
    ss << Number;
    return ss.str();
}

///constants
const ll ten5=100000;
const ll ten6 =1000000;
const ll ten7 =10000000;
const ll ten8 =100000000;
const ll ten9 =1000000000;
const ll mod=ten9+7;



int main()
{
    io;

    char c;
    cin>>c;

    map<char,char>m;
    m['A']='T';
    m['T']='A';
    m['C']='G';
    m['G']='C';

    cout<<m[c];
}



Measured memory_bytes: 3532
import math
from sys import stdin
import numpy as np

n = int(stdin.readline().rstrip())

data = [stdin.readline().rstrip().split() for _ in range(2)]
V = np.array(list(map(lambda x: int(x), data[0])))
C = np.array(list(map(lambda x: int(x), data[1])))
difference = V- C
difference[difference < 0.] = 0
print(np.sum(difference))


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

using namespace std;

int main() {
    string s;
    cin >> s;
    if (s.size() % 2) {
        cout << "No" << endl;
        return 0;
    }
    if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi") {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	int H, W; cin >> H >> W;
	multiset<int> intervals;
	map<int, int> s;
	for(int i = 0; i < W; i++) intervals.insert(0), s[i] = i;
	int cur = 0;
	for(int i = 0; i < H; i++) {
		int a, b; cin >> a >> b;
		a--;
		auto it = s.lower_bound(a);
		int maxrange = -1;
		while(it != s.end() && it->first <= b) {
			maxrange = max(maxrange, it->second);
			int x = it->first - it->second;
			intervals.erase(intervals.find(x));
			s.erase(it++);
		}
		if(maxrange != -1 && b < W) {
			intervals.insert(b - maxrange);
			s[b] = maxrange;
		}
		int ans = (intervals.empty() ? -1 : *intervals.begin() + i + 1);
		cout << ans << '\n';
	}
}


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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
typedef long long ll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

int keisan(vector<int> &l, int av, int bv, int cv, int a, int b, int c, int n){
    if(n==0){
        if(av>0&&bv>0&&cv>0){
            return abs(av-a)+abs(bv-b)+abs(cv-c);
        }
        return iinf;
    }
    n--;
    int one ,two, three, four;
    if(av>0){
        one = keisan(l, av+l[n], bv, cv, a, b, c, n)+10;
    }else{
        one = keisan(l, av+l[n], bv, cv, a, b, c, n);
    }
        
    if(bv>0){
        two = keisan(l, av, bv+l[n], cv, a, b, c, n)+10;
    }else{
        two = keisan(l, av, bv+l[n], cv, a, b, c, n);
    }

    if(cv>0){
        three = keisan(l, av, bv, cv+l[n], a, b, c, n)+10;
    }else{
        three = keisan(l, av, bv, cv+l[n], a, b, c, n);
    }

    four = keisan(l, av, bv, cv, a, b, c, n);
    int tmp=iinf;
    amin(tmp,one);
    amin(tmp,two);
    amin(tmp,three);
    amin(tmp,four);
    return tmp;
}

int main(){
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<int> l(n);
    rep(i,n){
        cin >> l[i];
    }
    int av=0, bv=0, cv=0;
    int min = keisan(l, av, bv, cv, a, b, c, n);
    cc(min);
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


#define H 0
#define V 1


bool feasible(const int x, const std::vector<int>& a)
{
  if (a.empty())
    return x == 0;
  
  bool dp[2][20000], *curr = dp[0], *next = dp[1];

  memset(dp, 0, sizeof(dp));

  curr[10000] = true;

  for (const auto& i : a) {
    for (int j = 0; j < 20000; j ++)
      if (curr[j]) {
        assert(0 <= j - i && j + i < 20000);
        
        if (! curr[j - i])
          curr[j] = false;
        
        next[j - i] = next[j + i] = true;
      }

    std::swap(curr, next);
  }

  return curr[x + 10000];
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  std::string s;

  int x, y, size;

  std::cin >> s >> x >> y;

  size = s.size();

  std::reverse(ALL(s));

  while (! s.empty()) {
    char c = s.back();

    if (c == 'T')
      break;

    x --;

    s.pop_back();
  }

  int d = H;

  std::vector<int> h, v;

  while (! s.empty()) {
    char c = s.back();

    int n = 1;

    s.pop_back();

    while (! s.empty() && s.back() == c) {
      s.pop_back();

      n ++;
    }

    if (c == 'T') {
      if (n % 2)
        d = 1 - d;
    }
    else {
      (d == H ? h : v).push_back(n);
    }
  }

  std::cout << (feasible(x, h) && feasible(y, v) ? "Yes" : "No") << std::endl;

  return 0;
}


Measured memory_bytes: 384
puts gets.to_i.times.map {
  board = 9.times.map { gets.split.map(&:to_i) }
  rs = Array.new(9) { Array.new 9, false }
  (1..9).each do |x|
    9.times do |j|
      if 9.times.count {|i| board[j][i] == x } > 1
        9.times {|i| rs[j][i] = true if board[j][i] == x }
      end
    end
    9.times do |i|
      if 9.times.count {|j| board[j][i] == x } > 1
        9.times {|j| rs[j][i] = true if board[j][i] == x }
      end
    end
    3.times do |q|
      3.times do |p|
        if 3.times.reduce(0) {|r, j| r + 3.times.count {|i| board[3*q+j][3*p+i] == x } } > 1
          3.times {|j| 3.times {|i| rs[3*q+j][3*p+i] = true if board[3*q+j][3*p+i] == x } }
        end
      end
    end
  end
  9.times.map {|j| 9.times.map {|i| "#{rs[j][i] ? ?* : ' '}#{board[j][i]}" }.join + ?\n }.join
}.join ?\n

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

long long ans = 0;
string s;
string one = "1";
string zero = "0";
vector<string> code;


void dfs(string str){
    if((int)str.size() == (int)s.size()){
        code.push_back(str);
        return;
    }
    dfs(str + one);
    dfs(str + zero);
}


int main(){
    //codeを生成
    string tmp = "a";
    cin >> s;
    dfs(tmp);


    /*
    for(int i = 0; i < (int)code.size(); i++){
        for(int j = 0; j < (int)s.size(); j++) cout << code[i][j];
        cout << endl;
    }
    */


    for(int i=0; i < (int)code.size(); i++){
        string temp = s.substr(0, 1);
        for(int j=1; j < (int)code[i].size(); j++){
            if(code[i][j] == '1') temp += "+";
            temp += s[j];
        }
        temp += "+";
        //cout << "temp = " << temp << endl;

        //式tempを計算
        long long parts = 0;
        long long res = 0;
        for(int i=0; i < (int)temp.size(); i++){
            if(temp[i] != '+'){
                parts *= 10;
                parts += temp[i] - '0';
            }
            else{
                res += parts;
                parts = 0;
                //cout << res << endl;
            }
        }
        //cout << "Temp = " << res << endl;
        ans += res;
    }




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


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

typedef struct tt{
  char name[10];
  int t;
}A;
A Q[100000];
int head=0,tail,n;
void enqueue(A x){
  strcpy(Q[tail].name,x.name);
  Q[tail].t=x.t;
  tail++;
  if(tail==100000){
    tail=0;
  }
}
int main(){
  int elaps = 0;
  int i,q;
  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  tail=n;
  while(tail!=head){
    if(Q[head].t>q){
      elaps += q;
      Q[head].t -= q;
      enqueue(Q[head]);
    }else{
      elaps += Q[head].t;
      printf("%s %d\n",Q[head].name,elaps);
    }
    head++;
    if(head==100000){
      head = 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;

int main() {
  int n,m;
  cin>>n>>m;
  vector<vector<int>> g(n);
  REP(i,m) {
    int a,b;
    cin>>a>>b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  REP(i,n) sort(ALL(g[i]));
  bool ok = false;
  for (int i : g[0]) {
    if (g[i].size() > 0 && g[i].back() == n-1) {
      ok = true;
    }
  }
  if (ok) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 12016
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int x = sc.nextInt();
		//String s = sc.next();
		
		//String[] ss = s.split("");
		
		//int[] a = new int[n];
		int ans=-1;
		if( n>9) {
			
		}else {
			if(x>9) {
				
			}else {
				ans = n*x;
			}
		}
		
		System.out.println(ans);

		/*
		TreeMap<Integer,Integer> treeMap = new TreeMap<>();//sorted no duplication
		treeMap.put(b[n], n);
		*/

	}

}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 23764
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;

int main(){
     ll n, m;
     cin >> n >> m;

     ll a = n - m;

     ll b = pow(2,m);
     cout << ((n - m) * 100 + m * 1900) * b << endl;
}

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

#define MAX_N 100

int n;
int cards[MAX_N * 2];

void cut(int k) {
	int next[2*n];

	for (int i = 0; i < k; i++) next[2*n-k+i] = cards[i];
	for (int i = k; i < 2*n; i++) next[i-k] = cards[i];

	memcpy(cards, next, sizeof(next));
}

void riffle() {
	int next[2*n];

	for (int i = 0; i < n; i++) {
		next[2*i] = cards[i];
		next[2*i+1] = cards[i+n];
	}
	
	memcpy(cards, next, sizeof(next));
}

void init() {
	for (int i = 0; i < 2*n; i++) cards[i] = i+1;
}

int main() {
	int m;
	cin >> n >> m;
	init();
	for (int i = 0; i < m; i++) {
		int k; cin >> k;
		if (k) cut(k);
		else riffle();
	}
	for (int i = 0; i < 2 * n; i++) {
		cout << cards[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<math.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
int main()
{
  ll H, K=0;
  cin >> H;
  while(H != 1){
    H /= 2;
    K++;
  }
  ll ans = pow(2,K+1)-1;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
int K, X;

int main() {
  scanf(" %d%d", &K, &X);
  int end = X + K;
  for (int i = X - K + 1; i < end; ++i) {
    printf("%d%c", i, (i == end) ? '\n' : ' ');
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for(int i = 0; i < n + 1; i++) cin >> a[i];
  vector<int> b(n);
  for(int i = 0; i < n; i++) cin >> b[i];
  long long int ans = 0;
  for(int i = 0; i < n; i++) {
    if(a[i] <= b[i]) {
      ans += a[i];
      if(a[i + 1] - (b[i] - a[i]) < 0) {
        ans += a[i + 1];
        a[i + 1] = 0;
      } else {
        ans += b[i] - a[i];
        a[i + 1] -= b[i] - a[i];
      }
    } else {
      ans += b[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

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

  if((a+b)%2 != 0) 
    cout << "IMPOSSIBLE" << endl;
  else cout << (a+b)/2 << endl;  
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int n; cin>>n;
    int ans=0;
    vector<pair<bool,bool>> v(n,mp(false,false));
    rep(i,0,3){
        int m;cin>>m;
        rep(j,0,m){
            int x;cin>>x;
            if(i==0)v[x-1].fi=true;
            else if(i==1)v[x-1].se=true;
            else {
                if(!v[x-1].fi||v[x-1].se)ans++;
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main(){
    int A, B, C;
    cin >> A;
    cin >> B;
    cin >> C;
    if((A + B) - C >= 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void initStr(char s[][101]){
  int i, j;
  for(i=0; i<101; i++){
    for(j=0; j<101; j++){
      s[i][j] = '0';
    }
  }
}
int answerDestination(char s[][101]){
  int nowPositionX=0, nowPositionY=0;
  while(s[nowPositionY][nowPositionX]!='.'){
    if(s[nowPositionY][nowPositionX]=='1'){
      break;
    }else if(s[nowPositionY][nowPositionX]=='>'){
      s[nowPositionY][nowPositionX] = '1';
      nowPositionX += 1;
    }else if(s[nowPositionY][nowPositionX]=='<'){
      s[nowPositionY][nowPositionX] = '1';
      nowPositionX -= 1;
    }else if(s[nowPositionY][nowPositionX]=='^'){
      s[nowPositionY][nowPositionX] = '1';
      nowPositionY -= 1;
    }else if(s[nowPositionY][nowPositionX]=='v'){
      s[nowPositionY][nowPositionX] = '1';
      nowPositionY += 1;
    }
  }
  if(s[nowPositionY][nowPositionX]=='.'){
    printf("%d %d\n", nowPositionX, nowPositionY);
  }else if(s[nowPositionY][nowPositionX]=='1'){
    printf("%s\n", "LOOP");
  }
}
int main(){
  int H, W, i, j;
  char s[101][101];
  while(scanf("%d%d", &H, &W)!=EOF && (H!=0 && W!=0)){
    initStr(s);
    for(i=0; i<H; i++){
        scanf("%s", s[i]);
    }
    answerDestination(s);
  }
  return 0;
}

Measured memory_bytes: 628
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

class RollingHash{
private:
    ll base1, base2, mod1, mod2; // use two primes to prevent hash collision
    vector<ll> hash1, hash2, pow1, pow2, ipow1, ipow2;
    
    ll pow_mod(ll a, ll b, ll m){
        ll ret = 1;
        while (b > 0) {
            if (b & 1) {
                ret = ret * a % m;
            }
            a = a * a % m;
            b >>= 1;
        }
        return ret;
    }
    
    ll inv_mod(ll a, ll m){
        return pow_mod(a, m - 2, m);
    }
    
public:
    RollingHash(string s, ll mod1 = 1000000007, ll mod2 = 1000000009, ll base1 = 1009, ll base2 = 1007) : mod1(mod1), mod2(mod2), base1(base1), base2(base2), hash1(s.size() + 1), hash2(s.size() + 1), pow1(s.size() + 1), pow2(s.size() + 1), ipow1(s.size() + 1), ipow2(s.size() + 1) {
        pow1[0] = pow2[0] = 1;
        rep(i, s.size()){
            pow1[i + 1] = pow1[i] * base1 % mod1;
            pow2[i + 1] = pow2[i] * base2 % mod2;
            hash1[i + 1] = (hash1[i] + s[i]) * base1 % mod1;
            hash2[i + 1] = (hash2[i] + s[i]) * base2 % mod2;
        }
        rep(i, s.size() + 1){
            ipow1[i] = inv_mod(pow1[i], mod1);
            ipow2[i] = inv_mod(pow2[i], mod2);
        }
    }
    
    ll getHash(int l, int r){
        ll h1 = ((hash1[r] - hash1[l] * pow1[r - l]) % mod1 + mod1) % mod1;
        return h1;
    }
    
    pair<ll, ll> getHashes(int l, int r){
        ll h1 = ((hash1[r] - hash1[l] * pow1[r - l]) % mod1 + mod1) % mod1;
        ll h2 = ((hash2[r] - hash2[l] * pow2[r - l]) % mod2 + mod2) % mod2;
        return mp(h1, h2);
    }
    
    
    
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    RollingHash rh(S);
    
    vector<pair<ll, ll>> hashSet;
    int l = 0, r = 1;
    rep(i, Q){
        string q;
        cin >> q;
        if (q == "L++") l++;
        if (q == "L--") l--;
        if (q == "R++") r++;
        if (q == "R--") r--;
        hashSet.pb(rh.getHashes(l, r));
        // cout << S.substr(l, r - l) << endl;
        // cout << l << ", " << r << endl;
    }
    
    sort(all(hashSet));
    int ret = 1;
    repd(i, 1, hashSet.size()){
        if (hashSet[i] != hashSet[i - 1]) {
            ret++;
        }
    }
    
    output(ret, 0);
    
    
    return 0;
}

Measured memory_bytes: 25624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


typedef long long ll;
#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;
int main(){
  int N, C;
  cin >> N >> C;
  vector<int> s(200001), t(200001), c(200001);

  rep(i, N) {
    cin >> s[i] >> t[i] >> c[i];
  }
  
  vector<int> sm(200001);
  for(int i = 1; i <= C; ++i){
    vector<int> time(200001, 0);

    for(int j = 0; j < N; ++j){
      if(c[j] == i){
        time[s[j] * 2 - 1]++;
        time[t[j] * 2]--;
      } 
    }

    int m = 0;
    /* */
    for(int j = 1; j < 200001; ++j) time[j] += time[j - 1];
    for(int j = 0; j < 200001; ++j) if(time[j] > 0) sm[j]++;
    
    /*
    for(int j = 0; j < 100; ++j){
      m += time[j];
      sm[j] += m;
    }
    */
  }

  int ans = 0;
  for(int i = 0; i < 200001; ++i){
    ans = max(ans, sm[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 4208
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <numeric>

using namespace std;

typedef long long int lo;
#define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0);
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define inf (lo)1e9
#define N (lo)1e5 * 5
#define all(x) (x).begin(), (x).end()
#define ii pair<lo,lo>
#define iii pair<lo, pair<lo,lo> >
#define si pair<string,lo>
#define vi vector <lo> 
#define vii vector <ii> 

int main() {
    fast
    lo a,b,c,d;
    cin >> a >> b >> c >> d;
    bool p = 0;
    while(a > 0 && c > 0){
        if(!p){
            c -= b;
        }
        else{
            a -= d;
        }
        p ^= 1;
    }
    if(a > 0){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	ll a, b, c, d;
	a = s[0] - '0'; b = s[1] - '0'; c = s[2] - '0'; d = s[3] - '0';
	if (a + b + c + d == 7) cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
	else if (a + b + c - d == 7) cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
	else if (a + b - c + d == 7) cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
	else if (a + b - c - d == 7) cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
	else if (a - b + c + d == 7) cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
	else if (a - b - c + d == 7) cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
	else if (a - b + c - d == 7) cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
	else if (a - b - c - d == 7) cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
B = input().split()
for i in range(N-1):
    B[i] = int(B[i])
A = list(range(N))
A[0] = B[0]
for i in range(0,N-1):
    A[i+1] = B[i]
    if A[i] > B[i]:
        A[i] = B[i]
print(sum(A))


Measured memory_bytes: 3060