akhauriyash/Code-Regression huggingface dataset:
// <------------- Template -----------------------> //


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(0);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[200];ll visit[300]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,q;
string s,t;
ll sum = 0;
// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	ll val = 111;
	while(val < n) val+=111;
	cout<<val;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>

using namespace std;

int main () {
  int Q, N;
  string S;
  int dp[100000];

  cin >> N >> Q;
  cin >> S;

  dp[0] = 0;
  for (int i=1; i<N; i++) {
    dp[i] = dp[i-1];
    if (S[i-1] == 'A' && S[i] == 'C') {
      dp[i]++;
    }
  }

  for (int i=0; i<Q; i++) {
    int l,r;
    cin >> l >> r;
    cout << dp[r-1] - dp[l-1] << endl;
  }

  return 0;
}


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

#define N 1000010 

using namespace std;

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

int rd() {
	int x = 0, f = 1;
	char c = nc();
	while (c < 48) {
		if (c == '-')
			f = -1;
		c = nc();
	}
	while (c > 47) {
		x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
	}
	return x * f;
}

struct Node {
	int x, y;
}b[5];

inline bool cmp(const Node &a, const Node &b) {
	return a.x > b.x;
}

struct Mode {
	Node a;
	Node b;
}f[N];

void merge(Mode &x, Mode y) {
	b[1] = x.a;
	b[2] = x.b;
	b[3] = y.a;
	b[4] = y.b;
	sort(b + 1, b + 4 + 1, cmp);
	x.a = b[1];
	for (int i = 2; i <= 4; i ++ ) {
		if (b[i].y != b[1].y) {
			x.b = b[i];
			return;
		}
	}
}

int a[N];

int bin[20];

