akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a;
    cin >> n >> a;
    cout << n * n - a << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  int n;
  cin >> n;
  vector<int> counter(n,0);
  for(int i = 1; i < n; ++i) {
    int d;
    cin >> d;
    --d;
    counter[d]++;
  }

  for(int i = 0; i < n; ++i) {
    cout << counter[i] << endl;
  }

  return 0;
}

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

int main(){
    long long int x;
    cin >> x;
    
    long long int res = 0;
    long long int a = x / 11;
    long long int b = x % 11;
    
    res += a * 2;
    if(b == 0){
        res;
    }else if(b <= 6){
        res += 1;
    }else{
        res += 2;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10 ** 6)

Q, A, B, C = map(int, input().split())

def conv(s):
    return (0, 1) if s == "AB" else (1, 2) if s == "BC" else (0, 2)

S = [conv(input()) for i in range(Q)]
N = [A, B, C]
ans = []

def dfs(i):
    global ans, N
    if N[0] < 0 or N[1] < 0 or N[2] < 0:
        return
    if i == Q:
        print("Yes")
        for idx in ans:
            print("ABC"[idx])
        exit()
    x, y = S[i]
    for _ in range(2):
        N[x] += 1; N[y] -= 1
        ans.append(x)
        dfs(i + 1)
        N[x] -= 1; N[y] += 1
        ans.pop()
        x, y = y, x

dfs(0)

print("No")


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

int main(){
	int n, ans = 0;
	while (cin >> n){
		for (int i = 0; i <= 9; i++){
			for (int j = 0; j <= 9; j++){
				for (int k = 0; k <= 9; k++){
					for (int l = 0; l <= 9; l++){
						if (i + j + k + l == n)
							ans++;
					}
				}
			}
		}
		cout << ans << endl;
		ans = 0;
	}
	return 0;
}

Measured memory_bytes: 1160
//AtCoder ABC109 B - Shiritori
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
#if LOCAL&0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N; cin>>N;
    vector<string> wn(N);
    unordered_set<string> us;
    for(auto&& w:wn){
        cin>>w;
        us.insert(w);
    }
    bool ans=us.size()==wn.size();
    for(int i=0;i<wn.size()-1;++i){
        if(wn[i].back()!=wn[i+1].front()) ans=false;
    }
    cout<<(ans?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
using namespace std;
#define BIT 380000.0
 

int main() {
    int N; cin >> N;
	double sum = 0;
	for(int i = 0; i < N; i++){
		double x; cin >> x;
		string u; cin >> u;
		if(u == "JPY") sum += x;
		else sum += x * BIT;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeSearch(Node u, int k){
  while(u != NIL && u->key != k){
  if( u->key > k)u = u->left;
  else u = u->right;
  }
  return u;
}
 
void insert(int k){
  Node a = root;
  Node b = NIL;
  Node c;
 
  c = malloc(sizeof(struct node));
  c->key = k;
  c->left = NIL;
  c->right = NIL;
 
  while(a != NIL){
    b = a;
    if(c->key < a->key){
      a = a->left;
    }
    else a = a->right;
  }
 
  c->parent = b;
  if(b == NIL) {
    root = c;  
  }
  else if(c->key < b->key){
    b->left = c;
  }
  else b->right = c;
}
 
 
void inorder(Node n){
  if(n->left != NIL){
    inorder(n->left);
  }
  printf(" %d",n->key);
  if(n->right != NIL){
    inorder(n->right);
  }
 
}
void preorder(Node n){
  printf(" %d",n->key);
  if(n->left!= NIL){
    preorder(n->left);
  }
  if(n->right!= NIL){
    preorder(n->right);
  }
}
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }
  return 0;
}

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

struct edge{ll to,ver;};
vector<vector<edge>>g;
vector<ll>ans;


void dfs(ll v, ll p){
  for(int i=0; i<g[v].size(); i++){
   ll u=g[v][i].to;
   if(u==p) continue;
   ans[u]=ans[v]+g[v][i].ver;
   dfs(u,v);
  }
}

int main(){
  ll n;
  cin >> n;
  g.resize(n);
  ans.resize(n);
  for(int i=0; i<n-1; i++){
    ll a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].push_back((edge){b,c});
    g[b].push_back((edge){a,c});
  }
  
  ll q,k;
  cin >> q >> k;
  k--;
  vector<ll>x(q),y(q);
  for(int i=0; i<q; i++) cin >> x[i] >> y[i];
  
  dfs(k,-1);
  for(int i=0; i<q; i++){
   cout << ans[x[i]-1]+ans[y[i]-1] << endl;
  }
  
  
}

Measured memory_bytes: 15872
#include <cstdio>
#include <map>
#include <cmath>
using namespace std;

int main(){
  pair<double,double> p[20];
  int i=1;
  double a,b,c,z,S;
  S=0.0;
  scanf("%lf,%lf",&p[0].first,&p[0].second);
  scanf("%lf,%lf",&p[1].first,&p[1].second);
  while(scanf("%lf,%lf",&p[i+1].first,&p[i+1].second)>0){
    a=sqrt((p[i+1].first-p[0].first)*(p[i+1].first-p[0].first)+(p[i+1].second-p[0].second)*(p[i+1].second-p[0].second));
    b=sqrt((p[i].first-p[0].first)*(p[i].first-p[0].first)+(p[i].second-p[0].second)*(p[i].second-p[0].second));
    c=sqrt((p[i].first-p[i+1].first)*(p[i].first-p[i+1].first)+(p[i].second-p[i+1].second)*(p[i].second-p[i+1].second));
    z=(a+b+c)/2;
    S+=sqrt(z*(z-a)*(z-b)*(z-c));
    i++;
  }
  printf("%.6lf\n",S);
return 0;
}

Measured memory_bytes: 1084
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) for(auto &i:vec)fprintf(stderr,"%ld ",i);puts("");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

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

