akhauriyash/Code-Regression huggingface dataset:
sN = input()

sN_list = [int(d) for d in sN]

ans = 0

carry = 0

Nlen = len(sN)

for i in range(Nlen):
  d = sN_list[Nlen-i-1]
  if i != Nlen-1:
    left = sN_list[Nlen-i-2]
  else:
    left = 0
  if carry == 0:
    if d <= 4:
      ans += d
      carry = 0
    else:
      if d == 5 and left <= 4:
        ans += 5
        carry = 0
        continue
      ans += 10 - d
      carry = 1
  elif carry == 1:
    if carry + d <= 4:
      ans += carry + d
      carry = 0
    else:
      if carry + d == 5 and left <= 4:
        ans += 5
        carry = 0
        continue
      ans += 10 - (carry + d)
      carry = 1
if carry == 1:
  ans += 1

print(ans)

Measured memory_bytes: 116388
package main

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

func solve(sc *scanner, wr *bufio.Writer) {
	s := sc.getString()
	q := sc.getInt()

	rolling := false
	var fb, rb strings.Builder
	for i := 0; i < q; i++ {
		switch t := sc.getInt(); t {
		case 1:
			rolling = !rolling
		case 2:
			f := sc.getInt()
			c := sc.getString()
			if rolling {
				if f == 1 {
					rb.WriteString(c)
				} else {
					fb.WriteString(c)
				}
			} else {
				if f == 1 {
					fb.WriteString(c)
				} else {
					rb.WriteString(c)
				}
			}
		}
	}

	reverse := func(s string) string {
		var b strings.Builder
		for i := len(s) - 1; i >= 0; i-- {
			b.WriteByte(s[i])
		}
		return b.String()
	}

	front := reverse(fb.String())
	rear := rb.String()

	ans := front + s + rear
	if rolling {
		ans = reverse(ans)
	}
	fmt.Fprintln(wr, ans)
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


Measured memory_bytes: 5400
#include <stdio.h>

int main(void)
{
	int a,b,c,d,e;
	
	scanf("%d %d\n",&a,&b);
	scanf("%d %d",&c,&d);
	
	e=a*b-c*b-d*a+c*d;
	
	printf("%d\n",e);
	
	
  return 0;
}


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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

ll dp[70][2]; // dp[n-1 bitまで見た][n bitまでで小さい数が出た] = maxSum;

//方針 digitDP
int main(){
  int N;
  ll K,x=0;
  cin >> N >> K;

  VLL A(N);
  rep(i,N) cin >> A[i];

  for(int d = 62; d >= 0; d--){
    ll c = 0;
    rep(i,N) c += (A[i] >> d) & 1;
    if(2 * c < N && (x | (1LL << d)) <= K) x |= 1L << d;
  }
  ll ans = 0;
  rep(i,N) ans += x ^ A[i];
  cout << ans << endl;
  return 0;
}


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

map<string,int>his;
vector<string>V;

void init(){
	string tmp="abcdefghij";
	for(int i=0;i<100;i++){
		string tmp2="";
		tmp2+=tmp[i/10];
		tmp2+=tmp[i%10];
		V.push_back(tmp2);
	}
}

int main(){
	init();
	
	char last='a';
	
	for(int cnt=0;true;cnt++){
		cout<<'?'<<last<<V[cnt]<<'a'<<endl;
		fflush(stdout);
		string s;
		cin>>s;
		if(his[s]==1 || s[0]!='a'){
			cout<<"!OUT\n";
			break;
		}
		his[s]=1;
		last=s[s.size()-1];
	}
	
	
	return 0;
}


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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> ND(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) cin >> ND.at(i).at(j);
  }

  int ans = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i <= j) continue;
      int dis = 0;
      for (int k = 0; k < D; k++) {
        int X = ND.at(i).at(k) - ND.at(j).at(k);
        dis += X * X;
      }
      if (sqrt(dis) == (int)sqrt(dis)) ans++;
    }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
            int a,b;
            char op;
            int answer;
            for(;;){
                    cin >> a >> op >> b;
                            switch(op){
                                    case '+':   answer=a+b; break;
                                    case '-':   answer=a-b; break;
                                    case '*':   answer=a*b; break;
                                    case '/':   answer=a/b; break;
                            }
                           if(op=='?')break;
                           cout<< answer << endl;
                                                                          \
                                                          }
                                                                          \
                                                                  return 0\
;
}

Measured memory_bytes: 3080
#include<cstdio>
#include<cstring>
const int MAXN=55;
const int MOD=1e9+7;