int main() {
	int n = rd();
	int all = (1 << n);
	bin[0] = 1;
	for (int i = 1; i <= 19; i ++ ) {
		bin[i] = bin[i - 1] << 1;
	}
	for (int i = 0; i < all; i ++ ) {
		a[i] = rd();
	}
	for (int i = 0; i < all; i ++ ) {
		f[i].a.x = f[i].b.x = 0xefefefef;
	}
	f[0].a = (Node){a[0], 0};
	int ans = 0;
	for (int i = 1; i < all; i ++ ) {
		for (int j = 0; j <= 19; j ++ ) {
			if (i & bin[j]) {
				merge(f[i], f[i ^ bin[j]]);
			}
		}
		Mode mdl;
		int inf = 0xefefefef;
		mdl.a = (Node){a[i], i};
		mdl.b = (Node){inf, 0};
		merge(f[i], mdl);
		ans = max(ans, f[i].a.x + f[i].b.x);
		printf("%d\n", ans);
	}
	return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main() {

	FAST;

	int n, k;
	cin >> n >> k;
	vector <int> v(n);
	for (int i = 0; i < n; i ++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	int ans = 0;
	for (int i = 0; i < k; i ++) {
		ans += v[i];
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3656
# AOJ 1011: Finding the Largest Carbon Compound Give...
# Python3 2018.7.4 bal4u

a = [0]*32
a[1], a[2] = 1, 2
for i in range(3, 31): a[i] = 3*a[i-2] + 2
while True:
	try: i = int(input())
	except: break
	print(a[i])


Measured memory_bytes: 5592
#include <stdio.h>



int main () {
	int d, n;

	scanf ("%d %d", &d, &n);
	int tmp = 1;
	for (int i=0; i<d; i++)
		tmp *= 100;
	if (n!=100)
		printf ("%d\n", tmp*n);
	else
		printf ("%d\n", tmp*(n+1));

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<functional>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

int main(void) {
  int n;
  int hh1, mm1, ss1, hh2, mm2, ss2;
  int a, b;
  int ans;
  int buri[90000];
  while (1) {
	cin >> n;
	if (n == 0) return 0;
	ans = 0;
	fill(buri, buri + 90000, 0);
	for (int i = 0; i < n; i++) {
	  scanf("%d:%d:%d%d:%d:%d", &hh1, &mm1, &ss1, &hh2, &mm2, &ss2);
	  a = 3600 * hh1 + 60 * mm1 + ss1;
	  b = 3600 * hh2 + 60 * mm2 + ss2;
	  for (int j = a; j < b; j++) {
		buri[j]++;
		ans = max(ans, buri[j]);
	  }
	}
	cout << ans << endl;
  }
}

Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	int X;
	string A,B;
	cin>>A>>B;

	A+=B;
	X=stoi(A);
	REP(i,330){
		if(i*i==X){
			print("Yes");
			return 0;
		}
	}	
	print("No");
	return 0;
}


Measured memory_bytes: 256
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

s=groupby(input())
print(len(s)-1)

Measured memory_bytes: 13300
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int h,w,a,b;
  cin>>h>>w>>a>>b;
  auto NO=[](){
            cout<<"NO"<<endl;
            exit(0);
          };
  
  if(h*w<2*(a+b)) NO();
  vector<string> s(h,string(w,'.'));

  if(h==1&&b>0) NO();
  if(w==1&&a>0) NO();
  
  if(h&1){
    for(Int j=0;j+1<w;j+=2){
      if(a==0) break;
      s[0][j]='<';
      s[0][j+1]='>';
      a--;
    }
  }

  if(w&1){
    for(Int i=0;i+1<h;i+=2){
      if(b==0) break;
      s[i][w-1]='^';
      s[i+1][w-1]='v';
      b--;
    }
  }
  
  if(!a&&!b){
    cout<<"YES"<<endl;
    for(Int i=0;i<h;i++) cout<<s[i]<<endl;
    return 0;
  }

  if((h&1)&&(w&1)&&a>0&&b>0){
    assert(h>=3&&w>=3);
    if(a&1){
      s[h-1][w-2]='<';
      s[h-1][w-1]='>';
      a--;
    }
    if(b&1){
      s[h-2][w-3]='^';
      s[h-1][w-3]='v';
      b--;
    }
  }

  for(Int i=(h&1);i+1<h;i+=2){
    for(Int j=0;j+1<w;j+=2){
      if(a>0){
        if(a>0){s[i][j]='<';s[i][j+1]='>';a--;}
        if(a>0){s[i+1][j]='<';s[i+1][j+1]='>';a--;}  
      }else if(b>0){        
        if(b>0){s[i][j]='^';s[i+1][j]='v';b--;}
        if(b>0){s[i][j+1]='^';s[i+1][j+1]='v';b--;}
      }
    }    
  }
  
  if(a||b) NO();
  cout<<"YES"<<endl;
  for(Int i=0;i<h;i++) cout<<s[i]<<endl;
  return 0;
}


Measured memory_bytes: 2304
W,H,x,y,r = map(int,raw_input().split())
if x < 0 or y < 0 or (x-r) < 0 or (y-r) < 0:
    print "No"
elif x > W or y > H:
    print "No"
elif (x - r) > W or (y - r) > H:
    print "No"
elif x == W and r!=0 or y == H and r!=0:
    print "No"
else:
    print "Yes"


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

int main(){
  int n;
  cin >> n;
  ll a[n][n];
  rep(i,n) rep(j,n) cin >> a[i][j];
  
  vector<ll> g((1<<n),0);
  rep(i,1<<n) {
    rep(j,n) {
      for(int k = j+1; k < n; k++) {
        if((i&(1<<j)) && (i&(1<<k))) g[i] += a[j][k];
      }
    }
  }
  vector<ll> dp(1<<n,0);
  rep(s,1<<n) {
    for(ll t = s; ;t = (t-1)&s) {
      dp[s] = max(dp[s],dp[s^t] + g[t]);
      if(t == 0) break;
    }  
  }
  cout << dp[(1<<n)-1] << endl;
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define re register
struct eg{int to,c;eg*nx;}e[200100],*la[100100],*cnt=e;
inline void addE(re int a,re int b,re int c)
{
	*++cnt=(eg){b,c,la[a]};la[a]=cnt;
	*++cnt=(eg){a,c,la[b]};la[b]=cnt;
}
int d[100100],dd[100100],dd1[100100],aa[100100],bb[100100],cc[100100],bl;
long long num,nc,vl1[100100],vl2[100100];
bool vis[200100];
std::vector<long long>vv,vk,v1;
void dfs(re int a)
{
	vis[a]=1;if(d[a]>2)bl=1;
	for(re eg*i=la[a];i;i=i->nx)
	{
		if(!vis[i->to])
		{
			dfs(i->to);
		}
		nc+=i->c-1;
	}
}
int main()
{
//	freopen("01-02.txt","r",stdin);
	re int n,m,ans=0,a,b,c;
	scanf("%d%d",&n,&m);
	for(re int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&a,&b,&c);
		aa[i]=a;bb[i]=b;cc[i]=c;
		if(a==b)
		{
			d[a]+=3;dd[a]++;dd1[a]++;
		}
		else
		{
			d[a]++;d[b]++;addE(a,b,c);
			dd[a]++;dd1[b]++;ans++;
		}
	}
	for(re int i=1;i<=m;i++)
	{
		if(aa[i]==bb[i]&&cc[i]>1)
		{//if(d[aa[i]]==3)printf("****%d %d %d %d\n",aa[i],d[aa[i]],cc[i],v1.size());
			if(d[aa[i]]!=3)vv.push_back(cc[i]-1);
			else v1.push_back(cc[i]-2);
		}
	}
	for(re int i=1;i<=n;i++)
	{
		if(!dd1[i]&&dd[i]){puts("-1");return 0;}
		if(!vis[i])
		{
			bl=0;nc=0;
			dfs(i);nc/=2;//printf("****%d %d %lld\n",i,bl,nc);
			if(bl)
			{
				num+=nc;//printf("**a**%d %lld\n",i,nc);
			}
			else
			{
				vk.push_back(nc);
			}
		}
	}
	//printf("****%lld %d %d\n",num,ans,vk.size());
	std::sort(vv.begin(),vv.end());
	std::sort(vk.begin(),vk.end());
	std::sort(v1.begin(),v1.end());
	if(vk.empty()){printf("%d\n",ans);return 0;}
	if(!num)
	{
		if(!vv.empty())ans++,num+=*vv.rbegin(),vv.pop_back();
		else
		{
			puts("-1");return 0;
		}
	}
	while(num&&!vk.empty())
	{
		num+=*vk.rbegin()-1;
		ans++;vk.pop_back();
	}
	ans+=vk.size();
//	printf("***%d %lld %d %d %d\n",vk.size(),*vk.rbegin(),v1.size(),vv.size(),ans);
	std::reverse(v1.begin(),v1.end());
	std::reverse(vv.begin(),vv.end());
	for(re int i=1;i<=v1.size();i++)vl1[i]=vl1[i-1]+v1[i-1];
	for(re int i=1;i<=vv.size();i++)vl2[i]=vl2[i-1]+vv[i-1];
	if(vk.size()>vl1[v1.size()]+vl2[vv.size()])
	{
		puts("-1");return 0;
	}
	re int nw=v1.size(),bs=1<<30;
	for(re int i=0;i<=vv.size();i++)
	{
		while(nw!=0&&vl2[i]+vl1[nw-1]>=vk.size())nw--;
		if(vl2[i]+vl1[nw]>=vk.size())
		{
			bs=std::min(bs,i+nw*2);
		}
	}
	printf("%d\n",ans+bs);
}

Measured memory_bytes: 10248
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val h = (1..n).map { sc.nextInt() }


  val array = h.toIntArray()
  var count = 0
  for (i in 0 until n) {
    while (array[i] > 0) {
      count++
      for (j in i until n) {
        if (array[j] == 0) break
        array[j] -= 1
      }
    }
  }

  println(count)

}

Measured memory_bytes: 37768
#include<cstdio>
#include<cmath>
bool findPrimeNum(int n){
  for(int i=2;i<=sqrt(n);i++)
    if(n%i==0) return false;
  return n!=1 ? true : false;
}
int main(){
  
  int n,cnt=0;
  scanf("%d",&n);
  int data;
  for(int i=0;i<n;i++){
    scanf("%d",&data);
    if(findPrimeNum(data)==true)cnt++;
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	int t=a;
	a-=min(a,c);
	c-=min(c,t);
	if(c){
		b-=min(b,c);
		cout<<a<<" "<<b;
	}else{
		cout<<a<<" "<<b;
	}
	return 0;
}

Measured memory_bytes: 256
// finish date: 2018/01/10
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int i=a;i<b;i++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long

bool isExist(char c, string str) {
    rep(i, str.length()) {
        if (c == str[i]) return true;
    }
    return false;
}

int fact(int n) {
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans *= i;
    }
    return ans;
}

int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << ((a + b) * h / 2.0) << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if((a==b&&b==c)||(a!=b&&b!=c&&c!=a)){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;
 
int main(){
    int A,B;cin>>A>>B;
    cout<<(A-1)*(B-1)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

int dp[200001][27];
int idx[200001][27];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	int n=s.length();
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<26;j++)
		{
			dp[i][j]=n+10;
		}
	}
	memset(idx,-1,sizeof(idx));
	for(int i = 0; i < 26; i++)
	{
		dp[n-1][i] = 1;
	}
	dp[n-1][s[n-1]-'a'] = 2;
	idx[n-1][s[n-1]-'a'] = 0;
	string ans;
	for(int i = n - 2; i >= 0; i--)
	{
		for(int j = 0; j < 26; j++)
		{
			if(s[i]==j+'a')
			{
				for(int k = 0; k < 26; k++)
				{
					if(dp[i+1][k] + 1 < dp[i][j])
					{
						dp[i][j] = dp[i+1][k] + 1;
						idx[i][j] = k;
					}
				}
			}
			else
			{
				if(dp[i+1][j] < dp[i][j])
				{
					idx[i][j] = j;
					dp[i][j] = dp[i+1][j];
				}
			}
		}
	}
	int cur = 0;
	int best = -1; int mini = 100000000;
	for(int i = 0; i < 26; i++)
	{
		if(dp[0][i] < mini)
		{
			mini=dp[0][i];
			best=i;
		}
	}
	ans+=char('a'+best);
	cur = best;
	for(int i = 0; i < n; i++)
	{
		if(i+1<n)
		{
			if(dp[i][cur]>dp[i+1][idx[i][cur]])
			{
				ans+=char('a'+idx[i][cur]);
			}
		}
		else
		{
			if(idx[i][cur]!=-1)
			{
				ans+=char('a'+idx[i][cur]);
			}
		}
		//cerr<<i<<' '<<cur<<'\n';
		cur=idx[i][cur];
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 42772
#include <bits/stdc++.h>
#define MAX 1010
using namespace std;

int main(void)
{
	int N, X;
	cin >> N >> X;
	int D = 0;
	int cnt = 1;
	for (int i = 0; i < N; i++)
	{
		int t;
		cin >> t;
		D += t;
		if (D <= X) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

using namespace std;

int det(int a, int b, int c, int d) {
	return a * d - b * c;
}

int main() {
	int a[6];
	while(cin) {
		for(int i = 0; i < 6; i++)
			cin >> a[i];
		if(!cin)
			break;
		int d = det(a[0], a[1], a[3], a[4]);
		int x1 = det(a[2], a[1], a[5], a[4]);
		int x2 = det(a[0], a[2], a[3], a[5]);
		cout << setprecision(3) << fixed << 1. * x1 / d + 1e-9 << " ";
		cout << setprecision(3) << fixed << 1. * x2 / d + 1e-9 << endl;
	}

	return 0;
}

Measured memory_bytes: 0
import java.io.*;
import java.util.*;

class Main {
    public void run() throws Exception {
        Scanner sc = new Scanner(System.in);
        int sum = 0;
        sum += sc.nextInt();
        sum += sc.nextInt();
        System.out.println(Math.round(sum / 2.0));
    }

    public static void main(String... args) throws Exception{
        new Main().run();
    }
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
LL n,a[MaxN + 5],b[MaxN + 5],c[MaxN + 5],cnt1[MaxN + 5], cnt2[MaxN + 5];

bool cmp(LL x, LL y){
	return x < y;
}

int main()
{
	scanf("%lld",&n);
	for(LL i = 1; i <= n; i++){
		scanf("%lld",&a[i]);
	}
	for(LL i = 1; i <= n; i++){
		scanf("%lld",&b[i]);
	}
	for(LL i = 1; i <= n; i++){
		scanf("%lld",&c[i]);
	}
	sort(a + 1, a + n + 1,cmp);
	sort(b + 1, b + n + 1,cmp);
	sort(c + 1, c + n + 1,cmp);
	LL l = 1, r = n;
	LL mid;
	for(LL i = 1; i <= n; i++){
		l = 1;
		r = n;
		while(l <= r){
			mid = (l + r) >> 1;
			if(a[mid] >= b[i])
				r = mid - 1;
			else
				l = mid + 1,cnt1[i] = mid;
		}
	}
	for(int i = 1;i <= n; i++){
		l = 1;
		r = n;
		while(l <= r){
			mid = (l + r) >> 1;
			if(c[mid] <= b[i])
				l = mid + 1;
			else
				r = mid -1,cnt2[i] = n - mid + 1;
		}
	}
	LL sum = 0;
    for(int i = 1; i <= n; i++){
    	sum += cnt1[i] * cnt2[i];
	}
	printf("%lld\n",sum);
	return 0;
}






Measured memory_bytes: 4096
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


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

    int n; cin >> n;
    if(n % 2 == 0) cout << n / 2 << endl;
    else cout << n / 2 + 1 << endl;
}







Measured memory_bytes: 256
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
MOD = 10**9+7

def main():
    A = int(readline())
    B = int(readline())
    if A>B:
        print('GREATER')
    elif A<B:
        print('LESS')
    else:
        print('EQUAL')




if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
const int MOD = 1e9 + 7;
int f[N][N], ans;
int n, m, k;
void ADD(int &t, int d) {t += d; if (t >= MOD) t -= MOD;}
int main()
{
    cin >> n >> m >> k;
    f[0][0] = 1;
    for (int i = 0; i <= n; ++ i)
        for (int j = 0; j <= m; ++ j)
            if ((i + j) % (k - 1) == 0)
            {
                for (int p = 0; p < k; ++ p)
                {
                    int q = k - 1 - p;
                    if (i + p > n) continue;
                    if (j + q > m) continue;
                    ADD(f[i + p][j + q], f[i][j]);
                    if (j + q + 1 > m) continue;
                    if (p && ((n - (i + p)) % (k - 1) == 0) && ((m - (j + q + 1)) % (k - 1) == 0))
                        ADD(ans, f[i][j]);
                }
            }
    cout << ans << endl;
}


Measured memory_bytes: 16000
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N;
    cin>>N;
    vector<string> dp[14][14];
    dp[0][0].push_back("a");
    rep(i, N) rep(j, 11){
        rep(k, dp[i][j].size()){
            rep(l, j+1){
                char b='a'+l;
                dp[i+1][j].push_back(dp[i][j][k]+b);
            }
            char b='a'+j+1;
            dp[i+1][j+1].push_back(dp[i][j][k]+b);
        }
    }
    vector<string> ans;
    rep(i, 11){
        rep(j, dp[N-1][i].size()){
            ans.push_back(dp[N-1][i][j]);
        }
    }
    sort(all(ans));
    rep(i, ans.size()){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 59376
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int N=1e5+7;
int f[N][2],head[N],to[N<<1],nxt[N<<1],val[N],fa[N],cnt[N],ans,st,maxdp=-1e9;
char str[N];
inline void ade(int x,int y)
{
	nxt[++nxt[0]]=head[x];
	head[x]=nxt[0];
	to[nxt[0]]=y;
}
void dfs(int x)
{
	cnt[x]=val[x];
	for(int now=head[x];now;now=nxt[now])
	{
		if(to[now]==fa[x])	continue;
		fa[to[now]]=x;dfs(to[now]);
		cnt[x]+=cnt[to[now]];
	}
	if(!st&&cnt[x]==1)	st=x;
}
void dfs2(int x)
{
	for(int now=head[x];now;now=nxt[now])
	{
		if(to[now]==fa[x]||!cnt[to[now]])	continue;
		ans++;val[to[now]]^=1;dfs2(to[now]);
		ans++;val[x]^=1;
	}
}
void dp(int x)
{
	f[x][0]=f[x][1]=val[x];
	int mx1=-1e9,mx2=-1e9;
	for(int now=head[x];now;now=nxt[now])
	{
		if(to[now]==fa[x]||!cnt[to[now]])	continue;
		dp(to[now]);
		if(f[to[now]][1]>mx1)	mx2=mx1,mx1=f[to[now]][1];
		else	if(f[to[now]][1]>mx2)	mx2=f[to[now]][1];
	}
	if(mx1>0)	f[x][1]+=mx1,f[x][0]+=mx1;
	if(mx2>0)	f[x][0]+=mx2;
	maxdp=max(maxdp,f[x][0]);
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n=ri(),i,x,y;
	for(i=1;i<n;i++)
	{
		x=ri(),y=ri();
		ade(x,y);ade(y,x);
	}
	scanf("%s",str+1);
	for(i=1;i<=n;i++)	val[i]=str[i]=='W';
	dfs(1);
	fa[st]=0;dfs(st);
	dfs2(st);
	for(i=1;i<=n;i++)
		if(val[i])	ans++,val[i]=2;
//	printf("ans=%d\n",ans);
	dp(st);
//	for(i=1;i<=n;i++)
//		printf("i=%d f0=%d f1=%d\n",i,f[i][0],f[i][1]);
	int opt=ans-maxdp;
	if(opt==-1)	opt=1;
	wi(opt);putchar('\n');
	return 0;
}


Measured memory_bytes: 8960
N, K = map(int, input().split())
S = str(input())
cnt = 0
l = 0
r = 0

for i in range(N-1):
    if S[i] == "R" and S[i+1] == "L":
        cnt += 1
if S[0] == "L":
    l += 1
if S[N-1] == "R":
    r += 1
    
unhappy = 0
if cnt + max(l,r) <= K:
    unhappy = 1
else:
    unhappy = 2 * (cnt - K) + l + r
print(N - unhappy)

Measured memory_bytes: 39408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int Mod;
inline int add(int a,int b,const int mod=Mod){a+=b;return a>=mod?a-mod:a;}
inline int sub(int a,int b,const int mod=Mod){a-=b;return a<0?a+mod:a;}
inline int mul(int a,int b,const int mod=Mod){return (ll)a*b%mod;}
inline int qpow(int a,int b,const int mod=Mod)
{int ret=1;for(;b;b>>=1,a=mul(a,a,mod))if(b&1)ret=mul(ret,a,mod);return ret;}
/* math */
void upd(int &a,int b){a=add(a,b);}
const int N = 210;
int n,k;
namespace solve0{
	int f[210][210];
	inline void doit(){
		f[0][0]=1;
		for(int i=1;i<=n;i++){
			for(int j=0;j<=k/2;j++){
				f[i][0]=add(f[i][0],f[i-1][j]);
				if(j+1<=k/2)f[i][j+1]=add(f[i][j+1],f[i-1][j]);
			}
		}
		int a=n/2,b=n-a;
		int ans1=0,ans2=0;
		for(int sz=0;sz<=k/2;sz++){
			ans1=add(ans1,f[a][sz]);
			ans2=add(ans2,f[b][sz]);
		}
		cout << mul(ans1,ans2) << endl;
	}
}
namespace solve1{
	int f[N*2][N*2][N*2];
	void doit(){
		f[0][0][0]=1;
		for(int i=1;i<=n+1;i++){
			int r=(i<<1),l=r-k;
			bool fr=(r>=1&&r<=n),fl=(l>=1&&l<=n);
			for(int j=0;j<=n;j++)for(int p=0;p<=k+1;p++)if(f[i-1][j][p]){
				f[i][0][0]=add(f[i][0][0], f[i-1][j][p]);
				if(fr)f[i][j+1][0]=add(f[i-1][j][p],f[i][j+1][0]);
				if(fl&&p+1<k+2)upd(f[i][0][p?p+1:p],f[i-1][j][p]);
				if(fl&&fr&&max(j+2,p+1)<k+2)upd(f[i][j+1][max(p+1,j+2)],f[i-1][j][p]);
			}
		}
		cout << f[n+1][0][0] << endl;
	}
}

int main()
{
	cin >> n >> k >> Mod;
	if(k%2) {
		solve1::doit();
	} else {
		solve0::doit();
	}
	return 0;
}

Measured memory_bytes: 102656
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll gcd(ll x, ll y) {
    if(y == 0) {
        return x;
    }
    return gcd(y, x%y);
}

class Monoid {
public:
    ll unit;  // 単位元

    Monoid() {
        // 単位元(gcdのときは0)
        unit = 0;
    }
    
    // 演算関数(いまはgcd)
    ll calc(ll a, ll b) {
        return gcd(a, b);
    }
};

class SegmentTree {
public:
    ll n;  // セグメント木の葉の要素数
    vector<ll> tree;  // セグメント木
    Monoid mono;  // モノイド
    
    SegmentTree(vector<ll> &v) {
        n = 1 << (ll)ceil(log2(v.size()));
        tree = vector<ll>(n << 1);
        for(ll i = 0; i < v.size(); i++) {
            update(i, v[i]);
        }
        for(ll i = v.size(); i < n; i++) {
            update(i, mono.unit);
        }
    }
    
    // k番目の値(0-index)をxに変更
    void update(ll k, ll x) {
        k += n;
        tree[k] = x;
        for(k = k >> 1; k > 0; k >>= 1){
            tree[k] = mono.calc(tree[k << 1 | 0], tree[k << 1 | 1]);
        }
    }
    
    // [l, r)(0-index)で演算をする
    ll query(ll l, ll r) {
        ll res = mono.unit;
        l += n;
        r += n;
        while(l < r) {
            if(l & 1) {
                res = mono.calc(res, tree[l++]);
            }
            if(r & 1) {
                res = mono.calc(res, tree[--r]);
            }
            l >>= 1;
            r >>= 1;
        }
        return res;
    }

    ll operator[](ll k) {
        // seg[i]で添字iの要素の値を返す
        if(k - n >= 0 || k < 0) {
            return -INF;
        }
        return tree[tree.size()-n+k];
    }
    
    void show() {
        ll ret = 2;
        for(ll i = 1; i < 2*n; i++) {
            cout << tree[i] << " ";
            if(i == ret - 1) {
                cout << endl;
                ret <<= 1;
            }
        }
        cout << endl;
    }
};
 
int main() {
    ll n;
    cin >> n;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    SegmentTree seg(a);
    ll ans = 0;
    rep(i, n) {
        ll x = seg[i];
        seg.update(i, 0);
        chmax(ans, seg.query(0, n));
        seg.update(i, x);
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 3072
package main

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

func solution(n int) int {
	if n == 0 {
		return 1
	}
	return 0
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	fmt.Println(solution(n))
}


Measured memory_bytes: 1840
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String A = sc.next();
        String B = sc.next();
        String C = sc.next();

        if (A.equals(B) && A.equals(C)) {
            System.out.println("No");
        } else if (A.equals(B) || A.equals(C) || B.equals(C)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


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

#define ll long long
#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,n,m) for(int i=m; i<n; i++)
#define MAX 100005
#define MOD 1000000007
#define pb push_back
#define debug(x) cout << x << endl;
#define END cout << endl;
#define sorti(x) sort(x.begin(), x.end())

class UnionFind {
    vector<int> par;
    int n;
 
public:
    UnionFind(int n) : par(n, -1) {}
 
    int find(int x) {
        if (par[x] < 0) return x;
        return par[x] = find(par[x]);
    }
 
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
 
    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int n,m;

int main() {
  cin >> n >> m;
  UnionFind ufi(n+1);
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  rep(i,m) {
    int x,y; cin >> x >> y;
    ufi.unite(x,y);
  }
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    if (ufi.same(p[i], i+1)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	seg := Segment{}
	seg.init(n)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[getNextInt(scanner)-1] = i
	}
	var ans int64
	for i := 0; i < n; i++ {
		seg.add(aa[i], 1)
		l := seg.nextLeft(aa[i])
		r := seg.nextRight(aa[i])
		ans += int64(aa[i]-l) * int64(r-aa[i]) * int64(i+1)

	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

// Segment ...
type Segment struct {
	n, h, i int
	unit    []int
	bucket  [][]int
}

func (seg *Segment) init(n int) {
	seg.n = n
	seg.unit = make([]int, 1)
	seg.unit[0] = 1
	seg.bucket = make([][]int, 1)
	seg.bucket[0] = make([]int, n)

	chunk := 32
	i := 0
	for n > chunk+1 {
		n = (n-1)/chunk + 1
		seg.bucket = append(seg.bucket, make([]int, n))
		seg.unit = append(seg.unit, seg.unit[i]*chunk)
		i++
	}
	seg.h = len(seg.unit)
}

func (seg *Segment) add(index, value int) {
	for i := 0; i < seg.h; i++ {
		seg.bucket[i][index/seg.unit[i]] += value
	}
}

func (seg *Segment) nextLeft(index int) int {
	raw := seg.bucket[0]
	for index = index - 1; index >= 0; index-- {
		if raw[index] > 0 {
			return index
		}
		for seg.i = 0; seg.i < seg.h; seg.i++ {
			if (index+1)%seg.unit[seg.i] != 0 {
				break
			}
			if seg.bucket[seg.i][index/seg.unit[seg.i]] != 0 {
				break
			}
		}
		seg.i--
		index -= seg.unit[seg.i] - 1
	}

	return -1
}

func (seg *Segment) nextRight(index int) int {
	raw := seg.bucket[0]
	for index = index + 1; index < seg.n; index++ {
		if raw[index] > 0 {
			return index
		}
		for seg.i = 0; seg.i < seg.h; seg.i++ {
			if index%seg.unit[seg.i] != 0 {
				break
			}
			if seg.bucket[seg.i][index/seg.unit[seg.i]] != 0 {
				break
			}
		}
		seg.i--

		index += seg.unit[seg.i] - 1
	}

	return seg.n
}

func (seg *Segment) get(index int) int {
	for i := 0; i < seg.n; i++ {
		for seg.i = 0; seg.i < seg.h; seg.i++ {
			if index%seg.unit[seg.i] != 0 {
				break
			}
			if seg.bucket[seg.i][index/seg.unit[seg.i]] >= index {
				break
			}
		}
		seg.i--

		index -= seg.bucket[seg.i][index/seg.unit[seg.i]]
		i += seg.unit[seg.i] - 1

		if index == 0 {
			return i
		}
	}

	return -1
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
long long n,m,k,cnt=1,MAX=1,ans=0,num=0,sum=0,ave,tmp=0;
string s,t;
int main(){
  cin >> n;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    a[i]--;
    a[i]-=i;
    sum+=a[i];
  }
  ave=sum/n;
  sort(a,a+n);
  for(int i=1;i<n;i++){
    if(a[i]!=a[i-1]){
      cnt=1;
    }else{
      cnt++;
    }
    if(cnt>MAX){
      num=a[i];
    }
    MAX=max(cnt,MAX);
  }
  for(int i=0;i<n;i++){
    ans+=abs(a[i]-num);
  }
  for(int i=ave-1;i<ave+2;i++){
    for(int j=0;j<n;j++){
      tmp+=abs(a[j]-i);
    }
    ans=min(ans,tmp);
    tmp=0;
  }
  for(int i=0;i<n;i++){
    tmp+=abs(a[i]-a[(n-1)/2]);
  }
  ans=min(ans,tmp);
  tmp=0;
  for(int i=0;i<n;i++){
    tmp+=abs(a[i]-a[(n-1)/2+1]);
  }
  ans=min(ans,tmp);
  tmp=0;
  for(int i=0;i<n;i++){
    tmp+=abs(a[i]-a[(n-1)/2-1]);
  }
  ans=min(ans,tmp);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

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

    ll r = 0,g = 0,b = 0;

    for(int i = 0;i < N;i++){
        if(S.at(i) == 'R')
            r++;
        else if(S.at(i) == 'G')
            g++;
        else
            b++;
    }

    ll ans = r * g * b,hosyuu=0;

    for(int i = 0;i < N;i++)
        for(int j = i+1;j < N;j++){
            if(S.at(i) == S.at(j))
                continue;
            int k = 2 * j - i;
            if(k >= N or S.at(k) == S.at(i) or S.at(k) == S.at(j))
                continue;
            else
                ++hosyuu;
        }
    cout << ans - hosyuu << endl;
}

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

int main()
{
	int N;
	cin >> N;
	int ans = 0;
	int res = 0;
	if (N == 1) {
		res = 1;
	}
	else {
		for (int i = 1;i <= N;i++) {
			if (i % 2 == 0) {
				int s = 0;
				for (int j = i;j % 2 == 0;j /= 2) {
					s++;
					if (ans < s) {
						ans = s;
						res = i;
					}
				}
			}
		}
	}
		cout << res << endl;
}

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


int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> v;
    map<int, int> m;
    int sum = q;
    for (int i = 1; i <= n; i++)
    {
        m[i] = 0;
    }
    for (int i = 1; i <= q; i++)
    {
        int x;
        cin >> x;
        m[x] += 1;
    }
    for (int i = 1; i <= n; i++)
    {
        if (k > sum - m[i])
        {
            cout << "Yes" << "\n";
        }
        else
        {
            cout << "No" << "\n";
        }
    }


    return 0;
}



Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
deque < long long > a;
deque < long long > b;
int main()
{
	long long n,a2,b2;
	cin>>n;
	for(long long i=0;i<n;i++)
	{
		cin>>a2;
		a.push_back(a2);
	}
	for(long long i=0;i<n;i++)
	{
		cin>>b2;
		b.push_back(b2);
	}
	long long k=0;
	for(long long i=0;i<n;i++)	k+=b[i]-a[i];
	long long two=0;
	for(long long i=0;i<n;i++)
	{
		long long d=b[i]-a[i];
		if(d>0)	two+=(d+1)/2;
	}
	if(two>k) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n;
    cin >> n;

    string s;
    cin >> s;

    constexpr auto M = 1000000007;
    int64_t num = 0;
    int64_t ans = 1;
    for (auto c : s) {
        if (c == 'W') {
            if (num % 2 == 0) {
                ans *= num;
                ans %= M;
                --num;
            } else {
                ++num;
            }
        } else {
            if (num % 2 == 0) {
                ++num;
            } else {
                ans *= num;
                ans %= M;
                --num;
            }
        }
    }

    for (auto i : irange(1L, n + 1)) {
        ans *= i;
        ans %= M;
    }

    if (num > 0) {
        cout << 0 << endl;
    } else {
        cout << ans << endl;
    }
}

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m; assert(b>=0); for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, m;
string s, t;

signed main() {
	while (1) {
		cin >> s;
		if (s==".") break;
		cin >> t;
		n = s.size(), m = t.size();
		string a, b;
		vst x, y;
		rep(i,n) {
			if (s[i]!='\"') a.pb(s[i]);
			else {
				a.pb('@');
				int j = i+1;
				string p;
				while (s[j]!='\"') p.pb(s[j++]);
				x.pb(p);
				i = j;
			}
		}
		rep(i,m) {
			if (t[i]!='\"') b.pb(t[i]);
			else {
				b.pb('@');
				int j = i+1;
				string p;
				while (t[j]!='\"') p.pb(t[j++]);
				y.pb(p);
				i = j;
			}
		}
		if (x.size()!=y.size() || a!=b) cout << "DIFFERENT" << ln;
		else {
			int d = 0;
			rep(i,x.size()) if (x[i]!=y[i]) d++;
			if (d==0) cout << "IDENTICAL" << ln;
			else if (d==1) cout << "CLOSE" << ln;
			else cout << "DIFFERENT" << ln;
		}
	}
}


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

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

    double a[n] ;
    double s = 0;
    for(int i = 0 ; i < n ; i++){
        cin >> a[i] ;
        s += a[i] ;
    } 
    
    ll count = 0;
    for(int i = 0 ; i < n ; i++){
        if(a[i] >= s / (4 * m )){
            count ++ ;
        }
    }
    if(count >= (ll)m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0 ;
}

 


Measured memory_bytes: 256
import Control.Monad

import Data.Ord
import Data.List
import Data.Function
import Data.Maybe

import qualified Data.ByteString.Char8 as BS

import Debug.Trace

tuplify :: [String] -> (String, Integer)
tuplify (x:y:_) = (x, - read y)
tuplify _ = undefined

--Input functions by ByteString
readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

readStrTuple = tuplify . words

getIntList = readIntList <$> BS.getLine

getStrTuples = map readStrTuple . lines <$> getContents

main = do
  [n] <- getIntList
  sps <- getStrTuples
  mapM_ print . map fst . sortBy (compare `on` snd) $ zip [1..n] sps

Measured memory_bytes: 1020
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
using namespace std;


using ll=long long int;


int main() {

	string s;
	cin >> s;

	int mini = 10000;


	for (int i = 0; i < s.size() - 2; i++) {

		mini = min(mini, abs(stoi(s.substr(i,3)) - 753));

	}


	cout << mini << endl;

	return 0;
}





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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



int main(){
    string s;
    cin >> s;
    int n = sz(s);
    int p = 0, g = 0;
    rep(i,n) {
        if(s[i] == 'g') g++;
        if(s[i] == 'p') p++;
    }
    int ans = min(n/2, g) - min(n-n/2, p);
    cout << ans << endl;
}

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

int a[100004], b[2][100004], c[2][100004];
int main(){
	int n, f = 0, cnt = 0;
	scanf("%d", &n);
	for(int i = 1;i <= n;i++)scanf("%d", &a[i]);
	
	for(int i = 1;i <= n;i++){
		if(a[i] == i%2)b[0][i]++;
		if(a[i] != i%2)b[1][i]++;
	}
	
	for(int i = 1;i <= n;i++){
		if(b[0][i] == 0)cnt++;
		if(b[0][i] == 1){
			c[0][i] = cnt;
			cnt = 0;
		}
	}
	
	cnt = 0;
	for(int i = 1;i <= n;i++){
		if(b[1][i] == 0)cnt++;
		if(b[1][i] == 1){
			c[1][i] = cnt;
			cnt = 0;
		}
	}
	
	for(int i = 1;i <= n;i++){
		if(b[0][i] == 0)f = 0;
		if(!f && b[0][i]){
			b[0][i] += b[0][i-1];
			f = 1;
		}else b[0][i] = b[0][i-1];
	}
	
	f = 0;
	for(int i = 1;i <= n;i++){
		if(b[1][i] == 0)f = 0;
		if(!f && b[1][i]){
			b[1][i] += b[1][i-1];
			f = 1;
		}else b[1][i] = b[1][i-1];
	}
	
	int ans = 0, l = 1, res, x, y;
	for(int i = 1;i <= n;i++){
		while(1){
			x = b[0][i]-b[0][l];
			y = b[1][i]-b[1][l];
			if(x == y){
				res = x;
				cnt = max(c[0][l], c[1][l]);
			}else if(x < y){
				res = x;
				cnt = c[0][l];
			}else{
				res = y;
				cnt = c[1][l];
			}
			if(res <= 0)break;
			l++;
		}
		ans = max(ans, i-l+1+cnt);
	}
	
	printf("%d\n", ans);
	//for(int i = 1;i <= n;i++)printf("%d ", b[0][i]);
	return 0;
}


Measured memory_bytes: 5136
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int n; readV(n);
  int[] a; readC(n, a); a[] -= 1;

  auto v = new bool[](n), c = 0, b = 0;
  v[0] = true;

  for (;;) {
    b = a[b];

    if (v[b]) {
      writeln(-1);
      return;
    }

    ++c;
    if (b == 1) {
      writeln(c);
      return;
    }

    v[b] = true;
  }
}


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

int N,K,Q;
int A[2010];
int main(){
	cin >> N >> K >> Q;
	vector<int> v(N);
	for(int i=0;i<N;i++){
		cin >> A[i];
		v[i] = A[i];
	}
	sort(v.begin(),v.end());
	int ans = 2e9;
	vector<int> removed,pre_removed;
	for(int i=0;i<N;i++){
		int c = 0;
		for(int j=0;j<=N;j++){
			if(j!=N && A[j]>=v[i]){
				pre_removed.push_back(A[j]);
				c++;
			}else if(j==N || A[j]<v[i]){
				if(c>=K){
					sort(pre_removed.begin(),pre_removed.end());
					for(int k=0;k<=c-K;k++){
						removed.push_back(pre_removed[k]);
					}
				}
				pre_removed.clear();
				c = 0;
			}
		}
		if(removed.size()>=Q){
			sort(removed.begin(),removed.end());
			ans = min(ans,removed[Q-1]-removed[0]);
		}
		removed.clear();
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func solution(n int, a []int) int {
        const MOD = 1e9 + 7
        out := 0
        cur := make([]int, n+1)
        cur[0] = a[0]
        for i := 0; i < n; i++ {
                cur[i+1] = a[i] + cur[i]
        }
        for i := 0; i < n; i++ {
                sum := (cur[n] - cur[i+1]) % MOD
                out += a[i] * sum
                out %= MOD
        }
        return out
}

func main() {
        r := bufio.NewReader(os.Stdin)
        var n int
        fmt.Fscan(r, &n)
        a := make([]int, n)
        for i := range a {
                fmt.Fscan(r, &a[i])
        }
        fmt.Println(solution(n, a))
}

Measured memory_bytes: 7592
A, B = (int(i) for i in input().split())
def euclid(a, b):
    while b:
        a, b = b, a%b
    return a
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table
try:
  print(len(list(set(prime_decomposition(euclid(A,B)))))+1)
except:
  print(1)

Measured memory_bytes: 3064
N = int(input())
l=list()#empty list
 
for i in range(1,N+1):
    tempS,tempP = input().split()
    l.append([tempS,-int(tempP),i])
 
sortedList = sorted(l,key=lambda item:(item[0],item[1]))
 
for i in range(1,N+1):
    print(sortedList[i-1][2])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

int my_ceil(int a, int b){
    return a/b + (a%b > 0);
}

int main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, x, t; cin >>n >>x >>t;

    cout <<my_ceil(n, x)*t <<endl;

    return 0;
}


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

int main() {

    int A , B , C , X;
    cin >> A >> B >> C >> X;

    int count=0;
    
    for(int a=0 ; a <= A ; a++){
        for(int b=0 ; b <= B;b++){
            for(int c=0 ; c <= C;c++){
                int total = 500*a+100*b+50*c;
                if(total == X) count++;
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256