akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _dbg(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _dbg(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_dbg(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define sz(a) ((int)a.size())
#define forn(i,n) for(int i=0;i<(n);++i)
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}

const int N=111;
vector<int> ans[N];
int32_t main() {

    int n;
    cin>>n;
    int gs=0;
    if(n&1){
        for(int i=0;i<=n/2;++i){
            gs++;
            ans[i]={i,n-i};
        }
    }else{
        for(int i=1;i<=n/2;++i){
            gs++;
            ans[i-1]={i,n+1-i};
        }
    }


    vector<pii> res;
    forn(i,gs){
        forn(j,i){
            for(int p:ans[i])
                for(int q:ans[j])
                    if(p&&q)
                        res.pb(p,q);
        }
    }
    cout<<res.size()<<'\n';
    for(pii p:res)cout<<p.f<<' '<<p.s<<'\n';

    return 0;
}


Measured memory_bytes: 512
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter

# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))
    a = list(map(int, readline().split()))

    total = sum(a)

    cnt = 0

    for i in range(n):
        if a[i] >= (total / (4 * m)):
            cnt += 1

    if cnt >= m:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    list<int> L;
    auto ite = L.end();
    int q,query,x;
    cin >> q;
    rep(i,q){
        scanf("%d",&query);
        if(query == 0){
            scanf("%d",&x);
            ite = L.insert(ite,x);
        }else if(query == 1){
            scanf("%d", &x);
            if(x>0){
                rep(i,x){
                    ite++;
                }
            }else{
                rep(i,-x){
                    ite--;
                }
            }
        }else{
            ite = L.erase(ite);
        }
    }

    for(auto ele : L){
        cout << ele << endl;
    }
}


Measured memory_bytes: 18708
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
                      
using namespace std;
                      
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
                      
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}

#define int long long
#define ghost signed
#define left left228
#define right right228
#define prev prev228
#define list list228
#define next next228

const int N = 100 * 1000 + 228;

struct test
{
	int b, l, u;
	test() {}
	test(int _b, int _l, int _u) {
		b = _b;
		l = _l;
		u = _u;
	}
};

int n, x;
test t[N];

bool cmp(test fir, test sec) {
	int value1 = fir.u * (x - fir.b) + fir.l * fir.b;
	int value2 = sec.u * (x - sec.b) + sec.l * sec.b;
	return value1 > value2;
}

int pref1[N], pref2[N];

bool check(int h) {
	int r = h % x;
	int bal = 0;
	if (r) {
		for (int i = 1; i <= n; ++i) {
			bal = 0;
			int R = h / x;
			if (i <= h / x) ++R;
			bal += pref1[R];
			if (i <= R) bal -= (pref1[i] - pref1[i - 1]);
			if (r - t[i].b >= 0) bal += t[i].u * (r - t[i].b);
			else bal += t[i].l * (r - t[i].b);
			bal += pref2[n] - pref2[R];
			if (i > R) bal -= (pref2[i] - pref2[i - 1]);
			if (bal >= 0) return 1;
		}
		return 0;
	} else {
		bal = pref1[h / x] + pref2[n] - pref2[h / x];
	}
	return bal >= 0;
}

ghost main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cin >> n >> x;
	for (int i = 1; i <= n; ++i) {
		cin >> t[i].b >> t[i].l >> t[i].u;
	}
	sort(t + 1, t + n + 1, cmp);
	for (int i = 1; i <= n; ++i) {
		pref1[i] = pref1[i - 1] + t[i].u * (x - t[i].b);
		pref2[i] = pref2[i - 1] - t[i].l * t[i].b;
	}
	int l = -1;
	int r = x * n;
	while (r - l > 1) {
		int m = (l + r) >> 1;
		if (check(m)) r = m;
		else l = m;
	}
	cout << r << '\n';
    return 0;
} // kek;








Measured memory_bytes: 4224
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; LL K; std::cin >> N >> K;
  std::map<int, LL> bucket;
  for (int i = 0; i < N; ++i) {
    int a, b; std::cin >> a >> b;
    bucket[a] += (LL)b;
  }

  LL cnt = 0;
  for (auto p : bucket) {
    cnt += p.second;
    if (cnt >= K) {
      std::cout << p.first << std::endl;
      return 0;
    }
  }
}


Measured memory_bytes: 4224
use proconio::*;

fn run() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        mut k: i64,
    }
    let mut ans = 0;
    let x = std::cmp::min(a, k);
    ans += x;
    k -= x;
    k -= std::cmp::min(b, k);
    ans -= std::cmp::min(k, c);
    println!("{}", ans);
}

fn main() {
    run();
}


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