int main(){
	int n, t, ans = 2e9;
	scanf("%d %d", &n, &t);
	rep(i, 0, n){
		int c, v;
		scanf("%d %d", &c, &v);
		if(v<=t) ans = std::min(ans, c);
	}
	if(ans>10000) puts("TLE");
	else printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python

import sys

H, W = map(int, raw_input().split())

ind1 = int(H*W/3)

#first trial
Wp = int(ind1/H)
p1 = H*Wp
Wresid = W-Wp
if Wresid%2 == 0: p2 = p3 = Wresid/2*H
elif H%2 == 0: p2=p3=H/2*Wresid
else:
    Ht, Wt = max([H, Wresid]), min([H, Wresid])
    Hresidspl1 = Ht/2
    Hresidspl2 = Ht-Hresidspl1
    p2 = Wresid*Hresidspl1
    p3 = Wresid*Hresidspl2
ps1 = [p1, p2, p3]
diff1 = max(ps1)-min(ps1)

#second trial
Wp = int(ind1/H)+1
p1 = H*Wp
Wresid = W-Wp
if Wresid%2 == 0: p2 = p3 = Wresid/2*H
elif H%2 == 0: p2 = p3 = H/2*Wresid
else:
    Ht, Wt = max([H, Wresid]), min([H, Wresid])
    Hresidspl1 = Ht/2
    Hresidspl2 = Ht-Hresidspl1
    p2 = Wresid*Hresidspl1
    p3 = Wresid*Hresidspl2
ps2 = [p1, p2, p3]
diff2 = max(ps2)-min(ps2)

#third trial
Hp = int(ind1/W)
p1 = W*Hp
Hresid = H-Hp
if Hresid%2 == 0: p2 = p3 = Hresid/2*W
elif W%2 == 0: p2 = p3 = W/2*Hresid
else:
    Wt, Ht = max([Hresid, W]), min([Hresid, W])
    Wresidspl1 = Wt/2
    Wresidspl2 = Wt-Wresidspl1
    p2 = Hresid*Wresidspl1
    p3 = Hresid*Wresidspl2
ps3 = [p1, p2, p3]
diff3 = max(ps3)-min(ps3)

#fourth trial
Hp = int(ind1/W)+1
p1 = W*Hp
Hresid = H-Hp
if Hresid%2==0: p2 = p3 = Hresid/2*W
elif W%2 == 0: p2 = p3 = W/2*Hresid
else:
    Wt, Ht = max([Hresid, W]), min([Hresid, W])
    Wresidspl1 = Wt/2
    Wresidspl2 = Wt-Wresidspl1
    p2 = Hresid*Wresidspl1
    p3 = Hresid*Wresidspl2
ps4 = [p1, p2, p3]
diff4 = max(ps4)-min(ps4)

print min([diff1, diff2, diff3, diff4])


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  ll n,k;
  cin >> n >> k;
  vi a(n);
  rep(i,0,n) {
    cin >> a[i];
    --a[i];
  }

  vvi st(65, vi(n));
  rep(i,0,n) st[0][i] = a[i];

  rep(j,1,65) rep(i,0,n) st[j][i] = st[j-1][st[j-1][i]];

  int ans = 0;
  per(i,0,64) if (k&(1LL<<i)) ans = st[i][ans];
  cout << 1+ans << '\n';
}

