akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll ans=0;
  for(ll i=1; i*i<=m; i++) {
    if(m%i==0) {
      if(m/i>=n) ans=max(ans,i);
      if(i>=n) ans=max(ans,m/i);
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

using namespace std;

string s;
int n, ac, wa, tle, re;

int main(){
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> s;
		if(s == "AC") ac++;
		else if(s == "WA") wa++;
		else if(s == "TLE") tle++;
		else re++;
	}
	printf("AC x %d\n", ac);
	printf("WA x %d\n", wa);
	printf("TLE x %d\n", tle);
	printf("RE x %d\n", re);
}

Measured memory_bytes: 3756
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>

#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

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

  vector<int> H(N);
  for (int i = 0; i < N; ++i) cin >> H[i];

  vector<int> max_num(N, 0);
  for (int i = 0; i < M; ++i)
  {
    int A, B;
    cin >> A >> B;
    max_num[A - 1] = max(max_num[A - 1], H[B - 1]);
    max_num[B - 1] = max(max_num[B - 1], H[A - 1]);
  }

  int result = 0;
  for (int i = 0; i < N; ++i)
  {
    if (H[i] > max_num[i] || max_num[i] == 0) ++result;
  }

  cout << result;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
 
typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
 
int main(){
    string s;
    cin >> s;
    ll k;
    cin >> k;
    ll len = s.size();
    int memo[len];
    for(ll i = 0; i < len; i++){
        memo[i] = s[i] - 'a';
    }

    for(ll i = 0; i < len; i++){
        if(memo[i] == 0)    continue;
        
        if(26 - memo[i] <= k){
            k -= 26 - memo[i];
            memo[i] = 0;
        }
    }
 
    k %= 26;
    memo[len-1] += k;
    memo[len-1] %= 26;
 
    for(ll i = 0; i < len; i++){
        s[i] = memo[i]+'a';
    }

    cout << s << endl;
 
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
using namespace std;
string b[1000000];
bool cmp(string a, string b)
{
    return a < b;
}
int main()
{
    //freopen("test.in","r",stdin);
    //freopen("test.out","w",stdout);

    int n,l;
    cin >> n >> l;
    for(int i = 1;i <= n;++i)
        cin >> b[i];
    sort(b + 1,b + 1 + n,cmp);   //sort
    for(int i = 1;i <= n;++i)
        cout << b[i];
    return 0;
}

Measured memory_bytes: 8064
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int n;
map<char, int> cnt;
string s = "MARCH";

int main() {
    fastio();

    cin >> n;
    forn(i, n) {
        string x;
        cin >> x;
        cnt[x[0]]++;
    }

    ll ans = 0;
    for (int p = 0; p < (1 << s.size()); p++) {
        if (popcnt(p) != 3) continue;

        ll temp = 1;
        for (int i = 0; i < s.size(); i++) {
            if ((p >> i) & 1) {
                temp *= cnt[s[i]];
            }
        }

        ans += temp;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from math import pi
# import bisect
# from collections import deque

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 998244353


# for _ in range(int(ri())):
n= int(ri())
a = Ri()
dic  = {}
for i in a:
    if i in dic:
        dic[i]+=1
    else:
        dic[i] = 1

for i in range(1,n+1):
    if i in dic:
        print(dic[i])
    else:
        print(0)

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

void sieve(vector<int>& primes)
{
  int n = primes.size();
  primes[0] = primes[1] = 0;
  for (int i = 2; i * i < n; ++i) {
    if (not primes[i]) { continue; }
    for (int j = i * i; j < n; j += i) {
      primes[j] = 0;
    }
  }
}

int main()
{
  int N; scanf("%d", &N);
  int upper = 55555;
  vector<int> primes(upper + 5, 1);
  sieve(primes);
  int cnt = 0;
  vector<int> ans;
  for (int p = 2; p <= 55555; ++p) {
    if (primes[p] and (p % 5) == 1) {
      ans.push_back(p);
      if (++cnt == N) { break; }
    }
  }
  printf("%d", ans[0]);
  for (int i = 1; i < N; ++i) {
    printf(" %d", ans[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#define M 45
int f[M]; 
int F(int);
 
int main(int argc,char *argv[]){
  int n,i;
  f[0] = 1;
  f[1] = 1;
   
  scanf("%d",&n);
   
  for(i = 2; i < M; i++){
    f[i] = -1;
  }
   
  printf("%d\n",F(n));
    
  return 0;
}

int F(int n){
  int x;
   
  if(f[n] != -1) return f[n];
  x = F(n-1) + F(n-2);
  f[n] = x;
  return x;
}

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

int main() {
    int n;

    cin >> n;
    int a[n];

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

    for(int i = n -1; i >= 0; i-- ) {
        cout << a[i];
        if(i != 0){
        cout << ' ';
        }
    }
    cout << endl;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  int s = 0, x;

  cin >> n;

  x = n;
  while(x != 0){
    s += (x % 10);
    x /= 10;
  }

  if(n % s == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define N 1000
#define M 1000000007
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define bs binary_search
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;
/**
  * @author :: Rishabh
  *
  */
int main()
{
	ibs;
	cti;
	ll n;
	cin>>n;
	ll a[n];
	ll dp[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	dp[0]=a[0];
	dp[1]=a[1]*a[0];
	ll b[n];
	b[0]=a[0];
	b[1]=a[0]+a[1];
	for(ll i=2;i<n;i++)
	{
		b[i]=b[i-1]+a[i];
		b[i]=b[i]%M;
	}
	for(ll i=2;i<n;i++)
	{
		dp[i]=dp[i-1]+(a[i]*b[i-1]);
		dp[i]=dp[i]%M;
	}
	cout<<dp[n-1]%M<<"\n";
	return 0;
}

Measured memory_bytes: 8368
def is_prime(num):
    if num == 1:
        raise ValueError("error!")
    d = 2
    while d * d <= num:
        if num % d == 0:
            return False
        d += 1
    return True

n = int(input())
for i in range(n, n+1000):
    if is_prime(i):
        print(i)
        exit()


Measured memory_bytes: 2940
N = list(input())
if len(N) == 1:
    print(int(N[0]))
elif N.count('9') == len(N):
    print(len(N) * 9)
else:
    for i in range(len(N)):
        if N[i] != '9':
            idx = i
            break
    if idx == len(N) - 1:
        print(sum(map(int, N[:-1])) + 8)
    else:
        if N[idx] == '0':
            print(len(N) * 9 - 1)
        elif N[idx + 1:].count("9") == len(N[idx + 1:]):
            print(sum(map(int, N)))
        else:
            print(sum(map(int, N[:idx + 1])) + (len(N) - idx - 1) * 9 - 1)


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <chrono>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#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 FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong pow(int x, int n) {
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}

int min(int a, int b) {
    if (a > b) {
        return b;
    } else {
        return a;
    }
}

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

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

    int n, d, x;
    int a[100] = {0};
    cin >> n;
    cin >> d >> x;
    rep(i, n) {
        cin >> a[i];
    }

    int cnt = 0;

    rep(i, n) {
        cnt += (d - 1) / a[i] + 1;

    }

    cout << cnt + x << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i,s,e) for (int64_t i=s; i<e; i++)
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int64_t X, K, D, mod, T;
  cin >> X >> K >> D;
  if (X<=0) {
    X=-X;
  }
  mod=X%D;
  T=(X-mod)/D;
  if (T>=K) {
    cout << X-D*K << endl;
  }
  else {
    if (T%2==K%2) {
      cout << mod << endl;
    }
    else {
      cout << D-mod << endl;
    }
  }
}

Measured memory_bytes: 3600
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;

namespace Fish.aizu
{
	public static class AizuOnlineJudge
	{
		public static int[] SplitToInts(string line)
		{
			return line.Split(' ').Select(x => int.Parse(x)).ToArray();
		}
		public static double[] SplitToDoubles(string line)
		{
			return line.Split(' ').Select(x => double.Parse(x)).ToArray();
		}
		public static long[] SplitToLongs(string line)
		{
			return line.Split(' ').Select(x => long.Parse(x)).ToArray();
		}
		public static int Main()
		{
			Compute(Console.In, Console.Out);
			return 0;
		}
		
		public static void Compute(TextReader reader, TextWriter writer)
		{
			while (true)
			{
				var v = SplitToInts(reader.ReadLine());
				var n = v[0];
				var x = v[1];
				var count = 0;
				
				if (n == 0 && x == 0) return;
				
				for (var a = 1; a <= n && x - a >= x / 3; a++)
				{
					for (var b = a + 1; b <= n && x > b * 2; b++)
					{
						for (var c = b + 1; c <= n; c++)
						{
							if (a + b + c == x)
							{
								count++;
							}
						}
					}
				}
				writer.WriteLine(count);
			}
		}
	}
}

Measured memory_bytes: 5920
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int a,b;
	cin >> a >> b;
	set<int> st;
	for(int i = 1;i <= 3;i++) st.insert(i);
	st.erase(a);
	st.erase(b);
	cout << *st.begin() << endl;
}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
  int h, w;
  char f[50][51];
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; ++i)
  {
    scanf("%s", f[i]);
  }
  
  const int dir[] = {0, 1, 1, 1, 0, -1, -1, -1, 0, 1};
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      if (f[i][j] == '#') continue;
      char c = '0';
      for (int d = 0; d < 8; ++d)
      {
        int X = j + dir[d + 2];
        int Y = i + dir[d];
        if (0 <= X && X < w && 0 <= Y && Y < h)
        {
          if (f[Y][X] == '#') ++c;
        }
      }
      f[i][j] = c;
    }
    puts(f[i]);
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
using namespace std;


int main(void){
    //printf("fdsfjaofiojaisdf");
    int x1,x2,x3,x4,x5;
    
    cin >> x1 >> x2 >> x3 >> x4 >> x5;
    
    if(x1 == 0){
        cout << 1;
    }else if(x2 == 0){
        cout << 2;
    }else if(x3 == 0){
        cout << 3;
    }else if(x4 == 0){
        cout << 4;
    }else if(x5 == 0){
        cout << 5;
    }
    
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

const int N=200;

int h,w;
int a[N][N];
int dp[N][N][2*N];

int dx1[]={1,0,1,0},dy1[]={0,1,0,1};
int dx2[]={1,1,0,0},dy2[]={0,0,1,1};

int dfs(int X1,int Y1,int X2,int Y2) {
	if(dp[X1][X2][X1+Y1]!=-1) return dp[X1][X2][X1+Y1];
	int res=0;
	res+=a[Y1][X1];
	if(X1!=X2||Y1!=Y2) res+=a[Y2][X2];
	int ma=0;
	REP(i,4) {
		int nx1=X1+dx1[i],ny1=Y1+dy1[i];
		int nx2=X2+dx2[i],ny2=Y2+dy2[i];
		if(nx1<0||nx1>=w||ny1<0||ny1>=h||nx2<0||nx2>=w||ny2<0||ny2>=h) continue;
		ma=max(ma,dfs(nx1,ny1,nx2,ny2));
	}
	//cout<<'('<<X1<<','<<Y1<<','<<X2<<','<<Y2<<')'<<' '<<res<<' '<<ma<<endl;
	return dp[X1][X2][X1+Y1]=res+ma;
}

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

	cin>>h>>w;
	REP(i,h) REP(j,w) cin>>a[i][j];
	REP(i,N) REP(j,N) REP(k,2*N) dp[i][j][k]=-1;

	cout<<dfs(0,0,0,0)<<endl;

	return 0;
}


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

int main() {
 string s;
  cin >> s;
  int m=s.size();
  vector<char> ans;
  for(int i=0;i<m;i++){
    if(s[i]=='0' || s[i]=='1') ans.push_back(s[i]);
    if(s[i]=='B'){
      if(ans.size()>0)  ans.pop_back();

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

}


Measured memory_bytes: 256
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


S = sys.stdin.readline().rstrip()
if len(S)==2:
    print(S)
else:
    print(S[::-1])


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

using namespace std;
typedef long long ll;

ll comb(ll N){
  if(N==0){
    return 0;
  }
  
  ll res=1;

  for(int i=0;i<N;i++){
    res *= (i+1);
  }

  return res;
}

int main(void)
{
  ll N;cin>>N;
  vector<ll> P(N);
  vector<ll> Q(N);

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

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

  vector<int> Nums1(N);
  vector<int> Nums2(N);
  for(int i=0;i<N;i++){
    Nums1[i]=i+1;
    Nums2[i]=i+1;
  }

  ll pl1=0;
  ll pl2=0;
  for(ll i=0;i<N;i++){
    auto minnum = min_element(Nums1.begin(),Nums1.end());
    ll num = P[i]-*minnum;
    int times = find(Nums1.begin(),Nums1.end(),P[i])-Nums1.begin();
    //cout<<times<<"!"<<num<<"!"<<*minnum<<"!"<<pl1<<endl;
    pl1 += comb(N-i-1)*times;
    Nums1.erase(find(Nums1.begin(),Nums1.end(),P[i]));
  }

  for(ll i=0;i<N;i++){
    auto minnum = min_element(Nums2.begin(),Nums2.end());
    ll num = Q[i]-*minnum;
    int times = find(Nums2.begin(),Nums2.end(),Q[i])-Nums2.begin();
    pl2 += comb(N-i-1)*times;
    //cout<<num<<"!"<<*minnum<<"!"<<pl2<<endl;
    Nums2.erase(find(Nums2.begin(),Nums2.end(),Q[i]));
  }
  
  //cout<<pl2<<endl;

  ll res = abs(pl1-pl2);

  cout<<res<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll ans1 = 0;
	ll ans2 = 0;
	ll sum = 0;
	rep(i, n) {
		sum += a[i];
		if (i % 2 == 0) {
			if (sum <= 0) {
				ans1 += 1 - sum;
				sum = 1;
			}
		}
		else {
			if (sum >= 0) {
				ans1 += sum + 1;
				sum = -1;
			}
		}
	}
	sum = 0;
	rep(i, n) {
		sum += a[i];
		if (i % 2 != 0) {
			if (sum <= 0) {
				ans2 += 1 - sum;
				sum = 1;
			}
		}
		else {
			if (sum >= 0) {
				ans2 += sum + 1;
				sum = -1;
			}
		}
	}
	cout << min(ans1, ans2) << endl;
	return 0;
}

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

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)

typedef long long ll;

int main()
{
    int A,B,C;
    int x;
    cin >> A >> B >> C >> x;

    int ans = 0;

    FOR(i,0,A+1){
        FOR(j,0,B+1){
            FOR(k,0,C+1){
                int total = i*500+j*100+k*50;
                if(total == x) ans++;
            }
        }
    }
    cout << ans << endl;
    
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  long long A, B;
  string op;
  cin >> A >> op >> B;
  if (op == "+") {
    cout << (A + B) << endl;
  }
  else {
    cout << (A - B) << endl;
  }
  return 0;
}


Measured memory_bytes: 3548
from math import gcd, sqrt, cos, radians, pi, floor, ceil
from collections import defaultdict as d
from itertools import combinations as c
from string import ascii_lowercase as a

h, w, k = map(int, input().split())
t = []
total = 0
for i in range(h):
	t+=[input()]
	total += t[-1].count('#')
count = 0
for i in range(h):
	for j in range(w):
		for u in c(list(range(h)), i):
			for v in c(list(range(w)), j):
				cnt = 0
				for x in u:
					cnt += t[x].count('#')
				for x in v:
					for y in range(h):
						if t[y][x] == '#' and y not in u:cnt += 1
				if total - cnt == k:
					count += 1
print(count)

Measured memory_bytes: 9968
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
ll c;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> c;
  vector<ll> x(n + 1), v(n + 1), vc(n + 1), r(n + 1), l(n + 1);
  x[0] = 0, v[0] = 0;
  FOR(i, 1, n + 1) cin >> x[i] >> v[i];

  // vc[0] = 0;
  // FOR(i, 1, n + 1) vc[i] = vc[i - 1] + v[i];

  ll sum;
  r[0] = 0;
  FOR(i, 1, n + 1) {
    sum += v[i];
    r[i] = max(r[i - 1], sum - x[i]);
  }

  l[n] = max(0LL, v[n] - (c - x[n]));
  sum = v[n];
  for(int i=n-1; i>0; i--) {
    sum += v[i];
    l[i] = max(l[i + 1], sum - (c - x[i]));
  }

  ll ans = 0;
  REP(i, n) {
    ans = max(ans, r[i] - x[i] + l[i + 1]);
  }

  for(int i=n; i>0; i--) {
    ans = max(ans, l[i] - (c - x[i]) + r[i - 1]);
  }

  ans = max(ans, l[n]);
  ans = max(ans, r[n]);
  cout << ans << endl;
}


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

int gcd(int a, int b, int c) {
	while (a % b != 0) {
		int a_hold = a;
		a = b;
		b = a_hold % b;
	}
	while (b % c != 0) {
		int b_hold = b;
		b = c;
		c = b_hold % c;
	}
	return c;
}

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

	int ans = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int l = 1; l <= k; l++) {
				ans += gcd(i,j,l);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define int long long

#define MOD 2019

signed main() {
  std::string s;
  std::cin >> s;

  int n = s.length();

  int cur = 0;
  int ans = 0;
  std::vector<int> dp(MOD, 0);
  dp[0] = 1;

  int pow = 1;
  for(int i = n-1; i >= 0; i--) {
    pow = (10*pow)%MOD;
    cur = (cur + (s[i]-'0')*pow)%MOD;

    ans += dp[cur];
    dp[cur]++;
  }

  std::cout << ans << std::endl;

  return 0;
}



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

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


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

using namespace std;

int main(){
  int n;
  scanf("%d",&n);
  int m=100000;
  for (int i=0;i<n;i++){
    m*=1.05;
    if (m%1000){
      m=m/1000*1000+1000;
    }
  }
  printf("%d\n",(int)m);
  return 0;
}

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

long long mod=1e9+7;
string grid[1005];
long long dp[1005][1005];

int main(){
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;++i){
		cin>>grid[i];
		grid[i]=" "+grid[i];
	}

	dp[1][1]=1;
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j){
			if(grid[i][j]=='#')
				continue;
			dp[i][j]+=dp[i-1][j]+dp[i][j-1];
			dp[i][j]%=mod;
		}
	cout<<dp[h][w]<<endl;	
		
	return 0;
}


Measured memory_bytes: 9088
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n; string s1, s2; cin >> n >> s1 >> s2;
	long long ans = 1;
	for (int i = 0; i < n; i++) {
		if (s1[i] == s2[i]) {
			if (i == 0)ans *= 3;
			else if (s1[i - 1] == s2[i - 1])ans *= 2;
		}
		else {
			if (i == 0)ans *= 6;
			else if (s1[i - 1] == s2[i - 1])ans *= 2;
			else ans *= 3;
			i++;
		}
		ans %= 1000000007;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
    // INPUT
    int K = 0;
    int X = 0;
    int sum = 0;
    cin >> K >> X;

    // SOURCE
    sum = 500 * K;
    if( sum >= X ) cout << "Yes";
    else cout << "No";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
// finish date: 2018/2/09

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


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

    if((N+1)/2 >= K) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


V<string> split(const string& s, char c) {
  V<string> res;
  stringstream ss(s);
  string t;
  while (getline(ss, t, c)) res.push_back(t);
  return res;
}

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  string s;
  while (getline(cin, s)) {
    auto ss = split(s, ' ');
    lint a = stoll(ss[0]), b = stoll(ss[1]);
    lint g = __gcd(a, b);
    lint l = a * b / g;
    cout << g << ' ' << l << '\n';
  }
}


Measured memory_bytes: 3104
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

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

func main() {
	sc.Split(bufio.ScanWords)
	
	n := scanInt()
	a := make([]int,n+1)
	b := make([]int, n)

	for i := 0; i < n+1; i++ {
		a[i] = scanInt()
	}
	for i := 0; i < n; i++ {
		b[i] = scanInt()
	}

	ans := int64(0)
	over := int64(0)
	for i := 0; i < n; i++ {
		var mon int64
		if int64(a[i]) <= over {
			mon = 0
			ans += int64(a[i])
		} else {
			mon = int64(a[i]) - over
			ans += over
		}

		if mon <= int64(b[i]) {
			over = int64(b[i]) - mon
			ans += mon
		} else {
			over = 0
			ans += int64(b[i])
		}

	}

	if int64(a[n]) <= over {
		ans += int64(a[n])
	} else {
		ans += over
	}

	fmt.Println(ans)

}


Measured memory_bytes: 4736
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in) ;
    String S = sc.next();
    int[] count = new int[4];
    int OK =0;
    for (int i =0; i<4; i++) {
      for (int j =0; j<4; j++) {
        if (S.charAt(i) == S.charAt(j)) {
          count[i]++;
        }
      }
    }
    for (int i=0; i<4; i++) {
      if (count[i] != 2) {
        System.out.println("No");
        OK++;
        break;
      } 
    }  
    if (OK ==0) System.out.println("Yes");
  }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#include <cstdint>
#define pi 3.14159
#define ll long long
// #define int ll
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  cin>>n;
  int a[n+1];
  rep(i,1,n+1) cin>>a[i];
  vector<pair<ll,ll>> dp(n+1,{0,0});
  dp[0].f=0;
  dp[0].s= -1e15;
  rep(i,1,n+1){
    dp[i].f = max(dp[i-1].f+a[i], dp[i-1].s-a[i]);
    dp[i].s = max(dp[i-1].f-a[i], dp[i-1].s+a[i]);
    // cout<<dp[i].f<<" "<<dp[i].s<<endl;
  }
  cout<<dp[n].f<<endl;
}
int main(){
    optimizeIO();
    solve();
}