int n;long long k;
void upd(long long &x,long long y){
	x=(x+y)%MOD;
}
struct matrix{
	long long a[MAXN][MAXN];
	matrix(){memset(a,0,sizeof(a));}
	matrix operator*(const matrix &rhs){
		matrix res;
		for(int k=0;k<n;k++)
			for(int i=0;i<n;i++)
				for(int j=0;j<n;j++)
					upd(res.a[i][j],a[i][k]*rhs.a[k][j]%MOD);
		return res;
	}
	void operator^=(long long k){
		matrix res;
		for(int i=0;i<n;i++)
			res.a[i][i]=1;
		while(k){
			if(k&1)
				res=res*(*this);
			(*this)=(*this)*(*this);
			k>>=1;
		}
		(*this)=res;
	}
}msk;

int main(){
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			scanf("%lld",&msk.a[i][j]);
	msk^=k;
	long long ans=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			upd(ans,msk.a[i][j]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define ll long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12

int main(void)
{
	//変数の宣言
	int a,b;
	
	//データの読み込み
	
	scanf("%d %d",&a,&b);
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	
//	printf("計算部分終了\n");
	
	//出力
	if(b%a==0){
		printf("%d",a+b);
	}else{
		printf("%d",b-a);
	}
	
	//('・ω・'）
	
//	printf("結果の出力終了\n");
	
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(long i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int MOD = 1000000007;

int exp_mod(long long a, long long b, int m) {
	long long res = 1;
	while (b > 0) {
		if (b&1)
			res = (res * a)%m;
		a = (a * a)%m;
		b >>= 1;
	}
	return (int)res;
}

int fact_mod(int n, int m) {
	long long res = 1;
	for (int i=n; i>0; --i)
		res = (res * i)%m;
	return (int)res;
}

int comb_mod(int n, int r) {
	long long res = 1;
	for (int i=0; i<r; ++i)
		res = (res * (n - i) )%MOD;
	return ( res * exp_mod(fact_mod(r, MOD), MOD-2, MOD) ) % MOD;
}

struct Pony
{
    string name;
    int score, n;

    Pony(string name_, int score_, int n_)
    {
        name = name_;
        score = score_;
        n = n_;
    }

    bool operator<(const Pony &another) const
    {
        return name < another.name || ((name == another.name) && score > another.score);
    };
};


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

  int n;

  cin >> n;

  vector<Pony> p;

  rep(i, n) {
    string name;
    int score;
    cin >> name >> score;
    p.push_back(Pony(name, score, i+1));
  }

  sort(p.begin(), p.end());

  rep(i, n) {
    cout << p[i].n << endl;
  }
  
}


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

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

  vector<int> m(N);
  rep(i, 0, N) cin >> m.at(i);

  sort(m.begin(), m.end());

  int temp = 0;
  rep(i, 0, N) temp += m.at(i);
  cout << N+((X-temp)/m.front()) << endl;
}


Measured memory_bytes: 256
def run(N, M, PY):
    PY = sorted(PY, key=lambda x: x[1])
    # key: P, values:list(識別番号, 順番), count
    ret = {}
    for i in range(len(PY)):
        P = PY[i][0]
        j = PY[i][2]
        if P in ret.keys():
            cnt = ret[P][1]
        else:
            cnt = 0
            ret[P] = [[], cnt]
        cnt += 1
        id = '{0:06d}'.format(P)+'{0:06d}'.format(cnt)
        ret[P][0].append([id, j])
        ret[P][1] += 1
    ret2 = []
    for r in ret.values():
        for id, j in r[0]:
            ret2.append([id, j])
    ret2 = sorted(ret2, key=lambda x: x[1])
    ret3 = []
    for r in ret2:
        ret3.append(r[0])
    return ret3


def main():
    N, M = map(int, input().split())
    PY = []
    for i in range(M):
        tmp = list(map(int, input().split()))
        tmp.append(i)
        PY.append(tmp)
    ret = run(N, M, PY)
    for r in ret:
        print(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 81248
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int n, c, k, t;

vector<int> vt;

int main() {
    GI(n);
    GI(c);
    GI(k);

    FOR1(i, n) {
        GI(t);
        vt.PB(t);
    }

    sort(vt.rbegin(), vt.rend());

    int res = 0;

    while (vt.size()) {
        int tm = vt[vt.size()-1]; vt.pop_back();
        tm += k;
        res++;

        int left = c - 1;

        while (vt.size() && vt[vt.size()-1] <= tm && left > 0) {
            vt.pop_back();
            left--;
        }
    }

    cout << res << "\n";
    
    return 0;
}

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

if A + B - 1 > N or A * B < N:
    print('-1')
else:
    ans = list(range(1, B + 1)[::-1])
    if A > 1:
        x = (N - B) // (A - 1)
        y = (N - B) % (A - 1)
        st = B + 1
        for i in range(y):
            ans += list(range(st, st + x + 1)[::-1])
            st += x + 1
        for i in range(A - 1 - y):
            ans += list(range(st, st + x)[::-1])
            st += x

    print(' '.join(map(str, ans)))


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

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

const int NMAX = 25;
bool flag;

int main(){
    LCIN(N);
    ll ans=0;
    ll cls=0;
    if(N>0) {
        ans=(N/500)*1000;
        cls=N%500;
    }
    if(cls>0)ans+=(cls/5)*5;
 
    printf("%lld\n",ans); 

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
  int h, m, s;
  int S;
  scanf("%d", &S);

  if(!(0 <= S && S < 86400)) {
    printf("0〜86400で入力してください\n");
  } else {
    h = S / 3600;
    m = (S - h * 3600) / 60;
    s = S % 60;
    printf("%d:%d:%d\n", h, m, s);
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  map<int,int> m;
  rep(i, N) {
    int a; cin >> a;
    m[a]++;
  }
  
  int ans = 0;
  for(auto p : m) {
    if(p.second < p.first) ans += p.second;
    if(p.second > p.first) ans += p.second-p.first;
  }
  cout << ans << endl;

}

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

INF=10**9
N,M=map(int,input().split())

def dfs(u,d1):
  pos_list[u]=d1
  for v,d2 in graph[u]:
    if pos_list[v]==-INF:
      dfs(v,d1+d2)
    elif pos_list[v]!=d1+d2:
      print("No")
      sys.exit(0)      
  return

graph=[]
for i in range(N+1):
  graph.append([])
for i in range(M):
  L,R,D=map(int,input().split())
  graph[L].append((R,D))
  graph[R].append((L,-D))
#print(graph)

pos_list=[-INF]*(N+1)
for i in range(1,N+1):
  if pos_list[i]!=-INF:
    continue
  dfs(i,0)
          
#print(pos_list[1:])
print("Yes")


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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int count = 0;
  int ans;
  for(int i=max(a, b); i<=max(a, b); i--) {
    if(a%i == 0 && b%i == 0) count++;
    if(count == k) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-

def solve(K, S):
    count = 0
    
    for i in range(K+1):
        for j in range(K+1):
            if(0<= S-i-j <= K):
                count += 1
                
    print(count)

if __name__ == '__main__': 
    K, S = map(int, input().split())
    
    solve(K, S)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;
#define MAXN 100001
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<vector<ll>> Graph;
ll N,M;
ll color[MAXN];
bool col(const Graph &G,int x,int c = 1){
    color[x] = c;
    for(auto nxt:G[x]){
        if(color[nxt]==c){
            return false;
        }
        if(color[nxt]==-1&&!col(G,nxt,1-c)){
            return false;
        }
    }
    return true;
}


int main(){
    cin >> N >>M;
    Graph G(N+1);
    rep(i,N)color[i] = -1;
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ll B = 0,W = 0;
    if(col(G,0)){
        rep(i,N){
            if(color[i]==0)B++;
            if(color[i]==1)W++;
        }
        cout << B*W - M << endl;;
    }else{
        cout << ((N*(N-1))/2)-M << endl;
    }

    return 0;

}

Measured memory_bytes: 7424
def resolve():
    T,M=map(int,input().split())

    MOD = 10 ** 9 + 7
    N = 10 ** 5

    fact = [1] * (N + 1)
    rfact = [1] * (N + 1)
    r = 1
    for i in range(1, N + 1):
        fact[i] = r = r * i % MOD
    rfact[N] = r = pow(fact[N], MOD - 2, MOD)
    for i in range(N, 0, -1):
        rfact[i - 1] = r = r * i % MOD

    # nPk (mod MOD) を求める
    def perm(n, k):
        return fact[n] * rfact[n - k] % MOD

    if T==M:
        ans=perm(T,T)*perm(M,M)*2%MOD
    elif abs(T-M)==1:
        ans=perm(T,T)*perm(M,M)%MOD
    else:
        ans=0
    print(ans)





resolve()

Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i <= n; i++)
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

ll dp[110][101010];

int main(){
    int n, k;
    cin >> n >> k;
    int A[110];
    for (int i = 0; i < n; i++) cin >> A[i];
    int a = 0;
    vector<ll> S(k + 2, 0LL);
    dp[0][0] = 1LL;
    for (int i = 0; i < n; i++) {
        a += A[i];

        for (int j = 0; j <= min(k, a); j++) {
            S[j + 1] = (S[j] + dp[i][j]) % mod;
        }

        for (int j = 0; j <= min(k, a); j++) {
            dp[i + 1][j] = S[j + 1] - S[max(0, j - A[i])];
            dp[i + 1][j] %= mod;
            if(dp[i + 1][j] < 0) dp[i + 1][j] += mod;
        }
    }

    cout << dp[n][k] << endl;
}


Measured memory_bytes: 80128
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
typedef long long LL;
using namespace std;

static LL MOD = 1000000007;

vector<vector<LL>> comb(int n) {
  vector<vector<LL>> v(n + 1,vector<LL>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
      v[j][k] %= MOD;
    }
  }
  return v;
}

int main(){
    int n;
    int k;
    int r;
    LL ans;
    cin >> n >> k;
    r = n - k;
    vector<vector<LL>> v(n + 1,vector<LL>(n + 1, 0));
    v = comb(n);
    for(int i=1; i<=k; i++){
        ans = v[r+1][i] * v[k-1][i-1];
        ans %= MOD;
        cout << ans << endl;
    }
}

Measured memory_bytes: 62976
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

int n; cin >> n;
vi v(n); rep(i,n) cin >> v[i];

map<int, int> mp1, mp2;
for(int i = 0; i < n; i += 2) mp1[v[i]]++;
for(int i = 1; i < n; i += 2) mp2[v[i]]++;

int MAX_mp1 = 0;
int o;
for(auto x : mp1) {
    if (chmax(MAX_mp1, x.second)) {
        o = x.first;
    }
}
int MAX2_mp1 = 0;
for(auto x : mp1) {
    if(x.first == o) continue;
    chmax(MAX2_mp1, x.second);
}

int MAX_mp2 = 0;
int e;
for(auto x : mp2) {
    if (chmax(MAX_mp2, x.second)) {
        e = x.first;
    }
}
int MAX2_mp2 = 0;
for(auto x : mp2) {
    if(x.first == e) continue;
    chmax(MAX2_mp2, x.second);
}

if(o != e) cout << n - MAX_mp1 - MAX_mp2 << endl;
else {
    cout << n - max((MAX_mp1 + MAX2_mp2) ,(MAX2_mp1 + MAX_mp2)) << endl;
}

return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define MAXN 100000
std::vector <int> g[MAXN+1];
int grad[MAXN+1];
bool viz[MAXN+1];
int q[MAXN+1];
int dist[MAXN+1];
int from[MAXN+1];
int sol[MAXN+1];
void BFS(int nod){
   int b,e;
   b=0;
   e=1;
   q[0]=nod;
   dist[nod]=1;
   do{
      for(auto it:g[q[b]])
       if(dist[it]==0){
          dist[it]=dist[q[b]]+1;
          q[e++]=it;
          from[it]=q[b];
       }
      b++;
   }while(b<e);
}
int len[MAXN+1];
void dfs(int nod){
   viz[nod]=1;
   len[nod]=1;
   for(auto it:g[nod]){
     if(!viz[it]){
       dfs(it);
       len[nod]=std::max(len[nod],len[it]+1);
       from[it]=nod;
     }
   }
}
int sz;
void dfs1(int nod){
   sol[++sz]=nod;
   for(auto it:g[nod])
     if(len[nod]==len[it]+1){
       dfs1(it);
       break;
     }
}
int main(){
   FILE*fi,*fout;
   int i,n,m,a,b,cnt,nod,max,min;
  // fi=fopen("A.in" ,"r");
  // fout=fopen("A.out" ,"w");
   fi=stdin;
   fout=stdout;
   fscanf(fi,"%d %d " ,&n,&m);
   for(i=1;i<=m;i++){
      fscanf(fi,"%d %d " ,&a,&b);
      g[a].push_back(b);
      g[b].push_back(a);
      grad[a]++;
      grad[b]++;
   }
   cnt=0;
   for(i=1;i<=n;i++)
     cnt+=(grad[i]==1);
   if(cnt>=2){
      i=1;
      while(grad[i]>1)
        i++;
      BFS(i);
      sz=0;
      nod=i;
      i++;
      while(grad[i]>1)
        i++;
      while(i!=nod){
        sol[++sz]=i;
        i=from[i];
      }
      sol[++sz]=nod;
   }
   else{
      min=n+1;
      for(i=1;i<=n;i++){
         if(grad[i]<min){
            min=grad[i];
            nod=i;
         }
      }
      dfs(nod);
      max=0;
      for(i=1;i<=n;i++)
         if(len[i]>max){
           max=len[i];
           nod=i;
         }
      sz=0;
      dfs1(nod);
   }
   fprintf(fout,"%d\n" ,sz);
   for(i=1;i<=sz;i++)
     fprintf(fout,"%d " ,sol[i]);
   fprintf(fout,"\n");
  // fclose(fi);
  // fclose(fout);
   return 0;
}


Measured memory_bytes: 8192
using System;
using System.Collections.Generic;
using System.Linq;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nmx = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var n = nmx[0];
            var m = nmx[1];
            var x = nmx[2];
            var books = new int[n][];
            for (var i = 0; i < n; i++)
            {
                books[i] = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            }

            var p = -1;
            for (var i = 0; i < n; i++)
            {
                Hoge(i, new int[m + 1]);
            }

            Console.WriteLine(p);

            void Hoge(int index, int[] result)
            {
                var book = books[index];
                var ok = true;
                for (var i = 0; i <= m; i++)
                {
                    result[i] += book[i];
                    if (i > 0 && result[i] < x)
                        ok = false;
                }
                var price = result[0];
                if (ok && (p == -1 || price < p))
                {
                    p = price;
                    return;
                }

                for (var i = index + 1; i < n; i++)
                {
                    var copy = new int[m + 1];
                    result.CopyTo(copy, 0);
                    Hoge(i, copy);
                }
            }
        }
    }
}

