akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

typedef long long ll;
typedef std::vector< std::pair< ll, ll > > VP;
typedef std::vector< std::pair< ll, ll > >::iterator PIT;

const ll INF = 1e12;

bool check[100];

int main()
{
  ll N, M;
  std::cin >> N >> M;
  VP vp(M, std::make_pair(0, 0));

  for (ll i = 0; i < M; i++) {
    std::cin >> vp[i].first >> vp[i].second;
  }

  ll ans = 0;
  for (ll i = 0; i < M; i++) {
    PIT it;
    std::map< ll, std::vector< ll > > mymap;
    for (it = vp.begin(); it != vp.end(); it++) {
      ll idx = std::distance(vp.begin(), it);
      if (idx == i) {
	//std::cout << "cut_idx: " << idx << std::endl;
	continue;
      }

      if (mymap.find(it->first) == mymap.end()) {
	mymap.insert(std::make_pair(it->first, std::vector< ll > (1, it->second)));
	//std::cout << "fir1:" << it->first << " " << it->second << std::endl;
      } else {
	mymap[it->first].push_back(it->second);
	//std::cout << "fir2:" << it->first << " " << it->second << std::endl;
      }
      if (mymap.find(it->second) == mymap.end()) {
	mymap.insert(std::make_pair(it->second, std::vector< ll > (1, it->first)));
	//std::cout << "sec1:" << it->second << " " << it->first << std::endl;
      } else {
	mymap[it->second].push_back(it->first);
	//std::cout << "sec2:" << it->second << " " << it->first << std::endl;
      }
    }

    for (ll pos = 0; pos < N+1; pos++) {
      check[pos] = false;
    }

    std::priority_queue< ll > que;
    que.push(1);

    while (!que.empty()) {
      ll pos = que.top();
      que.pop();
      for (std::vector< ll >::iterator it = mymap[pos].begin(); it != mymap[pos].end(); it++) {
	//std::cout << "pass:" << pos << " " << *it << std::endl;
	if (check[*it] == false) {
	  que.push(*it);
	}
      }
      check[pos] = true;
    }

    //std::cout << "---------" << std::endl;
    bool is_all_reached = true;
    for (ll pos = 1; pos < N+1; pos++) {
      //std::cout << pos << " " << check[pos] << std::endl;
      if (check[pos] == false) {
	is_all_reached = false;
      }
    }
    if (!is_all_reached) {
      ans++;
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vi v;
vi a,b,c,d;
ll n,m,q;
ll ans=0;
ll solve(){
    ll res=0;
    rep(i,q){
        if(v[b[i]]-v[a[i]]==c[i])res+=d[i];
    }
    return res;
}
void dfs(){
    if(v.size()==n)chmax(ans,solve());
    else{
        REP(k,v.back(),m+1){
            v.pb(k);
            dfs();
        }
    }
    v.pop_back();
}
int main(){
    cin>>n>>m>>q;
    a=vi(q);
    b=vi(q);
    c=vi(q);
    d=vi(q);
    rep(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;b[i]--;
    }
    REP(i,1,m+1){
        v=vi(1);v[0]=i;
        dfs();
    }
    out(ans);
}

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, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];

  int ans = 0;
  set<int> a, b;
  rep(i, n) {
    rep(j, s[i].length() - 1) {
      if (s[i].substr(j, 2) == "AB") ans++;
    }
    if (s[i][0] == 'B') a.insert(i);
    if (s[i][s[i].length() - 1] == 'A') b.insert(i);
  }
  ans += min(a.size(), b.size());
  if (!a.empty() && a == b) ans--;
  cout << ans << endl;


  
  return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split(' ')))

s = [0 for i in range(n-1)]
s[0] = sum(a) - a[0]
for i in range(1, n-1):
  s[i] = s[i-1] - a[i]

ans = 0
mod = 10 ** 9 + 7

for i in range(n - 1):
  k = a[i] * s[i] % mod
  ans += k
  ans %= mod
    
print(ans)

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#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 	= 	4 * MAX5;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

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

ll t = 1;
ll n, x, k, q, m, y, r;
string s;


// <------------- Implement Functions Here ----------> //




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

void MAIN() {
	cin >> n >> r;
	if (n >= 10) cout<<r;
	else {
		cout<<r+100*(10-n);
	}
}

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