Measured memory_bytes: 5308
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

#define __ { \
	freopen("input.txt","r",stdin); \
	freopen("output.txt","w",stdout); \
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    __;
   int n;cin>>n;
   vector<ll> v(n),l(n),r(n);
   for(int i=0;i<n;i++)cin>>v[i];
   ll L=v[0],R=v[n-1];
for(int i=1;i<n;i++){
	L=__gcd(L,v[i]);
	l[i]=L;
}
for(int i=n-2;i>-1;i--){
	R=__gcd(R,v[i]);
		r[i]=R;
}
l[0]=v[0];r[n-1]=v[n-1];
ll ans=0;
for(int i=1;i<n-1;i++){
  ans=max(ans,__gcd(l[i-1],r[i+1]));
}
ans=max(ans,r[1]);
ans=max(ans,l[n-2]);
cout<<ans;
}

Measured memory_bytes: 2560
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int a =sc.nextInt();
		String op=sc.next();
		int b=sc.nextInt();
		
		while(true){

		int ans=0;
		
		if(op.equals("?")){ 
			break;
		} else if (op.equals("+")){
			ans=a+b;
		} else if (op.equals("-")){
			ans=a-b;
		} else if (op.equals("*")){
			ans=a*b;
		} else if (op.equals("/")){
			ans=a/b;
		}

				System.out.println(ans);
				
				a =sc.nextInt();
				op=sc.next();
				b=sc.nextInt();
		}
	}

}