Measured memory_bytes: 28484
#include <cstdio>
#include <cstring>
char c[128];
int main(void)
{
  while(1){
    int n;
    scanf("%d",&n);
    if(!n) break;
    memset(c,0,sizeof(c));
    for(int i=0;i<n;i++){
      char a,b;
      scanf(" %c %c",&a,&b);
      c[a] = b;
    }
    int m;
    scanf("%d",&m);
    for(int i=0;i<m;i++){
      char a;
      scanf(" %c",&a);
      if(c[a]){
	printf("%c",c[a]);
      } else {
	printf("%c",a);
      }
    }
    puts("");
  }
}

Measured memory_bytes: 1020
from sys import stdin, setrecursionlimit
from bisect import bisect_left


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    py = [list(map(int, input().split())) for _ in range(m)]

    summary = [[] for _ in range(n)]

    for p, y in py:
        summary[p - 1].append(y)

    for i in range(n):
        summary[i].sort()

    for p, y in py:
        print(str(p).zfill(6), str(bisect_left(summary[p - 1], y) + 1).zfill(6), sep='')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

using namespace std;

#define pb push_back
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

const int N = (int)505;

int n, m, q;

vector < int > vec[N];
int lr[N][N];
int cnt[N];

main() {
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    vec[l].pb(r);
    cnt[r]++;
  }
  for (int i = 1; i <= n; i++)
    sort(all(vec[i]));
  lr[1][n] = m;
  int rres = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = n; j >= i; j--) {
      if (j == n) {
        if (i == 1) continue;
        for (int to : vec[i - 1]) {
          cnt[to]--;
          rres++;
        }
        lr[i][j] = m - rres;
      } else {
        int res = 0;
        lr[i][j] = lr[i][j + 1] - cnt[j + 1];
      }
    }
  }
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", lr[l][r]);
  }
}


