akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String S = in.next();
			long tmp = 0;
			long ans = 0;
			for(int i = 0; i < S.length(); i++) {
				if(S.charAt(i) == 'W') {
					ans += tmp;
				}else {
					tmp++;
				}
			}
			out.println(ans);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 26836
import sys
sys.setrecursionlimit(100002)
n=int(input())
point=[]
answer=[]
already=[]
for i in range(n):
    point.append([])
    answer.append(0)
    already.append(0)
for i in range(n-1):
    u,v,w=map(int,input().split())
    point[u-1].append((v-1,w))
    point[v-1].append((u-1,w))
def dfs(now,c):
    answer[now]=c
    already[now]=1
    for i in point[now]:
        if already[i[0]]==1:
            pass
        else:
            if i[1]%2==0:
                dfs(i[0],c)
            else:
                if c==0:
                    dfs(i[0],1)
                else:
                    dfs(i[0],0)
dfs(0,0)
for i in answer:
    print(i)


        


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

int64_t mod=1e9+7;
map<int64_t,map<int64_t,int64_t>> cache;
int64_t rec(int64_t s,int64_t x){
    if(cache[s].find(x)!=cache[s].end()) return cache[s][x];
    return cache[s][x]=(rec(s/2,x/2)+(s-1>=0 and x-1>=0?rec((s-1)/2,(x-1)/2):0)+(s-2>=0?rec((s-2)/2,x/2):0))%mod;
}