Measured memory_bytes: 17256
#include<bits/stdc++.h>
using namespace std;
 
#define       pb(a)             push_back((a))
#define       mp(a,b)           make_pair((a),(b))
#define       REP(a,b)          for(ll i=(a);i<(b);i++)
#define       REP2(a,b)         for(ll j=(a);j<(b);j++)
#define       REPE(a,b,c,d)     REP(a,b)for(ll j=(c);j<(d);j++)
#define       REPV(a,b,c)       for(ll (a)=b;(a)<(c);(a)++)
#define       IREP(a,b)         for(ll i=(a);i>=(b);i--)
#define       IREP2(a,b)        for(ll j=(a);j>=(b);j--)
#define       IREPV(a,b,c)      for(ll (a)=b;(a)>=(c);(a)--)
#define       all(v)            (v).begin(),(v).end()
#define       Trvs(c)           for (auto it = (c).begin(); it != (c).end(); it++)
#define       INF               INT_MAX
#define       sz(x)             x.size()
#define       flash             ios_base::sync_with_stdio(false);cin.tie(NULL);
#define       F                 first
#define       S                 second
#define       MOD               1000000007
 
using         ll     = long long;
using         vi     = vector<int>;
using         vvi    = vector<vi>;
using         vll    = vector<ll>;
using         vvll   = vector<vll>;
using         vb     = vector<bool>;
using         vd     = vector<double>;
using         vs     = vector<string>;
using         pii    = pair<int, int>;
using         pll    = pair<ll, ll>;
using         pdd    = pair<double, double>;
using         vpii   = vector<pii>;
using         vvpii  = vector<vpii>;
using         vpll   = vector<pll>;
using         vvpll  = vector<vpll>;
using         vpdd   = vector<pdd>;
using         vvpdd  = vector<vpdd>;
 
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void solve(){
    ll n;
    cin>>n;
    vll a(n,0);
    REP(0,n)cin>>a[i];
    ll ser = 0;
    REP(0,n){
        if(ser+1 == a[i]){
            ser++;
        }
    }
    if(ser == 0 ){cout<<"-1";return;}
    else {cout<<n-ser; return;}
}
 
 
int main(){
 
	flash
	/*
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("output.txt","w",stderr);
	#endif
 	*/
   
	//ll t;cin>>t;while(t--)
	solve();
 
 
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

const int MAX_N = 30;
const int INF = (1 << 28);

typedef pair<int, int> P;

struct Masu {
    bool u, d, l, r;
};

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

int d[MAX_N][MAX_N];

int main(void) {
    int w, h;
    while (cin >> w >> h, w) {
        vector<vector<Masu>> maze(h, vector<Masu>(w));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                maze[i][j].u = maze[i][j].d = maze[i][j].l = maze[i][j].r = false;
            }
        }
        for (int j = 1; j < w; j++) {
            maze[0][j].u = true;
        }
        for (int j = 0; j < w-1; j++) {
            maze[h-1][j].d = true;
        }
        for (int i = 0; i < h; i++) {
            maze[i][0].l = true;
            maze[i][w-1].r = true;
        }

        int tmp;
        for (int i = 1; i < 2*h; i++) {
            if (i%2) {
                for (int j = 1; j < w; j++) {
                    cin >> tmp;
                    if (tmp) {
                        maze[i/2][j-1].r = true;
                        maze[i/2][j].l = true;
                    }
                }
            } else {
                for (int j = 0; j < w; j++) {
                    cin >> tmp;
                    if (tmp) {
                        maze[i/2-1][j].d = true;
                        maze[i/2][j].u = true;
                    }
                }
            }
        }

        queue<P> que;
        for (int i = 0; i < MAX_N; i++) {
            for (int j = 0; j < MAX_N; j++) {
                d[i][j] = INF;
            }
        }

        que.push(P(0, 0));
        d[0][0] = 1;

        while (!que.empty()) {
            P p = que.front(); que.pop();
            if (p.first == w-1 && p.second == h-1) break;

            for (int i = 0; i < 4; i++) {
                bool flag = false;
                switch (i) {
                case 0:
                    if (maze[p.second][p.first].l) flag = true;
                    break;
                case 1:
                    if (maze[p.second][p.first].u) flag = true;
                    break;
                case 2:
                    if (maze[p.second][p.first].d) flag = true;
                    break;
                case 3:
                    if (maze[p.second][p.first].r) flag = true;
                    break;
                }
                if (flag) continue;

                int nx = p.first + dx[i];
                int ny = p.second + dy[i];

                if (0 <= nx && nx < w && 0 <= ny && ny < h) {
                    if (d[ny][nx] == INF) {
                        que.push(P(nx, ny));
                        d[ny][nx] = d[p.second][p.first] + 1;
                    }
                }
            }
        }

        if (d[h-1][w-1] != INF) {
            cout << d[h-1][w-1] << endl;
        } else {
            cout << 0 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  int ice[10];
  int n, tmp;

  while(cin >> n, n){
    memset(ice, 0, sizeof(ice));
    for(int i = 0 ; i < n ; i++){
      cin >> tmp;
      ice[tmp]++;
    }
    
    for(int i = 0 ; i < 10 ; i++){
      if(ice[i] == 0){
	cout << '-' << endl;
	continue;
      }
      
      for(int j = ice[i] ; j > 0 ; j--){
	cout << '*';
      }
      cout << endl;
    }
  }
  return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{int N, M;
	cin >> N >> M;
	vec(A);
	ll sum = 0;
	fx(M) {
		vecp(A);
		sum += A[x];
	}
	if (N>=sum) {
		ce(N-sum)
	}
	else {
		ce(-1)
	}
    return 0;
}



Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){

  int r,D,x; cin >> r >> D >> x;
  for(int i = 0; i < 10; i++){
    int res = r*x - D;
    cout << res << endl;
    x = res;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	while(cin >> n){
		if(n==0) break;
		int sum=0, p;
		for(int i=0; i<n*(n-1)/2; i++){
			cin >> p;
			sum+=p;
		}
		cout << sum/(n-1) << endl;
	}
	return 0;
}

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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define REVREP(i, n)      for(ll i = n - 1; i >= 0 ; i--)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }

void Solve()
{
	ll N;
	string C;
	cin >> N >> C;

	ll ans = 0;
	int j = C.size() - 1;
	for (int i = 0; i < C.size(); i++) {
		if (C[i] == 'W') {
			for (; j >= 0; j--) {
				if (i >= j) {
					break;
				}
				if (C[j] == 'R') {
					C[i] = 'R';
					C[j] = 'W';
					ans++;
					break;
				}
			}
		}

		if (i >= j) {
			break;
		}
	}

	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


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

using namespace std;

long long int gcd(long long int x, long long int y){
  if(y == 0) return x;
  return gcd(y,x%y);
}

long long int lcm(long long int x, long long int y){
  long long int g = gcd(x,y);
  return x / g * y;
}

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<long long int> tvec(n), avec(n);
  for (size_t i = 0; i < n; i++) {
    cin >> tvec[i] >> avec[i];
  }
  long long int t=tvec[0], a=avec[0];
  for (size_t i = 1; i < n; i++) {
    long long int mul = 1;
    long long int mult = (t+(tvec[i]-1))/tvec[i], mula = (a+(avec[i]-1))/avec[i];
    mul = max(mult, mula);

    t = tvec[i]*mul;
    a = avec[i]*mul;
  }

  cout << t+a << endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

SumA_old=sum(A)

P=[_ for _ in range(N)]

for i in range(N):
    if A[i]-B[i]>0:
        A[i]=A[i]-B[i]
    else:
        A[i+1]=max(A[i]+A[i+1]-B[i],0)
        A[i]=0

SumA_new=sum(A)

print(SumA_old-SumA_new)




    

Measured memory_bytes: 19284
N, M = list(map(int, input().split()))

s = [0]*M
c = [0]*M
for i in range(M):
    s[i], c[i] = list(map(int, input().split()))

if N == 1:
    if M == 0:
        print(0)
        exit()

    for x in range(0, 10):
        Sx = str(x)
        for xx in range(M):
            if s[xx] == 1 and str(c[xx]) == Sx[0]:
                pass
            else:
                break

            if xx == M-1:
                print(x)
                exit()

    print('-1')
    exit()


if N == 2:
    if M == 0:
        print(10)
        exit()

    for y in range(10, 100):
        Sy = str(y)
        for yy in range(M):
            if s[yy] == 1 and str(c[yy]) == Sy[0] or \
                s[yy] == 2 and str(c[yy]) == Sy[1]:
                pass
            else:
                break

            if yy == M-1:
                print(y)
                exit()

    print('-1')
    exit()


if N == 3:
    if M == 0:
        print(100)
        exit()

    for z in range(100, 1000):
        Sz = str(z)
        for zz in range(M):
            if s[zz] == 1 and str(c[zz]) == Sz[0] or \
                s[zz] == 2 and str(c[zz]) == Sz[1] or \
                s[zz] == 3 and str(c[zz]) == Sz[2]:
                pass
            else:
                break

            if zz == M-1:
                print(z)
                exit()

    print('-1')
    exit()


Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 200000;
const int N = 100;

long long S[MAX];

int main() {
	int n; cin>>n;
	rep(i, n) {
		long long a; cin>>a;
		if(i>0) S[i]=S[i-1]+a;
		else S[i]=a;
	}
	long long ans = INFL;
	rep(i, n-1) ans = min(ans, abs(S[n-1]-2*S[i]));
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int h,w,n;
  cin>>h>>w>>n;
  std::vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
  }
  vector<int> vec;
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < a[i]; ++j)
    {
      vec.emplace_back(i+1);
    }
  }
  vector<vector<int>> ans(h,vector<int>(w));
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      ans[i][j]=vec[w*i+j];
    }
    if(i%2==1){
      reverse(ans[i].begin(), ans[i].end());
    }
    for(auto&& e: ans[i]) {
      cout<<e<<" ";
    }
    cout<<endl;
  }
}

