akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    vector<int> even(100000 + 10, 0), odd(100000 + 10, 0);
    for (int i = 0; i < n; i += 2) {
        odd[v[i]]++;
    }
    for (int i = 1; i < n; i += 2) {
        even[v[i]]++;
    }
    class Max {
       public:
        int cntmax = -1;
        int cntsecond = -1;
        int nummax = -1;
        Max(int cm, int cs, int nm) {
            cntmax = cm;
            cntsecond = cs;
            nummax = nm;
        }
    };
    Max odds(odd[0], odd[1], 0), evens(even[0], even[1], 0);
    for (int i = 1; i < 100000 + 10; i++) {
        if (odds.cntmax < odd[i]) {
            odds.cntsecond = odds.cntmax;
            odds.cntmax = odd[i];
            odds.nummax = i;
        } else if (odds.cntsecond < odd[i]) {
            odds.cntsecond = odd[i];
        }
        if (evens.cntmax < even[i]) {
            evens.cntsecond = evens.cntmax;
            evens.cntmax = even[i];
            evens.nummax = i;
        } else if (evens.cntsecond < even[i]) {
            evens.cntsecond = even[i];
        }
    }
    int ans;
    if (odds.nummax == evens.nummax) {
        ans = n -
              max(odds.cntmax + evens.cntsecond, odds.cntsecond + evens.cntmax);
    } else {
        ans = n - odds.cntmax - evens.cntmax;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4524
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  if((abs(a - c) <= d) || (abs(a - b) <= d && abs(b - c) <= d))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
import collections

s=input()
l=len(s)
cnt=collections.defaultdict(int)
cnt[0]+=1
tmp=0
for i in range(l):
  tmp+=int(s[l-1-i])*pow(10,i,2019)
  tmp%=2019
  cnt[tmp]+=1
ans=0
for key in cnt.keys():
  ans+=(cnt[key]*(cnt[key]-1))//2
print(ans)

Measured memory_bytes: 69056
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>

using namespace std;

#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 ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
	int to;
	T cost;
	Edge() {};
	Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
	int n;
	bool directed;
	vector<vector<Edge<T>>> edges;
public:

	Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)) {};
	Graph() {};

	void add(int to, T cost) {
		emplace_back(to, cost);
	}

	int size() {
		return n;
	}
};


