akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X, Y;
    cin >> X >> Y;
    ll ans = 0;
    while (X <= Y) {
        ans++;
        X *= 2LL;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int[][] A = new int[3][3];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				A[i][j] = scan.nextInt();
			}
		}
		int N = scan.nextInt();

		boolean bingo = false;
		int b;
		for (int i = 0; i < N; i++) {
			b = scan.nextInt();
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					if (A[j][k] == b) {
						A[j][k] = 0;
					}
				}
			}
		}

		for (int i = 0; i < 3; i++) {
			if (A[i][0] == 0 && A[i][1] == 0 && A[i][2] == 0) bingo = true;
		}
		for (int i = 0; i < 3; i++) {
			if (A[0][i] == 0 && A[1][i] == 0 && A[2][i] == 0) bingo = true;
		}
		if (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0) bingo = true;
		if (A[2][0] == 0 && A[1][1] == 0 && A[0][2] == 0) bingo = true;

		if (bingo) System.out.println("Yes");
		else System.out.println("No");

	}

}


Measured memory_bytes: 35564
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

void solve(){
	string s;
	cin >> s;
	ll geko = 1;
	REP(i, s.length()) {
		geko *= 10;
	}
	ll ans = -1;
	ll now_itr = 0;
	vector<char> inputs;
	REP(i, 10) {
		inputs.push_back('0' + i);
	}
	do {
		string b;
		REP(q, s.length()) {
			b.push_back(inputs[q]);
		}
		ll tmp = llabs(stoll(b) - stoll(s));
		tmp = min(tmp, geko - tmp);
		if (tmp > ans||(tmp == ans&&now_itr >= stoll(b))) {
			ans = tmp;
			now_itr = stoll(b);
		}
	} while (next_permutation(ALL(inputs)));
	string a = to_string(now_itr);
	while (a.length() != s.length()) {
		a.insert(a.begin(), '0');
	}
	cout << a << endl;
}

#undef int
int main() {
	init();
	solve();
}


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

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

using namespace std;

int prime[1000001];

void CreatePrime(int n)
{
	rep(i,n)
	{
		prime[i] = 1;
	}

	prime[0] = prime[1] = 0;

	REP(i,2,sqrt(n))
	{
		if(prime[i])
		{
			for(int j=0;i*(j+2) < n;j++)
			{
				prime[i*(j+2)] = 0;
			}
		}
	}
}

int main()
{
	CreatePrime(1000001);
	
	int n;
	while(cin >> n && n)
	{
		int count = 0;
		REP(i,2,(n/2)+1)
		{
			if(prime[i] == 1 && prime[n-i]) count++;
		}

		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 5064
n = input()
m = 0
for i in range(n):
  (p, x) = raw_input().split()
  x = int(x)

  if p == "(":
    m += x
  else:
    m -= x

  if m < 0:
    print "NO"
    quit()

if m:
  print "NO"
else:
  print "YES"

Measured memory_bytes: 4240
#include <bits/stdc++.h>
using namespace std;
int n, x, l = -1;
long long z = -1;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		if (x <= l) {
			z += x;
		} else if (x == l + 1) {
			z++;
		} else {
			printf("-1\n");
			return 0;
		}
		l = x;
	}
	printf("%lld\n", z);
	return 0;
}

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

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

    int ans = 1;
    REP(i,n-1){
        if(s[i] != s[i+1])ans++;
    }

    cout << ans << endl;

    return 0;
}

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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

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

  long long H = 0;
  int index = 0;
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i) == A.at(i + 1)) {
      H = A.at(i);
      index = i + 1;
      break;
    }
  }

  long long W = 0;
  for (int i = (index + 1); i < N - 1; i++) {
    if (A.at(i) == A.at(i + 1)){
      W = A.at(i);
      break;
    }
  }

  cout << H * W << endl;
}

Measured memory_bytes: 640
import math
from collections import Counter

def nCm(n, m):
    return math.factorial(n) / (math.factorial(m) * (math.factorial(n - m)))
    
n = int(input())
A = [int(i) for i in input().split()]
ans = 0

S = [0]*n
S[0] = A[0]
for i in range(1,n):
    S[i] = S[i-1] + A[i]
S=[0]+S   
c = Counter(S)

for k,v in c.items():
    if v > 1 :
        ans += int(nCm(v,2))
      
print(ans)

Measured memory_bytes: 41904
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9 + 7;
int INF = 2e18;