Measured memory_bytes: 3200
import sys
bbn=1000000007
	
#+++++
		
def main():
	n = int(input())
	al=[]
	for i in range(n):
		b , c = map(int, input().split())
		al.append([b,c])
	tps=0
	for xi,yi in al:
		for xj,yj in al:
			bb=((xi-xj)**2) + ((yi-yj)**2)
			tps+=(bb**0.5)
	print(tps/n)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
import math
from functools import reduce


def read():
    N, X = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, X, A


def solve(N, X, A):
    A = [a-X for a in A]
    ans = reduce(math.gcd, A)
    return abs(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 20552
fun main(args: Array<String>) {
    abc149d()
}

fun abc149d() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val points = readLine()!!.split(' ').map { it.toInt() }
    val t = readLine()!!.map {
        when (it) {
            'r' -> 2
            's' -> 0
            else -> 1
        }
    }.toIntArray()

    val grouped = t.withIndex().groupBy { it.index % k }
        .map { it.value.map { iv -> iv.value } }

    var answer = 0L

    for (g in grouped) {
        val before = Array(g.size) { -1 }
        before[0] = g.first()
        answer += points[g.first()]

        for (i in 1..g.lastIndex) {
            val value = g[i]
            if (before[i - 1] != value) {
                answer += points[value]
                before[i] = value
            }
        }
    }

    println(answer)
}


