akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <fstream>
#include <numeric>
#include <unordered_set>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define pii pair <int, int>
#define print(x) for(auto it : x) cout << it << ' ';
#define endl "\n" // TODO: remove
#define int long long

const int N = (1e6) + 322;
const int inf = (int)(2e9);
const int mod = (int)(1e9) + 7; // check modulo

void solve() {
    int n; cin >> n;
    cout << (1000 - (n % 1000))  % 1000;

}

signed main () {
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
//    int test; cin >> test;
//    for(int t = 1; t <= test; ++t) {
        solve();
//    }
    return 0;
}


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

int main() {

	int a, b, c;

	cin >> a >> b >> c;

	if (a == b&&b==c&&c==a) {
		cout << 1 << endl;
	}
	else if (b == c) {
		cout << 2 << endl;
	}
	else if (a == c) {
		cout << 2 << endl;
	}
	else if (a == b) {
		cout << 2 << endl;
	}
	else {
		cout << 3 << endl;
	}

	return 0;


}

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

using namespace std;
int main(){
    int a, p;
    cin >> a >> p;
    cout <<  (a*3 + p)/2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
#define ll long long
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bs binary_search
#define mp make_pair
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ld long double
#define meme(a,no)  memset(a,no,sizeof(a))
using namespace std; 

const int INF=1e9+7;

/*const int N=1000+5;

int x;

//const int mod=998244353;

//const int N=100000+9;

vector<vector<int>>v(N);

int vis[N]={0};

int level[N];*/

long long binpow(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b&1){
            res=res*a;
        }
        a=a*a;
        b>>=1;
    }
    return res;
}

long long binpow_mod(ll a,ll b,ll c){
    ll res=1;
    while(b>0){
        if(b&1){
            res=res*a%c;
        }
        a=a*a%c;
        b>>=1;
    }
    return res;
}

/*void dfs(int a){
    vis[a]=1;
    for(auto x:v[a]){
        if(!vis[x]){
            sz++;
            dfs(x);
        }
    }
}*/
vector<bool>v;
vector<int>isfactor;

void Seive(int n){
    v.assign(n+1,true);
    isfactor.assign(n+1,0);
    v[0]=false; v[1]=false;
    for(int i=2;i<=n;i++){
        if(v[i]){
            isfactor[i]=i;
            for(int j=i*i;j<=n;j+=i){
                if(v[j]){
                    v[j]=false;
                    isfactor[j]=i;
                }
            }
        }
    }
    
}

int32_t main(){
    ios
    int T;
    //cin>>T;
    T=1;
    while(T--){
        int n,w;
        cin>>n>>w;
        int wt[n+1],val[n+1];
        for(int i=1;i<=n;i++){
            cin>>wt[i]>>val[i];
        }
        int mat[n+1][w+1];
        meme(mat,0);
        int i,j;
        for(i=1;i<=n;i++){
            for(j=1;j<=w;j++){
                if(j>=wt[i]){
                    mat[i][j]=max(mat[i-1][j],mat[i-1][j-wt[i]]+val[i]);
                }
                else mat[i][j]=mat[i-1][j];
            }
        }
        cout<<mat[n][w]<<endl;
        
    }
    
    
}