Measured memory_bytes: 55736
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int N;
  cin>>N;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }
  int ANS = 0;
  for (int i = 1; i < N-1; i++)
  {
    vector<int> v;
    for (int j = 0; j < 3; j++)
    {
      v.push_back(vec[i+j-1]);
    }
    sort(ALL(v));
    // DEBUG(v);
    if(v[1] == vec[i]) ANS++;

  }
  cout<<ANS<<endl;
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader r =
         new BufferedReader(new InputStreamReader(System.in), 1);
         
        String s = r.readLine();    
        String[] w = s.split(" ",0); 
        int tate=Integer.parseInt(w[0]);
        int yoko=Integer.parseInt(w[1]);
        
        
        System.out.println(tate*yoko+" "+2*(tate+yoko));
        
        r.close();
    }
}

Measured memory_bytes: 24168
import math
from functools import reduce


n=int(input())
    
res=0
nlist=[]
for a in range(1,n+1):
    for b in range(1,n+1):
        nlist.append(math.gcd(a,b))
        
import collections

c = collections.Counter(nlist)
ck=list(c.keys())
cv=list(c.values())

cn=len(ck)

for i in range(cn):
    for c in range(1,n+1):
        res+=math.gcd(c,ck[i])*cv[i]
print(res)

Measured memory_bytes: 9880
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int main(){
	int n,max=0,ans=0;
	cin>>n;
	vector<int>A(n);
	for(int i=0;i<n;i++) cin>>A[i];
	for(int i=0;i<n;i++){
		if(A[i]>=max){
			ans++;
			max=A[i];
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=201010;
const ll mod=1e9+7;

vector<vector<ll>> dp(110, vector<ll>(mx,0));
vector<ll> w(110), v(110);
int n,c;

int main(){
  cin >> n >> c;
  rep(i,n){ cin>>w[i]>>v[i]; }
  
  rep(i,n)rep(j,c){
    dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j]+v[i]);
  }
  
  ll ans=0;
  rep(j,c+1){ ans = max(ans, dp[n][j]); }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 174720
def main():
    N = int(input())
    time = [0]*N
    data = [list(map(int,input().split()))for _ in range(N-1)]
    for i in range(N-1):
        for j  in range(i,N-1):
            c,s,f = data[j]
            if time[i] > s:
                tmp = time[i]-s
                if tmp % f != 0:
                    tmp //= f
                    tmp += 1
                else:
                    tmp //= f
                time[i] = s+tmp*f+c
            else:
                time[i] = s+c
    for t in time:
        print(t)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <stdio.h>

int main(){
  int n,i=100000000,j;
  scanf("%d",&n);
  n*=6283182;
  while(1){
    if(n/i!=0) break;
    i/=10;
  }
  while(i>=1000000){
    printf("%d",n/i);
    n%=i;
    i/=10;
  }
  printf(".");
  while(i>=1000){
    printf("%d",n/i);
    n%=i;
    i/=10;
  }
  return(0);
}

Measured memory_bytes: 1732
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner scan = new Scanner(System.in);
		String str = scan.next();

		String box[] = new String[str.length()];

		for(int i=0; i < str.length(); i++)
		{
			box[i]=String.valueOf(str.charAt(i));
		}

		String rebox[] = new String[str.length()];

		for(int i=0; i<str.length(); i++)
			rebox[i] =box[str.length()-1-i];

		for(int i=0; i<str.length(); i++)
			System.out.print(rebox[i]);

		System.out.println();
	}
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

ll dp[110][101000];
int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, W;
    cin >> N >> W;

    ll w[110], v[110];
    rep(i, N)
    {
        cin >> w[i] >> v[i];
    }

    memset(dp, 0, sizeof(dp));
    rep(i, N)
    {
        rep(j, W + 1)
        {
            if (j < w[i]) {
                dp[i + 1][j] = dp[i][j];
            } else {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            }
        }
    }

    cout << dp[N][W] << endl;
}