Measured memory_bytes: 13000
#include <iostream>
#include<string>
using namespace std;
int main()
{
    int n,i;
    string s;
    char a;
    cin>>n>>s;
    a=n;
    for(i=0;i<s.size();i++)
    {
        s[i]+=a;
        if(s[i]>'Z')s[i]-=26;
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N,K;
	cin>>N>>K;
	vec(A)
	fx(N){
		vecp(A)
	}
	sorts(A)
	reverses(A)
	int ans=0;
	fx(K){
		ans+=A.at(x);
	}
	ce(ans)
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

vector<ll>V;

void solve(ll N)
{
	ll res = 0;

	for(ll i = 0;i<N;i++)
	{
		res ^= V[i];
	}

	for(ll i = 0;i<N;i++)
		V[i] = res ^ V[i];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N;
	cin>>N;

	for(ll i = 0;i<N;i++)
	{
		ll inp;
		cin>>inp;
		V.pb(inp);
	}

	solve(N);

	for(ll i = 0;i<N;i++)
		cout<<V[i]<<" ";

	return 0;
} 

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

int main(void)
{
    double A, B, C;
    char K[20];
    int i;
    double tmpA, tmpB, tmpC, seisuu, shousuu;
    scanf("%lf%lf%lf%s", &A, &B, &C, &K);
//    printf("%f %f %f", A, B, C);

    if (fabsf(A-B)>1e+18){
        printf("Unfair\n");
    } else {
//        shousuu = modf(K/2.0,&seisuu);
//        printf("%f\n", shousuu);
//        printf("%.0f\n", fabsf(shousuu-0.5)>1e-3 ? A-B : B-A );
        if (atoi(&K[strlen(K)-1])%2==0) {
            printf("%.0f\n", A-B);
        } else {
            printf("%.0f\n", B-A);
        }
    }
    return 0;
}

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


signed main() {
  int N, P;
  cin >> N >> P;
  
  if( N == 1 ){
    cout << P << endl;
    return 0;
  }
  
  int A = P;
  int ans = 1;
  int cnt = 2;
  int waru = 0;
  while( P > 1 && cnt <= sqrt(A) ){
    if( P % cnt == 0 && P / cnt > 0 ){
      waru++;
      P /= cnt;
    }else if( P % cnt != 0 ){
      cnt++;
      waru = 0;
    }
    if( waru == N ){
      ans *= cnt;
      waru = 0;
    }
  }
  cout << ans << endl;
    
}



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

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

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

    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    long d = sc.nextLong();

    long[] x = new long[n];
    long[] y = new long[n];

    long dDist = d*d;

    int counter = 0;

    for(int i=0; i<n; i++){
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();

      long dist = x[i] * x[i] + y[i] * y[i];
      if(dDist >= dist) counter++;
    }

    System.out.println(counter);
    
    return;

  }
}

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

using namespace std;

int main(){
  int n, m, x;
  cin >> n >> m >> x;
  
  int l_cost = 0;
  int r_cost = 0;
  int location;
  for(int i=0;i<m;i++){
    cin >> location;
    if(location<x)l_cost++;
    else r_cost++;
  }
  cout << min(l_cost, r_cost) << 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++)

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  long long int a=0,b=0,c=0,d=0,n=0,h,w,count=0,ans=0;
  string s;
  cin>>a>>b>>c>>d;
  h=d-b;
  w=c-a;
  rep(i,w) cout<<'R';
  rep(i,h) cout<<'U';
  rep(i,w) cout<<'L';
  rep(i,h) cout<<'D';
  cout<<'D';
  rep(i,w+1) cout<<'R';
  rep(i,h+1) cout<<'U';
  cout<<'L'<<'U';
  rep(i,w+1) cout<<'L';
  rep(i,h+1) cout<<'D';
  cout<<'R'<<endl;
  
  
  
}
///////////////////////////

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int q;
    cin >> q;
    multiset<long long> st;
    int x;
    long long a,b;
    auto itr = st.begin();
    long long cnst = 0;
    long long sum,dsum;
    dsum = sum = 0;
    int cnt = 0;
    vector<long long> ans1,ans2;
    rep(i,q){
        cin >> x;
        if(i==0){
            cin >> a >> b;
            cnst+=b;
            st.insert(a);
            cnt++;
            dsum+=a;
            sum+=a;
            itr = st.begin();
        }
        else{
            if(x==1){
                cin >> a >> b;
                cnst+=b;
                st.insert(a);
                cnt++;
                sum+=a;
                //dsum&itrの変更
                if(cnt%2==0){
                    if(a>=*itr){
                        dsum=dsum;
                        itr = itr;
                    }
                    else{
                        dsum = dsum - *itr + a;
                        itr--;
                    }
                }
                else{
                    if(a>=*itr){
                        itr++;
                        dsum+=*itr;
                    }
                    else{
                        dsum += a;
                        itr = itr;
                    }
                }
                //
            }
            else{
                ans1.push_back(*itr);
                ans2.push_back(sum - 2*dsum + *itr*(st.size()%2) + cnst);
            }
        }
    }
    rep(i,ans1.size()){
        cout << ans1[i] << " " << ans2[i] << endl;
    }
}

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