Measured memory_bytes: 82440
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
ll INF = 1LL<<58;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A), t(B);
    REP(i, A){
        cin >> s[i];
    }
    REP(i, B){
        cin >> t[i];
    }
    s.push_back(INF);
    s.push_back(-INF);
    t.push_back(INF);
    t.push_back(-INF);
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    
    REP(i, Q){
        ll x;
        cin >> x;
        ll res = INF;
        
        REP(j, 2){
            ll first = (j ?
                        (upper_bound(s.begin(), s.end(), x) - s.begin() - 1) :
                        (lower_bound(s.begin(), s.end(), x) - s.begin()));
            first = s[first];
            REP(k, 2){
                ll second = (k ?
                             (upper_bound(t.begin(), t.end(), first) - t.begin() - 1) :
                             (lower_bound(t.begin(), t.end(), first) - t.begin()));
                second = t[second];
                res = min(res, abs(x-first) + abs(first - second));
            }
        }

        REP(j, 2){
            ll first = (j ?
                        (upper_bound(t.begin(), t.end(), x) - t.begin() - 1) :
                        (lower_bound(t.begin(), t.end(), x) - t.begin()));
            first = t[first];
            REP(k, 2){
                ll second = (k ?
                             (upper_bound(s.begin(), s.end(), first) - s.begin() - 1) :
                             (lower_bound(s.begin(), s.end(), first) - s.begin()));
                second = s[second];
                res = min(res, abs(x-first) + abs(first - second));
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 2912
#include<stdio.h>
char a[100010];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		scanf("%s",a);
		int total=0;
		for(int i=0;i<n;i++)
		{
			if(a[i]==a[i+1])
			continue;
			else
			total++;
        }
		printf("%d\n",total);
	}
}

Measured memory_bytes: 256
N = int(input())
count=0
A = 0
B = 0
BA = 0
for i in range(N):
  s = input()
  exist = 0
  if (s[0] == 'B') and (s[-1] == 'A'):
    BA +=1
  elif s[0] == 'B':
    B+=1
  elif s[-1:] == 'A':
    A+=1
  for j in range(len(s)-1):
    if s[j:j+2] == "AB":
      count+=1
#print(A,B,BA,count)

if BA > 1:
  count += BA - 1
if BA >0:
  if A > 0 :
    count +=1
    A-=1
  if B>0:
    count+=1
    B-=1
if A>B:
  count += B
else:
  count += A
print(count)
  

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
  while(true) {
    int n, m;
    cin >> n >> m;
    if(!n && !m) break;
    VVI rec;
    REP(i, m) {
      int a, b, c;
      cin >> a >> b >> c;
      rec.PB({a, b-1, c-1});
    }
    sort(ALL(rec));
    /*REP(i, m) {
      REP(j, 3) {
        cout << rec[i][j] << " ";
      }
      cout << endl;
    }*/
    bool g[20010] = {false};
    g[0] = true;
    REP(i, m) {
      if(g[rec[i][1]]) g[rec[i][2]] = true;
    }
    int ret = 0;
    REP(i, n) if(g[i]) ret++;
    cout << ret << endl;
  }

  return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    rep(i, H) cin >> s[i];
    vector<vector<int>> cnt(H, vector<int>(W)); // c[i][j] => (i, j)にライトを置いたときの上下左右の連結成分の個数

    rep(i, H) {
        // 横方向の連結成分をカウントする
        vector<bool> done(W);
        rep(j, W) {
            if (s[i][j] == '#') continue;
            if (done[j]) continue;
            int l = 0;
            while (j + l < W) { // 連結成分の終端までlをすすめる
                if (s[i][j + l] == '#') break;
                l++;
            }
            rep(k, l) {
                cnt[i][j + k] += l; // j ～ j+l-1までの連結成分にlを足す
                done[j + k] = true;
            }
        }
    }

    rep(j, W) {
        // 縦方向の連結成分をカウントする
        vector<int> done(H);
        rep(i, H) {
            if (s[i][j] == '#') continue;
            if (done[i]) continue;
            int l = 0;
            while (i + l < H) {
                if (s[i + l][j] == '#') break;
                ++l;
            }
            rep(k, l) {
                cnt[i + k][j] += l;
                done[i + k] = 1;
            }
        }
    }
    int ans = 0;
    rep(i, H)rep(j, W) ans = max(ans, cnt[i][j] - 1); // 上下 + 左右しているので中央が1個多く集計されているので1を引く
    cout << ans << endl;
}


Measured memory_bytes: 20096
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

vec visited(1000,0);
mat G(1000,vec(0));

bool dfs(ll to){
    if(visited[to] != 3) visited[to] = 2;
    for(ll next : G[to]){
        if(visited[next] == 2){
            visited[to] = 1;
            return false;
        }
    }
    for(ll next : G[to]){
        if(visited[next] == 3) {
            return true;
        }
    }
    vec memo(0);
    for(ll next : G[to]){
        memo.push_back(visited[next]);
        visited[next] = 1;
    }
    rep(i,G[to].size()){
        ll next = G[to][i];
        if(memo[i] != 1) {
            if(dfs(next)) return true;
        }
    }
    visited[to] = 1;
    return false;
}

int main() {
    cin>>N>>M;
    rep(i,M) {
        cin>>A>>B;
        --A; --B;
        G[A].push_back(B);
        //G[B].push_back(A);
    }
    rep(i,N){
        visited[i] = 3;
        if(dfs(i)){
            vec ans(1,i+1);
            rep(j,N){
                if(visited[j] == 2) ans.push_back(j+1);
            }
            cout<<ans.size()<<endl;
            for(ll t : ans) cout<<t<<endl;
            return 0;
        }
        /*
        cout<<i<<endl;
        rep(j,N) cout<<visited[j]<<' ';
        cout<<endl;
        */
        rep(j,N) visited[j] = 0;
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 384
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		String s = in.next();
		char[] s_chars = s.toCharArray();
        int x = s.length();
        int nam = 0;
      
      for(int i=0;i<x;i++){
        if(s_chars[i]=='x'){
          nam++;
        }
      }
      if(nam<=7){System.out.print("YES");}
      else{System.out.print("NO");}
        
     
	}
}

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

void solve(){
	int n;
	cin>>n;
	set <string> s;
	string tmp;
	for(int i = 0; i < n; i++){
		cin>>tmp;
		s.insert(tmp);
	}
	cout<<s.size();
}

int main(){
	solve();
	return 0;
}

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

struct katana{
  int a;
  int b;
  bool operator<(katana k)const{
    return b>k.b;
  }
};