Measured memory_bytes: 69244
#include <cstdio>
using namespace std;

int get_gcd(int a, int b) {
  int r;
  while (r = a % b) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int a, b;
  while (~scanf("%d %d", &a, &b)) {
    int gcd = get_gcd(a, b);
    int lcm = a / gcd * b;
    printf("%d %d\n", gcd, lcm);
  }
}


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

int main()
{
  string s,t;
  cin >> s >> t;
  
 for(int i = 0; i < static_cast<int>(s.size()); i++){
   for(int j = static_cast<int>(s.size())-1; j > i; j--){
     if(s.at(j) < s.at(j-1)){
       char tmp = s.at(j-1);
       s.at(j-1) = s.at(j);
       s.at(j) = tmp;
     }
   }
 }
  
  for(int i = 0; i < static_cast<int>(t.size()); i++){
   for(int j = static_cast<int>(t.size())-1; j > i; j--){
     if(t.at(j) > t.at(j-1)){
       char tmp = t.at(j-1);
       t.at(j-1) = t.at(j);
       t.at(j) = tmp;
     }
   }
 }
 
  if(s < t){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3652
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())

    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab.sort()
    ans = 0

    for i, j in ab:
        if m < j:
            ans += i*m
            break
        m -= j
        ans += i*j
        

    print(ans)

main()

Measured memory_bytes: 16920
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

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

const int mod = 1000000007;

long d[10][10];

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

  int n;
  cin >> n;

  string s;
  cin >> s;

  int lbr = 0;
  int rbr = 0;

  int mxlbr = 0;
  int mxrbr = 0;

  rep(i, n) {
    if(s[i] == ')') lbr++;
    else lbr--;

    mxlbr = max(lbr, mxlbr);
  }

  rep(i, n) {
    if(s[n-i-1] == '(') rbr++;
    else rbr--;

    mxrbr = max(rbr, mxrbr);
  }

  cout << string(mxlbr, '(') + s + string(mxrbr, ')') << endl;
}


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