string s;

signed main()
{
	cin>>s;
	if (s[0]=='7'||s[1]=='7'||s[2]=='7')  cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
} 

Measured memory_bytes: 3612
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;



int main(void){
	ll H,W,N,a,h=0,w=0,direction=0,color[101][101];//H,W
	cin>>H>>W>>N;
	reg(i,1,N){
		cin>>a;
		rep(j,a){
			color[h][w]=i;
			if(direction==0){
				if(w==W-1){
					h++;
					direction=1;
				}else{
					w++;
				}
			}else{
				if(w==0){
					h++;
					direction=0;
				}else{
					w--;
				}
			}
		}
	}
	rep(i,H){
		rep(j,W)cout<<color[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var a, b, k int
	fmt.Scanf("%d %d %d", &a, &b, &k)

	if a < k {
		if b < (k - a) {
			b = 0
		} else {
			b = b - (k - a)
		}
		a = 0
	} else {
		a = a - k
	}

	fmt.Printf("%d %d", a, b)
}


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

#define int unsigned long long int

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

	string S;
	cin>>S;
	if(S == "ABC")
		cout<<"ARC\n";
	else
		cout<<"ABC\n";

	return 0;
}

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


int main() {
    long long int MAX = 1000000007;
    int N;
    std::string S1, S2;
    std::cin >> N;
    std::cin >> S1 >> S2;

    long long int scale = 3;
    for (int i = 0; i < N; i++) {
        if (S1[i] != S2[i]) {
            if (i == 0 || S1[i - 1] == S2[i - 1]) {
                scale = (scale * 2) % MAX;
            } else {
                scale = (scale * 3) % MAX;
            }
            i++;
        } else {
            if (i > 0 && S1[i - 1] == S2[i - 1]) {
                scale = (scale * 2) % MAX;
            }
        }
    }
    std::cout << scale << std::endl;
}


Measured memory_bytes: 3636
import fractions
N,M=map(int,input().split())
S=input()
T=input()
lcm=(N*M)/fractions.gcd(N,M)
num=0
s=[]
t=[]
flag=1
sindex=0
tindex=0
while (sindex<N)and(tindex<M):
    if S[sindex]!=T[tindex]:
        flag=0
        break
    sindex=sindex+(N//fractions.gcd(N,M))
    tindex = tindex + (M // fractions.gcd(N, M))
"""
for j in range(N):
    s.append([S[j],int(1+(num//N)*j)-1])
for j in range(M):
    t.append([T[j], int(1 + (num // M) * j) - 1])
#print(s,t)
while (sindex<N)and(tindex<M):
    #print(sindex,tindex)
    if s[sindex][1]==t[tindex][1]:
        if s[sindex][0]!=t[tindex][0]:
            flag=0
            break
        sindex=sindex+1
        tindex=tindex+1
    elif s[sindex][1]<t[tindex][1]:
        sindex=sindex+1
    else:
        tindex = tindex + 1
    #input()
"""
if flag==0:
    print("-1")
else:
    print(int(lcm))




Measured memory_bytes: 5344
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>

using namespace std;

string user[256];
int n,m;

int check(string in){
	for(int i=0;i<n;i++) if(user[i] == in) return 1;
	return 0;
}
main(){
	string in;
	int i,j;
	int state = 0;
	cin >> n;
	for(i=0;i<n;i++) cin >> user[i];
	cin >> m;
	for(i=0;i<m;i++){
		cin >> in;
		if(check(in)) printf("%s by %s\n", state++%2 ? "Closed":"Opened", in.c_str());
		else printf("Unknown %s\n", in.c_str());
	}
}

Measured memory_bytes: 1224
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskD   {
public void solve(int testNumber, Scanner in, PrintWriter out) {
        int X = in.nextInt();
        int Y = in.nextInt();
        int Z = in.nextInt();
        int K = in.nextInt();
        long A[] = new long[X];
        long B[] = new long[Y];
        long C[] = new long[Z];
        for (int i=0; i<X; i++) {
            A[i] = in.nextLong();
        }
        for (int i=0; i<Y; i++) {
            B[i] = in.nextLong();
        }
        for (int i=0; i<Z; i++) {
            C[i] = in.nextLong();
        }
        Arrays.sort(A);
        Arrays.sort(B);
        Arrays.sort(C);

        PriorityQueue<long[]> Q = new PriorityQueue<>((array1, array2)->(int)((-array1[0]+array2[0])%1_000_000_000_000L));
        HashSet<Long> inQ = new HashSet<>();

        long temp[] = {A[X-1]+B[Y-1]+C[Z-1], X-1, Y-1, Z-1};
        Q.add(temp);
        inQ.add(hl(X-1, Y-1, Z-1));

        for (int i=0; i<K; i++) {
            temp = Q.poll();
            out.println(temp[0]);
            if(temp[1] > 0 && !inQ.contains(hl(temp[1]-1, temp[2], temp[3]))){
                long temp1[] = {A[(int)temp[1]-1]+B[(int)temp[2]]+C[(int)temp[3]], temp[1]-1, temp[2], temp[3]};
                Q.add(temp1);
                inQ.add(hl(temp[1]-1, temp[2], temp[3]));
            }
            if(temp[2] > 0 && !inQ.contains(hl(temp[1], temp[2]-1, temp[3]))){
                long temp2[] = {A[(int)temp[1]]+B[(int)temp[2]-1]+C[(int)temp[3]], temp[1], temp[2]-1, temp[3]};
                Q.add(temp2);
                inQ.add(hl(temp[1], temp[2]-1, temp[3]));
            }
            if(temp[3] > 0 && !inQ.contains(hl(temp[1], temp[2], temp[3]-1))){
                long temp3[] = {A[(int)temp[1]]+B[(int)temp[2]]+C[(int)temp[3]-1], temp[1], temp[2], temp[3]-1};
                Q.add(temp3);
                inQ.add(hl(temp[1], temp[2], temp[3]-1));
            }
        }
    }

long hl(long x, long y, long z) {
        return x * 10000 * 10000 + y * 10000 + z;
    }

}
}




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

int main()
{
    int n , k ;
    scanf("%d%d",&n,&k) ;
    int a[n] ;
    for(int i = 0 ; i < n ; ++i) scanf("%d",&a[i]) ;
    sort(a,a+n) ;
    int dp[k+1] = {0} ;
    for(int i = 1 ; i <= k ; ++i)
    {
        for(int j = 0 ; j < n ; ++j)
        {
            if(a[j]<=i && dp[i-a[j]]==0) dp[i] = 1 ;
        }
    }
    if(dp[k]) puts("First") ;
    else puts("Second") ;
}


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

int main()
{
  int k;
  scanf("%d", &k);
  
  int current = 9;
  list<long long> lunluns;
  for (int i = 1; i < 10; i++)
    lunluns.push_back(i);
  while (current < k)
  {
    long long t = lunluns.front();
    lunluns.pop_front();
    
    for (int i = -1; i < 2; i++) {
      int d = t % 10 + i;
      if (d >= 0 && d < 10) {
        lunluns.push_back(t * 10 + d);
        current++;
      }
    }
  }
  
  for (int i = 0; i < current - k; i++)
    lunluns.pop_back();
  printf("%lld\n", lunluns.back());  

  return 0;
}

Measured memory_bytes: 2304
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
	string sA, sB, sC;
	cin >> sA >> sB >> sC;

	char current = 'a';

	while(current != '\0'){
		switch(current){
			case 'a':
				current = sA[0];
				if (current == '\0'){
					cout << "A" << endl;
					return 0;
				}
				sA.erase(sA.begin());
				break;

			case 'b':
				current = sB[0];
				if (current == '\0'){
					cout << "B" << endl;
					return 0;
				}
				sB.erase(sB.begin());
				break;

			case 'c':
				current = sC[0];
				if (current == '\0'){
					cout << "C" << endl;
					return 0;
				}
				sC.erase(sC.begin());
				break;
		}
	}

}
	


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll a, b;
  cin >> a >> b;
  cout << (a + b) / 2 << endl;
	return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0; }
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S, T;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//
int main() {
	ll A, B;
	cin >> A >> B;
	vl C = { 0,1,1,1 };
	C[A] = 0;
	C[B] = 0;
	for (i = 0; i < 4; i++) {
		if (C[i] == 1) {
			cout << i;
			exit(0);
		}
	}
}

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

