akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;
int N;
vector<ll> a,s;
ll sum(int l,int r){	//[l,r)
	return s[r]-s[l];
}
int main(){
	cin>>N;
	a.resize(N);
	rep(i,N) cin>>a[i];
	s.resize(N+1);
	rep(i,N) s[i+1] = s[i] + a[i];
	ll ans = 1e18;
	for(int L=2;L<=N-2;L++){
		vector<ll> vs;
		{
			int ub = L, lb = 0;
			while(ub-lb>1){
				int m = (ub+lb)/2;
				if(sum(0,m)<sum(m,L)) lb = m;
				else ub = m;
			}
			int x = lb;
			if(abs(sum(0,lb)-sum(lb,L)) > abs(sum(0,ub)-sum(ub,L))) x = ub;
			vs.pb(sum(0,x));
			vs.pb(sum(x,L));
		}
		{
			int ub = N-L, lb = 0;
			while(ub-lb>1){
				int m = (ub+lb)/2;
				if(sum(L,L+m)<sum(L+m,N)) lb = m;
				else ub = m;
			}
			int x = lb;
			if(abs(sum(L,L+lb)-sum(L+lb,N)) > abs(sum(L,L+ub)-sum(L+ub,N))) x = ub;
			vs.pb(sum(L,L+x));
			vs.pb(sum(L+x,N));
		}
		sort(all(vs));
		chmin(ans,vs[3]-vs[0]);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3328
N,M = map(int,input().split())
path_list = []
for i in range(N):
    z = []
    path_list.append(z)
for i in range(M):
    A,B = map(int,input().split())
    path_list[A-1].append(B)
    path_list[B-1].append(A)
chk = [0] * N

def bfs(a,chk,path):
    queue = [a]
    while queue:
        b = queue.pop(0)
        for i in range(len(path[b-1])):
            if chk[path[b-1][i]-1] == 0:
                queue.append(path[b-1][i])
                chk[path[b-1][i]-1] =b
    return chk
bfs(1,chk,path_list)
print("Yes")
for i in range(N):
    if i == 0:
        continue
    else:
        print(chk[i])


Measured memory_bytes: 33816
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
typedef long long ll;
typedef long double ld;

int main(){
    ll ans = 0;
    ll cnt_b = 0;
    ll H, W, K;
    cin >> H >> W >> K;
    char c[7][7];
    char c_test[7][7];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> c[i][j];
            if(c[i][j] == '#'){
                cnt_b++;
            }
        }
    }

    
    for (int bit = 0; bit < (1 << H + W); bit++){
        ll cnt_b_test = 0;
        memcpy(c_test,c,sizeof(c));
        for (int i = 0; i < H + W; i++) {
            if (bit & (1 << i)) { // i が bit に入るかどうか
                if(i < H){
                    for(int j = 0; j < W; j++){
                        c_test[i][j] = '-';
                    }
                }
                else{
                    for(int j = 0; j < H; j++){
                        c_test[j][i - H] = '-';
                    }
                }
            }
        }
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(c_test[i][j] == '#'){
                    cnt_b_test++;
                }
            }
        }
        if(cnt_b_test == K){
            ans++;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int> pii;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int main(){
	int n;
	cin>>n;
	cout<<(n+999)/1000*1000-n<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
#define ll long long
#define ld long double
int main()
{
	//freopen("/home/zz7/CFInput","r",stdin);
	ll n,m,d;scanf("%lld%lld%lld",&n,&m,&d);
	ll A=n-d;
	if(d>0&&d+1<=n-d)A+=n-2*d;
	/*
	for(int n=1;n<100;n++){
		for(int j=0;j<100;j++){
			ll A=n-d;
			if(n-2*d>=0)A+=d;
			else A+=d+(n-2*d);
		}
	}*/
	if(n-2*d>=0)A+=d;
	else A+=d+(n-2*d);
	printf("%.14lf\n",(double)A*(m-1)/(n*n));
}


Measured memory_bytes: 256
Prizes = [300000, 200000, 100000]
Special = 400000

def main(argv)
  (x, y) = gets.chomp.split(' ').map(&:to_i)

  prize = 0

  prize += Prizes[x - 1] if x <= 3
  prize += Prizes[y - 1] if y <= 3

  prize += Special if (x == 1) && (y == 1)

  puts prize.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

string s;
ll memo[100005][20],n;

ll add(ll a, ll b)
{
	ll res = a + b;
	if(res >= mod)
		return res - mod;
	return res;
}

ll mult(ll a, ll b)
{
	long long res = a;
	res *= b;
	if(res >= mod)
		return res % mod;
	return res;
}

ll power(ll x,ll n,ll m)
{
    if(n==0)
        return 1;
    else if((n&1)==0){
        ll y=power(x,n/2,m);
        return (y*y)%m;
    }else{
        return ((x%m)*power(x,n-1,m))%m;
    }
}

ll p10[100005];

ll fn(ll i,ll sum){
  if(i==n){
    if(sum%13==5) return 1;
    else return 0;
  }
  if(memo[i][sum]!=-1)
    return memo[i][sum];

  ll ans=0;
  if(s[i]!='?'){
    ll digit=(ll)(s[i]-'0');
    ll sum1=(sum+digit*p10[n-i-1])%13;
    ans=add(ans,fn(i+1,sum1));
  }else{
    for(ll digit=0;digit<=9;digit++){
      ll sum1=(sum+digit*p10[n-i-1])%13;
      ans=add(ans,fn(i+1,sum1));
    }
  }
  memo[i][sum]=ans;
  return ans;
}

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  cin>>s;
  n=sz(s);
  p10[0]=1;
  forn(i,1,n+1){
    p10[i]=(p10[i-1]*10)%13;
  }
  //forn(i,0,10) cout<<p10[i]<<" ";
  memset(memo,-1,sizeof(memo));
  ll ans=fn(0LL,0LL);
  cout<<ans<<endl;
  return 0;
}


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

int main() {
  string S;
  int a = 0;
  cin >> S;
  for(int i=0;i<3;i++){
    if(S[i]=='a'){
      a++;
    }else if(S[i]=='b'){
      a += 10;
    }else{
      a += 100;
    }
  }
  if(a==111){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
int n;
set<int>ans;
vector<int>v;
void gf(int x);
bool jdg(int x);
signed main(){
	Rd(n),gf(n-1);
	for(int i:v)if(i>=2)ans.insert(i);
	gf(n);
	for(int i:v)if(i>=2&&jdg(i))ans.insert(i);
	wr(ans.size());
}
void gf(int x){
	v.clear();
	for(int i(1);i*i<=x;++i)if(!(x%i)){
		v.push_back(i);
		if(i*i<x)v.push_back(x/i);
	}
}
bool jdg(int x){
	int r(n);
	while(!(r%x)){
		r/=x;
		if(!((r-1)%x))return 1;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n);i++)
#define rep1(i,n) for(int i=1; i<(n); i++)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int a, b, t;
    cin >> a >> b >> t;
    cout << t/a * b << endl;
}

Measured memory_bytes: 256
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define bf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double d;
#define MAX 1000009
#define MIN -1
#define M 1000000007
#define INF 5e17
using namespace std;
typedef vector<ll> Vector;
typedef queue<ll > Queue;
typedef stack<ll> Stack;
typedef pair<ll,ll> Pair;
#define mp make_pair
#define pb push_back
bool desc(ll i, ll j) { return i > j; }
ll gcd(ll a, ll b)
{   if (a == 0) return b;
    return gcd(b%a, a);
}
ll power(ll x,ll n)
{   if(n==0) return 1;
    else if(n%2 == 0) return power((x*x)%M,n/2);
    else return (x*power((x*x)%M,(n-1)/2))%M;
}
ll ar[MAX],not_prime[MAX]; 
void sieve(){
    not_prime[1]=1; not_prime[0]=1;
    for(ll p=2;p*p<=MAX;p++){
        if(!not_prime[p]){
            for(ll i=p*2;i<=MAX;i+=p) not_prime[i]=1;
        }
    }
}
int main(){
    bf; 
    //sieve();
    ll x=1,n,t,i=0,j=0,m,p,c,flag,t1,ta1,ta2,t2,ans=0,k=0; string s,a,b;
    cin>>a>>b;
    while(i<a.size()+b.size()){
        if(i%2==0) { cout<<a[j]; j++;}
        else { cout<<b[k];k++; }
        i++;
    }
    
    
    return 0;
} 

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()
    A = LI()

    ans = 1
    if 0 in A:
        ans = 0
    else:
        for i in A:
            ans *= i
            if ans>10**18:
                ans = -1
                break

    print(ans)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 22436
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

/*bool func(long long a)
{
    long long res=1,ans=0;
    for(i=0;i<a;i++)
    {
        res=res*26;
        ans+=res;
    }
    if(ans<=a){return true;}
    else{return false;}
}*/
int main()
{
    long long n,rem,t;
    string s="";
    //cin>>t;
    t=1;
    while(t--)
    {cin>>n;
    while(n>0)
    {
        rem=n%26;
        if(rem!=0){s+=(rem-1+'a');}
        else{s+="z";}
        n/=26;
        if(rem==0){n-=1;}
    }
    if(s.length()>1){reverse(s.begin(),s.end());}
    cout<<s<<"\n";s.clear();}
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h> // 新手专用万能头 
using namespace std; // 万能头在它在，万能头亡它亡 
int main() // main函数东东 
{
	int a, b, c, d, e, f; // e 和 f 方便偷懒  
	cin >> a >> b >> c >> d; // 输入 a b c d， 意思见题目； 
	e = a + b;
	f = c + d; // e 表示 a + b, f 表示 c + d;
	if (e > f) // 如果 e 大于 f 
	{
		cout << "Left" << endl; // 则输出 ← 
	}
	if (e == f) // 如果它俩相等 
	{
		cout << "Balanced" << endl; // 则输出这个东东（我不认识） 
	}
	if (e < f) // 如果 e 小于 f 
	{
		cout << "Right" << endl; // 则输出 → 
	}
	return 0; // 白白！ 
}

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


ll calc(ll A) {
    ll cnt1 = (A + 1) / 2;
    ll ans = cnt1 % 2;
    if (A % 2 == 0) ans ^= A;
    return ans;
}

int main() {
    ll A, B;
    cin >> A >> B;
    ll ans = calc(B) ^ calc(A - 1);
    cout << ans << endl;
}




Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = [[0,0] for _ in range(40)]
for i in range(n):
    for j in range(40):
        l[j][a[i] >> j & 1] += 1
lst = [0]*41
for i in range(40):
    lst[i+1] = lst[i] + max(l[i])*2**i
l2 = [k >> j & 1 for j in range(40)]
lst2 = [0]*41
for i in range(39,-1,-1):
    lst2[i] = lst2[i+1]+l[i][1-l2[i]]*(2**i)
ans = lst2[0]
for i in range(40):
    if l2[i] == 0:
        continue
    t = lst2[i+1] + l[i][1]*(2**i) + lst[i]
    ans = max(t,ans)
print(ans)

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

int main () {
  int A, B, K;
  cin >> A >> B >> K;
  
  int count = 0;
  int ans;
  for (int i = 100; i > 0; i--) {
    if ( A % i == 0 && B % i == 0 ) {
      count++;
      if (count == K) {
        ans = i;
        break;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

signed main(){
    int n, x;
    cin >> n >> x;
    
    int now = 0, ans = 1;
    rep(i,n){
        int l; cin >> l;
        now += l;
        if(now > x) break;
        ans++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long ans=0;
    string s,now="",pre="";
    cin>>s;
    f(i,0,s.size()){
        now.push_back(s[i]);
        if(now!=pre){
            pre=now;
            now="";
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3752
n = int(input())
h = list(map(int, input().split()))
ans = [0] * (n)
ans[1] = abs(h[0]-h[1])
for i in range(2, n):
    ans[i] = min(ans[i-2]+abs(h[i]-h[i-2]), ans[i-1]+abs(h[i]-h[i-1]))
print(ans[-1])


Measured memory_bytes: 13908
using System;

class C
{
	static void Main()
	{
		var words = new[] { "dream", "dreamer", "erase", "eraser" };
		var s = Console.ReadLine();
		Dfs(0);
		Console.WriteLine("NO");

		void Dfs(int i)
		{
			foreach (var w in words)
			{
				if (!Contains(s, i, w)) continue;
				var ni = i + w.Length;
				if (ni == s.Length) { Console.WriteLine("YES"); Environment.Exit(0); }
				Dfs(ni);
			}
		}
	}

	static bool Contains(string s, int start, string w)
	{
		for (int i = 0; i < w.Length; i++)
			if (start + i >= s.Length || s[start + i] != w[i]) return false;
		return true;
	}
}


Measured memory_bytes: 18320
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    long long m;
    cin >> m;
    int n = 5;
    vector<long long> v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i];

    long long x = *min_element(v.begin(), v.end());
    long long ans = (m + x - 1) / x + (n - 1);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
 
//# define int long
 
using namespace std;
 
 
int32_t main()
{
	int n, mx = 0;
	cin >> n;

	map < string, int > mp;

	for ( int i = 0; i < n; i++ ) {
		string s;
		cin >> s;
		mp[s]++;
		mx = max( mx, mp[s] );
	}

	for ( auto i: mp ) {
		if ( i.second == mx ) {
			cout << i.first << '\n';
		}
	}
}

Measured memory_bytes: 25216
#include<cstdio>
#include<algorithm>
#define mod 1000000007
using namespace std;
long long n,m,a[1000],b[1000],ans=1,la,lb,x;
int main(){
    scanf("%lld %lld",&n,&m);
    for(long long i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    for(long long i=0;i<m;i++){
        scanf("%lld",&b[i]);
    }
    sort(a,a+n);
    sort(b,b+m);
    for(long long i=0;i<n-1;i++){
        if(a[i]==a[i+1]){
            ans=0;
        }
    }
    for(long long i=0;i<m-1;i++){
        if(b[i]==b[i+1]){
            ans=0;
        }
    }
    if(ans==0){
        printf("0\n");
        return 0;
    }
    la=0;
    lb=0;
    for(long long i=1;i<=n*m;i++){
        while(la!=n&&i>a[la]){
            la++;
        }
        while(lb!=m&&i>b[lb]){
            lb++;
        }
        x=(n-la)*(m-lb)-(n*m-i);
        if(a[la]==i&&b[lb]==i);
        else if(a[la]==i){
            ans*=(m-lb);
        }
        else if(b[lb]==i){
            ans*=(n-la);
        }
        else if(x>0){
            ans*=x;
        }
        else{
            printf("0\n");
            return 0;
        }
        ans%=mod;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct BIT{
    vector<ll> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    ll sum(int i){
        ll s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    void add(int i, ll x){
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
int main()
{
    int Q; cin>>Q;
    ll a[200020], b[200020];
    int t[200020];
    int ind[200020];
    int c=0;
    vector<ll> v;
    v.push_back(0);
    int p[200020];
    for(int i=0; i<Q; i++){
        cin>>t[i];
        if(t[i]==1){
            cin>>a[i]>>b[i];
            v.push_back(a[i]);
            c++;
            p[i]=c;
        }else{
            p[i]=p[i-1];
        }
    }
    for(int i=1; i<=c; i++) ind[i]=i;
    sort(ind+1, ind+c+1, [&](int i, int j){ return v[i]<v[j];});
    int indv[200020];
    for(int i=1; i<=c; i++) indv[ind[i]]=i;

    BIT ai(c), as(c);
    ll s=0;
    ll sb=0;
    for(int i=0; i<Q; i++){
        if(t[i]==1){
            ai.add(indv[p[i]], 1);
            as.add(indv[p[i]], a[i]);
            s+=a[i];
            sb+=b[i];
        }else{
            int l=0, r=c;
            while(r-l>1){
                int mid=(l+r)/2;
                if(ai.sum(mid)>=(p[i]+1)/2) r=mid;
                else l=mid;
            }
            ll x=v[ind[r]];
            cout<<x<<" ";
            ll s1=as.sum(r);
            cout<<(2*((p[i]+1)/2)-p[i])*x+s-2*s1+sb<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 11380
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cctype>
#include <map>
#include <cstring>
#include <typeinfo>
#include <utility>
#define REP(i,n) for(int i = 0;i < n ;i++)
#define FOR(i,m,n) for(int i= m ;i<n;i++)
using namespace std;

int main(void){
  int a,b;
  char c;
  cin >> a >> c >> b;
  if(c=='-')cout <<a-b<<endl;
  else cout <<a+b<<endl;
  return 0;
}


Measured memory_bytes: 256
line= input().split(" ")
op = ["+","-","*"]

stack = []

def push(i):
	stack.append(i)

def pop(i):
	return stack.pop(i)

for i in line:
	if i not in op:
		push(int(i))
	else:
		if i == "+":
			push(pop(-1) + pop(-1))
		elif i == "-":
			push(pop(-2) - pop(-1))
		elif i == "*":
			push(pop(-1) * pop(-1))

print(*stack)



Measured memory_bytes: 5592
//author:satwik_bhv1
#include<bits/stdc++.h>
//datatypes
#define ll long long 
#define ld long double
//loops
#define fr(i,z,n) for(ll i=z;i<n;i++)
#define br(i,z,n) for(ll i=z;i>n;i--)
//operations
#define mp  make_pair
#define ff  first
#define ss  second
#define pub push_back
#define all(v) v.begin(),v.end()
//map
#define mi map<ll,ll>
//vectors
#define vi vector<ll>
#define vpi vector<pair<ll,ll> >
//constants
#define pi 3.1415926535897932384626
#define mod 1000000007 
#define MAXN 100001
/*notes
    Don't use inbuilt fun for power
    Range of longlong=(-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 )
    INT_MAX = 2147483647(aprox 2*10^10)
    INT_MIN = -2147483648
    LLONG_MAX = 9223372036854775807 
    LLONG_MIN = -9223372036854775808
    __gcd is the function in built for hcf
    priority queue is max heap by default
    topological sort -> khan's algo use bfs and indegree of node  
    sssp(positive weighted edges) -> Dijkstras
    apsp -> Floydwarshall
    MST -> kruskal(DSU)
*/
using namespace std;
//functions
ll power(ll x,ll y){ll res=1;while(y){if(y%2){res*=x;}y/=2;x*=x;} return res;}
ll power(ll x,ll y,ll z){ll res=1;while(y){if(y%2){res=(res*x)%z;}y/=2;x=(x*x)%z;} return res;}
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
bool sortbysec(const pair<ll, ll>& a, const pair<ll, ll>& b) { return (a.second > b.second); }
ll ceil(ll x,ll y){return (x/y)+(x%y!=0);}
vi dp;
//ll n;
vi v;
ll fun(ll ind,ll n)
{
    if(ind==n-1)
    {
        return dp[ind]=0;
    }
    if(ind>n-1)
    {
        return -1;
    }
    if(dp[ind]!=-1)
    {
        return dp[ind];
    }
    ll l=LLONG_MAX,r=LLONG_MAX;
    if(fun(ind+1,n)!=-1)
    {
        l=abs(v[ind]-v[ind+1])+dp[ind+1];
    }
    if(fun(ind+2,n)!=-1)
    {
        r=abs(v[ind]-v[ind+2])+dp[ind+2];
    }
    return dp[ind]=min(l,r);
}
void solve()
{
    ll n;
    cin>>n;
    fr(i,0,n)
    {
        ll o;
        cin>>o;
        v.pub(o);
        dp.pub(-1);
    }
    cout<<fun(0,n);
}
int main()
{
    fast();
    ll t;
    t=1;
    //cin>>t;
    fr(i,0,t)
    {
        solve();
    }
}
/*





























*/


Measured memory_bytes: 9580
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include<vector>

using namespace std;
typedef long long ll;

ll ans,mx,sum,mn=1e8,cnt;


int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0; i<n; i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(ll i=0; i<n-1; i++){
		sum +=a[i];
	}
	if(a[n-1]<sum) cout<<"Yes";
	else cout<<"No";
}




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


int isPrime(int n){
  if(n == 0 || n == 1) return 0;
  for(int i=2;i*i<=n;i++) if(n%i==0) return 0;
  return 1;
}

signed main(){

  while(1){
    int a, d, n;
    cin>>a>>d>>n;
    if(a == 0 && d == 0 && n == 0) break;
    int cnt = 0;
    int ans = -1;
    for(int num=a; cnt < n;num+=d){
      if(isPrime(num) == 0) continue;
      cnt++;
      ans = num;
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 2988
#include<iostream>
#include<vector>
#include<string>

#define MAX 100000
typedef long long llong;

using namespace std;

int n, k;
vector<llong> T(MAX);

int check(llong P) {
	int i = 0;
	for (int j = 0; j < k; ++j) {
		llong s = 0;
		while (s + T[i] <= P) {
			s += T[i];
			++i;
			if (i == n)
				return n;
		}
	}
	return i;
}

llong solve() {
	llong left = 0, right = MAX*10000;
	llong mid;
	while (right-left>1) {
		mid = (left + right) / 2;
		int v = check(mid);
		if (v >= n) right = mid;
		else
			left = mid;
	}
	return right;
}

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> T[i];
	}
	llong res = solve();
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3444
S = input().split(" ")
D = int(S[0])
G = int(S[1])

DATA = []
for i in range(D):
    DATA.append([int(s) for s in input().split(" ")])

def calculate(d, _g, data):
    counts = []
    for i in range(2 ** len(data)):
        arr = []
        bonusIndexes = []
        notBonusIndexes = []
        bonusSum = 0
        bonusCounts = 0
        for j in range(len(data)):
            s = i >> j & 1
            arr.insert(0,s)
            _j = len(data)-1 - j
            if s == 1:
                bonusIndexes.append(_j)
                bonusSum = bonusSum + (_j + 1) * 100 * data[_j][0] + data[_j][1]
                bonusCounts = bonusCounts + data[_j][0]
            else:
                notBonusIndexes.append(_j)

        g = _g

        if bonusSum >= g:
            # 该情况下奖金能满足
            counts.append(bonusCounts)
        else:
            g = g - bonusSum
            # 该情况下，奖金不能满足，还要去找奖金拿不到的情况
            # 只需要考虑目前单价最大的情况
            notBonusMaxIndex = max(notBonusIndexes)
            notBonusMaxIndexNum = data[notBonusMaxIndex][0]
            notBonuxMaxIndexPrice = (notBonusMaxIndex + 1) * 100
            for n in range(1, notBonusMaxIndexNum):
                g = g - notBonuxMaxIndexPrice
                bonusCounts = bonusCounts + 1
                if g <= 0:
                    break

            if g <= 0:
                counts.append(bonusCounts)
            else:
                pass
    return counts


result = calculate(D, G, DATA)

print(min(result))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int x[100001],y[100001];
vector<int> G[100001];
int cnt[100001];
bool flag[100001];

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&x[i],&y[i]);
		x[i]--;
		y[i]--;
	}
	for(int i=0;i<n;i++){
		cnt[i]=1;
	}
	flag[0]=true;
	for(int i=0;i<m;i++){
		if(!flag[x[i]]){
			cnt[y[i]]++;
			cnt[x[i]]--;
		}else{
			if(cnt[x[i]]==1){
				flag[x[i]]=false;
			}
			cnt[y[i]]++;
			cnt[x[i]]--;
			flag[y[i]]=true;
		}
	}
	int res=0;
	for(int i=0;i<n;i++){
		if(flag[i])res++;
	}
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int N;
string S;
void setValue(int n,vector<int> &A,vector<int> &B)
{
	char NumA[26]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	char NumB[26]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	int i;
	for (i=0;i<n;i++){
		NumA[S[i]-'a']++;
	}
	for (i=n;i<N;i++){
		NumB[S[i]-'a']++;
	}
	int aw=0;
	for (i=0;i<26;i++){
		if (NumA[i]>0 && NumB[i]>0){
			aw++;
		}
	}
	A[n-1]=aw;
	B[n-1]=aw;
}
int main(int argc, char* argv[])
{


	cin>>N;
	cin>>S;
	int i;
	vector<int> A(N-2,0),B(N-2,0);
	bool bSame=true;
	for (i=0;i<N;i++){
		if (S[i]!=S[0]){
			bSame=false;
			break;
		}
	}
	if (bSame){
		cout<<1<<endl;
		return 0;
	}
	for (i=1;i<N-1;i++){
		setValue(i,A,B);
	}
	int maxV=0;
	for (i=0;i<A.size();i++){
		if (maxV<A[i]){
			maxV=A[i];
		}
	}
	cout<<maxV<<endl;
	return 0;
}

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

int main() {
    long h;
    cin >> h;

    long mon_num = 1;
    long atack_num = 0;

    while ( 1 ) {
        atack_num += mon_num;
        if ( h == 1 ) {
            break;
        }
        else {
            h /= 2;
            mon_num *= 2;
        }
    }

    cout << atack_num << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

bool f[101][101];
int dp[101][101];

int main(){
    int w,h,n,x,y,s,t;

    while(cin >> n && n){
        cin >> w >> h;
        memset(f, false, sizeof(f));
        memset(dp, 0, sizeof(dp));
        for(int i=0;i<n;++i){
            cin >> x >> y;
            f[y][x] = true;
        }
        cin >> s >> t;
        for(int i=1;i<=h;++i){
            for(int j=1;j<=w;++j){
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + f[i][j];
            }
        }

        int ret = -1;
        for(int i=1;i<=h;++i){
            for(int j=1;j<=w;++j){
                if(i >= t && j >= s){
                    ret = max(ret, dp[i][j] - dp[i-t][j] - dp[i][j-s] + dp[i-t][j-s]);
                }
            }
        }

        cout << ret << endl;
    }
}

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

using namespace std;

int main(int argc, char const *argv[]) {
	int A,B,C,D;
	std::cin >> A >> B >> C >> D;
	std::vector<int> v(101,0);
	for (size_t i = A; i < B; i++) {
		v[i]++;
	}
	for (size_t i = C; i < D; i++) {
		v[i]++;
	}
	int count = 0;
	for (size_t i = 0; i < v.size(); i++) {
		if (v[i] == 2) {
			count++;
		}
	}

	std::cout << count << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    vector<int> s(N);
    bool error = true;
    int sum = 0;
    for(int i=0; i<N; i++){
        cin >> s[i];
        sum += s[i];
        if(s[i]%10 != 0) error = false;
    }

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

    if(sum%10 != 0) cout << sum << endl;
    else if(error){
        cout << 0 << endl;
    } else {
        int res;
        for(int i=0; i<N; i++){
            if(s[i]%10 != 0){
                res = s[i];
                break;
            }
        }
        cout << sum - res << endl;
    }
}

Measured memory_bytes: 256
from statistics import median
import math
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
    a[i] -= i+1
a_fl = math.floor(median(a))
a_ce = math.ceil(median(a))
ans_fl=ans_ce=0

for i in range(n):
    ans_fl += abs(a[i]-a_fl)
    ans_ce += abs(a[i]-a_ce)
print(int(min(ans_fl,ans_ce)))

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

int main(){
  int N;
  cin >> N;
  
  vector<int> answer(10000);
  for (int i=1 ; i<=100 ; i++){
    for (int j=1 ; j<=100 ; j++){
      for (int k=1 ; k<=100 ; k++){
        int l = i*i+j*j+k*k+i*j+j*k+k*i;
        if (l<=10000)
          answer.at(l-1)++;
      }
    }
  }
  
  for (int i=0 ; i<N ; i++)
    cout << answer.at(i) << endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
const LL MOD=1000000007ll;
const LL INF=2000000000ll;

long power(long a,long b){return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}
long comb(int N,int K)
{
	long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
		y=y*i%MOD;
	}
	return x*power(y,MOD-2)%MOD;
}

long hcomb(int N, int K){
    return comb(N+K-1, N-1);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);

    int N;
    cin >> N;
    cout << (int) ceil(N/2.0) << endl;
}

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())

if a >= c:
    if a-c <= d:
        print("Yes")
    elif a-c > d*2:
        print("No")
    elif a-b > d or b-a > d:
        print("No")
    elif c-b > d or b-c > d:
        print("No")
    else: 
        print("Yes")
else:
    if c-a <= d:
        print("Yes")
    elif c-a > d*2:
        print("No")
    elif a-b > d or b-a > d:
        print("No")
    elif c-b > d or b-c > d:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int value1 = scan.nextInt();
		int value2 = scan.nextInt();
		int sum = value1 * value2;
		scan.close();
		System.out.println(sum);
	}

}


Measured memory_bytes: 26948
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
 
  cin >> S;

  if(S[2] == S[3] && S[4] == S[5]){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
 
}

Measured memory_bytes: 256
n=int(input())
num=list(map(int,input().split()))
count=0
for i in range(0,n):
	minj=i
	a=0
	for j in range(i+1,n):
		if num[minj]>num[j]:
			minj=j
	if minj!=i:
		count+=1
	a=num[minj]
	num[minj]=num[i]
	num[i]=a
print(' '.join(list(map(str,num))))
print(count)


Measured memory_bytes: 5596
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var (
	n int
	c []int
	s []int
	f []int
)

func main() {
	sc.Split(bufio.ScanWords)

	n = nextInt()
	c = make([]int, n)
	s = make([]int, n)
	f = make([]int, n)

	for i := 0; i < n-1; i++ {
		c[i], s[i], f[i] = nextInt(), nextInt(), nextInt()
	}

	for i := 0; i < n-1; i++ {
		t := s[i] + c[i]
		for j := i + 1; j < n; j++ {
			if t <= s[j] {
				t += s[j] - t
			}

			if t > s[j] {
				if f[j] != 0 && (t-s[j])%f[j] != 0 {
					t += (t/f[j]+1)*f[j] - t
				}

				// if f[j] != 0 && t%f[j] != 0 {

				// }
			}

			t += c[j]
		}
		fmt.Println(t)
	}
	fmt.Println(0)
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n; vl sum(n+1); ll center = 0;
  
  rep(i,n){
    ll x; cin >> x;
    sum[i+1] = sum[i] + x;
  }
  
  rep(i,n){
    if(2*sum[i+1] >= sum[n]){
      center = i+1;
      break;
    }
  }
  
  cout << min(abs(sum[n]-2*sum[center]),
              abs(sum[n]-2*sum[center-1])) << endl;
  
}

Measured memory_bytes: 4792
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;

// 插入此處
const int MAXN = 102;
int ans[MAXN][MAXN];

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    string s[MAXN];
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    ans[0][0] = s[0][0] == '.' ? 0 : 1;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (i == 0 && j == 0)  continue;
            if (i == 0) {
                ans[i][j] = ans[i][j-1] + (s[i][j] == '#' && s[i][j-1] == '.' ? 1 : 0);
            } else if (j == 0) {
                ans[i][j] = ans[i-1][j] + (s[i][j] == '#' && s[i-1][j] == '.' ? 1 : 0);
            } else {
                ans[i][j] = min(ans[i][j-1] + (s[i][j] == '#' && s[i][j-1] == '.' ? 1 : 0),
                                ans[i-1][j] + (s[i][j] == '#' && s[i-1][j] == '.' ? 1 : 0));
            }
        }
    }
    cout << ans[h-1][w-1] << endl;
    return 0;
}


Measured memory_bytes: 384
const main = () => {
  const txys = getParams()
      , txys_with_init = [[0,0,0], ...txys];
  console.log(solve(txys_with_init));
};

const getParams = () =>
  getStdin().split('\n').slice(1).map(s => s.split(' ').map(Number));

const getStdin = () =>
  require('fs').readFileSync('/dev/stdin', 'utf8').trim();

const solve = txys => {
  const pairs = zip(txys, txys.slice(1));
  return pairs.every(p => reachable(p[0], p[1])) ? 'Yes' : 'No';
};

const zip = (xs, ys) => {
  const minlen = Math.min(xs.length, ys.length);
  return [...Array(minlen).keys()].map(i => [xs[i], ys[i]]);
};

const reachable = (txy1, txy2) => {
  const t1 = txy1[0]
      , t2 = txy2[0]
      , x1 = txy1[1]
      , x2 = txy2[1]
      , y1 = txy1[2]
      , y2 = txy2[2]
      , difft = t2 - t1
      , distance = manhattanDistance(x1, x2, y1, y2);
  return enoughTime(difft, distance) && sameParity(difft, distance);
};

const manhattanDistance = (x1, x2, y1, y2) =>
  Math.abs(x1 - x2) + Math.abs(y1 - y2);

const enoughTime = (difft, distance) =>
  difft >= distance;

const sameParity = (m, n) =>
  m % 2 === n % 2;

main();


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

int main(){
  int w,h;
  while(cin>>w>>h , w+h){
    char Map[20][20]={0};
    int pos = 0; 
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>Map[i][j];
	if(Map[i][j]=='@') pos=i*w+j;
      }
    }
    int cnt=0;
    queue<int> q;
    q.push(pos);
    while(!q.empty()){
      pos = q.front();
      q.pop();
      cnt++;
      int x=pos%w;
      int y=pos/w;
      if(x>=1 && Map[y][x-1]=='.'){
	q.push(y*w+x-1);
	Map[y][x-1]='@';
      }
      if(y>=1 && Map[y-1][x]=='.'){
	q.push((y-1)*w+x);
	Map[y-1][x]='@';
      }
      if(x+1<w && Map[y][x+1]=='.'){
	q.push(y*w+x+1);
	Map[y][x+1]='@';
      }
      if(y+1<h && Map[y+1][x]=='.'){
	q.push((y+1)*w+x);
	Map[y+1][x]='@';
      }
      //      cout<<" x = "<<x<<" y = "<<y<<endl;
    }
    cout<<cnt<<endl;

  }
  return 0;
}

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

int a[100005];

int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
	sort(a + 1, a + 1 + n);
  	int ans = a[n];
  	for (int i = n - 1; i >= 1; i--) {
      ans = __gcd(ans, a[i]);
    }
  	cout << ans << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    
    int bi = 1;
    int ans = 1;
    
    rep(i,n)ans*=3;
    
    rep(i,n){
        if(v[i]%2==0)bi*=2;
    }
    
    cout<<ans-bi<<endl;
}



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

using namespace std;
using ll = long long;
using vs = vector<string>;
using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;

#define R(a,i) for(ll a=0; a < (i); (a)++)
#define FOR(a,i,j) for(ll a=(i); a < (j); (a)++)
#define RD(a,i) for(ll a=(i)-1; (a) >= 0; (a)--)
#define FORD(a,i,j) for(ll a=(j)-1; (a) >= (i); (a)--)

#define xx first
#define yy second
#define pb push_back

#define all(X) begin(X),end(X)
#define sz(X) (X).size()

#define DBG 1
#define TR(X) {if(DBG) cerr << (#X) << " = " << (X) << "\n";}
#define hline {if(DBG) cerr << "----------------------------------------------------------------------" << "\n";}
#define PK(X) {if(DBG) cerr << (X) << "\n";}

void die(void){
	cout << "No" << endl;
	exit(0);
}

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

	string s;
	cin >> s;
	FOR(i,0,sz(s)) {
		if(i % 2) {
			if( s[i] == 'R' )
				die();
		} else {
			if( s[i] == 'L' )
				die();
		}
	}
	cout << "Yes" << endl;
}


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

using namespace std;
typedef long long ll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
 int N;
 cin >> N;
 string S;
 cin >> S;
 int cnt = 0;
 for (int i = 0; i < N - 2; i++) {
   if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
     cnt++;
   }
 }
 cout << cnt << endl;
 return 0;
}


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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_A



int main() {
	int n, m;
	cin >> n;
	int s[n];
	for (int i = 0; i < n; i++) cin >> s[i];
	cin >> m;
	int t[m];
	for (int i = 0; i < m; i++) cin >> t[i];
	
	int ans = 0;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			if (t[i] == s[j]) {
				ans++;
				break;
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1196
from collections import deque
n,m=map(int,input().split())
g=[[] for _ in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  g[a].append(b)
  g[b].append(a)
q=deque([0])
d=[-1]*n
d[0]=1
while q:
    now = q.pop()
    for i in g[now]:
        if d[i] != -1: continue
        d[i] = now+1
        q.appendleft(i)
print("Yes")
print(*d[1:], sep="\n")

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    i64 n, k;
    cin >> n >> k;

    vector< int > as(n);
    for (auto &a: as) {
        cin >> a;
        a--;
    }

    int st = 0;
    while (k) {
        if (k & 1) {
            st = as[st];
        }

        vector< int > bs = as;
        range(i, 0, n) {
            as[i] = bs[bs[i]];
        }
        
        k /= 2;
    }
    
    cout << st + 1 << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 4748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e6 + 5;
const int P = 1e9 + 7;
vector<ll> fac;
vector<ll> inv;
vector<ll> facinv;
ll C(int n, int m) {
	++n;
	++m;
	return fac[n + m] * facinv[n] % P * facinv[m] % P;
}
int main() {
	fac.resize(maxn);
	facinv.resize(maxn);
	inv.resize(maxn);
	fac[0] = 1;
	inv[1] = 1;
	facinv[0] = 1;
	for(int i = 1; i < maxn; ++i) {
		fac[i] = fac[i - 1] * i % P;
		if(i != 1) {
			inv[i] = (P - P / i) * inv[P % i] % P;
		}
		facinv[i] = facinv[i - 1] * inv[i] % P;
	}
	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	cout << ((C(r2, c2) - C(r1 - 1, c2) - C(r2, c1 - 1) + C(r1 - 1, c1 - 1)) % P + P) % P << '\n';
	return 0;
}

Measured memory_bytes: 47104
w, h, n = map(int, input().split())
OPS = list(list(map(int, input().split())) for _ in range(n))
l, r, t, b = 0, w, h, 0
for i in OPS:
    if i[2] == 1 and i[0] > l:
        l = i[0]
    elif i[2] == 2 and i[0] < r:
        r = i[0]
    elif i[2] == 3 and i[1] > b:
        b = i[1]
    elif i[2] == 4 and i[1] < t:
        t = i[1]
print(max(r - l, 0) * max(t - b, 0))

Measured memory_bytes: 9184
def solution1():
    # https://www.youtube.com/watch?v=aRdGRrsRo7I 
    n = int(input())
    s = input()
    r, g, b = 0, 0, 0
    for i in s:
        if i == 'R': r += 1
        elif i == 'G': g += 1
        else: b += 1
    
    total = r*g*b
    # all permutations of rgb are valid, to check if s[i], s[j], s[k] is a permutation of 'rgb' we could use counter. Or neat trick: ASCII value of the sum of s[i] + s[j] + s[k] is same.

    is_rgb = ord('R') + ord('G') + ord('B')

    for i in range(n):
        for j in range(i+1, n):
            # Condition 2 fails when: i - j = k - j --> k = 2*j - i
            k = 2*j - i
            if k < n:
                if ord(s[i]) + ord(s[j]) + ord(s[2*j-i]) == is_rgb:
                    total -= 1
    print(total)

solution1()

Measured memory_bytes: 68348
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

int n, ret, a[MAXN];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 1; i <= n; i ++)
		a[i] = Read();
	for (int i = 29; ~i; i --)
	{
		bool flg = false;
		for (int j = 1; j <= n; j ++)
			if (a[j] > 1 << i)
			{
				if (a[j] == 1 << i + 1)
					flg = true;
				else if (!flg)
					flg = true;
				else
					flg = false, ret ++;
				a[j] = 1 << i;
			}
			else
				ret += flg, flg = 0;
		ret += flg;
	}
	return printf("%d\n", ret), 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	int N = 2*n;
	vector<vector<bool>> imp(N, vector<bool>(N));
	rep(i,0,N) imp[i][i] = 1;

	auto add = [&](int a, int b){
		if(a == b && imp[a][a+n]==0){
			rep(i,0,n) imp[i][a+n] = 1;
			return;
		}
		imp[a][b+n] = imp[b][a+n] = 1;
	};

	rep(_,0,m){
		int x,y;
		cin >> x >> y;
		--x, --y;
		rep(i,0,n)
			if(imp[i][x+n] || imp[i][y+n])
				add(i,x), add(i,y);
		add(x,y);
	}
	rep(k,0,N) rep(i,0,N) rep(j,0,N)
		if(imp[i][k] && imp[k][j])
			imp[i][j] = 1;
	int ans = 0;
	rep(i,0,n) rep(j,0,i){
		if(!imp[i][j+n] && !imp[i][i+n] && !imp[j][j+n])
			++ans;// cout << i+1 << ' ' << j+1 << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 512