int main(void)
{
    int n;
    cin >> n;

    for(int i=1;i<=n;i++) {
        int x = i;
        if (x % 3 == 0) {
            printf(" %d",i);
            continue;
        }
        do {
            if (x % 10 == 3) {
                printf(" %d",i);
                break;
            }
            x/=10;
        }while(x!=0);
    }
    cout<<endl;
    return 0;
}


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

long burgernum(int n){
  long s;
  long ss;
  if (n==0){
    s=1;
    return s;
  }
  else{
    ss=burgernum(n-1);
    s=3+2*ss;
    return s;
  }
}
long burgerpnum(int n){
  long s;
  long ss;
  if (n==0){
    s=1;
    return s;
  }
  else{
    ss=burgerpnum(n-1);
    s=1+2*ss;
    return s;
  }
}
long burgers(int n,long L){
  long s;
  long ss;
  if (n==0){
    s=L;
    return s;
  }
  else{
    ss=burgernum(n-1);
    if (L==0){
      s=0;
    }
    else if (L==2*ss+3){
      s=burgerpnum(n);
    }
    else if (L==ss+2){
      s=burgerpnum(n-1)+1;
    }
    else if (L<ss+2){
      s=burgers(n-1,L-1);
    }
    else{
      s=burgerpnum(n-1)+1+burgers(n-1,L-ss-2);
    }
  }
  return s;
}

int main(){
  int N;
  long L;
  cin>>N;
  cin>>L;
  //cout<<burgerpnum(N-1)<<endl;
  cout<<burgers(N,L);
  return 0;
}


Measured memory_bytes: 256
use io::*;
use std::*;

fn solve(a: i64, b: i64) {
    let ans = if a * b % 2 == 0 { "Even" } else { "Odd" };
    println!("{}", ans);
}

// 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)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut a: i64;
    a = scanner.next();
    let mut b: i64;
    b = scanner.next();
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(a, b)).unwrap().join().unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n; cin >> n;
	vl d(n); REP(i, n) cin >> d[i];
	ll m; cin >> m;
	vl t(m); REP(i, m) cin >> t[i];

	map<ll, ll> x;
	REP(i, n) x[d[i]]++;
	REP(i, m) {
		if (x[t[i]]-- == 0) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;



	return 0;
}


Measured memory_bytes: 15872
#include <stdio.h>
#include <stdlib.h>
 
int bubbleSort(int array[],int n);
 
int main() {
    int arraySize;
    int* insertedData;
    int changeLineFlag=0;
    while(1) {
        scanf("%d", &arraySize);
        if(arraySize==0)break;
        if(changeLineFlag==0)
        {
            changeLineFlag++;
        }
        else
        {
            printf("\n");
        }
        insertedData = (int *) malloc(sizeof(int) * arraySize);
        for (int i = 0; i < arraySize; i++)
            scanf("%d", &insertedData[i]);
        int result = bubbleSort(insertedData, arraySize);
        //結果出力
        printf("%d", result);
        free(insertedData);
    }
printf("\n");
    return 0;
}
int bubbleSort(int array[],int n)
{
    int counter = 0;
    int flag=1;
    while(flag==1)
    {
        flag=0;
        for(int i=0;i<n-1;i++)
        {
            if(array[i]>array[i+1])
            {
                flag=array[i];
                array[i]=array[i+1];
                array[i+1]=flag;
                flag=1;
                counter++;
            }
        }
    }
    return counter;
}