int main() {
	int N;
	char s[100];

	int r = 0, l = 0;

	cin >> N >> s;

	for (int i = 0; i < N; i++) {
		if (s[i] == 'R')
			r++;
		else
			l++;
	}

	if (r > l)
		cout << "Yes\n";
	else
		cout << "No\n";


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

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

    int si,ci;

    vector<int> v(3,-1);
    bool no = false;
    for(int i=0; i<m; i++){
        cin >> si >> ci;
        si = n-si;

        if(v[si] == -1){
            v[si] = ci;
        }else if(v[si]!=ci){
            no = true;
        }
    }
    
    if(v[n-1]==0 and n>1){
        no = true;
    }
    
    for(int i=0; i<n; i++){
        if(v[i]==-1){
            if(i<n-1){
                v[i]=0;
            }else{
                if(n>1){
                    v[i]=1;
                }else{
                    v[i]=0;
                }
            }
        }
    }



    int ans = 0;
    for(int i=0; i<n; i++){
        if(i==0){
            ans += v[i];
        }else if(i==1){
            ans += v[i]*10;
        }else{
            ans += v[i]*100;
        }
    }

    if(no){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}

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

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

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define N 52
#define IT set<int>::iterator
using namespace std;
int T,n,fa[N],fb[N];
set<int> a[N],b[N],c[N];

template <class T> inline void read(T &x)
{
	char c;int sign=1;
	while((c=getchar())>'9'||c<'0') if(c=='-') sign=-1; x=c-48;
	while((c=getchar())>='0'&&c<='9') x=(x<<1)+(x<<3)+c-48; x*=sign;
}

void dfs(int rt)//跑a 
{
	for(IT i=a[rt].begin();i != a[rt].end();++i)
	{
		int v = (*i);
		if(v == fa[rt]) continue;
		fa[v] = rt;
		dfs(v);
	}
}
void DFS(int rt)
{
	for(IT i=b[rt].begin();i != b[rt].end();++i)
	{
		int v = (*i);
		if(v == fb[rt]) continue;
		fb[v] = rt;
		DFS(v);
	}
}
bool del[N];
void tx(int rt)
{
	del[rt] = 1;
	bool same[N]={0};
	for(IT i=a[rt].begin();i != a[rt].end();++i) same[*i] = 1;
	for(IT i=b[rt].begin();i != b[rt].end();++i)
	{
		int v = (*i);
		if(v == fb[rt] || !same[v]) continue;
		tx(v);
	}
}
bool vis[N];
bool cir(int rt)
{
	if(vis[rt]) return 1;
	vis[rt] = 1;
	for(IT i=c[rt].begin();i != c[rt].end();++i) if(cir(*i)) return 1;
	vis[rt] = 0;
	return 0;
}

int solve(int t)
{
	for(int i=0;i<N;++i) c[i].clear();
	memset(del,0,sizeof(del));
	memset(fa,0,sizeof(fa));
	memset(fb,0,sizeof(fb));
	dfs(t); DFS(t); tx(t);

	for(int i=1;i<=n;++i)
	{
		if(del[i]) continue;
		c[0].insert(i);
		if(!del[fa[i]]) c[fa[i]].insert(i);
		if(!del[fb[i]]) c[i].insert(fb[i]);
	}
	memset(vis,0,sizeof(vis));
	if(!cir(0))
	{
		int mn = n;
		for(int i=1;i<=n;++i) mn -= del[i];
		return mn;
	}
	return n + 1;
}

int main()
{
	read(T);
	while(T--)
	{
		for(int i=1;i<N;++i) a[i].clear();
		for(int i=1;i<N;++i) b[i].clear();
		read(n);
		for(int i=1;i<n;++i)
		{
			int x,y;
			read(x);read(y);
			a[x].insert(y);
			a[y].insert(x);
		}
		for(int i=1;i<n;++i)
		{
			int x,y;
			read(x);read(y);
			b[x].insert(y);
			b[y].insert(x);
		}
		int ans = n + 1;
		for(int t=1;t<=n;++t) ans = min(ans,solve(t));
		if(ans == n + 1)
		{
			for(int i=1;i<=n;++i)
			{
				if(a[i].size() == 1)
				for(int j=1;j<=n;++j)
				{
					if(i != j)
					{
						set<int> tp = a[i],cc = a[j],kk = a[*a[i].begin()];
						a[*a[i].begin()].erase(i);
						a[i].clear();
						a[i].insert(j);
						a[j].insert(i);
						
						if(solve(i) != n + 1)
						{
							ans = n;
							goto u;
						}
						a[i] = tp;
						a[j] = cc;
						a[*a[i].begin()]=kk;
					}
				}
			}
		}
		u:;
		printf("%d\n",ans == n + 1 ? -1 : ans);
	}
	return 0;
}
/*
2
5
1 3
2 3
3 4
4 5
3 1
1 2
2 4
4 5

5
1 2
2 3
3 4
4 5
3 1
1 2 
2 4 
4 5
*/

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
template<class T>void sort(vec<T> &v){sort(v.begin(),v.end());}
template<class T>void rsort(vec<T> &v){sort(v.rbegin(),v.rend());}
const ll mod = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    cout << (s == "ABC" ? "ARC" : "ABC") << endl;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int MaxN = 2e5;

int n, m;
vector<int> edge[MaxN + 5];
int main(){
	while(~scanf("%d %d", &n, &m)){
		for(int i = 1; i <= m; i++){
			int u, v;
			scanf("%d %d", &u, &v);
			edge[u].push_back(v);
			edge[v].push_back(u);
		}
		bool flag = false;
		for(int i = 2; i < n; i++){
			bool ok1 = false, ok2 = false;
			for(int j = 0; j < edge[i].size(); j++){
				if(edge[i][j] == 1) ok1 = true;
				if(edge[i][j] == n) ok2 = true;
			}
			if(ok1 && ok2) flag = true;
		}
		if(flag) printf("POSSIBLE\n");
		else printf("IMPOSSIBLE\n");
	}
	return 0;
}

Measured memory_bytes: 11888
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e6+50;
int n, a[N];

int main() {
	scanf("%d", &n);
	REP(i,1,n) scanf("%d", a+i);
	ll ans = 1e18;
	REP(d,-100,100) {
		ll ret = 0;
		REP(i,1,n) ret+=(a[i]-d)*(a[i]-d);
		ans = min(ans, ret);
	}
	printf("%lld\n", ans);
}








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

void insert(vector<int>&s,int k){
	s.emplace_back(k);
	int i=s.size()-1;
	while(i/2>0&&s.at(i)>s.at(i/2)){
		swap(s.at(i),s.at(i/2));
		i/=2;
	}
}

void maxHeapify(vector<int>&s,int i=1){
	int left=i*2,right=i*2+1,largest;
	if(left<s.size()&&s.at(left)>s.at(i)){
		largest=left;
	}else{
		largest=i;
	}
	if(right<s.size()&&s.at(right)>s.at(largest)){
		largest=right;
	}
	if(largest!=i){
		swap(s.at(largest),s.at(i));
		maxHeapify(s,largest);
	}
}

void extract(vector<int>&s){
	cout<<s.at(1)<<"\n"s;
	s.at(1)=minf;
	swap(s.at(1),s.back());
	s.pop_back();
	maxHeapify(s);
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	vector<int>s(1,0);
	string com;
	for(int k;;){
		cin>>com;
		if(com=="insert"s){
			cin>>k;
			insert(s,k);
		}else if(com=="extract"s)extract(s);
		else if(com=="end"s)break;
	}
}


Measured memory_bytes: 7140
#include <bits/stdc++.h>
typedef long long int ll;
#define vaibhavv06               \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(0);
#define endl '\n'
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define int long long
#define go(i, a, n) for (int i = a; i < n; i++)
const ll MOD = (ll)1e9 + 7;
using namespace std;
const int mod = 998244353;

signed main()
{
    vaibhavv06;
    int n; cin>>n; double arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    double x=0;
    for(int i=0;i<n;i++)x+= 1/arr[i];
    cout<<1/x<<endl;
    return 0;
    int sum = 0;
    for(int i=0;i<n;i++){
        sum += (x/arr[i]);
    }
    cout<<fixed<<setprecision(16);
    double ans = (1.0*x)/(sum);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;

int main() {

  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n*a, b) << endl;

  return 0;
}


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

#define NIL -1
long long int dp[50];

long long int fib(int n){
    if(dp[n]==NIL){
        if(n==0||n==1)dp[n]=1;
        else dp[n]=fib(n-1)+fib(n-2);
    }
    return dp[n];
    
}

int main(){
    int n,i;
    scanf("%d",&n);
    for(i=0;i<=n;i++)dp[i]=NIL;
    printf("%lld\n",fib(n));
    return 0;
}

Measured memory_bytes: 596
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL<<60LL)
typedef long long ll;