using namespace std;

int main()
 {
     int a,b,c;
     int ar[4],res;

    for(int i=0;i<3;i++)
    {
        cin>>ar[i];
    }

     sort(ar,ar+3,greater<int>());

     res=(ar[0]*10)+ar[1]+ar[2];

     cout<<res<<endl;

    return 0;
  }



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

int main(){
    int N, M;
    std::cin >> N >> M;
    std::vector< std::vector< bool > >A(N, std::vector< bool >(N));
    for(int i=0; i<N; i++){
        std::string tmp;
        std::cin >> tmp;
        for(int j=0; j<N; j++){
            if(tmp[j] == '.'){
                A[i][j] = true;
            }else{
                A[i][j] = false;
            }
        }
    }
    std::vector< std::vector< bool > >B(M, std::vector< bool >(M));
    for(int i=0; i<M; i++){
        std::string tmp;
        std::cin >> tmp;
        for(int j=0; j<M; j++){
            if(tmp[j] == '.'){
                B[i][j] = true;
            }else{
                B[i][j] = false;
            }
        }
    }
    
    for(int i=0; i<N-M+1; i++){
        for(int j=0; j<N-M+1; j++){
            bool find = true;
            for(int a=0; a<M; a++){
                for(int b=0; b<M; b++){
                    if(A[a+i][b+j] != B[a][b]){
                        find = false;
                        break;
                    }
                }
                if(!find){
                    break;
                }
            }
            if(find){
                std::cout << "Yes" << std::endl;
                return 0;
            }
        }
    }
    
    std::cout << "No" << std::endl;
    
    return 0;
    
}