int main(void){
  int N,H;
  cin>>N>>H;
  vector<katana> k(N);
  int maxa=-1;
  for (int i=0;i<N;i++) {
    int a,b;
    cin>>a>>b;
    k[i].a=a;
    k[i].b=b;
    if (maxa<a) maxa=a;
  }
  long long int ans=0;
  sort(k.begin(),k.end());
  for (int i=0;i<N;i++){
    if (H<=0) {
      cout<<ans<<endl;
      return 0;
    }
    if (k[i].b>maxa){
      H-=k[i].b;
      ans++;
    }

  }

  ans+=(H+maxa-1)/maxa;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>                        
#define pb push_back                            
#define mp make_pair                            
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define endl "\n"
#define jonathan ios_base::sync_with_stdio(0)
#define livingston cin.tie(0)                   
using namespace std;                            
                                                
void yes() {cout << "YES" << endl;}                                               
void no() {cout << "NO" << endl;}                                                        
                                                
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};         
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; 

const long long INF = 8e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7;

void solve() {
    int n; cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    long long cnt = 0;
    for (int i = 1; i < n - 1; i++) {
        for (int j = 0; j < i; j++) {
            for (int k = i + 1; k < n; k++) {
                if (a[i] != a[j] and a[i] != a[k]) {
                    if (a[i] + a[j] > a[k]) {
                        cnt++;
                    }
                }
            }
        }
    }
    cout << cnt << endl;
}