Measured memory_bytes: 87040
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n;
ll h[101010];
ll dp[101010];
int main(){
    cin>>n;
    REP(i, 0, n) cin>>h[i];
    REP(i, 1, n+2) dp[i]=inf;

    REP(i, 0, n-1){
        dp[i+1]=min(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
        dp[i+2]=min(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
    }

    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, i;
    std::cin >> N >> i;

    // std::string S;
    // std::cin >> S;


    std::cout << N - i + 1<< std::endl;

    return 0;
}


Measured memory_bytes: 256
// {{{ include and macros
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(a, b) for(int unsafe_cnt=a; unsafe_cnt < b;unsafe_cnt++)
#include <iostream>
// #include <stdio.h>
// #include <vector>
// #include <math.h>
// #include <algorithm>
// #include <string>
// #include <map>
// #include <set>
using namespace std;
// }}}

// {{{ put
void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
// }}}

long long fact(long long n){
    const long long m = 1e9 + 7;
    long long sum = 1;
    for (long long i = 1; i <= n; ++i){
        sum = (sum * i)%m;
    }
    return sum%m;
}

int main() {
  long long n, m;
  cin >> n >> m;
  if(abs(n-m) > 1){
    put("0");
  }else{
    const long long a = 1e9 + 7;
    if(n==m){
      const long long pattern = (fact(n) * fact(m))%a;
      put(((pattern%a)*(2%a))%a);
    }else{
      const long long pattern = (fact(n>m?n:m) * fact(n<=m?n:m))%a;
      put(pattern);
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <bitset>
#include <list>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> p(n), q(n), v(n);
	for (int i = 0; i < n; ++i) {
		cin >> p.at(i);
	}
	for (int i = 0; i < n; ++i) {
		cin >> q.at(i);
	}
	for (int i = 0; i < n; ++i) {
		v.at(i) = i + 1;
	}
	int pi = -1;
	int qi = -1;
	for (int i = 0; i < 100000; ++i) {
		if (p == v) {
			pi = i;
		}
		if (q == v) {
			qi = i;
		}
		if (pi != -1 && qi != -1) {
			break;
		}
		next_permutation(begin(v), end(v));
	}
	cout << abs(qi - pi) << endl;

	return 0;
}

Measured memory_bytes: 256
N=int(input())
Grid=[list(input()) for i in range(N)]
Grid_v=[list(x) for x in zip(*Grid)]
W,H=N,0
if Grid==[["."]*N for i in range(N)]:
  print(-1)
  exit()
for i in range(N):
  if Grid_v[i]!=["."]*N:
    W=min(W,N-Grid[i].count("#"))
  else:
    W=min(W,N-Grid[i].count("#")+1)
for i in range(N):
  if Grid_v[i]!=["#"]*N:
    H+=1
print(W+H)
        

Measured memory_bytes: 52336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N,K;
    cin>>N>>K;
    vector<int> A(N);
    rep(i,N)cin>>A.at(i);
    vector<bool> dp(K+1,false);
    rep(i,K+1){
        if(dp[i])continue;
        rep(j,N){
            if(i+A.at(j)<=K)dp[i+A.at(j)]=true;
        }
    }
    if(dp[K])cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n;
  cin >> n;
  cout << (n-1)/2 << endl;
  
  return 0;
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
// #define int long long
struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
}IoSetup;

using Int = __int128_t;
using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int SMOD = 1000000007;
constexpr int NMOD = 998244353;
constexpr int dx[]={1,0,-1,0,1,1,-1,-1};
constexpr int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T&b){if(a<b)return(a=b,1);return 0;}
template<class T>bool chmin(T &a, const T&b){if(b<a)return(a=b,1);return 0;}


signed main() {

    int x;
    cin >> x;

    cout << !(x) << endl;

    return 0;
}


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

long long n, a[3010], dp[3010][3010];

long long func(int l, int r){
//	cout << l << " " << r << "\n";
	if(dp[l][r] != -1) return dp[l][r];
	if(l > r) return 0;
	long long res = 0;
	if((r - l) % 2 != n % 2){
		res = max(a[l] + func(l+1, r), a[r] + func(l, r-1));
	}else{
		res = min(-a[l] + func(l+1, r), -a[r] + func(l, r-1));
	}
//	cout << l << " " << r << " " << res << "\n";
	return dp[l][r] = res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<n; ++i) cin >> a[i];
	int l = 0, r = n-1;
	memset(dp, -1, sizeof(dp));
	cout << func(l, r) << "\n";
}

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

#define int long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).end()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for(int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a,n) sort(a, a+n)
#define sortvec(V) sort(all(V))

typedef vector<int> V;
typedef pair<int , int> pairi;
typedef set<int> seti;
typedef deque<int> deqi;

const int MOD = 1e9+7;
const int INF = 1e9+8;
const double pi = 3.14159265359;

void solve()
{
    int a, c = 0;
    string b;
    cin >> a >> b;
    for(auto i : b)
        if(i != '.'){
            c += (i - '0');
            c *= 10;
        }
    c /= 10;
    cout << (a * c)/100 << endl;
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}


Measured memory_bytes: 3828
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int x, y, ans;
    cin >> x >> y;

    vector<int> win = {300000, 200000, 100000};
    ans = 0;
    
    if (x < 4)
        ans += win[x - 1];
    if(y < 4) ans += win[y - 1];

    if(x == 1 && y == 1) ans += 400000;

    cout << ans << endl;

    return 0;
}


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