int main() {

	int A, B;

	cin >> A >> B;

	FOR(i, 1, 1010) {

		int a = i*0.08, b=i*0.1;
		if (a == A && b == B) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_A&lang=jp
sample_input = list(range(3))
sample_input[0] = '''5
1 2 3 4 5
3
3 4 1'''
sample_input[1] = '''3
3 1 2
1
5'''
sample_input[2] = '''500
0 933 743 262 529 700 508 752 256 256 119 711 351 843 705 108 393 330 366 169 932 917 847 972 868 980 223 549 592 164 169 551 427 190 624 635 920 944 310 862 484 363 301 710 236 876 431 929 397 675 491 190 344 134 425 629 30 727 126 743 334 104 760 749 620 256 932 572 613 490 509 119 405 695 49 327 719 497 824 596 649 356 184 93 245 7 306 509 754 352 665 783 738 801 690 330 337 195 656 963 11 427 42 106 968 212 1 510 480 658 571 331 814 847 564 197 625 438 931 18 487 151 187 913 179 995 750 750 913 562 134 273 547 521 830 140 557 678 726 503 597 408 893 988 238 85 93 188 720 211 746 387 710 209 887 668 103 473 900 674 105 183 952 370 787 302 410 905 110 400 996 142 585 860 47 924 731 158 386 219 400 415 55 682 874 61 6 602 268 365 470 518 723 89 106 319 130 655 732 993 974 595 810 673 55 730 95 245 705 694 948 873 353 474 760 741 756 644 143 640 737 679 135 149 529 210 607 417 255 787 373 626 445 112 172 595 153 53 183 717 655 17 176 77 776 399 654 728 2 161 455 870 316 694 381 930 480 604 386 359 207 954 79 702 365 453 732 836 432 563 17 107 583 910 467 116 546 719 528 71 107 256 520 353 528 154 430 477 48 520 204 414 810 719 925 298 131 701 709 751 22 817 652 924 695 471 153 625 978 616 142 597 88 732 917 404 743 395 749 407 936 302 767 45 563 340 398 896 51 807 767 997 978 650 809 330 360 716 161 293 209 753 98 130 634 543 889 88 31 692 401 674 294 693 165 949 765 737 458 841 48 943 229 215 389 209 388 754 243 501 271 516 564 277 912 5 611 212 782 92 123 201 324 4 437 602 804 363 391 273 575 906 759 626 896 859 763 358 577 484 747 156 948 605 454 194 359 430 323 883 24 447 202 847 876 49 792 588 304 133 558 842 414 567 728 506 391 0 992 118 398 718 868 975 579 119 363 596 379 916 466 840 232 430 414 155 571 311 179 796 300 216 903 993 55 728 481 905 29 37 897 286 657 377 682 554 506 757 529 580 641 866 852 933 660 490 616 732 606 114 185 647 227 435 58 183 110 742 374 604 671 872 605 480 671 979 717 481 680 791
30
0 9 18 30 31 42 48 49 59 74 85 115 121 153 165 168 181 195 205 207 220 228 248 252 255 270 274 289 291 300'''
give_sample_input = None
if give_sample_input is not None:
    sample_input_list = sample_input[give_sample_input].split('\n')
    def input():
        return sample_input_list.pop(0)
        
# main
num_of_S = int(input())
S = list(map(int, input().split(' ')))
num_of_T = int(input())
T = list(map(int, input().split(' ')))

count = 0
for s in S:
    for i in range(len(T)):
        if s == T[i]:
            count += 1
            T[i] = -1
            break

print(count)

Measured memory_bytes: 8500
#include <stdio.h>

int main(void){
	int n, m, l, i, j, k;
	int A[100][100] = { 0 }, B[100][100] = { 0 };
	long long int C[100][100] = { 0 };

	scanf("%d %d %d", &n, &m, &l);
	for (i = 0; i < n; i++){
		for (j = 0; j < m; j++){
			scanf("%d", &A[i][j]);
		}
	}
	for (i = 0; i < m; i++){
		for (j = 0; j < l; j++){
			scanf("%d", &B[i][j]);
		}
	}
	for (i = 0; i < n; i++){
		for (j = 0; j < l; j++){
			for (k = 0; k < m; k++){
				C[i][j] += A[i][k] * B[k][j];
			}
		}
	}
	for (i = 0; i < n; i++){
		for (j = 0; j < l; j++){
			printf("%lld", C[i][j]);
			if (j < l - 1){
				printf(" ");
			}else{
				printf("\n");
			}
		}
	}
	return 0;
}

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

V = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    X = 0
    Y = 0
    for j in range(N):
        if ((i >> j) & 1):
            X += V[j]
            Y += C[j]
    ans = max(ans, X-Y)

print(ans)
    


Measured memory_bytes: 42092
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

bool check(bool, bool, bool, char);

int main(){
  /*
  ifstream fin("07.txt");
  if(!fin){
    cout << "file not found" << endl;
    return 0;
  }
  */

  int n; cin >> n;
  string s; cin >> s;

  bool animals[n]; //true:S, false:W

  bool flag = false;
  for(int i=0; i<4; i++){
    animals[0] = (i>>1)&1;
    animals[1] = i&1;

    for(int j=2; j<n; j++){
      if(s[j-1]=='o'){
        if(animals[j-1]){
          animals[j] = animals[j-2];
        }
        else{
          animals[j] = !animals[j-2];
        }
      }
      else if(s[j-1]=='x'){
        if(animals[j-1]){
          animals[j] = !animals[j-2];
        }
        else{
          animals[j] = animals[j-2];
        }
      }
    }

    //チェック
    bool ch=check(animals[n-2], animals[n-1], animals[0], s[n-1])
              && check(animals[n-1], animals[0], animals[1], s[0]);

    if(ch){
      flag = true;
      break;
    }
  }

  if(flag){
    for(int i=0; i<n; i++){
      if(animals[i]) cout << "S";
      else if(!animals[i]) cout << "W";
    }
    cout << endl;
  }
  else{
    cout << -1 << endl;
  }

  return 0;
}

bool check(bool before, bool now, bool next, char c){
  if(c=='o'){
    if(now) return before==next;
    else return before!=next;
  }
  else{
    if(now) return before!=next;
    else return before==next;
  }
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>

typedef long long ll;
using namespace std;


string s;

int main() {
    
    cin >> s;
    
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'C') {
            for (int j = i; j < s.length(); j++) {
                if (s[j] == 'F') {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
    
    
    return 0;
}





Measured memory_bytes: 256
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

s = input()
s = s.replace("P?",'PD')
s = s.replace("?",'D')
print(s)

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int n,a[100002],sum[100002],ans;

main() {
    cin >> n;
    a[n+1] = 0;
    rep1(i,n) {
        cin >> a[i];
        if ((a[i] >= 0 && a[i-1] >= 0) || (a[i] < 0 && a[i-1] < 0)) sum[i] = abs(a[i-1]-a[i])+sum[i-1];
        else sum[i] = abs(a[i] - a[i-1])+sum[i-1];
    }
    sum[n+1] = ans = abs(a[n])+sum[n];
    rep1(i,n) {
        if( (a[i-1] <= a[i] && a[i] <= a[i+1]) || (a[i-1] >= a[i] && a[i] >= a[i+1]) ) ct(ans)
        else {
            int k,r;
            if ((a[i+1] >= 0 && a[i-1] >= 0) || (a[i+1] < 0 && a[i-1] < 0)) k = abs(a[i-1]-a[i+1]);
            else k = abs(a[i+1] - a[i-1]);
            r = abs(sum[i+1] - sum[i-1]);
            ct(ans-(r-k))
        }
    }
}

Measured memory_bytes: 2816
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int POW(int a,int n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  int X,i,p,flag=0,ans=0;
  scanf("%d",&X);
  if(X==2)ans=2;
  while(ans==0){
    flag=0;
    p=(int)sqrt(X)+2;
    FOR(i,2,p)if(X%i==0){
      flag=1;
      break;
    }
    if(flag==0)ans=X;
    X++;
  }

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


Measured memory_bytes: 128
import numpy
s = list(map(int, input().split()))
n=s[0]
s = list(map(int, input().split()))
for i in range(n):
    s[i]=s[i]-i-1
s=numpy.array(s)
i=numpy.median(s)
a=numpy.sum(numpy.abs(s-i))
print(int(a))

Measured memory_bytes: 34180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ll n, k;
	vector<pair<int, int>> v;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		v.push_back(make_pair(a, b));
	}
	sort(v.begin(), v.end(), [](auto &a, auto & b) { 
		return a.first < b.first;
	});
	ll count = 0;
	for (auto i : v) {
		count += i.second;
		if (count >= k) {
			cout << i.first << endl;
			return 0;
		}
	}
	return 0;
}

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

int translate(char c);

int main()
{
    int n, initial[6]{};
    long long ans{};

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        char name[16];
        scanf("%s", name);
        initial[translate(name[0])]++;
    }

    for (int i = 0; i < 5; i++)
    {
        if (!initial[i]) continue;
        for (int j = i + 1; j < 5; j++)
        {
            if (!initial[j]) continue;
            for (int k = j + 1; k < 5; k++)
            {
                ans += (long long)initial[i] * initial[j] * initial[k];
            }
        }
    }

    printf("%lld\n", ans);

    return 0;
}

int translate(char c)
{
    char str[] = "MARCH";
    for (int i = 0; i < 5; i++)
        if (str[i] == c) return i;
    return 5;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N;
ll a[200010], b[200010];

/*==================================================*/
/*function*/

//最終的なxorにおいて, 下からd桁目が 1 かどうか判定
bool check(int d){
    ll t = (1 << d);

    //下d桁目までのみが必要
    ll aa[200010], bb[200010];
    REP(i,0,N){
        aa[i]  = a[i] % (2*t);
        bb[i]  = b[i] % (2*t);
    }

    //繰り上がりの条件分岐のために分類
    vector<ll> sb[2];
    REP(i,0,N){
        //if(bb[i] & t) sb[1].push_back(bb[i] - t);
        //if(bb[i] & t) sb[1].push_back(bb[i] % t);
        if(bb[i] & t) sb[1].push_back(bb[i] & ~t);
        else sb[0].push_back(bb[i]);
    }

    sort(sb[0].begin(), sb[0].end());
    sort(sb[1].begin(), sb[1].end());

    ll cnt = 0;

    REP(i,0,N){
        ll ta = aa[i];

        //a'=a[i]%2^(d+1),b'=b[i]%2^(d+1)

        //a',b'それぞれ(2^d)引いてのしきい値t(2^d)との大小比較
        //=> d桁目のビットの1/0をチェック (d桁目について, 繰り上がって1になるか or もとの1が残るか)

        if(ta & t){
            //(d-1)桁目からの繰り上がりについてのみ考えたい(２分探索を使いやすく) => tの余りをとる(or tを引く(前提:t以上) or bitを折る)操作 => d桁目の1を0にする
            //ta -= t;
            //ta %= t;
            ta &= ~t;

            //(d-1)桁目からの繰り上がりがなくa'のd桁目の1が残る (逆に繰り上がりがあるとd桁目が0になる)
            //((a'-(2^d))+(b'-(2^d))) < (2^d)
            cnt += lower_bound(sb[0].begin(), sb[0].end(), t - ta) - sb[0].begin(); //しきい値を超えない値(=未満)が欲しいのでこのまま

            //a'とb'の各d桁目の1で繰り上がるため,(d-1)桁目からの繰り上がりが必要
            //((a'-(2^d))+(b'-(2^d))) >= (2^d)
            cnt +=  sb[1].size()
                    - (lower_bound(sb[1].begin(), sb[1].end(), t - ta) - sb[1].begin()); //しきい値以上がほしいので"未満"のサイズとの差分
        }else{
            //a'とb'のどちらのd桁目にも0がないため,(d-1)桁目からの繰り上がりが必要
            //((a'-(2^d))+(b'-(2^d))) >= (2^d)
            cnt += sb[0].size()
                   -  (lower_bound(sb[0].begin(), sb[0].end(), t - ta) - sb[0].begin());

            //(d-1)桁目からの繰り上がりがなくb'のd桁目の1が残る (逆に繰り上がりがあるとd桁目が0になる)
            //((a'-(2^d))+(b'-(2^d))) < (2^d)
            cnt += lower_bound(sb[1].begin(), sb[1].end(), t - ta) - sb[1].begin();
        }
    }

    return cnt % 2 == 1;
}

/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,N) cin>>a[i];
    REP(i,0,N) cin>>b[i];

    ll ans = 0;
    REP(d,0,29){
        if(check(d)) ans += (1 << d);
    }

    cout<<ans<<endl;

    return 0;
}


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

int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	int sum = 0;
	sum += x * min(k, n);
	if( k < n ) {
		sum += y * (n-k);
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007;
#define inf (1LL<<60)
using namespace std;


ll solve(ll h[],ll b[],int n)
{
    ll dp[n];
    map<ll,ll> m;
    dp[0]=b[0];
    m[h[0]]=dp[0];
    ll ans=dp[0];
    for(int i=1;i<n;i++)
    {
        dp[i]=b[i];
        auto it=m.lower_bound(h[i]+1);
        if(it!=m.begin())
        {
            it--;
            dp[i]+=it->second;
        }
        m[h[i]]=dp[i];
        it=m.upper_bound(h[i]);
        while(it!=m.end()&&it->second<=dp[i])
        {
            auto temp =it;
            temp++;
            m.erase(it);
            it=temp;
        }
        ans=max(ans,dp[i]);
    }
    return ans;
}
int main()
{
    int n;
    cin>>n;
    ll h[n],b[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    cout<<solve(h,b,n);
    return 0;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
char a[100001];
int b[100001],n;
int f(int s1,int s2)
{
    b[1]=s1;
    b[2]=s2;
    for (int i=3;i<=n;++i)
        if (a[i-1]=='o')
        {
            if (b[i-1]==1) b[i]=b[i-2]^1;
            if (b[i-1]==0) b[i]=b[i-2];
        }
        else if (a[i-1]=='x')
        {
            if (b[i-1]==0) b[i]=b[i-2]^1;
            if (b[i-1]==1) b[i]=b[i-2];
        }
    if (b[1]==b[n-1] && b[n]==b[2])
    {
        if (b[n]==0 && a[n]=='o' && b[1]==0 && a[1]=='o') return 1;
        else if (b[n]==1 && a[n]=='x' && b[1]==0 && a[1]=='o') return 1;
        else if (b[n]==1 && a[n]=='x' && b[1]==1 && a[1]=='x') return 1;
        else if (b[n]==0 && a[n]=='o' && b[1]==1 && a[1]=='x') return 1;
    }
    else if (b[1]!=b[n-1] && b[n]==b[2])
    {
        if (b[n]==0 && a[n]=='x' && b[1]==0 && a[1]=='o') return 1;
        else if (b[n]==1 && a[n]=='o' && b[1]==1 && a[1]=='x') return 1;
        else if (b[n]==0 && a[n]=='x' && b[1]==1 && a[1]=='x') return 1;
        else if (b[n]==1 && a[n]=='o' && b[1]==0 && a[1]=='o') return 1;
    }
    else if (b[1]==b[n-1] && b[n]!=b[2])
    {
        if (b[n]==0 && a[n]=='o' && b[1]==0 && a[1]=='x') return 1;
        else if (b[n]==1 && a[n]=='x' && b[1]==1 && a[1]=='o') return 1;
        else if (b[n]==0 && a[n]=='o' && b[1]==1 && a[1]=='o') return 1;
        else if (b[n]==1 && a[n]=='x' && b[1]==0 && a[1]=='x') return 1;
    }
    else if (b[1]!=b[n-1] && b[n]!=b[2])
    {
        if (b[n]==0 && a[n]=='x' && b[1]==0 && a[1]=='x') return 1;
        else if (b[n]==1 && a[n]=='o' && b[1]==1 && a[1]=='o') return 1;
        else if (b[n]==0 && a[n]=='x' && b[1]==1 && a[1]=='o') return 1;
        else if (b[n]==1 && a[n]=='o' && b[1]==0 && a[1]=='x') return 1;
    }
    return 0;
}
int main()
{
    cin>>n;
    for (int i=1;i<=n;++i) cin>>a[i];
    for (int i=0;i<=1;++i)
        for (int j=0;j<=1;++j)
            if (f(i,j))
            {
                for (int u=1;u<=n;++u)
                    if (b[u]==1) cout<<"W";
                    else cout<<"S";
                return 0;
            }
    cout<<"-1";
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

int main() {
    double a, b, c;
    double ans;
    cin >> a >> b >> c;

    // area
    printf("%f\n", a * b * sin(c * M_PI / 180.) / 2.0);

    // perimeter
    printf("%f\n", a + b + sqrt(pow(a, 2) + pow(b, 2) - a * b * 2.0 * cos(c * M_PI / 180.)));

    // height
    printf("%f\n", b * sin(c * M_PI / 180.));
}


Measured memory_bytes: 3496
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
using namespace std;

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<int>> vvint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(int i=0;i<n;i++)
#define repf(i,f,n) for(int i=f;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())



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


int main() {


  int N;
  cin >> N;
  string s;
  cin >> s;


  int r,b;
  r=0;b=0;

  rep(i,s.size()){
    if(s[i]=='R') r++;
    else b++;
  }

  if(r>b) cout << "Yes" << endl;
  else cout << "No" << endl;

}

















//


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
	}
	sort(a,a+n);
	int l=a[0],r=a[n-2];
	int aim=a[n-1]/2;//+(a[n-1]%2==0?0:1);
	int now;
	int dis=0x3f3f3f3f;
	for(int i=0;i<n-1;i++)
	{
		if(abs(a[i]-aim)<=dis)
		{
			dis=abs(a[i]-aim);
			now=a[i];
		}
	}
	cout << a[n-1] <<' ' << now;
	
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion
n, q = map(int, input().split())
 
tree_index = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  tree_index[a].append(b) # a<bとは限らないため、双方向にする
  tree_index[b].append(a)
ans = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
def dfs(cur, par):
    for chl in tree_index[cur]:
      if chl == par: #parentとchildが等しい時はとばす
        continue
      ans[chl] += ans[cur] 
      dfs(chl, cur)
dfs(0, -1)
print(*ans)

Measured memory_bytes: 230960
#include<iostream>
using namespace std;
int N;
long A[1<<17],B[1<<17],ans;
main()
{
	cin>>N;
	for(int i=0;i<=N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	for(int i=0;i<N;i++)
	{
		long t=A[i]<B[i]?A[i]:B[i];
		ans+=t;
		B[i]-=t;
		t=A[i+1]<B[i]?A[i+1]:B[i];
		A[i+1]-=t;
		ans+=t;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1920
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

l = Counter(A)
ans = sum([v*(v-1)//2 for v in l.values()])

for a in A:
    print(ans - l[a]*(l[a]-1)//2 + (l[a]-1)*(l[a]-2)//2)

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

int n, cnt;
set<string> rate;

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (1 <= x && x <= 399) rate.insert("gray");
        else if (400 <= x && x <= 799) rate.insert("brown");
        else if (800 <= x && x <= 1199) rate.insert("green");
        else if (1200 <= x && x <= 1599) rate.insert("lblue");
        else if (1600 <= x && x <= 1999) rate.insert("blue");
        else if (2000 <= x && x <= 2399) rate.insert("yellow");
        else if (2400 <= x && x <= 2799) rate.insert("orange");
        else if (2800 <= x && x <= 3199) rate.insert("red");
        else if (3200 <= x) cnt++;
    }
    int min = (int)rate.size();
    int max = min + cnt;
    if (min == 0) {
        min = 1;
    }
    cout << min << " " << max << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())

    N, M = min(N, M), max(N, M)
    if N == M == 1:
        ans = 1
    elif N == 1:
        ans = M - 2
    elif N == 2:
        ans = 0
    else:
        ans = N * M - 2 * (N - 2) - 2 * (M - 2) - 4

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import itertools
N = int(input())
N_List = [list(map(int,input().split())) for _ in range(N)]
ans = 0
cnt = 0
for Sort_List in itertools.permutations(N_List, N):
    cnt += 1
    cans = 0
    for v in range(1,N):
        cans += ((Sort_List[v][0] - Sort_List[v-1][0])**2 + (Sort_List[v][1] - Sort_List[v-1][1])**2)**0.5
    ans += cans

print(ans/cnt)

Measured memory_bytes: 9396
// https://atcoder.jp/contests/abl/submissions/17034149
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace atcoder;
using namespace std;

const int SZ = 300005;
int mx(int a, int b) { return max(a, b); }
int e() { return 0; }

void solve() {
    int n, k;
    cin >> n >> k;
    // 1点更新、区間最大値を求めるセグ木を用いる。
    auto st = segtree<int, mx, e>(SZ);
    while (n--) {
        int x;
        cin >> x;
        // 過去に存在した x±k の座標に対する点の数の最大値を求める
        int me = st.prod(max(0, x - k), min(SZ, x + k + 1));
        // 現在のx座標に対して上記+1をセット
        st.set(x, me + 1);
    }
    cout << st.all_prod() << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}

Measured memory_bytes: 8484
package main

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

type IntList []int

func (a IntList) ChMax(i int, value int) bool {
	curV := a[i]
	if curV < value {
		a[i] = value
		return true
	}
	return false
}
func lib_MaxInt(values ...int) (max int, err error) {
	if len(values) == 0 {
		return 0, errors.New("empty slice is given")
	}
	max = values[0]
	for _, value := range values {
		if max < value {
			max = value
		}
	}
	return
}
func lib_MustMaxInt(values ...int) (max int) {
	max, err := lib_MaxInt(values...)
	if err != nil {
		panic(err)
	}
	return max
}
func lib_NewIntList(length int, initialValue int) IntList {
	ret := make([]int, length, length)
	for i := 0; i < length; i++ {
		ret[i] = initialValue
	}
	return ret
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int
	scanner.Scan()
	N, _ = strconv.Atoi(scanner.Text())
	var M int
	scanner.Scan()
	M, _ = strconv.Atoi(scanner.Text())
	x := make([]int, M)
	y := make([]int, M)
	for i := 0; i < M; i++ {
		scanner.Scan()
		x[i], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		y[i], _ = strconv.Atoi(scanner.Text())
	}
	fmt.Println(solve(N, M, x, y))
}
func rec(dp IntList, neighbors [][]int, n int) int {
	if dp[n] != -1 {
		return dp[n]
	}
	dp[n] = 0
	for _, neighbor := range neighbors[n] {
		dp.ChMax(n, rec(dp, neighbors, neighbor)+1)
	}
	return dp[n]
}
func solve(N int, M int, x []int, y []int) int {
	neighbors := make([][]int, N+5, N+5)
	dp := lib_NewIntList(N+5, -1)
	for i := 0; i < M; i++ {
		curX, curY := x[i], y[i]
		neighbors[curX] = append(neighbors[curX], curY)
	}
	ret := 0
	for i := 1; i <= N; i++ {
		ret = lib_MustMaxInt(ret, rec(dp, neighbors, i))
	}
	return ret
}


Measured memory_bytes: 22912
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		string s = Console.ReadLine();
    int[] alphabetUses = new int[26];
		long answer = 1;
    long mod = 1000000007;

    for(int i = 0; i < n; i++)
    {
      alphabetUses[s[i]-'a']++;
    }

    for(int i = 0; i < 26; i++)
    {
      if(alphabetUses[i] >= 1)
      {
        answer *= alphabetUses[i]+1;
        answer %= mod;
      }
    }

    answer += mod;
    answer--;
    answer %= mod;

		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 13116
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

vector<int> ham;

void makeHamList(){
	for(int i = 0; i <= 21; i++){
		for(int j = 0; j <=11; j++){
			for(int k = 0; k <= 9; k++){
				int sum=(int)pow(2.0,i)*(int)pow(3.0,j)*(int)pow(5.0,k);
				if(sum<=1000000)
					ham.push_back(sum);
			}
		}
	}
}

int main(){

	int m,n;
	makeHamList();
	while(cin>>m&&m!=0){
		cin>>n;
		int cnt=0;
		for(int i = 0; i < ham.size(); i++){
			if(ham[i]>=m&&ham[i]<=n)
				cnt++;
		}
		cout<<cnt<<endl;
	}

	return 0;
}

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

#define rep(i, a, b) for (int i = (a); i < (b); i++)

int main()
{
  int k;
  cin >> k;

  if (k % 2 == 0 or k % 5 == 0)
  {
    cout << -1 << endl;
    return 0;
  }

  int cur = 0, ans = 0;
  while (!ans or cur != 0)
  {
    cur = 10 * cur + 7;
    cur %= k;
    ans++;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define FOR(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define lli long long int
#define all(c) (c.begin(),c.end())
#define sz(c) c.size()
const int MOD = 1000000007;
const int MX = 2e5 + 5;
const lli INF = 1e18;


void solve() {
	string s;
	cin >> s;
	lli ans = 0, temp = 0;
	for (char x : s) {
		if (x == 'R')temp++;
		else temp = 0;
		ans = max(ans, temp);
	}
	cout << ans << endl;
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--) {
	solve();
	// }



	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define DEBUG(x) cerr << #x << " " << x << endl
using namespace std;
 
int magic(int A) {
  for(int k = 0; ; ++k) {
    if(A <= k * (k + 1) / 2) return k;
  }
  return -1;
}
 
string paren(int a, int n) {
  // DEBUG(a);
  // DEBUG(n);
  if(a == n * (n + 1) / 2) {
    string ret;
    REP(i,n) ret += ")";
    REP(i,n) ret += "(";
    return ret;
  }
  else {
    int rem = a - n;
    int k = magic(rem);
    string ret = ")";
    for(int i = 0; i < n - 1 - k; ++i) ret += "()";
    ret += paren(rem, k);
    ret += "(";
    return ret;
  }
}
 
signed main() {
  int A; cin >> A;
  int k = magic(A);
  cout << paren(A, k) << endl;
}

Measured memory_bytes: 9632
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int main(){
	int n;
	cin>>n;
	int cnt=1;
	for(int i=0;i<n;i++)cin>>a[i];
	int res=a[0];
	for(int j=0;j<n-1;j++){
		res=max(res,a[j+1]);
		if(a[j+1]>=res)cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

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

using namespace std;

int main(void){
    int n;

    cin >> n;

    vector<int> perm(n,0);

    for(int i=0; i<n; i++){
        perm[i] = i+1;
    }

    vector<int> p(n,0),q(n,0);

    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    for(int i=0; i<n; i++){
        cin >> q[i];
    }

    int p_i, q_i;

    int i=0;
    do{
        int p_cnt = 0;
        int q_cnt = 0;
        for(int i=0; i<n; i++){
            if(perm[i] == p[i]) p_cnt++;
        }
        if(p_cnt == n)
            p_i = i;
        for(int i=0; i<n; i++){
            if(perm[i] == q[i]) q_cnt++;
        }
        if(q_cnt == n)
            q_i = i;

        i++;
    } while( next_permutation(perm.begin(), perm.end()));

    cout << abs(p_i - q_i) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <iomanip>
#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>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int a, b;
    cin >> a >> b;
    int S = (a - 1) * (b - 1);
    cout << S << endl;
}


Measured memory_bytes: 256
data=[]
for i in range(3):
    data.append(list(map(int,input().split())))
if data[0][0]-data[1][0] == data[0][1]-data[1][1] == data[0][2]-data[1][2]:
    if data[1][0]-data[2][0] == data[1][1]-data[2][1] == data[1][2]-data[2][2]:
        if data[0][0]-data[0][1] == data[1][0]-data[1][1] == data[2][0]-data[2][1]:
            if data[0][1]-data[0][2] == data[1][1]-data[1][2] == data[2][1]-data[2][2]:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 62140
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC085C - Otoshidama
  // i+j+k=N
  // 10000i+5000j+1000k=Y
  // bについて解くとb=(Y-1000N-9000i)/4000
  // N<=2000なのでiにつき0〜Nで全探索
  // 余りがゼロになるもの
  // ただし、j又はk=N-i-jが負になるものは除く
  int N, Y, ans;
  cin >> N >> Y;
  REP(i, N+1){
    int j, k;
    j = (Y-1000*N-9000*i)/4000;
    k = N-i-(Y-1000*N-9000*i)/4000;
    if((Y-1000*N-9000*i) % 4000 == 0){
      if(j >= 0 && k >= 0){
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
def resolve():
    N = int(input())
    B = list(map(int, input().split()))
    A = [0] * N
    A[0] = B[0]
    A[N-1] = B[N-2]
    for i in range(1, N-1):
        A[i] = min(B[i-1], B[i])
    print(sum(A))

resolve()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
int main(){
  string s;cin >> s;
  int n=s.size();
  ll dp[n+1][4];
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<4;j++){
      if(s[i]=='?'){
        dp[i+1][j]+=dp[i][j]*3%mod;
        dp[i+1][j]%=mod;
      }
      else{
        dp[i+1][j]+=dp[i][j];
        dp[i+1][j]%=mod;
      }
    }
    if(s[i]=='A'||s[i]=='?'){
      dp[i+1][1]+=dp[i][0];
      dp[i+1][1]%=mod;
    }
    if(s[i]=='B'||s[i]=='?'){
      dp[i+1][2]+=dp[i][1];
      dp[i+1][2]%=mod;
    }
    if(s[i]=='C'||s[i]=='?'){
      dp[i+1][3]+=dp[i][2];
      dp[i+1][3]%=mod;
    }
  }
  cout << dp[n][3] << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int h,w;
    vector<vector<char>> p,r,b;
    Problem(LL h, LL w):h(h),w(w),p (h,vector<char>(w)), r (h,vector<char>(w,'.')), b (h,vector<char>(w,'.')){};

    void solve(){
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                if(i==0)r[i][j]='#';
                else if(i==h-1)b[i][j]='#';
                else if(j%2==0)r[i][j]='#';
                else b[i][j]='#';
                cin >> p[i][j];
                if(p[i][j]=='#')r[i][j]=b[i][j]='#';
            }
        }
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                cout << r[i][j];
            }
            cout <<"\n";
        }
        cout <<"\n";
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                cout << b[i][j];
            }
            cout <<"\n";
        }
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long h,w;
    cin >> h >> w;
    Problem p(h,w);
    p.solve();
    return 0;
}



Measured memory_bytes: 1536
def factorization(n):
    p=2
    fcr=[]
    while p*p<=n:
        while n%p==0:
            fcr.append(p)
            n//=p
        p+=1
    if n>1:
        fcr.append(n)
    return fcr

x=int(input())
while True:
 l=factorization(x)
 if len(l)==1:
  print(x)
  exit()
 else:
  x+=1

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>	
using namespace std;
int main() {
	long long m;
	cin >> m;
	for (long long i = sqrt(m + 1); i >= 1; i--) {
		if (m % i == 0) {
			cout << m / i - 1 + i - 1;
			return 0;
		}
	}

}

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

int main(void)
{
    string s;
    cin >> s;
    int k = s.length();
    int win = 0;
    for (int i = 0; i < k; i++) {
        if (s[i] == 'o') win++;
    }
    if (15 - k + win >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	long N = (long)Math.pow(10,18);
      	long[] num = new long[n];
      	long ans = 1;
      	boolean overF = false;
      	boolean zeroF = false;
		for(int i=0;i<n;i++){
			num[i] = sc.nextLong();
          	if( num[i] == 0 ){
              zeroF = true;
              break;
            }
        }
      if( !zeroF ){
     	for(int i=0;i<n;i++){
          	if( ans * num[i] > N || ( ( ans>100000000)&&(num[i]>1000000000) )  ){
              overF = true;
              break;
            }
          ans *= num[i];
        }
      }
      if( zeroF ){
        ans = 0;
      }else if( overF ){
        ans = -1;
      }else{
      
      }         
       System.out.println(ans); 
	}
}

Measured memory_bytes: 50412
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>

using namespace std;
#define   FOR(i,n) for(int i=0;i<n;i++)

typedef long long int lld;
typedef vector<lld> vi;
typedef vector<char> vc;

lld a,b,c,d,x,y,N;

//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());

int main() {
	int a,b,c,N;
	char tmp[100000];
	double ans=0;

	vector<double> A(1000000);

	cin>>N;
	FOR(i,N){
		cin>>A[i]>>tmp;
		if( tmp[0]=='B' ){
			A[i]*=380000.0;
			
		}
		ans+=A[i];
	}
	cout<<ans;

}







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

string getResult(const string &s){
  const size_t sSize = s.size();
  string result = "";
  for(int i = 0; i < sSize; i++){
    if(s[i] == 'B'){
      result.pop_back();
    }else{
      result.push_back(s[i]);
    }
  }
  return result;
}

int main(){
  string s;
  cin >> s;
  string result = getResult(s);
  cout << result << endl;
}

Measured memory_bytes: 3036
import math

def comb_count(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)

S = input()[::-1]
ans = 0

mods = [0] * 2019 #余りが0~2018
mods[0] = 1
current = 0
tmp = 1

for i in range(len(S)):
    current = (int(S[i]) * tmp + current) % 2019
    mod = current % 2019
    # ans += mods[mod]
    mods[mod] += 1
    tmp = tmp * 10 % 2019

for mod in mods:
    if mod > 1:
        # print(mod)
        ans += comb_count(mod, 2)

print(ans)


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

using namespace std;

int main()
{
   int a,b,ans;

    cin >> a >> b;

    if((a+b)%2 != 0){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    ans = (a+b)/2;
    cout << ans << endl;

   return 0;
}

Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

string s;
int p,q,r;
const int n[]={2,1,0};
int i;

int f(){
    int ret;
    if(s[i]=='P')ret=p;
    else if(s[i]=='Q')ret=q;
    else if(s[i]=='R')ret=r;
    else if(isdigit(s[i]))ret=s[i]-'0';
    else if(s[i]=='-'){
        i++;
        return n[f()];
    }
    else if(s[i]=='('){
        i++;
        ret=f();
        if(s[i]=='*')i++,ret=min(ret,f());
        else if(s[i]=='+')i++,ret=max(ret,f());
    }
    i++;
    return ret;
}

void run(){
    cin>>s;
    if(s==".")return;
    int ans=0;
    for(p=0;p<3;p++)for(q=0;q<3;q++)for(r=0;r<3;r++){
        i=0;
        int ret=f();
        if(ret==2)ans++;
    }
    cout<<ans<<endl;
    run();
}


Measured memory_bytes: 3232
class Main:
    n = int(input())
    num_list =[]
    count = 0
    for i in range(n):
        num_list.append(list(map(int,input().split())))

    for i in range(n-2):
        if num_list[i][0]==num_list[i][1] and num_list[i+1][0]==num_list[i+1][1] and num_list[i+2][0]==num_list[i+2][1]:
            count +=1

    if count >= 1:
        print('Yes')
    else :
        print('No')

Measured memory_bytes: 9164
#include<stdio.h>
int main(){
  int i,n;
  scanf("%d",&n);
  int a[n];
  int max=0,sec=0,tmp;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(max < a[i]){
      tmp = i;
      sec = max;
      max = a[i];
    }else{
      if(sec < a[i])
        sec = a[i];
    }
  }

  for(i=0;i<n;i++){
    if(i==tmp){
      printf("%d\n",sec);
      continue;
    }
    printf("%d\n",max);
  }
  return 0;
}

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

int main(){
    int n=5;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int k;
    cin>>k;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(k<a[j]-a[i]){
                cout<<":("<<endl;
                return 0;
            }
        }
    }
    cout<<"Yay!"<<endl;
    return 0;
}

Measured memory_bytes: 256
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int> > G;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};
string Psb[2] = {"Impossible", "Possible"};
string psb[2] = {"impossible", "possible"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, m;
    cin >> n;
    map<int, int> a, b;
    forn(i, n)
    {
        ll x;
        cin >> x;
        a[x]++;
    }
    cin >> m;
    forn(i, m)
    {
        ll x;
        cin >> x;
        b[x]++;
    }
    for (auto it : b)
    {
        if (a[it.first] < it.second) cout << "NO", exit(0);
    }
    cout << "YES";
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 19072
#include<bits/stdc++.h>
using namespace std;
#define MAXN	100005
struct edge {int dest, type; };
int nxt[2][3] = {{1, 2, 0}, {2, 0, 1}};
vector <edge> a[MAXN];
int n, m, type[MAXN];
bool visited[MAXN], illegal;
long long cnt[3], totedges;
void work(int pos) {
	totedges += a[pos].size();
	cnt[type[pos]]++;
	for (unsigned i = 0; i < a[pos].size(); i++)
		if (!visited[a[pos][i].dest]) {
			visited[a[pos][i].dest] = true;
			type[a[pos][i].dest] = nxt[a[pos][i].type][type[pos]];
			work(a[pos][i].dest);
		} else if (type[a[pos][i].dest] != nxt[a[pos][i].type][type[pos]]) illegal = true;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		a[x].push_back((edge) {y, 0});
		a[y].push_back((edge) {x, 1});
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (visited[i]) continue;
		memset(cnt, 0, sizeof(cnt));
		illegal = false;
		visited[i] = true;
		type[i] = 0;
		totedges = 0;
		work(i);
		if (illegal) ans += (cnt[0] + cnt[1] + cnt[2]) * (cnt[0] + cnt[1] + cnt[2]);
		else {
			if (cnt[0] && cnt[1] && cnt[2]) ans += cnt[0] * cnt[1] + cnt[1] * cnt[2] + cnt[2] * cnt[0];
			else ans += totedges / 2;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 10880
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		if(a<b&&b<c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		scanner.close();
	}

}


Measured memory_bytes: 26180
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;

int main() {
    int k, a, b;
    cin >> k >> a >> b;

    for(int i = a; i <= b; i++) {
        if(i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3636