akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define here			cout<<"here";
#define int             long long
#define pb              push_back
#define mp              make_pair
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x)           fixed<<setprecision(10)<<x
#define nl			    "\n"
#define w(x)            int x; cin>>x; while(x--)
#define fr(i,n)         for (int i = 0; i < n; ++i)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

double dp[3001][3001];
int n;
double pro( double p[], int coins, int left) {
//base
	if (left == 0) return 1.0;
	if (coins == 0) return 0.0;
//lookup
	// cout<<ps(dp[coins][left])<<nl;
	if (dp[coins][left]> -0.9999999998) { return dp[coins][left];}               //i am unable to access this condition as dp[coins][left] is not initialized properly
//rec
	double op2 = p[coins] * pro(p, coins - 1, left - 1);
	double op1 = (1 - p[coins]) * pro(p, coins - 1, left);
	return dp[coins][left] = op1 + op2;
}

int32_t main()
{
	FIO;

	cin >> n;
	double p[n + 1];
	fr(i, n) cin >> p[i + 1];
	// memset(dp,-1,sizeof(dp));                                     // if i am initializing using memset it is showing me nan for all dp indices

	fr(i, n+1) {                                               // if i am using these three lines to initialize dp then my line 23 is showing me o instead of -1
		fr(j, (n + 1) ) {dp[i][j] = -1.0;}
	}

	//for printing dp array
	    //fr(i, n) {fr(j, (n + 1) / 2) {cout << dp[i][j] << " ";} cout << nl;}

	cout << ps(pro(p, n, (n + 1) / 2));
	//cout << nl << nl;

	//fr(i, n+1) {fr(j, (n + 1) ) {cout << dp[i][j] << " ";} cout << nl;}

}


Measured memory_bytes: 70784
#include <iostream>
#include <vector>

using namespace std;

int main() {
    unsigned N, W;
    cin >> N >> W;
    vector<vector<unsigned>> knapsack = {vector<unsigned>(W + 1)};
    for (unsigned i = 1; i < N + 1; ++i) {
        unsigned v, w;
        cin >> v >> w;
        vector<unsigned> tmp_knapsack;
        for (unsigned witer = 0; witer <= W; ++witer) {
            unsigned tmp_value;
            if (witer >= w && knapsack[i - 1][witer - w] + v > knapsack[i - 1][witer]) {
                tmp_value = knapsack[i - 1][witer - w] + v;
            } else {
                tmp_value = knapsack[i - 1][witer];
            }
            tmp_knapsack.push_back(tmp_value);
        }
        knapsack.emplace_back(tmp_knapsack);
    }
    cout << knapsack.back().back() << endl;
}


Measured memory_bytes: 6928
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

typedef long long ll;

const ll MAX_N = 200000;