int main() {
    jonathan; 
    livingston;
    bool tests = 0;
    int t = 1;
    if (tests) cin >> t;
    for (int i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	double a, b, c;
	cin >> a >> b;
	c = ceil((a + b) / 2);
	cout << (int)c << endl;
	return 0;
}

Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N;cin>>N;
    REP(i,N){
        char c;
        cin>>c;
        if(c=='Y'){
            cout<<"Four"<<"\n";
            exit(0);
        }
    }
    cout<<"Three\n";
    return 0;
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

n = int(input())

li = make_divisors(n)

ans = 10 ** 10

for i in li:
    j = n // i
    ans = min(ans,i + j)

print(i + j - 2)


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

ll f(ll a,ll b,ll c) {
    return a-a/b-a/c+a/(b*c/__gcd(b,c));
}
int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<f(b,c,d)-f(a-1,c,d)<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

public class Hello{
    public static bool[] Primes;
    public static bool[] Checked;
    
    public static void Main(){
        // Make Primes
        Primes = Enumerable.Repeat(true, Consts.MAXBADGET + 1).ToArray();
        for(int i = 0; i < Primes.Length; i++){
            if(i == 0){ // 0 is not prime
                Primes[i] = false;
                continue;
            }
            else if(i == 1 || Primes[i] == false){
                continue; // iclude 1 when this problem.
            }
            else{
                for(int n = i * 2; n < Primes.Length; n += i){
                    Primes[n] = false;
                }
            }
        }
        

        while(true){
            // Input MenuNum and Badget
            string[] n_x = System.Console.ReadLine().Split(' ');
            int MenuNum = int.Parse(n_x[0]);
            int Badget = int.Parse(n_x[1]);
            if(MenuNum == 0 && Badget == 0) break;
          
            // Input MenuPrices
            int[] MenuPrices = new int[MenuNum];
            bool ContainsOdd = false;
            for(int i = 0; i < MenuNum; i++){
                MenuPrices[i] = int.Parse(System.Console.ReadLine());
                ContainsOdd = MenuPrices[i] % 2 != 0 ? true : ContainsOdd;
            }
            Checked = Enumerable.Repeat(false, Primes.Length).ToArray();
            Checked[0] = true;
            int MaxPrime = 0;
            for(int i = 0; i < MenuPrices.Length; i++){
                for(int n = 0; n < Checked.Length; n++){
                    if(Checked[n]){
                        int Nextn = n + MenuPrices[i];
                        if(Badget < Nextn) break;
                        try{
                            Checked[Nextn] = true;
                        }
                        catch(IndexOutOfRangeException){
                            break;
                        }
                        if(Primes[Nextn]){
                            MaxPrime = MaxPrime < Nextn ? Nextn : MaxPrime;
                        }
                    }
                }
            }
            System.Console.WriteLine((MaxPrime <= 0 ? "NA" : MaxPrime.ToString()));
        }
    }
}

public static class Consts{
    public static int MAXBADGET = 1000000;
}

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

int main(){
  double n ,flag=0 ,num[4001] ,price[4001] ,earnings[4001] ,total[4001] ,overlap;
  while( true ){
    cin >> n;
    if( n == 0 ){
      break;
    }
    for( int i=0 ; i<n ; i++ ){ // 入力と合計を計算
      cin >> num[i] >> price[i] >> earnings[i];
      total[i] = price[i] * earnings[i];
    }

    for( int i=0 ; i<n ; i++ ){ // 重複を無くす
      overlap = num[i]; // 重複したかの判定
      for( int j=0 ; j<n ; j++ ){
	if( num[j] == overlap && i != j ){ // 重複したか
	  total[i] += total[j];
	  num[j] = -1;
	  total[j] = 0;
	}
      }
    }

    for( int i=0 ; i<n ; i++ ){ // 出力
      if( total[i] >= 1000000 ){
	cout << num[i] << endl;
	flag = 1;
      }
    }

    if( flag == 0 ){ // いなかったら
      cout << "NA" << endl;
    }
    flag = 0;
  }
}

Measured memory_bytes: 1328
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
	int a,b;cin>>a>>b;
	if(a<=0&&b>=0){
		puts("Zero"); return 0;
	}
	if(a<0 && (b-a)%2 == 0){
		puts("Negative");
	}
	else{
		puts("Positive");
	}
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX=1e9;

int main(){
	int n;
	cin>>n;
	int a[n];
	map<int,int> cnt;
	REP(i,n){
		cin>>a[i];
		if(cnt.find(a[i])!=cnt.end()){
			int num=cnt.at(a[i]);
			cnt.erase(cnt.find(a[i]));
			cnt.insert(make_pair(a[i],num+1));
		}else{
			cnt.insert(make_pair(a[i],1));
		}
	}
	int min_size=0;
	REP(i,n){
		if(cnt.find(a[i])!=cnt.end()){
			int count=cnt.at(a[i]);
			if(count<a[i])min_size+=count;
			else min_size+=count-a[i];
			cnt.erase(cnt.find(a[i]));
		}
	}
	cout<<min_size<<endl;
	return 0;
}


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

int main() {
    int N; cin >> N;
    vector<string>B(N);
    vector<int>A(5);
    for (int i = 0; i < N; i++) {
        cin >> B.at(i);
        if (B.at(i).at(0) == 'M') A.at(0)++;
        else if (B.at(i).at(0) == 'A') A.at(1)++;
        else if (B.at(i).at(0) == 'R') A.at(2)++;
        else if (B.at(i).at(0) == 'C') A.at(3)++;
        else if (B.at(i).at(0) == 'H') A.at(4)++;
    }
    int zero = 0;
    for (int i = 0; i < 5; i++) {
        if (A.at(i) == 0) zero++;
    }
    if (zero > 2) cout << 0 << endl;
    else {
        long long ans = 0;
        for (int i = 0; i < (1 << 5); i++) {
            long long num = 1;
            vector<int>C;
            for (int j = 0; j < 5; j++) {
                if (i & (1 << j)) C.push_back(j);
            }
            if (C.size() == 3) {
                bool check = true;
                for (int i = 0; i < 3; i++) {
                    if (A.at(C.at(i)) == 0) check = false;
                }
                if (check) {
                    for (int i = 0; i < 3; i++) {
                        num *= A.at(C.at(i));
                    }
                    ans += num;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const int DEFAULT = 2147483647;

//Regular lazy propagation RMQ
struct SegmentTree {
    int n;
    vector<int> heap;
    vector<int> lazy;
    
    SegmentTree(int n): n(n) {
        heap.assign(4 * n, DEFAULT);
        lazy.assign(4 * n, DEFAULT);
    }
    
    void update(int nodeId, int l, int r, int ql, int qr, int v) {
        if (qr < l || ql > r) {
            return;
        }
        else if (ql <= l && r <= qr) {
            lazy[nodeId] = v;
        }
        else {
            pushdown(nodeId);
            int m = l + (r - l)/2;
            update(nodeId * 2, l, m, ql, qr, v);
            update(nodeId * 2 + 1, m + 1, r, ql, qr, v);
            pushup(nodeId);
        }
    }
    
    void pushdown(int nodeId) {
        if (lazy[nodeId] != -1) {
            lazy[nodeId * 2] = lazy[nodeId];
            lazy[nodeId * 2 + 1] = lazy[nodeId];
            heap[nodeId] = lazy[nodeId];
            lazy[nodeId] = -1;
        }
    }
      
      void pushup(int nodeId) {
          heap[nodeId] = min(getMin(nodeId * 2), getMin(nodeId * 2 + 1));
      }
      
      int getMin(int nodeId) {
          if (lazy[nodeId] != -1) {
              return lazy[nodeId];
          }
          else {
              return heap[nodeId];
          }
      }
    
    int query(int nodeId, int l, int r, int ql, int qr) {
        if (qr < l || ql > r) {
            return DEFAULT;
        }
        if (ql <= l && r <= qr) {
            return getMin(nodeId);
        } 
        else {
            pushdown(nodeId);
            int m = l + (r - l)/2;
            return min(query(nodeId * 2, l, m, ql, qr),
                    query(nodeId * 2 + 1, m + 1, r, ql, qr));
        }
    }  
};

int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree st(n);
    for (int i = 0; i < q; i++) {
        int cmd;
        cin >> cmd;
        if (cmd == 0) {
            int ql, qr, v;
            cin >> ql >> qr >> v;
            st.update(1, 0, n - 1, ql, qr, v);
//            for (int i = 0; i < 4 * n; i++) {
//                cout << i << ":" << st.heap[i] << endl; 
//            }
        }
        else {
            int ql, qr;
            cin >> ql >> qr;
            cout << st.query(1, 0, n - 1, ql, qr) << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 5940
L = int(input())
R = 0
while True:
  R += 1
  if 2 ** R > L:
    R -= 1
    break
N = R + 1
M = 2 * R
_L = L
for r in range(R, 0, -1):
  if _L - 2 ** (r - 1) >= 2 ** R:
    M += 1
    _L -= 2 ** (r - 1)
print(N, M)
for i in range(R):
  print(i + 1, i + 2, 2 ** i)
  print(i + 1, i + 2, 0)
for r in range(R, 0, -1):
  if L - 2 ** (r - 1) >= 2 ** R:
    print(r, N, L - 2 ** (r - 1))
    L -= 2 ** (r - 1)

Measured memory_bytes: 3064
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

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

fn main() {
    let mut v = vec![];
    for i in 0..4 {
        v.push(read::<i32>());
    }
    let ans = min(v[0], v[1]) + min(v[2], v[3]);
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    K=I()
    S=input()
    
    if len(S)<=K:
        print(S)
    else:
        print(S[:K]+"...")

main()


Measured memory_bytes: 61708
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl




signed main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    cout << a[0]*a[1]/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int n,nt[8],temp;
int max,min,sa;
 char str;
  cin>>n;
  for(int k=0;k<n;k++){
    max=0;
    min=0;
    for(int i=0;i<8;i++){
      cin>>str;
      str-=0;
      nt[i]=str;
    }
    for(int i=0;i<8;i++){
      for(int j=7;i<j;j--){
	if(nt[j]>nt[j-1]){
	  temp=nt[j];
	  nt[j]=nt[j-1];
	  nt[j-1]=temp;
	}
      }
    }
    for(int i=0;i<8;i++){
      max*=10;
      max+=nt[i];
    }
    for(int i=0;i<8;i++){
      for(int j=7;i<j;j--){
	if(nt[j]<nt[j-1]){
	  temp=nt[j];
	  nt[j]=nt[j-1];
	  nt[j-1]=temp;
	}
      }
    }
    for(int i=0;i<8;i++){
      min*=10;
      min+=nt[i];
    }
    sa=max-min;
    cout<<sa<<endl;
  }
  return 0;
}

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

#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\n"
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}

int main(){
	c_p_c();
	int a,b,c; cin >> a >> b >> c ;
	cout << c << " " << a << " " << b << endl;

	return 0;
} 

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int n; scanf("%d",&n);
    printf("%d",n*n*n);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    ll h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) cout << 1 << endl;
    else cout << ((h + 1) / 2) * ((w + 1) / 2) + (h / 2) * (w / 2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#include <algorithm> 
#include<vector>
#include<map>
#define ll long long int
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   /* ll n,x,y,i,j,a,k=0,b=0,sum=0;

	cin >> n;
	for(i=0;i<n;i++)
	{
		cin>>a;
		sum+=a;
		k+=1-a*2;
		if(k<0)k=0;
		if(b<k)b=k;
	}
	if(b==0) cout << sum-1;
	else cout << sum+b;
	return 0;*/

char n;
 cin>>n;
 if(n>=65&&n<97)
 {
   cout<<"A";
 }
 else{
   cout<<"a";
 }
}


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

int main() {
	int n;
	cin >> n;
	int as[n], bs[n], cs[n];
	for (int i = 0; i < n; i ++) {
		int a;
		cin >> a;
		as[i] = a-1;
	}
	for (int i = 0; i < n; i ++) {
		int a;
		cin >> a;
		bs[i] = a;
	}
	for (int i = 0; i < n-1; i ++) {
		int a;
		cin >> a;
		cs[i] = a;
	}

	int sum = 0, b, a_prev = -1;
	for (int i = 0; i < n; i ++) {
		int a = as[i];
		b = bs[a];
		sum += b;
		if(a_prev >= 0 && a == a_prev + 1) {
			int c = cs[a_prev];
			sum += c;
		}
		a_prev = a;
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;

ll n,c;
vector<ll> h;
vector<p> lines;
vector<ll> dp;

bool check(p p1, p p2, p p3){
  return (p2.second-p1.second)*(p3.first-p2.first)>(p3.second-p2.second)*(p2.first-p1.first);
}

ll get_y(p line, ll x){
  return line.first*x+line.second;
}

void add(p line){
  if(lines.size()>=2){
    ll t = lines.size()-1;
    while(t-1>=0&&!check(lines[t-1],lines[t],line)){
      lines.pop_back();
      t--;
    }
  }
  lines.push_back(line);
}

ll query(ll x){
  ll l = -1, r = lines.size()-1, mid;
  while(r-l>1){
    mid = (l+r)/2;
    if(get_y(lines[mid],x)>=get_y(lines[mid+1],x)){
      l = mid;
    }else{
      r = mid;
    }
  }
  return get_y(lines[r],x);
}

int main(){
  cin >> n >> c;
  REP(i,n){
    ll tmp;
    cin >> tmp;
    h.push_back(tmp);
  }
  ll dp;
  add(p(-2*h[0],c+h[0]*h[0]));
  for(ll i = 1; i < n; i++){
    dp = query(h[i])+h[i]*h[i];
    add(p(-2*h[i],h[i]*h[i]+c+dp));
  }
  cout << dp << endl;
  return 0;
}


Measured memory_bytes: 7792
fun main(args: Array<String>)
{
    val n = readInt()
    val p = readNInts()

    var cnt = 0
    for (i in 1..n){
        cnt += if (p[i-1] == i) 0 else 1
    }

    println(if (cnt == 0 || cnt == 2) "YES" else "NO")

}


// Read an integer
// Usage: val a = readInt()
private fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
private fun readNInts() = readLine()!!.split(" ").map(String::toInt)

// Read a string
// Usage: val a = readString()
private fun readString() = readLine()!!


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

int N;
int a[100000];

void solve()
{
	bool ok = true;
	for(int i=0;i<N;++i)if(i==0 || a[i-1]<a[i])a[i]--;
	for(int i=0;i<N;++i){
		if(i+1<N&&a[i]>a[i+1]){
			ok = false;
			break;
		}
	}
	if(ok) cout << "Yes\n";
	else cout << "No\n";
}

int main()
{
	cin >> N;
	for(int i=0;i<N;++i)cin >> a[i];
	solve();
	return 0;
}

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

r = n - 1
x, i = a[r], -1
for j in range(r):
    if a[j] <= x:
        i += 1
        a[i], a[j] = a[j], a[i]
i += 1
a[i], a[r] = a[r], a[i]

a[i] = '[' + str(a[i]) + ']'
print(*a)

Measured memory_bytes: 18272
from collections import Counter
from functools import reduce
import fractions
import math
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


n, k = MI()
dp = [INF] * n
h = LI()
dp[0] = 0
for i in range(0, n-1):
    for j in range(1, k+1):
        if n <= i+j:
            continue
        dp[i+j] = min(dp[i] + abs(h[i]-h[i+j]), dp[i+j])
P(dp[n-1])


Measured memory_bytes: 79360
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdlib>
using namespace std;
char fieldL[51][51];
char fieldR[51][51];
bool isArrival[51][51][51][51];
int h,w;
const int dy[]={-1,0,0,1};
const int dx[]={0,-1,1,0};
int fly,flx,frx,fry;
void bfs(int slx,int sly,int srx,int sry){
	queue<pair<int,int> > *prvL=new queue<pair<int,int> >();
	queue<pair<int,int> > *nxtL=new queue<pair<int,int> >();
	queue<pair<int,int> > *prvR=new queue<pair<int,int> >();
	queue<pair<int,int> > *nxtR=new queue<pair<int,int> >();
	prvL->push(make_pair(sly,slx));
	prvR->push(make_pair(sry,srx));
	while(prvL->size()){
		while(prvL->size()){
			pair<int,int> pl=prvL->front();prvL->pop();
			pair<int,int> pr=prvR->front();prvR->pop();
			int ly=pl.first;int lx=pl.second;
			int ry=pr.first;int rx=pr.second;
			if(isArrival[ly][lx][ry][rx])
				continue;
			isArrival[ly][lx][ry][rx]=true;
			for(int i = 0; i < 4; i++){
				int nly=max(0,min(h-1,ly+dy[i]));
				int nlx=max(0,min(w-1,lx+dx[i]));
				int nry=max(0,min(h-1,ry+dy[i]));
				int nrx=max(0,min(w-1,rx-dx[i]));
				if(fieldL[nly][nlx]=='#'){
					nly=ly;
					nlx=lx;
				}
				if(fieldR[nry][nrx]=='#'){
					nry=ry;
					nrx=rx;
				}
				if((nly==fly&&nlx==flx)&&!(nry==fry&&nrx==frx)){
					continue;
				}
				else if(!(nly==fly&&nlx==flx)&&(nry==fry&&nrx==frx)){
					continue;
				}
				else if((nly==fly&&nlx==flx)&&(nry==fry&&nrx==frx)){
					isArrival[nly][nlx][nry][nrx]=true;
					delete prvL,prvR,nxtL,nxtR;
					return;
				}

				if(!isArrival[nly][nlx][nry][nrx]){
					nxtL->push(make_pair(nly,nlx));
					nxtR->push(make_pair(nry,nrx));
				}
			}
		}
		swap(prvL,nxtL);
		swap(prvR,nxtR);
	}
	delete prvL,prvR,nxtL,nxtR;
}

int main(){
	while(cin>>w>>h&&!(w==0&&h==0)){
		memset(isArrival,0,sizeof(isArrival));
		int sly,slx,srx,sry;

		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin>>fieldL[i][j];
				if(fieldL[i][j]=='L'){
					fieldL[i][j]='.';
					sly=i;
					slx=j;
				}
				else if(fieldL[i][j]=='%'){
					fieldL[i][j]='.';
					fly=i;
					flx=j;
				}
			}
			for(int j = 0; j < w; j++){
				cin>>fieldR[i][j];
				if(fieldR[i][j]=='R'){
					fieldR[i][j]='.';
					sry=i;
					srx=j;
				}
				else if(fieldR[i][j]=='%'){
					fieldR[i][j]='.';
					fry=i;
					frx=j;
				}
			}
		}
		bfs(slx,sly,srx,sry);
		if(isArrival[fly][flx][fry][frx])
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 9332
package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

type List []int

func (l List) Len() int {
	return len(l)
}

func (l List) Swap(i, j int) {
	l[i], l[j] = l[j], l[i]
}

func (l List) Less(i, j int) bool {
	return l[i] < l[j]
}

func main(){
	var n int
	fmt.Scan(&n)
	var l List = scanIntSplit(n)
	sort.Sort(sort.Reverse(l))
	ans := 0
	for i, v := range l {
		if i%2 == 0 {
			ans += v
		} else {
			ans -= v
		}
	}
	fmt.Println(ans)
}

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

int main(){
	int N;
	cin >> N;
	int H[N];
	for(int i=0;i<N;i++)cin>>H[i];
	
	int maxv=0;
	int ans=0;
	for(int i=0;i<N;i++){
		if(H[i]>=maxv)ans++;
		maxv=max(maxv,H[i]);
		}	
	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
      ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
    ll a, b;
    ll f = 0, ind = 0;
    cin >> a >> b;
    for (ll i = 0; i <= 10000000; i++)
    {
        if ((ll)(i * 0.08) == a && (ll)(i * 0.1) == b)
        {
            f = 1;
            ind = i;
            break;
        }
    }
    if (f == 1)
        cout << ind << endl;
    else
    {
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
s=list(input())
q=int(input())
c=[chr(i) for i in range(97, 97+26)]
l=[input().split() for i in range(q)]

def segfunc(x,y):
  return x+y

def init(init_val,c):
  for i in range(n):
    seg[c][i+num-1]=init_val[i]
  for i in range(num-2,-1,-1):
    seg[c][i]=segfunc(seg[c][2*i+1],seg[c][2*i+2])

def update(k,x,c):
  k+=num-1
  seg[c][k]+=x
  while k:
    k=(k-1)//2
    seg[c][k]=segfunc(seg[c][k*2+1],seg[c][k*2+2])

def query(p,q,c):
  if q<=p:
    return ide_ele
  p+=num-1
  q+=num-2
  res=ide_ele
  while q-p>1:
    if p&1==0:
      res=segfunc(res,seg[c][p])
    if q&1==1:
      res=segfunc(res,seg[c][q])
      q-=1
    p=p//2
    q=(q-1)//2
  if p==q:
    res=segfunc(res,seg[c][p])
  else:
    res=segfunc(segfunc(res,seg[c][p]),seg[c][q])
  return res

ide_ele=0

num=2**(n-1).bit_length()
seg=[[ide_ele]*2*num for i in range(26)]

L=[[0 for i in range(n)] for j in range(26)]
for i in range(n):
  L[c.index(s[i])][i]+=1

for i in range(26):
  init(L[i],i)

for i in range(q):
  if l[i][0]=='1':
    update(int(l[i][1])-1,1,c.index(l[i][2]))
    update(int(l[i][1])-1,-1,c.index(s[int(l[i][1])-1]))
    s[int(l[i][1])-1]=l[i][2]
  else:
    ct=0
    for j in range(26):
      if query(int(l[i][1])-1,int(l[i][2]),j)!=0:
        ct+=1
    print(ct)

Measured memory_bytes: 610768
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String[][] tmp = new String[2][3];
        tmp[0] = sc.next().split("");
        tmp[1] = sc.next().split("");

        int tmpLen = 3;

        boolean swt = false;
        for ( int i = 0 ; i < 3 ; i++ ) {
            tmpLen --;
            if (tmp[0][i].equals(tmp[1][tmpLen])) {
                swt = true;
            }else{
                swt = false;
                i = 3;
            }
        }

        if (swt) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }




    }
}


Measured memory_bytes: 21716
n = int(input())
balls = list(map(int, input().split()))
num_dict = {}
total_pairs = 0

for b in balls:
    if b not in num_dict.keys():
        num_dict[b] = [1, 0]
    else:
        num_dict[b][0] += 1
        num_dict[b][1] = (num_dict[b][0] * (num_dict[b][0]-1) - (num_dict[b][0]-1) * (num_dict[b][0]-2))//2

for val in num_dict.values():
    v = val[0]
    total_pairs += v*(v-1)//2
    
for i in range(n):
    ball_val = balls[i]
    print(total_pairs - num_dict[ball_val][1])

Measured memory_bytes: 30652
#include<bits/stdc++.h>
using namespace std;
#define nn 500008
#define mod 1000000007
char str[nn];int n,m;
long long dp[nn],sum[nn];
#define err return 0*puts("0");
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",str+1);
	
	int cnt=0;
	if(str[1]=='B') for(int i=1;i<=m;i++) if(str[i]=='R') str[i]='B';else str[i]='R';
	for(int i=1;i<=m;i++) if(str[i]=='B') cnt++;
	int mx=n;int flg=0;
	if(cnt)
	{
		cnt=0;
		if(n%2) err;int j=1;
		for(int i=m;i>=1;i--)
			if(str[i]=='B')  {for(int j=i;j<=m;j++) str[j]='B';break;}

		for(int i=1;i<=m;i++)
		{
			if(str[i]=='B') break;
			cnt++;j=i;
		}
		mx=min(mx,cnt/2+1);
		
		j++;
		cnt=0;str[m+1]='B';
		for(;j<=m+1;j++)
		{
			if(str[j]=='B')
			{
				if(cnt%2) mx=min(mx,cnt/2+1);
				cnt=0;
			}
			else cnt++;
		}
		flg=1;
		n/=2;
	}
	
	dp[0]=sum[0]=1;
	int ls=0;if(!flg) ls=1,sum[1]=1;
	for(int i=ls+1;i<=n;i++) 
	{
		if(i-mx-1>=0 and flg) dp[i]=(sum[i-1-ls]-sum[i-mx-1]+mod)%mod;
		else dp[i]=sum[i-1-ls];
		sum[i]=(sum[i-1]+dp[i])%mod;
	}
	long long ans=0;
	for(int i=1+ls;i<=n and i<=mx;i++)
	{
		ans+=1ll*dp[n-i]*i%mod;
		if(flg) ans+=1ll*dp[n-i]*i%mod;
		ans%=mod;
	}
	if(ls==1) ans++;
	
	printf("%lld\n",(ans%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 7936
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long 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;
}


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll GetDigit(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}


int main(void){

 string s;
 cin>>s;

 vector<ll> v(26, 0);
 REP(i, s.size()){
   v[s[i]-'a'] = i+1;
 }

 if(s.size()!=26){
   cout<<s;
   REP(i, 26){
     if(v[i]==0){
       char x = 'a';
       cout<<char(x+i)<<endl;
       return 0;
     }
   }
}else{
     vector<char> c;
     int a;

     for(int i=25;i>0;i--){
       if(s[i]>s[i-1]){
        c.push_back(s[i]);
        a = i-1;
        break;
       }
       c.push_back(s[i]);
       if(i==1){
         cout<<"-1"<<endl;
         return 0;
       }
     }

    sort(c.begin(), c.end());
    
    REP(i, a){
       cout<<s[i];
    }
    REP(i, c.size()){
      if(c[i]>s[a]){
        cout<<c[i]<<endl;
        return 0;
      }
    }

   }
   
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N,W;
    string S;
    cin >> N>>W;

    if(N>W){
        cout << "safe" << endl;
    }
    else{
        cout << "unsafe" << endl;
    }
}


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

int main() {
    int N;
    int H[110];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> H[i];
    
    int cnt = 0;
    int max = 0;

    for (int i = 0; i < N; ++i) {
        if(H[i] >= max) {
            max = H[i];
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  string s; cin >> s;
  int ans = 0;
  for ( int i = 0; i < s.length(); i++ ) {
    int sum = 0;
    for ( int j = i; j < s.length(); j++ ) {
      if ( s[j] == 'A' || s[j] == 'C'
	   || s[j] == 'G' || s[j] == 'T' ) {
	sum++;
      } else {
	break;
      }
    }
    ans = max(ans,sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
#define Q 50000
main(){
  int array1[N],array2[Q],i,j,c=0,n,m,left,right,mid;

  scanf("%d%",&n);
  for(i=0;i<n;i++){
    scanf("%d%",&array1[i]);
  }
  
  scanf("%d%",&m);
  for(j=0;j<m;j++){
    scanf("%d%",&array2[j]);
  }
  
  for(j=0;j<m;j++){
    left=0;
    right=n;
    while(left<right){
      mid=(left+right)/2;
      if(array2[j]==array1[mid]){
	c++;
	break;
      }
      if(array2[j]>array1[mid]){
	left=mid+1;
      }
      else if(array2[j]<array1[mid]){
	right=mid;
      }
    }
  }
  
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 1184