Measured memory_bytes: 2100
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

ans = -1
d = float('inf')
for i in range(n):
    b = abs(a - (t - 0.006 * h[i]))
    if b < d:
        d = b
        ans = i + 1

print(ans)

Measured memory_bytes: 3060
#!/usr/bin/env python3
# -*- coding: utf-8 -*-*-

from sys import stdin


def main():
    N, M = map(int, stdin.readline().split())
    A = list(map(int, stdin.readline().split()))
    j = sum(A) / (4 * M)
    cnt = 0
    for a in A:
        if a >= j:
            cnt += 1
            if cnt == M:
                print('Yes')
                return
    print('No')


if __name__ == "__main__":
    main()


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

using namespace std;

void no()
{
    cout << "NO" << endl;
    exit(0);
}

int main()
{
    int h,w,n;
    cin >> h >> w >> n;
    int r,c;
    cin >> r >> c;
    string s,t; //s wants to remove
    cin >> s >> t;
    int a;
    //Up
    a=r;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='U') a--;
        if(a==0) no();
        if(t[i]=='D'&&a!=h) a++;
    }
    //Down
    a=r;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='D') a++;
        if(a==h+1) no();
        if(t[i]=='U'&&a!=1) a--;
    }
    //Left
    a=c;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='L') a--;
        if(a==0) no();
        if(t[i]=='R'&&a!=w) a++;
    }
    //Right
    a=c;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R') a++;
        if(a==w+1) no();
        if(t[i]=='L'&&a!=1) a--;
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 776
#include<iostream>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define arep(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << N * N * N << endl;
    return 0;
}

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

using namespace std;


int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 1000000;
    int w = 0, r = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'W') {
            w++;
        } else {
            r++;
        }
    }
    ans = min(ans, r);
    int w_counter = 0, r_counter = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'W') {
            w_counter++;
        } else {
            r_counter++;
        }
        int rr = r - r_counter;
        int ans1 = max(w_counter, rr);
        ans = min(ans, ans1);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3732
#include<iostream>
#include<cstring>
using namespace std;
int main(){
  string s;
  string b;
  string e;
  cin>>s;
  int q;
  cin>>q;
  bool flag = true;
  while(q--){
    int t;
    cin>>t;
    if(t==1) flag = !flag;
    else{
      int f;
      cin>>f;
      char c;
      cin>>c;
      if((flag && f==1) ||(!flag && f==2)){
        b=b+c;
      }else e=e+c;
    }
  }
  if(flag){
    for(int i=b.length()-1;i>=0;i--) cout<<b[i];
    cout<<s;
    cout<<e;
    cout<<endl;
  }else{
    for(int i=e.length()-1;i>=0;i--) cout<<e[i];
    for(int i=s.length()-1;i>=0;i--) cout<<s[i];
    cout<<b;
    cout<<endl;
  }
}


Measured memory_bytes: 1456
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  map<string,int>data;
  for(int i=0;i<N;i++){
    string tmp;
    cin>>tmp;
    data[tmp]++;
  }
  int ans=data.size();
  cout<<ans<<endl;
}


Measured memory_bytes: 19148
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


X = inp()
if X == 1:
    print(1)
else:
    res = 1
    for b in range(2, X):
        for p in range(2, X):
            a = b**p
            if a <= X:
                res = max(a, res)
            else:
                break
    print(res)


