akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;
map<string,int> ma;
signed main(){
  int n;cin>>n;
  rep(ima,n){
    string s;cin>>s;
    int m=s.length();
    rep(i,m){
      for(int j=i+1;j<m;j++){
        if(s[i]>s[j])swap(s[i],s[j]);
      }
    }
    ma[s]++;
  }
  int ans=0;
  for(auto p:ma){
    int po=p.S;
    ans+=po*(po-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

int n;
int A[200000], S[200000];
int L, R;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        S[i] = A[i];
    }
    sort(S, S+n);
    L = S[n/2 -1];
    R = S[n/2];

    for (int i = 0; i < n; i++) {
        if (A[i] <= L) cout << R << endl;
        else cout << L << endl;
    }
}


Measured memory_bytes: 3712
#include <stdio.h>

int table[15][15];

void magicsquare( int num )
{
        int i = 0, j = 0, curnum = 1;
        for ( i = 0 ; i < num ; i++ ) {
                for ( j = 0 ; j < num ; j++ ) {
                        table[i][j] = 0;
                }
        }

        i = num/2+1; j = num/2;
        table[i][j] = curnum;
        i++; j++;
        while ( curnum < num*num ) {
                if ( j <   0 ) { j = num-1; }
                if ( j >= num ) { j = 0; }
                if ( i >= num ) { i = 0; }
                if ( table[i][j] != 0 ) { i++; j--; }
                if ( table[i][j] == 0 && i >= 0 && i < num && j >= 0 && j < num ) {
                        curnum++;
                        table[i][j] = curnum;
                        i++; j++;
                }
        }
        return ;
}


int main()
{
        int num, i, j;

        while ( scanf( "%d", &num ) == 1 ) {
                if ( num == 0 ) { break; }

                magicsquare( num );
                for ( i = 0 ; i < num ; i++ ) {
                        for ( j = 0 ; j < num ; j++ ) {
                                printf( "%4d", table[i][j] );
                        }
                        printf( "\n" );
                }
        }

        return 0;
}



Measured memory_bytes: 2052
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>

using namespace std;
using ll = long long;

// inf
const ll infl = 1LL << 60;
const int inf = 1 << 30;

int main() {
    int N; cin >> N;
    vector<pair<int, int> > works(N);
    for (int i = 0; i < N; ++i) {
        int a, b; cin >> a >> b;
        works[i] = pair<int, int>(b, a);
    }
    sort(works.begin(), works.end());
    ll cur = 0LL;
    bool ans = true;
    for (auto w : works) {
        cur += w.second;
        if (cur > w.first) {
            ans = false;
            break;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#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
typedef long long ll;

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

string s;
bool flag[26];
int main() {
    cin>>s;
    REP(i, 0, s.size()){
        flag[s[i]-'a']=true;
    }
    REP(i, 0, 26){
        if(!flag[i]){
            cout<<(char)('a'+i)<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n,x;
  cin >> n >> x;
  vector<ll> a(n), v(n);
  for(int i=0;i<n;i++) {
    cin >> a[i];
    v[i] = a[i];
  }

  ll ans = 1e9 * 2100;
  for(int k=0;k<n;k++) {
    ll k_ans = 0;
    for(int i=0;i<n;i++) {
      if(i-k < 0) {
        v[i] = min<ll>(v[i], a[n+i-k]);
      } else {
        v[i] = min<ll>(v[i], a[i-k]);
      }

      k_ans += v[i];
    }
    ans = min<ll>(ans, k_ans + k * x);
  }
  cout << ans << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int s,d;
	while(cin>>s>>d,s){
		int sd[s][d],dd[d][d],t;
		rep(i,s)rep(j,d)cin>>sd[i][j];
		rep(i,d)rep(j,d){
			if(i<j)cin>>t,dd[i][j]=dd[j][i]=t;
			if(i==j)dd[i][i]=0;
		}
		int cost=0,V[d],v=0; rep(i,d)V[i]=0;
		priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >F;
		rep(i,s)rep(j,d)if(sd[i][j])F.push(make_pair(sd[i][j],j));
		while(v<d&&!F.empty()){
			int cc=F.top().first,cn=F.top().second;F.pop();
			if(V[cn]||!cc)continue;
			V[cn]=1,cost+=cc,v++;
			rep(i,d)if(!V[i]&&dd[cn][i])F.push(make_pair(dd[cn][i],i));
		}
		cout<<cost<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e3 + 10;
const long long mod = 1e9 + 7;

long long dp[maxn][maxn];

int s[maxn], t[maxn], n, m;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> s[i];
	for (int i = 1; i <= m; i++)
		cin >> t[i];
	for (int i = 0; i <= max(n, m); i++)
		dp[i][0] = dp[0][i] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			if (s[i] == t[j])
				dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod;
			else
				dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + mod * mod) % mod;
			//cout << dp[i][j] << " \n"[j == m];
		}
	cout << dp[n][m] << '\n';
	return 0;
}


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

using namespace std;

void solve(string s, char v, int n) {
    if (n == 0) {
        cout << s << endl;
        return;
    }
    for (char c = 'a'; c <= v; c++) {
        solve(s + c, c < v ? v : v + 1, n - 1);
    }
}

int main(void) {
    int n;
    cin >> n;

    solve("", 'a', n);

    return 0;
}


Measured memory_bytes: 1536
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>

using namespace std;

int n;
char s[222222];
long long c[256];
set<string> vs;

int main(void) {
  scanf("%s", s);
  for (n = 0; s[n]; n++);
  long long res = (long long)n*(n-1)/2 + 1;
  for (int i = 0; i < n; i++) {
    c[int(s[i])] += 1;
  }
  for (int i = 0; i < 256; i++) {
    res -= (c[i]*(c[i]-1))/2;
  }
  printf("%lld\n", res);
  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int n, k;
vector<int> v;
int memo[60][60][110];
int dp(int l,int r, int num)
{
    if(l>r||num<0)   return -1000000007;
    if(num==0)  return 0;
    if(l==r)  return memo[l][r][num]=max(v[l],0);
    if(memo[l][r][num]!=-100000000)  return memo[l][r][num];
    int x=-99999999,y=-99999999,z,t;
    if(v[l]<0) x=dp(l+1,r,num-2);
    if(v[r]<0) y=dp(l,r-1,num-2);
    z=dp(l+1,r,num-1)+v[l];
    t=dp(l,r-1,num-1)+v[r];
    return memo[l][r][num]= max(max(max(x,y),max(z,t)),0);
}
int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(NULL);
    //freopen("inp","r",stdin);
    cin>>n>>k;
    v.resize(n);
    for(int i=0;i<=n;++i)
        for(int j=0;j<=n;++j)
            for(int x=0;x<=k;++x)  memo[i][j][x]=-100000000;
    for(int i=0;i<n;++i) cin>>v[i];
    printf("%d",dp(0,n-1,k));
    return 0;
}


Measured memory_bytes: 1536
#include <cstdio>

#define N 50
#define INF 100000

#define MIN(X,Y) ((X)<(Y)?(X):(Y))

using namespace std;


int main(void){
  int a,b,c;
  int dp[N+2][N+2][N+2];
  
  scanf("%d%d%d", &a,&b,&c);
  
  for (int i=0; i<=N+1; i++)for (int j=0; j<=N+1; j++)for (int k=0; k<=N+1; k++){
    dp[i][j][k] = (i==j)&&(j==k)?0:INF;
  }
  for (int i=N+1; i>=0; i--) for (int j=N+1; j>=0; j--) for (int k=N+1; k>=0; k--){
    if (i-1>=0 && j-1>=0) dp[i-1][j-1][k] = MIN(dp[i-1][j-1][k], dp[i][j][k]+1);
    if (j-1>=0 && k-1>=0) dp[i][j-1][k-1] = MIN(dp[i][j-1][k-1], dp[i][j][k]+1);
    if (i-1>=0 && k-1>=0) dp[i-1][j][k-1] = MIN(dp[i-1][j][k-1], dp[i][j][k]+1);
    if (i-2>=0) dp[i-2][j][k] = MIN(dp[i-2][j][k], dp[i][j][k]+1);
    if (j-2>=0) dp[i][j-2][k] = MIN(dp[i][j-2][k], dp[i][j][k]+1);
    if (k-2>=0) dp[i][j][k-2] = MIN(dp[i][j][k-2], dp[i][j][k]+1);
  }
  
//  for (int i=0; i<5; i++) for (int j=0; j<5; j++) for (int k=0; k<5; k++){
//    printf("%d,%d,%d: %d\n", i,j,k, dp[i][j][k]);
//  }
  
  printf("%d\n", dp[a][b][c]);
  return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
  long N,M;
  cin>>N>>M;
  if(abs(N-M)==1) { long sum=1;
      for(int i=1;i<=N;i++){
         sum=(sum*i)%1000000007;
      }
      for(int i=1;i<=M;i++){
          sum=(sum*i)%1000000007;
      }
      cout<<sum;
  }
  else if(N==M){ long sum=2;
    for(int i=1;i<=N;i++){
        sum=(sum*i)%1000000007;
    }
    for(int i=1;i<=M;i++){
        sum=(sum*i)%1000000007;
    }
    cout<<sum;  
  }
  else cout<<0;
  
  return 0;
}


Measured memory_bytes: 256
#ABC014-A
abc = list(map(int,input().split()))

cnt = 0

while True:
    prev = abc[:]
    if abc[0] % 2 == 1 or abc[1] % 2 == 1 or abc[2] % 2 == 1:
        break
    tmp = [abc[0]//2,abc[1]//2,abc[2]//2]

    abc = [tmp[1]+tmp[2],tmp[0]+tmp[2],tmp[0]+tmp[1]]
    cnt += 1
    

        
    if abc[0] == prev[0] and abc[1] == prev[1] and abc[2] == prev[2]:
        cnt = -1
        break
    else:
        continue
        
    
        
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int x;
    cin >> x;
    int ans = 1;
    rrep(i, x) {
        forr(j, 2, x + 1) {
            if((int)pow(i, j) <= x) {
                int value = pow(i, j);
                ans = max(value, ans);
            } else break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include "stdio.h"

#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};

void preParse(Node matrix[], int id){
  if(id  == NIL ){
    return;
  }
  printf(" %d", id);
  preParse(matrix, matrix[id].left);
  preParse(matrix, matrix[id].right);
}

void inParse(Node matrix[], int id){
  if(id  == NIL ){
    return;
  }
  inParse(matrix, matrix[id].left);
  printf(" %d", id);
  inParse(matrix, matrix[id].right);
}
  
void postParse(Node matrix[], int id){
  if(id  == NIL ){
    return;
  }
  postParse(matrix, matrix[id].left);
  postParse(matrix, matrix[id].right);
  printf(" %d", id);
}

int getRootId(Node matrix[]){
  int i=0;
  while(matrix[i].parent != NIL){
    i++;
  }
  return i;
}


int main(void){

  int N;
  scanf("%d", &N);

  Node* node = new Node [N];

  for(int i=0;i<N;i++){
    node[i].parent = NIL;
    node[i].left   = NIL;
    node[i].right  = NIL; 
  }

  int id, left_temp, right_temp;
  for(int i=0;i<N;i++){
    scanf("%d %d %d", &id, &left_temp, &right_temp );
    
    node[id].left  = left_temp;
    node[id].right = right_temp;

    node[ node[id].left  ].parent  = id;
    node[ node[id].right ].parent  = id;    
  }

  int rootId = getRootId(node);
  
  printf("Preorder\n");
  preParse(node, rootId);
  printf("\n");

  printf("Inorder\n");
  inParse(node, rootId);
  printf("\n");
  
  printf("Postorder\n");
  postParse(node, rootId);
  printf("\n");
  
  delete [] node;


  return 0;
}


Measured memory_bytes: 2716
import java.util.Scanner;

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

	public static void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] x = new long[n];
		long[] y = new long[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		sc.close();

		long area = Long.MAX_VALUE;
		for (int x1 = 0; x1 < n; x1++) {
			for (int x2 = 0; x2 < n; x2++) {
				for (int y1 = 0; y1 < n; y1++) {
					for (int y2 = 0; y2 < n; y2++) {
						int count = 0;
						for (int idx = 0; idx < n; idx++) {
							if (x[idx] < x[x1] || x[idx] > x[x2] || y[idx] < y[y1] || y[idx] > y[y2]) {
								continue;
							} else {
								count++;
							}
						}
						if (count >= k) {
							area = Math.min(area, (x[x2] - x[x1]) * (y[y2] - y[y1]));
						}
					}
				}
			}
		}
		System.out.println(area);
	}
}

Measured memory_bytes: 23124
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N;
int C[502];
int S[502];
int F[502];
int Ans[502];

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

  cin >> N;
  rep(i, N-1){
    cin >> C[i] >> S[i] >> F[i];
  }
  rep(i, N){
    int ans = 0;
    for (int j=i;j<N-1;j++){
      if (S[j] >= ans){
        ans= S[j];
      } else{
        int amari = ans%F[j];
        if (amari>0) ans+=F[j]-amari;
      }
      ans+=C[j];
    }
    cout << ans << "\n";
  }

  // cout << N << "\n";
  return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

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

ll cost[1000];
bool kakutei[1000];

vector<int> nodes[1000];

void init(){
    rep(i, 1000) cost[i] = mod;
    rep(i, 1000) kakutei[i] = false;
    rep(i, 1000) nodes[i].clear();
}

void dijk(int s){
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push(make_pair(1, s));
    cost[s] = 1;
    while(!pq.empty()){
        pair<ll, int> op = pq.top();
        pq.pop();
        int id = op.second;
        ll c = op.first;
        if(kakutei[id]) continue;
        kakutei[id] = true;
        rep(i, nodes[id].size()){
            int to = nodes[id][i];
            if(c+1 < cost[to]){
                cost[to] = c+1;
                pq.push(make_pair(c+1, to));
            }
        }
    }
}

int main(void){
    //右: 0, 上: 1, 左: 2, 下: 3
    vector<int> ans;
    int H, W;
    while(true){
        init();
        cin >> W >> H;
        if(W == 0) break;
        int input_loop = 2*H-1;
        rep(i, input_loop){
            int id = i/2;
            int st = id*W;
            if(i % 2){
                rep(j, W){
                    int temp; cin >> temp;
                    if(temp == 0){
                        nodes[st+j].push_back(st+j+W);
                        nodes[st+j+W].push_back(st+j);
                    }
                }
            }
            else{
                rep(j, W-1){
                    int temp; cin >> temp;
                    if(temp == 0){
                        nodes[st+j].push_back(st+1+j);
                        nodes[st+1+j].push_back(st+j);
                    }
                }
            }
        }
        dijk(0);

        /*
        rep(i, H){
            rep(j, W){
                cout << cost[i*W+j] << " ";
            }
            cout << endl;
        }
        */
        ans.push_back(cost[H*W-1]);
    }
    rep(i, ans.size()){
        if(ans[i] != mod)cout << ans[i] << endl;
        else cout << 0 << endl;
    }
    return 0;
}


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

using namespace std;

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

  int K;
  cin >> K;

  int X;
  cin >> X;
 
  int Y;
  cin >> Y;

  if(N >= K)
    cout << X*K + (N-K) * Y << endl;

  if(N < K)
    cout << N * X << endl;
}

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

int main() {
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    ll pre;
    h[0] -= 1;
    for(int i = 1; i < n - 1; i++) {
        if(h[i] >= h[i + 1] and h[i - 1] <= h[i] - 1)
            h[i] -= 1;
        else if(h[i] < h[i + 1])
            continue;
    }
    rep(i, n - 1) {
        if(h[i] > h[i + 1]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 4016
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;
#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> X(N,0);
    for(ll i=0;i<N;++i)cin>>X[i];
    ll L;
    cin >> L;
    ll Q;
    cin >> Q;
    vector<ll> a(Q,0);
    vector<ll> b(Q,0);
    for(ll i=0;i<Q;++i){cin>>a[i]>>b[i];if(a[i]>b[i])swap(a[i],b[i]);a[i]--;b[i]--;}
    vector<vector<ll>> cango(20, vector<ll>(N, 0));
    for(ll i=0;i<N;++i){
        cango[0][i]=upper_bound(X.begin(), X.end(), X[i]+L)-X.begin()-1;
    }
    for(ll i=1;i<20;++i){
        for(ll j=N-1;j>=0;--j){
            cango[i][j]=cango[i-1][cango[i-1][j]];
        }
    }
    for(ll i=0;i<Q;++i){
        ll count=1;
        ll now=a[i];
        for(ll j=19;j>=0;--j){
            if(cango[j][now]<b[i]){
                count+=1LL<<j;
                now=cango[j][now];
            }
        }
        prt(count);
    }

    return 0;
}



Measured memory_bytes: 21920
import java.util.*;
public class Main { 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String ans = "";
		char[] A = new char[26];
		A[0] = 'A';
		A[1] = 'B';
		A[2] = 'C';
		A[3] = 'D';
		A[4] = 'E';
		A[5] = 'F';
		A[6] = 'G';
		A[7] = 'H';
		A[8] = 'I';
		A[9] = 'J';
		A[10] = 'K';
		A[11] = 'L';
		A[12] = 'M';
		A[13] = 'N';
		A[14] = 'O';
		A[15] = 'P';
		A[16] = 'Q';
		A[17] = 'R';
		A[18] = 'S';
		A[19] = 'T';
		A[20] = 'U';
		A[21] = 'V';
		A[22] = 'W';
		A[23] = 'X';
		A[24] = 'Y';
		A[25] = 'Z';
		for(int i = 0; i < s.length(); i++) {
			char tp = s.charAt(i);
			for(int p = 0; p <= 25; p++) {
				if(p + n >= 26 && A[p] == tp) {
					tp = A[p + n - 26];
					break;
				}
				if(A[p] == tp) {
					tp = A[p + n];
					break;
				}
			}
			ans = ans + tp;
		}
		System.out.println(ans);
     }
}

Measured memory_bytes: 147768
#include <iostream>
#include <cstring>
using namespace std;
char a[4005];
int main() {
    int N, cnt = 0;
    long long sum = 0;
    cin >> N >> a;
    for(int i = 0; i < N; i++)
        if(a[i] == 'B')
            cnt ++;
    for(int i = 0; i < N; i++)
        if(a[i] != 'R')
            continue;
        else for(int j = 0; j < N; j++) {
            if(j == i || a[j] != 'G')
                continue;
            else if(i < j) {
                sum += cnt - (2 * i - j  > 0 && a[2 * i - j] == 'B') - (2 * j - i  < N && a[2 * j - i] == 'B');
                if(i != j - 1)
                    sum -= ((i + j) % 2 == 0 && a[(i + j) / 2] == 'B');
            } else if(i > j) {
                sum += cnt - (2 * j - i  > 0 && a[2 * j - i] == 'B') - (2 * i - j  < N && a[2 * i - j] == 'B');
                if(i != j + 1)
                    sum -= ((i + j) % 2 == 0 && a[(i + j) / 2] == 'B');
            }
           // cout << i << " " << j << " " << sum << endl;
        }
    cout << sum << endl;
}

Measured memory_bytes: 3616
#include <stdio.h>

int main()
{
	for(;;) {
		int h, w, i, j;
		scanf("%d %d", &h, &w);
		if (h == 0 & w == 0) { return 0; }
		for ( j = 0 ; j < h; j++)
		{
			for ( i = 0 ; i < w; i++)
			{
				printf("#");	
			}
			printf("\n");
		}
		printf("\n");
	}
}

Measured memory_bytes: 572
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <cmath>

using namespace std;
typedef long long ll;

int main(){
    ll a,b,c,k,ans=0;
    cin >> a >> b >> c >> k;
    if(a > k){
        ans += k;
        k = -1;
    }else{
        ans += a;
        k -= a;
    }
    if(k < 0){
        cout << ans << endl;
        return 0;
    }
    k -= b;
    if(k < 0){
        cout << ans << endl;
        return 0;
    }
    cout << ans - k << endl;
   
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main() {
   int N,A;
   cin >> N >> A;
   int c = N / 500;
   int remain = N - 500 * c;
   if(remain <= A) {
       cout << "Yes" << endl;
   } else {
       cout << "No" <<endl;
   }
}

Measured memory_bytes: 256
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
lastday=[0 for j in range(26)]
points=[0 for i in range(D)]
t=[0 for i in range(D)]
total=[0 for i in range(D)]
# first day
lastday=[lastday[i]+1 for i in range(26)]
bestpoint=0
for i in range(26):
    temp=[con for con in lastday]
    temp[i]=0
    minus=sum([x*y for (x,y) in zip(c,temp)])
    temppoint=s[0][i]-minus
    if bestpoint<temppoint:
        today=i
        bestpoint=temppoint
        minusb=minus
lastday[today]=0
t[0]=today+1
total[0]=s[0][today]-minusb



for days in range(1,D):
    lastday=[lastday[i]+1 for i in range(26)]
    bestpoint=0
    for i in range(26):
        temp=[con for con in lastday]
        temp[i]=0
        minus=sum([x*y for (x,y) in zip(c,temp)])
        temppoint=s[days][i]-minus
        if bestpoint<temppoint:
            today=i
            bestpoint=temppoint
            minusb=minus
    lastday[today]=0
    t[days]=today+1
    total[days]=total[days-1]+s[days][today]-minusb
    
for ts in t:
    print(ts)

Measured memory_bytes: 9376
#include <stdio.h>
#include <string.h>

#define MAX 300000

int N;
char S[MAX];

/* [pos][status]
status
  0 : 1でも2でもOK
  1 : 1のみ
  2 : 2のみ
*/
int memo[MAX][3];

int dp(int pos, int status) {
	int answer = 0;
	if (pos > N) return -MAX * 2;
	if (pos == N) return 0;
	if (memo[pos][status]) return ~memo[pos][status];
	if (status != 2) {
		int ng = S[pos] == S[pos + 1];
		int c = dp(pos + 1, ng ? 2 : 0) + 1;
		if (c > answer) answer = c;
	}
	if (status != 1) {
		int ng = S[pos] == S[pos + 2] && S[pos + 1] == S[pos + 3];
		int c = dp(pos + 2, ng ? 1 : 0) + 1;
		if (c > answer) answer = c;
	}
	return ~(memo[pos][status] = ~answer);
}

int main(void) {
	if (scanf("%299999s", S) != 1) return 1;
	N = strlen(S);
	printf("%d\n", dp(0, 0));
	return 0;
}


Measured memory_bytes: 11776
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,p,p1,c=1,i;
    cin>>n;
    cin>>p1;
    for(i=2;i<=n;i++)
    {
        cin>>p;
        if(p1>p)
            {c++;
            p1=p;}
    }
    cout<<c;
}


Measured memory_bytes: 256
def solve(n, a):
    if a[0] != 0:
        return -1

    if any(x > 1 for x in (t - s for s, t in zip(a, a[1:]))):
        return -1

    p = None
    ans = 0
    for c in reversed(a):
        if p is None or c != (p - 1):
            ans += c
        p = c
    return ans


if __name__ == '__main__':
    n = int(input())
    a = [int(input()) for _ in range(n)]
    print(solve(n, a))

# 単調非減少
# 差分は0/1


Measured memory_bytes: 12620
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    A, B = map(int, input().split())

    ans = 0
    for i in (A - 1, B):
        if i % 4 == 0:
            ans ^= i
        elif i % 2 == 0:
            ans ^= i ^ 1
        elif (i + 1) % 4 != 0:
            ans ^= 1
    print(ans)

if __name__ == '__main__':
    main()


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

#a = [28,27,24]

for i in a :
  if i%2 == 1 :
    continue
  else :
    if i % 3 == 0 or i % 5 == 0 :
      continue
    else :
      ck = False
      break
else : 
  ck = True

print('APPROVED' if ck else 'DENIED')

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

using namespace std;
int binarySearch(vector<int> int_array,int val){
    int key = val;
    int right = int_array.size();
    int left  = 0;
    while(left < right){
        int mid = (left + right)/2;
        if(int_array[mid]==key) return mid;
        else if(key < int_array[mid]) right = mid;
        else left = mid + 1;
    }
    return -1;
}

int main(){
    int len_array1,len_array2;
    int counter = 0;
    cin >> len_array1;
    vector<int> objective_array(len_array1,0);
    for(int i = 0;i < len_array1;i++) cin >> objective_array[i];

    cin >> len_array2;
    vector<int> search_array(len_array2,0);
    for(int i = 0;i < len_array2;i++){
        cin >> search_array[i];
        if(binarySearch(objective_array,search_array[i]) >= 0) counter++;
    }
    cout << counter << "\n";

    return 0;   
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using M = map<int, int>;

ll r, g, b, ng;

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;


  for(int i=0; i<n; ++i)
		s[i]=='R'? r++: s[i]=='G'? g++: b++;

  ll ans = r*g*b;

  /*
  int cntR = 0, cntG = 0, cntB = 0;
  rep(i, n) {
    if (s[i] == 'R') cntR++;
    else if (s[i] == 'G') cntG++;
    else if (s[i] == 'B') cntB++;
  }

  ll ans = cntR * cntG * cntB;
  */


  /*
  rep(i, n) {
    repI(j, i+1, n) {
      int k = 2*j - i;
      if (k >= n) break;
      if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) ans--;
    }
  }
  */
  for(int i=0; i<n-2; ++i){
		for(int d=1; d<=(n-1)/2; ++d){
			int j = i + d, k = j + d;
			if(k >= n) break;
			if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) ng++;
		}
	}

  cout << ans - ng << endl;

  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int qp(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
signed main()
{
	int n;
	cin>>n;
	cout<<((qp(10,n)-2*qp(9,n)+qp(8,n))%mod+mod)%mod;
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#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 MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

template <class T>
inline bool chmin(T& a, T b)
{
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T& a, T b)
{
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

typedef long long ll;

#define MAX_N 10000

struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;

vector<int> dx = { 1, 0, -1, 0 };
vector<int> dy = { 0, 1, 0, -1 };
typedef pair<int, int> P;

template <typename T>
T GCD(T x, T y)
{
    return (y ? GCD<T>(y, x % y) : x);
}

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank;

    UnionFind(int n = 1)
    {
        init(n);
    }

    void init(int n = 1)
    {
        par.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int root(int x)
    {
        if (par[x] == x) {
            return x;
        } else {
            int r = root(par[x]);
            return par[x] = r; // 辺の縮約（一度根をたどったら辺を直接根に向かって貼り直す）
        }
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (rank[x] < rank[y])
            swap(x, y);
        if (rank[x] == rank[y])
            ++rank[x];
        par[y] = x; // xよりyのほうが高さが小さい木
        return true;
    }
};

// railwayとroadそれぞれについてunion-find treeを用意し，どちらでもis-sameなcityの数を求める
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    rep(i, N)
    {
        cin >> p.at(i);
        p.at(i)--;
    }

    UnionFind exchange(N);
    rep(i, M)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        exchange.merge(x, y);
    }

    int ans = 0;
    int ord = 0;
    rep(i, N)
    {
        if (i == p.at(i))
            ord++;
        if (exchange.root(i) == exchange.root(p.at(i)))
            ans++;
    }

    cout << max(ord, ans) << endl;
}

Measured memory_bytes: 1408
#import  sys
#input=sys.stdin.readline
#sys.setrecursionlimit(1000000)
mod=int(1000000007)
#I=lambda: map(int,input().split())

def bm(n,p):
    n,p=int(n),int(p)
    if p==0:
        return 1
    x=bm(n,p/2)
    x=(x*x)%mod
    if p%2==1:
        x=(x*n)%mod
    return x

dp=[0]*(100000+2)
ans=0
n,k=map(int,input().split())

for i in range(k,0,-1):
    dp[i]=bm(k/i,n)
    for j in range(i*2,k+1,i):
        dp[i]=(dp[i]-dp[j]+mod)%mod
    ans=ans+dp[i]*i;
    ans%=mod
print(ans)


Measured memory_bytes: 76676
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s1 = "RUD";
    string s2 = "LUD";
    string s;
    cin >> s;
    int oe = 0;
    for(char c : s){
        bool f = false;
        if(oe==0){
            REP(i,3){
                if(c==s1[i]){
                    f=true;
                }
            }
            if(!f){
                cout << "No\n";
                return 0;
            }
        }else{
            REP(i,3){
                if(c==s2[i]){
                    f=true;
                }
            }
            if(!f){
                cout << "No\n";
                return 0;
            }
        
        }
        oe = 1-oe;
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;

int main(){

    ll l,r;
    cin >> l >> r;

    ll asize = r-l+1;
    if(asize>=2019){
        cout << 0 << endl;
        return 0;
    }


    vector<ll> A(asize);

    for(int i= 0; i< asize; i++){
        A.at(i) = l+i;
    }
    
    for(int i= 0; i< asize; i++){
        A.at(i) = A.at(i)%2019;
    }

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

    ll modmin = 2019;
    ll cmodmin;
    for(int i = 0; i< asize; i++){
        for(int j = i+1; j< asize; j++){
            cmodmin = (A.at(i)*A.at(j))%2019;
            if(modmin>cmodmin){
                modmin = cmodmin;
            }
        }
    }
    cout << modmin << endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
XYZ=[list(map(int,input().split())) for _ in range(n)]

ans=0
for i in (-1,1):
    for j in (-1,1):
        for k in (-1,1):
            A=sorted([i*x+j*y+k*z for x,y,z in XYZ],reverse=True)
            ans=max(ans,sum(A[:m]))

print(ans)

Measured memory_bytes: 3316
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        double ans = 0;
        for (int i = 1; i <= n; i++) {
            int x = i;
            int count = 0;
            while (true) {
                if (x < k) {
                    x = x << 1;
                    count++;
                } else {
                    break;
                }
            }
            ans += Math.pow(0.5, count) / n;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll n, k, m, M = 1e9 + 7;

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

    int n;
    cin >> n;

    int x = n / 1.08;

    if((int)(x * 1.08) == n) {
        cout << x << endl;
    } else if((int)((x + 1) * 1.08) == n) {
        cout << x + 1 << endl;
    } else {
        cout << ":(" << endl;
    }
}


Measured memory_bytes: 3632
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd
n = ni()
A = list(ma())
q = ni()
co = collections.Counter(A)
s = sum(A)
for i in range(q):
    b,c = ma()
    s = s - co[b]*b +co[b]*c
    co[c] +=co[b]
    co[b] = 0
    print(s)


Measured memory_bytes: 24140
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define  pb push_back
#define  pob pop_back
#define mp make_pair
#define db long double
#define up upper_bound
#define lb lower_bound
#define pll pair<ll,ll>
#define vll vector<ll>
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define sz(x) (int)x.size()
#define endl '\n'
#define int long long
#define mod 1000000007
#define MAX 100005
using namespace std;
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
 
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
 
    ll n;
    cin >> n;
    string a,b;
    string ans;
    cin >> a>> b;
    rep(i,0,n){
    	ans.pb(a[i]); ans.pb(b[i]);
    }
    cout << ans;
    
    return 0;
 
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int a;
	int ans = 0;
	int mini = 10;
	for(int i = 0; i < 5; i++){
		cin >> a;
		ans += (a/10 + (a%10 != 0))*10;
		if(a%10)
			mini = min(mini, a%10);
	}

	cerr << mini << endl;
	cout << ans - (10-mini) << endl;


	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

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

  int result=0;
  rep(x, n){
    bool f=true;
    rep(i, n-1)for(int j=i+1; j<n; j++){
      int by=i,bx=j;
      int cy=by, cx=(bx+x)%n;
      int rcy=(by+x)%n, rcx=bx;
//if(x==2)cout<<i<<','<<j<<' '<<cy<<','<<cx<<' '<<rcy<<','<<rcx<<' '<<s[cy][cx]<<','<<s[rcx][rcy]<<endl;
      if(s[cy][cx]!=s[rcx][rcy])f=false;
    }
    if(f)result++;
  }

  cout<<result*n<<endl;

  return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
    /* Dear Judge :i Tried Hard for Solving this problem
      please accept My solution I will remain grateful for that */
#define ON(x, k)    ((x)|(1<<(k)))
#define isOn(x, k)    ((x)&(1<<(k)))
//#define isOn(x, k)    ((x>>k)&1)
#define OFF(x, k)   ((x)&(~(1<<(k))))
#define TOGGLE(x, k)   ((x)^(1<<(k)))

    using namespace std ;
    int const c =1e4+5;
    int A[c];
     int main (){


    int n ;
    cin >> n ;
 for(int i = 0 ;i < n ;++i )
    cin >> A[i];
 sort(A,A+n);
 cout << A[n-1]-A[0];
   /* int n , d ;
    cin >> n >> d ;
    if(n<1)
     cout << d;
    else
    cout << d*pow(100,n);
     */return 0;
     }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cstdlib>
using namespace std;


int main(){
	string N;	// 0 - 10^200,000
	bool judge = false;
	cin >> N;
	
	int sum = 0;
	for(long unsigned i=0; i<N.size(); i++){
		sum += (N[i] - '0');
		sum = (sum % 9);
	}
	if((sum % 9) == 0) judge = true;
	
	cout << (judge ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 3660
let print_a_rectangle h w =
  let buf = Buffer.create 256 in
  let ws = String.make w '#' in
  let rec loop i =
    if i = h then Buffer.contents buf
    else (Buffer.add_string buf ws; Buffer.add_char buf '\n'; loop (i+1))
  in print_endline (loop 0)

let () =
  let rec loop () =
    let line = read_line () in
    let h,w = Scanf.sscanf line "%d %d" (fun h w -> h,w) in
    if (h,w) = (0,0) then ()
    else loop (print_a_rectangle h w);
  in loop ()

Measured memory_bytes: 2360
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    int A,B,C;
    cin >> A >> B >> C;
    if(B*C < A) fin("No");
    else fin("Yes");
    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    string s;
    cin >> s;

    int cnt = 0;
    REP(i, s.size())
    {
        if (s[i] == 'W')
            cnt++;
    }

    if (cnt == 0 || cnt == s.size())
    {
        cout << 0 << endl;
        return 0;
    }

    ll res = 0;

    int i = 0;
    int b = 0;
    while (i < s.size())
    {
        if (s[i] == 'W')
        {
            res += b;
        }
        else
        {
            b++;
        }
        i++;
    }

    cout << res << endl;

    return 0;
}

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

int main() {
    int l,r;cin>>l>>r;
    r=min(r,l+2019);
    int mn=2019;
    for (int i=l;i<r;i++)
        for (int j=i+1;j<=r;j++)
            mn=min(mn,i%2019*(j%2019)%2019);
    cout<<mn<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
int dp[1000001][2];
 
int main() {
  string s; cin >> s;
  int n = s.size();
  vector<int> ld(n);
  for (int i = 0; i < n; ++i) {
    ld[i] = s[i]-'0';
  }
  dp[0][1] = 1;
  for (int i = 0; i < n; ++i) {
    int d = ld[i];
    dp[i+1][0] = min(dp[i][0]+d, dp[i][1]+10-d);
    dp[i+1][1] = min(dp[i][0]+d+1, dp[i][1]+9-d);
  }
  cout << dp[n][0] << endl;
  return 0;
}

Measured memory_bytes: 13060
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

int main(){

  int n;
  cin >> n;

  for(int i=1; i<10;i++){
    for(int j=1; j<10; j++){
      if(n==i*j) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

};


Measured memory_bytes: 256
#include <stdio.h>

int N;
int coin[6] = { 500,100,50,10,5,1 };
int ans = 0;

int main(void) {
	while (true) {
		scanf("%d", &N);
		if (N == 0) { break; }

		ans = 0;
		int res = 1000 - N;
		while (res != 0) {
			if (res >= 500) {
				ans += res / 500;
				res -= 500 * (res / 500);
			}
			else if (res >= 100) {
				ans += res / 100;
				res -= 100 * (res / 100);
			}
			else if (res >= 50) {
				ans += res / 50;
				res -= 50 * (res / 50);
			}
			else if (res >= 10) {
				ans += res / 10;
				res -= 10 * (res / 10);
			}
			else if (res >= 5) {
				ans += res / 5;
				res -= 5 * (res / 5);
			}
			else { ans += res; res = 0; }
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vl A, B;
void input() {
    cin>>n;
    cin>>S;
}
void solve() {
    a=0;
    rep(i,n){
        if(S[i]=='R')a++;
    }

    rep(i,n){
        if(i<a&&S[i]=='W')ans++;
        if(i>=a&&S[i]=='R')ans++;
    }

    print(ans/2);
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

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

using namespace std;

int n,m;
int a[10];
bool ok=1;

int main()
{
	scanf("%d%d",&n,&m);
	memset(a,0,sizeof(a));
	int tmp1,tmp2;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&tmp1,&tmp2);
		if(tmp1==1&&tmp2==0&&n>=2)
		{
			ok=0;
		}
		if(a[tmp1]==0||a[tmp1]==tmp2)
		{
			a[tmp1]=tmp2;
			continue;
		}
		ok=0;
	}
	if(ok)
	{
		for(int i=1;i<=n;i++)
		{
			if(i==1&&a[i]==0&&n>=2)
			{
				cout<<"1";
			}
			else
			{
				cout<<a[i];
			}
		}
		cout<<endl;
	}
	else
	{
		cout<<"-1"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*
    Ujjawal Pabreja [cuber_coder]
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll              long long
#define ld              long double
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define in              insert
#define ff              first
#define ss              second
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define rev             reverse
#define Y				"YES"
#define N 				"NO"
#define endl            "\n"
#define debug(x)        cout << #x << " : " << x << nl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

// ====== BigInt begins ======
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// ====== BigInt ends ======

// ====== PBDS begins ======
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, 
//         tree_order_statistics_node_update> 
//         pbds; 
// ====== PBDS ends ======

// ====== Useful functions begin ======
inline ll add(ll a,ll b) {return ((a % mod) + (b % mod)) % mod;}
inline ll sub(ll a,ll b) {return ((a % mod) - (b % mod) + mod) % mod;}
inline ll mul(ll a,ll b) {return ((a % mod) * (b % mod)) % mod;}
ll pwr(ll x,ll n){
    if(n == 0){
        return 1;
    }
    if(n&1){
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    } else {
        return pwr(mul(x, x), n / 2);
    }
}
ll modInv(ll n){ 
    return pwr(n, mod - 2); 
}
ll gcd(ll a,ll b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
// ====== Useful functions end ======
 
// ====== Variables begin ======

// ====== Variables end ======
void speed_solve(){
    ll n;
    cin >> n;
    ll a, cnt = 0;
    rep(i,n){
        cin >> a;
        if(!(i&1) and a&1) cnt++;
    }
    cout << cnt;
}

int main(){
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  if (A >= 13) {
  	cout << B << endl;
  } else if (A >= 6 && A <= 12) {
  	cout << B / 2 << endl;
  } else {
  	cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void solve () {
    int n;
    cin >> n;
    long long int x = 1;
    long long int y = 1;
    for (int i = 0; i < n; i++) {
        long long int a, b;
        cin >> a >> b;
        long long p  = ( a + x - 1ll) / a;
        long long p2 = (b + y - 1ll) / b;
        p = max (p, p2);
        x = a * p, y = p * b;
    }
    cout << x + y;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3656