Measured memory_bytes: 384
n, k = map(int, input().split())
a = list(map(int, input().split()))
min_a = min(a)
count = 0
for i in range(n):
    if min_a != a[i]:
        count += 1
a, b = divmod(count, k-1)
if b == 0:
    print(a)
else:
    print(a+1)


Measured memory_bytes: 14008
a=input()
aa=a.split('/')
year=int(aa[0])
month=int(aa[1])
day=int(aa[2])
judge=0
if year<2019:
    judge=0
elif year>2019:
    judge=1
else:
    if month>4:
        judge=1
    else:
        judge=0

if judge==1:
    print('TBD')
else:
    print('Heisei')

Measured memory_bytes: 3064
MODE = "stdio"
require 'matrix'
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = 'aabc
  3
  1
  2
  1
  vwxyz
  2
  3
  4
  -'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end

s = ""
n=0
while true
  s = line[n]
  n += 1
  break if s=="-"
  line[n].to_i.times do
    n += 1
    h = line[n].to_i
    s = s[h...s.size]+s[0...h]
  end
  n += 1
  puts s
end

Measured memory_bytes: 9228
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

///////////////////////////

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



int main() {
	ll N, X;
	cin >> N >> X;

	ll x[MAX];

	repn(i, N) cin >> x[i];

	ll ans = abs(X - x[1]);

	repn(i, N) ans = gcd(ans, abs(X - x[i]));

	cout << ans;

	

	system("PAUSE");
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

struct edge {
    int to, cost;
    edge() = default;
    edge(int to, int cost) : to(to), cost(cost) {}
};
using edges = vector<edge>;
using Graph = vector<edges>;
int N, Q, K;
Graph G;
vector<int> dis;

void dfs(int v, int pv, int s) {
    dis[v] = s;
    for (auto e : G[v]) if (e.to != pv) {
        dfs(e.to, v, s + e.cost);
    }
}

void _main() {
    cin >> N;
    G.resize(N);
    dis.resize(N);
    REP (i, N - 1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }
    cin >> Q >> K;
    K--;
    dfs(K, -1, 0);
    REP (i, Q) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << dis[x] + dis[y] << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
#define chmax(x,y) x=max(x,y)




int main(){
    char x,y; cin>>x>>y;
    char ans='=';
    if(x<y) ans='<';
    else if(x>y) ans='>';
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3516