signed main() {
    string S;
    cin >> S;
    if (S == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (S == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
}


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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

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

  int answer = 0, m = 0;
  REP1(i, N) {
    int j = i;
    int count = 0;
    while (j % 2 == 0) {
      j /= 2;
      count++;
    }
    if (count >= m) {
      m = count;
      answer = i;
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;

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

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

ll mod(ll val, ll M) {
    ll res = val % M;
    if(res < 0) {
        res += M;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int H,W;
int sy,sx,gy,gx;
char maze[1010][1010];
int dist[1010][1010];
vector<int> dy = {-1,1,0,0};
vector<int> dx = {0,0,-1,1};

void solve() {
    for(int i = 0;i < 1010;i++) {
        for(int j = 0;j < 1010;j++) {
            dist[i][j] = Inf;
        }
    }
    dist[sy][sx] = 0;
    deque<P> que;
    que.push_back(P(sy,sx));
    while(!que.empty()) {
        P p = que.front();
        que.pop_front();
        for(int i = 0;i < 4;i++) {
            int ny = p.first + dy.at(i);
            int nx = p.second + dx.at(i);
            if(0 <= ny && ny < H && 0 <= nx && nx < W && maze[ny][nx] == '.') {
                if(chmin(dist[ny][nx],dist[p.first][p.second])) {
                    que.push_front(P(ny,nx));
                }
            }
        }
        for(int i = -2;i <= 2;i++) {
            for(int j = -2;j <= 2;j++) {
                int ny = p.first + i;
                int nx = p.second + j;
                if(0 <= ny && ny < H && 0 <= nx && nx < W && maze[ny][nx] == '.') {
                    if(chmin(dist[ny][nx],dist[p.first][p.second] + 1)) {
                        que.push_back(P(ny,nx));
                    }
                }
            }
        }
    }
}

int main() {
    cin >> H >> W;
    cin >> sy >> sx >> gy >> gx;
    sy--;
    sx--;
    gy--;
    gx--;
    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W;j++) {
            cin >> maze[i][j];
        }
    }
    solve();
    if(dist[gy][gx] == Inf) {
        cout << -1 << endl;
    }
    else {
        cout << dist[gy][gx] << endl;
    }
}

Measured memory_bytes: 8620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  ll n,k; cin >> n >> k;
  if(k>=n){
    cout << n;
    return 0;
  }
  string s; cin >> s;
  queue<ll> q;
  q.push(0);
  char prev='1';
  ll num_1=0;
  ll num_0=0;
  vector<ll> v;
  rep(i,n){
    char cur = s[i];
    if(i>0&&prev!=cur&&cur=='1'){
      q.push(num_1+num_0);
      num_1=0;
      num_0=0;
    }
    if(prev!=cur&&cur=='0'){
      v.push_back(i);
    }
    if(cur=='1'){
      num_1++;
    }else{
      num_0++;     
    }
    prev=cur;
  }
  q.push(num_1+num_0);
  v.push_back(n);
  if(v.size()<=k){
    cout << n;
    return 0;
  }
  ll ans=0;
  ll ruiseki=0;
  for(ll i=k; i<v.size(); i++){
    ruiseki+=q.front();
    q.pop();
    ans=max(ans,v[i]-ruiseki);
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 1148
n = int(input())
T, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

ans, mi=0, 1000000
for i, x in enumerate(A):
    t = T-x*0.006
    if abs(t-K) <= mi:
        mi = abs(t-K)
        ans = i+1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std; 
using ll = long long;
signed main() { 
	cin.tie(0);
	cin.sync_with_stdio();
	int n; 
	cin>>n;
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		if(a%2 == 0 && !((a%3 == 0) || (a%5 == 0))){
			cout<<"DENIED";
			return 0;
		}
	}
	cout<<"APPROVED";
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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



  ll a[11];
  rep(i, 6) cin >> a[i];
  if (a[4] - a[0] > a[5]) cout << ":(" << endl;
  else cout << "Yay!" << endl;




  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

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

int main(void) {
    int a, b;
    cin >> a >> b;
    if (b % a == 0) {
        cout << a + b << endl;
    } else {
        cout << b - a << endl;
    }
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

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

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

// int main() {
//     double a, b, x, theta;
//     cin >> a >> b >> x;
//     if (x > a * a * b / 2) {
//         theta = atan(2 * (a * a * b - x) / (a * a * a));
//     } else {
//         theta = atan((a * b * b) / (2 * x));
//     }

//     theta = theta * 180 / acos(-1);
//     printf("%.12f\n", theta);
//     return 0;
// }

double a, b, c;

bool f(double theta) { return pow(a, 2) * b - pow(a, 3) * tan(theta) / 2 > c; }
bool g(double theta) { return pow(b, 2) * a / tan(theta) / 2 > c; }

int main() {
    cin >> a >> b >> c;
    double ok = 0.0, ng = 1.6;
    REP(i, 1e6) {
        double mid = (ok + ng) / 2;
        if (c > a * a * b / 2) {
            if (f(mid)) {
                ok = mid;
            } else {
                ng = mid;
            }
        } else {
            if (g(mid)) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
    }

    ok = ok * 180 / acos(-1);
    printf("%.12f\n", ok);
}

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

typedef long long ll;


int main()
{

    ios::sync_with_stdio(false);
    cin.tie(0);

    int n,flag=0,ts=0 , ts2=0;
    cin>>n;

    int arr[n];

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

    }
    for(int i=0 ; i<n ; i++)
    {
        if(arr[i] %2==0)
        {
            if(arr[i] %3 !=0 )
            {
                ts=1;
            }
            if(arr[i] %5 !=0)
            {
                ts2=1;
            }
        }

        if(ts==1 && ts2==1)
        {
            flag=1;
            break;
        }
        ts=0;
        ts2=0;
    }

    if(flag==0)
    {
        cout<<"APPROVED";
    }
    else
    {
        cout<<"DENIED";
    }

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    int res = 1;
    for (int i = 1; i < n; ++i) {
        if (a[i] > a[i - 1])
            ++res;
    }
    if (res % 2 == 0)
        --res;
    cout << res << endl;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int d, n;
    cin >> d >> n;
    if(d==2){
        if(n==100){
            cout << 1010000 << endl;
        }else{
            cout << 10000*n << endl;
        }
    }else if(d==1){
        if(n==100){
            cout << 10100 << endl;
        }else{
            cout << 100*n << endl;
        }
    }else{
        if(n==100){
            cout << 101 << endl;
        }else{
            cout << n << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
  var N string
  fmt.Scan(&N)
  
  x := make([]string, 3)

  x[0] = "Sunny"
  x[1] = "Cloudy"
  x[2] = "Rainy"

  var i int
  for N != x[i]{
  i++
  }

  if i == 2 {
    fmt.Println(x[0]) 
  } else {
    fmt.Println(x[i+1])
  }
}


Measured memory_bytes: 512
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int main() {
	ll N, M;
	scanf("%lld %lld", &N, &M);

	ll c = min(N, M / 2);
	M -= 2 * c;
	c += M / 4;
	return !printf("%lld\n", c);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Program{
    public static void Main(){
        int q = int.Parse(Console.ReadLine());
        var list = new LinkedList<int>();
        var node = new LinkedListNode<int>(Int32.MaxValue);
        list.AddFirst(node);
        for(int i=0; i<q; i++){
            string[] str = Console.ReadLine().Split(' ');
            int order = int.Parse(str[0]);
            switch(order){
                case 0:
                    int n = int.Parse(str[1]);
                    list.AddBefore(node,n);
                    node = node.Previous;
                    break;
                case 1:
                    int d = int.Parse(str[1]);
                    for(int j=0; j<d; j++){
                        node = node.Next;
                    }
                    for(int j=d; j<0; j++){
                        node = node.Previous;
                    }
                    break;
                case 2:
                    node = node.Next;
                    list.Remove(node.Previous);
                    break;
                default:
                    break;
            }
        }
        var ans = list.Where(l => l != Int32.MaxValue).ToList();
        ans.ForEach(Console.WriteLine);
    }
}



Measured memory_bytes: 50160
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto K = s[2];

    long C = 1;
    foreach (i; 1..N*M-1) {
        C = C * i % MOD;
    }
    foreach (i; 1..K-1) {
        C = C * powmod(i, MOD-2, MOD) % MOD;
    }
    foreach (i; 1..(N*M-2-(K-2))+1) {
        C = C * powmod(i, MOD-2, MOD) % MOD;
    }

    long ans = 0;
    long tmp = 0;

    foreach (i; 0..N) {
        long right = N - i - 1;
        long left = i;
        tmp = (tmp + right * (right + 1) / 2 * M) % MOD;
        tmp = (tmp + left * (left + 1) / 2 * M) % MOD;
    }

    ans += tmp * C % MOD * M % MOD;
    ans %= MOD;

    tmp = 0;
    foreach (i; 0..M) {
        long right = M - i - 1;
        long left = i;
        tmp = (tmp + right * (right + 1) / 2 * N) % MOD;
        tmp = (tmp + left * (left + 1) / 2 * N) % MOD;
    }

    ans += tmp * C % MOD * N % MOD;
    ans %= MOD;
    ans =  ans * powmod(2, MOD-2, MOD) % MOD;
    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         for(;;){
            int n = sc.nextInt();
            if(n==0) break;
            int cnt = 0;
            int flag = -1;//フラグoff
            for(int i=0;i<n;i++){
                int k = sc.nextInt();
                if(k>0) cnt++; //景品の種類数
                if(k>=2) flag = 1; //２以上の景品があればon
            }
            if(flag<0) System.out.println("NA");
            else System.out.println(cnt+1);//景品の種類数+1で100%
        }
    }
}

Measured memory_bytes: 158536
import java.util.*;
import java.io.*;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long min = 1000000000;
        for (long i = 1; i <= (long)Math.sqrt(n); i++) {
            if (n % i == 0) {
                long a = i;
                long b = n / i;
                min = Math.min(min, f(a,b));
            }
        }
        System.out.println(min);
    }

    public static long f(long a, long b) {
        long num = Math.max(a,b);
        long digits = 0;
        while (num > 0) {
            num /= 10;
            digits++;
        }
        return digits;
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <deque>

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

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

    vector<int> a(N);

    REP(i, N)
        cin >> a[i];

    bool tail = true;

    int n = N - 1;
    bool down = true;
    REP(i, N + 1)
    {
        if( down )
        {
            if( n >= 0 )
            {
                cout << a[n] << " ";
                n -= 2;
            }
            else
            {
                if( n == -1 ) n = 0;
                else n = 1;
                down = false;
            }
        }
        else
        {
            if( n < N )
            {
                cout << a[n] << " ";
                n += 2;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int h, w, n; cin >> h >> w >> n;
    int sh, sw; cin >> sh >> sw;
    string s,t ; cin >> s >> t;
    int ch = sh;

    bool ok = true;
    rep(i, n) {
        if (s[i]=='U') ch--;
        if (ch<1) ok = false;
        if (t[i]=='D'&&ch<h) ch++;
    }
    debug(ok);
    ch = sh;
        rep(i, n) {
        if (s[i]=='D') ch++;
        if (ch>h) ok = false;
        if (t[i]=='U'&&ch>1) ch--;
    }
    debug(ok);
    int cw = sw;
    rep(i, n) {
        if (s[i]=='L') cw--;
        if (cw<1) ok = false;
        if (t[i]=='R'&&cw<w) cw++;
    }
    debug(ok);
    cw = sw;
    rep(i, n) {
        if (s[i]=='R') cw++;
        if (cw>w) ok = false;
        if (t[i]=='L'&&cw>1) cw--;
    }
    debug(ok);
    if (!ok) puts("NO");
    else puts("YES");
}

Measured memory_bytes: 776
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()

amax=0
bmin=10**100
arra=[]
arrb=[]
for i in range(n):
    a,b=mii()
    arra.append(a)
    arrb.append(b)

arra.sort()
arrb.sort()

if n%2==1:
    p=arra[n//2 ]
    q=arrb[n//2 ]

    print(q-p+1)
else:
    p=(arra[n//2 -1]+arra[n//2])
    q=(arrb[n//2 -1]+arrb[n//2])
    #print(p,q,arra[n//2-1])
    print(q-p+1)


Measured memory_bytes: 26872
//#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
//#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
//#include <cstring>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;

int main(void){

	double a, b, c, d, e, f;
	
	while(cin >> a >> b >> c >> d >> e >> f){
		double y = (double)((a * f - d * c)/(a * e - b * d));
		double x = (double)((e * c - b * f)/(a * e - b * d));
		if(x == 0)x = 0.000;
		if(y == 0)y = 0.000;
	  	printf("%.3f %.3f\n", x, y);
	}

	return 0;
}

/*
for(i=0;i<N;i++){
	cin >> X[i];
}


for(i=0;i<N;i++){
	for(j=0;j<N;j++){
		cin >> X[i][j];
	}
}
*/

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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


int main(){

	REP(i,1,10){
		REP(j,1,10){
			cout << i << "x" << j << "=" << i * j << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1116
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)


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


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


int Svec(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}


int GCD(int a,int b){
  int r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


int LCM(int a,int b){
  int c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


int Factorial(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}


/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  int n;
  cin>>n;
  vector<long long int> v(n);
  rep(i,n) cin>>v[i];
  map<long long int,long long int> mp;
  rep(i,n){
    mp[v[i]]++;
  }
  int ans=0;
  for(auto c:mp){
    if(c.second%2!=0){
      ans++;
    }
  }
  cout<<ans<<endl;
}

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

int main() {
  int count=100000,countb=0;
  int H,W,N;
  cin>>H>>W>>N;
  rep(i,H+1){
    rep(j,W+1){
      if(W*i+H*j-i*j>=N){
        count=min(count,i+j);
      }
    }
  }
  cout<<count;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N,A,B; cin >> N >> A >> B;
    cout << min(A*N,B) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

void f(int u, int v) {
    cout << u + 1 << ' ' << v + 1 << endl;
}

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

    int l = (n - 1) * (n - 2) / 2 - k;
    if (l < 0) {
        cout << -1 << endl;
        exit(0);
    }

    int m = l + (n - 1);
    cout << m << endl;

    for (int i = 1; i < n; i++) {
        f(0, i);
    }
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (l-- == 0) exit(0);
            f(i, j);
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int n;
string s;
string a,b;
int ans;
int moji[30];
int moji2[30];

int main(){
  cin >> n;
  cin >> s;
  for(int i=1;i<n;i++){
    a = s.substr(0,i);
    b = s.substr(i,n-i);
    //cout << a << " "<< b << endl;
    REP(j,30) moji[j]=0;
    REP(j,30) moji2[j]=0;
    REP(j,a.size()) moji[a[j]-'a'] ++;
    REP(j,b.size()) moji2[b[j]-'a'] ++;
    //REP(j,30) cout << moji[j] << " ";
    int tmp = 0;
    REP(j,30){
      if(moji[j]>0&&moji2[j]>0){
        tmp ++;
        //cout << i << " " << j << " " << moji[j] << " " << moji2[j] << endl;
      }
      if(tmp>ans) ans = tmp;
    }
  }
    cout << ans << endl;
    return 0;
  }


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int count = 0;
        for (int i = a; i <= b; i++) {
            if (i / 10000 == i % 10 && i / 1000 % 10 == i % 100 / 10)
                count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21716
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define MAX 490000
#define max(a, b) ((a) < (b) ? (b) : (a))
using namespace std;
int to[MAX];
int head[MAX];
int nxt[MAX];
int v[MAX];
int sign[MAX];
int tot;
void Add(int fir, int sec) {
    nxt[++tot] = head[fir];
    to[tot] = sec;
    head[fir] = tot;
}

void bfs(int node) {
    // v[node] = 1;
    queue<int> q;
    q.push(node);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        v[x] = 1;
        for (int i = head[x]; i != -1; i = nxt[i]) {
            int y = to[i];
            if (v[y] == 1) {
                continue;
            }
            if (sign[y] == 0) {
                sign[y] = x;
                q.push(y);
            }
                
            // printf("%d sign is %d\n", y, x);
        }
    }
}

int main() {
    int N, M;
    while (cin >> N >> M) {
        tot = 0;
        memset(nxt, -1, sizeof(nxt));

        int fir, sec;
        for (int i = 1; i <= M; i++) {
            scanf("%d%d", &fir, &sec);
            Add(fir, sec);
            Add(sec, fir);
        }
        bfs(1);
        int flag = 0;
        for (int i = 2; i <= N; i++) {
            if (!sign[i]) {
                flag = 1;
                break;
            }
        }
        if (flag) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
            for (int i = 2; i <= N; i++)
                printf("%d\n", sign[i]);
            // cout << sign[i] << endl;
        }
    }
    return 0;
}


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

using namespace std;

const int MAX = 200002;
bool toN[MAX];
bool fromOne[MAX];

int main() {
  int N, M;
  cin >> N >> M;
  int a, b;
  for (int i = 0; i < M; ++i) {
    cin >> a >> b;
    if (a == 1) fromOne[b] = true;
    if (b == N) toN[a] = true;
  }
  for (int i = 0; i < N; ++i) {
    if (toN[i] && fromOne[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)

signed main()
{
  int N;
  int A;
  int val = 0, run = 0, ans = 1;
  
  cin >> N;
  Rep(i, N) {
    cin >> A;
    if(i == 0) val = A;
    
    if(!run) {
      if(val < A) run++;
      else if(val > A) run--;
    } else if(run == 1) {
      if(val > A) {
	ans++, run = 0;
      }
    } else if(run == -1) {
      if(val < A) {
	ans++, run = 0;
      }
    }
    val = A;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))


n = load()
sm = []
for _ in range(n):
    speak = {}
    a = load()
    for _ in range(a):
        x, y = load_list()
        speak[x-1] = bool(y)
    sm.append(speak)

def bit_count(bit):
    c = 0
    while bit > 0:
        bit &= bit - 1
        bit = bit >> 1
        c += 1
    return c


mx = 0
for bit in range(0, 1<<n):
    bf = False
    for i in range(0, n):
        if bit & (1 << i):
            for other, honest in sm[i].items():
                if (((bit & (1 << other))) > 0) == honest:
                    pass
                else:
                    bf = True
                    break
        if bf:
            break
    if not bf:
        mx = max(mx, bit_count(bit))
        
print(mx)

Measured memory_bytes: 3308
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n, e, m, j, i;
	double a;
	string s;
	while (cin >> n && n)
	{
		s = "";
		for (i = 0; i < n; i++)
		{
			cin >> m >> e >> j;
			a = ((double)m+e+j)/3;
			if (m == 100 || e == 100 || j == 100 || (m+e)/2 >= 90 || a >= 80)
				s += "A\n";
			else if (a >= 70 || (a >= 50 && (m >= 80 || e >= 80)))
				s += "B\n";
			else
				s += "C\n";
		}
		cout << s;
	}
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 1111

typedef long long ll;
typedef long double ld;

char str[2][maxn];
ll dp[maxn][4][4];
int n;


ll fun(int x, int a, int b){
	if(x == n)
		return 1;

	ll &cur = dp[x][a][b];
	if(cur != -1)
		return cur;

	cur = 0;
	if(str[0][x] == str[1][x]){
		for(int i = 1; i <= 3; i++){
			if(i != a && i != b)
				cur = (cur + fun(x + 1, i, i)) % MOD;
		}
	}

	else{
		for(int i = 1; i <= 3; i++){
			for(int j = 1; j <= 3; j++){
				if(i != a && j != b && i != j)
					cur = (cur + fun(x + 2, i, j)) % MOD;
			}
		}
	}

	return cur;
}


int main(){
	memset(dp, -1, sizeof(dp));

	scanf("%d", &n);
	scanf("%s%s", str[0], str[1]);
	printf("%lld", fun(0, 0, 0));
	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		int count;
		
		boolean hamming[] = new boolean[1000001]; hamming[1] = true;
		int num[] = new int[]{2, 3, 5};
		for(int i = 0; i < 3; i++){
			for(int j = 1; j * num[i] < 1000001; j++){
				if(hamming[j * num[i]]) continue;
				if(j * num[i] % num[i] == 0 && hamming[j * num[i] / num[i]])
					hamming[j * num[i]] = true;
			}
		}
		
		while(!(string = reader.readLine()).equals("0")){
			count = 0;
			for(int i = Integer.valueOf(string.split(" ")[0]);
					i <= Integer.valueOf(string.split(" ")[1]); i++){
				if(hamming[i]) count++;
			}
			System.out.println(count);
		}
		reader.close();
	}
}

Measured memory_bytes: 287864
#include <cstdio>
long long p[100001],x[100001],n,s;;
long long ans;
int main(){
	scanf("%d%d",&n,&s);
	for (int i=1;i<=n;i++)
		scanf("%d%d",&x[i],&p[i]);

	int i=1,j=n;
	while (i<=j){
			if (s<=x[i]){
				printf("%lld",x[j]-s+ans);
				return 0;
			}
			else if (s>=x[j]){
				printf("%lld",ans+s-x[i]);
				return 0;
			}
			if (p[i]>=p[j]){
				ans+=x[j]-x[i];
				while (i<j && p[i]>=p[j]) p[i]+=p[j--];
			}
			else{
				ans+=x[j]-x[i];
				while (i<j && p[i]<p[j]) p[j]+=p[i++];
			}
	}
} 

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <bitset>
#include <cmath>

using namespace std;

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

	int bit[10];
	int mask = 1;
	for (int i = 0; i < 10; i++) {
		bit[i] = mask;
		mask = mask << 1;
		//cout << static_cast<bitset<9> >(bit[i]) << endl;
	}

	unsigned long long sum = 0;
	mask = 0;
	for (int i = 0; i < pow(2, S.length() - 1); i++) {
		string str;
		str = S[0];
		int cosum = 0;
		for (int j = 0; j < S.length() - 1; j++) {
			if ((mask & bit[j]) == bit[j]) {
				sum += (unsigned long long)stod(str);
				//cout << (int)stod(str) << endl;
				str = S[j + 1];

			}
			else {
				str += S[j + 1];
			}

		}

		sum += (unsigned long long)stod(str);
		//cout << sum << endl;
		mask++;
	}
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
arr=list(map(int,input().split()))
def isvalid(mid,k):
    if mid==0:
        return False
    ans=k
    for i in arr:
        if i>mid:
            ans-=i//mid
    return ans>=0


l=0
r=10**9
while(l<r):
    mid=(l+r)//2
    if isvalid(mid,k):
        r=mid
    else:
        l=mid+1
print(l)













Measured memory_bytes: 94152
#include <iostream>
#include<bits/stdc++.h>
#define  ll long long
 using namespace std;
int dp[3000003][3],sum[3000003][3];
int main()
{
  int t;
  cin>>t;
  string s;
  cin>>s;
  if(t>=3200)cout<<s;
  else cout<<"red";
return 0;
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        
        int h = s/3600;
        s -= h*3600;
        
        int m = s/60;
        s -= m*60;
        
        System.out.println(h+":"+m+":"+s);
    }
}


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

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

#define ll long long int
#define ld long double
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define pi 3.14159265358979
#define pa pair<ll,ll>
//#define goodset tree<pa, null_type, less<pa>, rb_tree_tag, tree_order_statistics_node_update>
//#define FRE freopen("acm.in","r",stdin); freopen("acm.out","w",stdout);

const ll mod = 1e9+7 ;
const ll N = 1e7+5;
int main()
{
    FAST

    ll tc,i,j,k;
    //cin>>tc;
    tc=1;
    while(tc--)
    {
        ll n;
        cin>>n;
        string s;
        cin>>s;
        ll cntr=0,cntw=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='W')
                cntw++;
            else
                cntr++;
        }
        ll ans=min(cntw,cntr);
        vector<ll>v;
        for(i=0; i<n; i++)
        {
            if(s[i]=='W')
                v.pb(i);

        }
        ll st=0,cnt=0;
        for(i=n-1; i>=0; i--)
        {
            if(s[i]=='R')
            {
                if(st==cntw )
                    break;
                if(v[st]>i)
                    break;
                swap(s[v[st]],s[i]);
                cnt++;
                st++;
            }
        }
        ans=min(ans,cnt);
        cout<<ans<<"\n";

    }
    return 0;
}



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

int main(void) {
    int n;
    long long k;
    cin>>n>>k;
    long long ans[100001];
    for (int i = 0; i < n;i++)
        ans[i] = 0;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        ans[a] += b;
        }
    for (int i = 1; i <= 100000; i++)
    {
        if(ans[i]>=k) {
            cout << i << endl;
            break;
        }
        k -= ans[i];
    }
    return 0;
}

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

int main() {
	int N,Y,yen,yuki,higu,nogu;
	bool pro = false;
	cin >> N>>Y;
	yen=Y;
	for (int i=0;i<=N ;i++){
		for(int k=0;k<=N-i;k++){
			Y=yen;
			Y=Y-10000*i-5000*k;
			
			if(Y<0){
				continue;
			}
			
			else if(Y == 1000*(N-i-k)){
				yuki =i;
				higu=k;
				nogu=N-i-k;
				cout << yuki <<" "<<higu<<" "<< nogu<< endl;
				pro = true;
			break;
			}
			
			
		}
	if (pro == true){
		break;
	}
	}
	
	
	if(pro == false){
		cout << -1<<" " << -1<<" " << -1<<endl;
	}
			
}


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

using namespace std;

#define sf scanf
#define pf printf
#define ll long long
#define fr(I,M,N) for(I=M;I<=N;I++)
#define fr_(I,M,N) for(I=M;I>=N;I--)
#define re return
#define sfn cin>>n
#define bal pf("bal\n")
#define pb push_back
#define ins insert
#define sz(X) X.size()
#define xx first
#define yy second
#define skip continue
#define memo(X,N) memset(X,N,sizeof(X))
#define all(X) X.begin(),X.end()
#define mp make_pair
#define pi acos(-1)


/*
#define nMX 5000000
#define pMX 500000
int pr[pMX+1],prnum[nMX+1];

int sieve()
{
    int i,j;
    for(i=1;i<=nMX;i++)
        prnum[i]=i+1;
    for(i=1;i<=nMX;i++)
        if(prnum[i]!=-1)
            for(j=2*prnum[i]-1;j<=nMX;j+=prnum[i])
                    prnum[j]=-1;
    j=0;
    for(i=1;i<=nMX;i++)
        if(prnum[i]!=-1)
            pr[++j]=prnum[i];
    re j;
}*/

/*ll m_ncr[10001][10001];
ll ncr(ll i,ll j)
{
    if(j==1) re i;
    if(i==j) re 1;
    if(m_ncr[i][j]!=-1) re m_ncr[i][j];
    re m_ncr[i][j]=ncr(i-1,j) + ncr(i-1,j-1);
}*/

/*ll m_fact[21];
ll fact(ll i)
{
    if(i==1 || i==0) re 1;
    if(m_fact[i]!=-1) re m_fact[i];
    re m_fact[i]=i*fact(i-1);
}*/

int main()
{
    ios_base::sync_with_stdio(0);
    ll int i,j,x,y,n,m,cnt=0,k,g,flg,t,mx=0;
    string s;
    cin>>s;
    fr(i,0,sz(s)-1)
    {
        if(s[i]=='A' || s[i]=='G' || s[i]=='C' || s[i]=='T')
        {
            cnt++;
            mx=max(mx,cnt);
        }
        else
        {
            cnt=0;
        }
    }
    cout<<mx;
}


Measured memory_bytes: 256
#include <stdio.h>

#define DEBUG 1
#define NINF -1
#define PINF 1E9+1

int main()
{
	int a,b,c,d,i,ret;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);

	ret = 0;

	for (i=0;i<c;i++) {
		ret += b;
	}
	for (i=0;i<d;i++) {
		ret += a-c;
	}


	printf("%d\n",a*b-ret);
	return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val primeTable = primeTable(100000)
    val table2017 = BooleanArray(100000 + 1) { false }
    for (i in primeTable.indices) {
        val tmp = (i + 1) / 2
        table2017[i] = tmp >= 0 && primeTable[i] && primeTable[tmp]
    }

    val cumulativeSumList = IntArray(table2017.size + 1)
    for (i in 1 until cumulativeSumList.size) {
        cumulativeSumList[i] += cumulativeSumList[i - 1] + if (table2017[i - 1]) 1 else 0
    }

    val q = readInteger()
    repeat(q) {
        val (l, r) = readIntegerList()
        println(cumulativeSumList[r + 1] - cumulativeSumList[l])
    }
}

fun primeTable(n: Int): BooleanArray {
    val table = BooleanArray(n + 1) { true }
    if (n >= 0) table[0] = false
    if (n >= 1) table[1] = false
    var i = 2
    while (i * i <= n) {
        if (table[i]) {
            for (j in (i + i)..n step i) {
                table[j] = false
            }
        }

        i++
    }
    return table
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 56036
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
const double PI = acos(-1);

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double theta1 = h * PI / 6.0 + m * 0.5 * PI / 180.0;
  double theta2 = m * PI / 30.0;
  if(theta1==theta2){
    printf("%.12f\n", abs(a-b));
  }else{
    double th = abs(theta1 - theta2);
    if(th>=2.0*PI) th -= 2.0*PI;
    double ans = a*a + b*b - 2.0*a*b*cos(th);
    printf("%.12f\n", sqrt(ans)); 
  }

  return 0;
}


Measured memory_bytes: 4232
#include <stdio.h>

int main(void){
	char str[100005];
	scanf("%s", str);
	int i = 0;
	int last = 0, bd;
	while(str[i] != '\0'){
		last = i;
		while(str[i] == 'R')i++;
		bd = i;
		while(str[i] == 'L')i++;
		for(int k = last; k < bd - 1; k++)
			printf("0 ");
		if((i - last) % 2 == 0){
			printf("%d %d ", (i - last) / 2, (i - last) / 2);
		}else{
			if((bd - last) % 2 == 0){
				// 右が多い
				printf("%d %d ", (i - last) / 2, (i - last) / 2 + 1);
			}else{
				printf("%d %d ", (i - last) / 2 + 1, (i - last) / 2);
			}
		}
		for(int k = bd + 1; k < i; k++)
			printf("0 ");
	}
}


Measured memory_bytes: 512