Measured memory_bytes: 256
use proconio::input;

fn main() {
  input!{
    x: i64
  }
  
  for a in 1..=1000 {
    for b in -1000..=1000 {
      if a*a*a*a*a - b*b*b*b*b == x {
        println!("{} {}", a, b);
        return;
      }
    }
  }
}

Measured memory_bytes: 2116
#include <stdio.h>
int n, m, a[100], b[100];
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; i++) scanf("%d%d", &a[i], &b[i]);
	int l = 1, c = 0;
	while(l <= n) {
		int ptr = -1;
		for(int j = 0; j < m; j++) {
			if(a[j] <= l && b[j] >= l && b[ptr] < b[j]) ptr = j;
		}
		if(ptr == -1) {
			printf("Impossible\n");
			return 0;
		}
		l = b[ptr] + 1; c++;
	}
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 2724
N,A,B=gets.chomp.split(" ").map{|n| n.to_i}
if(A>B)
	puts 0
	exit(0)
end
if(N==1)
	if(A==B)
		puts 1
	else
		puts 0
	end
	exit(0)
end
puts (N-2)*(B-A)+1



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

int main() {
 int n,c=0; cin>>n;
  int p[n];
  for(int i=0;i<n;i++) cin>>p[i];
   
  for(int i=0;i<n-2;i++){
    if( (p[i]-p[i+1]) * (p[i+2]-p[i+1]) < 0 ) c++;
  }
  cout<<c<<endl;
}
  