using namespace std;


int main() {
	ll r, d, x; cin >> r >> d >> x;
	rep(i, 10) {
		x = r * x - d;
		cout << x << endl;
	}
}

Measured memory_bytes: 256
from collections import Counter

s = input()

length = len(s)

x = length // 2
if length % 2:
    f, l = s[:x], s[x+1:][::-1]
else:
    f, l = s[:x], s[x:][::-1]

# print(f, l)

count = 0

for x, y in zip(f, l):
    if x != y:
        count += 1

print(count)


Measured memory_bytes: 3316
/* Alohomora */
        #include<bits/stdc++.h>
        #define ll         long long
        #define fl(i,n)    for(i=0;i<n;i++)
        #define fld(i,a,b) for(i=a;i>b;i--)
        #define fli(i,a,n) for(i=a;i<n;i++)
        #define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
        #define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
        #define pb         push_back
        #define mp         make_pair
        #define mod        1000000007 
        #define all(x) 	   x.begin(),x.end()	
        #define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
        #define bada 1000000000000000005
        using namespace std;
        ll fact(ll n){ if(n==0){return 1;}return (n*fact(n-1))%mod;}
        ll power(ll x, ll y){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
        ll inverse(ll a){return power(a,mod-2);}
        ll gcd(ll a,ll b){if(b==0){return a;}gcd(b,a%b);}
        ll a[2000000];
        void sieve(){ll i,j;fli(i,2,1000001){if(a[i]==0){for(j=i*i;j<1000001;j+=i){a[j]=i;}}}}
        bool compar(const pair<ll,ll> &a, const pair<ll,ll> &b) 
        { 
            return (a.second < b.second);
        }
        void comp()
        {
        	ll i,j,k,a,b;
        	ll n,p;
        	cin>>n>>k;
        	vector<ll>v1;
        	fl(i,n)
        	{
        		cin>>j;
        		v1.pb(j);
        	}
        	ll dp[n+1];
        	fl(i,n){dp[i]=INT_MAX;}
        	dp[0]=0;
        	ll lim;
        	fli(i,1,n)
        	{
        		lim=max(0ll,i-k);
        		fli(j,lim,i)
        		{
        			dp[i]=min(dp[i],dp[j]+abs(v1[j]-v1[i]));
        		}	
        	}
        	cout<<dp[n-1];
        }
        int main()
        {
        	speedup;
        	ll i=0,t;
        	//cin>>t;
        	t=1;
        	while(t--)
        	{
        	 comp();
        	}
        }

Measured memory_bytes: 1908
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline bool match(char c, char b) { return c == '?' || c == b; }
inline int mul(int x, int y) { return (1LL*x*y)%MOD; }

int solve01(string S) {
  S.erase(S.begin());
  //cout<<"solve01("<<S<<")\n";
  int all = 1;
  for (char c : S) if (c == '?') all = (2LL*all)%MOD;
  int s = 1;
  for (int i=0; i+1<S.length(); i+=2) {
    int e = 0;
    for (char a : {'0','1'}) for (char b : {'0','1'}) if (!(a=='1'&&b=='1')) {
      if (match(S[i], a) && match(S[i+1], b)) e++;
    }
    s = (1LL*s*e)%MOD;
  }
  return (all+MOD-s)%MOD;
}
int solve00(string S) {
  vector<int> R(S.length(), 0);
  int rp = 1, rall = 1;
  for (int i=S.length()-2; i>=0; i-=2) {
    if (S[i+1] == '?') rall = (2LL*rall)%MOD;
    R[i] = (rall+MOD-mul(rp, match(S[i+1], '0')))%MOD;

    int e = 0;
    for (char a : {'0','1'}) for (char b : {'0','1'}) if (!(a=='1'&&b=='1')) {
      if (match(S[i], a) && match(S[i+1], b)) e++;
    }
    rp = (1LL*rp*e)%MOD;
    if (S[i] == '?') rall = (2LL*rall)%MOD;
  }

  int s = 0, prod = 1;
  for (int i=0; i+1<S.length(); i+=2) {
    if (match(S[i], '1') && match(S[i+1], '1')) {
      s = (s + 1LL*prod*R[i+1]) % MOD;
    }

    int e = 0;
    for (char a : {'0','1'}) for (char b : {'0','1'}) if (!(a=='1'&&b=='1')) {
      if (match(S[i], a) && match(S[i+1], b)) e++;
    }
    prod = (1LL*prod*e)%MOD;
  }
  //cout<<"solve00("<<S<<")="<<s<<"\n";
  return s;
}

string S;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> S;
  if (S.length() == 1) {
    if (S == "0") cout << 0 << "\n";
    else cout << 1 << "\n";
    return 0;
  }
  assert(S.length() >= 3);

  int s = 0;
  // 1...1
  if (match(S.front(), '1') && match(S.back(), '1')) {
    int e = 1;
    for (int i=1; i<S.length()-1; i++) if (S[i] == '?') e = (2LL*e)%MOD;
    s = (s+e)%MOD;
  }
  // 0...1
  if (match(S.front(), '0') && match(S.back(), '1')) {
    string t(S); t[0] = '0', t[t.length()-1] = '1';
    s = (s+solve01(t))%MOD;
  }
  // 1...0
  if (match(S.front(), '1') && match(S.back(), '0')) {
    string t(S); t[0] = '1', t[t.length()-1] = '0';
    reverse(all(t));
    s = (s+solve01(t))%MOD;
  }
  // 0...0
  if (match(S.front(), '0') && match(S.back(), '0')) {
    string t;
    for (int i=1; i<S.length()-1; i++) t.pb(S[i]);
    s = (s+solve00(t))%MOD;
  }
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 2376
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;







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

  
  int n;
  cin>>n;

  vector<pii>v;
  for(int i=1;i*i<=n;i++)
  {
     if(n%i==0)
     {
        v.push_back({i,n/i});
     }
  }

  int ans=LLONG_MAX;
  for(auto i  : v)
  {
     ans=min(ans,(int)(i.first+i.second-2));
  }

  cout<<ans<<"\n";

   
}

 

 
 
 
 
 