void solve(){
    int64_t n;
    cin >> n;
    cache[0][0]=1;
    cout << rec(n,n) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#define debug(...) fprintf(stderr,__VA_ARGS__)

using namespace std;

inline char nc(){ static char buf[1000000] ,*p1,*p2;return p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,100000,stdin),p1 == p2) ? EOF : *p1++;}
template<class T>inline void rd(T & x){ x = 0;char ch = nc();for(;!isdigit(ch);ch = nc()); for(;isdigit(ch);ch = nc())x = x * 10 - 48 + ch;}
const int maxn = 1e6 + 10;
typedef long long ll;
int a[maxn];
int main(){
    int n;
    rd(n);
    for(int i = 1;i <= n;i++){
        rd(a[i]);
    }
    ll ans = 0;
    if(a[1]) return !printf("-1");
    for(int i = 2;i <= n;i++){
        if(a[i] - a[i - 1] > 1) return !printf("-1");
    }
    for(int i = 2;i <= n;i++){
        ans++;
        if(a[i] != a[i - 1] + 1)ans += a[i] - 1;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>

int main() {
  using namespace std;

  int N;
  cin >> N;

  char S[100];
  for (int i=0; i<N; i++) {
    cin >> S[i];
  }

  char R[4] = {0};
  for (int i=0; i<N; i++) {
    if (S[i] == 'P') {
      R[0] = 1;
    }
    if (S[i] == 'W') {
      R[1] = 1;
    }
    if (S[i] == 'G') {
      R[2] = 1;
    }
    if (S[i] == 'Y') {
      R[3] = 1;
    }
  }

  int sum = 0;
  for (int i=0; i<4; i++) {
    if (R[i] == 1) {
      sum++;
    }
  }

  cout << (sum == 3 ? "Three" : "Four") << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  cout << char(s1[0]-'a'+'A') << char(s2[0]-'a'+'A')<<char(s3[0]-'a'+'A')<<endl;
}

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

int main(void){
    int d, g, ans = 1100000;
    cin >> d >> g;
    vector<int> p(d+10), c(d+10);
    g /= 100;
    for(int i=1;i<=d;++i){
        cin >> p[i] >> c[i];
        c[i] /= 100;
    }
    for(int i=0;i<(1<<d);++i){
        int sum = 0, cnt=0;
        for(int j=1;j<=d;++j){
            if(i & (1 << (j-1))){
                sum += j*p[j]+c[j];
                cnt += p[j];
            }
        }
        int tmp = 1000000000;
        if(sum < g){
            for(int j=1;j<=d;++j){
                if(!(i & (1 << (j-1)))){
                    if((g-sum+j-1)/j <= p[j]){
                        tmp = min(tmp, (g-sum+j-1)/j);
                    }
                }
            }
            cnt += tmp;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//数取得
		String S = sc.next();
		sc.close();
		
		int answer = 0; 
		ArrayList<Character> charList = new ArrayList<>();
		
		for(int i = 0; i < S.length(); i++) {
			charList.add(S.charAt(i));
		}
		
		if(charList.get(0) == 'R') {
			if(charList.get(1) == 'R') {
				if(charList.get(2) == 'R') {
					answer = 3;
				}else {
					answer = 2;
				}
			}else {
				answer = 1;
			}
		}else {
			//最初がＳ
			if(charList.get(1) == 'R') {
				if(charList.get(2) == 'R') {
					answer = 2;
				}else {
					answer = 1;
				}
			}else {
				if(charList.get(2) == 'R') {
					answer = 1;
				}
			}
		}
		
		System.out.println(answer);
	}

}


Measured memory_bytes: 26992
from sys import stdin
readline = stdin.buffer.readline
def r_map(): return map(int, readline().rstrip().split())
def r_list(): return list(r_map())

def main():
    N = int(readline().rstrip())
    A = r_list()
    M = max(A)
    d = [0] * (M + 1)
    g = True
    for a in A:
        d[a] += 1
    for i in range(2, M + 1):
        c = sum(d[i::i])
        if c == N:
            print("not coprime")
            exit()
        elif c > 1:
            g = False
    if g:
        print('pairwise coprime')
    else:
        print('setwise coprime')

if __name__ == "__main__":
    main()


Measured memory_bytes: 190948
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


class UnionFind:
    def __init__(self, node: int) -> None:
        self.n = node
        self.par = [i for i in range(self.n)]
        self.rank = [0 for i in range(self.n)]

    def find(self, x: int) -> int:
        if x == self.par[x]:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> bool:
        if self.isSame(x, y):
            # print("x and y has already united")
            return False

        rx = self.find(x)
        ry = self.find(y)

        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = self.par[ry]
        else:
            self.par[ry] = self.par[rx]

            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

        return True

    def isSame(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)


from collections import defaultdict

n, k, l = li()

road = [li_() for _ in range(k)]
rail = [li_() for _ in range(l)]

uf_road = UnionFind(n)
uf_rail = UnionFind(n)

for pi, qi in road:
    uf_road.unite(pi, qi)

for ri, si in rail:
    uf_rail.unite(ri, si)

for i in range(n):
    uf_road.find(i)
    uf_rail.find(i)

dic = defaultdict(int)

for road_par, rail_par in zip(uf_road.par, uf_rail.par):
    dic[(road_par, rail_par)] += 1

ans = []
for i in range(n):
    ans.append(dic[(uf_road.par[i], uf_rail.par[i])])

print(*ans)



Measured memory_bytes: 167432
#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 <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <valarray>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>

using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import heapq
def main():
    n, m = list(map(int, input().split()))
    t = list(map(int, input().split()))
    t = list(map(lambda x: x*(-1), t))
    heapq.heapify(t)
    while m > 0:
        v = heapq.heappop(t) * -1
        heapq.heappush(t, (v // 2)* -1)
        m -= 1

    print(sum(t)*-1)


if __name__ == '__main__':
    main()

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

class UnionFind{
public:
  vector<int> par, rank;
public:
  UnionFind(int n, const VL& xs){
	par.assign(n, 0);
	rank.assign(n, 0);
	for(int i=0;i<n;++i){
	  par[i] = i;
	}
  }

  //find root of x
  int find(int x){
	if(par[x] == x)
	  return x;

	int p = find(par[x]);
	par[x] = p;
	return p;
  }

  void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(rank[x] < rank[y]){
	  par[x] = y;
	}
	else{
	  par[y] = x;
	  if(rank[x] == rank[y])
		++rank[x];
	}
  }

  bool same(int x, int y){
	return find(x) == find(y);
  }
};

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

  int N, M;
  cin >> N >> M;
  VL xs(N);
  cin >> xs;

  UnionFind uf(N, xs);
  REP(i,M){
	int x, y;
	cin >> x >> y;
	uf.unite(x, y);
  }

  VVL xss(N);
  REP(i,N){
	int g = uf.find(i);
	xss[g].PB(xs[i]);
  }
  REP(i,N) if(!xss[i].empty()) SORT(xss[i]);
  sort(ALL(xss), [](const VL& l, const VL& r){ return SZ(l) > SZ(r); });

  LL ans = 0;
  using D = pair<LL,PII>;
  priority_queue<D, vector<D>, greater<D>> pq;
  int i;
  for(i=0;i<N;++i)
	if(!xss[i].empty()){
	  pq.push(MP(xss[i][0], MP(i,1)));
	  break;
	}
  for(i=i+1;i<N;++i){
	if(xss[i].empty()) continue;
	if(pq.empty()){
	  cout << "Impossible" << endl;
	  return 0;
	}

	auto tp = pq.top();
	pq.pop();
	ans += tp.FF + xss[i][0];

	if(tp.SS.SS < SZ(xss[tp.SS.FF]))
	  pq.push(MP(xss[tp.SS.FF][tp.SS.SS], MP(tp.SS.FF, tp.SS.SS+1)));
	if(SZ(xss[i]) > 1)
	  pq.push(MP(xss[i][1], MP(i,2)));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7296
#include <iostream>

using namespace std;

typedef long long ll;

int n;
string s;

int n1, n2;
char c1[50], c2[50];

ll d[50][50];

ll calc2() {
    for (int u1 = 0; u1 <= n1; u1++) {
    	for (int u2 = 0; u2 <= n2; u2++) {
    		int p = n-1+u1+u2;
    		d[u1][u2] = u1+u2 == 0;
    		if (u1 > 0 && s[p] == c1[n1-u1]) d[u1][u2] += d[u1-1][u2];
    		if (u2 > 0 && s[p] == c2[n2-u2]) d[u1][u2] += d[u1][u2-1];
    	}
    }
    return d[n1][n2];
}

int main() {
	cin >> n;
	cin >> s;
	ll t = 0;
	for (int b = 0; b < (1<<n); b++) {
		n1 = n2 = 0;
		for (int i = 0; i < n; i++) {
			if (b&(1<<i)) c1[n1++] = s[i];
			else c2[n2++] = s[i];
		}
		t += calc2();
	}
	cout << t << "\n";
}


Measured memory_bytes: 256
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

class Binary_Indexed_Tree:
    #Binary_Indexed_Tree
    #A1 ... AnのBIT(1-indexed)
    def __init__(self,n):
        self.N = n
        self.BIT = [0]*(n+1)
        self.l2 = 2**(len(format(n,'b'))-1)

    #A1 ~ Aiまでの和 O(logN)
    def query(self,idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def update(self,idx,x):
        while idx <= self.N:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return

    def lower_bound(self,w):
        if w <= 0:
            return 0
        x = 0
        k = self.l2
        while k > 0:
            if x+k <= self.N and self.BIT[x+k] < w:
                w -= self.BIT[x+k]
                x += k
            k //= 2
        return x+1

    def upper_bound(self,w):
        x = 0
        k = self.l2
        while k > 0:
            if x+k <= self.N and self.BIT[x+k] <= w:
                w -= self.BIT[x+k]
                x += k
            k //= 2
        return x


def main():
    n,m = map(int,ipt().split())
    nms = []
    for i in range(m):
        a,b = map(int,ipt().split())
        nms.append(b*(10**6)+a)
    nms.sort()

    ans = 0
    bt = Binary_Indexed_Tree(n)

    for i in nms:
        a = i%(10**6)
        b = i//(10**6)
        if bt.query(b)-bt.query(a):
            continue
        else:
            bt.update(b,1)
            ans += 1

    print(ans)



    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 79960
#include <iostream>
#include <cmath>

int main() {

   int N;
   unsigned long A;
   unsigned long ans = 1;
   unsigned long th_val = (unsigned long)std::pow(10, 18);
   int check = 0;
   int zero_check = 0;
   
   std::cin >> N;
   
   for (int i = 0; i < N; i++) {
      std::cin >> A;
      
      if (ans > (double)th_val/A) {
         check = 1;
      }
      if (A == 0) {
         zero_check = 1;
      }
      
      ans *= A;
      
   }
   
   if (zero_check == 1) {
      std::cout << 0 << std::endl;
   }
   else if (ans > th_val || check == 1) {
      std::cout << -1 << std::endl;
   }
   else {
      std::cout << ans << std::endl;
   }

  return 0;
  
}


Measured memory_bytes: 3184
import collections
# import time
#start = time.time()



x=int(input())
a=list(map(int,input().split()))
 
c=collections.Counter(a)
#print(c)

num=0
for i in c.values():
    num += i*(i-1)/2
    
for i in range(x):
    print(int(num-c[a[i]]+1))

Measured memory_bytes: 26780
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}



int main() {
	//int a, b, c,d; cin >> a;
	//string s,t,u; cin >> s>>t>>u;
	vector<int> n(3);
	for (int i = 0; i < 3; i++) {
		cin >> n[i];
	}
	ssort(n);
	if (n[0] == 5 && n[1] == 5 && n[2] == 7)cout << "YES";
	else cout << "NO";
	

	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

vector<bool> eratosthenes_sieve(size_t size) {
  vector<bool> is_prime(size + 1, true);
  for (size_t i = 0; i <= size; i++) {
    if (i < 2) {
      is_prime[i] = false;
    } else if (is_prime[i]) {
      for (size_t j = 2 * i; j <= size; j += i) {
        is_prime[j] = false;
      }
    }
  }
  return move(is_prime);
}

int main() {
  int64_t N, P;
  cin >> N >> P;

  const int64_t R = ceil(sqrt(P));
  auto is_prime = eratosthenes_sieve(R);

  using F = pair<int64_t, int>;
  vector<F> factor;
  for (int64_t d = 2; d * d <= P; d++) {
    if (is_prime[d]) {
      int cnt = 0;
      while (P % d == 0) {
        P /= d;
        cnt++;
      }
      if (cnt > 0) {
        factor.push_back(F(d, cnt));
      }
    }
  }
  factor.push_back(F(P, 1));

  int64_t result = 1;
  for (auto f : factor) {
    int64_t p;
    int e;
    tie(p, e) = f;
    rep(i, e / N) { result *= p; }
  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
ll mod=1e9+7;
int main()
{
    string s,t;
    cin>>s>>t;
    int n=s.length();
    int m=t.length();
    string ans;
    for(int i=n-m;i>=0;i--)
    {
        int flag=0;
        for(int j=0;j<m;j++)
        {
            if(s[i+j]=='?')
            continue;
            if(s[i+j]!=t[j])
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            for(int j=0;j<m;j++)
            {
                s[i+j]=t[j];
            }
            for(int k=0;k<n;k++)
            {
                if(s[k]=='?')
                s[k]='a';
            }
            cout<<s<<endl;
            return 0;
        }
    }
    cout<<"UNRESTORABLE";
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define V vector<int>
#define COUT(x) cout<<(x)<<endl
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))




signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h, w; cin >> h >> w;
	int ans = h * w;
	rep(k, 2) {
		for (int i = 1; i < h; i++) {
			int s1 = i * w; int s2 = (h - i)*(w / 2);
			int s3 = h * w - s1 - s2;
			int tmp = max(max(s1, s2), s3) - min(min(s1, s2), s3);
			ans = min(ans, tmp);
		}
		swap(h, w);
	}
	ans = min(ans, h); ans = min(ans, w);
	if (h % 3 == 0 || w % 3 == 0)ans = 0;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
list=[]
W,H,N=map(int,input().split())
for a in range(N):
    x,y,a=map(int,input().split())
    list.append([x,y,a])
yoko=[d for d in range(W+1)]
tate=[e for e in range(H+1)]
for f in range(N):
    if list[f][2]==1:
        yoko=[g for g in yoko if g>=list[f][0]]
    elif list[f][2]==2:
        yoko=[h for h in yoko if h<=list[f][0]]
    elif list[f][2]==3:
        tate=[i for i in tate if i>=list[f][1]]
    else:
        tate=[j for j in tate if j<=list[f][1]]
if len(yoko)==0 or len(tate)==0:
    print(0)
else:
    nyoko = max(yoko) - min(yoko)
    ntate = max(tate) - min(tate)
    print(ntate * nyoko)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    ll N;
    cin >> N;
    int ans[40], en;
    rep(i, 40){
        if(N != 2*(N/2)){
            ans[i] = 1;
            if(i%2 == 0) N -= 1;
            else N += 1;
        }
        else ans[i] = 0;
        N /= 2;
        if(N == 0){
            en = i;
            break;
        }
    }
    rep3(i, en, 0) cout << ans[i];
    cout << endl;
}

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

const int SIZ = 4005, MAXN = 1e5 + 5;

long long pref[SIZ][SIZ], numBlack;
long long n, k, x[MAXN], y[MAXN];
string c[MAXN];
long long ans;

long long getBlock(int l, int d, int r, int u){
	long long sum = pref[r][u];
	if(l > 0){
		sum -= pref[l-1][u];
	}
	if(d > 0){
		sum -= pref[r][d-1];
	}
	if(l > 0 && d > 0){
		sum += pref[l-1][d-1];
	}
	return sum;
}

int main(){
	cin >> n >> k;
	k *= 2;
	for(int i = 0; i < n; ++i){
		cin >> x[i] >> y[i] >> c[i];
		if(c[i][0] == 'B'){
			numBlack++;
			pref[(x[i]%k) + (k/2)][(y[i]%k) + (k/2)]--;
		}else{
			pref[(x[i]%k) + (k/2)][(y[i]%k) + (k/2)]++;
		}
	}
	k /= 2;
	for(int i = 0; i < SIZ; ++i){
		for(int j = 0; j < SIZ; ++j){
			if(i)
				pref[i][j] += pref[i-1][j];
			if(j)
				pref[i][j] += pref[i][j-1];
			if(i && j)
				pref[i][j] -= pref[i-1][j-1];
		}
	}
	for(int i = k; i <= 2*k; ++i){
		for(int j = k; j <= 2*k; ++j){
			long long sum = getBlock(i, j, i+k-1, j+k-1);
			sum += getBlock(i+k, j+k, i+k+k-1, j+k+k-1);
			sum += getBlock(i-k, j+k, i-1, j+k+k-1);
			sum += getBlock(i+k, j-k, i+k+k-1, j-1);
			sum += getBlock(i-k, j-k, i-1, j-1);
			ans = max(ans, max(sum+numBlack, n-(sum+numBlack)));
		}
	}
	printf("%lld\n", ans);
}

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

int main(){
  int64_t X,Y;
  cin>>X>>Y;
  if(X%Y==0)
    cout<<-1<<endl;
  else
    for(int64_t i=0;i<1000000000000000000;i++)
      if(X*i%Y!=0){
        cout<<X*i<<endl;
        return 0;
      }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& x : a) cin >> x;
  int mn = *min_element(a.begin(), a.end());
  int mx = *max_element(a.begin(), a.end());
  ll ans = 0, sum = 0, sum2 = 0;
  for (auto x : a) sum += x, sum2 += x * x;
  for (int x = mn; x <= mx; ++x) {
    ll v = 1ll * n * x * x - 2 * x * sum + sum2;
    ans = (x == mn) ? v : min(ans, v);
  }
  cout << ans;
}

Measured memory_bytes: 256
h,w = map(int,input().split())

ans = 10**10

if h * w % 3 == 0:
    print(0)
    exit()

ans = min(ans,w,h)

for i in range(1,h//2+1):
    a = [w * i, (h - i) * (w // 2), (h - i) * (w // 2 + w % 2)]
    a.sort()
    ans = min(ans, a[2] - a[0])
for i in range(1, w//2+1):
    a = [h * i, (w - i) * (h // 2), (w - i) * (h // 2 + h % 2)]
    a.sort()
    ans = min(ans, a[2] - a[0])
print(ans)

Measured memory_bytes: 40940
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n,m,d;
	cin >> n >> m >> d;
	bool f[100][100] = {};
	rep(i,0,n){
		rep(j,0,m){
			char c;
			cin >> c;
			if( c == '#')
				f[i][j] = 1;
		}
	}
	
	int ans = 0;
	rep(i,0,n){
		rep(j,0,m-d+1){
			bool ff = 1;
			rep(k,j,j+d){
				if( f[i][k] ){
					ff = 0;
					break;
				}
			}
			if( ff )
				ans ++;
		}
	}

	//cout << ans << endl;

	rep(i,0,n-d+1){
		rep(j,0,m){
			bool ff = 1;
			rep(k,i,i+d){
				if( f[k][j] ){
					ff = 0;
					break;
				}
			}
			if( ff )
				ans ++;
		}
	}

	cout << ans << endl;
	ret 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

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

    int sum = 1;
    if (a >= b)
    {
        if (b == 1)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << 1 << endl;
        }
        return 0;
    }
    b -= a;
    sum += b / (a - 1);
    if (b % (a - 1) != 0)
    {
        sum++;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define msg(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define pri(a) cout << a << endl;

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

  // ll n,ans=0;
  // cin >> n;
  //ll n,k,ans=0;
  //cin >> n >> k;
  string s;
  cin >> s;

  if(s=="SUN"){
    cout << "7" << endl;
  }
  if(s=="MON"){
    cout << "6" << endl;
  }
  if(s=="TUE"){
    cout << "5" << endl;
  }
  if(s=="WED"){
    cout << "4" << endl;
  }
  if(s=="THU"){
    cout << "3" << endl;
  }
  if(s=="FRI"){
    cout << "2" << endl;
  }
  if(s=="SAT"){
    cout << "1" << endl;
  }



}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main(){
ll n,m;cin>>n>>m;
set<pair<ll ,ll> > v;
for(ll i=0;i<m;i++){
    ll a,b;cin>>a>>b;
    v.insert(make_pair(a,b));
}
for(ll i=1;i<n;i++){
   if(v.count(make_pair(1,i))&&v.count(make_pair(i,n))){cout<<"POSSIBLE";return 0;}
}
cout<<"IMPOSSIBLE";return 0;
}

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

#define long long long int
using namespace std;

// @author: pashka

vector<int> p, mxd;
vector<long> szc, szv;

int get(int x) {
    if (p[x] != x) p[x] = get(p[x]);
    return p[x];
}

void join(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
        p[x] = y;
        mxd[y] = max(mxd[x], mxd[y]);
        szv[y] += szv[x];
        szc[y] += szc[x];
    }
}

int main() {
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m), c(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
    }

    p.resize(n);
    mxd.resize(n);
    szv.resize(n);
    szc.resize(n);
    for (int i = 0; i < n; i++) {
        p[i] = i;
        szv[i] = 1;
    }
    for (int i = 0; i < m; i++) {
        mxd[a[i]]++;
    }

    for (int i = 0; i < m; i++) {
        join(a[i], b[i]);
        if (a[i] != b[i]) {
            szc[get(a[i])] += c[i] - 1;
        }
    }

    vector<long> cycles;
    vector<long> loops;
    long curc = 0;
    vector<vector<long>> alll(n);
    vector<long> curl;

    int res = m;
//    cout << res << "\n";

    for (int i = 0; i < m; i++) {
        if (a[i] == b[i]) {
            res--;
//            cout << i << " " << a[i] << " " << b[i] << " " << res << "\n";
            int x = get(a[i]);
            if (c[i] > 1)
                alll[x].push_back(c[i] - 1);
        }
    }

    for (int i = 0; i < n; i++) {
        if (p[i] == i) {
            if (mxd[i] == 1) {
                if (szv[i] == 1) {
                    loops.insert(loops.end(), alll[i].begin(), alll[i].end());
                } else {
                    cycles.push_back(szc[i]);
                }
            } else {
                curc += szc[i];
                curl.insert(curl.end(), alll[i].begin(), alll[i].end());
            }
        }
    }

    sort(cycles.rbegin(), cycles.rend());
    sort(curl.rbegin(), curl.rend());
    sort(loops.rbegin(), loops.rend());

    while (loops.size() > 0 && loops.back() == 1) loops.pop_back();
    for (auto &x : loops) x--;

    int cc = 0;
    int startc = curc;
    for (long x : cycles) {
        if (curc == 0) {
            cc++;
            curc++;
        }
        res++;
        curc--;
        curc += x;
    }

    if (cc == 0) {
        cout << res << "\n";
        return 0;
    }

    long s1 = 0;
    int n1 = curl.size();
    for (auto x : curl) s1 += x;
    long s2 = 0;
    int n2 = 0;

    int res2 = INT_MAX;
    while (true) {
        if (startc == 0 && n1 == 0) break;
        while (n2 < loops.size() && s1 + s2 < cc) {
            s2 += loops[n2];
            n2++;
        }
        if (s1 + s2 >= cc) {
            res2 = min(res2, res + n1 + 2 * n2);
        }
        if (n1 == 0) {
            break;
        }
        s1 -= curl[n1 - 1];
        n1--;
    }

    if (res2 == INT_MAX) {
        cout << -1 << "\n";
    } else {
        cout << res2 << "\n";
    }


    return 0;
}

Measured memory_bytes: 11088
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<vector<long long int>> vvint;
typedef vector<string> vstr;
typedef long long int llint;

llint gcd(llint x, llint y){
	while (y != 0){
		if (x > y){
			llint r = x%y;
			x = y;
			y = r;
		}
		else {
			llint r = y%x;
			y = r;
		}
	}
	return x;
}

int main(void) {
	int longs;
	string s;
	cin >> s;
	longs = s.length();

	for (int i = 0; i < longs; i += 2){
		cout << s[i];
	}
	cout << endl;
}


Measured memory_bytes: 512
main :: IO()
main = do
    [a, b, h, m] <- map read . words <$> getLine
    let angle = abs ( (30.0 * h + 0.5 * m) - ( 6.0 *  m) ) * (pi / 180.0)

    print $ sqrt(a ^ 2 + b ^ 2 - 2 * a * b * (cos angle))


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

long long dp[401][401];
int a[401];
long long pref[401];

void solve()
{
  int n; cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    dp[i][i] = a[i];
    if (i == 0) pref[i] = a[i];
    else pref[i] = pref[i - 1] + a[i];
  }
  
  for (int len = 2; len <= n; len++)
  {
    for (int i = 0; i + len - 1 < n; i++)
    {
      int j = i + len - 1;
      dp[i][j] = 4e18;
      for (int mid = i; mid <= j; mid++)
      {
          long long calc = dp[i][mid] + dp[mid + 1][j];
          if (i != mid)
          {
              calc += pref[mid];
              if (i != 0) calc -= pref[i - 1]; 
          }
          if (mid + 1 != j)
          {
              calc += pref[j];
              calc -= pref[mid];
          }
          dp[i][j] = min(dp[i][j], calc);
      }
    }
  }
  
  cout << dp[0][n - 1] << endl;
}

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

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

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

  int h, m, s;

  h = S / 3600;
  m = (S%3600)/60;
  s = (S%3600)%60;

  cout << h << ":" << m << ":" << s << endl;
}



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

void solve(){

}

int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    unsigned long long ans = 0;
    vector<unsigned long long> a(10000001,2);
    a[1]=1;
    for(int i=2;i*i<=10000000;i++){
        for(int j=i;j*i<=10000000;j++){
            if(j==i) ++a[i*j];
            else ++++a[j*i];
        }
    }
    for(unsigned long long i=1;i<=n;i++){
        ans += i*a[i];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 81340
N=int(input())
ac,wa,tle,re=0,0,0,0
for i in range(N):
    s=input()
    if s=='AC': ac+=1
    if s=='WA': wa+=1
    if s=='TLE': tle+=1
    if s=='RE': re+=1
print('AC x '+str(ac))
print('WA x '+str(wa))
print('TLE x '+str(tle))
print('RE x '+str(re))

Measured memory_bytes: 9132
#include <iostream>

using namespace std;

#define MAX_N 100

int n;
char s[MAX_N];

void solve()
{
    string ans = "Three";
    for (int i = 0; i < n; i++) {
        if (s[i] == 'Y') ans = "Four";
    }

    cout << ans << endl;
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        cin >> s[i];

    solve();

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
int read()
{
    char s;
    int k=0,base=1;
    while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
    if(s==EOF)exit(0);if(s=='-')base=-1,s=getchar();
    while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
    return k*base;
} 
void write(int x)
{
    if(x<0){putchar('-');write(-x);}
    else{if(x/10)write(x/10);putchar(x%10+'0');}
}
int n;
int a[10][300];
int dp[10][300]; 
int main()
{
	n=read();
	for (int j=1;j<=2;j++)
		for (int i=1;i<=n;i++)
		a[j][i]=read();
	for (int i=1;i<=2;i++)
		for (int j=1;j<=n;j++)
		{
			dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];
		}
	printf("%d\n",dp[2][n]);
	return 0;
} 

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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long
#define ld long double

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const int mod = 1e9 + 7;
const int MAXN = 5e5 + 5;

struct SuperSet{
    int k;
    ll sum = 0;
    multiset<int> s;
    SuperSet(int k) : k(k) {}
    void insert(int x) {
        if ((int)s.size() < k) {
            sum += x;
            s.insert(x);
            return;
        }
        if (*s.begin() < x) {
            sum -= *s.begin();
            s.erase(s.begin());
            s.insert(x);
            sum += x;
        }
        return;
    }
    ll get() {
        return sum;
    }
};

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c);
    for (auto &l : p) cin >> l;
    for (auto &l : q) cin >> l;
    for (auto &l : r) cin >> l;
    sort(all(p));
    sort(all(q));
    sort(all(r));
    reverse(all(p));
    reverse(all(q));
    reverse(all(r));
    SuperSet s(y);
    for (auto &l : q) s.insert(l);
    ll sump = 0, ans = 0;
    int j = c - 1;
    vector<ll> pr(c + 1);
    for (int i = 0; i < c; i++) pr[i + 1] = pr[i] + r[i];
    for (int i = 0; i <= x; i++) {
        if (i > 0) sump += p[i - 1];
        if (x - i > c) continue;
        while (j >= x - i) {
            s.insert(r[j]);
            j--;
        }
        ans = max(ans, sump + s.get() + pr[x - i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 9516
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n,k;
	cin>>n>>k;
	vector <ll> v(n);
	for(ll i=0;i<n;i++)
	{
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	bool check[k+1];
	memset(check,false,sizeof check);
	check[0]=1;
	for(int i=1;i<=k;i++)
	{
		for(int j=0;j<v.size();j++)
		{
			if(v[j]>i)
			break;
			if(v[j]==i)
			{
				check[i]=true;
			}
			else
			check[i]=check[i] or !check[i-v[j]];
		}
	}
	if(check[k])cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}

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

int main() {
  /*
  long N;
  cin>>N;
  string S;
  cin>>S;
  vector<long> r;
  for(int i=N-1;i>=0;i--){
    if(S[i]=='R'){
      r.push_back(i);
    }
  }

  vector<long> w;
  for(int i=0;i<=r.size();i++){
    if(S[i]=='W') w.push_back(i);
  }
  long rs=r.size(),ws=w.size();
  long i=0,j=0;
  long ans=0;
  while(i<rs&&j<rs){
    int s=r[i];
    int t=w[j];
    if(s<t) break;
    ans++;
    i++,j++;
  }
cout<<ans<<endl;
*/
long N;
cin>>N;
string S;
cin>>S;

int i=0,j=N-1;
long ans=0;
while(i<j){
  if(S[j]=='R'){
    while(S[i]!='W'&&i<N){
      i++;
    }
    if(i<j){
      S[i]='R';
      S[j]='W';
      ans++;
    }
  }
  j--;
}
cout<<ans<<endl;
}


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

int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
int a = n%10;
if(a == 2 || a == 4 || a == 5 || a == 7 || a == 9){
    cout<<"hon";
}else if ( a == 0 || a == 1 || a == 6 || a == 8){
    cout<<"pon";
}else{
    cout<<"bon";
}

    return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> field(h + 2, vector<int>(w + 2));
  for (int y = 0; y < h + 2; y++) {
    for (int x = 0; x < w + 2; x++) {
      field[y][x] = 0;
    }
  }
  for (int y = 0; y < h; y++) {
    string str;
    cin >> str;
    for (int x = 0; x < w; x++) {
      field[y + 1][x + 1] = str.at(x) == '#' ? 1 : 0;
    }
  }

  vector<vector<char>> count(h, vector<char>(w));
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      int fx = x + 1;
      int fy = y + 1;
      if (field[fy][fx] == 1) {
        count[y][x] = '#';
        continue;
      }
      int count_element =
          field[fy - 1][fx - 1] + field[fy - 1][fx] + field[fy - 1][fx + 1]  //
          + field[fy][fx - 1] + field[fy][fx] + field[fy][fx + 1]            //
          + field[fy + 1][fx - 1] + field[fy + 1][fx] +
          field[fy + 1][fx + 1];  //
      count[y][x] = count_element + '0';
    }
  }

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      cout << count[y][x];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 888
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int n = sc.nextInt();
    int a[] = new int[n];
    for(int i = 0 ; i < n ; ++i){
      a[i] = sc.nextInt();
    }

    int count = 0;
    
    for(int i = 0 ; i < n ; ++i){
      count += a[i];
    }
    
    if(count >= h){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
    
  }
}

Measured memory_bytes: 59720
N=int(input())
T=[0]*(N+1);S=[0]*(N+1);f=0
for i in range(1,N+1):
  t,x,y=map(int,input().split())
  T[i]=t
  S[i]=[x,y]
T[0]=0;S[0]=[0,0]

#print(T)
#print(S)

for i in range(1,N+1):
  if (T[i]-T[i-1])<(abs(S[i][0]-S[i-1][0])+abs(S[i][1]-S[i-1][1])):
    f=1
  if (T[i]-T[i-1])%2!=(abs(S[i][0]-S[i-1][0])+abs(S[i][1]-S[i-1][1]))%2:
    f=1

print("Yes" if f==0 else "No")

Measured memory_bytes: 24592
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

long long int a = 0, b = 0, c = 1, x = 0, y = 0, z = 0, maxy = -1, mini = 9999, counter = 0,startp=0,endp=0,checker=0;
std::vector<unsigned long long int> vec{}, vecsec{};
int iremono[100001];
std::vector<long long int>kinds{}, ans{}, kaku{};
char moji;
bool okada = false,okada2=false;
std::string output, output2, input, one, two;
char cutcount[201];
int kakunou2[50][50] = {};

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int main()
{
	cin >> a;
	okada = false;
	rep(i, a) {
		cin >> moji;
		if (moji == 'Y') {
			okada = true;
		}
	}
	if (okada) {
		cout << "Four" << endl;
	}
	else {
		cout << "Three" << endl;
	}
}

	
	





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

class Segtree{
public:
  int n;
  vector<int> lazy, val;
  inline void lazy_eval(int k){//dbg(mp(k,v));
    if(lazy[k]>-1){
      if(lazy[k]==0) val[k]=0;
      else val[k] = 1;
      if(k<n-1){
        lazy[2*k+1]=lazy[k];
        lazy[2*k+2]=lazy[k];
      }
      lazy[k]=-1;
    }
  }
  int get(int v){
    v += n-1;
    int ret = val[v];
    if(lazy[v]>-1) ret = lazy[v];
    while(v>0){
      v = (v-1)/2;
      if(lazy[v]>-1) ret = lazy[v];
    }
    return ret;
  }
  void _update(int a, int b, int v, int k, int l, int r){// dbg(k);
    lazy_eval(k);
    if(r<=a || b<=l) return;
    if(a<=l && r<=b){
      lazy[k]=v;
      lazy_eval(k);
      return;
    }
    int m=(l+r)/2;
    _update(a,b,v,k*2+1,l,m);
    _update(a,b,v,k*2+2,m,r);
    val[k] = val[k*2+1] + val[k*2+2] - get(m-1) * get(m);
    return;
  }
  void update(int a, int b, int v){ _update(a,b,v,0,0,n); return; }
  Segtree(int n_){
    n=1;
    while(n<n_) n*=2;
    lazy = vector<int>(2*n-1, -1);
    val = vector<int>(2*n-1, 0);
  }
};


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

  Segtree st(n);
  rep(i,n) st.val[st.n-1+i] = s[i]=='1';

  function<pair<int,int>(int)> idfs = [&](int i){
    if(i>=st.n-1){
      return mp(i-(st.n-1), i-(st.n-1)+1);
    }
    auto pl = idfs(i*2+1);
    auto pr = idfs(i*2+2);assert(pl.se==pr.fi);
//    cout << vector<int>{i, st.val[i*2+1], st.val[i*2+2], st.val[pr.fi-1], st.val[pr.fi]} << endl;
    st.val[i] = st.val[i*2+1] + st.val[i*2+2] - st.val[st.n-1+pr.fi-1]*st.val[st.n-1+pr.fi];
    return mp(pl.fi, pr.se);
  };
  idfs(0);

//  dbg(st.val);

  int q;cin>>q;
  rep(_,q){
    int l,r,b;
    cin>>l>>r>>b;
    st.update(l-1,r,b);// dbg(st.val);dbg(st.lazy);
    cout << st.val[0] << endl;
  }


  return 0;
}

Measured memory_bytes: 5212
import java.util.Scanner;

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

			int k = sc.nextInt();
			int x = sc.nextInt();
			
			for(int i = x - k + 1 ; i <= x + k - 1; i++ ) {
				System.out.println(i);
			}
			
			
			
		}
	}
}


Measured memory_bytes: 23892
N = int(input())
a = list(map(int, input().split()))

b = [val//400 for val in a]
#print(b)
c = set(b)
#print(c)
over=len([val for val in b if val >= 8])
under=[val for val in b if val <8]
if over:
    M=len(set(under))+over
    m=len(set(under))
    if m == 0:
        m=1
else:
    M=len(c)
    m=len(c)
print(m, M)

Measured memory_bytes: 38256
import collections

def cmb(n):
    sum = 0
    for i in range(n):
        sum += i
    return(sum)


N=int(input())
S=[]
for i in range(N):
    S.append(input())

ss_num = collections.Counter()

for s in S:
    ss_num[tuple(sorted(s))] += 1

ans = 0
for s,n in ss_num.items():
    ans += cmb(n)
print(ans)

Measured memory_bytes: 31088
#include <bits/stdc++.h>
#define mod 1e9+7
#define pb push_back
#define F first
#define S second

using namespace std;
typedef long long ll;
typedef long double ld;
int dx[4] = {-1, 0, +1, 0}, dy[4] = {0, -1, 0, +1};



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a, b;
    cin >> a >> b;
    int l = 10 * b, r = 10 * (b + 1);
    for (int i = l; i < r; i++) {
        if (((i * 8) / 100) == a) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256