Measured memory_bytes: 256
//コンパイラ最適化用
#pragma GCC optimize("O3")
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set
//.lower_boundはO(√n)
signed main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    ll n;cin>>n;
    vector<ll> p(n);vector<ll> p_num(n);
    REP(i,n){cin>>p[i];p[i]--;p_num[p[i]]=i;}
    //番兵を入れておくと良い
    //p[i]よりも大きい数のインデックスを保存しておく
    set<ll> s;
    s.insert(-2);s.insert(-1);
    s.insert(n);s.insert(n+1);
    ll ans=0;
    //大きい数から処理
    REPD(i,n){
        //pでのインデックス
        ll j=p_num[i];
        ll l1,l2,r1,r2;
        r1=*(s.upper_bound(j));
        r2=*(++s.upper_bound(j));
        l1=*(--s.lower_bound(j));
        l2=*(--(--s.lower_bound(j)));
        //cout<<l2<<" "<<l1<<" "<<r1<<" "<<r2<<endl;
        if(l1>-1)ans+=((i+1)*(l1-l2)*(r1-j));
        if(r1<n)ans+=((i+1)*(r2-r1)*(j-l1));
        s.insert(j);
    }
    cout<<ans<<endl;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int h, n;
    cin >> h >> n;
    int sum = 0;
    int a;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        sum += a;
    }
    if (sum >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<queue>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#define all(c) c.begin(),c.end()
#define pb push_back
#define INF 10000000
using namespace std;
typedef pair<int,int> P;
int w,h;
vector<string> s;
P d[10],q;
map<int,int> mp;
string op;
int dp[20][20];
bool in(P n){
	if(n.second>=0&&n.second<w&&n.first>=0&&n.first<h)
		return true;
	return false;
}
int ret(P b,int time){
	if(time>400)
		return INF;
	if(dp[b.first][b.second]<=time){
		q.first=b.first;q.second=b.second;
		return time;
	}
	P nb;
	nb.first=b.first+d[op[time%op.size()]-'0'].first;
	nb.second=b.second+d[op[time%op.size()]-'0'].second;
	if(!in(nb))
		nb=b;
	return ret(nb,time+1);
}
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
void bfs(P a){
	queue<P> que;
	que.push(a);
	dp[a.first][a.second]=0;
	while(!que.empty()){
		P t=que.front(),nt;
		que.pop();
		for(int i=0;i<4;i++){
			nt.first=t.first+dy[i];
			nt.second=t.second+dx[i];
			if(in(nt)&&dp[nt.first][nt.second]==INF&&s[nt.first][nt.second]!='#'){
				que.push(nt);
				dp[nt.first][nt.second]=dp[t.first][t.second]+1;
			}
		}
	}
}
int main(){
	d[5]=P(0,0);d[8]=P(-1,0);d[6]=P(0,1);d[4]=P(0,-1);d[2]=P(1,0);
	mp[0]=5;mp[1]=8;mp[2]=6;mp[3]=4;mp[4]=2;
	while(cin>>h>>w,h||w){
		s.clear();
		P a,b;
		for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
		dp[i][j]=INF;
		for(int i=0;i<h;i++){
			string t;
			cin>>t;
			s.pb(t);
			for(int j=0;j<t.size();j++){
				if(t[j]=='A'){
					a.first=i;a.second=j;
				}else if(t[j]=='B'){
					b.first=i;b.second=j;
				}
			}
		}
		cin>>op;
		bfs(a);
		int ans=ret(b,0);
		(ans==INF)?cout<<"impossible"<<endl:cout<<ans<<" "<<q.first<<" "<<q.second<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		string s = cin.next();
		int pnum = s.Length / 2;
		int gnum = s.Length - pnum;
		int ans = 0;
		for (int i = s.Length - 1; i >= 0; i--)
		{
			if (s[i] == 'g')
			{
				if (pnum > 0)
				{
					pnum--;
					ans++;
				}
				else
				{
					gnum--;
				}
			}
			else
			{
				if (gnum > 0 || gnum == pnum)
				{
					gnum--;
					ans--;
				}
				else
				{
					pnum--;
					ans++;
				}
			}
		}
		Console.WriteLine(ans);
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 3416
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  auto f = [](int n) { return n & 1 ? 3 * n + 1 : n / 2; };
  const int N = 1123456;
  int a[N];
  cin >> a[1];
  bool used[N];
  fill(used, used + N, false);
  used[a[1]] = true;
  for (int i = 2; i < N; i++) {
    a[i] = f(a[i - 1]);
    if (used[a[i]]) {
      cout << i << '\n';
      break;
    }
    used[a[i]] = true;
  }
  return 0;
}


Measured memory_bytes: 4688
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    private long fac[];
    private long finv[];
    private long inv[];
    private static int MAX_LEN = 710000;
    private static int MOD = 1000000007;
    void COMinit() {
        this.fac = new long[MAX_LEN];
        this.finv = new long[MAX_LEN];
        this.inv = new long[MAX_LEN];
        this.fac[0] = this.fac[1] = 1;
        this.finv[0] = this.finv[1] = 1;
        this.inv[1] = 1;
        for (int i = 2; i < MAX_LEN; 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;
        }
    }
    long COM(int n, int k) {
        if (n < k) {
            return 0;
        };
        if (n <0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k]%MOD)%MOD;
    }
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        this.COMinit();
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int X = scan.nextInt();
        int Y = scan.nextInt();
        if ((X + Y) % 3 != 0) {
            System.out.println(0);
            return;
        }
        int R = Math.min(X, Y);
        int C = Math.max(X, Y);
        int count = (R + C) / 3;
        long ans = 0;
        for (int i = 0; i <= count; i++) {
            if (i * 1 + (count - i) * 2 == R && (i * 2 + (count - i) * 1 == C)) {
                ans += COM(count, i);
            }
        }
        System.out.println(ans);
    }
}


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

