akhauriyash/Code-Regression huggingface dataset:
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
    
    int n;
    cin>>n;

    vi v(n, 0);
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        x--;

        v[x] = i+1;
    }

    for(int x:v) cout<<x<<' ';
} 

Measured memory_bytes: 1664
# # E - League
# https://atcoder.jp/contests/abc139/tasks/abc139_e

# トポロジカルソート　トポソ

from collections import defaultdict, deque

n, m = map(int, input().split())
es = [[int(x) for x in input().split()] for _ in range(n + m - 1)]

outs = defaultdict(list)
rev = defaultdict(list)
ins = defaultdict(int)
for v1, v2 in es:
    outs[v1 - 1].append(v2 - 1)
    rev[v2 - 1].append(v1 - 1)
    ins[v2 - 1] += 1

q = deque(v1 for v1 in range(n) if ins[v1] == 0)
res = []
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)

order = [i for i, v in sorted(enumerate(res), key=lambda x: x[1])]
 
ans = [0] * n
ans[res[0]] = 0
for v in res[:0:-1]:
    ans[v] = max([(order[v2], v2) for v2 in rev[v]])[1] + 1
 
for a in ans:
    print(a)

Measured memory_bytes: 92584
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read();

    let mut ans = 0.0;
    for _ in 0..n {
        let x: f64 = read();
        let u: String = read();
        if u == "BTC" {
            ans += x * 380000.0;
        } else {
            ans += x;
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<stdio.h>
int main()
{char s1[10],s2[10];
scanf("%s%s",s1,s2);
int a,b;
scanf("%d%d",&a,&b);
 char s[10];
scanf("%s",s);
if(strcmp(s,s1)==0)
	printf("%d\t%d",a-1,b);
else
	printf("%d\t%d",a,b-1);
return 0;}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Question.Exec();
		}
	}

	public static class Question
	{
		public static void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			var r = array[0];
			var g = array[1];
			var b = array[2];
			var answer = r * 100 + g * 10 + b;

			if (answer % 4 == 0)
			{
				Console.WriteLine($"YES");
			} else
			{
				Console.WriteLine($"NO");
			}

			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 13396
#include <iostream>
using namespace std;
string S;
int main(){
  cin >> S;
  int N = S.size();
  for(int i=0;i<N-1;i++){
    if(S[i]=='A' && S[i+1]=='C'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

int main(void){
    string s;
    int ans = 753;
    cin >> s;
    for(int i = 2;i < s.size();i++){
        int a = 100*(s[i-2]-'0')+10*(s[i-1]-'0')+(s[i]-'0');
        if(abs(a-753) < ans)ans = abs(a-753);
    }
    cout << ans;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import collections
import heapq

def solve(N: int, S: "List[str]"):
    count_dict = collections.defaultdict(int)
    for s in S:
        count_dict[s] += 1
    #sorted_count_dict = sorted(count_dict.items(), key=lambda x: x[1], reverse=True)

    largest = heapq.nlargest(1, [y for x, y in count_dict.items()])[0]
    list = []
    for k, v in count_dict.items():
        if v == largest:
            list.append(k)
    answer_list = sorted(list)
    for ans in answer_list:
        print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 35564
N, K, C = map(int, input().split())
S = input()
L, R = [-1] * K, [-1] * K
k = 0; temp = -C
for i, s in enumerate(S, 1):
    if s == 'o' and i > temp + C: L[k] = i; k += 1; temp = i
    if k == K: break
k = K - 1; temp = N + C + 1
for i, s in reversed(list(enumerate(S, 1))):
    if s == 'o' and i < temp - C: R[k] = i; k -= 1; temp = i
    if k == -1: break
ans = []
for l, r in zip(L, R):
    if l == r: ans.append(l)
for a in ans: print(a)

Measured memory_bytes: 34792
def examA():
    N = I(); A = LI()
    sumnale = sum(A)/N
    cur = 10**9; curL = 0
    for i in range(N):
        if cur>abs(A[i]-sumnale):
            cur = abs(A[i]-sumnale)
            curL = i
    ans = curL
    print(ans)
    return

def examB():
    N, K = LI(); A = LI()
    AK = []; ans = 0
    d = defaultdict(int)
    for i in range(N):
        cur = A[i]
        AK.append(cur)
        for k in range(40):
            if cur&(1<<k)==(1<<k):
                d[k] +=1
        for j in range(i+1,N):
            cur += A[j]
            AK.append(cur)
            for k in range(40):
                if cur & (1 << k) == (1 << k):
                    d[k] += 1
#    print(AK)
#    print(d)
    k = 40; curA = []
    while(k>0):
        k -=1
        if d[k]<K:
            continue
        for i in range(len(AK)):
            if AK[i]&(1<<k)==(1<<k):
                curA.append(AK[i])
        if len(curA)>=K:
            ans = 2**k
            break
#    print(curA)
    while(k>0):
        k -=1; neA = []
        if d[k]<K:
            continue
        for i in range(len(curA)):
            if curA[i]&(1<<k)==(1<<k):
                neA.append(curA[i])
        if len(neA)<K:
            continue
        else:
            curA = copy.deepcopy(neA)
            ans += 2**k
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()


Measured memory_bytes: 85512
/**********************************************
 *Author*        :coderdz
 *Created Time*  : 2018/5/4 10:47:40

 *********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <cstdlib>
#include<sstream>
#include <ctime>
#include <stack>
using namespace std;
#define IO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define rep(i,n) for(int i=1;i<=n;i++)
#define m(a,b) memset(a,b,sizeof(a))
typedef pair<int, int> PII;
typedef long long ll;
char s[55][55];

int main(){
	IO;
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>s[i][j];
	int flag=1;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			if (s[i][j]=='#')
				if (s[i+1][j]=='.'&&s[i][j+1]=='.'&&s[i-1][j]=='.'&&s[i][j-1]=='.'){
					flag=0;
					break;
				}
	if (flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int a[maxn], b[maxn];
int x[maxn], y[maxn];
int n, A, B, d;
typedef std::set<int> set;
typedef std::vector<int> vec;
std::unordered_map<int, set> mp0, mp1;
std::unordered_map<int, vec> map0, map1;
inline long long pr(int x,int y) { return (ll) x << 32 | (unsigned) y; }
std::unordered_map<long long, int> map;
std::queue<int> q;
inline void ins(int i) { q.push(i); mp0[x[i]].erase(y[i]); mp1[y[i]].erase(x[i]); }
ll ans = 0;
inline void popx(set & x,vec & v,int l,int r, int ix) {
	if(l <= r) {
		std::vector<int> numbers(x.lower_bound(l), x.upper_bound(r));
		ans += std::upper_bound(v.begin(), v.end(), r) - std::lower_bound(v.begin(), v.end(), l);
		for(int i : numbers) ins(map[pr(ix, i)]);
	}
}
inline void popy(set & x,vec & v,int l,int r,int iy) {
	if(l <= r) {
		std::vector<int> numbers(x.lower_bound(l), x.upper_bound(r));
		ans += std::upper_bound(v.begin(), v.end(), r) - std::lower_bound(v.begin(), v.end(), l);
		for(int i : numbers) ins(map[pr(i, iy)]);
	}
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	mp0.rehash(1e6 + 7), mp1.rehash(1e6 + 7);
	map0.rehash(1e6 + 7), map1.rehash(1e6 + 7);
	map.rehash(1e6 + 7);
	cin >> n >> A >> B;
	rep(i, 1, n) cin >> a[i] >> b[i];
	d = std::abs(a[A] - a[B]) + std::abs(b[A] - b[B]);
	rep(i, 1, n) {
		x[i] = a[i] + b[i];
		y[i] = a[i] - b[i];
		mp0[x[i]].insert(y[i]);
		mp1[y[i]].insert(x[i]);
		map0[x[i]].push_back(y[i]);
		map1[y[i]].push_back(x[i]);
		map[pr(x[i], y[i])] = i;
	}
	for(auto& i : map0) std::sort(i.second.begin(), i.second.end());
	for(auto& i : map1) std::sort(i.second.begin(), i.second.end());
	ins(A), ins(B);
	for(;!q.empty();) {
		int i = q.front(); q.pop();
		popx(mp0[x[i] - d], map0[x[i] - d], y[i] - d + 1, y[i] + d - 1, x[i] - d);
		popx(mp0[x[i] + d], map0[x[i] + d], y[i] - d + 1, y[i] + d - 1, x[i] + d);
		popy(mp1[y[i] - d], map1[y[i] - d], x[i] - d, x[i] + d, y[i] - d);
		popy(mp1[y[i] + d], map1[y[i] + d], x[i] - d, x[i] + d, y[i] + d);
	}
	cout << ans / 2 << '\n';
}


Measured memory_bytes: 98304
#include<iostream>
#include<vector>
#include<iomanip>

using namespace std;

const int INF=100000008;

int main()
{
	int n;
	cin >> n;
	int T=0;
	vector<int> begi(n+2);
	vector<int> en(n+2);
	begi[0]=0;
	en[0]=0;
	for(int i=1;i<=n;i++)
	{
		int t;
		cin >> t;
		begi[i]=T;
		T+=t;
		en[i]=T;
	}
	begi[n+1]=T;
	en[n+1]=T;
	vector<int> v(n+2);
	v[0]=0;
	v[n+1]=0;
	for(int i=1;i<=n;i++)
		cin >> v[i];

	vector<double> velo(2*T+1,INF);

	for(int i=0;i<2*T+1;i++)
	{
		double now=i*0.5;
		for(int j=0;j<n+2;j++)
		{
			double lim;
			if(now<begi[j])lim=v[j]+begi[j]-now;
			else if(en[j]<now)lim=v[j]+now-en[j];
			else lim=v[j];
			if(velo[i]>lim)velo[i]=lim;
		}
	}

	double ans=0;

	for(int i=0;i<2*T;i++)
		ans+=(0.5*(velo[i]+velo[i+1])/2);

	cout << fixed << setprecision(13) << ans << endl;
}





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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);

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

    for (int i = 0; i < N; i++)
        cin >> B[i];
    for (int i = 0; i < N-1; i++)
        cin >> C[i];
    
    int tmp = 21,value = 0;
    for (int i = 0; i < N;i++){
        if(A[i]-1 == tmp){
            value += C[A[i]-2];
        }
        tmp = A[i];
        value += B[A[i]-1];
    }

    cout << value << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	
	int n;cin>>n;

	int t[n],x[n],y[n];

	for(int i=0;i<n;i++)cin>>t[i]>>x[i]>>y[i];

	for(int i=0;i<n;i++){
		int dis,time;
		if( i==0 ){
			dis = x[i]+y[i];
			time = t[i];
		}
		else{
			time = t[i]-t[i-1];
			dis = abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
		}


		if(dis>time){
			cout<<"No\n";
			return 0;
		}
		else{
			int rem = time-dis;
			if( rem%2!=0 ){
				cout<<"No\n";
				return 0;
			}
		}
	}
	cout<<"Yes\n";
	return 0;

	/*
	1. Check for output format
	2. CHeck for corner cases
	3. Compile and run given TC first
	*/

}

Measured memory_bytes: 4728
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll=long long;

int main(){
    std::string S,T;
    cin >> S >> T;
    ll tSize=T.length();
    ll res=-1*(1ll<<60);
    for(ll i=0;i<=S.length()-tSize;i++){
        ll counter=0;
        for(ll j=0;j<tSize;j++){
            if(S.at(i+j)==T[j])counter++;
        }
        res=max(res,counter);
    }
    cout << tSize-res << endl;
}



Measured memory_bytes: 3640
"use strict";

const Main = args => {
  const input = args.trim().split("\n").map(e => e.split(' ').map(e => e - 0));

  const W = input[0][0];
  const H = input[0][1];
  const N = input[0][2];
  const paints = input.slice(1);

  const points = new Array(H);
  for (let y = 0; y < points.length; y++) {
    points[y] = new Array(W).fill('□');
  }

  paints.forEach(e => {
    let xi = e[0];
    let yi = e[1];
    let ai = e[2];

    if (ai === 1) {
      for (let y = 0; y < H; y++) {
        for (let x = xi - 1; x >= 0; x--) {
          points[y][x] = '■';
        }
      }
    } else if (ai === 2) {
      for (let y = 0; y < H; y++) {
        for (let x = xi; x < W; x++) {
          points[y][x] = '■';
        }
      }
    } else if (ai === 3) {
      for (let y = yi - 1; y >= 0; y--) {
        for (let x = 0; x < W; x++) {
          points[y][x] = '■';
        }
      }
    } else if (ai === 4) {
      for (let y = yi; y < H; y++) {
        for (let x = 0; x < W; x++) {
          points[y][x] = '■';
        }
      }
    }
  });

  let counter = 0;
  for (let y = 0; y < H; y++) {
    for (let x = 0; x < W; x++) {
      if (points[y][x] === '□') counter++
    }
  }
  console.log(counter);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7460
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

const int N = 305;
int n, m, K, h[N];
vector<int> hs;
LL f[N][N][N];

int main() {
  memset(f, 20, sizeof f);
  cin >> n >> K;
  hs.push_back(0);

  for (int i = 1; i <= n; ++i) scanf("%d", &h[i]), hs.push_back(h[i]);
  sort(hs.begin(), hs.end());
  hs.resize(unique(hs.begin(), hs.end()) - hs.begin());
  m = hs.size();

  f[0][0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < m; ++j) {
      int idx = lower_bound(hs.begin(), hs.end(), h[i]) - hs.begin();
      int delta = 0;
      if (idx > j) delta = hs[idx] - hs[j];
      for (int k = 0; k <= K; ++k) {
        f[i][idx][k] = min(f[i][idx][k], f[i - 1][j][k] + delta);
      }
      for (int k = 1; k <= K; ++k) {
        f[i][j][k] = min(f[i][j][k], f[i - 1][j][k - 1]);
      }
    }
  }
  LL ans = 1LL << 50;
  for (int i = 0; i < m; ++i) ans = min(ans, f[n][i][K]);
  cout << ans << endl;
}


Measured memory_bytes: 221952
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N, M);
  vi mp(N);
  rep(i, 0, M) {
    VAR(int, ai, bi);
    mp[ai - 1]++;
    mp[bi - 1]++;
  }
  each(x, mp) {
    print(x);
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
        public static void main(String args[]){
                Scanner scan = new Scanner(System.in);
                int val1=scan.nextInt();
                int val2=scan.nextInt();
                if(val1<val2){
                        System.out.println("a < b");
                }else if(val1>val2){
                        System.out.println("a > b");
                }else if(val1==val2){
                        System.out.println("a == b");
                }
        }
}

Measured memory_bytes: 26128
#include <iostream>
#include <math.h>
using namespace std;
int main(){
    int n,c=0;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,x=0;
        cin>>a;
        if(a==2||a==3){
            c++;
            
        }
        else{
            double b=sqrt(a);
            for(int j=2;j<=b;j++){
                if(a%j==0){
                    x=1;
                    break;
                }
            }
            if(x==0){
                c++;
            }
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3096
using System;

namespace AtCoderCS
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var inputArray = input.Split(' ');

            // change a-b
            var temp1 = inputArray[0];
            inputArray[0] = inputArray[1];
            inputArray[1] = temp1;

            // change a-v
            var temp2 = inputArray[0];
            inputArray[0] = inputArray[2];
            inputArray[2] = temp2;

            Console.WriteLine("{0} {1} {2}", inputArray[0], inputArray[1], inputArray[2]);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;
 
typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no { cout << -1; return; }

const int N = 300;

int p[N * N], fi[N * N], dp[N][N];

int gcd(int a, int b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

void calc_fi() {
    for (int i = 2; i < N * N; ++i)
        if (!p[i]) {
            p[i] = i;
            for (int j = i * i; j < N * N; j += i)
                p[j] = i;
        }
    fi[1] = 1;
    for (int i = 2; i < N * N; ++i) {
        int x = i, d = 1;
        while (x % p[i] == 0) {
            x /= p[i];
            d *= p[i];
        }
        if (x == 1)
            fi[i] = i - i / p[i];
        else
            fi[i] = fi[x] * fi[d];
    }
}

void solve() {
    int k, ans = 0; cin >> k;
    loop1(x, k)
        loop1(d, k) {
            dp[x][d] = dp[x][d - 1];
            if (gcd(x, d) == 1)
                ++dp[x][d];
        }
    loop1(i, k)
        loop1(x, k / i)
            loop1(y, k / i)
                ans += i * dp[gcd(x, y)][k / i];
    cout << ans;
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    //calc_fi();
    solve();
    return 0;
}

Measured memory_bytes: 4036
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(final String[] args) {
        final Task task = new Task();
        task.solve();
    }
}

class Task {

    public void solve() {
        try(final Scanner scanner = new Scanner(System.in);) {
            final int n = scanner.nextInt();

            final int[] allInput = IntStream.rangeClosed(1, n).map(i -> scanner.nextInt() * -1).sorted().toArray();
            int aliceScore = 0;
            int bobScore = 0;
            for (int i = 0; i < allInput.length; i++) {
                if (i % 2 == 0) {
                    aliceScore += allInput[i];
                } else {
                    bobScore += allInput[i];
                }
            }
            System.out.println(bobScore - aliceScore);
        }
    }
}

Measured memory_bytes: 28880
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<map>
using namespace std;
#define ll long long
int main(){
    int H,W;
    cin >> H >> W;
    int i,j;
    string str;
    char a[H][W];
    for(i=0;i<H;i++){
      cin >> str;
      for(j=0;j<W;j++){
        a[i][j]=str[j];
      }
    }
    int rmh[H];
    int rmw[W];
    for(i=0;i<H;i++){
      rmh[i]=0;
    }
    for(j=0;j<W;j++){
      rmw[j]=0;
    }
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
        if(a[i][j]=='#'){
          rmh[i]=1;
          rmw[j]=1;
        }
      }
    }
    for(i=0;i<H;i++){
      if(rmh[i]==1){
        for(j=0;j<W;j++){
          if(rmw[j]==1){
            cout << a[i][j];
          }
        }
        cout << endl;
      }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] color = new int[9];
    int count = 0, countMax = 0;
    int allColor = 0;
    for(int i = 0; i<n; i++){
      int a = sc.nextInt();
      if(a <400) {color[0] = 1;}
      else if(a <800) {color[1] = 1;}
      else if(a <1200) {color[2] = 1;}
      else if(a <1600) {color[3] = 1;}
      else if(a <2000) {color[4] = 1;}
      else if(a <2400) {color[5] = 1;}
      else if(a <2800) {color[6] = 1;}
      else if(a <3200) {color[7] = 1;}
      else if(a <=4800) {allColor++;}
    }
    for(int i = 0; i<8; i++){
      count += color[i];
    }

    countMax = count + allColor;

    if((count == 0) && (allColor != 0)){
      System.out.print(1 + " ");
    }else{
      System.out.println(count + " ");
    }
    System.out.println(countMax);
  }
}


Measured memory_bytes: 21844
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] array = new int[2];
        array[0] = scanner.nextInt();
        array[1] = scanner.nextInt();

        int[] groupA = {1,3,5,7,8,10,12};
        int[] groupB = {4,6,9,11};
        boolean isFound1 = false;
        boolean isFound2 = false;

        if(array[0] == 2 && array[1] == 2) {
            isFound1 = true;
            isFound2 = true;
        } else {
            if(!isFound1 && !isFound2) {
                for(int i=0; i<groupA.length; i++) {
                    if(groupA[i] == array[0]) {
                        isFound1 = true;
                    } else if(groupA[i] == array[1]) {
                        isFound2 = true;
                    } else if(isFound1 && isFound2) {
                        break;
                    }
                }
            }
            if(!isFound1 && !isFound2) {
                for(int ii=0; ii<groupB.length; ii++) {
                    if(groupB[ii] == array[0]) {
                        isFound1 = true;
                    } else if(groupB[ii] == array[1]) {
                        isFound2 = true;
                    } else if(isFound1 && isFound2) {
                        break;
                    }
                }
            }
        }
        if(isFound1 && isFound2) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21200
#include <bits/stdc++.h>
#define BPhuong "main"
#define maxn 200005
#define maxm
#define fi(i,a,b) for(int i = a; i<= b; i++)
#define fid(i,a,b) for(int i = a; i>= b; i--)
#define se second
#define f first
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define bit(x, i) ((x>>i)&1)
#define oo 1e9
struct data{
    int x, y, z;
};
using namespace std;
int n, h[maxn], a[maxn];
ll l[maxn], f[maxn];
void upp(int x, ll j)
{
    while(x<=maxn)
    {
        l[x] = max(l[x], j);
        x+=(x&-x);
    }
}
ll get(int x)
{
    ll ans = 0;
    while(x>=1)
    {
        ans = max(ans, l[x]);
        x -= (x&-x);
    }
    return ans;
}
void nhap(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
   // freopen(BPhuong".inp","r",stdin);
    //freopen(BPhuong".out","w",stdout);
    cin >> n;
    fi(i, 1, n) cin >> h[i];
    fi(i, 1, n) cin >> a[i];
}

void xuli(){
    ll res = 0;
    fi(i, 1, n)
    {
       f[i] = max(f[i], get(h[i]-1) + a[i]);
       upp(h[i], f[i]);
       res = max(res, f[i]);
    }
    cout << res;
}

int main(){
    nhap();
    xuli();
}


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

typedef vector<int> vi;

int main()
{
	vi syll(3);
	scanf("%d %d %d", &syll[0], &syll[1], &syll[2]);
	sort(syll.begin(), syll.end());
	if (syll[0] == 5 and syll[1] == 5 and syll[2] == 7)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
class Problem
  def exec
    while l = gets do
      i = l.to_f
      res = calc(i)
      puts res
    end
  end

  def calc(i)
    # ?£????????????????????????????????¨????
    t = i / 9.8

    #?????????????????§??????????????¢????¨????
    y = 4.9 * (t ** 2)

    #??????????????¢????????????????????§???????????°?£???????????????¶????????????????°??????´??°N????±???????
    n = ((y + 5) / 5).ceil
    return n
  end
end

p = Problem.new
p.exec

Measured memory_bytes: 8628
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int p,l,r;
};
struct Node T[MAX];
int n;

void preParse(int u){
  if(u==NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if(u==NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u){
  if(u==NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(){
  int i,v,l,r,root;
  scanf("%d",&n);
  for(i=0 ; i<n ; i++){
    T[i].p=NIL;
  }
  for(i=0 ; i<n ; i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l!=NIL) T[l].p=v;
    if(r!=NIL) T[r].p=v;
  }
  for(i=0 ; i<n ; i++){
    if(T[i].p==NIL){
      root=i;
    }
  }
  printf("Preorder\n");
  preParse(root);
  printf("\n");
    printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}



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

using namespace std;

#define forn for (ll i = 0; i < n; i++)
#define form for (ll j = 0; j < m; j++)
#define NO cout << "NO\n";
#define YES cout << "YES\n";
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (ll i = a; i < b; i++)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

ll gcd(ll a, ll b){
    ll r;
    while (b != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}


ll *calc_z(string s){
    ll n = s.size();
    ll *z = new ll[n] {0};
    ll l = 0, r = 0;
    for (ll i = 1; i < n; i++){
        if (r >= i) z[i] = min(z[i-l], r-i+1);
        while (z[i]+i < n && s[z[i]] == s[z[i]+i]) z[i]++;
        if (i + z[i] - 1 > r){
            l = i;
            r = i+z[i]-1;
        }
    }
    return z;
}

ll find_lower(ll *a, ll n, ll v){
    ll l = -1, r = n;

    while (r>l+1){
        ll m = (l+r)/2;

        if (a[m] >= v) r = m;
        else l = m;
    }
    if (r == n) return n-1;
    if (a[r] == v) return r;
    return r == 0 ? 0 : r-1;
}

void solve(){
    ll n, d;
    cin >>n>>d;
    ll c=0;
    ll x, y;
    for(int i =0;i < n;i ++){
        cin >> x >> y;
        double dist = sqrt(x*x + y*y);
        if (dist <= d) c++;
    }
    cout << c << "\n";
}

int main(){
    //init();

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

    //ll t; cin >> t; while (t--)
        solve();
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  int l = 0, r = 0;
  rep(i,n) {
    if(s[i] == '.') {
      r++;
    }   
  }
  int ans = l+r;
  rep(i,n) {
    if(s[i] == '.') {
      r--;
    } else {
      l++;
    }
    ans = min(ans, l+r);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
int N;cin >> N;
int B = 0, sum = 0;int x = 15;
vector<vector<int>> Vec(0, vector<int>(2));
  for(int i = 0; i < N; i++){
  int A;cin >> A;
  B += 1 + A;
  Vec.resize(B, vector<int>(2));
  Vec.at(B - (1 + A)).at(0) = A;
  Vec.at(B - (1 + A)).at(1) = 0;
    for(int j= 0; j < A; j++){
      for(int k = 0; k < 2; k++){
      cin >> Vec.at(B - (1 + A) + j + 1).at(k);
      }
    }
  }
  for(int bit = 0; bit < (1 << N); bit++){
  bitset<15> S(bit);
  vector<int> X(N, 0);
  bool C = 1;
    for(int i = 0; i < N; i++)
      if(S.test(i))X.at(i) = 1;
    for(int i = 0; i < N; i++){
      if(!C)break;
      if(S.test(i)){
      int P = 0;
        for(int m = 0; m < i; m++)P += Vec.at(P).at(0) + 1;
        for(int j = 0; j < Vec.at(P).at(0); j++){
          if(Vec.at(P + j + 1).at(1) == 1){
            if(X.at(Vec.at(P + j + 1).at(0) - 1) != 0){
              X.at(Vec.at(P + j + 1).at(0) - 1) = 1;}
             if(X.at(Vec.at(P + j + 1).at(0) - 1) == 0){C = 0;break;}
             }
         if(Vec.at(P + j + 1).at(1) == 0){
            if(X.at(Vec.at(P + j + 1).at(0) - 1) != 1){
              X.at(Vec.at(P + j + 1).at(0) - 1) = 0;}
             if(X.at(Vec.at(P + j + 1).at(0) - 1) == 1){C = 0;break;}
             }                       
           }
        }
      }
    int count = 0;
    if(C){
      for(int i = 0; i < N; i++){
      if(S.test(i))count++;}
         if(count > sum)sum = count;
    }         
  }
      cout << sum << endl;

}                

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

int main()
{
    int n, a[50], min{}, max{}, count{};
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", a + i);
        if (a[i] < a[min])
            min = i;
        if (a[i] > a[max])
            max = i;
    }
    if (std::abs(a[min]) < std::abs(a[max]))
    {
        for (int i = 0; i < n; i++)
            if (a[i] < 0) count++;
        printf("%d\n", count + n - 1);
        for (int i = 0; i < n; i++)
            if (a[i] < 0)
                printf("%d %d\n", max + 1, i + 1);
        for (int i = 1; i < n; i++)
            printf("%d %d\n", i, i + 1);
    }
    else
    {
        for (int i = 0; i < n; i++)
            if (a[i] > 0) count++;
        printf("%d\n", count + n - 1);
        for (int i = 0; i < n; i++)
            if (a[i] > 0)
                printf("%d %d\n", min + 1, i + 1);
        for (int i = n - 1; i > 0; i--)
            printf("%d %d\n", i + 1, i);
    }
    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

int main()
{
    int n, m;
    cin >> n >> m;
    priority_queue<int> q;
    rep(i, n)
    {
        int a;
        cin >> a;
        q.push(a);
    }
    rep(i, m)
    {
        int a = q.top();
        q.pop();
        q.push(a / 2);
    }
    ll ans = 0;
    rep(i, n)
    {
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3908
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<vector>
#include<math.h>
#include<utility>
#include<iomanip>

using namespace std;

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

	int h, a;
	cin >> h >> a;
	if (h % a == 0) cout << h / a;
	else cout << h / a + 1;

}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int a=sc.nextInt();
    int b=sc.nextInt();
    int kari=x-a;
    kari=kari%b;
    System.out.println(kari);
  }
}

Measured memory_bytes: 22100
import os
import sys

import numpy as np


def solve(n, kd, precalc_x, precalc_y):
    ans = np.full(n + 1, 10 ** 18, dtype=np.int64)

    def get_cost(v, bit):
        cost = 0
        pcx = precalc_x[v]
        pcy = precalc_y[v ^ bit]
        for i in range(n):
            cost += min(pcx[i], pcy[i])
        return cost

    for bit in range(1 << n):
        k = kd[bit]
        v = bit
        while v:
            ans[k] = min(ans[k], get_cost(v, bit))
            v = (v - 1) & bit
        ans[k] = min(ans[k], get_cost(0, bit))

    return ans


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8, i8[:], i8[:,:], i8[:,:])')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8, i8[:], i8[:,:], i8[:,:])', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
n = inp[0]
xxx = inp[1::3]
yyy = inp[2::3]
ppp = inp[3::3]

bit_d = (((np.arange(1 << n)[:, None] & (1 << np.arange(n)))) > 0).astype(np.int64)
precalc_x = abs((xxx[None, :] * bit_d)[..., None] - xxx[None, None, :]).min(axis=1) * ppp[None, :]
precalc_y = abs((yyy[None, :] * bit_d)[..., None] - yyy[None, None, :]).min(axis=1) * ppp[None, :]
kd = bit_d.sum(axis=1)

ans = solve(n, kd, precalc_x, precalc_y)
print('\n'.join(map(str, ans)))


Measured memory_bytes: 96852
#include <bits/stdc++.h>
using namespace std;
#define reps(i,j,k) for(int i=j;i<k;i++)
#define rep(i,j) reps(i,0,j)
#define INF 1<<30
#define fr first
#define sc second
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
typedef pair<int,int> Pii;
int stage[21][21];
int W,H;
Pii goal;
int solve(int dep,Pii p,Pii blocks[12]){
	//cout << p.fr << " " << p.sc << "\n";
	if(dep == 10){
		return INF;
	}
	int ret = INF;
	rep(i,4){
		int ny,nx;
		bool flg = false; //??´?????????????????????
		bool ok = false; //goal???????????????????????????
		ny = p.fr;nx = p.sc;
		{
			bool isbroken = false;
			rep(j,dep){
				if(Pii(ny+dy[i],nx+dx[i]) == blocks[j]){
					isbroken = true;
				}
			}
			if(stage[ny+dy[i]][nx+dx[i]] == 1 && !isbroken)continue;
		}
		while(true){
			if(stage[ny][nx] == 1){
				bool isbroken = false;
				rep(j,dep){
					if(Pii(ny,nx) == blocks[j]){
						isbroken = true;
					}
				}
				if(!isbroken)break;
			} 
			if(Pii(ny,nx) == goal){
				ok = true;
			}
			ny += dy[i];
			nx += dx[i];
			if(ny < 0 || ny > H-1 || nx < 0 || nx > W-1){
				flg = true;
				break;
			}
		}
		if(ok){
			ret = min(ret,dep+1);
		}
		if(!flg){
			blocks[dep] = Pii(ny,nx);
			ny -= dy[i];
			nx -= dx[i];
			ret = min(ret,solve(dep+1,Pii(ny,nx),blocks));
			blocks[dep] = Pii(0,0);
		}
	}
	return ret;
}
int main(){
	while(scanf("%d%d",&W,&H),(W+H)){
		Pii start;
		memset(stage,0,sizeof(stage));
		rep(i,H){
			rep(j,W){
				scanf("%d",&stage[i][j]);
				if(stage[i][j] == 3){
					goal.fr = i;
					goal.sc = j;
				}
				if(stage[i][j] == 2){
					start.fr = i;
					start.sc = j;
				}
			}
		}
		Pii non[12];
		int ans = solve(0,start,non);
		if(ans >= INF)ans = -1;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
int era[maxn],sz[maxn];
int n;
int col[maxn];
vector<int> g[maxn];
ll res[maxn];
void dfs(int x,int fa)
{
	sz[x]=0;
	for(int i=0;i<g[x].size();i++)
	{
		int to=g[x][i];
		if(to==fa)continue;
		int rec=era[col[x]];
		dfs(to,x);
		sz[x]+=sz[to];
		int lft=sz[to]-(era[col[x]]-rec);
	//	cout<<"comb "<<x<<" "<<col[x]<<" "<<lft<<" "<<era[col[x]]<<" "<<rec<<" "<<sz[x]<<endl;
		res[col[x]]+=lft*1ll*(lft+1)/2;
		era[col[x]]=rec+sz[to];
	}
	sz[x]++;
	era[col[x]]++;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&col[i]);
	for(int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	{
		int lft=n-era[i];
	//	cout<<i<<" "<<era[i]<<" "<<lft<<endl;
		res[i]+=lft*1ll*(lft+1)/2;
	}
	for(int i=1;i<=n;i++)
	{
		printf("%lld\n",n*1ll*(n+1)/2-res[i]);
	}
	return 0;
}


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

typedef long long ll;

char str[11][11];

int n;

int main(){
    cin >> n;

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

    bool res = true;

    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if (i == j) continue;
            if (strcmp(str[i],str[j]) == 0){
                res = false;

                break;
            }
        }
    }

    for (int i = 0; i < n-1; i++){
        if (str[i][strlen(str[i]) -1] != str[i+1][0]){

            res = false;
        }
    }

    if (res){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

int main()
{
    int n, m, l;
    cin >> n >> m >> l;
    long long int a[101][101];
    long long int b[101][101];
    long long int c[101][101] = {0,};

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

    for (int k = 0; k < m; k++) {
        for (int j = 0; j < l; j++) {
            cin >> b[k][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            for (int k = 0; k < m; k++) {
                c[i][j] += a[i][k] * b [k][j];
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            if (j != 0) cout << " ";
            cout << c[i][j];
        }
        cout << endl;
    }
    
    return 0;
}


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

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

using namespace std;

typedef long long int lli;

int main () {
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    vector<int> a(N);
    REP (i, 0, N) cin >> a[i];
    vector<vector<int>> m(H, vector<int>(W, 0));
    int y = 0, x = 0;
    REP (i, 0, N) {
        REP(j, 0, a[i]) {
//            cout << y << ' ' << x << endl;
            m[y][x] = i + 1;
            if (x % 2 == 0) {
                y++;
                if (y == H) {
                    x++;
                    y--;
                }
            } else {
                y--;
                if (y == -1) {
                    y++;
                    x++;
                }
            }
        }
    }
    REP (i, 0, H) {
        REP (j, 0, W) {
            if (j != 0) cout << ' ';
            cout << m[i][j];
        }
        cout << endl;
    }
    return 0;
}


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

using ll = long long;
using boost::irange;

int main(){
    string s, t;
    cin >> s >> t;

    int cnt = 0;
    for (int i : irange(0,3)){
        if (s[i] == t[i]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<int,int>
const int M=100010;
const int MOD=1000000007;
const int INF=1000000007;
using ll=long long;


int main() {
	ll n,a,b,x,div;
	ll ans=0;
	cin>>n>>a>>b;
	int px=0;
	rep(i,0,n){
		cin>>x;
		div=x-px;
		px=x;
		if(i==0)continue;
		ans+=min(div*a,b);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
string C;

LL ans = INF;

void solve(){
	//C[0]~C[i-1]までのWの数をaccum_W[i]とする
	//ただしaccum_W[0] = 0;
	vector<LL> accum_W(N+1,0);
	//C[0]~C[i-1]までのRの数をaccum_R[i]とする
	//ただしaccum_R[0] = 0;
	vector<LL> accum_R(N+1,0);
	for(int i=0;i<N;i++){
		accum_W[i+1] = accum_W[i];
		accum_R[i+1] = accum_R[i];
		if(C[i]=='W') accum_W[i+1]++;
		if(C[i]=='R') accum_R[i+1]++;
	}

	for(int i=0;i<=N;i++){
		LL numof_left_W = accum_W[i];
		LL numof_right_R = accum_R[N] - accum_R[i];
		ans = min(ans,max(numof_right_R,numof_left_W));
	}
}

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

    solve();

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

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

int N,X;
int dx[100010];
int a[100010];
int gcd(int a, int b){
    if( a % b == 0 ) return b;
    else if( b > a ) gcd(b,a);
    gcd( b, a % b );
}

int main (){
    cin >> N >> X;
    a[0] = X;
    for(int i=1; i<N+1; i++) cin >> a[i];
    for(int i=0; i<N; i++){
        dx[i] = abs( a[i] - a[i+1] );
    }
    int g = dx[0];
    for(int i=0; i<N-1; i++){
        g = min( g, gcd(dx[i], dx[i+1]) );
    }
    cout << g << endl;
    return 0;
}

Measured memory_bytes: 1024
//confilm 0LL and 1LL
//confilm cornercases such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	unordered_map<ll, ll> ump;
	ll dp[n+1];
	dp[0] = 1;

	repn(i, n){
		dp[i] = dp[i-1];
		ll c;
		cin >> c;
		ll p = ump[c];
		if(p && p != i-1) dp[i] += dp[p];
		dp[i] %= MOD;
		ump[c] = i;
	}
	co(dp[n]);

	return 0;
}


Measured memory_bytes: 10056
// Sakhiya07 - Yagnik Sakhiya

#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 200005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
    ll n;
    cin >> n;
    ll a[n];
    map<ll,ll> y;
    ll sum = 0;
    for(ll i=0;i<n;i++)
    {
        cin >> a[i];
        sum += a[i];
        y[a[i]]++;
    }
    ll q;
    cin >> q;
    while(q--)
    {
        ll old,n;
        cin >> old >> n;
        sum = sum - y[old]*old;
        sum += y[old]*n;
        y[n] += y[old];
        y[old] = 0;
        cout<<sum<<"\n";
    }
}

int main()
{
    FAST;
    ll t = 1;
   // cin >> t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 10352
using System;
using System.Linq;

public class AtCoder_Pana_B
{
    public static void Main()
    {
        long[] line1 = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        long h = line1[0];
        long w = line1[1];

        if (h == 1 || w == 1)
        {
            Console.WriteLine(1);
        }
        else if (h % 2 == 0)
        {
            Console.WriteLine(h * w / 2);
        }
        else
        {
            Console.WriteLine((h - 1) * w / 2 + (w + 1) / 2);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
 
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, n) FOR(i, 0, (int)n - 1)
#define pb push_back
#define pi 3.141592653589793
#define sll signed long long int // -10^9 to 10^9
#define ll long long int// for 0 to 10^18
#define ull unsigned long long int // for 0 to 10^18
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin(),x.end()
#define MOD 1000000007
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename T> T power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
typedef vector<int> vi;
/* 
ll sum_ofGP_modM(ll a , ll n, ll mod)  //// (1 + A^1 +A^2 + A^3 + A^4 + -------+ A^N) % M  usually here n= Total terms in series-1
////and  if series is something for eg 3^2 + 3^4 here a= 9,r=9  our ans can be found out as 
// let a1= first term 3^2 just do ans = a1*sum_ofGP_modM(9 , N-1, ull mod)
	if(n == 0) return 1;
	if(n == 1) return (1 + a) % mod;
	ll res;
	if(n % 2)
		res = (a + 1) * GPSumWithMod((a*a) % mod , (n-1)/2);
	else{ res = (a + 1) * GPSumWithMod((a*a) % mod , n/2 - 1);res %= mod;res = (res * a) + 1;}
    return res % mod;
}
//Whenever we have (a/b)%P == (a * fast_pow(b,P-2))%P
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
} */



int main() {
  FAST
  int a,b;cin>>a>>b;
  string s;cin>>s;
  if(s[a]!='-') cout<<"No";
  else{
    bool p= true;
    for(int i=0;s[i]!='\0';i++){
      if(s[i]=='-' && i!=a) {p=false;break;}
      else if( ( (int)s[i]<48 || (int)s[i]>57) && i!=a  ) {p=false;break;}
      else if( i==a && s[i]!='-'){p=false;break;}
    }
    if(p) cout<<"Yes";
    else cout<<"No";
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<limits>
#include<iomanip>
#include<string>
#include<map>
#include<vector>
#include<string.h>

using namespace std;

int main(void) {
	int n, k, s=1;
	cin >> n >> k;
    while(true) {
    	 n/=k;
    	 if(n==0) break;
    	 s++;
    }
    cout << s << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
a = [[0, 0] for i in range(N)]
for i in range(M):
  IN = list(input().split())
  p = int(IN[0])
  S = IN[1]
  if S == "AC":
    a[p-1][1] = 1
  else:
    if a[p-1][1] == 0:
      a[p-1][0] += 1
m = 0
n = 0
for i in range(N):
  if a[i][1] == 1:
    m += 1
    n += a[i][0]
print(m)
print(n)

Measured memory_bytes: 86264