Measured memory_bytes: 384
void main()
{
    long n = rdElem;
    long[] a = new long[n], b = new long[n];
    foreach (i; 0 .. n)
    {
        rdVals(a[i], b[i]);
    }

    zip(a, b).sort!((x, y) => x[0] > y[0]);

    writeln(a[0] + b[0]);
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4860
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    int p, q, r;
    cin >> p >> q >> r;

    cout <<  p + q + r - max({p, q, r}) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n, t;
pair<llong, llong> u[3005];
llong a[3005];
llong b[3005];
llong dp[3005][6010];
llong ans;

int main() {
    cin >> n >> t;
    for (int i = 1; i <= n; i++) {
        cin >> u[i].first >> u[i].second;
    }

    sort(u + 1, u + n + 1);

    for (llong i = 1; i <= n; i++) {
        a[i] = u[i].first;
        b[i] = u[i].second;
        
        for (llong j = 1; j <= t + 3005; j++) {
            dp[i][j] = max({dp[i][j], dp[i - 1][j], dp[i][j - 1]});
            
            if (j - a[i] >= 0 && j - a[i] < t) {
                dp[i][j] = max(dp[i][j],
                               dp[i - 1][j - a[i]] + b[i]);
            }

            ans = max(dp[i][j], ans);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 141184
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int ll
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
typedef vector<int> vi;
typedef vector<vi> vvi;
inline int in() { int x; cin >> x; return x; }

void solve() {
  int n = in(), k = in();
  vi p(n+1, 0); FOR(i,0,n) p[i+1] = in();
  int e = 0, maxe = 0;
  FOR(i,0,k) e += p[i]+1;
  FOR(i,k,n+1) {
    e += p[i]-p[i-k];
    if (maxe<e) maxe = e;
  }
  cout << fixed << setprecision(7) << (double)maxe/2 << endl;
}
#undef int
int main() {
  solve();
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
main(){
  int n,a,b,c,d,i=0;
  while(scanf("%d",&n)!=EOF){;
    for(a=0;a<=9;a++){
      for(b=0;b<=9;b++){
	for(c=0;c<=9;c++){
	  for(d=0;d<=9;d++){
	    if(a+b+c+d==n){
	      i++;
	    }
	  }
	}
      }
    }
    printf("%d\n",i);
    i=0;
  }
  return 0;
}

Measured memory_bytes: 592
import sys
input = sys.stdin.readline

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy.sort()

memo1 = []
memo2 = []
for x, y in xy:
  memo1.append(x+y)
  memo2.append(x-y)

min1 = 10 ** 10
min2 = 10 ** 10

ans = 0

for i in range(n):
  ans = max(ans, memo1[i]-min1)
  ans = max(ans, memo2[i]-min2)
  min1 = min(min1, memo1[i])
  min2 = min(min2, memo2[i])

print(ans)



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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int n,p,c = 0;
ll ans;
int main() {
    cin >> n >> p;

    int a[n];
    rep(i,0,n){
        cin >> a[i];
        if(a[i]%2 != 0) c++;
    }
    if(c == 0){
        if(p == 0) ans = pow(2,n);
        else if(p == 1) ans = 0;
    }
    else{
        ans = pow(2,n-1);
    }
    printf("%lld\n",ans);
    return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

int main() {
    int P,Q,R;cin >> P >> Q >> R;

    pl(min(P+Q,min(Q+R,R+P)))

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import fractions
import collections
def main():
    A,B = map(int,input().split())
    gcd = fractions.gcd(A,B)
    def prime(n):
        a = []
        while n%2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f*f <= n:
            if n%f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n!=1:
            a.append(n)
        return a

    c = collections.Counter(prime(gcd))
    print(len(list(c.keys()))+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 5048
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 510
int a[N][N];
int main()
{
    int i,j,k,n,m,q,l,r;
    scanf("%d%d%d",&n,&m,&q);
    for(i=1;i<=m;i++)
    {
        scanf("%d%d",&l,&r);
        a[0][r]++;
        a[l+1][r]--;
    }
    for(i=0;i<=n;i++)
    for(j=i+1;j<=n;j++)
    {
        a[i+1][j]+=a[i][j];
        a[i][j]+=a[i][j-1];
    }
    for(i=0;i<q;i++)
    {
        scanf("%d%d",&l,&r);
        printf("%d\n",a[l][r]);
    }
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
using namespace std;
int maxn(int m ,int n,int x,int y)
{
	if(x*y>m*n)
	 cout<<x*y<<endl;
	else
	 cout<<m*n<<endl;
}
int main()
{
  int m,n,x,y;
  cin>>m>>n>>x>>y;
  maxn(m,n,x,y);
  return 0;	
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int64
	fmt.Scan(&n)
	aArray := scanNums(n)

	// n-k個のレンガを砕いた結果、1,2,3,...,kとなればよい
	// 1が見つからない...-1
	// 1が見つかる...それより左は全部砕く
	// 1より右で2を見つけるまで砕く
	// 2より右で3を見つけるまで砕く
	// 以下繰り返し O(n)
	// 最初に見つかった1より右にある1から始めた方がいい場合はない
	var ans int64 = 0
	var notFound bool = true
	var lastFoundIdx int64 = -1
	var finding int64 = 1
	var idx int64
	for idx = 0; idx < n; idx++ {
		if aArray[idx] == finding {
			ans += idx - lastFoundIdx - 1
			lastFoundIdx = idx
			finding++
			notFound = false
		}
	}
	if lastFoundIdx != n-1 {
		ans += n - 1 - lastFoundIdx
	}
	if notFound {
		ans = -1
	}

	fmt.Println(ans)
}

func scanNums(len int64) (nums []int64) {
	var num int64
	var i int64
	for i = 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 9988
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll inf = 1e18;

void warshall_floyd(vvll &d) {
    ll n = d.size();
    REP(i, n){
        REP(j, n){
            REP(k, n){
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
}

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

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

    ll a, b, c;
    vvll d(n, vll(n, inf));
    REP(i, n) d[i][i] = 0;
    REP(i, m){
        cin >> a >> b >> c;
        a--;
        b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    warshall_floyd(d);
    vvll x(n, vll(n, inf));
    REP(i, n) x[i][i] = 0;
    REP(i, n){
        REP(j, n){
            if(d[i][j] <= l){
                x[i][j] = 1;
                x[j][i] = 1;
            }
        }
    }
    warshall_floyd(x);
    ll q;
    cin >> q;
    ll s, t;
    while(q){
        q--;
        cin >> s >> t;
        s--;
        t--;
        ll res = x[s][t];
        if (res == inf) cout << -1 << endl;
        else cout << res - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1920
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static final int MD = 1000000007;
	int power(long a, int k) {
		long p = 1;
		while (k > 0) {
			if ((k & 1) == 1)
				p = p * a % MD;
			a = a * a % MD;
			k >>= 1;
		}
		return (int) p;
	}
	void main() {
		int m = sc.nextInt();
		int n = sc.nextInt();
		byte[] mobius = new byte[n + 1]; Arrays.fill(mobius, (byte) 2);
		mobius[1] = 1;
		for (int a = 2; a <= n; a++) {
			if (mobius[a] != 2)
				continue;
			for (int b = a; b <= n; b += a)
				if (mobius[b] == 2)
					mobius[b] = -1;
				else
					mobius[b] *= -1;
			if (a <= n / a) {
				int a2 = a * a;
				for (int b = a2; b <= n; b += a2)
					mobius[b] = 0;
			}
		}
		int[] kk = new int[n + 1];
		for (int a = 1, b = n; a <= n / a; a++) {
			kk[a] = power(n / a, m);
			int p = power(a, m);
			while (b > n / (a + 1))
				kk[b--] = p;
		}
		long ans = 0;
		for (int a = 1; a <= n; a++) {
			int k = 0;
			for (int b = 1; b <= n / a; b++)
				k = (k + kk[a * b] * mobius[b]) % MD;
			ans = (ans + (long) k * a) % MD;
		}
		if (ans < 0)
			ans += MD;
		println(ans);
	}
}


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

bool a[4][10001];//1 ????????????0 ????????????
int dp[10000][16];//i????????§?????????i+1????????§??????????????¨?????????1
int x[4]={0,1,2,0};
int y[4]={2,3,4,4};
signed main(){
	fill(dp[0],dp[0]+16,-(1<<29));
	int h,n;cin>>h>>n;
	memset(a,true,sizeof(a));
	for(int i=0;i<n;i++){
		int a,b;cin>>a>>b;
		::a[a][b]=false;
		}
	dp[0][15]=0;
	for(int i=0;i<4;i++){
		int bit=15;
		bool OK=true;
		for(int j=x[i];j<y[i];j++){
			if(!a[j][0]||!a[j][1]){
						OK=false;
						}
					
				bit-=(1<<j);	
			}
		if(OK){dp[0][bit]=(y[i]-x[i])/2;}	
		}
	for(int i=0;i<h-1;i++){
		for(int j=0;j<16;j++){
			dp[i+1][15]=max(dp[i+1][15],dp[i][j]);
			for(int k=0;k<4;k++){
				bool OK=true;
				for(int l=x[k];l<y[k];l++){
					if(!a[l][i+1]||!a[l][i+2]||(j&(1<<l))==0){
						OK=false;
						}
					}
				if(OK){
					int bit=15;
					for(int l=x[k];l<y[k];l++){
						bit-=(1<<l);
						}
					dp[i+1][bit]=max(dp[i+1][bit],dp[i][j]+(y[k]-x[k])/2);	
					}	
				}
			}
		}
	cout<<*max_element(dp[h-2],dp[h-2]+16)<<endl;		
	}

Measured memory_bytes: 3736
#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;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN   
#define linf LLONG_MAX
#define lninf LLONG_MIN   
const ll mod=1e9+7;
const int N=1e6+4;

ll me(ll a,ll b)
{
	ll res = 1;

	while(b)
	{
		if(b&1)
		res = (res*a)%mod;

		a = (a*a)%mod; b>>=1;
	}

	return res;
}

int main()
{
	int n; scn(n);

	ll ans = me(10,n)-2*me(9,n)+me(8,n); ans%=mod; ans = (ans+mod)%mod;

	lpri(ans);
}

Measured memory_bytes: 3820
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
// #include <fstream>
#define typeof(x) __typeof__(x)
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (int)(UB(c,x)-LB(c,x))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}


signed main()
{
  // string filename; cin >> filename;
  // ifstream in(filename);
  // cin.rdbuf(in.rdbuf());

  int N, M; cin >> N >> M;
  vector<bool> A(N), B(N);
  rep(i, 0, M) {
    int a, b; cin >> a >> b;
    if (a == 1) {
      A[b-1] = true;
    }
    if (b == N) {
      B[a-1] = true;
    }
  }

  rep(i, 0, N) {
    if (A[i] && B[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
    scanf("%d%d",&a,&b);
    if(a>0) cout<<"Positive";
    else if(b>=0)cout<<"Zero";
    else if((b-a)%2)cout<<"Positive";
    else puts("Negative");
    return 0;
}

Measured memory_bytes: 256
#include                        <bits/stdc++.h>
#include                        <ext/pb_ds/assoc_container.hpp>
#define lb                      lower_bound
#define ub                      upper_bound
#define fe(x)                   (*(x.begin()))
#define le(x)                   (*(x.rbegin()))
#define pb                      push_back
#define load(node,n)            bool operator < (const node &n) const
#define fbo(x,id)               (*(x.find_by_order(id)))
#define ook(y)                  order_of_key(y)
#define all(x)                  (x).begin(),(x).end()
#define FOR(i,n)                for(int i = 1; i<=n; i++)
#define REP(i,n)                for(int i = 0; i<n;  i++)
#define TT                      long long TC;  scanf("%lld",&TC);  while(TC--)
#define read                    freopen("input.txt","r",stdin)
#define write                   freopen("output.txt","w",stdout)
#define set(x)                  tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>
using                           namespace __gnu_pbds;
using                           namespace std;
typedef                         long long ll;
typedef                         pair<ll,ll> pll;
typedef                         pair<int,int> pii;

vector<int> v[1002];



main(){
//read;

int n;
cin>>n;

for(int i = 0; i<n; i++){
    int a,b;
    cin>>a>>b;
    v[i].pb(a);
    v[i].pb(b);
}

bool fl = 0;

for(int i = 2; i<n; i++){
    bool flag = 1;
    for(int j = i-2; j<=i; j++){
        if(v[j][0]!=v[j][1])    flag = 0;
    }
fl|=flag;
}

puts(fl ? "Yes" : "No");


return 0;
}


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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	string S;
	int ans = 0, count_R = 0, count_B = 0;
	
	cin >> S;
	
	rep(i, S.length()){
		if(S[i] == '0')
			count_R++;
		else
			count_B++;
	}
	
	cout << min(count_B, count_R) * 2 << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
long long Mod = 1000000007, n, K, C[101000];
vector<long long>V;
long long Pow(long long a, long long b) {
	long long r = 1;
	while (b) {
		if (b & 1)r = r*a%Mod;
		a = a*a%Mod; b >>= 1;
	}
	return r;
}
long long Get(long long a) {
	return Pow(K, (a + 1) / 2);
}
int main() {
	int i, j;
	scanf("%lld%lld", &n, &K);
	for (i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			V.push_back(i);
			if (i*i != n)V.push_back(n / i);
		}
	}
	sort(V.begin(), V.end());
	int sz = V.size();
	long long res = 0;
	for (i = 0; i < sz; i++) {
		C[i] = Pow(K, (V[i] + 1) / 2);
		for (j = 0; j < i; j++) {
			if (V[i] % V[j] == 0)C[i] = (C[i]-C[j]+Mod)%Mod;
		}
		long long t = C[i] * V[i];
		if (V[i] % 2 == 0)t /= 2;
		res = (res + t) % Mod;
	}
	printf("%lld\n", res);
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int a, b;
    string s;
    cin >> a >> b;
    bool flag = 0;
    if (a == 13 && b == 1)
        s = "Bob";
    else if (a == 1 && b == 13)
        s = "Alice";
    else if (a > b)
        s = "Alice";
    else if (a < b)
        s = "Bob";
    else if (a == b)
        s = "Draw";

    OP(s);

    return 0;
}

Measured memory_bytes: 256
while 1:    #ax+by=c #dx+ey=f
            
    try:
        a,b,c,d,e,f=map(float,input().split())
        det=a*e-d*b
        x=(e*c-b*f)/det
        y=(-d*c+a*f)/det
        if abs(x) < 0.0001:
            x = 0.0
        if abs(y) < 0.0001:
            y = 0.0
        print(format(x,'.3f'),format(y,'.3f'))   
    except EOFError:
        break


Measured memory_bytes: 5580
#include<iostream>
#include<cstdio>
#include<cstring>
#define N (4020)
#define INF (21000010)
using namespace std;
int p[2][N],A[2][N][2][N],n,dp[N][N],a[N],C[2][N][N];
//0 B/1 W			//A存每个球后面的球的情况 
char c[N];
int main(){
	scanf("%d",&n); int j,i,i1,j1; getchar();
	for (i=1;i<=2*n;i++){
		scanf("%c %d",&c[i],&a[i]); getchar();
		p[(c[i]=='W')][a[i]]=i; 
	}
	for (i=1;i<=2*n;i++)
		for (j=i+1;j<=2*n;j++)
			A[(c[i]=='W')][a[i]][(c[j]=='W')][a[j]]=1;
	for (i1=0;i1<2;i1++) for(i=1;i<=n;i++)
		for (j1=0;j1<2;j1++) for (j=1;j<=n;j++)
			A[i1][i][j1][j]+=A[i1][i][j1][j-1];
 	
	for (i=0;i<=n;i++) for (j=0;j<=n;j++){
 		C[0][i][j]=A[0][i+1][0][i]+A[0][i+1][1][j]+p[0][i+1]-(i+j+1);
 		C[1][i][j]=A[1][j+1][0][i]+A[1][j+1][1][j]+p[1][j+1]-(i+j+1);
 	}

 	for (i=0;i<=n;i++) for (j=0;j<=n;j++){
 		if (!i&&!j) continue;
 		dp[i][j]=INF; 
 		if (i>0) dp[i][j]=min(dp[i][j],dp[i-1][j]+C[0][i-1][j]);
 		if (j>0) dp[i][j]=min(dp[i][j],dp[i][j-1]+C[1][i][j-1]);
	}
	cout<<dp[n][n];
}

Measured memory_bytes: 229120
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int) x.size())
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {sws;

    int n;
    cin >> n;
    int ans = 0;

    fo(i, n) {
        int a;
        cin >> a;
        if ( i & 1 ) continue;
        if ( a & 1 ) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define badi_val 1000000007
int n;
int pd[1100];
const int mo=1e9+7;
int main(){
	int x;
	cin >> x;
	if(x < 1200)
		cout << "ABC" << endl;
	else
		cout << "ARC" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int p[509][509]={{}};
int main(){
	int n,m,q; cin >>n>>m>>q;
	for(int i=1;i<=m;i++){
		int l,r;
		cin >>l>>r;
		p[l][r]++;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			p[i][j]+=p[i][j-1];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			p[i][j]+=p[i-1][j];
		}
	}
	for(int i=1;i<=q;i++){
		int l,r; cin >>l>>r;
		cout << p[r][r] -p[l-1][r] -p[r][l-1]+p[l-1][l-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1920
n, a, b, kk = map(int, input().split())

MOD = 998244353
N = n + 10
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
    fact[i] = fact[i - 1] * i % MOD

invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)

for i in range(N - 2, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD
def nCk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return fact[n] * invfact[k] * invfact[n - k] % MOD
        
ans = 0
for i in range(n + 1):
    j = (kk - a * i)
    if j % b != 0:
        continue
    ans += nCk(n, i) * nCk(n, j // b)
    ans %= MOD
    
print(ans)

Measured memory_bytes: 122248
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()

typedef long long ll;

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "YES" : "NO";
}

int main(){
    string s; cin >> s;
    if(s[0] == '9' or s[1] == '9') cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

const int N=2e5+5;
int n,top,a[N];
struct Node {int pos,tot;} sta[N];

template <typename _Tp> inline void IN(_Tp&x) {
	char ch;bool flag=0;x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(flag) x=-x;
}

void solve(int pos,int mid) {
	while(sta[top].pos>pos) --top;
	if(sta[top].pos==pos) ++sta[top].tot;
	else sta[++top]=(Node){pos,1};
	if(top>1&&sta[top].tot==mid) --top,solve(pos-1,mid);
}
inline bool check(int mid) {
	sta[top=1]=(Node){0,0};
	for(int i=2;i<=n;++i) if(a[i]<=a[i-1]) solve(a[i],mid);
	return sta[1].tot==0;
}

int main() {
	IN(n);
	bool flag=true;
	for(int i=1;i<=n;++i) IN(a[i]);
	for(int i=2;i<=n;++i) flag&=(a[i]>a[i-1]);
	if(flag) return puts("1"),0;
	int l=2,r=n,mid,ans=n;
	while(l<=r) check(mid=l+r>>1)?ans=mid,r=mid-1:l=mid+1;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main() {

    ll x;
    cin >> x;
    
    ll ans;

    if (x < 7) {
        ans = 1;
    }
    else {
        if (x % 11 == 0) {
            ans = x / 11 * 2;
        }
        else if (x % 11 < 7) {
            ans = x / 11 * 2 + 1;
        }
        else {
            ans = x / 11 * 2 + 2;
        }
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 3644