int check_good(int N){
  int x, left = 10;
  int flag = 0;
  
  for(int i = 0;i < 4; i++){
    x = N % 10;
    N = N / 10;
    
    if(x == left){
      flag++;
      if(flag == 2){
        cout << "Yes" << endl;
        return 0;
      }
    }else{
      flag = 0;
    }
    left = x;
  }
  cout << "No" << endl;
  return 0;
}
    
int main(){
  int N;
  cin >> N;
  
  check_good(N);
  return 0;
}

Measured memory_bytes: 384
import itertools

N, x = [int(y) for y in input().split(' ')]
arr = sorted([int(y) for y in input().split(' ')], reverse=False)
cumsum = list(itertools.accumulate(arr))

ret = 0
p = True

for csum in cumsum:
  if csum > x:
    print(ret)
    p = False
    break
    
  ret += 1

if p: 
  print(ret) if cumsum[len(cumsum) - 1] == x else print(ret - 1)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d)
    cout<<"Left"<<endl;
  else if(a+b==c+d)
    cout<<"Balanced"<<endl;
  else
    cout<<"Right"<<endl;
  return 0;
}


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

#define SORT(v) sort(v.begin(),v.end())
#define si(n) scanf("%d",&n)
#define sii(n,m) scanf("%d %d",&n,&m)
#define sl(n) scanf("%lld",&n)
#define sll(n,m) scanf("%lld %lld",&n,&m)
#define ss(cad) scanf("%s",cad)
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl; 
#define M 1000000007
#define N_MAX 100010

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vp;

char cad[5000];
int dp[5000][3];

char op(char a, char b)
{
	string s = "RGB";
	s.erase(s.find(a), 1);
	s.erase(s.find(b), 1);
	return s[0];
}