int main(int argc, char const *argv[]) {
  ll n, sum = 0;
  cin >> n;
  vector<ll> a(n);
  for (size_t i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  ll y = sum-a[0], x = a[0];
  ll ans = abs(x-y);
  for (size_t i = 1; i < n-1; i++) {
    y -= a[i];
    x += a[i];
    ans = min(ans,abs(x-y));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n;
    cin >> n;
    vi a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    sort(all(a));
    sort(all(b));
    int m, mm;
    int ans = 0;
    if(n&1) {
        m = a[n/2];
        mm = b[n/2];
        ans = mm-m+1;
    } else {
        m = (a[n/2]+a[n/2-1]);
        mm = b[n/2]+b[n/2-1];
        ans = mm-m+1;
    }

    cout << ans << endl;
}

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

int main(){
    int m,f,r;
    
    while(1){
        cin >>m>>f>>r;
        
        if(m==-1 && f==-1 && r==-1){
             break;
        }
        
        if (m==-1||f==-1) {
            cout << "F"<<endl;
        }
        else{
            int a=m+f;
            if(a>=80){ 
                cout << "A" << endl;
            }
            else if(a>=65){
                 cout << "B"<<endl;
            }
            else if(a>=50){
                cout << "C"<<endl;
            }
            else if(a>=30){
                if(r>=50){
                     cout <<"C"<< endl;
                }
                else {
                    cout <<"D"<<endl;
                }
            }
            else {
                cout << "F"<< endl;
            }
        }
        
    }return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    cout<<n*n*n<<endl;
    return 0;
}

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

int main(void){
	int es[1000], eg[1000], eby, wy, n, q, i, j, query;
	char name[1000][18], c;
	while(1){
		scanf("%d%d%*c",&n,&q);
		if(n == 0 && q == 0)
			break;
		for(i = 0;i < n;i++){
			j = 0;
			while((c = getchar()) != ' ')
				name[i][j++] = c;
			name[i][j] = '\0';
			scanf("%d%d%*c",&eby,&eg[i]); // eby <= wy
			eg[i]--;
			es[i] = eg[i] - eby + 1;
		}
		for(i = 0;i < q;i++){
			scanf("%d%*c",&query);
			query--;
			for(j = 0;j < n;j++){
				if(es[j] <= query && query <= eg[j])
					break;
			}
			if(j != n)
				printf("%s %d\n",name[j],query - es[j] + 1);
			else
				printf("Unknown\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1068
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long long N, K;
    cin >> N >> K;
    vector< pair<long long, long long> > v(N);
    long long a, b;
    for(long long i = 0; i < N; i++){
        cin >> a >> b;
        v[i] = make_pair(a, b);
    }

    sort(v.begin(), v.end());

    long long ans;
    long long cnt = 0;
    for(long long i = 0; i < N; i++){
        cnt += v[i].second;
        if(cnt >= K){
            ans = v[i].first;
            break;
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1792
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Welcome to AtCoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

bool as[MAX_N];
int cs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  while (m--) {
    int pi;
    char s[8];
    scanf("%d%s", &pi, s);
    pi--;

    if (s[0] == 'A') as[pi] = true;
    else if (! as[pi]) cs[pi]++;
  }

  int an = 0, cn = 0;
  for (int i = 0; i < n; i++)
    if (as[i]) {
      an++;
      cn += cs[i];
    }

  printf("%d %d\n", an, cn);
  return 0;
}


Measured memory_bytes: 768
from heapq import *
n,m=map(int,input().split())
a=sorted([list(map(int,input().split()))for i in range(n)])+[[m+1,2]]
b,c,d=[],0,0
for i in range(1,m+1):
    while a[c][0]==i:
        heappush(b,-a[c][1])
        c+=1
    else:
        if len(b)!=0:
            d+=-heappop(b)
print(d)

Measured memory_bytes: 31948
s = str(input())
con = 0
con2 = 0
ans = 0
ans2 = 0
for i in range(len(s)):
  if i % 2 == 0:
    ans += 1
    if s[i] == '0':
      con += 1
  else:
    ans2 += 1
    if s[i] == '1':
      con2 += 1
L = [con + con2, (ans - con) + (ans2 - con2)]
print(min(L))


Measured memory_bytes: 9168
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  bool b=true;
  for (int i = 0; i < N; i++) {
    if(a.at(i)%2==0&&a.at(i)%3!=0){
      b=false;
    
    if(a.at(i)%2==0&&a.at(i)%5!=0){
      b=false;
      break;
    }
      else{
        b=true;
      }
    }
  }
  if(b){
    cout<<"APPROVED"<<endl;
  }
  
  else{
    cout<<"DENIED"<<endl;
  }
}
  

Measured memory_bytes: 256
package main
import (
  "fmt"
)
func main() {
  var n, k int
  fmt.Scan(&n, &k)
  var s string
  fmt.Scan(&s)
  
  count := 0
  for i := 0; i < n-1; i++ {
    if s[i] != s[i+1] {
      count++
    }
  }
  var result int
  if k*2 <= count {
    result = n-1 - (count-k*2)
  } else {
    result = n-1
  }
  fmt.Println(result)
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string t, p;
    cin >> t >> p;
    vector<int> a, b;
    int now = 0;
    bool f = true;
    rep(i, 0, t.size()){
        if(t[i] == p[now] && now < p.size()){
            a.push_back(i);
            now++;
        }
    }
    if(now != p.size()) f = false;
    now = p.size() - 1;
    repb(i, t.size() - 1, 0){
        if(t[i] == p[now] && now >= 0){
            b.push_back(i);
            now--;
        }
    }
    reverse(all(b));
    if(f && a == b){
        cout << "yes" << endl;
    }else{
        cout << "no" << endl;
    }
}

Measured memory_bytes: 13880
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
using namespace std;

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

typedef long long ll;

int main(void)
{
    int N,M;
    cin >> N >> M;
    vector<int> like(M,0);

    rep(i,N){
        int K;
        cin >> K;
        rep(j,K){
            int id;
            cin >> id;
            like[id-1] ++;
        }
    }
    int ans = 0;
    rep(i,M){
       // cout << i << ":" << like[i] << endl;
        if (like[i] == N) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
N = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K = int(input())

print(N[K-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;



int main() {
  int n,k;
  scanf("%d%d",&n,&k);
  if (k > (n+1)/2) dame;
  vp ans(n);
  int r = 3*n/2;
  int l = 2*n-r;
  rep(i,l) ans[i*2] = P(i,i+r);
  int c = (l+r)/2;
  rep(i,c-l) ans[i*2+1] = P(l+i,c+i);
  rep(i,n) {
    cout<<(ans[i].fi+k)<<" "<<(ans[i].se+k)<<" "<<(i+2*n+k)<<endl;
  }
  return 0;
}






















Measured memory_bytes: 3072
#include<stdio.h>
int x[200005], y[200005];
int h[200005], l;
int comp_h(int a, int b, int z)
{
	if (z == 0)
	{
		if (x[h[a]] > x[h[b]])
			return 1;
		else
			return -1;
	}
	else
	{
		if (y[h[a]] > y[h[b]])
			return 1;
		else
			return -1;
	}
}
void swap_h(int a, int b)
{
	int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void push(int ne, int z)
{
	h[l] = ne;
	int p = l;
	l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p, z) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
int pop(int z)
{
	l--;
	swap_h(0, l);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2, z) > 0)
			{
				if (comp_h(p, 2 * p + 2, z) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1, z) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1, z) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
int par[200005], cnt[200005];
int root(int n)
{
	if (par[n] != n)
		par[n] = root(par[n]);
	return par[n];
}
void uni(int a, int b)
{
	a = root(a);
	b = root(b);
	if (a != b)
	{
		par[a] = b;
		cnt[b] += cnt[a];
	}
	return;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	for (i = 0; i < n; i++)
	{
		scanf("%d %d", &x[i], &y[i]);
		x[i]--;
		y[i]--;
	}
	l = 0;
	int c[200005], d[200005];
	l = 0;
	for (i = 0; i < n; i++)
		push(i, 0);
	for (i = 0; i < n; i++)
		c[i] = pop(0);
	l = 0;
	for (i = 0; i < n; i++)
		push(i, 1);
	for (i = 0; i < n; i++)
		d[i] = pop(1);
	for (i = 0; i < n; i++)
	{
		cnt[i] = 1;
		par[i] = i;
	}
	int j;
	j = 0;
	for (i = 1; i < n; i++)
	{
		if (y[c[i]] > y[c[j]])
			uni(c[i], c[j]);
		else
			j = i;
	}
	j = n - 1;
	for (i = n - 2; i >= 0; i--)
	{
		if (y[c[i]] < y[c[j]])
			uni(c[i], c[j]);
		else
			j = i;
	}
	j = 0;
	for (i = 1; i < n; i++)
	{
		if (x[d[i]] > x[d[j]])
			uni(d[i], d[j]);
		else
			j = i;
	}
	j = n - 1;
	for (i = n - 2; i >= 0; i--)
	{
		if (x[d[i]] < x[d[j]])
			uni(d[i], d[j]);
		else
			j = i;
	}
	for (i = 0; i < n; i++)
		printf("%d\n", cnt[root(i)]);
	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int total = 0;

  for (int i=0;i<n;i++) {
    int x;
    cin >> x;
    if (x > k-x) {
      total += 2 * (k-x);
    } else {
      total += 2 * x;
    }
  }

  cout << total << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define Test ll t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define loopS(i,a,b,step) for(ll i=a;i<b;i+=step)
#define loopRS(i,a,b,step) for(ll i=a;i>=b;i-=step)
#define ull unsigned long long int
#define pll pair<ll,ll>
#define puu pair<ull, ull>
#define V vector
#define M map
#define UM unordered_map
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf INT_MAX
#define S3(a,b,c) cin >> a >> b >> c
#define S2(a,b) cin >> a >> b
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

void input(ll n, ll arr[]) {
	rep(i, 0, n)cin >> arr[i];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout.tie(NULL);
	ll n, w; S2(n, w);
	ll wt[n], val[n], sumValue = 0;
	rep(i, 0, n) {
		S2(wt[i], val[i]); sumValue += val[i];
	}
	ll dp[n + 1][sumValue + 1];
	// debug(sumValue);
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= sumValue + 1; ++j) {
			dp[i][j] = inf;
		}
	}
	dp[0][0] = 0;
	rep(i, 1, n + 1) {
		rep(j, 0, sumValue + 1) {
			if (j >= val[i - 1])
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i - 1]] + wt[i - 1]);
			else dp[i][j] = dp[i - 1][j];
		}
	}
	ll ans = -1;
	rep(j, 0, sumValue + 1) {
		if (dp[n][j] <= w)ans = j;
	}
	cout << ans << endl;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);
 
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;
 
constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;
 
template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    auto A = multivector(3,3,0);
    auto B = A;
    for(int i = 0; i < 3; ++i) {
        for(int j = 0; j < 3; ++j) {
            cin >> A[i][j];
        }
    }
    int N; cin >> N;
    while(N--){
        int b; cin >> b;
        for(int i = 0; i < 3; ++i) {
            for(int j = 0; j < 3; ++j) {
                if(b==A[i][j]) B[i][j]=1;
            }
        }
    }
    corner(B[0][0]&&B[0][1]&&B[0][2],"Yes");
    corner(B[1][0]&&B[1][1]&&B[1][2],"Yes");
    corner(B[2][0]&&B[2][1]&&B[2][2],"Yes");
    corner(B[0][0]&&B[1][0]&&B[2][0],"Yes");
    corner(B[0][1]&&B[1][1]&&B[2][1],"Yes");
    corner(B[0][2]&&B[1][2]&&B[2][2],"Yes");
    corner(B[0][0]&&B[1][1]&&B[2][2],"Yes");
    corner(B[2][0]&&B[1][1]&&B[0][2],"Yes");
    cout << "No" << endl;
    
	
    return 0;
}

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

using namespace std;
#define int long long
const int INF = 200000000007;


  
signed main(){
    int n;
    cin>>n;
    int a[n];
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        a[i]+=a[i-1];    
    }
    int ans=abs(a[n-1]-2*a[0]);
    for(int i=1;i<n-1;i++)ans=min(abs(a[n-1]-2*a[i]),ans);
   
    
    cout<<ans;
    
    return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int> p(N);
    for(int i = 0; i < N; i++) {
        cin >> p.at(i);
    }
    vector<int> q(N);
    for(int i = 0; i < N; i++) {
        q.at(i) =  p.at(i);
    }
    sort(p.begin(), p.end());
    int counter = 0;
    for(int i = 0; i < N; i++) {
        if(q.at(i) != p.at(i)) {
            ++counter;
        }
    }
    if(counter == 2 || counter == 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
//http:judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0042

#include <iostream>
#include <fstream>

#define fin cin

using namespace std;
 
int main(void){

    //ifstream fin("input2.txt");

    int Case = 1;
    int maxWeight;
 
    //??????????????????
    while(fin >> maxWeight, maxWeight) {

        int n, sumWeight = 0;
        int w[1000], v[1000];
        int dp[1001] = {0};
        fin >> n;
        for(int i = 0; i < n; i++){

            //value
            string str_in;
            getline(fin, str_in, ',');
            v[i] = stoi(str_in);

            //weight
            getline(fin, str_in);
            w[i] = stoi(str_in);

        }

        //?????????
        for(int i = 1; i <= maxWeight; i++)
            dp[i] = -10;
            
        //DynamicProgramming! not memoka!!!
        for(int i = 0; i < n; i++) {
            for(int j = maxWeight - w[i]; j >= 0; j--) {

                int sub = j + w[i];
                if(0 <= dp[j] && sub <= maxWeight) {

                    dp[sub] = max( dp[j] + v[i], dp[sub] );

                }
            }
        }
 
        for(int i = 0; i <= maxWeight; i++)
            if(dp[i] > dp[sumWeight]) sumWeight = i;
 
        cout << "Case " << Case++ << ":" << endl;
        cout << dp[sumWeight] << endl;
        cout << sumWeight << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3140
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7; 

fn main(){
    let a: isize = read();
    let s: String = read();
    let ans = if a >=  3200 {&s} else {"red"};
    println!("{}", ans);
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayDeque;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DStringFormation solver = new DStringFormation();
        solver.solve(1, in, out);
        out.close();
    }

    static class DStringFormation {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            String s = in.next();

            ArrayDeque<String> ad = new ArrayDeque<>();

            boolean isFirst = true;

            ad.addLast(s);

            int q = in.nextInt();
            for (int i = 0; i < q; i++) {
                int num = in.nextInt();
                if (num == 1) {
                    isFirst = !isFirst;
                } else {
                    boolean fir = in.nextInt() == 1;
                    String t = in.next();
                    if (fir ^ isFirst) {
                        // 末尾
                        ad.addLast(t);
                    } else {
                        ad.addFirst(t);
                    }
                }
            }

            StringBuffer sb = new StringBuffer();
            while (!ad.isEmpty()) {
                sb.append(ad.pollFirst());
            }

            if (isFirst) {
                out.println(sb.toString());
            } else {
                out.println(sb.reverse().toString());
            }


        }

    }
}



Measured memory_bytes: 156240
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
//#include <bits/stdc++.h>//atcoderでsqrtを使うときに必要
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long
#define sorts(c) sort((c).begin(),(c).end());

using namespace std;

void solve() {
	char s;
	cin >> s;

	if (isupper(s))
	{
		cout << "A" << endl;
	}
	else
	{
		cout << "a" << endl;
	}

	
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 2968
from collections import *
import sys
try: inp = raw_input
except: inp = input
def err(s):
    sys.stderr.write('{}\n'.format(s))

def ni():
    return int(inp())

def nl():
    return [int(_) for _ in inp().split()]

X = ni()

def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)
g = gcd(X, 360)
print(360//g)


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rs64() {
	int64_t n;
	scanf("%" SCNd64, &n);
	return n;
}

std::pair<int, int> d[] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; 

int main() {
	int h = ri(), w = ri();
	std::string a[h];
	for (auto &i : a) std::cin >> i;
	int res = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') continue;
			int dist[h][w];
			for (int k = 0; k < h; k++)
				for (int l = 0; l < w; l++) dist[k][l] = 1000000000;
			dist[i][j] = 0;
			std::queue<std::pair<int, int> > que;
			que.push({i, j});
			while (que.size()) {
				auto cur = que.front();
				que.pop();
				for (auto dd : d) {
					int next_x = cur.first + dd.first;
					int next_y = cur.second + dd.second;
					if (next_x < 0 || next_x >= h || next_y < 0 || next_y >= w) continue;
					if (a[next_x][next_y] == '#') continue;
					if (dist[next_x][next_y] > dist[cur.first][cur.second] + 1) {
						dist[next_x][next_y] = dist[cur.first][cur.second] + 1;
						que.push({next_x, next_y});
					}
				}
			}
			int cur = 0;
			for (int k = 0; k < h; k++) {
				for (int l = 0; l < w; l++) {
					if (dist[k][l] != 1000000000) {
						cur = std::max(cur, dist[k][l]);
					}
				}
			}
			res = std::max(res, cur);
		}
	}
	std::cout << res << std::endl;
	return 0;
}


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

ans = [["a"]]

def s_func(x):
    m = -1
    for i in range(len(x)):
        m = max(m, ord(x[i]))
    ret = [chr(i) for i in range(97,m+2)]
    return ret

for i in range(N-1):
    new = []
    for j in range(len(ans[i])):
        s_list = s_func(ans[i][j])
        for s in s_list:
            new.append(ans[i][j] + s)
    ans.append(new)
ans[N-1].sort()
for a in ans[N-1]:
    print(a)





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

#include <iostream>
#include <vector>
using namespace std;

vector<int> a;

// index が条件を満たすかどうか
bool isOK(int index, int key) {
    if (a[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(int key) {
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}


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

    ll i,j,k,l,m,n,w,x,y,z,p,q,tmp,sum=0;
    string str;
    cin>>n;
    rep(i,n)   {cin >> j;a.push_back(j);}
    cin>>m;
    rep(i,m){
        ll b;
        cin>>b;
        if(a[binary_search(b)]==b)sum++;
        //cout<<binary_search(b)<<" ";
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3436
# -*- coding: utf-8 -*-

s = input()
s = s[::-1]
flag = 0
while(flag >= 0):
    flag = 0
    if(s[:5] == 'maerd'):
        s = s[5:]
    elif(s[:5] == 'esare'):
        s = s[5:]
    elif(s[:6] == 'resare'):
        s = s[6:]
    elif(s[:7] == 'remaerd'):
        s = s[7:]
    elif(s == ''):
        print('YES')
        break
    else:
        flag = -1
        print('NO')

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

//0 1->codeforces
#define LL "%lld"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007
#define MAXN 100007

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;
void addmod(int &a, ll b){a=(a+b); if(a>=MODV)a-=MODV;}
void mulmod(int &a, ll b){a=(a*b)%MODV;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf(LL,&a);return a;}

int main() {
  char *s;
  s = new char[MAXN];
  scanf("%s", s);
  int n=strlen(s);
  for(int i=1;i<n;i++){
    if(s[i-1]==s[i]){
      printf("%d %d\n",i,i+1);
      return 0;
    }
    if(i>1 && s[i-2]==s[i]){
      printf("%d %d\n",i-1,i+1);
      return 0;
    }
  }
  printf("-1 -1\n");
  return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int a;
string s;

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

    if (a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;

    return 0;
}


Measured memory_bytes: 256
const MOD: usize = 1000000007;

fn repeat_sq(n: i64, p: i64, m: i64) -> i64 {
    if p == 0 {
        return 1;
    }

    if p % 2 == 0 {
        let t = repeat_sq(n, p / 2, m) % m;
        t * t % m
    } else {
        n * repeat_sq(n, p - 1, m) % m
    }
}

fn main() {
    let v = read_vec::<i64>();
    let n = v[0];
    let a = v[1];
    let b = v[2];
    let m = MOD as i64;

    let mut ans = repeat_sq(2, n, m);
    ans = (ans + m - 1) % m;

    let fac = |n, k, m| {
        let mut f = 1;
        for i in (1..n + 1).rev() {
            f *= i;
            f %= m;
            if i == n - k + 1 {
                break;
            }
        }
        f
    };

    let xa = fac(n, a, m);
    let aa = fac(a, a, m);
    let ya = repeat_sq(aa, m - 2, m);
    let nca = xa * ya % m;

    let xb = fac(n, b, m);
    let bb = fac(b, b, m);
    let yb = repeat_sq(bb, m - 2, m);
    let ncb = xb * yb % m;
    //println!("{} {} {} {} {} {} {}", ans, xa, xb, ya, yb, nca, ncb);

    ans = ((ans + m) - nca) % m;
    ans = ((ans + m) - ncb) % m;

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<queue>
#include<stack>
#include<utility>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    int n;
    cin >> n;
    int A[100003]{};
    for(int i = 0 ; i < n ; i++){
        int a;
        cin >> a;
        A[a]++;
        A[a+1]++;
        A[a+2]++;
    }
    int ans = 0;
    for(int i = 0 ; i < 100003 ; i++){
        ans = max(ans, A[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
N,M = map(int,input().split())
list = [[] for i in range(N)]

for i in range(M):
    j,k = map(int,input().split())
    list[j-1].append((k,i))

ans = [None]*M

for i,j in enumerate(list):
    j.sort()
    for k,(l,m) in enumerate(j):
        ans[m] = "%06d%06d" % (i+1,k+1)

print(*ans, sep='\n')

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

typedef long long ll;

int main()
{

    ll n,a,b,ans,c;
    cin >> a >> b >> c;
    ans=abs(a-b)+abs(b-c);
    ans=min(ans,abs(a-c)+abs(c-b));
    ans=min(ans,abs(b-a)+abs(a-c));

    cout << ans << "\n";

    return 0;
}




Measured memory_bytes: 256
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-05-02 22:09:21
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF 1000000000

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

    long ans = 0;
    long x;
    if (b > n) {
        x = n;
    } else if (b == n) {
        x = n-1;
    } else {
        x = b*(n/b) - 1;
    }
    ans = a*x/b - a*(x/b);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;
vector <int > a,ans1,ans2;





int main()
{

	cin >> N;

	a.resize(N);
	REP(i,N){
		cin >> a[i];
	}
	int flag=0;
	RREP(i,N){
		vector<int>::iterator it;
		if(flag==0){
			ans1.push_back(a[i]);
			flag=1;
		} else {
			it = ans2.begin();
			ans2.insert(it,a[i]);
			flag=0;
		}
	}

	REP(i,ans1.size()){
			cout << ans1[i] << " ";
	}
	REP(i,ans2.size()){
			cout << ans2[i] << " ";
	}

}




Measured memory_bytes: 3956
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

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


//main関数
int main() {
	int N,M;
	scanf("%d %d",&N,&M);
	
	long long H[N];
	for(int i=0;i<N;i++) {
		scanf("%lld",&H[i]);
	}
	
	int A[2][M];
	for(int j=0;j<M;j++) {
		scanf("%d %d",&A[0][j],&A[1][j]);
	}
	
	
	int ans[N];
	for(int i=0;i<N;i++) {
		ans[i] = 0;
	}
	
	for(int i=0;i<M;i++){
		if( H[ A[0][i] - 1 ] >= H[ A[1][i] -1] ) {
			ans[A[1][i] -1] = 1;
		} 
		if( H[A[1][i]-1] >= H[A[0][i]-1] ) {
			ans[A[0][i] -1] = 1;
		} 
	}
	
	int sum = 0;
	for(int i=0;i<N;i++) {
		if(ans[i]==0){
			sum++;
		}
	}
	printf("%d",sum);
}

Measured memory_bytes: 3680
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#define ll long long
using namespace std;

int main()
{

    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d\n",6-a-b);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<int>> mat;

int main(){
    int N;cin>>N;
    vec a(300010),S(300010);
    S[0]=0;
    for(int i=1;i<=3*N;i++){
        cin>>a[i];
        S[i]=S[i-1]+a[i];
    }
    vec L(100010),R(100010);
    //L[i]:a_1からa_(N+i)までの中で大きいN個の総和
    //R[i]:a_(2N+1-i)からa_3Nまでの中で小さいN個の総和
    priority_queue<ll,vec,greater<ll>> pqL;
    for(int i=1;i<=N;i++)
        pqL.push(a[i]);
    L[0]=S[N];
    for(int j=1;j<=N;j++){
        ll l=pqL.top();
        if(a[N+j]>l){
            pqL.pop();
            pqL.push(a[N+j]);
            L[j]=L[j-1]+a[N+j]-l;
        }
        else L[j]=L[j-1];
    }
    priority_queue<ll> pqR;
    for(int i=1;i<=N;i++)
        pqR.push(a[2*N+i]);
    R[0]=S[3*N]-S[2*N];
    for(int j=0;j<N;j++){
        ll l=pqR.top();
        if(a[2*N-j]<l){
            pqR.pop();
            pqR.push(a[2*N-j]);
            R[j+1]=R[j]-l+a[2*N-j];
        }
        else R[j+1]=R[j];
    }
    ll ans=-pow(10,18);
    for(int i=0;i<=N;i++)
        ans=max(ans,L[i]-R[N-i]);
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8820
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>

#define ll long long int

using namespace std;
typedef pair<int, int> P;


int main()
{
  ll n;
  char foot[100][2]={};
  int i;

  while(1){
    cin>>n;
    if(n==0)break;
    int sum=0;
    for(i=0;i<n;i++)
      cin>>foot[i][0]>>foot[i][1];
    for(i=1;i<n;i++){
       if(foot[i-1][1]==foot[i][1]){
	sum++;
	i++;
      }
    }
    cout<<sum<<endl;
  }

}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
using namespace std;
#define N 100009

int main(){
    int n;
    cin>>n;
    int data[n];
    for (int i=0; i<n; i++) cin>>data[i];
    
    bool color[n+1];
    for (int i=0; i<n; i++) color[i]=false;
    color[n]=true;
    
    int high[n+1];
    for (int i=0; i<n; i++){ 
        high[i]=0;
        if (data[i]==0) color[i]=true;
    }
    
    int count=0;
    bool ans=false;
    for (int i=0; i<n; i++){
        if (data[i]!=0){
            ans=true;
            break;
        }
    }

    while(ans){
        ans=false;
        int p,q;
        for (int i=0; i<n; i++){
            if (color[i]==false){
                p=i;
                break;
            }
        }
        for (int j=p+1; j<=n; j++){
            if (color[j]==true){
                q=j-1;
                break;
            }
        }
        
        for (int i=p; i<=q; i++){
            high[i]++;
            if (high[i]==data[i]) color[i]=true;
        }
        
        //for(int i=0; i<n; i++) cout<<color[i];
        //cout<<endl;
        
        count++;
        
        
        for (int i=0; i<n; i++){
            if (color[i]==false){ 
                ans=true;
            }
        }
        
    }
    
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 4e3+5;
ll r[maxn], b[maxn], g[maxn];
char s[maxn];

int main(){
	int n; cin >> n >> s+1;
	for(int i = 1; i <= n; i++){
		r[i] = r[i-1] + (s[i] == 'R');
		b[i] = b[i-1] + (s[i] == 'B');
		g[i] = g[i-1] + (s[i] == 'G');
	}
	ll sum = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(j+i+i > n) break;
			if(s[j] != s[j+i] && s[j+i] != s[j+i+i] && s[j] != s[j+2*i]) sum++;
		}
	}
	ll su = 0;
	for(int i = 1; i <= n; i++){
		if(s[i] == 'R'){
			su += b[i] * (g[n] - g[i]);
			su += g[i] * (b[n] - b[i]);
		}
		if(s[i] == 'B'){
			su += r[i] * (g[n] - g[i]);
			su += g[i] * (r[n] - r[i]);
		}
		if(s[i] == 'G'){
			su += r[i] * (b[n] - b[i]);
			su += b[i] * (r[n] - r[i]);
		}
	}
	cout << su - sum << endl;
}

Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main (String[] args) {
        FastReader sc = new FastReader();
        boolean[] d = new boolean[101];
        int n = sc.nextInt();
        for(int i = 0; i < n; i++)
            d[sc.nextInt()] = true;
        int r = 0;
        for(int i = 0; i < 101; i++)
            if(d[i])
                r++;
        System.out.println(r);
    }
}


Measured memory_bytes: 21204
#include <stdio.h>
int main(){
    int a,b,c,t=0;
    scanf("%d %d %d",&a,&b,&c);
    if(a>=b){
        t = a;
        a = b;
        b = t;
    }if(b>=c){
        t = b;
        b = c;
        c = t;
    }if(a>=b){
        t = a;
        a = b;
        b = t;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 1996
<?php
  $n = trim(fgets(STDIN));
  $d = explode(" ",trim(fgets(STDIN)));
  $total = 0;
  for($i=0; $i<$n; $i++){
    for($j=$i+1; $j<$n; $j++){
      $total += $d[$i]*$d[$j];
    }
  }
  echo $total."\n";

Measured memory_bytes: 4604
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
m = 0
ans = 0
for i in range(N):
    cnt = min(a[i],b[i]+m)
    ans += cnt
    m = min(b[i]+m-cnt,b[i])
ans += min(a[N],m)
print(ans)

Measured memory_bytes: 24000
a = []
for i in range(3):
  a += list(map(int,input().split()))
n = int(input())
b = []
for i in range(n):
  b = int(input())
  if b in a:
    a[a.index(b)] = 0
ans = 0
if a[0]+a[4]+a[8] == 0 or a[2]+a[4]+a[6] == 0:
  ans = 1
if ans != 1:
  for i in range(3):
    if sum(a[i*3:i*3+3]) == 0 or a[i]+a[i+3]+a[i+6] == 0:
      ans = 1
      break
if ans == 1:
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  int a,b,c,result=0;
  
  scanf("%d %d %d",&a,&b,&c);
  
  if(a!=b) result++;
  if(a!=c) result++;
  if(b!=c) result++;
  if(result==0) result++;
  
  printf("%d",result);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<class T> inline bool chmin(T& a, T b) {
        if (a > b) {
            a = b;
            return true;
        }
        return false;
    }
    template<class T> inline bool chmax(T& a, T b) {
        if (a < b) {
            a = b;
            return true;
        }
        return false;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin>>n;
        map<ll,ll> m;
        rep(i,n){
            ll a;
            cin>>a;
            m[a]++;
        }
        vl big;
        for(auto p:m){
            rep(i,p.second/2){
                big.pb(p.first);
            }
        }
        sort(rall(big));
        if(Size(big)<2)cout<<0<<endl;
        else{
            cout<<big[0]*big[1]<<endl;
        }
    }

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t
 
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int gcd(int x,int y)
{
	if(x==0) return y;
	return gcd(y%x,x);
}
int lcm(int x, int y)
{
    return (x * y / gcd(x, y));
}

int A,B,C;

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    cin>>A>>B>>C;
    int ans=min(A+B+1,C);
    ans+=B;
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}

Measured memory_bytes: 256