int main(){
    vector<string> word(3);
    for(int i = 0;i < 3;i++)cin >> word.at(i);
    vector<char> compare{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    vector<char> ANS{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
    for(int i = 0;i < 3;i++){
        for(int j = 0;j < compare.size();j++){
            if(word.at(i).at(0) == compare.at(j)){
                cout << ANS.at(j);
                break;
            }
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;
long long int a[1000];
int main()
{
    //int i,j;

    for(int i=0;i<10;i++)
    {
        scanf("%lld",&a[i]);
    }
    sort(a,a+10);

    for(int j=9;j>=7;j--)
    printf("%lld\n",a[j]);
}

Measured memory_bytes: 1044
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<int> a(n + 1);
  for(int i = 0; i < n; i++){
    cin >> a[i + 1];
  }
  int j = 1, sum = 0, x;
  while(sum <= n){
    x = a[j];
    j = a[j];
    sum++;
    if(x == 2){
      cout << sum << endl;
      return;
    }
  }
  cout << -1 << endl;
  return;
}

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


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  string S;
  cin >> S;
  S.erase(unique(S.begin(), S.end()), S.end());
  long white = 0;
  long black = 0;
  for (auto c: S) if (c == 'B') black++; else white++;

  if (white == 0 or black == 0) {
    cout << 0 << endl;
    return;
  }

  if (white == black) {
    // 1, 3, 5, ...
    cout << white * 2 - 1 << endl;
    return;
  }

  if (white != black) {
    // WBW: 2
    // WBWBW: 4
    // WBWBWBW: 6
    long foo = min(white, black);
    cout << foo * 2 << endl;
    return;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

char syuki[2][2] = {{'U','R'},{'D','L'}};

int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int u = D - B, r = C - A;
  Rep(p,2) {
    Rep(c,2) {
      if(p == 1 && c == 1)cout << "DR";
      Rep(i,u)cout << syuki[c][0];
      Rep(i,r)cout << syuki[c][1];
    }
    if(p == 0)cout << 'L';
    u++, r++;
  }
  cout << 'U' << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func line() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	ns := line()
	n, _ := strconv.Atoi(ns)
	seen := make(map[string]int, n)
	for i := 0; i < n; i++ {
		seen[line()]++
	}

	max := 0
	ans := make([]string, 0, n)
	for k, v := range seen {
		if v > max {
			ans = []string{k}
			max = v
		} else if v == max {
			ans = append(ans, k)
		}
	}
	sort.Sort(byStr(ans))
	for _, a := range ans {
		fmt.Println(a)
	}
}

type byStr []string

func (s byStr) Len() int      { return len(s) }
func (s byStr) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s byStr) Less(i, j int) bool {
	return s[i] < s[j]
}


Measured memory_bytes: 26368
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <sstream>

using namespace std;

int main() {
    int N;
    cin >> N;
    map<int, bool> d;
    for(int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        d[tmp] = true;
    }

    cout << d.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

const double INF = 1e20, EPS = 1e-8;

double W, H, w, h, x, y;
double lx, hx, ly, hy;

// x = vx (y1 <= y <= y2)の部分とy = axが交わるか
bool intersect_x(double a, double vx, double y1, double y2, double &px, double &py) {
  double vy = a * vx;
  if (!(y1 - EPS < vy && vy < y2 + EPS)) return false;
  px = vx;
  py = vy;
  return true;
}

// y = vy (x1 <= x <= x2)の部分とy = axが交わるか
bool intersect_y(double a, double vy, double x1, double x2, double &px, double &py) {
  if (abs(a) < EPS) return false;
  double vx = vy / a;
  if (!(EPS + x1 < vx && vx < x2 + EPS)) return false;
  px = vx;
  py = vy;
  return true;
}

bool ok(double a) {
  double x[4], y[4], b[4];
  b[0] = intersect_x(a, lx, ly, hy, x[0], y[0]);
  b[1] = intersect_y(a, hy, lx, hx, x[1], y[1]);
  b[2] = intersect_x(a, hx, ly, hy, x[2], y[2]);
  b[3] = intersect_y(a, ly, lx, hx, x[3], y[3]);

  ll cnt = 0;
  REP(i, 0, 4) if (b[i]) cnt++;

  double s;
  if (cnt == 3 || cnt == 4) {
    return true;
  } else if (b[0] && b[1]) {
    s = (hy - y[0]) * (x[1] - lx) / 2;
  } else if (b[1] && b[2]) {
    s = (hx - x[1]) * (hy - y[2]) / 2;
  } else if (b[2] && b[3]) {
    s = (hx - lx) * (hy - ly) - (y[2] - ly) * (hx - x[3]) / 2;
  } else if (b[3] && b[0]) {
    s = (hx - lx) * (hy - ly) - (x[3] - lx) * (y[0] - ly) / 2;
  } else if (b[0] && b[2]) {
    s = ((hy - y[0]) + (hy - y[2])) * (hx - lx) / 2;
  } else if (b[1] && b[3]) {
    s = ((x[1] - lx) + (x[3] - lx)) * (hy - ly) / 2;
  } else {
    return ly > a * lx;
  }

  return s > (hx - lx) * (hy - ly) / 2 - EPS;
}

int main(void) {
  cin >> W >> H >> w >> h >> x >> y;

  lx = max(-W / 2, x - w / 2);
  hx = min(+W / 2, x + w / 2);
  ly = max(-H / 2, y - h / 2);
  hy = min(+H / 2, y + h / 2);

  double l = -INF, h = INF;
  REP(i, 0, 250) {
    double m = (l + h) / 2;
    if (ok(m)) l = m;
    else h = m;
  }
  printf("%.15lf\n", h);
}


Measured memory_bytes: 3292
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s;
  	cin >> s;
  
	int price = 700;
  	if (s[0] == 'o') price += 100;
  	if (s[1] == 'o') price += 100;
  	if (s[2] == 'o') price += 100;
  
  	cout << price << endl;
  	return 0;
}

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

int main() {
  int N;
  cin >> N;
  string ans = "Three";
  for (int i = 0; i < N; ++i) {
    char S;
    cin >> S;
    if (S == 'Y') {
      ans = "Four";
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    LL n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    int gcd = __gcd( n, m );
    LL l = n / (LL)gcd * m;

    bool flg = true;
    for( LL i = 0; i < gcd && flg; ++i ) {
        if( s[i * n / (LL)gcd] != t[i * m / (LL)gcd] ) flg = false;

    }

    if( flg ) cout << l;
    else cout << -1;
    cout << endl;

    return 0;
}



Measured memory_bytes: 640
a = [0 for _ in range(5)]
b = [0 for _ in range(5)]

for i in range(5):
    d = int(input())
    a[i] = d // 10
    if d % 10 != 0:
        a[i] += 1
    b[i] = (d-1) % 10

print((sum(a) - 1) * 10 + min(b) + 1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n>=400 && n<=599){
        cout<<8<<"\n";
    }
    else  if(n<=799){
        cout<<7<<"\n";
    }
    else if(n<=999){
        cout<<6<<"\n";
    }
    else if(n<=1199){
        cout<<5<<"\n";
    }
    else if(n<=1399){
        cout<<4<<"\n";
    }
    else if(n<=1599){
        cout<<3<<"\n";
    }
    else if(n<=1799){
        cout<<2<<"\n";
    }
    else{
        cout<<1<<"\n";
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
int kaijo(int n){
	int ans=1;
	for(int i=2;i<=n;i++){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
	return kaijo(a)*modpow(kaijo(a-b),MOD-2)%MOD*modpow(kaijo(b),MOD-2)%MOD;
}
signed main(){
	int a,p;
	cin>>a>>p;
	p+=a*3;
	cout<<p/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

int main(){
  int n,x;cin>>n>>x;
  vi d(n+1,0);
  int ans=1;
  for(int i=1;i<n+1;i++){
    int l;cin>>l;
    d.at(i)=d.at(i-1)+l;
    if(d.at(i)<=x) ans++;
  }
  cout<<ans<<endl;
}

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

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}

bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

pair<int ,int> ab[100001], ab2[100001];
int h, n;
struct ka{
    int a,b,n;
};
int main(){
    cin >> n >> h;
    for(int i = 0; i < n; i++){
        cin >> ab[i].first >> ab[i].second;
        ab2[i] = ab[i];
    }

    sort(ab, ab+n);
    sort(ab2, ab2+n, SecondCompare);
    int ans = 0;
    int thrownum = n-1;
    while(h > 0){
        if(thrownum >= 0 && ab[n-1].first < ab2[thrownum].second){
            h -= ab2[thrownum].second;
            thrownum--;
        }
        else{
            if(h % ab[n-1].first == 0)  ans += h/ab[n-1].first;
            else    ans += h/ab[n-1].first + 1;
            break;
        }
        ++ans;
    }
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	int l[n];
	for(int i = 0; i < n; i++){
		cin >> l[i];
	}
	sort(l, l + n);
	int ans = 0;
	for(int i = n - 1; i >= n - k; i--){
		ans += l[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>

using namespace std;

int gcd(int a, int b) {
	if (a > b) {
		swap(a, b);
	}

	if (a == 0) {
		return b;
	}
	return gcd(b%a, a);
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);

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

	vector<int> gcd1(n);
	vector<int> gcd2(n);

	gcd1[0] = a[0];
	for (int i = 1; i < n; i++) {
		gcd1[i] = gcd(a[i], gcd1[i - 1]);
	}
	

	gcd2[n - 1] = a[n - 1];
	for (int i = n - 2; i >= 0; i--) {
		gcd2[i] = gcd(a[i], gcd2[i + 1]);
	}
	
	int ans = gcd2[1];
	for (int i = 1; i < n - 1; i++) {
		int g = gcd(gcd1[i - 1], gcd2[i + 1]);
		if (ans < g) {
			ans = g;
		}
	}

	if (ans < gcd1[n - 2]) {
		ans = gcd1[n - 2];
	}

	cout << ans << endl;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,d,e;
  cin>>a;
  cin>>b;
  c=a-b;
  d=a+b;
  e=a*b;
  if (c>d && c>e)
  {
    cout<<c;
  }
  else if(d>c && d>e)
  {
   cout<<d;
  }
  else if(e>c && e>d)
  {
  	cout<<e;
  }
  else
    cout<<c;
}
    

Measured memory_bytes: 256
n = int(input())
A, B = 0, 0
for i in range(n):
    x, y = map(int,input().split())
    dx, dy = 1, 1
    if A > x:
        dx = A // x
        if A % x != 0:
            dx += 1
    
    if B > y:
        dy = B // y
        if B % y != 0:
            dy += 1
 
    a = max(dx, dy)
    A, B = a * x, a * y
print(A + B)

Measured memory_bytes: 9140
/*
  In the name of ALLAH
  Author : Raashid Anwar
*/
 
#include <bits/stdc++.h>
using namespace std;
 
#define int int64_t
const int M1 =  998244353;
const int M2 =  1000000007;

int b[200001];

void upd(int i, int x) {
  for(; i <= 20000; i += (i & -i))
    b[i] += x;
}

int get(int i) {
  int sum = 0;
  for(; i; i -= (i & -i))
    sum += b[i];
  return sum;
}
 
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int sum = 0, l = 0, r = s.size() - 1;
  while(l < r) {
    while(l < r && s[l] == 'R')
      l++;
    while(r > l && s[r] == 'W')
      r--;
    if(l >= r)
      break;
    sum++;
    swap(s[l], s[r]);
  }
  cout << sum << "\n";
}
 
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
}

Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main() {
  string s, t;
  int n, m;

  cin >> s >> t;
  n = s.size(), m = t.size();

  vector<set<int>> pos(26);
  for (int i = 0; i < n; ++i) {
    auto c = s[i];
    pos[c-'a'].insert(i);
  }

  long long int ans = 0;
  int p = n-1;
  for (int i = 0; i < m; ++i) {
    auto c = t[i];
    auto np = pos[c-'a'].upper_bound(p);
    if (np == pos[c-'a'].end()) np = pos[c-'a'].upper_bound(-1);
    if (np == pos[c-'a'].end()) {
      cout << -1 << endl;
      return 0;
    }
    auto d = *np-p;
    if (d <= 0) d += n;
    ans += d;
    p = *np;
  }

  cout << ans << endl;
  return 0;
}


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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    int x;
    cin >> x;

    int ans = 0;

    ans += (x / 500) * 1000;
    x = x % 500;

    ans += (x / 5) * 5;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
using namespace std;

int main(){

    int n;
    cin >> n;

    int v[n], c[n];
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    for(int i=0; i<n; i++){
        cin >> c[i];
    }

    int imax = pow(2.0, n);
    int buyParam=0;
    int buy[n] = {};
    int profit = 0;

    while(buyParam < imax+1){

        int temp = buyParam;
        for(int i=0; i<n; i++){
            buy[i] = temp%2;
            temp /= 2;
        }

        int X=0, Y=0;
        for(int i=0; i<n; i++){
            if(buy[i] == 1){
                X += v[i];
                Y += c[i];
            }
        }
        if(profit < X-Y){
            profit = X-Y;
        }
        buyParam++;
    }

    cout << profit;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <math.h>
 
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
	int a,b,k,c,d,e,f;
	cin >> k >> a >> b;
    c = b - a;
    d = a/k;
    e = b/k;
    f = e-d;
    if(k == 1){
      cout << "OK" << "\n";
      return 0;
    }
    if(a%k == 0){
      cout << "OK" << "\n";
      return 0;
    }
    if(b%k == 0){
      cout << "OK" << "\n";
      return 0;
    }
    if(f > 0){
      cout << "OK" << "\n";
      return 0;
    }else{
      cout << "NG" << "\n";
      return 0;
    }
    
  
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io
	int n,a,b;
	cin>>n;
	if(n==1) cout<<"Hello World ";
	else {
	cin>>a>>b;
	cout<<(a+b);
	}
	return 0;
}

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

int main ( void )
{
	int n, r, dis;
	cin >> n >> r;

	if ( ( n < 1 ) && ( 100 < n ) ){
		cout << "ERROR!\n";
		return 0;
	}

	if ( ( r < 0 ) && ( 4111 < r ) ){
		cout << "ERROR!\n";
		return 0;
	}

	if ( n >= 10 ){
		cout << r << "\n";
	} else {
		dis = r + ( 100 * ( 10 - n ) );
		cout << dis << "\n";
	}

	return 0;
}

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

#define pb push_back
#define mp make_pair
#define size(n) ( int( n.size() ) )
#define sqr(n) ( (n) * (n) )
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 5;
vector < int > path, g[N];
int parent[N], x, sz[N], n;

void dfs( int v ){
    path.pb(v);
    if ( v == n ){
        if ( size(path) % 2 == 0 ){
            x = path[ size(path) / 2 ];
        }
        else{
            x = path[ size(path) / 2 + 1 ];
        }
    }
    sz[v] = 1;
    for ( int j = 0; j < size(g[v]); j++ ){
        int u = g[v][j];
        if ( u != parent[v] ){
            parent[u] = v;
            dfs(u);
            sz[v] += sz[u];
        }
    }
    path.pop_back();
}

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    scanf("%d",&n);
    for ( int i = 1; i <= n - 1; i++ ){
        int v, u;
        scanf("%d %d",&v,&u);
        g[v].pb(u);
        g[u].pb(v);
    }
    dfs(1);
    int cb = n - sz[x] - 1, cw = sz[x] - 1;
    if ( cb > cw ){
        puts("Fennec");
    }
    else{
        puts("Snuke");
    }
    return 0;
}


Measured memory_bytes: 11640
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pow10(n) stoll("1"+string(n,'0'))
int main(){
  string s;
  int cnt=0,n;
  cin>>n;
  cin>>s;
  for(int i=0;i<n;i++)
  {
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
      cnt++;
  }
      cout<<cnt;
}


Measured memory_bytes: 256
let input = require("fs").readFileSync("/dev/stdin", "utf8")

function main({ input, load, yesno, math_sum, math_max, math_min, log_json }) {
    const [A,B] = load(2)
    console.log(A*B)
}



let inputs = input.split(/[\s\n]/)
main({
    input,
    yesno: value => value ? 'Yes' : 'No',
    math_sum: numbers => numbers.reduce((acc, cur) => acc + cur, 0),
    load(rows = 1, cols = 1, is_number = true) {
        const length = rows * cols
        let result = inputs.splice(0, length)
        if(is_number) result = result.map(Number)
        if(cols > 1) {
            const arrays = new Array(cols)
            for(let col = 0; col < cols; col++) {
                arrays[col] = new Array()
                for(let row = 0; row < rows; row++) {
                    arrays[col].push(result[row * cols + col])
                }
            }
            result = arrays
        }
        return result
    },
    inifinite_loop_preventer() {
        throw new Error("Infinite loop")
    },
    math_max,
    math_min,
    log_json(value) {
        console.log(JSON.stringify(value))
    },
})


function math_max(numbers, initial_value = null) {
    let result = (initial_value === null) ? numbers[0] : initial_value
    for(const n of numbers) if(n > result) result = n
    return result
}

function math_min(numbers, initial_value = null) {
    let result = (initial_value === null) ? numbers[0] : initial_value
    for(const n of numbers) if(n < result) result = n
    return result
}


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

const int N = 3333;

double dp[N][N];

int main()
{
  int n;
  cin >> n;
  vector<double> a(n+1);
  for(int i=1;i<=n;++i)
    cin >> a[i];
  
  dp[0][0] = 1;
  for(int i=1;i<=n;++i)
  {
    for(int j = 0; j <= i; ++j)
    {
      dp[i][j] = dp[i-1][j] * (1.0 - a[i]); 
      if(j) dp[i][j] += dp[i-1][j-1] * a[i];
    }
  }
  
  double ans = 0;
  
  for(int i=(n+1)/2; i<= n;++i)
    ans += dp[n][i];
  
  cout << fixed << setprecision(10) << ans << endl;
  
  return 0;
}


Measured memory_bytes: 78464
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

#define N_MAX 100001

int color[N_MAX];
vector<pair<int, int> > edge[N_MAX];

void dfs(int index)
{
	for (int i = 0; i < edge[index].size(); i++){
		if (-1 != color[edge[index][i].first]){
			continue;
		}
		color[edge[index][i].first] = (color[index] + edge[index][i].second) % 2;
		dfs(edge[index][i].first);
	}

	return;
}

void solv()
{
	int N; scanf("%d", &N);

	for (int i = 0; i < N - 1; i++){
		int u, v, w; scanf("%d%d%d", &u, &v, &w);
		u--; v--;
		w = w % 2;
		edge[u].push_back(make_pair(v, w));
		edge[v].push_back(make_pair(u, w));
	}

	fill(color, color + N, -1);
	color[0] = 0;
	dfs(0);

	for (int i = 0; i < N; i++){
		printf("%d\n", color[i]);
	}

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int gcd(int a, int b)
{
  return b == 0 ? a : gcd(b, a % b);
}

int main()
{
  int A, B, C; scanf("%d %d %d", &A, &B, &C);
  printf("%s\n", C % gcd(A, B) == 0 ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256