int main()
{
	int n;
	si(n);
	ss(cad);
	ll ans = 0;
	for(int i = 0;  i < n; i++)
	{
		if(cad[i] == 'R')
			dp[i][0]++;

		if(cad[i] == 'G')
			dp[i][1]++;

		if(cad[i] == 'B')
			dp[i][2]++;

		if(i == 0)
			continue;
		dp[i][0] += dp[i-1][0];
		dp[i][1] += dp[i-1][1];
		dp[i][2] += dp[i-1][2];
	}

	for(int i = 0; i < n; i++)
	{
		for(int j = i+2; j < n; j++)
		{
			if(cad[i] != cad[j])
			{
				char c = op(cad[i], cad[j]);
				if(c == 'R')
					ans += dp[j][0] - dp[i][0];
				else if(c == 'G')
					ans += dp[j][1] - dp[i][1];
				else
					ans += dp[j][2] - dp[i][2];
				int med = (j - i + 1)/2;
				if(cad[med+i] == c && (j - i + 1)%2 == 1)
					ans--;
			}
		}
	}

	printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3804
#include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<stdlib.h>
#include<algorithm>
#include<functional>

using namespace std;

#define OUT cout <<
#define IN cin >>
#define E << endl;
#define FOR(i,a,b) for(int i = a;i < b;i++)

char c[10];
int array1[10];
int array2[10];

void input(){
	FOR(i, 0, 10){
		array1[i] = c[i] - '0';
	}
}

int main(){
	while(IN c){
		input();
		for(int i = 9; i >= 0; i--){
			for(int j = 0; j <  i; j++){
				array2[j] = (array1[j] + array1[j + 1]) % 10;
	     	}
			for(int j = 0; j <  i; j++){
				array1[j] = array2[j];
			}
		}	
		OUT array1[0] E
	}

}

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

#define FOR(s, i, n) for(int i = s; i n; i++)
typedef long long ll;
const int INF = 1e9;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	char c;
	cin>>c;
	if ('a' <= c){
		cout<<"a\n";
	}else{
		cout<<"A\n";
	}
	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t K,A,B;
  cin>>K>>A>>B;
  if(B-A<=1 || K<=A)
    cout<<K+1<<endl;
  else{
  if((K-A+1)%2==0){
  int64_t ans=A+(B-A)*(K-A+1)/2;
    cout<<ans<<endl;
  
  }else{
  int64_t ans=1+A+(B-A)*((K-A+1)/2);
    cout<<ans<<endl;
  }
    
  
  }
  
   return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define fout(x) cout << fixed << setprecision(20) << x << endl
const int MOD = 1e9 + 7;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 1e-8;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, k;
  cin >> n >> m >> k;
  ll ans = 0;
  VL a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  VL sa(n + 1, 0), sb(m + 1, 0);
  rep(i, n) sa[i + 1] = sa[i] + a[i];
  rep(i, m) sb[i + 1] = sb[i] + b[i];
  rep(i, n) {
    ll atime = sa[i + 1];
    if(atime > k) break;
    else if(atime == k) {
      ans = max(ans, i + 1LL);
      continue;
    }
    else {
      ll it = upper_bound(all(sb), (k - atime)) - sb.begin();
      ans = max(ans, it - 1 + i + 1);
    }
  }
  ans = max(ans, (ll)(upper_bound(all(sb), k) - sb.begin() - 1LL));
  out(ans);

  return 0;
}


Measured memory_bytes: 9508
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1
if p[n-1] == n:
    p[n-1], p[n-2] = p[n-2], p[n-1]
    ans += 1
print(ans)

Measured memory_bytes: 14008
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (h,w) =get!(usize, usize);
    if h == 1 {
        println!("1");
    } else if w == 1 {
        println!("1");
    } else {
        println!("{}", (h*w+1)/2);
    }
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	if(a > b) swap(a, b);
	if((a+b)%2 == 0) {
		cout << (a+b)/2 << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		if(n % 2 == 0) {
			int ans = n/2 - 1;
			System.out.println(ans);
		}
		else {
			int ans = (n-1)/2;
			System.out.println(ans);
		}
	}

}


Measured memory_bytes: 22612
fn run() {
    proconio::input! {
        n: u64,
    }
    let mut ans = 0;
    for i in 1..=n {
        let p = n / i;
        ans += i * p * (p + 1) / 2;
    }
    println!("{}", ans);
}

fn main() {
    run();
}

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

int main() {
  long long MOD = 1000000007;
  int N; cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  long long ans = 0;
  for (int i = 0; i < 60; i++) {
    long long zero = 0;
    long long one = 0;
    for (int j = 0; j < N; j++) {
      bitset<60> s(A.at(j));
      if (s.test(i)) one++;
      else zero++;
    }
    long long tmp = one * zero % MOD;
    for (int k = 0; k < i; k++) tmp = tmp * 2 % MOD;
    ans = (ans + tmp) % MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    int a[n], left[n], right[n];
    long long ans = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    for(int i = 0; i <= min(n, k); i++)
    {
        for(int j = 0; j <= min(n, k) - i; j++)
        {
            int sub[n];
            long long total = 0;
            for(int l = 0; l < i; l++)
            {
                sub[l] = a[l];
                total += a[l];
            }
            for(int l = 0; l < j; l++)
            {
                sub[l + i] = a[n - l - 1];
                total += a[n - l - 1];
            }
            sort(sub, sub + i + j);
            for(int l = 0; l < min(i + j, k - i - j); l++)
            {
                if(sub[l] < 0)
                {
                    total -= sub[l];
                }
            }
            ans = max(ans, total);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628