Measured memory_bytes: 3064
from collections import Counter
 
 
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    counter = Counter(A)
    searched = [0 for _ in range(10 ** 6 + 1)]
    ans = 0
    for i in range(1, 10 ** 6 + 1):
        if counter[i] == 0:
            continue
        if searched[i] == 0 and counter[i] == 1:
            ans += 1
        for j in range(1, ((10 ** 6) // i) + 1):
            searched[i * j] = 1
    print(ans)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 44312
a = []

for i in range(3):
    a.append(list(map(int, input().split())))

n = int(input())

b = []

for i in range(n):
    b.append(int(input()))


for j in range(len(a)):
    for k in range(len(a)):
        for u in range(len(b)):
            if a[j][k] == b[u]:
                a[j][k] = 0


if (a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0) or (a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0):
    print("Yes")
    exit()
elif (a[0][0] == 0 and a[1][0] == 0 and a[2][0] == 0) or (a[0][1] == 0 and a[1][1] == 0 and a[2][1] == 0) or (a[0][2] == 0 and a[1][2] == 0 and a[2][2] == 0):
    print("Yes")
    exit()

for y in range(len(a)):
    if a[y].count(0) == 3:
        print("Yes")
        exit()

print("No")



Measured memory_bytes: 3064
//abc154_b.cpp
//Sat Mar 28 17:45:51 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	for (int i=0;i<s.length();i++){
		cout << "x";
	}
	printf("\n");
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;
bool comp(const pll &a, const pll &b) {
	return a.first < b.first;
}
int main()
{
	priority_queue<int> q;
	ll h, w, a, b, ans = 0;
	int s[100005] = {};
	cin >> a;
	//vector<pair<ll, ll> > hoges(ll(a));
	vector<pair<ll, ll> > hoges(a);
	for (int i = 1; i <= a; i++)
	{
		cin >> h;
		hoges[i-1] = make_pair(h,i);
	}
	sort(hoges.begin(), hoges.end(), comp);
	for (int i = 0; i < a; i++)
	{
		cout << hoges[i].second << endl;
	}
	//cin >> a >> b;
	//for (int i = 0; i < a; i++)
	//{
	//	cin >> s[i];
	//	if (s[i] >= b)
	//	{
	//		ans++;
	//	}
	//}

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


Measured memory_bytes: 2432
import java.util.*;
public class Main{
	
	
	private static Scanner sc=new Scanner(System.in);
	
	public static void main(String []args){
		int n=sc.nextInt();
		int x=sc.nextInt();
		int t=sc.nextInt();
		
		int time=(n/x)*t;
		if(n%x!=0)
			time+=t;
		System.out.println(time);
		
	}
	
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 2e5 + 5;

int N;
ll V, E, C;

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N;
  vector<ii> vec;
  for(int i = 1; i < N; ++i){
    int u, v; cin >> u >> v;
    if(u > v) swap(u, v);
    E += 1ll * u * (N - v + 1);
    vec.eb(u, v);
  }
  for(int i = 1, j = N; i <= N; ++i, --j){
    V += 1ll * i * j;
  }
  #ifdef LOCAL
  ll V1 = 0, E1 = 0;
  for(int l = 1; l <= N; ++l){
    for(int r = l; r <= N; ++r){
      V1 += r - l + 1;
      auto ins = [&](int x)
      {
        return l <= x && x <= r;
      };
      for(auto & it : vec){
        if(ins(it.fi) && ins(it.se)) ++E1;
      }
    }
  }
  cerr << V << ' ' << E << ' ' << V1 << ' ' << E1;
  #endif // LOCAL
  cout << V - E;
}


Measured memory_bytes: 5336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vll vector<ll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
ll mod1 = 1e9 + 7;
ll mod2 = 998244353;

ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=(z*x);x =(x*x) ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll max(ll a,ll b,ll c){
	return max(max(a,b),c);
}
//to check overlap of intervals
bool overlap(pll p1,pll p2){
	if(p1.ss <= p2.ff)return false;
	if(p1.ff >= p2.ss)return false;
	return true;
	
}
void solve(ll tn){
	}






int main(){
	ll n,m;
	cin>>n>>m;
	ll a[n],sum = 0,cnt=0;
	fo(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	float th = (float)sum/(float)(4*m);
	fo(i,n){
		if(a[i]>=th)cnt++;
	}
	if(cnt>=m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;






}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  int x,n;
  scanf("%d%d",&x,&n);
  int a[n];
  for (int i=0;i<n;i++)
    scanf("%d",&a[i]);
  sort(a,a+n);
  vector<int> v;
  for (int i=-100;i<=1000;i++)
  {
    int c=0;
    for (int j=0;j<n;j++)
    {
      if (i==a[j])
        c++;
    }
    if (c==0)
      v.push_back(i);
  }
  if (n==0)
  {
      printf("%d\n",x);
      return 0;
  }
  int val1=-100,val2=1000,index=0;
  for (int i=0;i<v.size();i++)
  {
    if (v[i]>x)
    {
      val2=v[i];
      index=i;
      break;
    }
  }
  /*
  for (auto it=v.begin();it!=v.end();it++)
  {
    if (*it>x)
    {
      val2=*it;
      break;
    }
    else
      index++;
  }
  */
  val1=v[index-1];
  if (abs(val1-x)<=abs(val2-x))
    printf("%d\n",val1);
  else
    printf("%d\n",val2);
  return 0;
}

Measured memory_bytes: 3800